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


##########
superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx:
##########
@@ -107,6 +107,71 @@ interface TableSize {
   height: number;
 }
 
+type ConditionalFormattingColors = {
+  backgroundColor?: string;
+  color?: string;
+  backgroundColorCellBar?: string;
+  skipValueRange?: boolean;
+};
+
+function getConditionalFormattingColors(
+  columnColorFormatters: ColorFormatters,
+  record: DataRecord,
+  columnKey: string,
+  value: DataRecordValue,
+  applyCellBars = false,
+): ConditionalFormattingColors {
+  const colors: ConditionalFormattingColors = {};
+  const applyFormatter = (
+    formatter: ColorFormatters[number],
+    valueToFormat: DataRecordValue,
+  ) => {
+    const formatterResult = formatter.getColorFromValue(
+      valueToFormat as number | string | boolean | null,
+    );
+    if (!formatterResult) return;
+
+    if (
+      formatter.objectFormatting === ObjectFormattingEnum.TEXT_COLOR ||
+      formatter.toTextColor
+    ) {
+      colors.color = formatterResult;
+    } else if (formatter.objectFormatting === ObjectFormattingEnum.CELL_BAR) {
+      if (applyCellBars) {
+        colors.backgroundColorCellBar = forceHexAlpha(formatterResult);
+      }
+    } else {
+      colors.backgroundColor = formatterResult;
+      colors.skipValueRange = true;
+    }
+  };
+
+  columnColorFormatters
+    .filter(formatter => {
+      if (formatter.columnFormatting) {
+        return formatter.columnFormatting === columnKey;
+      }
+      return formatter.column === columnKey;
+    })
+    .forEach(formatter => {
+      const valueToFormat = formatter.columnFormatting
+        ? record[formatter.column as string]
+        : value;
+      applyFormatter(formatter, valueToFormat);
+    });

Review Comment:
   **Suggestion:** Comparison totals are keyed as `Main <metric>`, `# 
<metric>`, `△ <metric>`, and `% <metric>`, but this lookup always reads 
`record[formatter.column]`, where `formatter.column` remains the original 
metric key. Consequently, a rule configured with `columnFormatting` can match a 
comparison totals column but receives `undefined` instead of that totals cell's 
value, so the rule is skipped or produces incorrect formatting. Resolve the 
formatter's source value using the corresponding comparison key before calling 
`getColorFromValue`. [incorrect variable usage]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Comparison totals cells ignore matching conditional rules.
   - ⚠️ Time-comparison summary formatting appears inconsistent.
   - ⚠️ Comparison data cells use the same incorrect source lookup.
   ```
   </details>
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx
   **Line:** 149:161
   **Comment:**
        *Incorrect Variable Usage: Comparison totals are keyed as `Main 
<metric>`, `# <metric>`, `△ <metric>`, and `% <metric>`, but this lookup always 
reads `record[formatter.column]`, where `formatter.column` remains the original 
metric key. Consequently, a rule configured with `columnFormatting` can match a 
comparison totals column but receives `undefined` instead of that totals cell's 
value, so the rule is skipped or produces incorrect formatting. Resolve the 
formatter's source value using the corresponding comparison key before calling 
`getColorFromValue`.
   
   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%2F43370&comment_hash=83b2af9e1adcccce813299d05df70d3be0fe5b6189e92b68bb50c8949966a1e2&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43370&comment_hash=83b2af9e1adcccce813299d05df70d3be0fe5b6189e92b68bb50c8949966a1e2&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