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
19 changes: 19 additions & 0 deletions .changeset/26563-approval-step-line-visited-route.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@object-ui/app-shell': patch
'@object-ui/console': patch
---

fix(app-shell): the approval step line draws the route the request's run took, not the flow graph's first branch

Clause-②: no
Metadata-protocol: none

The approval step line used to draw the request's `flow_steps`. The approvals read builds that list by walking the flow from its start and taking the `approve` edge, else the `true` edge, else the first edge at every node. So a request that a decision routed down another branch showed rungs it never reaches. A contract routed from the manager to the finance-only rung read "manager · legal + finance (joint) · executive · general manager" while it waited on the finance controller.

What changes:

- On a business record's approvals panel, the line now shows the steps the pending request's flow run has passed, oldest first, then the pending step. Each step comes from a request the run actually opened: same flow run, another node, approved, and opened before the pending one. A step approved in several rounds is shown once. Nothing ahead of the pending step is shown, because no request row says which branch the run takes next.
- The approvals list serves a request only to its participants, so a step the viewer had no part in is left out rather than guessed. With fewer than two steps, no line is drawn.
- On the approval request page, the decision panel no longer draws a step line. Its row proves only its own step, which the page header already names. The line returns there once the approvals read serves the route the run takes.

What to do: nothing. Nothing a flow, page or object declares changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
*
* objectui#12491 (face 5 of ruling C on objectui#12438, the seat's Q1 A, Q2 A
* and Q3 A): on the page objectstack serves for an approval request, a
* multi-step request shows its vertical step line, and a request no person
* submitted shows its flow origin, as the approvals inbox's request sheet
* shows both.
* request no person submitted shows its flow origin, as the approvals inbox's
* request sheet shows it.
*
* objectstack#26563: the same page draws NO step line. The row's `flow_steps`
* is the flow graph's trunk (`attachFlowSteps` walks it from the start,
* preferring `approve`, then `true`, then the first edge), not the route this
* request takes, so a request a decision sent down another branch was drawn on
* rungs it never visits. The row proves only its own step, so the page draws
* none until the approvals read serves the route the run takes.
*
* Mounted as the other served-page pins mount it: the REAL `RecordDetailView`,
* opened by the generic record route under the console's `ApprovalRecordReads`,
Expand Down Expand Up @@ -283,51 +289,54 @@ afterEach(() => {
served = FLOW_ROW;
});

describe('the served request page shows the flow origin and the step line (objectui#12491)', () => {
describe('the served request page shows the flow origin (objectui#12491) and no guessed step line (objectstack#26563)', () => {
it('the served page parses as a spec page, with no node or prop added for either', () => {
const parsed = PageSchema.safeParse(SERVED_PAGE);
expect(parsed.success, JSON.stringify(parsed.error?.issues ?? [])).toBe(true);
expect(SERVED_PAGE.slots.actions).toEqual([{ type: 'record:approval_decision' }]);
});

it('a multi-step request shows its vertical step line, every step in order, the current one marked', async () => {
it('a multi-step request served with its flow trunk draws no step line, and none of the trunk\'s other rungs', async () => {
const panel = await openServedPage(FLOW_ROW);
const line = await within(panel).findByLabelText(PACK.stepProgress, undefined, { timeout: 8000 });
expect(line.tagName).toBe('OL');
expect(line.getAttribute('class')?.split(/\s+/)).toContain('flex-col');
const rows = within(line).getAllByRole('listitem');
expect(rows.map((r) => r.textContent)).toEqual(['Manager review', '2Finance review', '3Director sign-off', '4CFO sign-off']);
expect(within(rows[1]).getByText('Finance review').getAttribute('class')?.split(/\s+/)).toContain('font-medium');
// A first_response node carries no tally; the line is drawn without one.
await within(panel).findByRole('button', { name: 'Approve' }, { timeout: 8000 });
expect(within(panel).queryByLabelText(PACK.stepProgress)).toBeNull();
expect(within(panel).queryByRole('list')).toBeNull();
// The trunk's rungs past this request's own node are guesses: none is drawn.
for (const rung of ['Manager review', 'Director sign-off', 'CFO sign-off']) {
expect(pageText()).not.toContain(rung);
}
// A first_response node carries no tally.
expect(within(panel).queryByRole('progressbar')).toBeNull();
});

it('a request served with no submitter is marked with the flow origin', async () => {
expect('submitter_id' in FLOW_ROW).toBe(false);
const panel = await openServedPage(FLOW_ROW);
await within(panel).findByLabelText(PACK.stepProgress, undefined, { timeout: 8000 });
expect(marker(panel)?.textContent).toBe(PACK.flowOrigin);
const origin = await within(panel).findByTestId('approval-decision-flow-origin', undefined, { timeout: 8000 });
expect(origin.textContent).toBe(PACK.flowOrigin);
});

it('a decided request still shows its line and its origin', async () => {
it('a decided request shows its origin and still no step line', async () => {
const decided = {
...FLOW_ROW,
status: 'approved',
flow_steps: FLOW_STEPS.map((s) => ({ ...s, state: 'done' })),
viewer: { can_act: false, is_submitter: false, can_override: false },
};
const panel = await openServedPage(decided);
const line = await within(panel).findByLabelText(PACK.stepProgress, undefined, { timeout: 8000 });
expect(within(line).getAllByRole('listitem')).toHaveLength(FLOW_STEPS.length);
expect(marker(panel)?.textContent).toBe(PACK.flowOrigin);
const origin = await within(panel).findByTestId('approval-decision-flow-origin', undefined, { timeout: 8000 });
expect(origin.textContent).toBe(PACK.flowOrigin);
expect(within(panel).queryByLabelText(PACK.stepProgress)).toBeNull();
});

it('CONTROL: a request a person submitted carries no flow-origin marker, and its line is unchanged', async () => {
it('CONTROL: a request a person submitted carries no flow-origin marker, and no step line either', async () => {
const panel = await openServedPage(HUMAN_ROW);
const line = await within(panel).findByLabelText(PACK.stepProgress, undefined, { timeout: 8000 });
expect(within(line).getAllByRole('listitem')).toHaveLength(FLOW_STEPS.length);
// The decision button gates on the served row's `viewer`, which only the
// approvals get carries: once it shows, the panel is bound to that row.
await within(panel).findByRole('button', { name: 'Approve' }, { timeout: 8000 });
expect(marker(panel)).toBeNull();
expect(pageText()).not.toContain(PACK.flowOrigin);
expect(within(panel).queryByLabelText(PACK.stepProgress)).toBeNull();
});

it('CONTROL: a one-step flow draws no line', async () => {
Expand Down
16 changes: 8 additions & 8 deletions ui/packages/app-shell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,8 @@ for a longer walkthrough.

When a record has approval requests, its detail page grows an **Approvals
tab** — a peer of Details/Related with a request-count badge (#3461):
which step the approval sits at (with the flow's step strip), the
which step the approval sits at (with the step line of the route its flow
run took: the steps it passed, then the pending one), the
server-computed decision progress (quorum tally, per-group 会签 ticks), the
**waiting-on** approvers resolved to display names (group approvers labeled
with their group), one chronological decision timeline merged across all of
Expand Down Expand Up @@ -1251,13 +1252,12 @@ summary is not drawn.
Two more parts come from the same request row. A request no person submitted
(its `submitter_id` absent or null, as the approvals get serves a request a
flow run opened with no user context) is marked "Flow-initiated", above the
summary; a request a person submitted carries no marker. Below the summary,
when the owning flow has more than one approval step (`flow_steps`), the
block draws the flow's vertical step line, done / current / upcoming, at any
status: a decided request and a node with no progress tally draw it too. The
line is the same stepper the record approvals panel draws, and it never
scrolls sideways. The marker and the line's accessible name are the
Approval Center's `approvalsInbox.*` rows.
summary; a request a person submitted carries no marker. The block draws no
step line: the row's `flow_steps` is the flow graph's first branch at every
decision, not the route this request takes, and the row proves only its own
step, which the page header names. The record approvals panel draws the line
from the run's own request rows instead. The marker is the Approval Center's
`approvalsInbox.flowOrigin` row.

## User-scoped state (favorites, recent items)

Expand Down
11 changes: 10 additions & 1 deletion ui/packages/app-shell/src/hooks/useRecordApprovals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,17 @@ export interface ApprovalRequestLite {
step_label?: string;
/** Display name of the submitter (`sys_user.name`), when resolvable. */
submitter_name?: string;
/** Owning flow's approval steps for progress display (single reads only). */
/**
* Owning flow's approval steps in graph order (single reads only). ⚠️ The
* server walks one trunk of the graph, so this is NOT the route the request
* takes past a decision, and no surface draws it (objectstack#26563): the
* record's step line is read off `flow_run_id` / `flow_node_id` instead.
*/
flow_steps?: Array<{ id: string; label: string; state: 'done' | 'current' | 'upcoming' }>;
/** The flow run that opened this request; every request of one run shares it. */
flow_run_id?: string;
/** The approval node of the run this request was opened for. */
flow_node_id?: string;
/**
* Server-computed capability of the current viewer (framework#3310), attached
* by `getRequest`. `is_submitter` gates the record page's remind affordance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
* CJK labels, verbatim) is exercised directly, and the invariance test rules
* out a count threshold that could put some other length back on the old path.
*
* The steps reach the line as the panel builds them since objectstack#26563:
* off the pending request's run, one approved request per passed step and the
* pending request last (`visitedApprovalSteps`). So each fixture below is a
* run's request rows, every step but the last passed, and no step is ahead of
* the pending one.
*
* No build artifact sits between the edit and this test — the root Vitest
* config aliases every `@object-ui` specifier at that package's source.
*/
Expand All @@ -67,7 +73,8 @@ import { RecordApprovalsPanel } from './RecordApprovalsPanel';
/** The strip's accessible name, as the panel spells it through `tr`. */
const STEPPER_LABEL = 'Approval steps';

type Step = NonNullable<ApprovalRequestLite['flow_steps']>[number];
/** One step of a run: the approval node a request was opened for, and its label. */
type Step = { id: string; label: string };

/**
* The reporter's actual 6-step flow, labels verbatim (objectui#5554). They are
Expand All @@ -78,44 +85,49 @@ type Step = NonNullable<ApprovalRequestLite['flow_steps']>[number];
* would quietly move the fixture out of the failing regime.
*/
const REPORTED_STEPS: Step[] = [
{ id: 's1', label: '需求部门负责人初审', state: 'done' },
{ id: 's2', label: '工厂生产工艺负责人审核', state: 'done' },
{ id: 's3', label: '工厂业财审核(确认单价/派工工时)', state: 'current' },
{ id: 's4', label: '事业部成本改善经理加审', state: 'upcoming' },
{ id: 's5', label: '区域总经理+事业部业财运营总监会审', state: 'upcoming' },
{ id: 's6', label: '工厂厂长审批', state: 'upcoming' },
{ id: 's1', label: '需求部门负责人初审' },
{ id: 's2', label: '工厂生产工艺负责人审核' },
{ id: 's3', label: '工厂业财审核(确认单价/派工工时)' },
{ id: 's4', label: '事业部成本改善经理加审' },
{ id: 's5', label: '区域总经理+事业部业财运营总监会审' },
{ id: 's6', label: '工厂厂长审批' },
];

/** A synthetic flow of `n` steps, for the step-count invariance sweep. */
function stepsOfLength(n: number): Step[] {
return Array.from({ length: n }, (_, i) => ({
id: `syn_${i}`,
label: `区域总经理+事业部业财运营总监会审 ${i + 1}`,
state: i === 0 ? 'current' : 'upcoming',
})) as Step[];
}));
}

function pendingWith(flow_steps: Step[]): ApprovalRequestLite {
/** The request the run opened at `step`, the `i`-th step it reached. */
function requestAt(step: Step, i: number, status: string): ApprovalRequestLite {
return {
id: 'req_pending',
id: `req_${step.id}`,
process_name: 'flow:purchase',
process_label: 'Purchase Approval',
object_name: 'purchase_order',
record_id: 'rec_1',
status: 'pending',
status,
submitter_id: 'u_submitter',
submitter_name: 'Zhou Ming',
submitted_at: '2026-08-20T08:00:00Z',
submitted_at: `2026-08-20T08:${String(i).padStart(2, '0')}:00Z`,
flow_run_id: 'run_1',
flow_node_id: step.id,
current_step: step.id,
step_label: step.label,
viewer: { can_act: false, is_submitter: false },
flow_steps,
};
}

function renderWithSteps(flow_steps: Step[]) {
const pending = pendingWith(flow_steps);
/** A run that passed every step but the last, and waits on the last. */
function renderWithSteps(steps: Step[]) {
const rows = steps.map((s, i) => requestAt(s, i, i === steps.length - 1 ? 'pending' : 'approved'));
const pending = rows[rows.length - 1];
return render(
<RecordApprovalsPanel
approvals={{ available: true, requests: [pending], pendingRequest: pending }}
approvals={{ available: true, requests: [...rows].reverse(), pendingRequest: pending }}
currentUserId="u_viewer"
/>,
);
Expand Down Expand Up @@ -254,10 +266,10 @@ describe('RecordApprovalsPanel — vertical step stepper (objectui#5554)', () =>
expect(rows.slice(0, -1).every((r) => rail(r) !== undefined)).toBe(true);
expect(rail(rows[rows.length - 1])).toBeUndefined();

// s2 (done) and s3 (current) are the steps rows 1 and 2 lead into, so
// those segments are green; s4 is upcoming, so row 2's successor is not.
expect(tokens(rail(rows[0])!)).toContain('bg-emerald-300');
expect(tokens(rail(rows[1])!)).toContain('bg-emerald-300');
expect(tokens(rail(rows[2])!)).toContain('bg-border');
// Every step a segment leads into is passed or pending, so every segment
// is green: the line draws nothing ahead of the pending step.
for (const row of rows.slice(0, -1)) {
expect(tokens(rail(row)!)).toContain('bg-emerald-300');
}
});
});
71 changes: 64 additions & 7 deletions ui/packages/app-shell/src/views/RecordApprovalsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
useApproverDirectory,
type ApproverDirectory,
} from '../hooks/useApproverDirectory.js';
import { ApprovalStepLine } from './approval-progress/ApprovalStepLine.js';
import { ApprovalStepLine, type ApprovalFlowStep } from './approval-progress/ApprovalStepLine.js';
import { DecisionProgressIndicator } from './approval-progress/DecisionProgressIndicator.js';
import { eligibleApproverCount } from './approval-progress/eligibleApprovers.js';

Expand Down Expand Up @@ -206,6 +206,63 @@ function stepDisplayText(
return label || (machineName ? prettifyMachineName(machineName) : null);
}

/**
* The steps the record's step line draws for `current`: the approval steps
* its flow run has already passed, oldest first, then `current` itself
* (objectstack#26563). Every step is read off a request row the run really
* opened, never off the flow's graph.
*
* The approvals get's `flow_steps` is not this request's route: the server
* walks the flow from its start preferring `approve`, then `true`, then the
* first edge, and marks done / current / upcoming against that one trunk. A
* request a decision sent down another branch is then shown on rungs it never
* visits, and a rung a branch rejoins after shows the trunk's side-step as
* done. So the line is built from facts instead, until that read serves the
* route itself:
*
* - a passed step is a request of the same `flow_run_id`, on another node,
* `approved`, opened before `current`; a node approved in several rounds
* (ADR-0044) is drawn once, at its latest round;
* - nothing ahead of `current` is drawn: no request row says which branch the
* run takes next.
*
* `requests` is the list read, which serves a request only to its
* participants, so a step this viewer took no part in is missing from the
* line rather than guessed. A row without a run, node or open time draws no
* line at all.
*/
export function visitedApprovalSteps(
current: ApprovalRequestLite | null | undefined,
requests: ReadonlyArray<ApprovalRequestLite>,
): ApprovalFlowStep[] {
const runId = current?.flow_run_id;
const nodeId = current?.flow_node_id;
const openedAt = current?.submitted_at;
if (!current || !runId || !nodeId || !openedAt) return [];

const passed = new Map<string, { row: ApprovalRequestLite; at: string }>();
for (const r of requests) {
const node = r.flow_node_id;
const at = r.submitted_at;
if (r.flow_run_id !== runId || !node || node === nodeId) continue;
if (r.status !== 'approved' || !at || at >= openedAt) continue;
const prev = passed.get(node);
if (!prev || prev.at < at) passed.set(node, { row: r, at });
}

const step = (r: ApprovalRequestLite, id: string, state: ApprovalFlowStep['state']): ApprovalFlowStep => ({
id,
label: stepDisplayText(r.step_label, r.current_step || id) ?? id,
state,
});
return [
...[...passed.entries()]
.sort(([, a], [, b]) => a.at.localeCompare(b.at))
.map(([node, { row }]) => step(row, node, 'done')),
step(current, nodeId, current.status === 'approved' ? 'done' : 'current'),
];
}

/**
* Merge the per-request action threads into one chronological (oldest-first)
* timeline. Explicit sort — the panel must not depend on per-request server
Expand Down Expand Up @@ -424,12 +481,12 @@ export const RecordApprovalsPanel: React.FC<RecordApprovalsPanelProps> = ({
</div>

<div className="px-4 py-3 space-y-3">
{/* Flow-level step strip — where in the multi-level flow this record
sits; present on the enriched pending row only (single reads).
Vertical at every step count (objectui#5554); the markup is the
one `ApprovalStepLine` the approval request page's decision panel
draws too (objectui#12491), and it draws nothing under two steps. */}
<ApprovalStepLine steps={pendingRequest?.flow_steps} />
{/* Flow-level step line — the steps the pending request's run has
passed, then the pending one, read off the run's own request rows
and never off the flow graph (objectstack#26563, see
`visitedApprovalSteps`). Vertical at every step count
(objectui#5554); it draws nothing under two steps. */}
<ApprovalStepLine steps={visitedApprovalSteps(pendingRequest, requests)} />

{/* Aggregation progress — the pending node's server-computed tally
(unanimous / quorum approvals, per-group countersign), drawn by
Expand Down
Loading
Loading