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/36849-result-link-closes-flow-dialog.md
Original file line number Diff line number Diff line change
@@ -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.
36 changes: 35 additions & 1 deletion ui/packages/app-shell/src/views/FlowRunner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -575,7 +596,11 @@ export interface FlowRunnerProps {
authFetch: (url: string, init?: RequestInit) => Promise<Response>;
/** 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;
Expand Down Expand Up @@ -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 (
<Dialog open onOpenChange={(o) => { if (!o && !submitting) dismiss(); }}>
Expand Down Expand Up @@ -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
Expand Down
53 changes: 49 additions & 4 deletions ui/packages/app-shell/src/views/ScreenView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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` /
Expand Down Expand Up @@ -424,10 +430,16 @@ export interface ScreenViewProps {
* header, objectstack#26882). Absent, or a field not in it, draws no message.
*/
errors?: Readonly<Record<string, string>>;
/**
* 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
Expand Down Expand Up @@ -495,6 +507,7 @@ export function ScreenView({ screen, values, onValueChange, dataSource, objects,
error={error}
dataSource={dataSource}
objects={objects}
onRecordLinkFollow={onRecordLinkFollow}
/>
);
const message = errorId && (
Expand Down Expand Up @@ -562,6 +575,7 @@ export function ScreenFieldInput({
error,
dataSource,
objects,
onRecordLinkFollow,
}: {
field: ScreenFieldSpec;
value: unknown;
Expand All @@ -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<unknown>;
/** A `record_link` field's link was followed in this window ({@link ScreenViewProps.onRecordLinkFollow}). */
onRecordLinkFollow?: () => void;
}) {
const { t } = useObjectTranslation();
const id = screenFieldControlId(field.name);
Expand All @@ -598,7 +614,14 @@ export function ScreenFieldInput({
// It reads the served `defaultValue`, never `value`: nothing is collected.
if (isRecordLinkScreenField(field)) {
return (
<ScreenRecordLink id={id} field={field} dataSource={dataSource} objects={objects} describedBy={describedBy} />
<ScreenRecordLink
id={id}
field={field}
dataSource={dataSource}
objects={objects}
describedBy={describedBy}
onFollow={onRecordLinkFollow}
/>
);
}

Expand Down Expand Up @@ -766,12 +789,14 @@ function ScreenRecordLink({
dataSource,
objects,
describedBy,
onFollow,
}: {
id: string;
field: ScreenFieldSpec;
dataSource?: unknown;
objects?: ReadonlyArray<unknown>;
describedBy?: string;
onFollow?: () => void;
}) {
const recordId = recordLinkId(field);
const name = (
Expand All @@ -791,14 +816,28 @@ function ScreenRecordLink({
return (
<div id={id} aria-describedby={describedBy} data-screen-record-link={field.name} className="min-h-9 flex items-center">
{routed && recordId !== undefined && typeof field.reference === 'string' ? (
<RoutedRecordLink objectName={field.reference} recordId={recordId} objects={objects}>{name}</RoutedRecordLink>
<RoutedRecordLink objectName={field.reference} recordId={recordId} objects={objects} onFollow={onFollow}>
{name}
</RoutedRecordLink>
) : (
name
)}
</div>
);
}

/**
* 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<HTMLAnchorElement>): 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
Expand All @@ -808,19 +847,25 @@ function RoutedRecordLink({
objectName,
recordId,
objects,
onFollow,
children,
}: {
objectName: string;
recordId: string | number;
objects?: ReadonlyArray<unknown>;
onFollow?: () => void;
children: React.ReactNode;
}) {
const { appName } = useParams<{ appName?: string }>();
const perms = usePermissions();
const path = appRecordPath(appName, routableObjectNames(objects, perms), objectName, recordId);
if (path === null) return <>{children}</>;
return (
<Link to={path} className="text-primary underline-offset-4 hover:underline">
<Link
to={path}
className="text-primary underline-offset-4 hover:underline"
onClick={onFollow ? (event) => { if (navigatesInPlace(event)) onFollow(); } : undefined}
>
{children}
</Link>
);
Expand Down
Loading
Loading