({
value,
onChange,
columns,
}: EditChartMenuProps)
| 21 | } |
| 22 | |
| 23 | export default function EditChartMenu({ |
| 24 | value, |
| 25 | onChange, |
| 26 | columns, |
| 27 | }: EditChartMenuProps) { |
| 28 | const { forcedTheme, resolvedTheme } = useTheme(); |
| 29 | const isNotChartComponent = ["text", "single_value", "table"].includes( |
| 30 | value.type ?? "line" |
| 31 | ); |
| 32 | |
| 33 | // Add default yAxisKeyColors |
| 34 | useEffect(() => { |
| 35 | if (!value.params.options.yAxisKeyColors && columns?.length > 0) { |
| 36 | const appTheme: "light" | "dark" = (forcedTheme || resolvedTheme) as |
| 37 | | "light" |
| 38 | | "dark"; |
| 39 | const themeColor = THEMES.neonPunk.colors?.[appTheme ?? "light"]; |
| 40 | const colors = generateGradientColors( |
| 41 | themeColor[0], |
| 42 | themeColor[1], |
| 43 | columns.length |
| 44 | ); |
| 45 | |
| 46 | onChange((prev) => { |
| 47 | const newColors = columns.reduce( |
| 48 | (acc, col, i) => { |
| 49 | acc[col] = colors[i]; |
| 50 | return acc; |
| 51 | }, |
| 52 | {} as Record<string, string> |
| 53 | ); |
| 54 | return produce(prev, (draft) => { |
| 55 | draft.params.options.yAxisKeyColors = newColors; |
| 56 | }); |
| 57 | }); |
| 58 | } |
| 59 | }, [ |
| 60 | columns, |
| 61 | forcedTheme, |
| 62 | onChange, |
| 63 | resolvedTheme, |
| 64 | value.params.options.yAxisKeyColors, |
| 65 | ]); |
| 66 | |
| 67 | // add default yAxisKeys and xAxisKey |
| 68 | useEffect(() => { |
| 69 | const allColumns = columns ?? []; |
| 70 | if (!value.params.options.xAxisKey && columns?.length > 0) { |
| 71 | onChange((prev) => { |
| 72 | return produce(prev, (draft) => { |
| 73 | draft.params.options.xAxisKey = allColumns.pop(); |
| 74 | }); |
| 75 | }); |
| 76 | } |
| 77 | |
| 78 | if (!value.params.options.yAxisKeys && columns?.length > 0) { |
| 79 | onChange((prev) => { |
| 80 | return produce(prev, (draft) => { |
nothing calls this directly
no test coverage detected