Skip to content

Commit 4056fd9

Browse files
committed
feat(console): show a write answer's notice on the save toast, one toast per write
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwGdCkvhAHHVnAyVG1
1 parent 0b9008b commit 4056fd9

13 files changed

Lines changed: 613 additions & 58 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@object-ui/data-objectstack': patch
3+
'@object-ui/react': patch
4+
'@object-ui/app-shell': patch
5+
'@object-ui/plugin-form': patch
6+
'@object-ui/plugin-grid': patch
7+
---
8+
9+
feat(console): a save's toast shows the notice a hook set on the write, still one toast per write
10+
11+
Clause-②: yes (widening)
12+
Metadata-protocol: none
13+
14+
A create or update answer can carry a `notice`: one message a hook on the write set for the person who made it, such as "Sent to your manager for approval". The Console now shows it. The record form's save toast (the record dialog, its child-form task and the full-page form), the `object-form` drawer and modal, and the grid's inline-edit saves (the per-row save and "Save All") keep their own message as the title and show the notice under it. The toast stays a success when the notice is the only news, and moves to the warning variant, with the notice leading the lines, when the answer also carried warnings. A write no save surface reports itself, such as the record page's inline edit Save bar, gets one toast from the write-warning channel instead: an info toast with the notice as the hook wrote it, or the notice leading the "Saved — with warnings" lines.
15+
16+
- **`@object-ui/data-objectstack`**: `WriteWarningEvent` gains an optional `notice`, read off the single-record create and update answers. The event is now also emitted when the notice is the answer's only news. What `create` and `update` resolve is unchanged.
17+
- **`@object-ui/react`**: new type `RecordSaveFeedback` (`warnings`, optional `notice`). `AnswerWarningClaim.take` returns it, `AnswerWarningsEvent` gains `notice`, and `toastRecordSave` takes it as its third argument. These exports have not been released yet, so no released signature changes.

‎ui/packages/app-shell/src/console/AppContent.tsx‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useAssistant } from '../assistant/assistantBus.js';
1414
import { ModalForm } from '@object-ui/plugin-form';
1515
import { Empty, EmptyTitle, EmptyDescription, Button, DataErrorState } from '@object-ui/components';
1616
import { toast } from 'sonner';
17-
import { useActionRunner, useGlobalUndo, useMutationInvalidationBridge, notifyDataChanged, FilterScopeProvider, resolveApprovalLock, claimAnswerWarnings, toastRecordSave, type AnswerWarningClaim } from '@object-ui/react';
17+
import { useActionRunner, useGlobalUndo, useMutationInvalidationBridge, notifyDataChanged, FilterScopeProvider, resolveApprovalLock, claimAnswerWarnings, toastRecordSave, type AnswerWarningClaim, type RecordSaveFeedback } from '@object-ui/react';
1818
import { useRecordApprovals, openApprovalOf } from '../hooks/useRecordApprovals.js';
1919
import { useObjectTranslation, useObjectLabel, recordSaveMessage as buildRecordSaveMessage } from '@object-ui/i18n';
2020
import type { AppAccessVerdict, ConnectionState } from '@object-ui/data-objectstack';
@@ -763,9 +763,13 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
763763
runner.registerHandler('crud_success', async (action: any) => {
764764
closeRecordForm();
765765
setRefreshKey(k => k + 1);
766-
// `warnings`: the save's own advisory warning lines, which this one
767-
// toast carries (objectstack-ai/objectstack#27999).
768-
toastRecordSave(toast, action.params?.message ?? 'Record saved successfully', action.params?.warnings);
766+
// `warnings` / `notice`: the save's own advisory warning lines and its
767+
// hook's notice, which this one toast carries
768+
// (objectstack-ai/objectstack#27999, objectstack-ai/objectstack#28252).
769+
toastRecordSave(toast, action.params?.message ?? 'Record saved successfully', {
770+
warnings: action.params?.warnings,
771+
notice: action.params?.notice,
772+
});
769773
return { success: true, reload: true };
770774
});
771775

@@ -909,10 +913,10 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
909913
};
910914
}, [dataSource, recordFormParam, formObjectName]);
911915

912-
const handleCrudSuccess = useCallback((saved?: any, warnings?: string[]) => {
916+
const handleCrudSuccess = useCallback((saved?: any, feedback?: RecordSaveFeedback) => {
913917
executeAction({
914918
type: 'crud_success',
915-
params: { message: recordSaveMessage(saved), warnings },
919+
params: { message: recordSaveMessage(saved), warnings: feedback?.warnings, notice: feedback?.notice },
916920
});
917921
}, [executeAction, recordSaveMessage]);
918922

@@ -933,13 +937,13 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
933937
// the child's open related lists refetch on their own via the
934938
// invalidation bus (#2269): the dataSource write already emitted a
935939
// MutationEvent that the bridge fans out — no manual notify needed.
936-
const warnings = answerWarningClaim.current?.take(saved) ?? [];
940+
const feedback = answerWarningClaim.current?.take(saved);
937941
if (isChildFormTask) {
938-
toastRecordSave(toast, recordSaveMessage(saved), warnings);
942+
toastRecordSave(toast, recordSaveMessage(saved), feedback);
939943
closeRecordForm();
940944
return;
941945
}
942-
handleCrudSuccess(saved, warnings);
946+
handleCrudSuccess(saved, feedback);
943947
if (editingRecord || !currentObjectDef) return;
944948
const target = resolvePostCreateTarget({
945949
objectName: currentObjectDef.name,

‎ui/packages/app-shell/src/console/__tests__/AppContent.recordSaveOneToast-27999.test.tsx‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,18 @@ const NAMED = { id: 't1', subject: 'Quarterly review' };
180180

181181
let toastSuccess: ReturnType<typeof vi.spyOn>;
182182
let toastWarning: ReturnType<typeof vi.spyOn>;
183+
let toastInfo: ReturnType<typeof vi.spyOn>;
183184
beforeEach(() => {
184185
modalSchemas.length = 0;
185186
execute.mockClear();
186187
toastSuccess = vi.spyOn(toast, 'success');
187188
toastWarning = vi.spyOn(toast, 'warning');
189+
toastInfo = vi.spyOn(toast, 'info');
188190
});
189191
afterEach(() => {
190192
toastSuccess.mockRestore();
191193
toastWarning.mockRestore();
194+
toastInfo.mockRestore();
192195
cleanup();
193196
});
194197

@@ -280,3 +283,46 @@ describe('AppContent — an overlay save with warnings shows one record-named to
280283
expect(toastWarning.mock.calls).toEqual([['Saved — with warnings', { description: ADVISORY.message }]]);
281284
});
282285
});
286+
287+
// objectstack-ai/objectstack#28252 — the answer's `notice` (the message a hook
288+
// set, objectstack-ai/objectstack#28000) rides the overlay's claim: the
289+
// `crud_success` toast and the child-form task's direct toast carry it.
290+
describe('AppContent — the overlay save toast carries the hook notice (objectstack-ai/objectstack#28252)', () => {
291+
const NOTICE = 'Sent to your manager for approval';
292+
293+
it('update (crud_success): one success toast, the notice under the record-named message', async () => {
294+
await saveFrom(MAIN_EDIT, update({ warnings: undefined, notice: NOTICE }), NAMED);
295+
296+
expect(toastSuccess.mock.calls).toEqual([['Task "Quarterly review" updated', { description: NOTICE }]]);
297+
expect(toastWarning).not.toHaveBeenCalled();
298+
expect(toastInfo).not.toHaveBeenCalled();
299+
});
300+
301+
it('create (crud_success) with a warning too: one warning toast, the notice leading the lines', async () => {
302+
await saveFrom(
303+
MAIN_CREATE,
304+
{ operation: 'create', resource: 'showcase_task', id: 't1', droppedFields: [], warnings: [ADVISORY], notice: NOTICE },
305+
NAMED,
306+
);
307+
308+
expect(toastSuccess).not.toHaveBeenCalled();
309+
expect(toastInfo).not.toHaveBeenCalled();
310+
expect(toastWarning.mock.calls).toEqual([
311+
['Task "Quarterly review" created', { description: `${NOTICE}\n${ADVISORY.message}` }],
312+
]);
313+
});
314+
315+
it('child-form task: the direct toast carries the notice', async () => {
316+
await saveFrom(CHILD_EDIT, update({ warnings: undefined, notice: NOTICE }), NAMED);
317+
318+
expect(toastSuccess.mock.calls).toEqual([['Task "Quarterly review" updated', { description: NOTICE }]]);
319+
expect(toastInfo).not.toHaveBeenCalled();
320+
});
321+
322+
it('CONTROL: a notice on a write the overlay did not make keeps the channel info toast', async () => {
323+
await saveFrom(MAIN_EDIT, update({ id: 't9', warnings: undefined, notice: NOTICE }), NAMED);
324+
325+
expect(toastSuccess.mock.calls).toEqual([['Task "Quarterly review" updated']]);
326+
expect(toastInfo.mock.calls).toEqual([[NOTICE]]);
327+
});
328+
});

‎ui/packages/app-shell/src/providers/writeWarningToast.test.ts‎

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ const EVENT: WriteWarningEvent = {
7979

8080
/** Records what the shell would have shown. */
8181
function makeSink() {
82-
const calls: Array<{ title: string; description?: string }> = [];
82+
const calls: Array<{ title: string; description?: string; variant?: 'info' }> = [];
8383
const sink: WriteWarningSink = {
8484
warning: (title, options) => { calls.push({ title, description: options?.description }); },
85+
info: (title) => { calls.push({ title, variant: 'info' }); },
8586
};
8687
return { sink, calls };
8788
}
@@ -510,7 +511,7 @@ describe('claimAnswerWarnings — the save surface reports its write (objectstac
510511

511512
const saved = await ds.update('quote', 'r1', { discount: 40 });
512513
// Taken as the surface's success handler would, before the channel settles.
513-
expect(claim.take(saved)).toEqual([ADVISORY.message]);
514+
expect(claim.take(saved)).toEqual({ warnings: [ADVISORY.message] });
514515
await settle();
515516
claim.release();
516517

@@ -530,7 +531,7 @@ describe('claimAnswerWarnings — the save surface reports its write (objectstac
530531
await settle();
531532
expect(calls).toEqual([]);
532533

533-
expect(claim.take(saved)).toEqual([ADVISORY.message]);
534+
expect(claim.take(saved)).toEqual({ warnings: [ADVISORY.message] });
534535
expect(calls).toEqual([{ title: WARNED, description: other.message }]);
535536
claim.release();
536537
});
@@ -547,7 +548,7 @@ describe('claimAnswerWarnings — the save surface reports its write (objectstac
547548
const claim = claimAnswerWarnings(adapter, { operation: 'update', resource: 'andon', id: 'r1' });
548549

549550
const saved = await ds.update('andon', 'r1', { type: 'x', source_method: 'y' });
550-
expect(claim.take(saved)).toEqual([ADVISORY.message]);
551+
expect(claim.take(saved)).toEqual({ warnings: [ADVISORY.message] });
551552
await settle();
552553
claim.release();
553554

@@ -589,3 +590,78 @@ describe('claimAnswerWarnings — the save surface reports its write (objectstac
589590
expect(calls).toHaveLength(2);
590591
});
591592
});
593+
594+
// ── a write answer's notice rides the same claim (objectstack-ai/objectstack#28252) ──
595+
//
596+
// Same real chain. The notice a hook set (objectstack-ai/objectstack#28000)
597+
// is one toast per write: the surface's when it claims the write, the
598+
// channel's otherwise.
599+
600+
describe('the answer notice — one toast per write (objectstack-ai/objectstack#28252)', () => {
601+
const NOTICE = 'Sent to your manager for approval';
602+
const WARNED = 'Saved — with warnings';
603+
604+
beforeEach(() => {
605+
vi.clearAllMocks();
606+
adapter.getObjectSchema.mockResolvedValue(ANDON_SCHEMA);
607+
});
608+
609+
it('a claimed update: the channel shows nothing, the surface takes the notice with the warnings', async () => {
610+
const update = vi.fn().mockResolvedValue({ record: { id: 'r1' }, warnings: [ADVISORY], notice: NOTICE });
611+
const { ds, calls, settle } = wiredAdapter({ update });
612+
const claim = claimAnswerWarnings(adapter, { operation: 'update', resource: 'deal', id: 'r1' });
613+
614+
const saved = await ds.update('deal', 'r1', { stage: 'won' });
615+
expect(claim.take(saved)).toEqual({ warnings: [ADVISORY.message], notice: NOTICE });
616+
await settle();
617+
claim.release();
618+
619+
expect(calls).toEqual([]);
620+
});
621+
622+
it('a claimed create whose answer carries only a notice: the surface takes it', async () => {
623+
const create = vi.fn().mockResolvedValue({ record: { id: 'd1' }, notice: NOTICE });
624+
const { ds, calls, settle } = wiredAdapter({ create });
625+
const claim = claimAnswerWarnings(adapter, { operation: 'create', resource: 'deal' });
626+
627+
const saved = await ds.create('deal', { stage: 'won' });
628+
expect(claim.take(saved)).toEqual({ warnings: [], notice: NOTICE });
629+
await settle();
630+
claim.release();
631+
632+
expect(calls).toEqual([]);
633+
});
634+
635+
it('unclaimed, a notice alone is one info toast with the server text as written', async () => {
636+
const update = vi.fn().mockResolvedValue({ record: { id: 'r1' }, notice: NOTICE });
637+
const { ds, calls, settle } = wiredAdapter({ update });
638+
639+
await ds.update('deal', 'r1', { stage: 'won' });
640+
await settle();
641+
642+
expect(calls).toEqual([{ title: NOTICE, variant: 'info' }]);
643+
});
644+
645+
it('unclaimed, a notice beside warnings leads the one warnings toast', async () => {
646+
const update = vi.fn().mockResolvedValue({ record: { id: 'r1' }, warnings: [ADVISORY], notice: NOTICE });
647+
const { ds, calls, settle } = wiredAdapter({ update });
648+
649+
await ds.update('deal', 'r1', { stage: 'won' });
650+
await settle();
651+
652+
expect(calls).toEqual([{ title: WARNED, description: `${NOTICE}\n${ADVISORY.message}` }]);
653+
});
654+
655+
it('a claim closed without a take shows the notice it parked on the channel toast', async () => {
656+
const update = vi.fn().mockResolvedValue({ record: { id: 'r1' }, notice: NOTICE });
657+
const { ds, calls, settle } = wiredAdapter({ update });
658+
const claim = claimAnswerWarnings(adapter, { operation: 'update', resource: 'deal', id: 'r1' });
659+
660+
await ds.update('deal', 'r1', { stage: 'won' });
661+
await settle();
662+
expect(calls).toEqual([]);
663+
claim.release();
664+
665+
expect(calls).toEqual([{ title: NOTICE, variant: 'info' }]);
666+
});
667+
});

‎ui/packages/app-shell/src/providers/writeWarningToast.ts‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export type FieldLabelFn = (objectName: string, fieldName: string, fallback: str
5656
*/
5757
export interface WriteWarningSink {
5858
warning(title: string, options?: { description?: string }): void;
59+
info(title: string): void;
5960
}
6061

6162
/**
@@ -251,6 +252,14 @@ function lineFor(reason: DroppedFieldsNotice['reason']): StrippedLine {
251252
* so the claim holds the warnings by the time the surface's success handler
252253
* runs, whatever the label lookup below costs. The stripped-fields toast is
253254
* never claimed.
255+
*
256+
* The answer's `notice` (objectstack-ai/objectstack#28252) — the message a
257+
* hook on the write set for the person who made it — is parked with the
258+
* warnings on the same claim, so a record save surface shows it on its one
259+
* save toast. Unclaimed, it gets the channel's own toast: it leads the
260+
* warnings toast's lines when the write also carried warnings, and is an info
261+
* toast of its own, the server's text as written, when it did not. Either way
262+
* the write's answer feedback is one toast.
254263
*/
255264
export async function emitWriteWarning(
256265
ev: WriteWarningEvent,
@@ -261,23 +270,33 @@ export async function emitWriteWarning(
261270
): Promise<void> {
262271
// Before the first `await`: see the claim paragraph above.
263272
const messages = answerWarningLines(ev);
264-
const claimed = messages.length > 0 && !!adapter
265-
&& parkAnswerWarnings(adapter, ev, () => emitAnswerWarnings(messages, t, sink));
273+
const notice = ev.notice || undefined;
274+
const claimed = (messages.length > 0 || notice !== undefined) && !!adapter
275+
&& parkAnswerWarnings(adapter, ev, () => emitAnswerFeedback(messages, notice, t, sink));
266276
await emitStrippedFields(ev, t, adapter, fieldLabel, sink);
267-
if (!claimed) emitAnswerWarnings(messages, t, sink);
277+
if (!claimed) emitAnswerFeedback(messages, notice, t, sink);
268278
}
269279

270280
/**
271-
* The write answer's advisory `warnings`, one line per distinct message, under
272-
* one title. Nothing when the event carries none.
281+
* The write answer's advisory `warnings`, one line per distinct message under
282+
* one title, led by its `notice` when there is one; a notice alone is an info
283+
* toast of its own. Nothing when the event carries neither.
273284
*/
274-
function emitAnswerWarnings(messages: string[], t: TranslateFn, sink: WriteWarningSink): void {
275-
if (messages.length === 0) return;
285+
function emitAnswerFeedback(
286+
messages: string[],
287+
notice: string | undefined,
288+
t: TranslateFn,
289+
sink: WriteWarningSink,
290+
): void {
291+
if (messages.length === 0) {
292+
if (notice !== undefined) sink.info(notice);
293+
return;
294+
}
276295
sink.warning(
277296
t('detail.writeWarningsTitle', {
278297
defaultValue: 'Saved — with warnings',
279298
}),
280-
{ description: messages.join('\n') },
299+
{ description: (notice !== undefined ? [notice, ...messages] : messages).join('\n') },
281300
);
282301
}
283302

‎ui/packages/app-shell/src/views/RecordFormPage.saveToastCarriesWarnings-27999.test.tsx‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ import { RecordFormPage } from './RecordFormPage';
3939

4040
const h = React.createElement;
4141

42-
const { toastSuccess, toastWarning, saveState, ADAPTER } = vi.hoisted(() => ({
42+
const { toastSuccess, toastWarning, toastInfo, saveState, ADAPTER } = vi.hoisted(() => ({
4343
toastSuccess: vi.fn(),
4444
toastWarning: vi.fn(),
45+
toastInfo: vi.fn(),
4546
saveState: { event: undefined as unknown, saved: undefined as Record<string, unknown> | undefined },
4647
ADAPTER: { getObjectSchema: async () => ({ fields: {} as Record<string, { label?: string }> }) },
4748
}));
@@ -50,7 +51,7 @@ vi.mock('sonner', () => ({
5051
toast: Object.assign(vi.fn(), {
5152
success: toastSuccess,
5253
error: vi.fn(),
53-
info: vi.fn(),
54+
info: toastInfo,
5455
warning: toastWarning,
5556
loading: vi.fn(),
5657
dismiss: vi.fn(),
@@ -125,6 +126,7 @@ const NAMED = { id: 't1', subject: 'Quarterly review' };
125126
beforeEach(() => {
126127
toastSuccess.mockClear();
127128
toastWarning.mockClear();
129+
toastInfo.mockClear();
128130
pending.length = 0;
129131
saveState.event = undefined;
130132
saveState.saved = undefined;
@@ -217,3 +219,40 @@ describe('RecordFormPage — a save with warnings shows one record-named toast (
217219
expect(toastWarning).not.toHaveBeenCalled();
218220
});
219221
});
222+
223+
// objectstack-ai/objectstack#28252 — the answer's `notice` (the message a hook
224+
// set, objectstack-ai/objectstack#28000) rides the same claim: still one toast.
225+
// Direction, written before the run: with the channel parking warnings only,
226+
// the notice cells RED (an info toast beside a bare success toast).
227+
describe('RecordFormPage — the save toast carries the hook notice (objectstack-ai/objectstack#28252)', () => {
228+
const NOTICE = 'Sent to your manager for approval';
229+
230+
it('update with a notice only: one success toast, record-named, the notice under it', async () => {
231+
await saveOn('edit', update({ warnings: undefined, notice: NOTICE }), NAMED);
232+
233+
expect(toastSuccess.mock.calls).toEqual([['Task "Quarterly review" updated', { description: NOTICE }]]);
234+
expect(toastWarning).not.toHaveBeenCalled();
235+
expect(toastInfo).not.toHaveBeenCalled();
236+
});
237+
238+
it('create with a notice and a warning: one warning toast, the notice leading the lines', async () => {
239+
await saveOn(
240+
'create',
241+
{ operation: 'create', resource: 'showcase_task', id: 't1', droppedFields: [], warnings: [ADVISORY], notice: NOTICE },
242+
NAMED,
243+
);
244+
245+
expect(toastSuccess).not.toHaveBeenCalled();
246+
expect(toastInfo).not.toHaveBeenCalled();
247+
expect(toastWarning.mock.calls).toEqual([
248+
['Task "Quarterly review" created', { description: `${NOTICE}\n${ADVISORY.message}` }],
249+
]);
250+
});
251+
252+
it('CONTROL: a notice on a write the page did not make keeps the channel info toast', async () => {
253+
await saveOn('edit', update({ resource: 'showcase_project', id: 'p1', warnings: undefined, notice: NOTICE }), NAMED);
254+
255+
expect(toastSuccess.mock.calls).toEqual([['Task "Quarterly review" updated']]);
256+
expect(toastInfo.mock.calls).toEqual([[NOTICE]]);
257+
});
258+
});

0 commit comments

Comments
 (0)