codeant-ai-for-open-source[bot] commented on code in PR #28038:
URL: https://github.com/apache/superset/pull/28038#discussion_r2955061386
##########
superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberViz.tsx:
##########
@@ -213,11 +213,8 @@ function BigNumberVis({
let numberColor;
if (hasThresholdColorFormatter) {
colorThresholdFormatters!.forEach(formatter => {
- const formatterResult = bigNumber
- ? formatter.getColorFromValue(bigNumber as number)
- : false;
- if (formatterResult) {
- numberColor = formatterResult;
+ if (typeof bigNumber === 'number' && !isNaN(bigNumber)) {
+ numberColor = formatter.getColorFromValue(bigNumber);
Review Comment:
**Suggestion:** This assignment overwrites any previously matched color with
`undefined` when a later formatter does not match. With multiple conditional
formatters, a valid earlier match can be lost and the header ends up uncolored.
Store the formatter result first and only update the color when a formatter
actually returns a color value. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Big Number header color disappears with mixed rules.
- ⚠️ Conditional-formatting intent not reflected in KPI tiles.
- ⚠️ Dashboard visual alerting becomes unreliable for thresholds.
```
</details>
```suggestion
if (typeof bigNumber === 'number' && !isNaN(bigNumber)) {
const formatterResult = formatter.getColorFromValue(bigNumber);
if (formatterResult) {
numberColor = formatterResult;
}
```
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Open Explore/Dashboard with `big_number_total` chart type; this plugin is
registered in
`superset-frontend/src/visualizations/presets/MainPreset.ts:112-113` and
loads BigNumber
viz via
`superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/index.ts:63`.
2. Configure conditional formatting with multiple rules (first rule matches
value, later
rule does not match); these are converted into `colorThresholdFormatters` in
`superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/transformProps.ts:120-121`
and passed to viz at `:134`.
3. Render the chart header; `renderHeader` iterates all formatters in
`superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberViz.tsx:215-217`
and assigns `numberColor` on every iteration.
4. When a later formatter does not match, `getColorFromValue` returns
`undefined` (see
`superset-frontend/packages/superset-ui-chart-controls/src/utils/getColorFormatters.ts:263`),
overwriting an earlier valid color; header text ends uncolored.
```
</details>
<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-echarts/src/BigNumber/BigNumberViz.tsx
**Line:** 216:217
**Comment:**
*Logic Error: This assignment overwrites any previously matched color
with `undefined` when a later formatter does not match. With multiple
conditional formatters, a valid earlier match can be lost and the header ends
up uncolored. Store the formatter result first and only update the color when a
formatter actually returns a color value.
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.
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F28038&comment_hash=75943a9ba0b99ccf8719cc65af9eaf0e807e97ea4cc670f126244203e7b2ee92&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F28038&comment_hash=75943a9ba0b99ccf8719cc65af9eaf0e807e97ea4cc670f126244203e7b2ee92&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]