codeant-ai-for-open-source[bot] commented on code in PR #39452:
URL: https://github.com/apache/superset/pull/39452#discussion_r3532974513


##########
superset-frontend/plugins/legacy-plugin-chart-horizon/src/HorizonChart.tsx:
##########
@@ -106,35 +88,36 @@ class HorizonChart extends 
PureComponent<HorizonChartProps> {
       const rawExtent = d3Extent(allValues, d => d.y);
       // Only set yDomain if we have valid min and max values
       if (rawExtent[0] != null && rawExtent[1] != null) {
-        yDomain = [rawExtent[0], rawExtent[1]];
+        return [rawExtent[0], rawExtent[1]];
       }
     }
+    return undefined;
+  }, [colorScale, data]);
 
-    return (
-      <StyledDiv>
-        <div
-          className={`superset-legacy-chart-horizon ${className}`}
-          style={{ height }}
-        >
-          {data.map(row => (
-            <HorizonRow
-              key={row.key.join(',')}
-              width={width}
-              height={seriesHeight}
-              title={ensureIsArray(row.key).join(', ')}
-              data={row.values}
-              bands={bands}
-              colors={colors}
-              colorScale={colorScale}
-              mode={mode}
-              offsetX={offsetX}
-              yDomain={yDomain}
-            />
-          ))}
-        </div>
-      </StyledDiv>
-    );
-  }
+  return (
+    <StyledDiv>
+      <div
+        className={`superset-legacy-chart-horizon ${className}`}
+        style={{ height }}
+      >
+        {data.map(row => (
+          <HorizonRow
+            key={row.key.join(',')}
+            width={width}
+            height={seriesHeight}
+            title={ensureIsArray(row.key).join(', ')}

Review Comment:
   **Suggestion:** The row key is used as an array for `join`, but the same 
value is normalized with `ensureIsArray` for the title, which means non-array 
keys are expected at runtime. If `row.key` is a scalar, `row.key.join` throws 
and the whole chart fails to render. Normalize `row.key` before generating the 
React key as well. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ Horizon visualization crashes when series keys are scalars.
   - ⚠️ Some Horizon charts unusable for affected datasets.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Horizon visualization is registered in 
`src/visualizations/presets/MainPreset.ts:133`
   via `new HorizonChartPlugin().configure({ key: VizType.Horizon })`, which 
uses the
   `HorizonChart` component defined in
   `plugins/legacy-plugin-chart-horizon/src/HorizonChart.tsx:70-121`.
   
   2. `HorizonChart` accepts a `data: DataSeries[]` prop (interface at
   `HorizonChart.tsx:29-32`) where each series has a `key` and `values`; 
upstream code
   normalizes keys for display with `ensureIsArray(row.key)` in the title at
   `HorizonChart.tsx:108`, showing that `row.key` may be a scalar at runtime.
   
   3. At render time, `HorizonChart` maps over `data` and renders 
`<HorizonRow>` (see
   `HorizonChart.tsx:103-117`), setting the React key with 
`key={row.key.join(',')}` at line
   105, while the title uses the safe `ensureIsArray(row.key).join(', ')` at 
line 108.
   
   4. When a Horizon chart is rendered with series where `row.key` is a scalar 
(for example a
   single group label string coming from the legacy horizon plugin pipeline),
   `row.key.join(',')` at `HorizonChart.tsx:105` attempts to call `join` on a 
non-array
   value, throwing `TypeError: row.key.join is not a function` and preventing 
the Horizon
   chart from rendering even though the title logic would have handled the 
scalar correctly.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a436dfe1fba048a192e342fc21c2204e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a436dfe1fba048a192e342fc21c2204e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/plugins/legacy-plugin-chart-horizon/src/HorizonChart.tsx
   **Line:** 105:108
   **Comment:**
        *Type Error: The row key is used as an array for `join`, but the same 
value is normalized with `ensureIsArray` for the title, which means non-array 
keys are expected at runtime. If `row.key` is a scalar, `row.key.join` throws 
and the whole chart fails to render. Normalize `row.key` before generating the 
React key as well.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39452&comment_hash=b33f55bde8d96e181198cef6998c852ec4e708c65c4f1c3313c6f26e4aaf90a9&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39452&comment_hash=b33f55bde8d96e181198cef6998c852ec4e708c65c4f1c3313c6f26e4aaf90a9&reaction=dislike'>👎</a>



-- 
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