Skip to content

Commit f0750e0

Browse files
committed
fix(console): opening a dashboard's in-page edit writes nothing, and refuses where Studio's Customize would
Edit on an installed app's dashboard asked the ensure door at open, which creates the app's customization package on first use, so Edit then Discard left a new package behind. Opening now only reads: the pair is looked up in the package list (listedCustomizationPairOf), and the ensure door is asked at Save, the edit's first write. The edit state is also refused up front where Studio's Customize is: the ensure door walled for this caller, and a base listing no version to declare the override at (unless the item already declares one). Two things a live run showed: the not-filtered mark named the built-in date filter by its reserved name ("dateRange") instead of "Date range", and the edit state drew the stored document without the served _packageId, so its cards' dataset queries no longer named the dashboard's package as their reader. Both fixed and pinned. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUeSU9HhKxjcVsyprx
1 parent 3e7995a commit f0750e0

22 files changed

Lines changed: 349 additions & 95 deletions

‎.changeset/36372-dashboard-in-page-edit.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Metadata-protocol: none
1212

1313
A dashboard page draws an **Edit** button for a workspace admin who may author metadata, on a package Studio lists (the gate of the app's Studio entries). Edit opens the dashboard as stored (never the translated copy the page shows) in an edit state: the header says **Editing**, with **Add card**, **Discard** and **Save**; every card draws a dashed outline and can be dragged to move it, resized from its corner by whole grid tracks (or with the arrow keys on the corner handle) and clicked to select it. The panel at the right is Studio's own dashboard panels, as they stand: a selected card's (its data, its "follow page filters" switches, Remove) and otherwise the dashboard's (label, cards, filters, layout). The filter bar's **Add filter** opens the panel's Filters section. Add card appends a card at the end and selects it.
1414

15-
Save writes where Studio's Customize would and publishes that one item in the same act, so everyone sees the change at once without the app's package being published: into the owning package when it is writable, else into the app's customization package (`<base>.custom`, asked of the ensure door, declaring `overrides: { package, basedOn }`), so an installed app's dashboard is edited too. A dashboard with a draft already pending there (a Studio edit not yet published) is not opened for editing, and a save over one writes nothing: that draft is never published on its saver's behalf. Discard drops every change.
15+
Save writes where Studio's Customize would and publishes that one item in the same act, so everyone sees the change at once without the app's package being published: into the owning package when it is writable, else into the app's customization package (`<base>.custom`, declaring `overrides: { package, basedOn }`), so an installed app's dashboard is edited too. Opening the edit state writes nothing: the pair is asked of the ensure door, which creates it on first use, at Save only. As with Studio's Customize, an installed app's dashboard is not opened where that door is walled for the caller or the package list gives no installed version to declare the override at. A dashboard with a draft already pending there (a Studio edit not yet published) is not opened for editing, and a save over one writes nothing: that draft is never published on its saver's behalf. Discard drops every change and writes nothing.
1616

17-
Every card, in every mode, carries a small mark naming the page filters that do not reach it ("Not filtered by Region"), asked of the same binding its query is built from (`dashboardFiltersNotApplied` over `resolveBoundField`): a filter the card opts out of, or one whose `targetWidgets` leaves it out. A card every filter reaches carries none.
17+
Every card, in every mode, carries a small mark naming the page filters that do not reach it ("Not filtered by Region"), asked of the same binding its query is built from (`dashboardFiltersNotApplied` over `resolveBoundField`): a filter the card opts out of, or one whose `targetWidgets` leaves it out (an explicit string binding wins over `targetWidgets`). A card every filter reaches carries none.
1818

‎content/docs/frontend/plugins/plugin-dashboard.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ object it reads. A query asked alone, and every query of an adapter without
148148
Every widget, in every mode, carries a small mark naming the dashboard
149149
filters that do not reach it, for example "Not filtered by Region": a filter
150150
it opts out of (`filterBindings[name]: false`) or one whose `targetWidgets`
151-
leaves it out. A widget every filter reaches carries none. The list is
151+
leaves it out. An explicit string binding (`filterBindings[name]: 'field'`)
152+
wins over `targetWidgets`, so a widget that names its field is reached even
153+
when the list leaves it out. A widget every filter reaches carries none. The list is
152154
`dashboardFiltersNotApplied(widget, defs)` from `@object-ui/core`, which asks
153155
`resolveBoundField`, the binding the widget's query is built from, so the
154156
mark and the data cannot disagree.

‎ui/packages/app-shell/src/views/DashboardInPageEditor.test.ts‎

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ import {
1717
withAddedWidget,
1818
withResizedWidget,
1919
} from './DashboardInPageEditor';
20-
import type { DashboardSaveTargetDoors } from './runtime-metadata-persistence';
2120

2221
/**
2322
* objectstack#36372 — opening a dashboard for in-page editing, and the two
2423
* buffer edits the page makes itself (add a card, resize a card). The rest of
2524
* the buffer's edits are Studio's panels' own `onPatch`.
2625
*/
2726

28-
const doors = (writable: boolean): DashboardSaveTargetDoors => ({
29-
listPackages: async () => new Map([['crm', { writable, manifest: { id: 'crm', version: '3.0.0' } } as any]]),
30-
ensureCustomization: async (base) => ({ packageId: `${base}.custom`, writable: true }),
27+
const listed = (entries: Record<string, { writable: boolean; version?: string }>) => ({
28+
listPackages: vi.fn(async () =>
29+
new Map(Object.entries(entries).map(([id, e]) => [id, { writable: e.writable, manifest: { id, version: e.version } } as any])),
30+
),
3131
});
32+
const doors = (writable: boolean) => listed({ crm: { writable, version: '3.0.0' } });
3233

3334
const stored = { name: 'exec', label: 'Exec', widgets: [{ id: 'a', type: 'bar' }] };
3435

@@ -38,41 +39,89 @@ describe('openDashboardForEdit', () => {
3839
getDraft: vi.fn(async () => null),
3940
layered: vi.fn(async () => ({ code: { name: 'exec' }, effective: stored })),
4041
};
41-
await expect(openDashboardForEdit('exec', 'crm', client, doors(true))).resolves.toEqual({
42+
await expect(openDashboardForEdit('exec', 'crm', client, { doors: doors(true) })).resolves.toEqual({
4243
kind: 'ready',
4344
target: { kind: 'package', packageId: 'crm' },
4445
doc: stored,
4546
});
4647
expect(client.getDraft).toHaveBeenCalledWith('dashboard', 'exec', { packageId: 'crm' });
4748
});
4849

49-
it('into a customization pair that does not hold it yet, opens its base\'s document', async () => {
50+
it('an installed app with no pair yet opens its base\'s document, reading no pair and creating none', async () => {
51+
const client = {
52+
getDraft: vi.fn(async () => null),
53+
layered: vi.fn(async () => ({ code: stored, effective: stored })),
54+
};
55+
// The doors carry no ensure door at all: opening could not create the pair if it tried.
56+
const opened = await openDashboardForEdit('exec', 'crm', client, { doors: doors(false) });
57+
expect(opened).toEqual({ kind: 'ready', target: { kind: 'customization', base: 'crm', basedOn: '3.0.0', pair: null }, doc: stored });
58+
expect(client.getDraft).not.toHaveBeenCalled();
59+
expect(client.layered).toHaveBeenCalledTimes(1);
60+
expect(client.layered).toHaveBeenCalledWith('dashboard', 'exec', { packageId: 'crm' });
61+
});
62+
63+
it('into a listed pair that does not hold it yet, opens its base\'s document', async () => {
5064
const client = {
5165
getDraft: vi.fn(async () => null),
5266
layered: vi.fn(async (_t: string, _n: string, o?: { packageId?: string }) =>
5367
o?.packageId === 'crm' ? { code: stored, effective: stored } : { code: null, effective: null },
5468
),
5569
};
56-
const opened = await openDashboardForEdit('exec', 'crm', client, doors(false));
57-
expect(opened).toMatchObject({ kind: 'ready', target: { kind: 'customization', packageId: 'crm.custom', base: 'crm' }, doc: stored });
70+
const pairListed = listed({ crm: { writable: false, version: '3.0.0' }, 'crm.custom': { writable: true, version: '0.0.0' } });
71+
const opened = await openDashboardForEdit('exec', 'crm', client, { doors: pairListed });
72+
expect(opened).toMatchObject({ kind: 'ready', target: { kind: 'customization', base: 'crm', pair: 'crm.custom' }, doc: stored });
5873
expect(client.getDraft).toHaveBeenCalledWith('dashboard', 'exec', { packageId: 'crm.custom' });
5974
});
6075

76+
it('is refused for an installed app where Studio\'s Customize is: the ensure door walled, or no version to declare', async () => {
77+
const client = { getDraft: vi.fn(async () => null), layered: vi.fn(async () => ({ code: stored, effective: stored })) };
78+
await expect(openDashboardForEdit('exec', 'crm', client, { doors: doors(false), walled: true })).resolves.toEqual({
79+
kind: 'refused',
80+
reason: 'walled',
81+
});
82+
expect(client.layered).not.toHaveBeenCalled();
83+
// A writable package is not customized, so the wall does not apply to it.
84+
await expect(openDashboardForEdit('exec', 'crm', client, { doors: doors(true), walled: true })).resolves.toMatchObject({ kind: 'ready' });
85+
await expect(
86+
openDashboardForEdit('exec', 'crm', client, { doors: listed({ crm: { writable: false } }) }),
87+
).resolves.toMatchObject({ kind: 'refused', reason: 'no-version' });
88+
// An item the pair already declares an override of keeps that declaration: no listed version is owed.
89+
const customized = { ...stored, overrides: { package: 'crm', basedOn: '2.0.0' } };
90+
const inPair = {
91+
getDraft: vi.fn(async () => null),
92+
layered: vi.fn(async () => ({ code: null, effective: customized })),
93+
};
94+
await expect(
95+
openDashboardForEdit('exec', 'crm', inPair, {
96+
doors: listed({ crm: { writable: false }, 'crm.custom': { writable: true } }),
97+
}),
98+
).resolves.toMatchObject({ kind: 'ready', doc: customized });
99+
});
100+
61101
it('is refused over a pending draft, without reading the document', async () => {
62102
const client = {
63103
getDraft: vi.fn(async () => ({ item: { name: 'exec' } })),
64104
layered: vi.fn(),
65105
};
66-
await expect(openDashboardForEdit('exec', 'crm', client, doors(true))).resolves.toEqual({ kind: 'refused', reason: 'pending-draft' });
106+
await expect(openDashboardForEdit('exec', 'crm', client, { doors: doors(true) })).resolves.toEqual({
107+
kind: 'refused',
108+
reason: 'pending-draft',
109+
});
67110
expect(client.layered).not.toHaveBeenCalled();
68111
});
69112

70113
it('is refused when there is no package to save into, and when the read fails', async () => {
71114
const client = { getDraft: vi.fn(async () => null), layered: vi.fn(async () => ({ code: null, effective: null })) };
72-
await expect(openDashboardForEdit('exec', 'gone', client, doors(true))).resolves.toMatchObject({ kind: 'refused', reason: 'no-package' });
73-
await expect(openDashboardForEdit('exec', 'crm', client, doors(true))).resolves.toMatchObject({ kind: 'refused', reason: 'load-failed' });
115+
await expect(openDashboardForEdit('exec', 'gone', client, { doors: doors(true) })).resolves.toMatchObject({
116+
kind: 'refused',
117+
reason: 'no-package',
118+
});
119+
await expect(openDashboardForEdit('exec', 'crm', client, { doors: doors(true) })).resolves.toMatchObject({
120+
kind: 'refused',
121+
reason: 'load-failed',
122+
});
74123
const failing = { getDraft: vi.fn(async () => { throw new Error('500'); }), layered: vi.fn() };
75-
await expect(openDashboardForEdit('exec', 'crm', failing, doors(true))).resolves.toEqual({
124+
await expect(openDashboardForEdit('exec', 'crm', failing, { doors: doors(true) })).resolves.toEqual({
76125
kind: 'refused',
77126
reason: 'load-failed',
78127
detail: '500',

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

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
* change applies to everyone at once without the app's package being
1212
* published; Discard drops every change.
1313
*
14-
* Where a save lands is {@link resolveDashboardSaveTarget}'s answer: the
14+
* Where a save lands is {@link resolveDashboardEditTarget}'s answer: the
1515
* owning package when it is writable, else the app's customization package
16-
* `<base>.custom` (ADR-0146), so an installed app is edited too. Over a draft
17-
* already pending there (a Studio edit not yet published) the edit state is
18-
* not entered: that draft is its saver's, and is never published on their
16+
* `<base>.custom` (ADR-0146), so an installed app is edited too. Opening
17+
* writes nothing: the pair is read from the package list, and asked of the
18+
* ensure door (which creates it on first use) only at Save. The edit state is
19+
* not entered where Studio's Customize is refused up front (the ensure door
20+
* walled for this caller, or the base listing no version to declare the
21+
* override at), nor over a draft already pending there (a Studio edit not yet
22+
* published): that draft is its saver's, and is never published on their
1923
* behalf.
2024
*
2125
* Out of scope here: undo, a business user's own copy, a new dashboard, chart
@@ -29,10 +33,11 @@ import { completeWidgetLayout, defaultWidgetPlacement, type DashboardWidgetSchem
2933
import { useSafeTranslate } from '@object-ui/i18n';
3034
import {
3135
dashboardSaveBody,
32-
resolveDashboardSaveTarget,
36+
ensureDashboardSaveTarget,
37+
resolveDashboardEditTarget,
3338
saveDashboardInPlace,
3439
unwrapDraftBody,
35-
type DashboardSaveTarget,
40+
type DashboardEditTarget,
3641
type DashboardSaveTargetDoors,
3742
type SaveAndPublishOutcome,
3843
} from './runtime-metadata-persistence.js';
@@ -46,13 +51,16 @@ import { getDashboardForm } from './metadata-admin/dashboard-schema.js';
4651
import { useMetadataLocale, type SupportedLocale } from './metadata-admin/i18n.js';
4752
import type { MetadataSelection } from './metadata-admin/preview-registry.js';
4853

49-
/** A save target the editor can write to. */
50-
export type WritableDashboardSaveTarget = Exclude<DashboardSaveTarget, { kind: 'refused' }>;
54+
/** Where the editor would save, as read at open (nothing is written to open). */
55+
export type WritableDashboardEditTarget = Exclude<DashboardEditTarget, { kind: 'refused' }>;
56+
57+
/** Why the edit state is not entered. */
58+
export type DashboardEditRefusal = 'no-package' | 'walled' | 'no-version' | 'pending-draft' | 'load-failed';
5159

5260
/** What opening a dashboard for editing found. */
5361
export type DashboardEditOpening =
54-
| { kind: 'ready'; target: WritableDashboardSaveTarget; doc: Record<string, unknown> }
55-
| { kind: 'refused'; reason: 'no-package' | 'pending-draft' | 'load-failed'; detail?: string };
62+
| { kind: 'ready'; target: WritableDashboardEditTarget; doc: Record<string, unknown> }
63+
| { kind: 'refused'; reason: DashboardEditRefusal; detail?: string };
5664

5765
/** The metadata client calls {@link openDashboardForEdit} makes. */
5866
export interface DashboardEditReader {
@@ -69,31 +77,58 @@ function authoredDoc(layers: { code: unknown; effective: unknown } | null): Reco
6977
return doc && typeof doc === 'object' && !Array.isArray(doc) ? (doc as Record<string, unknown>) : null;
7078
}
7179

80+
/** What {@link openDashboardForEdit} is told besides the item. */
81+
export interface DashboardEditOpenOptions {
82+
doors?: Pick<DashboardSaveTargetDoors, 'listPackages'>;
83+
/**
84+
* The ensure door refuses this caller on this deployment
85+
* (`useCustomizeDoorWalled`): an installed app's dashboard is then not
86+
* opened, as Studio's Customize is disabled for it.
87+
*/
88+
walled?: boolean;
89+
}
90+
7291
/**
7392
* Open `name` for editing: where a save would land, and the document as
7493
* authored there (its layered read's `effective`, the buffer Studio edits; a
75-
* customization package that does not hold the item yet starts from its
76-
* base's). Refused when there is no package to save into, when a draft is
77-
* already pending there, or when the item cannot be read.
94+
* customization package that does not list the pair or hold the item yet
95+
* starts from its base's). Reads only: the customization pair is never
96+
* created here. Refused when there is no package to save into, where Studio's
97+
* Customize would be (the ensure door walled for this caller; no listed base
98+
* version to declare the override at), when a draft is already pending
99+
* there, or when the item cannot be read.
78100
*/
79101
export async function openDashboardForEdit(
80102
name: string,
81103
ownerPackageId: string | null | undefined,
82104
client: DashboardEditReader,
83-
doors?: DashboardSaveTargetDoors,
105+
options: DashboardEditOpenOptions = {},
84106
): Promise<DashboardEditOpening> {
85-
const target = await resolveDashboardSaveTarget(ownerPackageId, doors);
107+
const target = await resolveDashboardEditTarget(ownerPackageId, options.doors);
86108
if (target.kind === 'refused') return { kind: 'refused', reason: 'no-package', detail: target.reason };
87-
const at = target.kind === 'unbound' ? {} : { packageId: target.packageId };
109+
if (target.kind === 'customization' && options.walled) return { kind: 'refused', reason: 'walled' };
110+
// A pair not listed yet holds nothing: no draft to find, the base's document opens.
111+
const at =
112+
target.kind === 'unbound'
113+
? {}
114+
: target.kind === 'package'
115+
? { packageId: target.packageId }
116+
: target.pair
117+
? { packageId: target.pair }
118+
: null;
88119
try {
89-
if (unwrapDraftBody(await client.getDraft('dashboard', name, at))) {
120+
if (at && unwrapDraftBody(await client.getDraft('dashboard', name, at))) {
90121
return { kind: 'refused', reason: 'pending-draft' };
91122
}
92-
let doc = authoredDoc(await client.layered('dashboard', name, at));
123+
let doc = at ? authoredDoc(await client.layered('dashboard', name, at)) : null;
93124
if (!doc && target.kind === 'customization') {
94125
doc = authoredDoc(await client.layered('dashboard', name, { packageId: target.base }));
95126
}
96127
if (!doc) return { kind: 'refused', reason: 'load-failed' };
128+
// Studio's `noVersion`: no override declared yet, and no version to declare it at.
129+
if (target.kind === 'customization' && dashboardSaveBody(doc, target) === null) {
130+
return { kind: 'refused', reason: 'no-version', detail: target.base };
131+
}
97132
return { kind: 'ready', target, doc };
98133
} catch (err) {
99134
return { kind: 'refused', reason: 'load-failed', detail: err instanceof Error ? err.message : String(err) };
@@ -332,15 +367,18 @@ export function useDashboardInPageEdit({
332367
client,
333368
dataSource,
334369
doors,
370+
walled = false,
335371
}: {
336372
name: string;
337373
ownerPackageId: string | null | undefined;
338374
client: DashboardEditClient;
339375
dataSource?: object | null;
340376
doors?: DashboardSaveTargetDoors;
377+
/** `useCustomizeDoorWalled()` for this session: see {@link DashboardEditOpenOptions.walled}. */
378+
walled?: boolean;
341379
}): DashboardInPageEdit {
342380
const [session, setSession] = React.useState<{
343-
target: WritableDashboardSaveTarget;
381+
target: WritableDashboardEditTarget;
344382
draft: Record<string, unknown>;
345383
dirty: boolean;
346384
} | null>(null);
@@ -362,15 +400,15 @@ export function useDashboardInPageEdit({
362400
const open = React.useCallback(async () => {
363401
setOpening(true);
364402
try {
365-
const opened = await openDashboardForEdit(name, ownerPackageId, client, doors);
403+
const opened = await openDashboardForEdit(name, ownerPackageId, client, { doors, walled });
366404
if (opened.kind === 'refused') return opened;
367405
setSession({ target: opened.target, draft: opened.doc, dirty: false });
368406
setSelection(null);
369407
return null;
370408
} finally {
371409
setOpening(false);
372410
}
373-
}, [name, ownerPackageId, client, doors]);
411+
}, [name, ownerPackageId, client, doors, walled]);
374412

375413
const discard = React.useCallback(() => {
376414
setSession(null);
@@ -384,7 +422,9 @@ export function useDashboardInPageEdit({
384422
if (!body) return 'invalid-body';
385423
setSaving(true);
386424
try {
387-
const outcome = await saveDashboardInPlace(name, body, session.target, {
425+
// The first write of the edit: an installed app's pair is asked for (and made) here.
426+
const target = await ensureDashboardSaveTarget(session.target, doors);
427+
const outcome = await saveDashboardInPlace(name, body, target, {
388428
metadataClient: client,
389429
dataSource: (dataSource ?? null) as any,
390430
});
@@ -396,7 +436,7 @@ export function useDashboardInPageEdit({
396436
} finally {
397437
setSaving(false);
398438
}
399-
}, [session, name, client, dataSource]);
439+
}, [session, name, client, dataSource, doors]);
400440

401441
const addCard = React.useCallback(
402442
(type: string) => {

0 commit comments

Comments
 (0)