Skip to content

Commit 8a741ab

Browse files
feat(console): edit a dashboard on its own page, and mark the page filters a card does not follow (#36405)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbCxiFE11rsKwyNffJZKYqJs)_ repo:objectstack#7 · zhuangjianguo · session_01QsR2jUeSU9HhKxjcVsyprx Fixes #36372 Clause-②: yes (widening) — one new exported core function (`dashboardFiltersNotApplied`), two new optional `DashboardRenderer` props (`onWidgetResize`, `onAddFilter`), and new `@object-ui/i18n` keys (`dashboard.inPageEdit.*`, `dashboard.filters.notApplied`, `dashboard.filters.addFilter`); nothing removed or renamed Metadata-protocol: none ## 维护者速读 - 是什么:系统管理员在仪表盘页面上点「编辑」就能直接改:拖动和拉伸卡片、点卡片在右侧改属性、添加和删除卡片、添加和修改顶部筛选、设置每张卡片是否跟随页面筛选。「保存」后所有人立刻看到,不需要发布应用包;「放弃」丢掉全部改动。 - 为什么:以前改仪表盘必须进入工作室,管理员在看数据时发现问题要绕一大圈;现在在哪里看就在哪里改。 - 对已安装的应用:改动写进该应用的定制层(和工作室的「定制」写同一处),升级应用不会覆盖。点「编辑」本身什么都不写,定制层在第一次「保存」时才创建,所以「编辑」后「放弃」不留下任何东西。工作室不让定制的情况(本部署只有平台运营方能定制已安装应用、软件包列表没给出版本),页面也不进入编辑,并说明原因;如果工作室里已有这张仪表盘未发布的草稿,页面会提示先去工作室处理,不会替别人发布。 - 另外:每张卡片都会显示一个小标记,写明它不跟随哪些页面筛选(例如「不跟随『区域』筛选」),标记和卡片实际查到的数据用的是同一条判断,不会对不上。 ## What changes **Edit state on the dashboard page** (`DashboardView` + new `DashboardInPageEditor.tsx`). A workspace admin who may author metadata, on a package Studio lists (`useStudioEntryGate`, the gate of the app → Studio entries; writable or read-only, never a kernel package), gets an **Edit** button in the page header (from `sm` up: the edit state needs its side panel). Edit opens the dashboard **as stored** — the layered read's `effective` in the package a save would land in (a customization pair that is not listed yet, or does not hold it yet, opens its base's) — never the served, translated copy. **Opening writes nothing**: it reads the package list and the item only. In the edit state: - the header shows an **Editing** badge, the hint "Saved changes apply to everyone at once", and **Add card**, **Discard**, **Save** (Save is off until something changes); - every card draws dashed and is in the renderer's design mode: drag to move (the existing dnd-kit reorder), click to select, and a new corner handle resizes it by whole grid tracks; - the right panel is Studio's own dashboard panels, unchanged: `DashboardWidgetInspector` for a selected card (its data, the "follow page filters" switches, Remove) and `DashboardDefaultInspector` otherwise (label, cards, filters, layout); - **Add card** appends a card at the end (Studio's id and defaults) and selects it; **Add filter**, drawn at the end of the filter bar, opens the panel's Filters section. **Save** (`saveDashboardInPlace`) is the confirmed-save door of #35955 (ruling 7058616478): the body is staged as the item's draft under the first-write pin and that one item is published in the same act — no package-wide publish-drafts. Where it lands is read at open by `resolveDashboardEditTarget` (package list only): the owning package when the list carries it writable, else the app's customization package, whose id is taken from the list when it is already listed (`listedCustomizationPairOf`, the read Studio makes of a pair). At Save, and only there, `ensureDashboardSaveTarget` asks the ensure door for the pair (it creates `<base>.custom` on first use, as Studio's first saved customization does), and the body declares `overrides: { package, basedOn }` (`overrideDraftBody`, the body Studio's Customize writes; ADR-0146 D2/D3). So an installed app's dashboard is edited too, through the same doors Studio uses. The edit state is refused up front where Studio's Customize is: the ensure door walled for this caller (`useCustomizeDoorWalled`, toast "only the platform operator can customize an installed app's dashboard") and a base listing no version to declare the override at when the item declares none yet (Studio's `noVersion`). Over a draft already pending there, the edit state is not entered, and a save that races one writes nothing (`'pending-draft'`): a Studio draft is never published on its saver's behalf. **Discard** drops the buffer and writes nothing. After a save the bundle re-read keeps the shown dashboard standing, so the page does not flash its skeleton. The edit state draws the stored document with the served `_packageId` beside it, so its cards' dataset queries keep naming the dashboard's package (`callerPackage`, ADR-0150 D3) as in view mode; a save drops `_` keys. **The not-filtered mark** (`plugin-dashboard`). Every card, in every mode, names the page filters that do not reach it ("Not filtered by Region and Owner"; zh 「不跟随『区域和负责人』筛选」): a filter it opts out of (`filterBindings[name]: false`) or one whose `targetWidgets` leaves it out (an explicit string binding wins over `targetWidgets`). The built-in date filter is named as the bar names it ("Date range"), never by its reserved name. The list is the new core `dashboardFiltersNotApplied(widget, defs)`, which asks `resolveBoundField` — the binding `buildWidgetScopedFilter` builds the card's query from — so the mark and the data cannot disagree. A card every filter reaches carries none. **Renderer design mode** gains two opt-in affordances: `onWidgetResize(widgetId, { w, h })` draws the corner handle (snaps as the pointer crosses half a track; arrow keys step by one; width clamped to the grid's columns; not drawn on a phone), and `onAddFilter()` draws "Add filter" in the filter bar (the bar is drawn for it even before any filter exists). Studio's canvas passes neither, so it is unchanged. **Persistence seam.** `saveAndPublishRuntimeMetadata` itself is unchanged: `saveDashboardInPlace` hands it a client that names the target package on the three writes it makes (draft, publish, discard of a refused publish). Studio is not touched; panel wording is #36373's (not touched here). ADR: this realises the in-app half of the ADR-0146 D1 amendment row "ADR-0146 D1, \"Studio owns all metadata\"" that seat 7 filed on the weekly ADR card #36086 (epic #36359); no `docs/adr` edit here. Persistence stays on the ADR-0034 runtime metadata seam (draft + per-item publish through `/meta`). ## Tests - `ui/packages/core/src/utils/__tests__/dashboard-filters.test.ts` — `dashboardFiltersNotApplied` agrees with `buildWidgetScopedFilter` for default, opted-out, rebound, `targetWidgets`-listed and explicit-over-list widgets. - `ui/packages/plugin-dashboard/src/__tests__/DashboardRenderer.filters.test.tsx` — the mark is on the opted-out card and only it, a rebound card has none, a `targetWidgets`-excluded card has it, an opted-out built-in date filter reads "Not filtered by Date range"; each case reads the query's `runtimeFilter` beside the mark. - `ui/packages/plugin-dashboard/src/__tests__/DashboardRenderer.designMode.test.tsx` — the corner handle only with `onWidgetResize` in design mode, keyboard resize, no card selection from the handle; "Add filter" only in design mode, drawn before any filter exists. - `ui/packages/plugin-dashboard/src/designAffordances.test.ts` — `resizedSpan` snapping and clamps. - `ui/packages/app-shell/src/views/runtime-metadata-persistence.test.ts` — edit target read from the list only (writable package; read-only package with no pair listed: none named, ensure not called; a listed pair named for reading; unbound; refusal), the ensure door asked at save (pair with `basedOn`; refusal and non-writable pair throw), the save body, the target package named on draft/publish/discard, pending-draft writes nothing. - `ui/packages/app-shell/src/views/DashboardInPageEditor.test.ts` — opening (owner's layered `effective`; an installed app with no pair yet opens its base's reading no pair and with no ensure door at all; a listed pair that does not hold it opens its base's; refused when walled and when no version is listed, but not for an item that already declares its override; refused over a pending draft without reading; refusals), add card, resize keeps unnamed coordinates. - `ui/packages/app-shell/src/views/DashboardView.inPageEdit-36372.test.tsx` — through the real `DashboardView` and renderer: no Edit button behind the gate; Edit opens the stored document in design mode with badge and panel; resize + Save stages and publishes in the owning package and leaves the edit state; an installed package asks the ensure door at Save only and saves into `crm.custom` declaring the override; **Edit then Discard on an installed app calls the ensure door zero times and writes nothing**; a walled door refuses with its reason; a dataset card in the edit state still queries with `callerPackage` (ablated: red without the fix); a pending draft refuses; Discard writes nothing. ## Acceptance notes **Live run** (L1-e's REWORK) on head `f0750e0dd`: a fresh local showcase backend (`objectstack dev --seed-admin`, file DB) and the console from source (`ui/apps/console` Vite against it), driven by Playwright as the seeded admin. The writable leg uses a package created over REST (`com.example.livedash`, depending on `com.example.showcase`) holding an app and a four-card dashboard with one card opted out of the date range; the installed leg uses showcase's own `showcase_ops_dashboard` (`com.example.showcase`, listed read-only, version 0.1.0). | Acceptance | Reading | |---|---| | Writable: drag, widen, add, delete, Save | Dragged "Priority Mix" to the front, widened "Tasks all time" by its corner (192 → 400 px, `w` 3 → 6), added a Metric card (given its dataset and measure in the panel; Save without them is refused by the server, 422 `widgets.N.dataset`, shown in the "could not be saved" toast with that reason), removed "Tasks by Status" through the panel. Writes on **Edit**: none. Writes on **Save**: exactly `PUT /api/v1/meta/dashboard/livedash_board?mode=draft&package=com.example.livedash` (200, `state=draft`) then `POST …/livedash_board/publish?package=com.example.livedash` (200). No `/packages/:id/publish-drafts`. | | After a reload the layout holds | The served dashboard reads `w_priority, w_tasks, w_all_time (w 6), widget_1`; the page draws that order, the widened card, the added "Open tasks (added live)" and no "Tasks by Status". | | Installed app: Edit then Discard | Writes on Edit: none; package list before and after Edit → change → Discard: `["com.example.showcase"]` (no `.custom` created); the page shows the original titles. | | Installed app: Save lands in `<base>.custom` | Writes on Save: `POST /api/v1/packages/com.example.showcase/ensure-customization`, `PUT …/showcase_ops_dashboard?mode=draft&package=com.example.showcase.custom` with `overrides: { package: "com.example.showcase", basedOn: "0.1.0" }` (server: "Saved customization overlay"), `POST …/publish?package=com.example.showcase.custom`. After a reload the page shows "Total Budget (customized live)". Studio's Interfaces (`/studio/com.example.showcase/interfaces?surface=dashboard:showcase_ops_dashboard`) shows the same title, the "Overrides ObjectStack Showcase" badge and "Only customizations (1)". | | Discard after a change | Covered in the installed leg above: the page is as before and nothing is written. | | Mark on an opted-out time-filter card | "Tasks all time" (`filterBindings: { dateRange: false }`) reads "Not filtered by Date range"; no other card is marked. Last 90 days: follows 10, all-time 10; Yesterday: follows 1, all-time **10** (unchanged). | | Its switch turned on and saved | The panel's dateRange "Apply" checkbox on that card, then Save: the body's card has no `filterBindings`; draft + per-item publish only. After a reload: no mark on any card; Yesterday: follows 1, all-time **1** (now follows). | The live run found two defects, fixed in `f0750e0dd` and pinned: the mark named the built-in date filter by its reserved name ("dateRange"), and the edit state's dataset queries dropped `?callerPackage=` (the stored document carries no `_packageId`). **Screenshots** (live run, 2× scale) are in the project's shared files, under `repo-objectstack-7/shots/36372/`; they cannot be uploaded to GitHub from the cloud seat, as on #36397. They replace the harness shots. - `live-en-edit-writable.png` — edit state on the writable dashboard: Editing badge, hint, Add card / Discard / Save, dashed cards, the widened card selected with its panel, the marked card. - `live-en-view-marked-card.png` — view mode with "Not filtered by Date range" on the opted-out card, under "Yesterday". - `live-en-edit-installed.png`, `live-zh-edit-installed.png` — edit state on the installed showcase dashboard (zh: 「编辑中」「保存后所有人立刻看到」, five cards marked 「不跟随「Task Status」筛选」). - `live-en-after-reload-writable.png`, `live-en-after-reload-installed.png`, `live-en-studio-interfaces.png`, `live-en-view-after-switch-on.png` — the after-reload and Studio readings above. **Known gap** (not in this card): leaving the page in the edit state with unsaved changes drops them without asking. #36362's unsaved-edits seam (`useRegisterUnsavedEdits`) is the place to register it, in a later card. Undo, a business user's own copy, a new dashboard, chart drawing and drill-down are out of scope, per the card. ## Verification - At `f0750e0dd`: type check `@object-ui/app-shell` and `@object-ui/plugin-dashboard` green; `packages/plugin-dashboard/src`, the dashboard view / editor / persistence files, `core` dashboard-filters and `AppContent.dashboardRouteReads-28784` — 223 files, 2213 tests green; `packages/i18n/src/__tests__` 106 files green; `check-i18n-en-drift`, `check-i18n-call-site-keys`, `check-i18n-dead-keys` green. `overlap-check`: clean against main and 7 open PRs (#36398 included). - At `3e7995a73` (before this round): `node scripts/pm/dispatch-gates.mjs --commands`, 72 derived families all run and accounted (`--ran`); four first-pass reds re-run exit 0 (comment-mask sweep reading a deleted harness file, `vitest run scripts/` killed for memory, `check:skill-examples` prerequisite, `check:test-source-alias` fixed in the tests). This round's diff (app-shell editor, two i18n keys in every locale, the mark's label, docs) is left to CI's gates. https://claude.ai/code/session_01QsR2jUeSU9HhKxjcVsyprx 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: repo:objectstack#7 · zhuangjianguo · session_01QsR2jUeSU9HhKxjcVsyprx --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6a35635 commit 8a741ab

30 files changed

Lines changed: 2167 additions & 21 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@object-ui/core': patch
3+
'@object-ui/i18n': patch
4+
'@object-ui/plugin-dashboard': patch
5+
'@object-ui/app-shell': patch
6+
---
7+
8+
feat(console): a dashboard is edited on its own page by the people who may design its package, and every card marks the page filters it does not follow
9+
10+
Clause-②: yes (widening) — one new exported function (`dashboardFiltersNotApplied` in `@object-ui/core`), two new optional `DashboardRenderer` props (`onWidgetResize`, `onAddFilter`), and new `@object-ui/i18n` keys (`dashboard.inPageEdit.*`, `dashboard.filters.notApplied`, `dashboard.filters.addFilter`); nothing is removed or renamed
11+
Metadata-protocol: none
12+
13+
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.
14+
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.
16+
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.
18+

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,37 @@ request draws it, and a widget re-reads on its own when a write invalidates the
143143
object it reads. A query asked alone, and every query of an adapter without
144144
`queryDatasetBatch`, takes `queryDataset` unchanged.
145145

146+
## Filters a widget does not follow
147+
148+
Every widget, in every mode, carries a small mark naming the dashboard
149+
filters that do not reach it, for example "Not filtered by Region": a filter
150+
it opts out of (`filterBindings[name]: false`) or one whose `targetWidgets`
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
154+
`dashboardFiltersNotApplied(widget, defs)` from `@object-ui/core`, which asks
155+
`resolveBoundField`, the binding the widget's query is built from, so the
156+
mark and the data cannot disagree.
157+
158+
## Design mode: resizing and "Add filter"
159+
160+
In `designMode` two more affordances are drawn when the host hands their
161+
handler:
162+
163+
- `onWidgetResize(widgetId, { w, h })`: a corner handle on each widget
164+
resizes it by whole grid tracks (it snaps as the pointer crosses half a
165+
track; the arrow keys on the handle grow or shrink it by one). Width stays
166+
within the grid's columns. The host writes the span into the widget's
167+
`layout`. Not drawn below the phone breakpoint.
168+
- `onAddFilter()`: an "Add filter" button at the end of the filter bar, which
169+
is drawn for it even before any filter is declared.
170+
171+
The console's dashboard page uses both in its in-page edit state: an admin
172+
who may design the dashboard's package opens it with **Edit**, changes it with
173+
Studio's own dashboard panels at the right, and **Save** publishes that one
174+
dashboard (into the package, or into the app's customization package for an
175+
installed app), so everyone sees it at once.
176+
146177
## TypeScript Support
147178

148179
```ts

‎ui/packages/app-shell/src/console/__tests__/AppContent.dashboardRouteReads-28784.test.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ vi.mock('../../layout/ConsoleLayout', () => ({
5151
ConsoleLayout: ({ children }: { children?: React.ReactNode }) => <div data-testid="console-layout">{children}</div>,
5252
}));
5353
vi.mock('../../chrome/CommandPalette', () => ({ CommandPalette: () => null }));
54-
vi.mock('../../hooks/useStudioDesignGate', () => ({ useStudioDesignGate: () => null }));
54+
// `useStudioEntryGate`: the dashboard page's Edit button reads it (objectstack#36372).
55+
vi.mock('../../hooks/useStudioDesignGate', () => ({ useStudioDesignGate: () => null, useStudioEntryGate: () => null }));
5556
vi.mock('../../chrome/KeyboardShortcutsDialog', () => ({ KeyboardShortcutsDialog: () => null }));
5657
vi.mock('../../chrome/OnboardingWalkthrough', () => ({ OnboardingWalkthrough: () => null }));
5758
vi.mock('@object-ui/i18n', async (importOriginal) => ({
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
import { describe, it, expect, vi } from 'vitest';
10+
// Paid during collection, not inside a case's clock: Studio's dashboard panels
11+
// reach both through dynamic imports (check:test-source-alias).
12+
import '@objectstack/lint';
13+
import '@objectstack/formula';
14+
import {
15+
filtersSectionLabel,
16+
openDashboardForEdit,
17+
withAddedWidget,
18+
withResizedWidget,
19+
} from './DashboardInPageEditor';
20+
21+
/**
22+
* objectstack#36372 — opening a dashboard for in-page editing, and the two
23+
* buffer edits the page makes itself (add a card, resize a card). The rest of
24+
* the buffer's edits are Studio's panels' own `onPatch`.
25+
*/
26+
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+
),
31+
});
32+
const doors = (writable: boolean) => listed({ crm: { writable, version: '3.0.0' } });
33+
34+
const stored = { name: 'exec', label: 'Exec', widgets: [{ id: 'a', type: 'bar' }] };
35+
36+
describe('openDashboardForEdit', () => {
37+
it('opens the layered effective document of the owning package', async () => {
38+
const client = {
39+
getDraft: vi.fn(async () => null),
40+
layered: vi.fn(async () => ({ code: { name: 'exec' }, effective: stored })),
41+
};
42+
await expect(openDashboardForEdit('exec', 'crm', client, { doors: doors(true) })).resolves.toEqual({
43+
kind: 'ready',
44+
target: { kind: 'package', packageId: 'crm' },
45+
doc: stored,
46+
});
47+
expect(client.getDraft).toHaveBeenCalledWith('dashboard', 'exec', { packageId: 'crm' });
48+
});
49+
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 () => {
64+
const client = {
65+
getDraft: vi.fn(async () => null),
66+
layered: vi.fn(async (_t: string, _n: string, o?: { packageId?: string }) =>
67+
o?.packageId === 'crm' ? { code: stored, effective: stored } : { code: null, effective: null },
68+
),
69+
};
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 });
73+
expect(client.getDraft).toHaveBeenCalledWith('dashboard', 'exec', { packageId: 'crm.custom' });
74+
});
75+
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+
101+
it('is refused over a pending draft, without reading the document', async () => {
102+
const client = {
103+
getDraft: vi.fn(async () => ({ item: { name: 'exec' } })),
104+
layered: vi.fn(),
105+
};
106+
await expect(openDashboardForEdit('exec', 'crm', client, { doors: doors(true) })).resolves.toEqual({
107+
kind: 'refused',
108+
reason: 'pending-draft',
109+
});
110+
expect(client.layered).not.toHaveBeenCalled();
111+
});
112+
113+
it('is refused when there is no package to save into, and when the read fails', async () => {
114+
const client = { getDraft: vi.fn(async () => null), layered: vi.fn(async () => ({ code: null, effective: null })) };
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+
});
123+
const failing = { getDraft: vi.fn(async () => { throw new Error('500'); }), layered: vi.fn() };
124+
await expect(openDashboardForEdit('exec', 'crm', failing, { doors: doors(true) })).resolves.toEqual({
125+
kind: 'refused',
126+
reason: 'load-failed',
127+
detail: '500',
128+
});
129+
});
130+
});
131+
132+
describe('the page\'s own buffer edits', () => {
133+
it('adds a card at the end with a fresh id', () => {
134+
const added = withAddedWidget({ ...stored, widgets: [{ id: 'widget_1', type: 'bar' }] }, 'pie');
135+
expect(added.id).toBe('widget_2');
136+
const widgets = added.doc.widgets as Array<{ id: string; type: string }>;
137+
expect(widgets.map((w) => w.id)).toEqual(['widget_1', 'widget_2']);
138+
expect(widgets[1].type).toBe('pie');
139+
});
140+
141+
it('resizes a card, keeping the coordinates the span does not name', () => {
142+
const doc = { widgets: [{ id: 'a', type: 'bar', layout: { x: 6, y: 2, w: 3, h: 4 } }, { id: 'b', type: 'bar' }] };
143+
expect((withResizedWidget(doc, 'a', { w: 4, h: 2 }).widgets as any[])[0].layout).toEqual({ x: 6, y: 2, w: 4, h: 2 });
144+
// A card with no layout gets the grid's auto placement for its index.
145+
expect((withResizedWidget(doc, 'b', { w: 2, h: 1 }).widgets as any[])[1].layout).toEqual({ x: 3, y: 0, w: 2, h: 1 });
146+
// An unknown id changes nothing.
147+
expect(withResizedWidget(doc, 'zz', { w: 2, h: 1 })).toBe(doc);
148+
});
149+
150+
it('finds the panel section that edits the page filters', () => {
151+
expect(filtersSectionLabel('en-US')).toBe('Filters');
152+
});
153+
});

0 commit comments

Comments
 (0)