Skip to content

Commit 5f741ed

Browse files
fix(app-shell): AI-draft notice and discard on the Hooks tab, paired actions and OWD rows (#38285)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao153cRYFjsg9HJ2VwLVqVbD)_ Fixes #36660 repo:objectstack#3 · os-tesla · session_01L9qibxGxp6swERUK2T9NML Clause-②: no Metadata-protocol: none ## 维护者速读 - 在对象设计器的「钩子」页、只读基础对象「动作」页里的配套包动作、以及共享默认值总览的每一行上,如果 AI 助手留下了未发布的改动,现在会显示一行提示,说明保存会让 AI 的改动一起生效,并给一个「放弃 AI 的改动」按钮;以前保存会悄悄把它们一起发布。 - 属于「AI 改动要让人看见再生效」这条线:权限集和从左侧菜单打开的钩子、动作已经有这行提示,这次补齐剩下的三处。 - 只在草稿确实来自 AI 助手时才显示,人自己的草稿不受影响;放弃只丢这一项(共享默认值这一行是整个对象)的草稿,有没保存的编辑时会先确认。如果提示出现得不对,只是多一行文字和按钮,可以直接撤回。 - 无 ## What changes - **Object designer, Hooks tab** (`objectHooksBuffer.ts`, `ObjectHooksPanel.tsx`): - The buffer's load records which hooks have a pending draft whose provenance (`readDraftChanges`) names the AI assistant (`isAgentDraftSurface`: copilot or MCP). The set clears on an object switch and on a successful save. - The open hook shows `StudioAiDraftNotice` when its draft is the AI's and the hook is not a new one. The notice's discard calls the buffer's new `discardAiDraft`. - `discardAiDraft` asks `engine.studio.aiDraft.discardConfirmUnsaved` only when the hook holds unsaved edits. It then calls `client.reset('hook', name, { state: 'draft', packageId })`, the hook's own package, re-reads the list and emits the metadata refresh. A failure reads `engine.studio.aiDraft.discardFailed`. - **Paired package's actions on a read-only base object** (`pairObjectActions.ts`, `ObjectActionsPanel.tsx`): - A draft row whose provenance names the AI assistant carries `aiDraft`. A successful save, and a discard, put the row back to its live form. - The selected row shows the notice above the inspector. Discard is offered only where the row is editable. - `discardAiDraft(name)` asks only when that row holds an unsaved edit. It resets at the package the ensure door answers (`pairForWrite()`), never a hand-built `<base>.custom` name, then reloads. - **Organization-wide defaults overview** (`PackageOwdOverviewPanel.tsx`), seat ruling Q1 = A: - Each row reads its object's draft provenance. When the AI assistant wrote it, the row shows the notice with the OWD sentence, `engine.studio.owd.aiDraftNotice`: the whole object has the AI's unpublished changes, and saving this row makes all of them live. The plain "unpublished" chip is not shown beside it. - Discard drops that object's whole draft at the package (`client.reset('object', name, { state: 'draft', packageId })`). It asks `engine.studio.owd.aiDraftDiscardConfirmUnsaved` only when that row holds an unsaved edit. Other rows' unsaved edits are kept across the re-read. - `StudioAiDraftNotice.tsx`: an optional `text` prop, for a page that names what the draft covers. Without it the item sentence shows, as before. - i18n (`studio` namespace, en + zh): the two OWD keys above. Changeset `36660-owd-ai-draft-notice.md`: `@object-ui/i18n` patch. `@object-ui/app-shell` is private. - The hook list rows get no AI marker (seat ruling). ## Tests Three new files, 19 cases. Each covers the AI line for copilot and for MCP, no line for a person's draft or for a draft read with no provenance, discard with nothing unsaved (no confirm, one reset at the right package), and discard over an unsaved edit both declined and confirmed. - `ObjectHooksPanel.aiDraftNotice-36660.test.tsx` (7): through the Hooks tab host and the top bar's Save. Save publishes the AI version and the line goes away. - `DataPillar.pairActionsAiDraft-36660.test.tsx` (6): a read-only base object with a paired package. The reset names the door's pair. - `PackageOwdOverviewPanel.aiDraftNotice-36660.test.tsx` (6): the row's OWD sentence, the whole object's reset, and another row's unsaved edit surviving a discard. ## Acceptance notes - **Premise corrected at the claim:** the permission set and the hook and action opened from the left menu already carry the notice (#37089, #36902). This PR covers the three surfaces left. - **Out of scope, for the seat to decide on filing:** for an item the AI created and never published, the notice's discard tooltip reads "Drop this item’s unpublished draft and go back to the live version", while the discard removes the item. Seat ruling Q2: not in this card. - The local test run was narrowed to the files these changes reach (below). CI runs the whole app-shell suite. - The browser reading used a writable package made for the run, since the showcase package is managed (its writes answer `ITEM_LOCKED`). The HTTP doors refuse a copilot surface, so the draft's provenance was stamped as copilot in the stored draft row, and the served read confirmed `draftChanges[].by = copilot`. ## Verification <details><summary>Failing first, then green</summary> - On the base sources with the new tests: 15 failed, 4 passed. The 4 are the person's-draft and no-provenance controls. Failures: `Unable to find … studio-ai-draft-discard` ×9, `studio-ai-draft-notice` ×6. - With the change: 3 files, 19/19 passed. </details> <details><summary>Ablation</summary> Two parts removed on disk and restored (blob equal to HEAD afterwards): the OWD put-back of other rows' edits, and the hooks agent-surface check (any draft counts). 3 failed, 10 passed: OWD "another row keeps its edit", and hooks "a person's own pending draft" and "no provenance". </details> <details><summary>Wider runs</summary> - Affected test files: 328/328 files, 2574/2574 tests. - `@object-ui/app-shell` `tsc --noEmit` exit 0, `tsc -p tsconfig.test.json` exit 0. ESLint on the changed files: 0 errors, 5 warnings that were already there. - Derived gates at 4fd9904: 38 of 38 run, all exit 0, `dispatch-gates --ran` accounted. `pnpm --dir ui exec vitest run scripts/`: 172 files passed, 2 skipped. - `overlap-check`: clean against `origin/main` and #38204 (shares the studio i18n files). </details> <details><summary>Browser reading, real console build</summary> Vite console against a showcase backend, signed in, Studio → package → organization-wide defaults. Two objects in the package. The one with a copilot-stamped draft shows under its name: "This object has unpublished changes from the AI assistant. Saving this row makes all of them live too." with "Discard the AI’s changes" (1 line, 1 button). The other object's row shows no line. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibxGxp6swERUK2T9NML)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L9qibxGxp6swERUK2T9NML --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4ebe9a1 commit 5f741ed

12 files changed

Lines changed: 992 additions & 13 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/i18n': patch
3+
---
4+
5+
feat(i18n): the Studio sharing-defaults overview's line and confirm for an object the AI assistant left unpublished changes on
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Two keys join the studio namespace in English and Chinese: `engine.studio.owd.aiDraftNotice`, the line an organization-wide-defaults row shows when the AI assistant (copilot or MCP) left unpublished changes on that object, and `engine.studio.owd.aiDraftDiscardConfirmUnsaved`, the confirm its discard asks when the row also holds an edit the person has not saved. Both name the whole object, since saving or discarding that row reaches the object's whole pending draft. No key is renamed or removed.
Lines changed: 341 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,341 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#36660 — on a read-only base's object, an action the base's pair
5+
* adds is its own `action` item, buffered from its pending draft and published
6+
* by the top bar's Save. When the AI assistant (copilot or MCP) wrote that
7+
* draft, the open action carries the designers' line (`StudioAiDraftNotice`):
8+
* Save makes the AI's change live too, and 「放弃 AI 的改动」 drops that one
9+
* action's draft at the pair the ensure door answers, asking first only over
10+
* the row's unsaved edit. A person's own draft gets no such line.
11+
*
12+
* The REAL `DataPillar`, Actions view and action editor over the metadata
13+
* client double of DataPillar.pairActions-30088.test.tsx.
14+
*/
15+
16+
import '@testing-library/jest-dom/vitest';
17+
import * as React from 'react';
18+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
19+
// Module scope as well as in the `vi.mock` factory below: the cold transform is paid
20+
// during collection, which no test or hook timeout clocks (AGENTS.md, flaky-test discipline).
21+
import '@object-ui/components';
22+
import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
23+
import { MemoryRouter } from 'react-router-dom';
24+
25+
const BASE = 'com.example.crm';
26+
const PAIR = 'com.example.crm.custom';
27+
const OBJECT = 'crm_lead';
28+
29+
/** The vendor's action, served on the object. */
30+
const VENDOR = {
31+
name: 'crm_lead_convert',
32+
label: 'Convert',
33+
objectName: OBJECT,
34+
locations: ['record_page'],
35+
type: 'script',
36+
body: { language: 'expression', source: 'true' },
37+
};
38+
39+
/** An action the pair already holds on the object: published, and with a pending draft. */
40+
const KEPT = {
41+
name: 'crm_lead_action_7',
42+
label: 'Qualify',
43+
objectName: OBJECT,
44+
locations: ['record_page'], component: 'action:menu',
45+
operation: 'update',
46+
patch: { status: 'qualified' },
47+
};
48+
49+
const srv = vi.hoisted(() => ({
50+
/** The pair's published actions (every object's). */
51+
pairPublished: [] as Array<Record<string, unknown>>,
52+
/** The pair's pending action drafts, by name. */
53+
pairDrafts: {} as Record<string, Record<string, unknown>>,
54+
/** The provenance each pair draft's read serves, by name (absent: none recorded). */
55+
pairDraftChanges: {} as Record<string, Array<Record<string, unknown>>>,
56+
/**
57+
* objectstack#35054 — what the pair's layered read serves for an action, by
58+
* name, where it differs from the served reads above (which are then the
59+
* translated copies). `draft: undefined` serves no `draft` key at all.
60+
*/
61+
stored: {} as Record<string, { published: Record<string, unknown> | null; draft?: Record<string, unknown> | null }>,
62+
}));
63+
64+
const servedObject = () => ({
65+
name: OBJECT,
66+
label: 'Lead',
67+
fields: {
68+
name: { type: 'text', label: 'Name' },
69+
status: {
70+
type: 'select',
71+
label: 'Status',
72+
options: [
73+
{ label: 'New', value: 'new' },
74+
{ label: 'Qualified', value: 'qualified' },
75+
],
76+
},
77+
},
78+
// The published pair action is served folded into the object, under the pair.
79+
actions: [VENDOR, ...srv.pairPublished.filter((a) => a.objectName === OBJECT).map((a) => ({ ...a, _packageId: PAIR }))],
80+
});
81+
82+
const mockClient = {
83+
list: vi.fn(async (type: string, opts?: { packageId?: string }) => {
84+
if (type === 'action') return opts?.packageId === PAIR ? srv.pairPublished.map((a) => ({ ...a, _packageId: PAIR })) : [];
85+
if (type === 'object') return opts?.packageId === PAIR ? [] : [{ name: OBJECT, label: 'Lead' }];
86+
return [];
87+
}),
88+
listDrafts: vi.fn(async (opts?: { packageId?: string; type?: string }) =>
89+
opts?.type === 'action' && opts.packageId === PAIR
90+
? Object.keys(srv.pairDrafts).map((name) => ({ type: 'action', name }))
91+
: [],
92+
),
93+
layered: vi.fn(async (type: string, name: string, opts?: { packageId?: string }) => {
94+
if (type === 'action' && opts?.packageId === PAIR) {
95+
// The pair's action as stored: by default the served rows (no translation in play).
96+
const own = srv.stored[name];
97+
if (own) {
98+
const layers: Record<string, unknown> = { code: null, overlay: own.published, effective: own.published };
99+
if ('draft' in own) layers.draft = own.draft;
100+
return layers;
101+
}
102+
const published = srv.pairPublished.find((a) => a.name === name) ?? null;
103+
return { code: null, overlay: published, effective: published, draft: srv.pairDrafts[name] ?? null };
104+
}
105+
return { effective: servedObject(), code: servedObject() };
106+
}),
107+
getDraft: vi.fn(async (type: string, name: string, opts?: { packageId?: string }) =>
108+
type === 'action' && opts?.packageId === PAIR && srv.pairDrafts[name]
109+
? // Served decorated, as the draft read serves it.
110+
{
111+
type,
112+
name,
113+
item: { ...srv.pairDrafts[name], _packageId: PAIR },
114+
version: 'v1',
115+
...(srv.pairDraftChanges[name] ? { draftChanges: srv.pairDraftChanges[name] } : {}),
116+
}
117+
: null,
118+
),
119+
get: vi.fn(async () => null),
120+
// The pair's action drafts are kept, so a read after a write serves them.
121+
// A publish makes the pair's draft its published action, as the door does.
122+
publish: vi.fn(async (type: string, name: string, opts?: { packageId?: string }) => {
123+
if (type === 'action' && opts?.packageId === PAIR && srv.pairDrafts[name]) {
124+
srv.pairPublished = [...srv.pairPublished.filter((a) => a.name !== name), srv.pairDrafts[name]!];
125+
delete srv.pairDrafts[name];
126+
delete srv.pairDraftChanges[name];
127+
}
128+
return {};
129+
}),
130+
save: vi.fn(async (type: string, name: string, body: unknown, opts?: { packageId?: string }) => {
131+
if (type === 'action' && opts?.packageId === PAIR) srv.pairDrafts[name] = body as Record<string, unknown>;
132+
return { ok: true, version: 'v2', state: 'draft' };
133+
}),
134+
reset: vi.fn(async (type: string, name: string, opts?: { packageId?: string; state?: string }) => {
135+
if (type === 'action' && opts?.packageId === PAIR) {
136+
if (opts.state === 'draft') delete srv.pairDrafts[name];
137+
else srv.pairPublished = srv.pairPublished.filter((a) => a.name !== name);
138+
}
139+
return { ok: true };
140+
}),
141+
withPreviewDrafts() {
142+
return this;
143+
},
144+
};
145+
146+
vi.mock('../metadata-admin/useMetadata', async (importOriginal) => {
147+
const mod = await importOriginal<typeof import('../metadata-admin/useMetadata')>();
148+
return { ...mod, useMetadataClient: () => mockClient, useMetadataTypes: () => ({ entries: [] }) };
149+
});
150+
151+
vi.mock('./packages-io', async (importOriginal) => {
152+
const mod = await importOriginal<typeof import('./packages-io')>();
153+
return { ...mod, fetchPackages: vi.fn(async () => []) };
154+
});
155+
156+
// The Advanced views live in a Radix DropdownMenu; rendered as passthroughs,
157+
// as in DataPillar.actionRefusal-26736.test.tsx.
158+
type PassthroughProps = { children?: React.ReactNode; onSelect?: () => void };
159+
vi.mock('@object-ui/components', async (importOriginal) => {
160+
const mod = await importOriginal<typeof import('@object-ui/components')>();
161+
return {
162+
...mod,
163+
DropdownMenu: (p: PassthroughProps) => <div>{p.children}</div>,
164+
DropdownMenuTrigger: (p: PassthroughProps) => <div>{p.children}</div>,
165+
DropdownMenuContent: (p: PassthroughProps) => <div>{p.children}</div>,
166+
DropdownMenuItem: (p: PassthroughProps) => (
167+
<button type="button" onClick={() => p.onSelect?.()}>{p.children}</button>
168+
),
169+
DropdownMenuRadioGroup: (p: PassthroughProps) => <div>{p.children}</div>,
170+
DropdownMenuRadioItem: (p: PassthroughProps) => (
171+
<button type="button" onClick={() => p.onSelect?.()}>{p.children}</button>
172+
),
173+
};
174+
});
175+
176+
vi.mock('@object-ui/react', async (importOriginal) => {
177+
const mod = await importOriginal<typeof import('@object-ui/react')>();
178+
return { ...mod, useAdapter: () => dataSource };
179+
});
180+
181+
// The pillar reaches a dynamic `import('@objectstack/lint')`: pay its load at
182+
// collection, never inside a case's clocked window (`check:test-source-alias`).
183+
import '@objectstack/lint';
184+
import '@object-ui/plugin-detail';
185+
import { DataPillar, type StudioBaseCustomization } from './StudioDesignSurface';
186+
import { StudioSaveHarness, pressStudioSave } from './__tests__/studioSaveHarness';
187+
import { createEmptyDataSource } from './__tests__/emptyDataSource';
188+
import { registerBuiltinInspectors } from '../metadata-admin/inspectors';
189+
import { t } from '../metadata-admin/i18n';
190+
import { indexCustomizations } from './customizationMarks';
191+
import type { PackageCustomizationsState } from './CustomizationMark';
192+
193+
const dataSource = createEmptyDataSource();
194+
registerBuiltinInspectors();
195+
196+
const L = (key: string) => t(key, 'en');
197+
const confirmSpy = vi.fn((_message?: string) => true);
198+
const ensure = vi.fn(async (): Promise<string> => PAIR);
199+
200+
/** The base's customization read: the pair overrides nothing. */
201+
function marksRead(): PackageCustomizationsState {
202+
const read = {
203+
packageId: BASE,
204+
overrides: [],
205+
extensions: [],
206+
switchedOff: [],
207+
contributions: [],
208+
counts: { overrides: 0, extensions: 0, switchedOff: 0 },
209+
} as never;
210+
return { status: 'read', read, index: indexCustomizations(BASE, read)!, baseName: 'CRM', contributorNames: new Map() };
211+
}
212+
213+
function customizationOf(over: Partial<StudioBaseCustomization> = {}): StudioBaseCustomization {
214+
return {
215+
base: BASE,
216+
baseLabel: 'CRM',
217+
basedOn: '4.0.0',
218+
walled: false,
219+
pairId: PAIR,
220+
ensure,
221+
ensurePackage: vi.fn() as unknown as StudioBaseCustomization['ensurePackage'],
222+
marks: marksRead(),
223+
...over,
224+
};
225+
}
226+
227+
beforeEach(() => {
228+
srv.pairPublished = [];
229+
srv.pairDrafts = {};
230+
srv.pairDraftChanges = {};
231+
srv.stored = {};
232+
confirmSpy.mockReset();
233+
confirmSpy.mockReturnValue(true);
234+
vi.stubGlobal('confirm', confirmSpy);
235+
ensure.mockImplementation(async () => PAIR);
236+
});
237+
238+
afterEach(() => {
239+
cleanup();
240+
vi.unstubAllGlobals();
241+
vi.clearAllMocks();
242+
});
243+
244+
async function mountOnActions(props: { readOnly: boolean; customization?: StudioBaseCustomization | null }) {
245+
render(
246+
<StudioSaveHarness><MemoryRouter initialEntries={[`/studio/${BASE}/data`]}>
247+
<DataPillar objectName={OBJECT} packageId={BASE} readOnly={props.readOnly} customization={props.customization ?? null} />
248+
</MemoryRouter></StudioSaveHarness>,
249+
);
250+
// The first match is the flat tab (the passthrough menu draws a second).
251+
fireEvent.click((await screen.findAllByRole('button', { name: L('engine.studio.data.tab.actions') }, { timeout: 8000 }))[0]);
252+
await within(await screen.findByTestId('actions-list', undefined, { timeout: 8000 })).findByText('Convert');
253+
}
254+
255+
/** Past the retired autosave's 1.5 s debounce: nothing may leave before Save. */
256+
async function outlastDebounce(): Promise<void> {
257+
await act(async () => {
258+
await new Promise((r) => setTimeout(r, 2300));
259+
});
260+
}
261+
262+
const list = () => screen.getByTestId('actions-list');
263+
264+
const AI_KEPT = { ...KEPT, label: 'Qualify (AI)', patch: { status: 'new' } };
265+
const AI_CHANGE = { path: ['patch'], by: 'copilot', actor: 'u1', at: '2026-11-27T10:00:00.000Z' };
266+
const notice = () => screen.queryByTestId('studio-ai-draft-notice');
267+
268+
async function openAiRow(changes: Array<Record<string, unknown>> | null = [AI_CHANGE]) {
269+
srv.pairPublished = [KEPT];
270+
srv.pairDrafts = { [KEPT.name]: AI_KEPT };
271+
srv.pairDraftChanges = changes ? { [KEPT.name]: changes } : {};
272+
await mountOnActions({ readOnly: true, customization: customizationOf() });
273+
fireEvent.click(await within(list()).findByText('Qualify (AI)', undefined, { timeout: 8000 }));
274+
}
275+
276+
describe('a pair action\'s pending draft written by the AI assistant (objectstack#36660)', () => {
277+
it('the open action shows the AI version with the notice, and a person\'s Save makes it live', async () => {
278+
await openAiRow();
279+
expect(await screen.findByTestId('studio-ai-draft-notice')).toHaveTextContent(L('engine.studio.aiDraft.notice'));
280+
fireEvent.change(screen.getByRole('textbox', { name: L('engine.inspector.action.label') }), {
281+
target: { value: 'Qualify (AI, reviewed)' },
282+
});
283+
await pressStudioSave();
284+
await waitFor(() => expect(mockClient.publish).toHaveBeenCalledTimes(1));
285+
expect(mockClient.publish).toHaveBeenCalledWith('action', KEPT.name, { packageId: PAIR, draftVersion: expect.any(String) });
286+
await waitFor(() => expect(notice()).toBeNull());
287+
}, 30_000);
288+
289+
it('an MCP-written draft is the AI\'s too', async () => {
290+
await openAiRow([{ ...AI_CHANGE, by: 'mcp' }]);
291+
expect(await screen.findByTestId('studio-ai-draft-notice')).toBeInTheDocument();
292+
}, 30_000);
293+
294+
it('a person\'s own pending draft, or one whose read recorded nothing, gets no AI line', async () => {
295+
await openAiRow([{ ...AI_CHANGE, by: 'studio' }]);
296+
expect(screen.getByRole('textbox', { name: L('engine.inspector.action.label') })).toHaveValue('Qualify (AI)');
297+
expect(notice()).toBeNull();
298+
cleanup();
299+
await openAiRow(null);
300+
expect(screen.getByRole('textbox', { name: L('engine.inspector.action.label') })).toHaveValue('Qualify (AI)');
301+
expect(notice()).toBeNull();
302+
}, 30_000);
303+
304+
it('discard with nothing unsaved asks nothing and drops that one action\'s draft at the door\'s pair; the published action is back', async () => {
305+
await openAiRow();
306+
fireEvent.click(await screen.findByTestId('studio-ai-draft-discard'));
307+
await waitFor(() => expect(mockClient.reset).toHaveBeenCalledTimes(1));
308+
expect(confirmSpy).not.toHaveBeenCalled();
309+
expect(mockClient.reset).toHaveBeenCalledWith('action', KEPT.name, { state: 'draft', packageId: PAIR });
310+
expect(ensure).toHaveBeenCalledTimes(1);
311+
expect(mockClient.publish).not.toHaveBeenCalled();
312+
expect(await within(list()).findByText('Qualify', undefined, { timeout: 8000 })).toBeInTheDocument();
313+
await waitFor(() => expect(notice()).toBeNull());
314+
expect(within(list()).queryByText('Qualify (AI)')).toBeNull();
315+
}, 30_000);
316+
317+
it('discard over the row\'s unsaved edit asks first; declined, nothing is sent and the edit stays', async () => {
318+
confirmSpy.mockReturnValue(false);
319+
await openAiRow();
320+
const label = screen.getByRole('textbox', { name: L('engine.inspector.action.label') });
321+
fireEvent.change(label, { target: { value: 'Unsaved' } });
322+
fireEvent.click(screen.getByTestId('studio-ai-draft-discard'));
323+
expect(confirmSpy).toHaveBeenCalledWith(L('engine.studio.aiDraft.discardConfirmUnsaved'));
324+
await outlastDebounce();
325+
expect(mockClient.reset).not.toHaveBeenCalled();
326+
expect(label).toHaveValue('Unsaved');
327+
expect(notice()).toBeInTheDocument();
328+
}, 30_000);
329+
330+
it('discard over the row\'s unsaved edit, confirmed: the draft and the edit go', async () => {
331+
await openAiRow();
332+
fireEvent.change(screen.getByRole('textbox', { name: L('engine.inspector.action.label') }), {
333+
target: { value: 'Unsaved' },
334+
});
335+
fireEvent.click(screen.getByTestId('studio-ai-draft-discard'));
336+
expect(confirmSpy).toHaveBeenCalledTimes(1);
337+
await waitFor(() => expect(mockClient.reset).toHaveBeenCalledWith('action', KEPT.name, { state: 'draft', packageId: PAIR }));
338+
expect(await within(list()).findByText('Qualify', undefined, { timeout: 8000 })).toBeInTheDocument();
339+
await waitFor(() => expect(notice()).toBeNull());
340+
}, 30_000);
341+
});

‎ui/packages/app-shell/src/views/studio-design/ObjectActionsPanel.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import type { PairActionsDoor, PairObjectActions } from './pairObjectActions.js'
9797
import { RailCustomizationFilter, RailCustomizationMark, useRailCustomizationsOnly } from './StudioRailCustomizations.js';
9898
import { FlowLedgerSwitch } from './FlowLedgerSwitch.js';
9999
import { isStudioOrgScope } from './studioScope.js';
100+
import { StudioAiDraftNotice } from './StudioAiDraftNotice.js';
100101
import { useActionLedger } from '../setup/packagedActionLedger.js';
101102

102103
interface ActionItem {
@@ -160,6 +161,8 @@ const NO_PAIR_ACTIONS: PairObjectActions = {
160161
patch: () => undefined,
161162
remove: async () => undefined,
162163
reportBlocking: () => undefined,
164+
discardAiDraft: () => undefined,
165+
discardingAiDraft: null,
163166
dialog: <></>,
164167
};
165168

@@ -820,6 +823,17 @@ export function ObjectActionsPanel({
820823
{tFormat('engine.studio.actions.renameHeld', locale, { name: selRenamedFrom })}
821824
</p>
822825
)}
826+
{/* objectstack#36660 — the AI assistant's draft of this pair action is
827+
what the row holds: Save makes it live too, and its discard
828+
drops that one action's draft at the pair, the designers' line. */}
829+
{selRow?.aiDraft && (
830+
<StudioAiDraftNotice
831+
locale={locale}
832+
onDiscard={editable(sel.name) ? () => added.discardAiDraft(selRow.name) : undefined}
833+
busy={added.discardingAiDraft !== null || added.saving}
834+
className="m-2 mb-0"
835+
/>
836+
)}
823837
{/* eslint-disable-next-line react-hooks/static-components -- useRegisteredMetadataDefaultInspector returns a registered component (stable), not one created during render */}
824838
<Inspector
825839
type="action"

0 commit comments

Comments
 (0)