From 42b0b768bd44019c098c3323ac5780ed1696024e Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 09:50:57 +0000 Subject: [PATCH 1/2] test(console): reproduce a result screen's record link leaving the flow dialog on step one Claude-Session: https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ Co-authored-by: Claude --- .../FlowRunner.recordLink-25872.test.tsx | 160 +++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) diff --git a/ui/packages/app-shell/src/views/__tests__/FlowRunner.recordLink-25872.test.tsx b/ui/packages/app-shell/src/views/__tests__/FlowRunner.recordLink-25872.test.tsx index 3b3041f2268..2c235bfa9bf 100644 --- a/ui/packages/app-shell/src/views/__tests__/FlowRunner.recordLink-25872.test.tsx +++ b/ui/packages/app-shell/src/views/__tests__/FlowRunner.recordLink-25872.test.tsx @@ -14,9 +14,10 @@ * so a label that fell back to the raw id or to a `name` column would fail it. * Each "no link" leg sits beside a leg that does draw one. */ +import { useEffect, useState } from 'react'; import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'; import { render, screen, fireEvent, waitFor, cleanup, within } from '@testing-library/react'; -import { MemoryRouter, Route, Routes } from 'react-router-dom'; +import { MemoryRouter, Route, Routes, useParams } from 'react-router-dom'; // Module scope, per AGENTS.md 测试纪律: the link reaches `LookupField` through // a `React.lazy` factory inside `@object-ui/fields`. import '@object-ui/fields'; @@ -164,3 +165,160 @@ describe('objectstack#25872 — a `type: \'record_link\'` screen field links the expect(screenResumeValues(spec, untouched)).toBe(untouched); }); }); + +/** + * objectstack#36849 — following a record link on a screen flow's result + * screen ends the dialog. + * + * The record page that launched the run is the dialog's host, and it holds + * only the run's LAUNCH state: the step the run first paused on. A link to + * another record is a route change under the same page component, which + * draws its loading skeleton for a moment (`RecordDetailView` resets its + * loading flag on every object or record change), so the dialog unmounted + * and came back from that launch state: step one, inputs and a live Next, + * whose press posted step one's values to a run already on its last screen. + * + * `RecordPageHost` below is that host's shape, reduced: launch state held by + * the page, a loading flash on every route change, the runner drawn only + * after it. The run is HotCRM's quote wizard: step one declares `quoteName`, + * the result screen only the `quoteLink` record link. + */ +describe('objectstack#36849 — following a result screen\'s record link ends the dialog', () => { + const QUOTE_RECORDS: Record> = { q_1: { id: 'q_1', quote_name: 'Q-0001' } }; + const quoteDataSource = () => ({ + find: vi.fn(async () => ({ data: [] })), + findOne: vi.fn(async (_object: string, id: string) => QUOTE_RECORDS[id] ?? null), + getObjectSchema: vi.fn(async () => ({ name: 'crm_quote', nameField: 'quote_name', fields: { quote_name: { type: 'text', label: 'Quote' } } })), + }); + + const STEP_ONE: ScreenFlowState = { + flowName: 'quote_generation', + runId: 'run-q', + screen: { + nodeId: 'quote_details', + title: 'Quote details', + fields: [{ name: 'quoteName', label: 'Quote name', type: 'text' }], + progress: { nextScreen: 'certain', step: 1, stepCount: 2 }, + }, + }; + const QUOTE_LINK = { name: 'quoteLink', label: 'Quote', type: 'record_link', reference: 'crm_quote', defaultValue: 'q_1' }; + const resultScreen = (fields: ScreenSpec['fields']): ScreenSpec => ({ + nodeId: 'quote_result', + title: 'Quote created', + fields, + progress: { nextScreen: 'none', step: 2, stepCount: 2 }, + }); + const RESUME_URL = '/api/v1/automation/quote_generation/runs/run-q/resume'; + + /** Step one's resume pauses on `next`; every later resume completes the run. */ + function wizardRun(next: ScreenSpec) { + let resumed = 0; + return vi.fn(async (url: string, _init?: RequestInit) => { + if (url !== RESUME_URL) return jsonResponse({ success: false, error: { code: 'NOT_FOUND', message: 'no screen' } }, 404); + resumed += 1; + return resumed === 1 + ? jsonResponse({ success: true, data: { status: 'paused', runId: 'run-q', screen: next } }) + : jsonResponse({ success: true, data: { success: true } }); + }); + } + + function RecordPageHost({ authFetch, onClose, onComplete }: { + authFetch: ReturnType; + onClose: () => void; + onComplete: () => void; + }) { + const { objectName, recordId } = useParams(); + const [flow, setFlow] = useState(STEP_ONE); + const [loading, setLoading] = useState(true); + useEffect(() => { + setLoading(true); + queueMicrotask(() => setLoading(false)); + }, [objectName, recordId]); + if (loading) return
; + return ( +
+ { onClose(); setFlow(null); }} + onComplete={() => { onComplete(); setFlow(null); }} + dataSource={quoteDataSource()} + objects={[{ name: 'crm_opportunity' }, { name: 'crm_quote' }]} + /> +
+ ); + } + + function mountPage(next: ScreenSpec) { + const authFetch = wizardRun(next); + const onClose = vi.fn(); + const onComplete = vi.fn(); + render( + + + } + /> + + , + ); + const resumes = () => + authFetch.mock.calls + .filter(([url]) => url === RESUME_URL) + .map(([, init]) => JSON.parse(String(init?.body)).inputs); + return { authFetch, onClose, onComplete, resumes }; + } + + /** Fill step one and press Next; answers the result screen's link to the quote. */ + async function reachResultScreen(): Promise { + fireEvent.change(await screen.findByRole('textbox', { name: 'Quote name' }), { target: { value: 'Spring deal' } }); + fireEvent.click(screen.getByRole('button', { name: 'Next' })); + await screen.findByText('Quote created'); + return waitFor(() => within(linkCell('quoteLink')).getByRole('link', { name: 'Q-0001' })); + } + + /** The record page the link leads to, settled past its loading flash. */ + async function landOnQuote(): Promise { + await screen.findByTestId('page-crm_quote-q_1'); + // One more turn, so a dialog the page would draw again has been drawn. + await new Promise((resolve) => setTimeout(resolve, 0)); + } + + it('lands on the record with nothing on top, never on step one again', async () => { + const { onComplete, resumes } = mountPage(resultScreen([QUOTE_LINK])); + fireEvent.click(await reachResultScreen()); + await landOnQuote(); + expect(screen.queryByRole('dialog')).toBeNull(); + expect(screen.queryByRole('textbox', { name: 'Quote name' })).toBeNull(); + expect(screen.queryByRole('button', { name: 'Next' })).toBeNull(); + // The run has nothing left to ask: it is completed, as Done completes it. + await waitFor(() => expect(onComplete).toHaveBeenCalledTimes(1)); + expect(resumes()).toEqual([{ quoteName: 'Spring deal' }, {}]); + expect(toasts.success).toHaveBeenCalledTimes(1); + expect(toasts.error).not.toHaveBeenCalled(); + }); + + it('a link on a step that still takes input closes the dialog as Cancel does, resuming nothing', async () => { + const { onClose, onComplete, resumes } = mountPage( + resultScreen([QUOTE_LINK, { name: 'note', label: 'Note', type: 'text' }]), + ); + fireEvent.click(await reachResultScreen()); + await landOnQuote(); + expect(screen.queryByRole('dialog')).toBeNull(); + expect(onClose).toHaveBeenCalledTimes(1); + expect(onComplete).not.toHaveBeenCalled(); + expect(resumes()).toEqual([{ quoteName: 'Spring deal' }]); + }); + + it('a link opened in a new tab leaves the dialog where it is', async () => { + const { onClose, onComplete, resumes } = mountPage(resultScreen([QUOTE_LINK])); + fireEvent.click(await reachResultScreen(), { ctrlKey: true }); + expect(screen.getByRole('dialog')).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Done' })).toBeEnabled(); + expect(onClose).not.toHaveBeenCalled(); + expect(onComplete).not.toHaveBeenCalled(); + expect(resumes()).toEqual([{ quoteName: 'Spring deal' }]); + }); +}); From 8f7616989e4af1aebcb508ed7a6ef9400829badf Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 09:52:11 +0000 Subject: [PATCH 2/2] fix(console): following a result screen's record link closes the flow dialog Claude-Session: https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ Co-authored-by: Claude --- .../36849-result-link-closes-flow-dialog.md | 20 +++++++ .../app-shell/src/views/FlowRunner.tsx | 36 ++++++++++++- .../app-shell/src/views/ScreenView.tsx | 53 +++++++++++++++++-- 3 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 .changeset/36849-result-link-closes-flow-dialog.md diff --git a/.changeset/36849-result-link-closes-flow-dialog.md b/.changeset/36849-result-link-closes-flow-dialog.md new file mode 100644 index 00000000000..f98900355a7 --- /dev/null +++ b/.changeset/36849-result-link-closes-flow-dialog.md @@ -0,0 +1,20 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(console): following a record link on a screen flow's result screen closes the flow dialog + +Clause-②: no +Metadata-protocol: none + +On the last screen of a multi-screen screen flow, the screen that links the records the flow created, following one of those links now closes the flow dialog. The user lands on the record with nothing on top of it. + +Before, the dialog stayed open over the record page and showed the flow's first screen again, with its inputs and a live Next. The record page draws a loading state on every record change, and the dialog was rebuilt from the step the run first paused on. Pressing Next sent the first screen's values to a run that was already on its last screen, and the user saw the engine's English refusal ("Invalid screen input: Unknown screen field …"). A lead conversion and a quote wizard both showed this after their records had been created. + +Following a link in the same window now closes the dialog before the page changes: + +- On a result screen (only record links, nothing after it), the run is also completed, the same way Done completes it: the completion toast, the refresh, and the host's completion callback. +- On any other screen, the link closes the dialog the way Cancel does and resumes nothing. +- A link opened in a new tab or window leaves the dialog where it is. + +`ScreenView` takes an optional `onRecordLinkFollow` callback for this; the Studio preview passes none. Nothing to migrate. diff --git a/ui/packages/app-shell/src/views/FlowRunner.tsx b/ui/packages/app-shell/src/views/FlowRunner.tsx index 2c374ce54e8..8fa5a6ed056 100644 --- a/ui/packages/app-shell/src/views/FlowRunner.tsx +++ b/ui/packages/app-shell/src/views/FlowRunner.tsx @@ -337,6 +337,27 @@ * the engine's sentence. The engine's refusal itself is unchanged. A loop that * pauses on the same screen node again is indistinguishable from a retry by * `nodeId`, and keeps today's answer. + * + * ## Following a record link ends the dialog (objectstack#36849) + * + * A `record_link` field leads to another record's page, and the host holds + * only the run's LAUNCH state — the step the run first paused on; every later + * step lives in this component. A record page redraws its loading skeleton on + * every object or record change, so a dialog left open across the link's + * navigation unmounted with it and came back from that launch state: step one, + * its inputs and a live Next, which posted step one's values to a run already + * past it. + * + * So following a link in this window (`ScreenView`'s `onRecordLinkFollow`; a + * new-tab click leaves the dialog alone) ends the dialog through the same door + * as its close button, before the route changes: the host is told to close at + * once (`onClose`), so whatever it draws on the record page holds no run. On a + * result screen the run is then completed exactly as Done completes it (the + * resume-RESULT and result-screen sections above): the empty resume, its + * toast, `notifyDataChanged`, `onComplete`. Its answer arrives after the + * dialog is gone, so a failure is told by its toast alone. On any other screen + * the link closes as Cancel does and resumes nothing; while a resume is in + * flight, or after one has failed, it only closes, as the close button does. */ import { Suspense, useEffect, useState } from 'react'; import { @@ -575,7 +596,11 @@ export interface FlowRunnerProps { authFetch: (url: string, init?: RequestInit) => Promise; /** API base (e.g. `import.meta.env.VITE_SERVER_URL || ''`). */ baseUrl: string; - /** User dismissed the runner without completing. */ + /** + * The dialog closes. Usually the user dismissed it without completing; a + * result screen's record link closes it first and completes the run after, + * so `onComplete` can follow (objectstack#36849 — see the header). + */ onClose: () => void; /** The flow ran to completion — host should refresh. */ onComplete: () => void; @@ -907,6 +932,14 @@ export function FlowRunner({ state, authFetch, baseUrl, onClose, onComplete, dat // resume has failed, when closing is a plain close again and Done the retry. const resultScreen = !terminal && !anotherScreen && isDisplayOnlyScreen(screen); const dismiss = resultScreen && !resumeError ? () => { void submit(); } : onClose; + // A record link followed in this window ends the dialog before the route + // changes (objectstack#36849 — see the header): the host closes now, and a + // result screen's run completes behind it, as its close button completes it. + const followRecordLink = () => { + const complete = resultScreen && !resumeError && !submitting; + onClose(); + if (complete) void submit(); + }; return ( { if (!o && !submitting) dismiss(); }}> @@ -980,6 +1013,7 @@ export function FlowRunner({ state, authFetch, baseUrl, onClose, onComplete, dat values={values} onValueChange={setVal} errors={fieldErrors} + onRecordLinkFollow={followRecordLink} dataSource={dataSource} objects={objects} // Two columns from `sm` up; `space-y-0` replaces the body's own diff --git a/ui/packages/app-shell/src/views/ScreenView.tsx b/ui/packages/app-shell/src/views/ScreenView.tsx index d13933973d4..3a7f48ea562 100644 --- a/ui/packages/app-shell/src/views/ScreenView.tsx +++ b/ui/packages/app-shell/src/views/ScreenView.tsx @@ -70,6 +70,12 @@ * ({@link initialScreenValues}) and never posted ({@link screenResumeValues}): * the engine refuses a resume that carries any value under its name. * + * Following the link leaves the page the screen is drawn over, so the host is + * told: `onRecordLinkFollow` runs on a click the router itself navigates on (a + * plain primary click), never on one that opens a new tab or window. The + * runtime ends its dialog there (`FlowRunner`, objectstack#36849); the Studio + * preview passes none. + * * ## `date`, `datetime` and `boolean` are the platform controls (objectstack#26579) * * A `date` / `datetime` field is the record form's picker (`DatePickerField` / @@ -424,10 +430,16 @@ export interface ScreenViewProps { * header, objectstack#26882). Absent, or a field not in it, draws no message. */ errors?: Readonly>; + /** + * Called when the user follows a `record_link` field's link in this window + * (see the header, objectstack#36849). Not called for a click that opens the + * record in a new tab or window, which leaves this page where it is. + */ + onRecordLinkFollow?: () => void; className?: string; } -export function ScreenView({ screen, values, onValueChange, dataSource, objects, objectForm, errors, className }: ScreenViewProps) { +export function ScreenView({ screen, values, onValueChange, dataSource, objects, objectForm, errors, onRecordLinkFollow, className }: ScreenViewProps) { if (isObjectFormScreen(screen)) { const objectDef = Array.isArray(objects) ? objects.find((o: any) => o?.name === screen.objectName) : undefined; // objectstack-ai/objectstack#36425 — the child collections the object's @@ -495,6 +507,7 @@ export function ScreenView({ screen, values, onValueChange, dataSource, objects, error={error} dataSource={dataSource} objects={objects} + onRecordLinkFollow={onRecordLinkFollow} /> ); const message = errorId && ( @@ -562,6 +575,7 @@ export function ScreenFieldInput({ error, dataSource, objects, + onRecordLinkFollow, }: { field: ScreenFieldSpec; value: unknown; @@ -579,6 +593,8 @@ export function ScreenFieldInput({ dataSource?: unknown; /** The console's object definitions: the objects a `record_link` field may link to a page of. */ objects?: ReadonlyArray; + /** A `record_link` field's link was followed in this window ({@link ScreenViewProps.onRecordLinkFollow}). */ + onRecordLinkFollow?: () => void; }) { const { t } = useObjectTranslation(); const id = screenFieldControlId(field.name); @@ -598,7 +614,14 @@ export function ScreenFieldInput({ // It reads the served `defaultValue`, never `value`: nothing is collected. if (isRecordLinkScreenField(field)) { return ( - + ); } @@ -766,12 +789,14 @@ function ScreenRecordLink({ dataSource, objects, describedBy, + onFollow, }: { id: string; field: ScreenFieldSpec; dataSource?: unknown; objects?: ReadonlyArray; describedBy?: string; + onFollow?: () => void; }) { const recordId = recordLinkId(field); const name = ( @@ -791,7 +816,9 @@ function ScreenRecordLink({ return (
{routed && recordId !== undefined && typeof field.reference === 'string' ? ( - {name} + + {name} + ) : ( name )} @@ -799,6 +826,18 @@ function ScreenRecordLink({ ); } +/** + * Whether a click on a router `Link` navigates this window: the router's own + * rule — a primary click with no modifier key, not already handled. Any other + * click opens the record elsewhere (a new tab or window) and leaves this page, + * and whatever is drawn over it, where it is. + */ +function navigatesInPlace(event: React.MouseEvent): boolean { + return !event.defaultPrevented + && event.button === 0 + && !event.metaKey && !event.altKey && !event.ctrlKey && !event.shiftKey; +} + /** * The link to a record's page, under a router: the record route the record * page's related lists build (`appRecordPath`), or the bare name when this @@ -808,11 +847,13 @@ function RoutedRecordLink({ objectName, recordId, objects, + onFollow, children, }: { objectName: string; recordId: string | number; objects?: ReadonlyArray; + onFollow?: () => void; children: React.ReactNode; }) { const { appName } = useParams<{ appName?: string }>(); @@ -820,7 +861,11 @@ function RoutedRecordLink({ const path = appRecordPath(appName, routableObjectNames(objects, perms), objectName, recordId); if (path === null) return <>{children}; return ( - + { if (navigatesInPlace(event)) onFollow(); } : undefined} + > {children} );