bito-code-review[bot] commented on code in PR #38533:
URL: https://github.com/apache/superset/pull/38533#discussion_r2907734040


##########
docs/src/theme/ApiExplorer/MethodEndpoint/index.tsx:
##########
@@ -0,0 +1,94 @@
+/* ============================================================================
+ * Swizzled from docusaurus-theme-openapi-docs to fix SSG crash.
+ *
+ * The original component calls useTypedSelector (Redux) at the top level,
+ * which fails during static site generation because no Redux store is
+ * available. This version moves the hook into a browser-only child component
+ * so SSG can render the page without a store context.
+ * ========================================================================== 
*/
+
+import React from "react";
+
+import BrowserOnly from "@docusaurus/BrowserOnly";
+import { useTypedSelector } from "@theme/ApiItem/hooks";
+
+function colorForMethod(method: string) {
+  switch (method.toLowerCase()) {
+    case "get":
+      return "primary";
+    case "post":
+      return "success";
+    case "delete":
+      return "danger";
+    case "put":
+      return "info";
+    case "patch":
+      return "warning";
+    case "head":
+      return "secondary";
+    case "event":
+      return "secondary";
+    default:
+      return undefined;
+  }
+}
+
+export interface Props {
+  method: string;
+  path: string;
+  context?: "endpoint" | "callback";
+}
+
+interface ServerState {
+  server: { value: { url: string; variables?: Record<string, { default?: 
string }> } | null };
+}
+
+// Inner component rendered only in the browser, where the Redux store exists.
+function ServerUrl() {
+  const serverValue = useTypedSelector((state: ServerState) => 
state.server.value);
+
+  if (serverValue && serverValue.variables) {
+    let serverUrlWithVariables = serverValue.url.replace(/\/$/, "");
+    Object.keys(serverValue.variables).forEach((variable) => {
+      serverUrlWithVariables = serverUrlWithVariables.replace(
+        `{${variable}}`,
+        serverValue.variables?.[variable].default ?? ""
+      );
+    });
+    return <>{serverUrlWithVariables}</>;
+  }
+
+  if (serverValue && serverValue.url) {
+    return <>{serverValue.url}</>;
+  }
+
+  return null;
+}
+
+function MethodEndpoint({ method, path, context }: Props) {
+  const renderServerUrl = () => {
+    if (context === "callback") {
+      return "";
+    }
+    return <BrowserOnly>{() => <ServerUrl />}</BrowserOnly>;
+  };
+
+  return (
+    <>
+      <pre className="openapi__method-endpoint">
+        <span className={"badge badge--" + colorForMethod(method)}>
+          {method === "event" ? "Webhook" : method.toUpperCase()}

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Untranslated user-facing text</b></div>
   <div id="fix">
   
   Import useTranslate from "@docusaurus/Translate", add `const { t } = 
useTranslate();` in MethodEndpoint, and wrap the "Webhook" string in `t()` for 
internationalization support.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ```
    Import useTranslate, add const {t} = useTranslate(); in MethodEndpoint, and 
wrap "Webhook" with t().
   ```
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #7df401</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



##########
docs/src/theme/ApiExplorer/MethodEndpoint/index.tsx:
##########
@@ -0,0 +1,94 @@
+/* ============================================================================
+ * Swizzled from docusaurus-theme-openapi-docs to fix SSG crash.
+ *
+ * The original component calls useTypedSelector (Redux) at the top level,
+ * which fails during static site generation because no Redux store is
+ * available. This version moves the hook into a browser-only child component
+ * so SSG can render the page without a store context.
+ * ========================================================================== 
*/
+
+import React from "react";
+
+import BrowserOnly from "@docusaurus/BrowserOnly";
+import { useTypedSelector } from "@theme/ApiItem/hooks";
+
+function colorForMethod(method: string) {
+  switch (method.toLowerCase()) {
+    case "get":
+      return "primary";
+    case "post":
+      return "success";
+    case "delete":
+      return "danger";
+    case "put":
+      return "info";
+    case "patch":
+      return "warning";
+    case "head":
+      return "secondary";
+    case "event":
+      return "secondary";
+    default:
+      return undefined;

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Invalid CSS class for unknown methods</b></div>
   <div id="fix">
   
   For unsupported HTTP methods, colorForMethod returns undefined, creating an 
invalid CSS class "badge badge--undefined" that could break styling. Switch to 
"secondary" to match other cases like "head" and "event".
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
       default:
         return "secondary";
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #7df401</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to