Skip to content

Commit 0df531f

Browse files
committed
fix(app-shell): the dashboard page's card panel reads the served title, as in Studio (#36373)
#36405 hosts DashboardWidgetInspector on the dashboard page. Wrap its edit panel in ServedWidgetTextContext, pairing the page's served dashboard with the stored document the edit opened, so the title box shows the session's language and an edit lands in that language's entry. Pinned through the real DashboardView (ablation: provider value null, the case goes red). Claude-Session: https://claude.ai/code/session_01QsR2jUP9hxdL4RzdzTs9eK Co-authored-by: Claude <noreply@anthropic.com>
1 parent 12c41f8 commit 0df531f

4 files changed

Lines changed: 47 additions & 5 deletions

File tree

‎.changeset/36373-report-panel-business-wording.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ feat(app-shell): the report and dashboard-widget panels speak business wording,
99
Clause-②: yes (widening) — the report and widget panels accept an edit of a translated name or title in the session's language, stored as the inline locale map `{ default: SOURCE, LANG: EDIT }` the spec's `I18nLabel` already allows; nothing is removed or renamed
1010
Metadata-protocol: semantic — `translateReport` and `translateDashboard` now treat a report `label`/`description` or a widget `title` as changed when its inline locale-map entry for the requested locale (the entry the panel writes: exact tag, then the locale's own script, else base tag or a sibling region; never `default`) differs from the packaged base's own, so the base's translation no longer replaces it; a translation the paired `.custom` package ships still answers first (ruling record 6631250894), and with none the entry is served; dataset members (`translateDataset`, ADR-0149) are unchanged
1111

12-
The report editor beside a report (runtime 「编辑」 and Studio) and the dashboard widget property bar now name things the way a business reader does:
12+
The report editor beside a report (runtime 「编辑」 and Studio) and the dashboard widget property bar (Studio, and the dashboard page's edit state) now name things the way a business reader does:
1313

1414
- Fields, measures and data sources show their labels in the current language; the machine name is on hover only (`title`), never printed. A measure reads `LABEL · AGGREGATE` with the aggregate in words (「金额 · 合计」, "Amount · Sum").
1515
- 「行(维度)」「维度」 read 「分组」, 「值(度量)」 reads 「指标」, 「数据集」 reads 「数据来源」 (its label alone, no `(name)` and no description), and the filter-binding section reads 「跟着页面顶部的筛选变」 with each filter by its name (「时间」 for the date range, the dimension's label for a filter with none).

‎ui/packages/app-shell/src/views/DashboardInPageEditor.tsx‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { appendArray, uniqueId } from './metadata-admin/inspectors/_shared.js';
5050
import { getDashboardForm } from './metadata-admin/dashboard-schema.js';
5151
import { useMetadataLocale, type SupportedLocale } from './metadata-admin/i18n.js';
5252
import type { MetadataSelection } from './metadata-admin/preview-registry.js';
53+
import { ServedWidgetTextContext, servedWidgetTextOf } from './studio-design/servedDashboardText.js';
5354

5455
/** Where the editor would save, as read at open (nothing is written to open). */
5556
export type WritableDashboardEditTarget = Exclude<DashboardEditTarget, { kind: 'refused' }>;
@@ -259,6 +260,12 @@ export function DashboardEditActions({
259260
* The right panel while editing: Studio's card panel for the selected card,
260261
* its dashboard panel (label, cards, filters, layout) otherwise. `revealFilters`
261262
* opens and scrolls to the filters section, the "Add filter" path.
263+
*
264+
* objectstack#36373: the panels read a card title in the session's language
265+
* through {@link ServedWidgetTextContext}, as in Studio: `served` is the page's
266+
* served dashboard, `published` the stored document the edit opened, paired
267+
* widget by widget ({@link servedWidgetTextOf}). Without the pair the title box
268+
* shows the stored source and an edit there replaces it.
262269
*/
263270
export function DashboardEditPanel({
264271
name,
@@ -268,9 +275,15 @@ export function DashboardEditPanel({
268275
onSelectionChange,
269276
revealFilters,
270277
onFiltersRevealed,
278+
served,
279+
published,
271280
}: {
272281
name: string;
273282
draft: Record<string, unknown>;
283+
/** The dashboard as the page serves it, in the session's language. */
284+
served?: Record<string, unknown> | null;
285+
/** The stored document the edit state opened, before any change. */
286+
published?: Record<string, unknown> | null;
274287
selection: MetadataSelection | null;
275288
onPatch: (patch: Record<string, unknown>) => void;
276289
onSelectionChange: (next: MetadataSelection | null) => void;
@@ -280,6 +293,7 @@ export function DashboardEditPanel({
280293
const locale = useMetadataLocale();
281294
const tt = useSafeTranslate();
282295
const ref = React.useRef<HTMLElement | null>(null);
296+
const servedWidgets = React.useMemo(() => servedWidgetTextOf(published, served), [published, served]);
283297

284298
React.useEffect(() => {
285299
if (!revealFilters || selection) return;
@@ -303,6 +317,7 @@ export function DashboardEditPanel({
303317
className="w-full shrink-0 overflow-auto border-t bg-background p-3 sm:w-80 sm:border-l sm:border-t-0"
304318
data-testid="dashboard-edit-panel"
305319
>
320+
<ServedWidgetTextContext.Provider value={servedWidgets}>
306321
{selection?.kind === 'widget' ? (
307322
<DashboardWidgetInspector
308323
type="dashboard"
@@ -326,6 +341,7 @@ export function DashboardEditPanel({
326341
locale={locale}
327342
/>
328343
)}
344+
</ServedWidgetTextContext.Provider>
329345
</aside>
330346
);
331347
}
@@ -341,6 +357,8 @@ export type DashboardEditClient = DashboardEditReader & {
341357
export interface DashboardInPageEdit {
342358
/** The document being edited, `null` outside the edit state. */
343359
draft: Record<string, unknown> | null;
360+
/** The stored document as the edit state opened it, before any change; `null` outside it. */
361+
published: Record<string, unknown> | null;
344362
opening: boolean;
345363
saving: boolean;
346364
dirty: boolean;
@@ -380,6 +398,7 @@ export function useDashboardInPageEdit({
380398
const [session, setSession] = React.useState<{
381399
target: WritableDashboardEditTarget;
382400
draft: Record<string, unknown>;
401+
published: Record<string, unknown>;
383402
dirty: boolean;
384403
} | null>(null);
385404
const [opening, setOpening] = React.useState(false);
@@ -402,7 +421,7 @@ export function useDashboardInPageEdit({
402421
try {
403422
const opened = await openDashboardForEdit(name, ownerPackageId, client, { doors, walled });
404423
if (opened.kind === 'refused') return opened;
405-
setSession({ target: opened.target, draft: opened.doc, dirty: false });
424+
setSession({ target: opened.target, draft: opened.doc, published: opened.doc, dirty: false });
406425
setSelection(null);
407426
return null;
408427
} finally {
@@ -450,6 +469,7 @@ export function useDashboardInPageEdit({
450469

451470
return {
452471
draft: session?.draft ?? null,
472+
published: session?.published ?? null,
453473
opening,
454474
saving,
455475
dirty: session?.dirty ?? false,

‎ui/packages/app-shell/src/views/DashboardView.inPageEdit-36372.test.tsx‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,21 @@ vi.mock('sonner', () => ({
8888
info: vi.fn(),
8989
},
9090
}));
91-
vi.mock('./metadata-admin/inspectors/DashboardWidgetInspector', () => ({
92-
DashboardWidgetInspector: (p: any) => <div data-testid="stub-widget-inspector">{p.selection.id}</div>,
93-
}));
91+
vi.mock('./metadata-admin/inspectors/DashboardWidgetInspector', async () => {
92+
// objectstack#36373: the stub reads the served title the real panel reads.
93+
const { useServedWidgetText } = await import('./studio-design/servedDashboardText');
94+
return {
95+
DashboardWidgetInspector: (p: any) => {
96+
const pair = useServedWidgetText()?.widgets.get(p.selection.id);
97+
return (
98+
<div data-testid="stub-widget-inspector">
99+
{p.selection.id}
100+
<span data-testid="stub-widget-served-title">{pair ? `${pair.served} ← ${pair.authored}` : 'none'}</span>
101+
</div>
102+
);
103+
},
104+
};
105+
});
94106
vi.mock('./metadata-admin/inspectors/DashboardDefaultInspector', () => ({
95107
DashboardDefaultInspector: (p: any) => (
96108
<div data-testid="stub-default-inspector">
@@ -235,6 +247,14 @@ describe('DashboardView in-page edit (objectstack#36372)', () => {
235247
expect(queryDataset.mock.calls.every((c: unknown[]) => (c[2] as { callerPackage?: string })?.callerPackage === 'crm')).toBe(true);
236248
});
237249

250+
it('the card panel reads the served title beside the stored one (objectstack#36373)', async () => {
251+
mount();
252+
await openEdit();
253+
fireEvent.click(screen.getByTestId('dashboard-preview-widget-widget_total'));
254+
// The pair the title box shows and writes by: served for the session, authored as stored.
255+
expect(screen.getByTestId('stub-widget-served-title')).toHaveTextContent('Total (served) ← Total (stored)');
256+
});
257+
238258
it('Add card appends a card and selects it', async () => {
239259
mount();
240260
await openEdit();

‎ui/packages/app-shell/src/views/DashboardView.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ export function DashboardView({ dataSource }: { dataSource?: any }) {
511511
onSelectionChange={edit.select}
512512
revealFilters={edit.revealFilters}
513513
onFiltersRevealed={edit.filtersRevealed}
514+
served={dashboard as Record<string, unknown> | undefined}
515+
published={edit.published}
514516
/>
515517
)}
516518

0 commit comments

Comments
 (0)