You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by en...@apache.org on 2026/08/27 13:13:08 UTC
(superset) 17/46: fix(dashboard-v2): collapse the per-series styling section into an overrides list
This is an automated email from the ASF dual-hosted git repository.
EnxDev pushed a commit to branch enxdev/poc/dashboard-v2-editing-ui-flow
in repository https://gitbox.apache.org/repos/asf/superset.git
commit dbd40fda467827f94dceedd7fcd0226a45df7b0f
Author: Enzo Martellucci <en...@gmail.com>
AuthorDate: Wed Aug 26 12:30:13 2026 +0200
fix(dashboard-v2): collapse the per-series styling section into an overrides list
An x-dynamic series field (Balloons' customize.series) rendered one
always-expanded group per possible entry via the upstream JsonForms
object/group renderer — 96 entries for a real grouping column grew the
Properties panel to 24,000+ px and overflowed the rail horizontally.
Add a dedicated x-dynamic renderer: collapsed by default, showing only
entries actually customized (present in data, since JsonForms never
writes a key until it's touched) plus a picker to add one more. Also
covers the field's empty state (no dimension grouped yet) with an
explanatory line instead of two headings over nothing.
Impeccable critique: docs/../.impeccable/critique (gitignored) — action
1 of 4 from the P0/P1 recommended-actions list.
---
.gitignore | 1 +
.../DashboardBuilderV2/SchemaControlPanel.test.tsx | 179 ++++++++++++++++++
.../schemaControlRenderers.test.tsx | 22 +++
.../DashboardBuilderV2/schemaControlRenderers.tsx | 209 +++++++++++++++++++++
4 files changed, 411 insertions(+)
diff --git a/.gitignore b/.gitignore
index 52ec4a2cef4..854948d4409 100644
--- a/.gitignore
+++ b/.gitignore
@@ -144,3 +144,4 @@ oxc-custom-build/
*.duckdb
.superpowers/
.playwright-mcp/
+.impeccable/
diff --git a/superset-frontend/src/pages/DashboardBuilderV2/SchemaControlPanel.test.tsx b/superset-frontend/src/pages/DashboardBuilderV2/SchemaControlPanel.test.tsx
index 51bd991a3ac..006ca0ea5cf 100644
--- a/superset-frontend/src/pages/DashboardBuilderV2/SchemaControlPanel.test.tsx
+++ b/superset-frontend/src/pages/DashboardBuilderV2/SchemaControlPanel.test.tsx
@@ -667,3 +667,182 @@ test('the real balloons schema shape (dataBinding nested under $defs) renders pi
expect(provider.getNode(id)?.props?.colorDimension).toBe('gender'),
);
});
+
+// `Customization.series`, shaped the way the backend's `enrich_schema` leaves
+// it once a grouping dimension has real, discovered values: a fixed set of
+// per-value sub-schemas (a title and a palette-defaulted `color`), each with
+// `x-dynamic` living on the parent `series` field rather than on any one
+// entry.
+const seriesSchema = (properties: Record<string, unknown>) => ({
+ type: 'object',
+ properties: {
+ customize: { $ref: '#/$defs/Customization' },
+ },
+ $defs: {
+ Customization: {
+ type: 'object',
+ properties: {
+ series: {
+ type: 'object',
+ title: 'Per-series styling',
+ 'x-dynamic': true,
+ properties,
+ },
+ },
+ },
+ },
+});
+
+const BOY_GIRL_PROPERTIES = {
+ boy: {
+ type: 'object',
+ title: 'boy',
+ properties: {
+ color: {
+ type: 'string',
+ title: 'Color',
+ default: '#e74c3c',
+ 'x-control': 'color',
+ },
+ sizeScale: {
+ type: 'number',
+ title: 'Size scale (×)',
+ default: 1,
+ minimum: 0.25,
+ maximum: 4,
+ },
+ },
+ },
+ girl: {
+ type: 'object',
+ title: 'girl',
+ properties: {
+ color: {
+ type: 'string',
+ title: 'Color',
+ default: '#3498db',
+ 'x-control': 'color',
+ },
+ sizeScale: {
+ type: 'number',
+ title: 'Size scale (×)',
+ default: 1,
+ minimum: 0.25,
+ maximum: 4,
+ },
+ },
+ },
+};
+
+test('an x-dynamic series field with no discovered series yet explains why, instead of an empty group', async () => {
+ postSpy.mockResolvedValue({
+ json: { result: seriesSchema({}) },
+ } as never);
+
+ mount('balloons', {});
+
+ expect(
+ await screen.findByText(
+ 'Group by a dimension to enable per-series styling.',
+ ),
+ ).toBeInTheDocument();
+});
+
+test('a populated x-dynamic series field renders collapsed with a customized count, not one group per entry', async () => {
+ postSpy.mockResolvedValue({
+ json: { result: seriesSchema(BOY_GIRL_PROPERTIES) },
+ } as never);
+
+ mount('balloons', {});
+
+ expect(
+ await screen.findByText('2 series · 0 customized'),
+ ).toBeInTheDocument();
+ // Collapsed: neither series' own controls are in the document yet.
+ expect(screen.queryByLabelText('boy size scale')).not.toBeInTheDocument();
+ expect(screen.queryByLabelText('girl size scale')).not.toBeInTheDocument();
+});
+
+test('picking a series from the overrides picker writes its palette-defaulted style back', async () => {
+ postSpy.mockResolvedValue({
+ json: { result: seriesSchema(BOY_GIRL_PROPERTIES) },
+ } as never);
+
+ const id = mount('balloons', {});
+
+ await userEvent.click(await screen.findByText('2 series · 0 customized'));
+ await selectOption('girl', 'Add Per-series styling override');
+
+ await waitFor(() =>
+ expect(
+ (provider.getNode(id)?.props?.customize as Record<string, unknown>)
+ ?.series,
+ ).toEqual({ girl: { color: '#3498db', sizeScale: 1 } }),
+ );
+ expect(
+ await screen.findByText('2 series · 1 customized'),
+ ).toBeInTheDocument();
+ // Picked once, it's no longer offered a second time.
+ expect(
+ screen.queryByRole('option', { name: 'girl' }),
+ ).not.toBeInTheDocument();
+});
+
+test('resetting a customized series removes it from customize.series entirely', async () => {
+ postSpy.mockResolvedValue({
+ json: { result: seriesSchema(BOY_GIRL_PROPERTIES) },
+ } as never);
+
+ const id = mount('balloons', {
+ customize: { series: { boy: { color: '#123456', sizeScale: 2 } } },
+ });
+
+ await userEvent.click(await screen.findByText('2 series · 1 customized'));
+ await userEvent.click(await screen.findByLabelText('Reset boy to default'));
+
+ await waitFor(() =>
+ expect(
+ (provider.getNode(id)?.props?.customize as Record<string, unknown>)
+ ?.series,
+ ).toEqual({}),
+ );
+ expect(
+ await screen.findByText('2 series · 0 customized'),
+ ).toBeInTheDocument();
+});
+
+test('editing a customized series size scale writes the new value back', async () => {
+ postSpy.mockResolvedValue({
+ json: { result: seriesSchema(BOY_GIRL_PROPERTIES) },
+ } as never);
+
+ const id = mount('balloons', {
+ customize: { series: { boy: { color: '#e74c3c', sizeScale: 1 } } },
+ });
+
+ await userEvent.click(await screen.findByText('2 series · 1 customized'));
+ const sizeInput = await screen.findByLabelText('boy size scale');
+ await userEvent.clear(sizeInput);
+ await userEvent.type(sizeInput, '2.5');
+ await userEvent.tab();
+
+ await waitFor(() =>
+ expect(
+ (provider.getNode(id)?.props?.customize as Record<string, unknown>)
+ ?.series,
+ ).toEqual({ boy: { color: '#e74c3c', sizeScale: 2.5 } }),
+ );
+});
+
+test('a customized series exposes an accessibly-labeled color trigger', async () => {
+ postSpy.mockResolvedValue({
+ json: { result: seriesSchema(BOY_GIRL_PROPERTIES) },
+ } as never);
+
+ mount('balloons', {
+ customize: { series: { boy: { color: '#e74c3c', sizeScale: 1 } } },
+ });
+
+ await userEvent.click(await screen.findByText('2 series · 1 customized'));
+ expect(await screen.findByLabelText('boy color')).toBeInTheDocument();
+});
diff --git a/superset-frontend/src/pages/DashboardBuilderV2/schemaControlRenderers.test.tsx b/superset-frontend/src/pages/DashboardBuilderV2/schemaControlRenderers.test.tsx
index 08102106f41..696d7ab11ea 100644
--- a/superset-frontend/src/pages/DashboardBuilderV2/schemaControlRenderers.test.tsx
+++ b/superset-frontend/src/pages/DashboardBuilderV2/schemaControlRenderers.test.tsx
@@ -21,6 +21,7 @@ import {
hasAdvancedMetric,
metricOptions,
resolveDatasetPick,
+ seriesDefaults,
toDatasetSelectValue,
} from './schemaControlRenderers';
@@ -133,3 +134,24 @@ test('resolveDatasetPick rejects a semantic view — datasetId has no way to rep
test('resolveDatasetPick passes undefined through (nothing picked)', () => {
expect(resolveDatasetPick(undefined)).toBeUndefined();
});
+
+test("seriesDefaults reads a not-yet-customized entry's own palette-defaulted color and size", () => {
+ expect(
+ seriesDefaults(
+ {
+ properties: {
+ color: { default: '#3498db' },
+ sizeScale: { default: 1 },
+ },
+ },
+ '#000000',
+ ),
+ ).toEqual({ color: '#3498db', sizeScale: 1 });
+});
+
+test('seriesDefaults falls back to the given color when an entry schema is missing its own defaults', () => {
+ expect(seriesDefaults(undefined, '#123456')).toEqual({
+ color: '#123456',
+ sizeScale: 1,
+ });
+});
diff --git a/superset-frontend/src/pages/DashboardBuilderV2/schemaControlRenderers.tsx b/superset-frontend/src/pages/DashboardBuilderV2/schemaControlRenderers.tsx
index bb8339aa18e..1ef99d7d4f8 100644
--- a/superset-frontend/src/pages/DashboardBuilderV2/schemaControlRenderers.tsx
+++ b/superset-frontend/src/pages/DashboardBuilderV2/schemaControlRenderers.tsx
@@ -29,6 +29,10 @@
* Matched by property name rather than an `x-control` hint — the
* backend's `DataBinding` schema is unchanged, so this is the one
* control here selected structurally instead of by a declared extra.
+ * - `x-dynamic: true` (any object field so declared) → an "overrides" list:
+ * collapsed by default, showing only the entries actually customized,
+ * plus a picker to add one more — rather than the upstream JsonForms
+ * renderer's one always-expanded group per possible entry.
*
* `code` and `color` fall back to the field's schema `default`, since
* JsonForms does not write defaults into the data until a field is touched.
@@ -49,9 +53,12 @@ import { FeatureFlag, isFeatureEnabled } from '@superset-ui/core';
import {
AsyncSelect,
Button,
+ ColorPicker,
+ Collapse,
Flex,
Form,
Input,
+ InputNumber,
Select,
Typography,
} from '@superset-ui/core/components';
@@ -76,6 +83,11 @@ const xControlIs = (value: string) =>
(schema as Record<string, unknown>)['x-control'] === value,
);
+const isDynamicSeries = schemaMatches(
+ (schema: JsonSchema) =>
+ (schema as Record<string, unknown>)['x-dynamic'] === true,
+);
+
/** Raw JSON editor for an `x-control: code` field. */
function CodeControl({
data,
@@ -143,6 +155,199 @@ function ColorControl({
);
}
+interface SeriesEntrySchema {
+ properties?: {
+ color?: { default?: string };
+ sizeScale?: { default?: number; minimum?: number; maximum?: number };
+ };
+}
+
+interface SeriesMapSchema {
+ properties?: Record<string, SeriesEntrySchema>;
+}
+
+interface SeriesStyleValue {
+ color: string;
+ sizeScale: number;
+}
+
+/** The value a not-yet-customized series entry starts from, read off its
+ * own enriched sub-schema (the backend pre-colors each entry from a
+ * palette) rather than one fixed default shared by every series. Falls
+ * back to `fallbackColor` only for an entry the backend never colored —
+ * not expected to happen, but a theme token beats a literal black. */
+export function seriesDefaults(
+ entrySchema: SeriesEntrySchema | undefined,
+ fallbackColor: string,
+): SeriesStyleValue {
+ return {
+ color: entrySchema?.properties?.color?.default ?? fallbackColor,
+ sizeScale: entrySchema?.properties?.sizeScale?.default ?? 1,
+ };
+}
+
+/**
+ * `x-dynamic: true` on a dict-of-objects field (e.g. Balloons'
+ * `customize.series`, one entry per distinct color-dimension value): an
+ * overrides list, collapsed by default, rather than the upstream renderer's
+ * one always-expanded group per possible entry — which turns a real
+ * grouping column into thousands of pixels of identical, unstyled controls.
+ *
+ * The backend enriches this field's schema with one inlined per-value
+ * sub-schema (a title and a palette-defaulted `color`), but leaves the
+ * *data* untouched until an author actually edits a value — so "has an
+ * entry in `data`" already means "has been customized", with no comparison
+ * against the schema's own defaults needed.
+ */
+function SeriesOverridesControl(props: ControlProps): ReactElement {
+ const { data, handleChange, path, schema, label } = props;
+ const theme = useTheme();
+ const seriesSchema = schema as SeriesMapSchema;
+ const keys = useMemo(
+ () => Object.keys(seriesSchema.properties ?? {}),
+ [seriesSchema],
+ );
+ const values = (data ?? {}) as Record<string, SeriesStyleValue>;
+ const customizedKeys = keys.filter(key => values[key] !== undefined);
+ const availableKeys = keys.filter(key => values[key] === undefined);
+
+ if (keys.length === 0) {
+ return (
+ <Form.Item label={label}>
+ <Typography.Text type="secondary">
+ {t('Group by a dimension to enable per-series styling.')}
+ </Typography.Text>
+ </Form.Item>
+ );
+ }
+
+ const write = (next: Record<string, SeriesStyleValue>) =>
+ handleChange(path, next);
+
+ const removeOverride = (key: string) => {
+ const next = { ...values };
+ delete next[key];
+ write(next);
+ };
+
+ const addOverride = (key: string) => {
+ write({
+ ...values,
+ [key]: seriesDefaults(seriesSchema.properties?.[key], theme.colorText),
+ });
+ };
+
+ return (
+ <Form.Item label={label}>
+ <Collapse
+ ghost
+ size="small"
+ items={[
+ {
+ key: 'series-overrides',
+ label: t(
+ '%s series · %s customized',
+ keys.length,
+ customizedKeys.length,
+ ),
+ children: (
+ <Flex vertical gap="small">
+ {customizedKeys.map(key => {
+ const value = values[key];
+ const bounds =
+ seriesSchema.properties?.[key]?.properties?.sizeScale;
+ return (
+ <Flex key={key} align="center" gap="small">
+ <ColorPicker
+ value={value.color}
+ onChange={next =>
+ write({
+ ...values,
+ [key]: { ...value, color: next.toHexString() },
+ })
+ }
+ >
+ <button
+ type="button"
+ aria-label={t('%s color', key)}
+ style={{
+ width: 20,
+ height: 20,
+ borderRadius: 4,
+ border: '1px solid rgba(0, 0, 0, 0.15)',
+ background: value.color,
+ cursor: 'pointer',
+ padding: 0,
+ }}
+ />
+ </ColorPicker>
+ <div
+ style={{
+ flex: 1,
+ minWidth: 0,
+ whiteSpace: 'nowrap',
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ }}
+ >
+ {key}
+ </div>
+ <InputNumber
+ size="small"
+ aria-label={t('%s size scale', key)}
+ value={value.sizeScale}
+ min={bounds?.minimum ?? 0.25}
+ max={bounds?.maximum ?? 4}
+ step={0.25}
+ style={{ width: 64 }}
+ onChange={next =>
+ write({
+ ...values,
+ [key]: {
+ ...value,
+ sizeScale: typeof next === 'number' ? next : 1,
+ },
+ })
+ }
+ />
+ <Button
+ buttonSize="xsmall"
+ buttonStyle="link"
+ aria-label={t('Reset %s to default', key)}
+ icon={<Icons.CloseOutlined iconSize="s" />}
+ onClick={() => removeOverride(key)}
+ />
+ </Flex>
+ );
+ })}
+ {availableKeys.length > 0 && (
+ // Remounted on every pick: rc-select otherwise keeps
+ // showing the just-picked option's label internally even
+ // once it's gone from `options` (a controlled `value` of
+ // `null`/`undefined` doesn't clear that cache on its own —
+ // see `ReferenceMultiList`'s identical, pre-existing gap).
+ <Select
+ key={availableKeys.length}
+ value={null}
+ placeholder={t('Add a series override…')}
+ ariaLabel={t('Add %s override', label)}
+ options={availableKeys.map(key => ({
+ value: key,
+ label: key,
+ }))}
+ onChange={next => addOverride(next as string)}
+ css={{ width: '100%' }}
+ />
+ )}
+ </Flex>
+ ),
+ },
+ ]}
+ />
+ </Form.Item>
+ );
+}
+
/**
* The dataset id a column/metric-reference control resolves options
* against. A JsonForms control only sees its own field's data by default —
@@ -622,6 +827,10 @@ export const schemaControlRenderers = [
tester: rankWith(1000, xControlIs('color')),
renderer: withJsonFormsControlProps(ColorControl),
},
+ {
+ tester: rankWith(1000, isDynamicSeries),
+ renderer: withJsonFormsControlProps(SeriesOverridesControl),
+ },
{
tester: rankWith(1000, xControlIs('column')),
renderer: withJsonFormsControlProps(ColumnControl),