Skip to content

Commit 619651f

Browse files
committed
fix bito recommended
1 parent f6fbe17 commit 619651f

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

superset-frontend/packages/superset-ui-chart-controls/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ export type ColorFormatters = {
508508
objectFormatting?: ObjectFormattingEnum;
509509
getColorFromValue: (
510510
value: number | string | boolean | null,
511-
) => RgbaColor | string | undefined;
511+
) => string | undefined;
512512
}[];
513513

514514
export type ResolvedColorFormatterResult = {

superset-frontend/src/explore/components/controls/ColorPickerControl.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ const normalizeColorToHex = (color: string): string => {
5858

5959
const div = document.createElement('div');
6060
div.style.color = color;
61-
const normalized = div.style.color;
61+
const normalized = div.style.color || '';
6262

63-
const match = normalized.match(
64-
/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/,
63+
const match = /^rgba?\((\d+),\s+(\d+),\s+(\d+)(?:,\s*([\d.]+))?\)$/.exec(
64+
normalized,
6565
);
6666
if (match) {
6767
return rgbaToHex({
@@ -100,8 +100,11 @@ function toDisplayHex(
100100
if (value in SPECIAL_COLORS) {
101101
return rgbaToHex(SPECIAL_COLORS[value as SpecialColorKey]).toLowerCase();
102102
}
103-
if (themeColors && value in themeColors) {
104-
return themeColors[value].toLowerCase();
103+
if (
104+
themeColors &&
105+
Object.prototype.hasOwnProperty.call(themeColors, value)
106+
) {
107+
return themeColors[value as string].toLowerCase();
105108
}
106109
return value.toLowerCase();
107110
}
@@ -159,8 +162,11 @@ export default function ColorPickerControl({
159162
SPECIAL_COLORS[color as SpecialColorKey],
160163
).toLowerCase();
161164
}
162-
if (themeColors && color in themeColors) {
163-
return themeColors[color].toLowerCase();
165+
if (
166+
themeColors &&
167+
Object.prototype.hasOwnProperty.call(themeColors, color as string)
168+
) {
169+
return themeColors[color as string].toLowerCase();
164170
}
165171
return String(color).toLowerCase();
166172
}),

0 commit comments

Comments
 (0)