korbit-ai[bot] commented on code in PR #31752:
URL: https://github.com/apache/superset/pull/31752#discussion_r1907248723


##########
superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/buildQuery.ts:
##########
@@ -26,26 +27,28 @@ import {
   getXAxisColumn,
 } from '@superset-ui/core';
 import { rankOperator } from '@superset-ui/chart-controls';
-import { HeatmapFormData } from './types';
 
-export default function buildQuery(formData: HeatmapFormData) {
+export default function buildQuery(formData: QueryFormData) {
   const { groupby, normalize_across, sort_x_axis, sort_y_axis, x_axis } =
     formData;
   const metric = getMetricLabel(formData.metric);
   const columns = [
     ...ensureIsArray(getXAxisColumn(formData)),
     ...ensureIsArray(groupby),
   ];
-  const orderby: QueryFormOrderBy[] = [
-    [
+  const orderby: QueryFormOrderBy[] = [];
+  if (sort_x_axis) {
+    orderby.push([
       sort_x_axis.includes('value') ? metric : columns[0],
       sort_x_axis.includes('asc'),
-    ],
-    [
+    ]);
+  }
+  if (sort_y_axis) {
+    orderby.push([
       sort_y_axis.includes('value') ? metric : columns[1],

Review Comment:
   ### Array index access without bounds check <sub>![category 
Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   No validation that columns[1] exists before accessing it
   
   ###### Why this matters
   If groupby is empty array, columns[1] will be undefined, potentially causing 
incorrect sorting behavior or runtime errors
   
   ###### Suggested change
   Add validation: sort_y_axis.includes('value') ? metric : (columns[1] ?? 
columns[0])
   
   
   </details>
   
   ###### Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help 
Korbit improve your reviews.
   
   <!--- korbi internal id:99dde114-afa7-4f5e-bde4-3a27c2c35baa -->
   



##########
superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts:
##########
@@ -156,8 +156,10 @@ export default function transformProps(
       ),
       label: {
         show: showValues,
-        formatter: (params: CallbackDataParams) =>
-          valueFormatter(params.value?.[2]),
+        formatter: (params: CallbackDataParams) => {
+          const paramsValue = params.value as (string | number)[];
+          return valueFormatter(paramsValue?.[2] as number | null | undefined);
+        },

Review Comment:
   ### Unsafe Value Type Assertion in Formatter <sub>![category 
Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The type assertion of params.value to (string | number)[] may lead to 
runtime errors if the actual value structure differs from the expected format.
   
   ###### Why this matters
   If the data structure changes or if params.value is undefined, the code 
could crash during chart rendering. The current implementation doesn't provide 
proper runtime validation of the data structure.
   
   ###### Suggested change
   Add proper runtime validation:
   ```typescript
   formatter: (params: CallbackDataParams) => {
     if (!params.value || !Array.isArray(params.value)) {
       return '';
     }
     const value = params.value[2];
     return valueFormatter(typeof value === 'number' ? value : null);
   }
   ```
   
   
   </details>
   
   ###### Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help 
Korbit improve your reviews.
   
   <!--- korbi internal id:dab4afd5-9865-4a44-bf5a-2631546ffabd -->
   



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