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


##########
superset-frontend/packages/superset-ui-core/src/chart/components/Matrixify/MatrixifyGridGenerator.ts:
##########
@@ -134,6 +134,30 @@ function appendMatrixifyFilters(
   });
 }
 
+/**
+ * Apply the matrix's chosen metrics to the primary `metrics` collection as 
well
+ * as every query-specific `metrics_*` collection present on the formData (plus
+ * the singular `metric` field used by single-metric viz types). Charts with
+ * more than one query (e.g. Mixed Chart) read each query's metrics from a
+ * separate collection (`metrics_b`, `metrics_c`, ...), so a cell's chosen
+ * metrics must overwrite all of them, not just the primary query's.
+ */
+function overrideMatrixifyMetrics(
+  formData: QueryFormData & MatrixifyFormData,
+  metrics: AdhocMetric[],
+): void {
+  const metricsFields: Record<string, unknown> = formData;
+  const metricsKeys = [
+    'metrics',
+    ...Object.keys(metricsFields).filter(key => /^metrics_.+$/u.test(key)),
+  ];

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Duplicated key-discovery logic</b></div>
   <div id="fix">
   
   `overrideMatrixifyMetrics` repeats the key-discovery logic of 
`appendMatrixifyFilters` (base key plus `/^<base>_.+$/` scan over 
`Object.keys`), differing only in the per-key mutation. Extracting a shared 
helper would keep the two query-collection strategies from diverging on future 
changes.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #96600b</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



##########
superset-frontend/packages/superset-ui-core/src/chart/components/Matrixify/MatrixifyGridGenerator.ts:
##########
@@ -134,6 +134,30 @@ function appendMatrixifyFilters(
   });
 }
 
+/**
+ * Apply the matrix's chosen metrics to the primary `metrics` collection as 
well
+ * as every query-specific `metrics_*` collection present on the formData (plus
+ * the singular `metric` field used by single-metric viz types). Charts with
+ * more than one query (e.g. Mixed Chart) read each query's metrics from a
+ * separate collection (`metrics_b`, `metrics_c`, ...), so a cell's chosen
+ * metrics must overwrite all of them, not just the primary query's.
+ */
+function overrideMatrixifyMetrics(
+  formData: QueryFormData & MatrixifyFormData,
+  metrics: AdhocMetric[],
+): void {
+  const metricsFields: Record<string, unknown> = formData;

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Unsound double-cast defeats typing</b></div>
   <div id="fix">
   
   `const metricsFields: Record<string, unknown> = formData;` double-casts 
through `unknown`, disabling type checking for every write to formData. The 
repo standard requires proper TypeScript types over `any`-style escape hatches. 
A typed key list (e.g. `Object.keys(formData)` into `string[]`) achieves the 
same dynamic scan without the unsound cast.
   </div>
   
   
   </div>
   
   <details>
   <summary><b>Citations</b></summary>
   <ul>
   
   <li>
   Rule Violated: <a 
href="https://github.com/apache/superset/blob/b7945b8/.cursor/rules/dev-standard.mdc#L16";>dev-standard.mdc:16</a>
   </li>
   
   </ul>
   </details>
   
   
   
   
   <small><i>Code Review Run #96600b</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