Skip to content

feat(color-picker): consolidate remaining legacy color selectors onto ColorPickerControl - #42910

Draft
rusackas wants to merge 4 commits into
masterfrom
feat/color-picker-consolidation
Draft

feat(color-picker): consolidate remaining legacy color selectors onto ColorPickerControl#42910
rusackas wants to merge 4 commits into
masterfrom
feat/color-picker-consolidation

Conversation

@rusackas

@rusackas rusackas commented Aug 8, 2026

Copy link
Copy Markdown
Member

SUMMARY

Follow-up to #42053, which upgraded ColorPickerControl (custom presets, resolveThemeTokens, outputFormat) and used it to fix ConditionalFormattingControl. This PR finds and fixes the four remaining places in the app that still used a legacy/degraded color-selection UI instead of the shared picker, one commit per item.

1. Gauge chart interval colors

Gauge/controlPanel.tsx's "Interval colors" control asked users to type comma-separated 1-indexed positions into the chosen color scheme (e.g. 1,2,4), with zero visual feedback and silent discarding of malformed input.

Replaced with IntervalColorsControl: one ColorPickerControl per interval bound (parsed from the existing intervals control), storing real hex colors in a new interval_colors field, positionally matched to those bounds.

Design decision: bounds stay owned by the existing intervals text control rather than being folded into the new control's own row list (which the row-list add/remove pattern in the task brief technically implied). This keeps a single source of truth for bounds and avoids needing two-way sync between two independent controls — the new control's row count simply tracks whatever intervals currently contains.

Backward compatibility: charts saved before this control existed only have interval_color_indices (the old index strings). getIntervalBoundsAndColors in transformProps.ts still resolves those indices against the categorical scheme at render time whenever interval_colors is empty, so existing dashboards render identically with no migration. The control also resolves legacy indices to real colors for display the first time such a chart's panel is reopened (editor convenience only, not required for correct rendering).

Gauge: new Interval colors control + rendered chart

2. Bullet chart band colors

Bullet chart background bands were hardcoded to a 4-step theme-token ramp with no color control at all — a genuinely new feature, not a swap.

Added an optional range_colors control (BulletRangeColorsControl): one ColorPickerControl per threshold parsed from the existing ranges control, each starting unset ("use default") with a "Use default" link to clear a customization. transformProps.ts captures each range's chosen color by its original (pre-sort) position in ranges before the existing largest-first band sort reorders them for nested drawing, so colors stay pinned to the correct threshold regardless of draw order.

Backward compatible by construction: range_colors is optional and defaults to empty, so charts saved before this control existed have no such field and keep rendering with the exact default ramp.

Bullet: new Range colors control + rendered chart with custom band colors

3. Big Number Period-over-Period comparison colors

The comparison-color control was a 2-choice SelectControl ("Green for increase, red for decrease" / reverse) bound directly to theme.colorSuccess/theme.colorError.

Replaced with two ColorPickerControls, increase_color / decrease_color, using the exact resolveThemeTokens + outputFormat="hex" pattern #42053 introduced: picking the Green/Red preset swatch stores the token name (so it still reads the same as before for users who just want the classic behavior), while any other pick stores a literal hex color. Exported SPECIAL_COLORS/SpecialColorKey from ColorPickerControl.tsx so this call site doesn't redefine the Green/Red mapping.

The color→style resolution moved into two small, independently unit-tested pure functions in utils.ts (resolveComparisonColorKeys, getComparisonColorTokens) rather than living inline in PopKPI's render body — jsdom doesn't reliably expose emotion's injected styles to toHaveStyle for direct component assertions, so the logic needed to be testable on its own.

Backward compatibility: resolveComparisonColorKeys falls back to the legacy comparisonColorScheme field (kept, @deprecated in types.ts) whenever the new fields are absent — including correctly reversing increase/decrease for charts saved with the old "Red for increase, green for decrease" choice, the case a naive default-to-Green migration would have silently broken.

Big Number PoP: new Color for increase/decrease pickers + rendered comparison

4. Admin Theme editor curated colors

ThemeModal.tsx only exposed antd theming as a single JSON textarea, requiring admins to paste in a whole token object from an external tool to change even one color.

Added a "Colors" section (ThemeColorPickers) above the JSON textarea with one ColorPickerControl per curated antd token — the 5 SEED colors (colorPrimary, colorSuccess, colorWarning, colorError, colorInfo) plus 6 load-bearing map/alias tokens (colorLink, colorText, colorTextSecondary, colorBgBase, colorBgContainer, colorBorder). This intentionally does not attempt the full 100+ token surface — everything else stays fully editable via the JSON textarea, which remains the source of truth. Names are taken directly from antd's own SeedToken/MapToken types, not invented.

Sync is two-way, via two small pure functions (tryParseThemeJson, patchThemeJsonToken):

  • Picker → JSON: patches just that key into the JSON's token object and re-serializes with the modal's existing 2-space indent, preserving every other key (curated or not).
  • JSON → pickers: each render re-parses the textarea's current value and re-derives picker values from it.
  • Invalid/mid-edit JSON: tryParseThemeJson returns null instead of throwing (matching the file's existing isValidJson convention); the section shows a small notice and pickers stop persisting edits until the JSON is valid again.

The section is hidden for read-only system themes, matching the existing Format/Apply button visibility.

No backward-compat concern — additive UI over the same JSON, nothing about existing saved themes changes.

Theme editor: curated Colors section synced from JSON

TESTING INSTRUCTIONS

  • npm run test in superset-frontend/ — new/updated suites:
    • plugins/plugin-chart-echarts/test/Gauge/transformProps.test.ts
    • src/explore/components/controls/IntervalColorsControl/IntervalColorsControl.test.tsx
    • plugins/plugin-chart-echarts/test/Bullet/transformProps.test.ts
    • src/explore/components/controls/BulletRangeColorsControl/BulletRangeColorsControl.test.tsx
    • plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/{utils,PopKPI}.test.tsx
    • src/features/themes/{ThemeModal,ThemeColorPickers}.test.tsx
  • Manually: create/edit a Gauge chart, expand Customize → Intervals; create/edit a Bullet chart, expand Customize → Range colors; create/edit a Big Number w/ Time Comparison chart with "Add color for positive/negative change" enabled; open Settings → Themes → + Theme.
  • Backward compatibility: open an existing Gauge chart saved with interval_color_indices only, an existing Bullet chart with no range_colors, and a Big Number PoP chart saved with only comparison_color_scheme (including the Red value) — all three should render identically to before this PR.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

claude added 4 commits August 7, 2026 23:32
The Gauge chart's "Interval colors" control asked users to enter
comma-separated 1-indexed positions into the chosen color scheme (e.g.
"1,2,4"), forcing them to count swatches by hand with no visual
feedback and silently discarding malformed input.

Replace it with IntervalColorsControl, a new control that renders one
ColorPickerControl per interval bound (parsed from the existing
`intervals` control) and stores real hex colors in a new
`interval_colors` form-data field, positionally matched to those
bounds.

Backward compatibility: charts saved before this control existed only
have `interval_color_indices` (the old scheme-index strings).
`Gauge/transformProps.ts#getIntervalBoundsAndColors` still resolves
those indices against the chart's categorical scheme at render time
whenever `interval_colors` is absent or empty, so existing dashboards
render identically without a data migration. The new control also
resolves legacy indices to real colors for display the first time such
a chart's control panel is opened, purely as an editor convenience.

Design note: bounds stay owned by the existing `intervals` text
control rather than being folded into the new control's row list, so
there's a single source of truth for bounds and no risk of the two
controls drifting out of sync.
The Bullet chart's background range bands were hardcoded to a 4-step
theme-token ramp (colorFillQuaternary -> colorFill) with no way to
customize them, unlike the rest of the chart (ranges, markers, marker
lines) which are all user-configurable.

Add an optional `range_colors` control (BulletRangeColorsControl) that
renders one ColorPickerControl per threshold parsed from the existing
`ranges` control. Each row starts unset ("use default") with a "Use
default" link to clear a customization once made; unset rows keep
using the theme-token ramp exactly as before.

`Bullet/transformProps.ts` captures each range's chosen color
(matched by its original, pre-sort position in `ranges`) before the
existing largest-first band sort reorders them for nested drawing, so
colors stay pinned to the correct threshold regardless of draw order.

Backward compatible by construction: `range_colors` is optional and
defaults to empty, so Bullet charts saved before this control existed
have no such field and render with the exact same default ramp.
The Period-over-Period Big Number's "color scheme for comparison"
control only offered two fixed choices ("Green for increase, red for
decrease" and its reverse), bound directly to theme.colorSuccess /
theme.colorError with no room for a brand-specific color.

Replace it with two ColorPickerControls, `increase_color` and
`decrease_color` (defaulting to the 'Green' / 'Red' semantic tokens,
matching the historical default), using the same resolveThemeTokens +
outputFormat="hex" pattern #42053 introduced for
FormattingPopoverContent: picking the "Green"/"Red" preset swatch
stores the token name (so the UI still reads the same as before for
users who just want the classic behavior), while any other pick stores
a literal hex color.

`increaseColor`/`decreaseColor` and the color->style resolution move
to two small, independently unit-tested pure functions in utils.ts
(`resolveComparisonColorKeys`, `getComparisonColorTokens`) rather than
living inline in PopKPI's render body, since jsdom doesn't reliably
expose emotion's injected styles to `toHaveStyle` for direct
component-level assertions.

Backward compatibility: `resolveComparisonColorKeys` falls back to the
legacy `comparisonColorScheme` field (still read, marked @deprecated in
types.ts) whenever the new fields are absent, including correctly
reversing increase/decrease for charts saved with the old "Red for
increase, green for decrease" choice -- the case a naive
default-to-Green migration would have silently broken.

Also exports `SPECIAL_COLORS/SpecialColorKey` from ColorPickerControl
so other call sites (like this one) don't need to redefine the
Green/Red semantic color mapping.
The admin Theme editor (ThemeModal) only exposed antd theming as a
single JSON textarea, requiring admins to paste in a whole token
object generated by an external tool just to change, say, the brand
color.

Add a "Colors" section (ThemeColorPickers) above the JSON textarea
with one ColorPickerControl per curated antd token: the 5 SEED colors
(colorPrimary, colorSuccess, colorWarning, colorError, colorInfo) plus
6 load-bearing map/alias tokens (colorLink, colorText,
colorTextSecondary, colorBgBase, colorBgContainer, colorBorder). This
intentionally does not attempt to cover the full 100+ token surface --
anything else stays fully editable via the JSON textarea, which
remains the source of truth. Token names are taken directly from
antd's own SeedToken/MapToken types, not invented.

Sync is two-way and implemented as two small, independently tested
pure functions (`tryParseThemeJson`, `patchThemeJsonToken`):
- Picker -> JSON: patches just that one key into the JSON's `token`
  object and re-serializes with the same 2-space indent used
  elsewhere in this modal, preserving every other key (curated or
  not) and their values.
- JSON -> pickers: each render re-parses the JSON textarea's current
  value and re-derives picker values from it, so typing in the
  textarea updates the matching swatches live.
- Invalid/mid-edit JSON: `tryParseThemeJson` returns null instead of
  throwing (matching the file's existing `isValidJson` convention);
  the section shows a small notice and pickers stop persisting edits
  until the JSON is valid again, rather than crashing or silently
  clobbering the textarea.

The section is hidden for read-only system themes, matching the
existing Format/Apply button visibility, and both directions of sync,
invalid-JSON handling, and "uncurated token survives a picker edit"
are covered in ThemeColorPickers.test.tsx (unit) and ThemeModal.test.tsx
(integration).
@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.40994% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.48%. Comparing base (3872790) to head (7546cfe).

Files with missing lines Patch % Lines
...s/plugin-chart-echarts/src/Bullet/controlPanel.tsx 0.00% 3 Missing ⚠️
...ns/plugin-chart-echarts/src/Gauge/controlPanel.tsx 0.00% 2 Missing ⚠️
...omponents/controls/IntervalColorsControl/index.tsx 95.00% 2 Missing ⚠️
...igNumber/BigNumberPeriodOverPeriod/controlPanel.ts 0.00% 1 Missing ⚠️
...s/plugin-chart-echarts/src/Gauge/transformProps.ts 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #42910      +/-   ##
==========================================
+ Coverage   66.40%   66.48%   +0.08%     
==========================================
  Files        2857     2860       +3     
  Lines      161293   161434     +141     
  Branches    37134    37174      +40     
==========================================
+ Hits       107114   107337     +223     
+ Misses      52153    52071      -82     
  Partials     2026     2026              
Flag Coverage Δ
javascript 73.38% <94.40%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants