Compare commits

...

2 Commits

Author SHA1 Message Date
Claude Code
35679e13d7 test(big-number): add regression test for null colorPicker in transformProps
Adds BRAND_COLOR to the @superset-ui/core mock and a test verifying
that transformProps does not crash when colorPicker is null, and that
mainColor is undefined (so the ?? BRAND_COLOR fallback takes effect).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 12:07:59 -07:00
Amin Ghadersohi
536d30bdda fix(big-number): guard against null colorPicker in transformProps
colorPicker defaults to null when the colour-picker control has never been
set (e.g. a freshly-created Big Number chart). Destructuring it directly
crashes:

  TypeError: Cannot destructure property 'r' of 'colorPicker' as it is null

When colorPicker is null/undefined, mainColor is now left undefined so that
BigNumberViz falls back to its existing BRAND_COLOR default. The ECharts
trendline options fall back to BRAND_COLOR explicitly since they require a
string value.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 10:21:40 -07:00
2 changed files with 33 additions and 4 deletions

View File

@@ -56,6 +56,7 @@ jest.mock('@superset-ui/chart-controls', () => ({
}));
jest.mock('@superset-ui/core', () => ({
BRAND_COLOR: '#00A699',
GenericDataType: { Temporal: 2, String: 1 },
extractTimegrain: jest.fn(() => 'P1D'),
getMetricLabel: jest.fn(metric => metric),
@@ -280,4 +281,30 @@ describe('BigNumberWithTrendline transformProps', () => {
expect(result.bigNumber).toBe(360);
expect(result.subheader).toBe('50.0% WoW');
});
test('should not crash and should return undefined mainColor when colorPicker is null', () => {
const chartProps = {
width: 400,
height: 300,
queriesData: [
{
data: [
{ __timestamp: 1, value: 100 },
] as unknown as BigNumberDatum[],
colnames: ['__timestamp', 'value'],
coltypes: ['TEMPORAL', 'NUMERIC'],
},
],
formData: { ...baseFormData, colorPicker: null },
rawFormData: baseRawFormData,
hooks: baseHooks,
datasource: baseDatasource,
theme: { colors: { grayscale: { light5: '#eee' } } },
};
const result = transformProps(
chartProps as unknown as BigNumberWithTrendlineChartProps,
);
expect(result.mainColor).toBeUndefined();
});
});

View File

@@ -18,6 +18,7 @@
*/
import { t } from '@apache-superset/core/translation';
import {
BRAND_COLOR,
extractTimegrain,
getNumberFormatter,
NumberFormats,
@@ -140,8 +141,9 @@ export default function transformProps(
const compareLag = Number(compareLag_) || 0;
let formattedSubheader = subheader;
const { r, g, b } = colorPicker;
const mainColor = `rgb(${r}, ${g}, ${b})`;
const mainColor = colorPicker
? `rgb(${colorPicker.r}, ${colorPicker.g}, ${colorPicker.b})`
: undefined;
const xAxisLabel = getXAxisLabel(rawFormData) as string;
let trendLineData: TimeSeriesDatum[] | undefined;
@@ -290,12 +292,12 @@ export default function transformProps(
symbol: 'circle',
symbolSize: 10,
showSymbol: false,
color: mainColor,
color: mainColor ?? BRAND_COLOR,
areaStyle: {
color: new graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: mainColor,
color: mainColor ?? BRAND_COLOR,
},
{
offset: 1,