Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .changeset/26578-flow-wizard-between-steps-toast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@object-ui/app-shell': patch
---

fix(app-shell): a screen-flow wizard step toasts "Saved — next step" only when it saved a record

Clause-②: no
Metadata-protocol: none

In a screen-flow wizard, every step that led to another screen showed the toast "Saved — next step", even a step that only collected input. In a wizard that creates its record on step 3, steps 1 and 2 told the user something was saved when nothing was.

What changes:

- A step with plain input fields that leads to another screen now shows no toast. The next screen appearing is the answer.
- An `object-form` step still shows "Saved — next step", because it saved its record before the run moved on.
- The toast at the end of the run is unchanged.

The step button still reads "Submit" on every step. The paused screen the server sends does not say whether it is the last one, so the dialog cannot tell a middle step from the final one yet.

What to do: nothing. Nothing a flow declares changes.
37 changes: 30 additions & 7 deletions ui/packages/app-shell/src/views/FlowRunner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
* dispatches a declared action runs it through `useActionTextLocalizer`
* first, and the handler receives that copy, so there is no second
* localization step here. Nothing else moves: the pause stays silent, an
* intermediate step still toasts `flowRunner.nextStep`, and a `refused` or
* failed end still shows no success toast.
* intermediate step toasts only a record it saved (objectstack#26578, below),
* and a `refused` or failed end still shows no success toast.
*
* The order of the first two is not this file's: it is `flowSuccessCopy` in
* `utils/flowResponse`, which a run that goes straight through follows too
Expand Down Expand Up @@ -219,6 +219,25 @@
* The values then go out through `screenResumeValues`, which reduces each file
* field to its bare id: the engine reads `'file'` as a value domain and refuses
* anything else.
*
* ## A step between screens toasts only a record it saved (objectstack#26578)
*
* Every step of a wizard used to answer its pause with `Saved — next step`,
* including a flat step that only collected variables: in a five-step wizard
* whose record is created on step 3, steps 1 and 2 told the user something was
* saved when nothing was. So the between-steps toast now follows what this
* dialog itself persisted: an `object-form` step has written its record (the
* form calls `onSuccess` only after the write lands, and passing `onSuccess`
* is what silences the form's own confirmation), so it keeps the toast; a flat
* step wrote nothing here, and the next screen appearing is its whole answer.
* The terminal toasts are untouched.
*
* The flat footer's button still reads Submit on every step, and that is a
* measured limit, not a choice. "Next" on a step that is not the last needs to
* know which step IS the last, and nothing on the wire says so: the paused
* screen (`ScreenSpec` in `@objectstack/spec/contracts`) carries no final-step
* or step-count member, and a flow can branch after any screen, so only the
* engine could tell from the graph. The same gap keeps a step counter out.
*/
import { Suspense, useEffect, useState } from 'react';
import {
Expand Down Expand Up @@ -479,8 +498,10 @@ export function FlowRunner({ state, authFetch, baseUrl, onClose, onComplete, dat

// Resume the paused run with `inputs` (applied as bare flow variables) and
// advance: render the next screen (multi-step wizard) or finish + refresh.
// Shared by the flat-field submit and the object-form save callback.
const resumeWith = async (inputs: Record<string, unknown>): Promise<void> => {
// Shared by the flat-field submit and the object-form save callback;
// `savedRecord` says whether this step persisted a record before resuming,
// which only an `object-form` step does (objectstack#26578 — see the header).
const resumeWith = async (inputs: Record<string, unknown>, savedRecord: boolean): Promise<void> => {
const res = await authFetch(
`${baseUrl}/api/v1/automation/${encodeURIComponent(flowName)}/runs/${encodeURIComponent(runId)}/resume`,
{ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ inputs }) },
Expand Down Expand Up @@ -527,7 +548,9 @@ export function FlowRunner({ state, authFetch, baseUrl, onClose, onComplete, dat
setRunId(outcome.runId || runId);
setFlowLabel(outcome.flowLabel);
setValues(initialScreenValues(outcome.screen));
toast.success(t('flowRunner.nextStep', { defaultValue: 'Saved — next step' }));
// Only a step that saved a record says so; a flat step's answer is the
// next screen itself (objectstack#26578 — see the header).
if (savedRecord) toast.success(t('flowRunner.nextStep', { defaultValue: 'Saved — next step' }));
} else {
// Terminal success — the invoking action's own `successMessage` first
// (objectui#12234 — see the header), then the flow's declared completion
Expand Down Expand Up @@ -596,7 +619,7 @@ export function FlowRunner({ state, authFetch, baseUrl, onClose, onComplete, dat
setSubmitting(true);
try {
// File fields go out as their bare `sys_file` id (objectstack#25801).
await resumeWith(screenResumeValues(screen, values));
await resumeWith(screenResumeValues(screen, values), false);
} catch (err) {
// The request never produced a response (network / abort), so the
// suspension was not consumed — this one IS retryable.
Expand All @@ -617,7 +640,7 @@ export function FlowRunner({ state, authFetch, baseUrl, onClose, onComplete, dat
const inputs = screen.idVariable && id != null ? { [screen.idVariable]: id } : {};
setSubmitting(true);
try {
await resumeWith(inputs);
await resumeWith(inputs, true);
} catch (err) {
const message = (err as Error).message;
toast.error(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
* `ScreenFlowState.actionSuccessMessage`, it is the terminal toast — and it
* wins over the flow's own `successMessage`, because it is what the same
* click shows when the run does not pause.
* 2. **Only the TERMINAL toast moves.** A multi-step run still toasts the
* next-step notice between screens; a run that ends `refused` or fails after
* the pause still shows no success toast at all.
* 2. **Only the TERMINAL toast moves.** A multi-step run of flat screens shows
* nothing between them (objectstack#26578: a flat step saved no record, so
* it has no "Saved" to say) and closes with the action message alone; a run
* that ends `refused` or fails after the pause still shows no success toast
* at all.
* 3. **The controls keep today's toast.** No action copy (absent, blank, or an
* `I18nLabel` map no localizer resolved) ⇒ the flow's own message, else the
* catalog sentence — asserted in zh with the reported wording, so the
Expand Down Expand Up @@ -106,7 +108,7 @@ describe("objectui#12234 — the invoking action's successMessage closes the run
expect(toastSuccess.mock.calls).toEqual([[ACTION_MESSAGE]]);
});

it('a multi-step run keeps the next-step notice between screens and closes with the action message', async () => {
it('a multi-step run shows nothing between flat screens and closes with the action message', async () => {
const { onComplete } = mount(stateWith(ACTION_MESSAGE), [
jsonResponse({
success: true,
Expand All @@ -119,7 +121,7 @@ describe("objectui#12234 — the invoking action's successMessage closes the run
await submit();

await waitFor(() => expect(onComplete).toHaveBeenCalledTimes(1));
expect(toastSuccess.mock.calls).toEqual([['已保存 — 下一步'], [ACTION_MESSAGE]]);
expect(toastSuccess.mock.calls).toEqual([[ACTION_MESSAGE]]);
});

it('a run that ends refused after the pause still shows no success toast', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* objectstack#26578 — a step between screens toasts only a record it saved.
*
* A wizard step used to answer every pause with `Saved — next step`, so a flat
* step that only collected variables told the user something was saved. The
* toast now follows what the dialog itself persisted:
*
* 1. A flat step that pauses again draws the next screen and toasts nothing.
* 2. An `object-form` step that pauses again has written its record, so it
* keeps the toast — the form's own confirmation is silenced by `onSuccess`,
* which makes this the only one the user gets.
* 3. A flat step that ends the run still gets the completion toast: only the
* between-steps toast moved.
*
* The real `ScreenView` draws every flat screen; an `object-form` step is a
* stub whose button stands in for the form's Save (as in
* `FlowRunner.refusedMessageOnly-13342.test.tsx`).
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

const toastError = vi.fn();
const toastSuccess = vi.fn();
vi.mock('sonner', () => ({ toast: { error: toastError, success: toastSuccess } }));

vi.mock('../ScreenView.js', async (importOriginal) => {
const actual = await importOriginal<typeof import('../ScreenView.js')>();
type Props = Parameters<typeof actual.ScreenView>[0];
return {
...actual,
ScreenView: (props: Props) =>
actual.isObjectFormScreen(props.screen) ? (
<button type="button" onClick={() => props.objectForm?.onSuccess?.({ id: 'ctr_1' })}>
Stub save
</button>
) : (
<actual.ScreenView {...props} />
),
};
});

const { FlowRunner } = await import('../FlowRunner');
type ScreenFlowState = import('../FlowRunner').ScreenFlowState;
type ScreenSpec = ScreenFlowState['screen'];

const INFO_SCREEN: ScreenSpec = {
nodeId: 'screen_info',
title: 'Contract details',
fields: [{ name: 'contract_title', label: 'Title', type: 'text', required: true }],
};

const CONTRACT_FORM_SCREEN: ScreenSpec = {
nodeId: 'screen_contract',
title: 'New contract',
kind: 'object-form',
objectName: 'contract',
idVariable: 'contractId',
};

const NEXT_SCREEN: ScreenSpec = {
nodeId: 'screen_submit',
title: 'Send to legal',
fields: [{ name: 'notes', label: 'Notes', type: 'text' }],
};

const pausedBody = { success: true, data: { success: true, status: 'paused', runId: 'run_1', screen: NEXT_SCREEN } };
const completedBody = { success: true, data: { success: true } };

function jsonResponse(body: unknown): Response {
return new Response(JSON.stringify(body), { status: 200, headers: { 'Content-Type': 'application/json' } });
}

function mount(s: ScreenSpec, body: unknown) {
const onComplete = vi.fn();
const authFetch = vi.fn(async () => jsonResponse(body));
render(
<FlowRunner
state={{ flowName: 'start_contract', runId: 'run_1', screen: s }}
authFetch={authFetch}
baseUrl=""
onClose={vi.fn()}
onComplete={onComplete}
/>,
);
return { onComplete, authFetch };
}

async function typeAndSubmit() {
const user = userEvent.setup();
await user.type(screen.getByRole('textbox'), 'Supply agreement');
await user.click(screen.getByRole('button', { name: 'Submit' }));
}

beforeEach(() => {
toastError.mockClear();
toastSuccess.mockClear();
});

describe('objectstack#26578 — a step between screens toasts only a record it saved', () => {
it('a flat step that pauses again draws the next screen and toasts nothing', async () => {
const { authFetch, onComplete } = mount(INFO_SCREEN, pausedBody);
await typeAndSubmit();

expect(await screen.findByRole('heading', { name: 'Send to legal' })).toBeInTheDocument();
expect(authFetch).toHaveBeenCalledTimes(1);
expect(toastSuccess).not.toHaveBeenCalled();
expect(toastError).not.toHaveBeenCalled();
expect(onComplete).not.toHaveBeenCalled();
});

it('an `object-form` step that pauses again keeps the toast for the record it saved', async () => {
const { authFetch } = mount(CONTRACT_FORM_SCREEN, pausedBody);
await userEvent.setup().click(screen.getByRole('button', { name: 'Stub save' }));

expect(await screen.findByRole('heading', { name: 'Send to legal' })).toBeInTheDocument();
expect(authFetch).toHaveBeenCalledWith(
'/api/v1/automation/start_contract/runs/run_1/resume',
expect.objectContaining({ body: JSON.stringify({ inputs: { contractId: 'ctr_1' } }) }),
);
expect(toastSuccess.mock.calls).toEqual([['Saved — next step']]);
});

it('a flat step that ends the run still gets the completion toast', async () => {
const { onComplete } = mount(INFO_SCREEN, completedBody);
await typeAndSubmit();

await waitFor(() => expect(onComplete).toHaveBeenCalledTimes(1));
expect(toastSuccess.mock.calls).toEqual([['Flow "start_contract" completed']]);
});
});
Loading