Repository navigation
Commit 8a741ab
feat(console): edit a dashboard on its own page, and mark the page filters a card does not follow (objectstack-ai#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 objectstack-ai#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 objectstack-ai#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 objectstack-ai#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 objectstack-ai#36086 (epic objectstack-ai#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 objectstack-ai#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. objectstack-ai#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 (objectstack-ai#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
File tree
- .changeset
- content/docs/frontend/plugins
- ui/packages
- app-shell/src
- console/__tests__
- views
- core/src
- utils
- __tests__
- i18n/src/locales
- plugin-dashboard
- src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
146 | 177 | | |
147 | 178 | | |
148 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
0 commit comments