Skip to content

Commit 6a4d08a

Browse files
committed
fix(app-shell): both dashboard widget-type pickers read one registry derived from the spec
The Add-widget menu (11 types) and the widget inspector's Type select (10 types) kept their own hand-written lists while ChartTypeSchema accepts 20, every one of which the dashboard draws. widget-types.ts now takes the offered set from ChartTypeSchema.options and keeps only per-type presentation, checked against ChartType with `satisfies`; the Type select derives its options from the same registry. The nine newly offered types get their names in the studio namespace (en + zh), and the widget dataset hint stops naming the removed inline object query. Claude-Session: https://claude.ai/code/session_01JQwxbafngYyQTJq78seG4v Co-authored-by: Claude <noreply@anthropic.com>
1 parent aa00362 commit 6a4d08a

8 files changed

Lines changed: 339 additions & 76 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/i18n': patch
3+
---
4+
5+
fix(app-shell): the dashboard's Add-widget menu and the widget Type select offer every widget type the spec accepts, from one registry
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Studio's two dashboard widget-type pickers kept their own lists and disagreed with each other and with the spec: the Add-widget menu offered 11 types, the inspector's Type select 10 (no `scatter`), and `ChartTypeSchema` accepts 20, all of which a dashboard draws. Both pickers now read one registry derived from `ChartTypeSchema`, so they offer the same 20 types and follow the spec when it changes.
11+
12+
- The `studio` namespace gains the names of the newly offered types: `engine.inspector.widget.type.*` for `column`, `scatter`, `treemap`, `sankey`, `combo`, `gauge`, `solidGauge`, `kpi`, `bullet` and `radar`, and `engine.widgetPicker.type.*` for the same types except `scatter`, in en and zh.
13+
- `engine.inspector.widget.datasetHint` no longer mentions an "inline object query above", which the widget inspector has not had since ADR-0021; it describes the dataset, dimension and measure controls the inspector shows.

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/DashboardWidgetInspector.tsx‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,35 +50,27 @@ import {
5050
import { useDatasetCatalog, useDatasetSemantics } from '../previews/useDatasetCatalog.js';
5151
import type { ObjectFieldInfo } from '../previews/useObjectFields.js';
5252
import { widgetMissingInputs } from '../../studio-design/metadataError.js';
53+
import { WIDGET_TYPE_IDS, WIDGET_TYPE_META } from '../previews/widget-types.js';
5354

5455
// ADR-0021: dashboard widgets author the semantic-layer dataset shape only
5556
// (dataset + dimensions + values). The pre-ADR-0021 inline single-object query
5657
// (object / valueField / categoryField / aggregate) was removed from the spec
5758
// at @objectstack/spec 9.0.0 and is no longer authored here — its fields are
5859
// gone so no Studio surface can emit the dead shape (framework#3251).
5960
/**
60-
* The widget families this inspector offers. TYPED to `DashboardWidgetTypeName`
61-
* (objectui#4600, which closed the widget `type` vocabulary) so the inspector
62-
* cannot offer a type validation refuses — every entry here is a spec
63-
* visualization family. A hand-written SUBSET is fine; offering something
64-
* outside the vocabulary is not.
61+
* The widget families this inspector's Type select offers: the ONE registry
62+
* the Add-widget menu reads too (`../previews/widget-types`, objectstack#26745),
63+
* which derives the set from the spec's `ChartTypeSchema` instead of keeping a
64+
* list here. The two pickers used to keep their own lists and disagreed (10
65+
* here, 11 in the menu, 20 in the spec). ⛔ No hand-kept list in this file.
6566
*
6667
* Each label is a catalogue key, resolved in the designer locale at render
6768
* (objectui#10748, the objectui#10586 `KeyedOption` shape); the stored `value`
6869
* never moves.
6970
*/
70-
const WIDGET_TYPES: ReadonlyArray<{ value: DashboardWidgetTypeName; labelKey: string }> = [
71-
{ value: 'metric', labelKey: 'engine.inspector.widget.type.metric' },
72-
{ value: 'bar', labelKey: 'engine.inspector.widget.type.bar' },
73-
{ value: 'horizontal-bar', labelKey: 'engine.inspector.widget.type.horizontalBar' },
74-
{ value: 'line', labelKey: 'engine.inspector.widget.type.line' },
75-
{ value: 'area', labelKey: 'engine.inspector.widget.type.area' },
76-
{ value: 'pie', labelKey: 'engine.inspector.widget.type.pie' },
77-
{ value: 'donut', labelKey: 'engine.inspector.widget.type.donut' },
78-
{ value: 'funnel', labelKey: 'engine.inspector.widget.type.funnel' },
79-
{ value: 'table', labelKey: 'engine.inspector.widget.type.table' },
80-
{ value: 'pivot', labelKey: 'engine.inspector.widget.type.pivot' },
81-
];
71+
const WIDGET_TYPES: ReadonlyArray<{ value: DashboardWidgetTypeName; labelKey: string }> = WIDGET_TYPE_IDS.map(
72+
(id) => ({ value: id, labelKey: WIDGET_TYPE_META[id].selectLabelKey }),
73+
);
8274

8375
const COLORS = [
8476
'default',

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/inspectorStrings.i18n-10748.test.tsx‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import { ObjectFieldInspector } from './ObjectFieldInspector';
7878
import { FlowEdgeInspector } from './FlowEdgeInspector';
7979
import { FlowNodeInspector } from './FlowNodeInspector';
8080
import { encodeNestedNodeId, NESTED_NODE_KIND } from './flow-nested-selection';
81+
import { WIDGET_TYPE_META } from '../previews/widget-types';
8182
// The designer's `designer.*` / `perm.*` rows live in `@object-ui/i18n`'s `studio`
8283
// namespace, whose `zh` catalogue is fetched on demand (objectstack#25922).
8384
// Resident before any case, so the zh rows below read synchronously.
@@ -139,19 +140,14 @@ function mountWidget(lang: Lang, draft: Record<string, unknown>, selection: { ki
139140
));
140141
}
141142

142-
/** Stored widget `type` → the row its option label reads. */
143-
const WIDGET_TYPE_KEYS: ReadonlyArray<[string, string]> = [
144-
['metric', 'engine.inspector.widget.type.metric'],
145-
['bar', 'engine.inspector.widget.type.bar'],
146-
['horizontal-bar', 'engine.inspector.widget.type.horizontalBar'],
147-
['line', 'engine.inspector.widget.type.line'],
148-
['area', 'engine.inspector.widget.type.area'],
149-
['pie', 'engine.inspector.widget.type.pie'],
150-
['donut', 'engine.inspector.widget.type.donut'],
151-
['funnel', 'engine.inspector.widget.type.funnel'],
152-
['table', 'engine.inspector.widget.type.table'],
153-
['pivot', 'engine.inspector.widget.type.pivot'],
154-
];
143+
/**
144+
* Stored widget `type` → the row its option label reads — read off the one
145+
* widget registry the select derives its options from (objectstack#26745).
146+
*/
147+
const WIDGET_TYPE_KEYS: ReadonlyArray<[string, string]> = Object.values(WIDGET_TYPE_META).map((m) => [
148+
m.id,
149+
m.selectLabelKey,
150+
]);
155151

156152
/** The widget-type select's trigger text, for a widget stored with `type`. */
157153
function widgetTypeTrigger(lang: Lang, type: string): string | null {

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/inspectorStrings.i18n-10804.test.tsx‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -383,20 +383,12 @@ describe('the Problems panel — expression messages (objectui#10804)', () => {
383383

384384
// ─── Site 4: the dashboard add-widget picker (objectui#10805) ────────────────
385385

386-
/** Stored `type` → the catalogue row its picker entry displays. */
387-
const WIDGET_TYPE_KEYS: ReadonlyArray<[string, string]> = [
388-
['metric', 'engine.widgetPicker.type.metric'],
389-
['bar', 'engine.widgetPicker.type.bar'],
390-
['horizontal-bar', 'engine.widgetPicker.type.horizontalBar'],
391-
['line', 'engine.widgetPicker.type.line'],
392-
['area', 'engine.widgetPicker.type.area'],
393-
['pie', 'engine.widgetPicker.type.pie'],
394-
['donut', 'engine.widgetPicker.type.donut'],
395-
['scatter', 'engine.widgetPicker.type.scatter'],
396-
['funnel', 'engine.widgetPicker.type.funnel'],
397-
['table', 'engine.widgetPicker.type.table'],
398-
['pivot', 'engine.widgetPicker.type.pivot'],
399-
];
386+
/**
387+
* Stored `type` → the catalogue row its picker entry displays — read off the
388+
* one widget registry (objectstack#26745), which derives the offered set from
389+
* the spec, so this suite covers every type the picker offers.
390+
*/
391+
const WIDGET_TYPE_KEYS: ReadonlyArray<[string, string]> = Object.values(WIDGET_TYPE_META).map((m) => [m.id, m.labelKey]);
400392
const CATEGORIES = ['kpi', 'chart', 'data'] as const;
401393

402394
/** Mount the dashboard inspector with no widgets and open its add-widget picker. */
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#26745 — the dashboard's two widget-type pickers read ONE registry
5+
* of the renderable spec types.
6+
*
7+
* Measured on `main` before this change: the designer's Add-widget menu offered
8+
* 11 types, the widget inspector's Type select 10 (no `scatter`), and the spec's
9+
* `ChartTypeSchema` accepts 20 — every one of which the dashboard draws when
10+
* written through the API. Each picker kept its own hand-written list.
11+
*
12+
* Pinned here, each through the rendered control:
13+
* - the registry IS the spec vocabulary (`WIDGET_TYPE_IDS` = `ChartTypeSchema`);
14+
* - the Add menu offers exactly that set, and so does the Type select;
15+
* - every offered type renders through the real `DashboardRenderer` — no
16+
* "not supported yet" placeholder, no red unknown-component panel;
17+
* - every offered type has its two names in both catalogues (en + zh).
18+
*/
19+
20+
import '@testing-library/jest-dom/vitest';
21+
import * as React from 'react';
22+
import { afterEach, describe, expect, it, vi } from 'vitest';
23+
import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
24+
import { ChartTypeSchema } from '@objectstack/spec/ui';
25+
import { enumOptions } from '@object-ui/test-support';
26+
// Module-scope import of the lazily loaded renderer, so the preview's
27+
// `React.lazy` factory resolves at once instead of racing the test's wait
28+
// window (AGENTS.md, flaky-test discipline).
29+
import '@object-ui/plugin-dashboard';
30+
31+
vi.mock('@object-ui/react', async (importOriginal) => {
32+
const mod = await importOriginal<typeof import('@object-ui/react')>();
33+
return { ...mod, useAdapter: () => ({}) };
34+
});
35+
// Network-free dataset catalog for the widget inspector.
36+
vi.mock('./useDatasetCatalog', () => ({
37+
useDatasetCatalog: () => ({ datasets: [], loading: false, error: null }),
38+
useDatasetSemantics: () => ({ dimensions: [], measures: [], loading: false, error: null }),
39+
}));
40+
41+
import { t } from '../i18n';
42+
import { WIDGET_TYPE_IDS, WIDGET_TYPE_META } from './widget-types';
43+
import { DashboardPreview } from './DashboardPreview';
44+
import { DashboardDefaultInspector } from '../inspectors/DashboardDefaultInspector';
45+
import { DashboardWidgetInspector } from '../inspectors/DashboardWidgetInspector';
46+
// The `engine.inspector.*` rows live in `@object-ui/i18n`'s `studio` namespace,
47+
// whose `zh` catalogue is fetched on demand (objectstack#25922). Resident before
48+
// any case, so the zh rows below read synchronously.
49+
import { loadStudioCatalogue } from '@object-ui/i18n/namespaces/studio';
50+
await loadStudioCatalogue('zh');
51+
52+
// Radix Select reads pointer capture, which jsdom does not implement.
53+
for (const m of ['hasPointerCapture', 'setPointerCapture', 'releasePointerCapture'] as const) {
54+
if (!(m in Element.prototype)) {
55+
(Element.prototype as unknown as Record<string, unknown>)[m] = m === 'hasPointerCapture' ? () => false : () => {};
56+
}
57+
}
58+
if (!Element.prototype.scrollIntoView) Element.prototype.scrollIntoView = () => {};
59+
60+
afterEach(cleanup);
61+
62+
const specTypes: string[] = enumOptions(ChartTypeSchema);
63+
64+
async function flush() {
65+
await act(async () => {
66+
await new Promise((r) => setTimeout(r, 0));
67+
});
68+
}
69+
70+
/** The stored types the Add-widget menu lists, read off its rendered entries. */
71+
async function addMenuTypes(): Promise<string[]> {
72+
render(
73+
<DashboardDefaultInspector
74+
type="dashboard"
75+
name="sales"
76+
locale="en-US"
77+
draft={{ name: 'sales', label: 'Sales', widgets: [] }}
78+
onPatch={() => {}}
79+
onSelectionChange={() => {}}
80+
readOnly={false}
81+
/>,
82+
);
83+
fireEvent.click(screen.getByRole('button', { name: t('engine.inspector.add.widget', 'en-US') }));
84+
await flush();
85+
const picker = screen.getByRole('dialog');
86+
return Array.from(picker.querySelectorAll('button code')).map((c) => c.textContent ?? '');
87+
}
88+
89+
/** The option names the widget inspector's Type select lists. */
90+
async function typeSelectOptions(): Promise<string[]> {
91+
render(
92+
<DashboardWidgetInspector
93+
type="dashboard"
94+
name="sales"
95+
locale="en-US"
96+
draft={{ widgets: [{ id: 'w1', type: 'bar', title: 'Revenue' }] }}
97+
selection={{ kind: 'widget', id: 'w1' }}
98+
onPatch={() => {}}
99+
onClearSelection={() => {}}
100+
onSelectionChange={() => {}}
101+
readOnly={false}
102+
/>,
103+
);
104+
fireEvent.keyDown(document.getElementById('widget-type')!, { key: 'ArrowDown' });
105+
const listbox = await screen.findByRole('listbox');
106+
return within(listbox)
107+
.getAllByRole('option')
108+
.map((o) => o.textContent ?? '');
109+
}
110+
111+
describe('one widget-type registry, derived from the spec (objectstack#26745)', () => {
112+
it('reads a non-empty enum from the spec', () => {
113+
expect(specTypes, 'could not read ChartTypeSchema.options from the spec').not.toEqual([]);
114+
});
115+
116+
it('the registry is the spec vocabulary, in the spec order', () => {
117+
expect([...WIDGET_TYPE_IDS]).toEqual(specTypes);
118+
expect(Object.keys(WIDGET_TYPE_META).sort()).toEqual([...specTypes].sort());
119+
});
120+
121+
it('the Add-widget menu offers exactly the spec types', async () => {
122+
expect((await addMenuTypes()).sort()).toEqual([...specTypes].sort());
123+
});
124+
125+
it('the Type select offers exactly the spec types, named from the same registry', async () => {
126+
expect(await typeSelectOptions()).toEqual(
127+
specTypes.map((id) => t(WIDGET_TYPE_META[id].selectLabelKey, 'en-US')),
128+
);
129+
});
130+
131+
it('every offered type renders through the real DashboardRenderer — no placeholder, no red panel', async () => {
132+
const widgets = WIDGET_TYPE_IDS.map((type, i) => ({
133+
id: `w_${i}`,
134+
type,
135+
title: `Widget ${type}`,
136+
layout: { x: (i % 4) * 3, y: Math.floor(i / 4) * 2, w: 3, h: 2 },
137+
}));
138+
const { container } = render(
139+
<DashboardPreview
140+
type="dashboard"
141+
name="all_types"
142+
draft={{ name: 'all_types', label: 'All types', widgets }}
143+
editing={false}
144+
selection={null}
145+
onSelectionChange={() => {}}
146+
onPatch={() => {}}
147+
locale="en-US"
148+
/>,
149+
);
150+
await waitFor(() => {
151+
const cells = container.querySelectorAll('[style*="grid-column"]');
152+
if (cells.length !== widgets.length) throw new Error(`expected ${widgets.length} widget cells, saw ${cells.length}`);
153+
});
154+
expect(container.textContent).not.toMatch(/chart type is not supported yet/);
155+
expect(container.textContent).not.toMatch(/Unknown component type/);
156+
});
157+
158+
it('every offered type has its Add-menu name and its Type-select name in en and zh', () => {
159+
for (const meta of Object.values(WIDGET_TYPE_META)) {
160+
for (const key of [meta.labelKey, meta.selectLabelKey]) {
161+
expect(t(key, 'en-US'), `${key}: missing en row`).not.toBe(key);
162+
// A missing zh row reads the en one back.
163+
expect(t(key, 'zh-CN'), `${key}: missing zh row`).not.toBe(t(key, 'en-US'));
164+
}
165+
// The Add menu's en name is the English the stored default title is written from.
166+
expect(t(meta.labelKey, 'en-US'), meta.id).toBe(meta.label);
167+
}
168+
});
169+
});

0 commit comments

Comments
 (0)