Skip to content

Commit f590f3e

Browse files
feat(studio): hooks, an installed app's added actions and flows save with Cancel and Save, live at once (#36634)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi96kzyjcbK53dPTb3U2Eb422)_ Part of #36511 Clause-②: no Metadata-protocol: none This is the second PR for the card, on top of #36597 (the object page, merged). It covers the object page's hooks, the actions an installed app's object gains in its customization package, and flows. Permission sets in the Studio's Access pillar are done too, but are left out of this PR to keep it under the 3000-line budget: they wait on the branch `claude/issue-36511-studio-save-cancel-3`, about 380 more lines on top of this one. Field layout and the AI-draft notice stay with the third PR. ## 维护者速读 - 用户能看到什么变化:在 Studio 里,对象页的「钩子」「新增动作(已安装应用的定制)」和「自动化流程」不再每隔一秒半自动存草稿。改完点顶栏「保存」立即生效,点「取消」回到原样。流程的启用开关一按就生效,新建的流程一创建就上线(默认关闭),打开开关即刻运行。 - 为什么做:维护者裁定人类改一项就确认一项、点保存直接生效。这是「保存即生效」系列的第二步,接在已合入的对象页之后;权限集因行数预算另起一单紧随其后。 - 出错会怎样:保存被服务器拒绝时,改动留在页面上并写明原因,这次保存写下的草稿会被收回。可以直接撤回本单,回到原来的自动存草稿。 - 要你做什么:无。 ## What changes **Mechanism.** Nothing new. Each editor below registers its buffer with the top bar's coordinator from #36597 (`useStudioSaveEntry` in `studioSaveBar.tsx`). Save writes the item's draft, then publishes that one item with `publishSavedItem`. A refused publish takes back the draft that Save wrote, unless a draft was already pending before the Save. **Editors moved to explicit save in this PR.** - **Hooks**, on the object page's Hooks tab (`ObjectHooksPanel.tsx`): - The buffer moved out of the panel into a new `objectHooksBuffer.ts`. It is owned by the Data pillar, so an edit survives a tab switch and is still sent by Save. - It is read the first time the Hooks tab opens for an object, so opening an object reads nothing new. - A new hook ("+ New", and the empty block's button) is written only by Save, under the first-write pin (`If-None-Match: *`). - A rename or an expression that does not parse holds the whole Save and names why. - The panel is now presentational. Its saved-at line is gone; the toast names what was saved. - **An installed app's added actions**, on the object page's Actions tab (`pairObjectActions.ts`, `ObjectActionsPanel.tsx`): - The same lift: the Data pillar owns the buffer. - A preset adds the action locally; nothing is written and the ensure door is not asked until Save. - Delete takes the row off the page; Save deletes its draft and its published row in the pair. - Save writes each new or edited action's draft in the pair and publishes it there. - **Flows**, on the canvas and in the properties aside (`AutomationsPillar` in `StudioDesignSurface.tsx`): - The flow's autosave is gone. Save writes the draft (into the pair for a customized flow) and publishes that flow. Cancel reloads it as the server holds it. - **The enable switch needs no Save.** A flip writes the stored flow with the new `status` and publishes it at once. An unsaved canvas edit is not sent with it and stays on the page for Save. A refused flip rolls the switch back. - **A new flow is published as it is created**, switched off as before, so turning it on makes it live straight away. Self-built and installed apps take the same path. An installed app's flows that are switched through the ledger (`FlowLedgerSwitch`) were already immediate. - The header's 已保存 badge retired with the autosave. A Save also re-reads the flow's verdict, so a stale problem clears. **Words.** - The switch's titles and toasts say a flip is live now, not "publish to apply". - The inspector footers and the Studio landing lead say Save makes a change live. - A customized item's pillar footer has its own key, `engine.studio.customize.saveFooter`. The shared `customize.draftFooter` stays as written for the All-metadata item page, which still autosaves. - Three held clauses are new: `held.hookRename`, `held.celInvalidHook`, `held.pairActionRename`. - Three keys only the badge read are removed: `autoSaved`, `flowSavedNamed`, `flowSaveFailed`. **Two people saving the same item.** The later Save can overwrite one that already went live. The seat accepted this for the transition (ruling on the card, 7089589821); the server-side guard is #36601. ## Tests New suites, each asserting no write before Save (past the retired 1.5 s debounce), then the draft write followed by the single-item publish, and Cancel putting the page back with nothing sent: - `ObjectHooksPanel.saveCancel-36511.test.tsx`: edit, Save, Cancel; "+ New" under `If-None-Match: *`; a refused publish keeps the edit and takes back the draft; a rename holds Save. - `AutomationsPillar.saveCancel-36511.test.tsx`: edit, Save, Cancel. The switch is live at once without the unsaved edit. A new flow is published off, and switched on it is published on. - `DataPillar.pairActions-30088.test.tsx` (rewritten): a preset writes nothing and asks no pair until Save; an edit is saved and published at the pair; Delete is sent by Save. A new Cancel case covers an added action plus an edit. Rewritten onto the top bar's Save (the same assertions, with Save pressed where the autosave used to fire): - Hooks: `ObjectHooksPanel.celGate`, `.firstSavePinned-11773` (a re-opened hook now asserts no draft again, since Save published the last one), `.draftUnreadable-29148`, `.newHookTarget-11820`, `.designerRegistryMissing`, `StudioEmptyState.panels-12514` (Hooks block), `ObjectPanels.lateRegistration-11939`. The panel is mounted through a new test host, `__tests__/hooksPanelHost.tsx`. - Flows: `AutomationsPillar.customizeFlow-28570`, `.problemsAgree-27799`, `.serverVerdict-26858`, `.heldIncomplete-11786`, `StudioDesignSurface.autosaveInFlight-11204` (flow case), `.autosaveSwitch-11232` (two flow cases), `.publishRefusal-26730` (the switch's publish takes the draft off the pending feed), `.heldPublish-11786`. - `DirectoryPage.stateVocabulary-29705` pins the new `customize.saveFooter` key to 定制. Retired: - `ObjectHooksPanel.autosave-11787.test.tsx`: the hook autosave it pinned is gone. Its rename hold moved into the new hooks suite, and its in-flight case has no autosave left to race. - The three badge cases of `StudioDesignSurface.flowAutosave-34818.test.tsx`: the badge is gone, and the Save toast is pinned in the new flow suite. Its Interfaces, Debug and Runs cases stay. <details><summary>Local test readings</summary> All runs went through `os-verify-lock.sh`, after a fresh build of the app-shell dependency closure following the merge of main. - At c496e8b, the code as in this PR's head: `vitest run` over `app-shell/src/views/studio-design`, the `PermissionMatrix*` suites, `DirectoryPage.stateVocabulary-29705`, `studioAutomationCopy*` and the whole `packages/i18n`. Result: `Test Files 509 passed (509)`, `Tests 5138 passed | 13 skipped (5151)`, VERDICT command-exit 0. - At bf7dbf0, the head. The only change since c496e8b is a collection-time `import '@objectstack/lint'` in 13 suites, asked for by `check:test-source-alias`. Those 13 suites plus the new flow suite and the pair-actions suite: `Test Files 15 passed (15)`, `Tests 71 passed (71)`, VERDICT command-exit 0. - At bf7dbf0, app-shell `pnpm type-check` (both tsconfig and tsconfig.test) and `pnpm lint`: VERDICT command-exit 0, lint 0 errors. - `Test UI`, `Lint UI`, `Type Check UI` and the Live E2E run in CI. </details> ## Acceptance notes - Permission sets: they are on `claude/issue-36511-studio-save-cancel-3` (the Access matrix sends with Save and publishes the set; the banners say Save). They were left out only for the line budget: this PR is 30 files, +1773/−1008 against main. - The create dialogs still read "Save as draft" (`engine.studio.createDraft`, one label pinned for every create dialog by `CreateItemDialog.oneLabel-11787`). Objects since #36597, and flows now, are live when created. The label is left for the card to settle in one place. - The Access pillar's OWD overview keeps its own Save, which writes object drafts for Publish. It was not named in this PR's scope. - After a Save, the Problems tab reads the live flow's verdict, because no draft is left. A publish the server refuses still names the problem in the refusal strip. ## Verification Read first: 1. `ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx`, AutomationsPillar `doSave` and `toggleEnabled`: the publish after the draft, and the switch writing the stored flow, not the buffer. 2. `ui/packages/app-shell/src/views/studio-design/objectHooksBuffer.ts`, `save`: a new hook versus an existing one, and the re-pin after a refused or a landed publish. 3. `ui/packages/app-shell/src/views/studio-design/pairObjectActions.ts`, `save`: deletes first, then each draft and its publish, with refusals collected. Two minutes: open Studio on a self-built app, then Automations. Change a step's label: Cancel and Save appear at the top right. Press Save: the toast says the flow is saved, and reopening the app shows the label. Flip the switch: the toast says it is live now, with no Save and no Publish. <details><summary>Local gates at bf7dbf0</summary> Derived with `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` at bf7dbf0: 38 families, all run with exit 0. `pnpm --dir ui exec vitest run scripts/` ran under the lock: `Test Files 172 passed | 2 skipped`. Reconciled with `--ran`: `38 derived famil(ies) accounted for — 38 run, 0 NOT-MEASURED (a DERIVED zero — all 38 recorded an exit code and none of them is 3)`. `overlap-check`: clean against origin/main 4ef1ea9. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmPsv99YG2tCHoSe8Nb --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent e9fa6b5 commit f590f3e

32 files changed

Lines changed: 1806 additions & 1023 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(studio): hooks, an installed app's added actions and flows save with the top bar, and a Save is live at once
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
The Studio's hooks, the actions an installed app's object gains in its `.custom` package and flows no longer autosave a draft 1.5 s after each edit. Edits stay on the page until the author presses Save in the top bar; Cancel puts them back as the server holds them. Save writes each edited item's draft and then publishes that one item at the package it was written to, so the change is live at once. A new hook or an added action is written only by Save, and a removed added action is deleted by Save.
12+
13+
A flow's on/off switch needs no Save: a flip writes the stored flow with the new status and publishes it at once, leaving any unsaved canvas edit on the page for Save. A new flow is published as it is created, switched off, so switching it on makes it live straight away. The inspector footers and the Studio landing say that Save makes a change live; permission sets follow in a separate change.

‎ui/packages/app-shell/src/views/metadata-admin/DirectoryPage.stateVocabulary-29705.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ describe('one word per state, the second pass (objectstack#29729)', () => {
362362
'engine.studio.customize.walled',
363363
'engine.studio.customize.noVersion',
364364
'engine.studio.customize.draftFooter',
365+
'engine.studio.customize.saveFooter',
365366
'engine.studio.customize.restoreBody',
366367
'engine.studio.customize.restoreFlowBody',
367368
'engine.edit.resetConfirmBody',

‎ui/packages/app-shell/src/views/studio-design/AutomationsPillar.customizeFlow-28570.test.tsx‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const srv = vi.hoisted(() => ({
9292
saveRefusal: null as null | { status: number; message: string },
9393
saves: [] as Array<{ name: string; body: Record<string, unknown>; opts: Record<string, unknown> }>,
9494
resets: [] as Array<{ name: string; opts: Record<string, unknown> }>,
95+
publishes: [] as Array<{ name: string; opts: Record<string, unknown> }>,
9596
version: 0,
9697
/** Whether the engine's `_status` answer holds a row for the flow. */
9798
statusRow: true,
@@ -137,6 +138,16 @@ const mockClient = vi.hoisted(() => ({
137138
srv.version += 1;
138139
return { success: true, version: `v${srv.version}`, state: 'draft' };
139140
}),
141+
// objectstack#36511 — a Save publishes the one flow it wrote: the pair's draft
142+
// becomes its published row.
143+
publish: vi.fn(async (_type: string, name: string, opts: Record<string, unknown> = {}) => {
144+
srv.publishes.push({ name, opts: clone(opts) });
145+
if (opts.packageId === PAIR && srv.pairDraft) {
146+
srv.pairActive = srv.pairDraft;
147+
srv.pairDraft = null;
148+
}
149+
return { success: true };
150+
}),
140151
reset: vi.fn(async (_type: string, name: string, opts: Record<string, unknown> = {}) => {
141152
srv.resets.push({ name, opts: clone(opts) });
142153
if (opts.packageId === PAIR) {
@@ -159,12 +170,15 @@ vi.mock('@object-ui/react', async (importOriginal) => {
159170

160171
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn(), info: vi.fn(), warning: vi.fn() } }));
161172

173+
// The source reaches a dynamic `import('@objectstack/lint')`: its first load is paid at collection (`check:test-source-alias`).
174+
import '@objectstack/lint';
162175
import { AutomationsPillar, type StudioBaseCustomization } from './StudioDesignSurface';
163176
import { ensureCustomizationPackage } from './packages-io';
164177
import { registerMetadataPreview } from '../metadata-admin/preview-registry';
165178
import { publishRefusal } from './metadataError';
166179
import { t, tFormat } from '../metadata-admin/i18n';
167180
import { createEmptyDataSource } from './__tests__/emptyDataSource';
181+
import { StudioSaveHarness, pressStudioSave } from './__tests__/studioSaveHarness';
168182

169183
const dataSource = createEmptyDataSource();
170184

@@ -221,6 +235,7 @@ beforeEach(() => {
221235
srv.saveRefusal = null;
222236
srv.saves.length = 0;
223237
srv.resets.length = 0;
238+
srv.publishes.length = 0;
224239
srv.version = 0;
225240
srv.statusRow = true;
226241
for (const fn of Object.values(mockClient)) (fn as unknown as { mockClear: () => void }).mockClear();
@@ -262,9 +277,11 @@ function Host({
262277

263278
function mount(props: React.ComponentProps<typeof Host> = {}) {
264279
return render(
265-
<MemoryRouter initialEntries={[`/studio/${BASE}/automations`]}>
266-
<Host {...props} />
267-
</MemoryRouter>,
280+
<StudioSaveHarness>
281+
<MemoryRouter initialEntries={[`/studio/${BASE}/automations`]}>
282+
<Host {...props} />
283+
</MemoryRouter>
284+
</StudioSaveHarness>,
268285
);
269286
}
270287

@@ -331,7 +348,12 @@ describe('Customize a read-only base’s flow into its pair (objectstack#28570)'
331348
await customize();
332349

333350
patchFlow();
351+
await sleep(1500);
352+
expect(srv.saves, 'nothing is written before Save (objectstack#36511)').toEqual([]);
353+
await pressStudioSave();
334354
await waitFor(() => expect(srv.saves).toHaveLength(1), { timeout: 8000 });
355+
// Then that one flow is published at the pair: the override is live.
356+
await waitFor(() => expect(srv.publishes).toEqual([{ name: FLOW_NAME, opts: { packageId: PAIR } }]));
335357
expect(srv.ensure).toEqual([201]);
336358
const [saved] = srv.saves;
337359
expect(saved!.name).toBe(FLOW_NAME);
@@ -353,11 +375,13 @@ describe('Customize a read-only base’s flow into its pair (objectstack#28570)'
353375
await waitFor(() => expect(screen.queryByTestId('studio-override-popover')).toBeNull());
354376
await expectLedgerSwitchAlone();
355377

356-
// A later edit asks the door no more, and is pinned to the version it was answered.
378+
// A later edit asks the door no more; its draft was published, so the next
379+
// save asserts no draft again.
357380
patchFlow();
381+
await pressStudioSave();
358382
await waitFor(() => expect(srv.saves).toHaveLength(2), { timeout: 8000 });
359383
expect(srv.ensure).toEqual([201]);
360-
expect(srv.saves[1]!.opts).toMatchObject({ packageId: PAIR, ifMatch: 'v1' });
384+
expect(srv.saves[1]!.opts).toMatchObject({ packageId: PAIR, ifNoneMatch: '*' });
361385
expect(srv.saves[1]!.body.overrides).toEqual(DECLARATION);
362386
expect(calls('/toggle')).toHaveLength(0);
363387
});
@@ -385,6 +409,7 @@ describe('Customize a read-only base’s flow into its pair (objectstack#28570)'
385409
// Its editors are open: an edit is saved into the pair, keeping the declaration.
386410
fireEvent.keyDown(document.activeElement ?? document.body, { key: 'Escape' });
387411
patchFlow();
412+
await pressStudioSave();
388413
await waitFor(() => expect(srv.saves).toHaveLength(1), { timeout: 8000 });
389414
expect(srv.saves[0]!.opts.packageId).toBe(PAIR);
390415
expect(srv.saves[0]!.body.overrides).toEqual(DECLARATION);
@@ -436,6 +461,7 @@ describe('Customize a read-only base’s flow into its pair (objectstack#28570)'
436461
await customize();
437462
expect(within(header()).queryByRole('switch')).toBeNull();
438463
patchFlow();
464+
await pressStudioSave();
439465
await waitFor(() => expect(srv.saves).toHaveLength(1), { timeout: 8000 });
440466
await within(header()).findByTestId('studio-override-chip', undefined, { timeout: 8000 });
441467
expect(within(header()).queryByRole('switch')).toBeNull();
@@ -470,6 +496,7 @@ describe('Customize a read-only base’s flow into its pair (objectstack#28570)'
470496
await openFlow();
471497
await customize();
472498
patchFlow();
499+
await pressStudioSave();
473500
expect(await screen.findByTestId('studio-refusal-message', undefined, { timeout: 8000 })).toHaveTextContent(sentence);
474501
expect(within(header()).queryByTestId('studio-override-chip')).toBeNull();
475502
});

‎ui/packages/app-shell/src/views/studio-design/AutomationsPillar.heldIncomplete-11786.test.tsx‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ vi.mock('@object-ui/react', async (importOriginal) => {
8787

8888
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
8989

90+
// The source reaches a dynamic `import('@objectstack/lint')`: its first load is paid at collection (`check:test-source-alias`).
91+
import '@objectstack/lint';
9092
import { AutomationsPillar } from './StudioDesignSurface';
93+
import { StudioSaveHarness, pressStudioSave } from './__tests__/studioSaveHarness';
9194
import { createEmptyDataSource } from './__tests__/emptyDataSource';
9295
import { registerMetadataPreview } from '../metadata-admin/preview-registry';
9396
import { registerMetadataInspector } from '../metadata-admin/inspector-registry';
@@ -131,9 +134,11 @@ async function outlastDebounce(): Promise<void> {
131134
/** Open the flow and add a Notify step on its one edge, as an author does. */
132135
async function addNotify(): Promise<string> {
133136
render(
134-
<MemoryRouter initialEntries={[`/studio/${PKG}/automations`]}>
135-
<AutomationsPillar packageId={PKG} />
136-
</MemoryRouter>,
137+
<StudioSaveHarness>
138+
<MemoryRouter initialEntries={[`/studio/${PKG}/automations`]}>
139+
<AutomationsPillar packageId={PKG} />
140+
</MemoryRouter>
141+
</StudioSaveHarness>,
137142
);
138143
fireEvent.click(await screen.findByRole('button', { name: 'Insert node here' }, { timeout: 8000 }));
139144
const option = screen.getAllByRole('option').find((o) => o.textContent?.startsWith('Notify'));
@@ -168,6 +173,9 @@ describe('Automations page — a new Notify step is held until it is filled in (
168173
fireEvent.change(within(rail).getByPlaceholderText('Your request was approved'), {
169174
target: { value: 'Request approved' },
170175
});
176+
// objectstack#36511 — filled in, the step is no longer held, and Save sends it.
177+
await waitFor(() => expect(screen.queryByTestId('studio-held')).toBeNull());
178+
await pressStudioSave();
171179
await waitFor(() => expect(mockClient.save).toHaveBeenCalledTimes(1), { timeout: 4000 });
172180
const sent = mockClient.saves[0].nodes as Array<Record<string, unknown>>;
173181
expect(sent.find((n) => n.id === id)).toEqual(

‎ui/packages/app-shell/src/views/studio-design/AutomationsPillar.problemsAgree-27799.test.tsx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ vi.mock('../metadata-admin/previews/useObjectFields', () => ({
126126

127127
import { AutomationsPillar } from './StudioDesignSurface';
128128
import { createEmptyDataSource } from './__tests__/emptyDataSource';
129+
import { StudioSaveHarness, pressStudioSave } from './__tests__/studioSaveHarness';
129130
import { getMetadataPreview, registerMetadataPreview } from '../metadata-admin/preview-registry';
130131
import { registerMetadataInspector } from '../metadata-admin/inspector-registry';
131132
import { FlowInspector } from '../metadata-admin/inspectors/FlowInspector';
@@ -173,9 +174,11 @@ afterEach(() => {
173174
/** Open the flow, select Update Records, add the value `id` and switch it to a blank expression. */
174175
async function writeBlankExpression() {
175176
render(
176-
<MemoryRouter initialEntries={[`/studio/${PKG}/automations`]}>
177-
<AutomationsPillar packageId={PKG} />
178-
</MemoryRouter>,
177+
<StudioSaveHarness>
178+
<MemoryRouter initialEntries={[`/studio/${PKG}/automations`]}>
179+
<AutomationsPillar packageId={PKG} />
180+
</MemoryRouter>
181+
</StudioSaveHarness>,
179182
);
180183
fireEvent.click(await screen.findByRole('button', { name: 'select write' }, { timeout: 8000 }));
181184
// The node has two maps (Filter, Field values); the value goes in Field values.
@@ -209,7 +212,9 @@ describe('Automations page — Problems and the node agree on a blank expression
209212
// The node: business words, not the envelope's wire shape.
210213
expect(within(map).getByRole('alert').textContent).toBe(NEEDED());
211214

212-
// The draft is stored, and its verdict read again …
215+
// Saved (objectstack#36511: by the top bar's Save), and its verdict read
216+
// again. The double keeps serving the stored draft with its verdict.
217+
await pressStudioSave();
213218
await waitFor(() => expect(mockClient.save).toHaveBeenCalled(), { timeout: 6000 });
214219
await waitFor(() => expect(server.draftReads).toBeGreaterThan(readsBefore), { timeout: 6000 });
215220

@@ -227,6 +232,7 @@ describe('Automations page — Problems and the node agree on a blank expression
227232

228233
it('control: once the expression is written, the cell and the Problems list clear together', async () => {
229234
const { map } = await writeBlankExpression();
235+
await pressStudioSave();
230236
await waitFor(() => expect(mockClient.save).toHaveBeenCalled(), { timeout: 6000 });
231237
fireEvent.click(screen.getByTestId('auto-tab-problems'));
232238
await screen.findByTestId('flow-problem-target', {}, { timeout: 6000 });
@@ -237,6 +243,7 @@ describe('Automations page — Problems and the node agree on a blank expression
237243
fireEvent.blur(source);
238244

239245
expect(within(map).queryByRole('alert')).toBeNull();
246+
await pressStudioSave();
240247
await waitFor(() => expect(mockClient.save.mock.calls.length).toBeGreaterThan(saves), { timeout: 6000 });
241248
expect(await screen.findByText(EMPTY(), {}, { timeout: 6000 })).toBeInTheDocument();
242249
expect(screen.queryByTestId('flow-problem-target')).toBeNull();

0 commit comments

Comments
 (0)