codeant-ai-for-open-source[bot] commented on code in PR #42088:
URL: https://github.com/apache/superset/pull/42088#discussion_r3632061908
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/utils/getCellStyle.ts:
##########
@@ -55,29 +55,55 @@ const getCellStyle = (params: CellStyleParams) => {
let backgroundColor;
let color;
if (hasColumnColorFormatters) {
+ const applyFormatter = (
+ formatter: ColorFormatters[number],
+ valueToFormat: typeof value,
+ ) => {
+ const formatterResult =
+ valueToFormat || valueToFormat === 0
+ ? formatter.getColorFromValue(valueToFormat)
+ : false;
+ if (formatterResult) {
+ if (
+ formatter.objectFormatting === ObjectFormattingEnum.TEXT_COLOR ||
+ formatter.toTextColor
+ ) {
+ color = formatterResult;
+ } else if (
+ formatter.objectFormatting !== ObjectFormattingEnum.CELL_BAR
+ ) {
+ backgroundColor = formatterResult;
+ }
+ }
+ };
+
columnColorFormatters!
.filter(formatter => {
+ if (formatter.columnFormatting) {
+ return formatter.columnFormatting === colDef.field;
+ }
const colTitle = formatter?.column?.includes('Main')
? formatter?.column?.replace('Main', '').trim()
: formatter?.column;
return colTitle === colDef.field;
})
.forEach(formatter => {
- const formatterResult =
- value || value === 0 ? formatter.getColorFromValue(value) : false;
- if (formatterResult) {
- if (
- formatter.objectFormatting === ObjectFormattingEnum.TEXT_COLOR ||
- formatter.toTextColor
- ) {
- color = formatterResult;
- } else if (
- formatter.objectFormatting !== ObjectFormattingEnum.CELL_BAR
- ) {
- backgroundColor = formatterResult;
- }
- }
+ const valueToFormat = formatter.columnFormatting
+ ? node?.data?.[formatter.column]
+ : value;
Review Comment:
**Suggestion:** When `columnFormatting` is present, the formatter value is
read from `node.data[formatter.column]`, but this key can be a display label
(for example a legacy “Main …” label) rather than the actual field id used for
matching. In that case the lookup returns `undefined` and the color formatter
is silently skipped. Use the resolved field identifier
(`columnFormatting`/`colDef.field`) for value lookup so formatting is applied
reliably. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Column-level color formatters sometimes never apply to cells.
- ⚠️ AG Grid table plugin shows unformatted metric values.
- ⚠️ Users may distrust conditional formatting configuration behavior.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. In
`superset-frontend/plugins/plugin-chart-ag-grid-table/src/utils/getCellStyle.ts:41`,
call `getCellStyle` with `hasColumnColorFormatters = true` and
`columnColorFormatters`
containing a formatter where `formatter.columnFormatting` equals the field
id (e.g.,
`"my_field"`) and `formatter.column` is a display label (e.g., `"Main
my_field"`), while
`node.data` has a key only for `"my_field"`.
2. Ensure `colDef.field` is set to `"my_field"` so that the formatter passes
the filter at
lines 80–88, where `formatter.columnFormatting === colDef.field` is checked.
3. When execution reaches the `forEach` at lines 90–95, `valueToFormat` is
computed at
lines 91–93 as `node?.data?.[formatter.column]`, which looks up `"Main
my_field"` in
`node.data` and returns `undefined` because only `"my_field"` exists.
4. Inside `applyFormatter` at lines 58–78, the condition `valueToFormat ||
valueToFormat
=== 0` fails for `undefined`, so `formatter.getColorFromValue` is never
called and neither
`color` nor `backgroundColor` is set, causing the configured column color
formatter to be
silently ignored.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=4182a900970b4458989ae3fb79d5b999&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=4182a900970b4458989ae3fb79d5b999&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/plugin-chart-ag-grid-table/src/utils/getCellStyle.ts
**Line:** 91:93
**Comment:**
*Logic Error: When `columnFormatting` is present, the formatter value
is read from `node.data[formatter.column]`, but this key can be a display label
(for example a legacy “Main …” label) rather than the actual field id used for
matching. In that case the lookup returns `undefined` and the color formatter
is silently skipped. Use the resolved field identifier
(`columnFormatting`/`colDef.field`) for value lookup so formatting is applied
reliably.
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%2F42088&comment_hash=74108a847de41097296eb4fa1e6cbcd3a68495cae9c56a19ebb3cb578ff1661b&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42088&comment_hash=74108a847de41097296eb4fa1e6cbcd3a68495cae9c56a19ebb3cb578ff1661b&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]