From 3d176f3b495dbd4a6ab724c9845624af34c37935 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 02:59:17 +0000 Subject: [PATCH 1/7] feat(console): the approvals queue steps from request to request and opens the next one after a decision From the inbox's pending tab a request opens with the queue as the list shows it (filtered and sorted): the request page's top bar draws the existing counter and next / previous over it, and a toggle (default on, kept per reader) opens the next request once a decision takes the current one out of the reader's queue, back to the list when none is left. Claude-Session: https://claude.ai/code/session_01WGufzgwLxpT1AVJJAwAvyR Co-authored-by: Claude --- .../src/pages/system/ApprovalsInboxPage.tsx | 54 +++--- ui/packages/app-shell/src/index.ts | 3 + .../src/utils/workspacePreference.ts | 10 ++ .../app-shell/src/views/RecordDetailView.tsx | 11 +- .../approvalQueueAdvance.tsx | 165 ++++++++++++++++++ .../app-shell/src/views/recordDrawerStack.tsx | 39 +++-- ui/packages/i18n/src/locales/ar.ts | 2 + ui/packages/i18n/src/locales/de.ts | 2 + ui/packages/i18n/src/locales/en.ts | 2 + ui/packages/i18n/src/locales/es.ts | 2 + ui/packages/i18n/src/locales/fr.ts | 2 + ui/packages/i18n/src/locales/ja.ts | 2 + ui/packages/i18n/src/locales/ko.ts | 2 + ui/packages/i18n/src/locales/pt-BR.ts | 2 + ui/packages/i18n/src/locales/ru.ts | 2 + ui/packages/i18n/src/locales/zh-Hans.ts | 2 + ui/packages/i18n/src/locales/zh-Hant.ts | 2 + 17 files changed, 273 insertions(+), 31 deletions(-) create mode 100644 ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance.tsx diff --git a/ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx b/ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx index 405dd4f4f64..f26a3f64938 100644 --- a/ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx +++ b/ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx @@ -31,7 +31,7 @@ import { useCallback, useDeferredValue, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react'; import { Link, Navigate, useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom'; -import { ConsolePageHeader, objectHostAppSegment, useMetadata } from '@object-ui/app-shell'; +import { ConsolePageHeader, approvalQueueState, objectHostAppSegment, useMetadata } from '@object-ui/app-shell'; import { Button, buttonVariants, @@ -958,25 +958,6 @@ function ApprovalsQueue() { */ const [environmentPendingCount, setEnvironmentPendingCount] = useState(null); - /** - * Open a request on its page (objectui#12484): the page objectstack serves - * for it, on the standard record route. A navigation, so Back returns to the - * queue with its tab, filters and scroll as they were. It opens under the - * app that owns the row's record (`requestPagePath`). - */ - const openRequest = useCallback( - (r: ApprovalRequestRow) => - navigate( - requestPagePath( - Array.isArray(metadataApps) ? (metadataApps as Record[]) : undefined, - r.object_name, - appName, - r.id, - ), - ), - [navigate, appName, metadataApps], - ); - /** * objectui#5211 — an approver can be routed a request about a record they * cannot read (approver routing goes by position; record visibility is a @@ -1253,6 +1234,39 @@ function ApprovalsQueue() { return sorted; }, [rows, deferredQuery, processFilter, objectFilter, statusFilter, tab, sortKey, hiddenFields, displayLocale]); + /** + * Open a request on its page (objectui#12484): the page objectstack serves + * for it, on the standard record route. A navigation, so Back returns to the + * queue with its tab, filters and scroll as they were. It opens under the + * app that owns the row's record (`requestPagePath`). + * + * objectstack#34586 — from 「待我审批」 the page is handed the queue as this + * list shows it, filtered and sorted (`approvalQueueState`): its top bar + * draws 「第 N 条,共 M 条」 with ↓ ↑ and `j` / `k` over it, and a decision + * that takes the request out of the queue opens the next one. The other + * tabs list requests the reader is not deciding, so they hand no queue. + */ + const openRequest = useCallback( + (r: ApprovalRequestRow) => + navigate( + requestPagePath( + Array.isArray(metadataApps) ? (metadataApps as Record[]) : undefined, + r.object_name, + appName, + r.id, + ), + tab === 'pending' + ? { + state: approvalQueueState( + { pathname: `${location.pathname}${location.search}`, label: inboxTitle }, + filteredRows.map((row) => row.id), + ), + } + : undefined, + ), + [navigate, appName, metadataApps, tab, location.pathname, location.search, inboxTitle, filteredRows], + ); + // Reset selection when underlying filtered list changes (avoid acting on hidden rows). useEffect(() => { if (selectedRowIds.size === 0) return; diff --git a/ui/packages/app-shell/src/index.ts b/ui/packages/app-shell/src/index.ts index 2070525bc4d..cd1773bdd44 100644 --- a/ui/packages/app-shell/src/index.ts +++ b/ui/packages/app-shell/src/index.ts @@ -98,6 +98,9 @@ export { resolveHostAppSegment, appRouteSegment, filterActiveApps } from './util // the record, or to a page about it, opens under), as opposed to which app // hosts an app-independent page. `./utils/objectHostApp` is the contract. export { objectHostAppSegment } from './utils/objectHostApp.js'; +// objectstack#34586 — the history state the approvals inbox opens a request +// with, so its page steps the reader's pending queue and moves on after a decision. +export { approvalQueueState } from './views/approval-decision/approvalQueueAdvance.js'; // Which apps are the platform's own code-loaded built-ins (`com.objectstack.*`), // one criterion for the AI switcher and the console's first-run checklist. export { isPlatformBuiltinApp } from './utils/platformApp.js'; diff --git a/ui/packages/app-shell/src/utils/workspacePreference.ts b/ui/packages/app-shell/src/utils/workspacePreference.ts index 254b48d236c..df02f6d5ee6 100644 --- a/ui/packages/app-shell/src/utils/workspacePreference.ts +++ b/ui/packages/app-shell/src/utils/workspacePreference.ts @@ -151,6 +151,16 @@ export const RECORD_RELATED_COLUMN_PREFERENCE = defineWorkspacePreference({ + name: 'approvals.queue.open-next', + codec: switchCodec, +}); + /** * How the reader arranged the record page's related panels, per object * (scope `object:OBJECT_NAME`, objectstack#27055, objectstack#27524): diff --git a/ui/packages/app-shell/src/views/RecordDetailView.tsx b/ui/packages/app-shell/src/views/RecordDetailView.tsx index a9e43cb9454..53f7e3ff1d8 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.tsx @@ -86,6 +86,7 @@ import { RECORD_APPROVAL_ACTION_LOCATION, RECORD_APPROVAL_EXCLUDED_ACTIONS, } from './recordApprovalActions.js'; +import { useApprovalQueueAdvance } from './approval-decision/approvalQueueAdvance.js'; // Side-effect registration of `record:approvals` — synthesized record pages // reference the node whenever the record has approval requests (#3461), so // the type must resolve wherever this view renders, not only under hosts @@ -1256,6 +1257,13 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri }, [pageHasRightColumn, pageRootEl, relatedSwitch, setRelatedSwitch]); useAdvertiseShortcut(TOGGLE_RELATED_SHORTCUT, pageHasRightColumn); const [pageRecord, setPageRecord] = useState(null); + // objectstack#34586 — a request opened from the approvals queue: the top + // bar's 「处理后打开下一条」, and the next request once a decision takes this + // one out of the reader's queue. + const approvalQueueSwitch = useApprovalQueueAdvance( + !embedded && objectName === SYS_APPROVAL_REQUEST_OBJECT ? recordId : undefined, + pageRecord, + ); // 'idle' | 'loading' | 'loaded' | 'missing' | 'forbidden' | 'failed' — // distinguishes "haven't tried yet" from each way the read can end. The // short-circuits below render a clean empty state for the last three @@ -5165,6 +5173,7 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri leadingTestId="record-page-leading" leading={phoneBack} stepper={pageStepper} + toggles={approvalQueueSwitch ?? undefined} /> {phonePathRow} @@ -5173,7 +5182,7 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri leadingTestId="record-page-leading" leading={pageLeading} stepper={pageStepper} - toggles={panelToggles ?? undefined} + toggles={approvalQueueSwitch || panelToggles ? <>{approvalQueueSwitch}{panelToggles} : undefined} frame={pageReturn.collapse ? : undefined} /> ); diff --git a/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance.tsx b/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance.tsx new file mode 100644 index 00000000000..31ff724cb69 --- /dev/null +++ b/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance.tsx @@ -0,0 +1,165 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * Working through the approvals queue on the request pages + * (objectstack#34586). + * + * The inbox's 「待我审批」 tab opens a request on its page with the queue as it + * shows it, filtered and sorted: {@link approvalQueueState} is the history + * state it navigates with. Its `from` is the shape every list hands a page it + * opens (`from.pathname`, `from.label`, `from.siblings`), so the record page's + * own top bar draws the counter 「第 N 条,共 M 条」 and ↓ ↑ (with `j` / `k`) over + * it, through `useRecordPageReturn` — no second sibling mechanism. The one + * key this module adds, {@link APPROVAL_QUEUE_STATE}, says the set is the + * reader's pending queue, which is what lets a decision move on. + * + * {@link useApprovalQueueAdvance} watches the request the page shows. When it + * leaves the reader's pending queue — its status leaves `pending`, or the + * server's `viewer.can_act` turns false (approved by a countersign slot, + * reassigned, sent back, rejected) — while the reader's 「处理后打开下一条」 is + * on, the page is replaced by the next request of the queue, the one after it + * (or, at the end, the one before it), with the decided one dropped from the + * set. With none left it goes back to the list and says the list is done. The + * change is seen on the page's own re-read after the decision, not guessed + * from the action: an action that leaves the request pending for the reader + * (request more info, remind) keeps the page where it is. + * + * A page opened any other way — a notification, a direct link, another list — + * carries no such state: no counter, no switch, nothing moves. + * + * The switch is the reader's own preference + * ({@link APPROVAL_QUEUE_OPEN_NEXT_PREFERENCE}, kept per browser and never + * metadata), default on. + */ + +import * as React from 'react'; +import { useLocation, useNavigate } from 'react-router-dom'; +import { toast } from 'sonner'; +import { Checkbox } from '@object-ui/components'; +import { useObjectTranslation } from '@object-ui/react'; +import { readFromSiblings, siblingRecordStep } from '../recordDrawerStack.js'; +import { + APPROVAL_QUEUE_OPEN_NEXT_PREFERENCE, + useWorkspacePreference, + type PreferenceSwitch, +} from '../../utils/workspacePreference.js'; + +/** The history-state key that marks a request page opened from the reader's pending queue. */ +export const APPROVAL_QUEUE_STATE = 'approvalQueue'; + +/** + * The history state the inbox opens a request with: the queue as the list + * shows it, in its order, and the way back to the list. + */ +export function approvalQueueState( + list: { pathname: string; label: string }, + requestIds: ReadonlyArray, +): Record { + return { + from: { pathname: list.pathname, label: list.label, siblings: requestIds.map(String) }, + [APPROVAL_QUEUE_STATE]: true, + }; +} + +/** The queue a request page was opened from, or `undefined` when it was opened any other way. */ +export function readApprovalQueue( + state: unknown, + requestId: string | undefined, +): { siblings: readonly string[]; listPath: string } | undefined { + if (!requestId || !state || typeof state !== 'object') return undefined; + if ((state as Record)[APPROVAL_QUEUE_STATE] !== true) return undefined; + const listPath = (state as { from?: { pathname?: unknown } }).from?.pathname; + const siblings = readFromSiblings(state); + if (typeof listPath !== 'string' || !siblings || !siblings.includes(requestId)) return undefined; + return { siblings, listPath }; +} + +/** + * Whether the request row is in the reader's pending queue: pending, and the + * server says the reader can act on it. A row served without the `viewer` + * block answers by status alone; a row with no status is not known. + */ +export function inReaderQueue(row: unknown): boolean | undefined { + if (!row || typeof row !== 'object') return undefined; + const status = (row as { status?: unknown }).status; + if (typeof status !== 'string') return undefined; + if (status !== 'pending') return false; + const canAct = (row as { viewer?: { can_act?: unknown } }).viewer?.can_act; + return typeof canAct === 'boolean' ? canAct : true; +} + +/** + * Which request to open once `decidedId` has left the queue: the one after + * it, or at the end of the queue the one before it; `undefined` when it was + * the last. `remaining` is the queue without it, in its order. + */ +export function nextInQueue( + siblings: readonly string[], + decidedId: string, +): { next: string | undefined; remaining: string[] } { + const index = siblings.indexOf(decidedId); + const remaining = siblings.filter((id) => id !== decidedId); + if (index < 0) return { next: undefined, remaining }; + return { next: siblings[index + 1] ?? siblings[index - 1], remaining }; +} + +/** The reader's 「处理后打开下一条」 and its setter. */ +export function useApprovalQueueOpenNext(): [boolean, (on: boolean) => void] { + const [value, setValue] = useWorkspacePreference(APPROVAL_QUEUE_OPEN_NEXT_PREFERENCE, 'user', 'on'); + const set = React.useCallback((on: boolean) => setValue(on ? 'on' : 'off'), [setValue]); + return [value !== 'off', set]; +} + +/** + * The request page's half of the queue: watches `row` (the request the page + * shows, as it re-reads it) and moves on when a decision takes it out of the + * reader's queue. `requestId` is the page's own record id, `undefined` off a + * request page or in a pane. Answers the top bar's switch, or `null` when the + * page was not opened from the queue. + */ +export function useApprovalQueueAdvance(requestId: string | undefined, row: unknown): React.ReactNode { + const location = useLocation(); + const navigate = useNavigate(); + const { t } = useObjectTranslation(); + const [openNext, setOpenNext] = useApprovalQueueOpenNext(); + const queue = React.useMemo(() => readApprovalQueue(location.state, requestId), [location.state, requestId]); + const rowId = row && typeof row === 'object' ? (row as { id?: unknown }).id : undefined; + const queued = rowId != null && String(rowId) === requestId ? inReaderQueue(row) : undefined; + /** What the page last showed of this request: its id and whether it was in the queue. */ + const seen = React.useRef<{ id: string; queued: boolean } | null>(null); + + React.useEffect(() => { + if (!requestId || queued === undefined) return; + const before = seen.current; + seen.current = { id: requestId, queued }; + if (!queue || !openNext || before?.id !== requestId || !before.queued || queued) return; + const { next, remaining } = nextInQueue(queue.siblings, requestId); + if (next === undefined) { + toast.success(String(t('approvalsInbox.queueDone', { defaultValue: 'No more pending requests in this list.' }))); + navigate(queue.listPath, { replace: true }); + return; + } + const step = siblingRecordStep(location, requestId, next); + if (step === null) return; + const from = (step.state.from ?? {}) as Record; + navigate(step.to, { replace: true, state: { ...step.state, from: { ...from, siblings: remaining } } }); + }, [requestId, queued, queue, openNext, location, navigate, t]); + + if (!queue) return null; + const label = String(t('approvalsInbox.openNextAfterDecision', { defaultValue: 'Open next after deciding' })); + return ( + + ); +} diff --git a/ui/packages/app-shell/src/views/recordDrawerStack.tsx b/ui/packages/app-shell/src/views/recordDrawerStack.tsx index 54857658867..ac0ce9131f3 100644 --- a/ui/packages/app-shell/src/views/recordDrawerStack.tsx +++ b/ui/packages/app-shell/src/views/recordDrawerStack.tsx @@ -724,6 +724,31 @@ function siblingRecordPath(pathname: string, from: string, to: string): string | return null; } +/** + * Where a page opened from a list's rows (its `from` siblings) goes to show + * the sibling `toId` in place of `fromId`: the same route with the record + * segment renamed, the same `?tab=`, an open related tab left behind, and the + * history state carried along. `null` when the pathname names no `fromId` + * record. The counter's ↓ ↑ navigate here with `replace`; so does the + * approvals queue's 「open the next one」 after a decision + * (`approval-decision/approvalQueueAdvance.tsx`), with its own `from`. + */ +export function siblingRecordStep( + location: { pathname: string; search: string; state: unknown }, + fromId: string, + toId: string, +): { to: { pathname: string; search: string }; state: Record } | null { + const pathname = siblingRecordPath(location.pathname, fromId, toId); + if (pathname === null) return null; + const pageSearch = new URLSearchParams(location.search); + pageSearch.delete(RECORD_RELATED_ENLARGE_PARAM); + const qs = pageSearch.toString(); + return { + to: { pathname, search: qs ? `?${qs}` : '' }, + state: withoutKeys(location.state, [RECORD_RELATED_ENLARGE_PUSHED_STATE]), + }; +} + /** What a page opened from a list knows about that list. */ export interface RecordPageReturn { /** @@ -741,7 +766,7 @@ export interface RecordPageReturn { * The rows a list showed, handed in the page's `from` state by a list whose * rows open as pages (objectstack#27524): its row click and its record links. */ -function readFromSiblings(state: unknown): readonly string[] | undefined { +export function readFromSiblings(state: unknown): readonly string[] | undefined { const from = (state as { from?: { siblings?: unknown } } | null | undefined)?.from; const siblings = from?.siblings; return Array.isArray(siblings) && siblings.every((id) => typeof id === 'string') @@ -779,15 +804,9 @@ export function useRecordPageReturn(recordId: string | undefined): RecordPageRet if (!recordId || !siblings || index < 0) return {}; // The `from` state goes along unchanged: the next page has the same list. const go = (nextId: string) => () => { - const to = siblingRecordPath(location.pathname, recordId, nextId); - if (to === null) return; - const pageSearch = new URLSearchParams(location.search); - pageSearch.delete(RECORD_RELATED_ENLARGE_PARAM); - const qs = pageSearch.toString(); - navigate( - { pathname: to, search: qs ? `?${qs}` : '' }, - { replace: true, state: withoutKeys(location.state, [RECORD_RELATED_ENLARGE_PUSHED_STATE]) }, - ); + const step = siblingRecordStep(location, recordId, nextId); + if (step === null) return; + navigate(step.to, { replace: true, state: step.state }); }; return { stepper: { diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index 25c3804a5b1..3e2a9f619b7 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -4746,6 +4746,8 @@ const ar = { progressBar: 'تقدم القرار', declaredActions: 'الإجراءات', decisionPanelOffRequestPage: 'لوحة قرار الموافقة تعمل فقط في صفحات طلبات الموافقة.', + openNextAfterDecision: 'فتح التالي بعد اتخاذ القرار', + queueDone: 'لا توجد طلبات معلقة أخرى في هذه القائمة.', snapshotAsSubmitted: 'كما قُدِّم', attachmentChip: 'مرفق', attachmentOpenFailed: 'تعذّر فتح المرفق — يرجى المحاولة مرة أخرى', diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index 91f9d77be0c..a4379628942 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -4349,6 +4349,8 @@ const de = { progressBar: 'Entscheidungsfortschritt', declaredActions: 'Aktionen', decisionPanelOffRequestPage: 'Der Entscheidungsbereich für Genehmigungen funktioniert nur auf Seiten von Genehmigungsanfragen.', + openNextAfterDecision: 'Nach der Entscheidung die nächste öffnen', + queueDone: 'In dieser Liste sind keine offenen Anfragen mehr.', snapshotAsSubmitted: 'Wie eingereicht', attachmentChip: 'Anhang', attachmentOpenFailed: 'Anhang konnte nicht geöffnet werden – bitte erneut versuchen', diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index 399f5a34f49..b8d4e109fc1 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -5285,6 +5285,8 @@ const en = { progressBar: 'Decision progress', declaredActions: 'Actions', decisionPanelOffRequestPage: 'The approval decision panel only works on approval request pages.', + openNextAfterDecision: 'Open next after deciding', + queueDone: 'No more pending requests in this list.', snapshotAsSubmitted: 'As submitted', attachmentChip: 'Attachment', attachmentOpenFailed: 'Could not open the attachment — please try again', diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index 2c4e59cde03..e05c1a25ab0 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -4449,6 +4449,8 @@ const es = { progressBar: 'Progreso de la decisión', declaredActions: 'Acciones', decisionPanelOffRequestPage: 'El panel de decisión de aprobación solo funciona en las páginas de solicitudes de aprobación.', + openNextAfterDecision: 'Abrir la siguiente tras decidir', + queueDone: 'No quedan solicitudes pendientes en esta lista.', snapshotAsSubmitted: 'Tal como se envió', attachmentChip: 'Adjunto', attachmentOpenFailed: 'No se pudo abrir el archivo adjunto: inténtalo de nuevo', diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index 195c11068ac..5c4342f258d 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -4445,6 +4445,8 @@ const fr = { progressBar: 'Avancement de la décision', declaredActions: 'Actions', decisionPanelOffRequestPage: 'Le panneau de décision d\'approbation ne fonctionne que sur les pages de demande d\'approbation.', + openNextAfterDecision: 'Ouvrir la suivante après décision', + queueDone: 'Plus aucune demande en attente dans cette liste.', snapshotAsSubmitted: 'Tel que soumis', attachmentChip: 'Pièce jointe', attachmentOpenFailed: "Impossible d'ouvrir la pièce jointe — veuillez réessayer", diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index 3abb7feb40d..359d6184eef 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -4351,6 +4351,8 @@ const ja = { progressBar: '承認の進捗', declaredActions: 'アクション', decisionPanelOffRequestPage: '承認の決定パネルは承認リクエストのページでのみ機能します。', + openNextAfterDecision: '決定後に次を開く', + queueDone: 'このリストの保留中のリクエストはすべて処理済みです。', snapshotAsSubmitted: '申請時の内容', attachmentChip: '添付ファイル', attachmentOpenFailed: '添付ファイルを開けませんでした。もう一度お試しください', diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index f2d0bff50fe..3dd9ed98b64 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -4348,6 +4348,8 @@ const ko = { progressBar: '결정 진행 상황', declaredActions: '작업', decisionPanelOffRequestPage: '승인 결정 패널은 승인 요청 페이지에서만 작동합니다.', + openNextAfterDecision: '결정 후 다음 열기', + queueDone: '이 목록에 대기 중인 요청이 더 이상 없습니다.', snapshotAsSubmitted: '제출 당시 내용', attachmentChip: '첨부 파일', attachmentOpenFailed: '첨부 파일을 열 수 없습니다. 다시 시도해 주세요', diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index b3f5e8e11e1..f3404659acc 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -4444,6 +4444,8 @@ const pt = { progressBar: 'Progresso da decisão', declaredActions: 'Ações', decisionPanelOffRequestPage: 'O painel de decisão de aprovação só funciona nas páginas de solicitações de aprovação.', + openNextAfterDecision: 'Abrir a próxima após decidir', + queueDone: 'Não há mais solicitações pendentes nesta lista.', snapshotAsSubmitted: 'Conforme enviado', attachmentChip: 'Anexo', attachmentOpenFailed: 'Não foi possível abrir o anexo — tente novamente', diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index 42eb479a1b6..7ad3d05b114 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -4558,6 +4558,8 @@ const ru = { progressBar: 'Ход решения', declaredActions: 'Действия', decisionPanelOffRequestPage: 'Панель решения по согласованию работает только на страницах запросов на согласование.', + openNextAfterDecision: 'Открывать следующий после решения', + queueDone: 'В этом списке больше нет ожидающих запросов.', snapshotAsSubmitted: 'На момент подачи', attachmentChip: 'Вложение', attachmentOpenFailed: 'Не удалось открыть вложение — попробуйте ещё раз', diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index f618d296900..09335f75ffc 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -4598,6 +4598,8 @@ const zh = { progressBar: '决策进度', declaredActions: '操作', decisionPanelOffRequestPage: '审批决策面板仅在审批请求页面上可用。', + openNextAfterDecision: '处理后打开下一条', + queueDone: '这个列表里的待审请求已全部处理完。', snapshotAsSubmitted: '提交时的内容', attachmentChip: '附件', attachmentOpenFailed: '无法打开附件,请重试', diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index 1a20cc8cc7b..b6c01783d38 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -4598,6 +4598,8 @@ const zhHant = { progressBar: '決策進度', declaredActions: '操作', decisionPanelOffRequestPage: '審批決策面板僅在審批請求頁面上可用。', + openNextAfterDecision: '處理後打開下一條', + queueDone: '這個列表裡的待審請求已全部處理完。', snapshotAsSubmitted: '提交時的內容', attachmentChip: '附件', attachmentOpenFailed: '無法開啟附件,請重試', From 36749a16c0a6cdc0ac07b7a36a05a0d13da3eda0 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:03:15 +0000 Subject: [PATCH 2/7] test(console): pin the approvals queue stepper and open-next, and add the changeset Claude-Session: https://claude.ai/code/session_01WGufzgwLxpT1AVJJAwAvyR Co-authored-by: Claude --- .changeset/34586-approvals-queue-open-next.md | 17 + ...ovalsInboxPage.queueStepper-34586.test.tsx | 320 ++++++++++++++++++ .../approvalQueueAdvance-34586.test.tsx | 175 ++++++++++ 3 files changed, 512 insertions(+) create mode 100644 .changeset/34586-approvals-queue-open-next.md create mode 100644 ui/apps/console/src/pages/system/ApprovalsInboxPage.queueStepper-34586.test.tsx create mode 100644 ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance-34586.test.tsx diff --git a/.changeset/34586-approvals-queue-open-next.md b/.changeset/34586-approvals-queue-open-next.md new file mode 100644 index 00000000000..62b429f3fc0 --- /dev/null +++ b/.changeset/34586-approvals-queue-open-next.md @@ -0,0 +1,17 @@ +--- +'@object-ui/console': patch +'@object-ui/i18n': patch +--- + +feat(console): the approvals inbox's pending queue steps from request to request, and opens the next request after a decision + +Clause-②: no +Metadata-protocol: none + +From the Approvals Inbox's "My pending" tab, a request now opens with the queue as the list shows it, filtered and sorted: + +- The request page's top bar shows where the request sits in the queue (`1 / 3`, read out as "1 of 3 in Approvals Inbox") with the next / previous buttons and the `j` / `k` keys, and its breadcrumb leads back to the inbox. This is the counter every record page opened from a list already draws; the inbox now hands it the queue. +- A new "Open next after deciding" switch beside the counter, on by default and remembered per browser. When a decision takes the request out of your pending queue (approved, rejected, sent back, reassigned, or approved for your countersign slot while others still decide), the next request of the queue opens in its place and the decided one leaves the count. After the last one the page returns to the inbox and says the list is done. With the switch off the page stays on the decided request. An action that leaves the request waiting on you, such as asking for more information, does not move the page. +- A request opened any other way, from a notification, a direct link or the "Submitted by me" and "All" tabs, shows no counter and no switch, as before. + +No approval permission, rule or server endpoint changes. `@object-ui/i18n` adds `approvalsInbox.openNextAfterDecision` and `approvalsInbox.queueDone` in all 11 shipped locales; no key is renamed or removed. diff --git a/ui/apps/console/src/pages/system/ApprovalsInboxPage.queueStepper-34586.test.tsx b/ui/apps/console/src/pages/system/ApprovalsInboxPage.queueStepper-34586.test.tsx new file mode 100644 index 00000000000..e766201c7f6 --- /dev/null +++ b/ui/apps/console/src/pages/system/ApprovalsInboxPage.queueStepper-34586.test.tsx @@ -0,0 +1,320 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * objectstack#34586 — the approvals queue, request to request. + * + * From 「待我审批」 a request opens with the queue as the list shows it + * (filtered and sorted); the request page's top bar draws the counter and + * ↓ ↑ over it, and the 「处理后打开下一条」 switch (default on). A decision that + * takes the request out of the reader's queue opens the next one; with none + * left the page goes back to the list. A request opened without the list (a + * notification, a direct link) draws neither the counter nor the switch. + * + * The harness mounts the REAL inbox page and, on the record route, the REAL + * `RecordDetailView` under `ApprovalRecordReads`, with the served request page + * abridged to its decision panel and header, as + * `ApprovalsInboxPage.opensServedPage-12484.test.tsx` mounts them. Only the + * HTTP transport, the console adapter and the inbox's list read are doubled. + * A decision is the panel's own after-decision step: the served row changes + * and the request is announced changed on the data bus (`notifyDataChanged`), + * which is what `ApprovalDecisionPanel` does once a declared action succeeds; + * the advance logic itself is pinned beside its module + * (`approvalQueueAdvance-34586.test.tsx`). + */ +import '@testing-library/jest-dom/vitest'; +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { render, screen, cleanup, fireEvent, within, act, waitFor } from '@testing-library/react'; +import { MemoryRouter, Routes, Route, useLocation } from 'react-router-dom'; + +const { approvalsApiStub, ROWS, AUTH, toastStub } = vi.hoisted(() => { + const base = { + process_name: 'flow:invoice_approval', + process_label: 'Invoice Approval', + object_name: 'invoice', + object_label: 'Invoice', + status: 'pending', + current_step: 'manager_review', + step_label: 'Manager Review', + pending_approvers: ['u1'], + submitter_id: 'u2', + submitter_name: 'Sam Submitter', + }; + // Newest first is the inbox's default order: req_a, req_b, req_c. + const ROWS = [ + { ...base, id: 'req_a', record_id: 'inv_a', record_title: 'Alpha one', submitted_at: '2026-10-22T09:00:00.000Z' }, + { ...base, id: 'req_b', record_id: 'inv_b', record_title: 'Beta two', submitted_at: '2026-10-21T09:00:00.000Z' }, + { ...base, id: 'req_c', record_id: 'inv_c', record_title: 'Alpha three', submitted_at: '2026-10-20T09:00:00.000Z' }, + ]; + const approvalsApiStub = { + listRequests: vi.fn(async () => ({ data: ROWS.map((r) => ({ ...r })), total: ROWS.length })), + getRequest: vi.fn(async () => ({ data: ROWS[0] })), + listActions: vi.fn(async () => ({ data: [] })), + approve: vi.fn(async () => ({ data: ROWS[0], finalized: true })), + reject: vi.fn(async () => ({ data: ROWS[0], finalized: true })), + }; + const AUTH = { user: { id: 'u1', name: 'Ada', image: null }, activeOrganization: null }; + const toastStub = Object.assign(vi.fn(), { + success: vi.fn(), error: vi.fn(), info: vi.fn(), + warning: vi.fn(), loading: vi.fn(), dismiss: vi.fn(), + }); + return { approvalsApiStub, ROWS, AUTH, toastStub }; +}); + +vi.mock('@object-ui/auth', async (importOriginal) => ({ + ...(await importOriginal>()), + useAuth: () => AUTH, +})); +vi.mock('@object-ui/collaboration', async (importOriginal) => ({ + ...(await importOriginal>()), + useRecordPresence: () => [], + PresenceAvatars: () => null, +})); +vi.mock('sonner', () => ({ toast: toastStub })); +vi.mock('../../services/approvalsApi', async (importOriginal) => ({ + ...(await importOriginal>()), + approvalsApi: approvalsApiStub, +})); + +import { AdapterCtx, MetadataCtx, SchemaRendererProvider, notifyDataChanged, useAdapter } from '@object-ui/react'; +import { I18nProvider, type I18nConfig } from '@object-ui/i18n'; +import { RecordDetailView } from '@object-ui/app-shell'; +import { APPROVAL_STATUS_LABELS } from '@objectstack/spec/contracts'; +import { APPROVAL_ACTION_OBJECT, APPROVAL_REQUEST_OBJECT } from '../../services/approvalRequestsDataSource'; +import { ApprovalRecordReads } from '../../AppContent'; +import { ApprovalsInboxPage } from './ApprovalsInboxPage'; + +const APP = 'probe_app'; +const INBOX = `/apps/${APP}/system/approvals`; +const pageOf = (id: string) => `/apps/${APP}/${APPROVAL_REQUEST_OBJECT}/record/${id}`; + +const REQUEST_DEF = { + name: APPROVAL_REQUEST_OBJECT, + label: 'Approval Request', + pluralLabel: 'Approval Requests', + nameField: 'process_label', + fields: { + id: { label: 'Request ID', type: 'text', readonly: true }, + process_label: { label: 'Flow', type: 'text', readonly: true }, + object_name: { label: 'Object', type: 'text' }, + record_id: { label: 'Record ID', type: 'text', referenceVia: 'object_name' }, + status: { + label: 'Status', type: 'select', + options: Object.entries(APPROVAL_STATUS_LABELS).map(([value, label]) => ({ value, label })), + }, + }, + actions: [], + enable: { apiMethods: ['get', 'list'] }, +}; +const ACTION_DEF = { + name: APPROVAL_ACTION_OBJECT, + label: 'Approval Action', + pluralLabel: 'Approval Actions', + fields: { id: { label: 'Action ID', type: 'text' }, request_id: { label: 'Request', type: 'lookup', reference: APPROVAL_REQUEST_OBJECT } }, + enable: { apiMethods: ['get', 'list'] }, +}; +const INVOICE_DEF = { name: 'invoice', label: 'Invoice', nameField: 'name', fields: { name: { type: 'text', label: 'Name' } } }; +const DEFS: Record = { [APPROVAL_REQUEST_OBJECT]: REQUEST_DEF, [APPROVAL_ACTION_OBJECT]: ACTION_DEF, invoice: INVOICE_DEF }; + +/** objectstack's served request page, abridged to the header and the decision panel. */ +const SERVED_PAGE = { + name: 'sys_approval_request_detail', + label: 'Approval Request', + type: 'record', + object: APPROVAL_REQUEST_OBJECT, + template: 'default', + kind: 'full', + isDefault: true, + regions: [{ name: 'main', width: 'full', components: [{ type: 'page:header' }, { type: 'record:approval_decision' }] }], +}; + +function json(status: number, body: unknown): Response { + return new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } }); +} + +/** The approvals get per request, as `ApprovalRecordReads` reads it. A decision rewrites one. */ +let served: Record> = {}; +function resetServed() { + served = Object.fromEntries( + ROWS.map((r) => [r.id, { ...r, viewer: { can_act: true, is_submitter: false, can_override: false } }]), + ); +} +const transport = vi.fn(async (input: RequestInfo | URL, init?: RequestInit): Promise => { + const raw = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url; + const url = new URL(raw, 'http://test.local'); + const method = (init?.method ?? (input instanceof Request ? input.method : 'GET')).toUpperCase(); + const m = /^\/api\/v1\/approvals\/requests\/([^/]+)(\/actions)?$/.exec(url.pathname); + if (method === 'GET' && m && served[m[1]]) return m[2] ? json(200, { data: [] }) : json(200, served[m[1]]); + return json(200, { success: true, data: [] }); +}); +vi.stubGlobal('fetch', transport); + +const host = { + find: vi.fn(async () => ({ data: [], total: 0 })), + findOne: vi.fn(async () => null), + create: vi.fn(), update: vi.fn(), delete: vi.fn(), + getObjectSchema: vi.fn(async (name: string) => DEFS[name] ?? null), +}; +const metadata = { + apps: [], objects: [REQUEST_DEF, ACTION_DEF, INVOICE_DEF], dashboards: [], reports: [], + pages: [SERVED_PAGE], loading: false, error: null, + refresh: async () => {}, invalidate: () => {}, ensureType: async () => [], + getItem: vi.fn(async (type: string, name: string) => (type === 'object' ? (DEFS[name] ?? null) : null)), + getItemsByType: () => [], + getTypeStatus: () => 'ready' as const, +}; +const EN: I18nConfig = { defaultLanguage: 'en', detectBrowserLanguage: false }; + +function GenericRecordRoute() { + return {}} />; +} + +function RouterProbe() { + const location = useLocation(); + return {location.pathname}; +} + +function renderAt(entries: string[]) { + return render( + + + + + + + + + } /> + } /> + + + + + + + , + ); +} + +const where = () => screen.getByTestId('where').textContent; + +/** The inbox's desktop row whose record title is `title`. */ +async function inboxRow(title: string): Promise { + await screen.findAllByText(title, undefined, { timeout: 8000 }); + const row = screen.getAllByRole('row').find((r) => within(r).queryAllByText(title).length > 0); + if (!row) throw new Error(`no inbox row for ${title}`); + return row; +} + +/** The request page has drawn its decision panel. */ +async function requestPage(): Promise { + await screen.findByTestId('approval-decision-panel', undefined, { timeout: 8000 }); +} + +/** The top bar's counter, by its accessible name (「第 N 条,共 M 条」 in zh-CN). */ +const counter = () => document.querySelector('[data-record-top-bar-position]'); + +/** What `ApprovalDecisionPanel` does after a declared decision succeeds, with the server's new row. */ +async function decide(id: string, next: Record) { + served[id] = { ...served[id], ...next }; + await act(async () => { + notifyDataChanged({ objectName: APPROVAL_REQUEST_OBJECT, recordId: id }); + }); +} + +beforeEach(() => { + transport.mockClear(); + for (const fn of Object.values(approvalsApiStub)) fn.mockClear(); + toastStub.success.mockClear(); + resetServed(); + try { window.localStorage.clear(); } catch { /* no storage */ } +}); +afterEach(cleanup); + +describe('the approvals queue steps from request to request (objectstack#34586)', () => { + it('acceptance 1: the first of three pending opens as 1 of 3, and ↓ opens the second', async () => { + renderAt([INBOX]); + fireEvent.click(await inboxRow('Alpha one')); + await requestPage(); + expect(where()).toBe(pageOf('req_a')); + + await waitFor(() => expect(counter()).not.toBeNull()); + expect(counter()).toHaveAttribute('aria-label', '1 of 3 in Approvals Inbox'); + expect(screen.getByTestId('approval-queue-open-next')).toBeInTheDocument(); + // The crumb leads back to the inbox, by its name. + expect(document.querySelector('[data-record-crumb-object]')).toHaveTextContent('Approvals Inbox'); + + fireEvent.click(document.querySelector('[data-record-top-bar-step="next"]') as HTMLElement); + await waitFor(() => expect(where()).toBe(pageOf('req_b'))); + await waitFor(() => expect(counter()).toHaveAttribute('aria-label', '2 of 3 in Approvals Inbox')); + }); + + it('the set is the queue as the list shows it: a search narrows it', async () => { + renderAt([INBOX]); + await inboxRow('Alpha one'); + fireEvent.change(screen.getByPlaceholderText('Search record, process, requester…'), { target: { value: 'alpha' } }); + await waitFor(() => expect(screen.queryAllByText('Beta two')).toHaveLength(0)); + fireEvent.click(await inboxRow('Alpha three')); + await requestPage(); + await waitFor(() => expect(counter()).toHaveAttribute('aria-label', '2 of 2 in Approvals Inbox')); + }); + + it('acceptance 2: approving the first lands on the second, and the last back on the list', async () => { + renderAt([INBOX]); + fireEvent.click(await inboxRow('Alpha one')); + await requestPage(); + await waitFor(() => expect(counter()).not.toBeNull()); + + await decide('req_a', { status: 'approved', viewer: { can_act: false, is_submitter: false, can_override: false } }); + await waitFor(() => expect(where()).toBe(pageOf('req_b'))); + // The decided request left the set: the second is now the first of two. + await waitFor(() => expect(counter()).toHaveAttribute('aria-label', '1 of 2 in Approvals Inbox')); + + await requestPage(); + await decide('req_b', { status: 'rejected', viewer: { can_act: false, is_submitter: false, can_override: false } }); + await waitFor(() => expect(where()).toBe(pageOf('req_c'))); + await requestPage(); + await waitFor(() => expect(counter()).toHaveAttribute('aria-label', '1 of 1 in Approvals Inbox')); + + await decide('req_c', { status: 'approved', viewer: { can_act: false, is_submitter: false, can_override: false } }); + await waitFor(() => expect(where()).toBe(INBOX)); + expect(toastStub.success).toHaveBeenCalledWith('No more pending requests in this list.'); + }); + + it('acceptance 3: with the switch off, the page stays on the decided request', async () => { + renderAt([INBOX]); + fireEvent.click(await inboxRow('Alpha one')); + await requestPage(); + const toggle = within(await screen.findByTestId('approval-queue-open-next')).getByRole('checkbox'); + expect(toggle).toHaveAttribute('aria-checked', 'true'); + fireEvent.click(toggle); + expect(toggle).toHaveAttribute('aria-checked', 'false'); + + await decide('req_a', { status: 'approved', viewer: { can_act: false, is_submitter: false, can_override: false } }); + // Give the page its re-read; it must not move. + await waitFor(() => expect(transport.mock.calls.filter(([i]) => String(i).includes('/requests/req_a')).length).toBeGreaterThan(1)); + expect(where()).toBe(pageOf('req_a')); + }); + + it('acceptance 4: a request opened without the list draws no counter and no switch, and a decision moves nothing', async () => { + renderAt([pageOf('req_b')]); + await requestPage(); + expect(counter()).toBeNull(); + expect(screen.queryByTestId('approval-queue-open-next')).toBeNull(); + + await decide('req_b', { status: 'approved', viewer: { can_act: false, is_submitter: false, can_override: false } }); + await waitFor(() => expect(transport.mock.calls.filter(([i]) => String(i).includes('/requests/req_b')).length).toBeGreaterThan(1)); + expect(where()).toBe(pageOf('req_b')); + }); + + it('CONTROL: a request opened from another tab carries no queue', async () => { + renderAt([INBOX]); + await inboxRow('Alpha one'); + fireEvent.mouseDown(screen.getByRole('tab', { name: /^All/ })); + fireEvent.click(screen.getByRole('tab', { name: /^All/ })); + fireEvent.click(await inboxRow('Alpha one')); + await requestPage(); + expect(counter()).toBeNull(); + expect(screen.queryByTestId('approval-queue-open-next')).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance-34586.test.tsx b/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance-34586.test.tsx new file mode 100644 index 00000000000..709992bc9d4 --- /dev/null +++ b/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance-34586.test.tsx @@ -0,0 +1,175 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * objectstack#34586 — the request page's half of the approvals queue + * (`approvalQueueAdvance.tsx`): which state marks a page as opened from the + * reader's queue, which request opens after a decision, and when the page + * moves at all. The inbox-to-page flow on the real record page is pinned in + * the console (`ApprovalsInboxPage.queueStepper-34586.test.tsx`). + * + * The harness is a route with the hook over a row the test hands it, and the + * record page's own `useRecordPageReturn` beside it, so the counter the top + * bar would draw is read from the same history state the hook writes. + */ +import '@testing-library/jest-dom/vitest'; +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { render, screen, cleanup, fireEvent, within, waitFor } from '@testing-library/react'; +import { MemoryRouter, Route, Routes, useLocation, useParams } from 'react-router-dom'; + +const { toastStub } = vi.hoisted(() => ({ + toastStub: Object.assign(vi.fn(), { success: vi.fn(), error: vi.fn() }), +})); +vi.mock('sonner', () => ({ toast: toastStub })); + +import { + APPROVAL_QUEUE_STATE, + approvalQueueState, + inReaderQueue, + nextInQueue, + readApprovalQueue, + useApprovalQueueAdvance, +} from './approvalQueueAdvance.js'; +import { useRecordPageReturn } from '../recordDrawerStack.js'; + +const LIST = { pathname: '/apps/crm/system/approvals', label: 'Approvals Inbox' }; +const pageOf = (id: string) => `/apps/crm/sys_approval_request/record/${id}`; + +type Row = { id: string; status: string; viewer?: { can_act: boolean } }; +const pending = (id: string): Row => ({ id, status: 'pending', viewer: { can_act: true } }); + +/** The page: the hook over the row the test holds for the route's id. */ +function Page({ rows }: { rows: Record }) { + const { recordId } = useParams(); + const location = useLocation(); + const toggle = useApprovalQueueAdvance(recordId, recordId ? rows[recordId] : undefined); + const position = useRecordPageReturn(recordId).stepper?.position; + const siblings = (location.state as { from?: { siblings?: unknown } } | null)?.from?.siblings; + return ( + <> + {location.pathname} + {position ? `${position.index + 1}/${position.total}` : 'none'} + {JSON.stringify(siblings ?? null)} + {toggle} + + ); +} + +function Harness({ entry, rows }: { entry: { pathname: string; state?: unknown }; rows: Record }) { + return ( + + + {LIST.pathname}} /> + } /> + + + ); +} + +const QUEUE = ['r1', 'r2', 'r3']; +const fromQueue = (id: string, ids: string[] = QUEUE) => ({ pathname: pageOf(id), state: approvalQueueState(LIST, ids) }); +const where = () => screen.getByTestId('where').textContent; +const position = () => screen.getByTestId('position').textContent; + +beforeEach(() => { + toastStub.success.mockClear(); + try { window.localStorage.clear(); } catch { /* no storage */ } +}); +afterEach(cleanup); + +describe('the queue state (objectstack#34586)', () => { + it('reads the queue only from a page the inbox marked, and only for a request in it', () => { + const state = approvalQueueState(LIST, QUEUE); + expect(state[APPROVAL_QUEUE_STATE]).toBe(true); + expect(readApprovalQueue(state, 'r2')).toEqual({ siblings: QUEUE, listPath: LIST.pathname }); + expect(readApprovalQueue(state, 'r9')).toBeUndefined(); + // Another list's rows (the same `from` shape, no mark) are not the queue. + expect(readApprovalQueue({ from: { pathname: LIST.pathname, siblings: QUEUE } }, 'r2')).toBeUndefined(); + expect(readApprovalQueue(null, 'r2')).toBeUndefined(); + }); + + it('the next request is the one after the decided one, else the one before, else none', () => { + expect(nextInQueue(QUEUE, 'r1')).toEqual({ next: 'r2', remaining: ['r2', 'r3'] }); + expect(nextInQueue(QUEUE, 'r3')).toEqual({ next: 'r2', remaining: ['r1', 'r2'] }); + expect(nextInQueue(['r1'], 'r1')).toEqual({ next: undefined, remaining: [] }); + }); + + it('a request is in the reader queue while pending and the server says the reader can act', () => { + expect(inReaderQueue(pending('r1'))).toBe(true); + expect(inReaderQueue({ id: 'r1', status: 'pending', viewer: { can_act: false } })).toBe(false); + expect(inReaderQueue({ id: 'r1', status: 'approved', viewer: { can_act: false } })).toBe(false); + expect(inReaderQueue({ id: 'r1', status: 'pending' })).toBe(true); + expect(inReaderQueue({ id: 'r1' })).toBeUndefined(); + }); +}); + +describe('the request page moves on after a decision (objectstack#34586)', () => { + it('approved: the page is replaced by the next request, the decided one dropped from the set', async () => { + const rows = { r1: pending('r1'), r2: pending('r2'), r3: pending('r3') }; + const { rerender } = render(); + expect(position()).toBe('1/3'); + expect(screen.getByTestId('approval-queue-open-next')).toBeInTheDocument(); + + rerender(); + await waitFor(() => expect(where()).toBe(pageOf('r2'))); + expect(screen.getByTestId('siblings').textContent).toBe(JSON.stringify(['r2', 'r3'])); + expect(position()).toBe('1/2'); + expect(screen.getByTestId('approval-queue-open-next')).toBeInTheDocument(); + }); + + it('a countersign approval that leaves the request pending for others still moves on', async () => { + const rows = { r1: pending('r1'), r2: pending('r2'), r3: pending('r3') }; + const { rerender } = render(); + rerender(); + await waitFor(() => expect(where()).toBe(pageOf('r2'))); + }); + + it('the last request of the queue goes back to the list and says it is done', async () => { + const rows = { r3: pending('r3') }; + const { rerender } = render(); + rerender(); + await waitFor(() => expect(where()).toBe(LIST.pathname)); + expect(toastStub.success).toHaveBeenCalledWith('No more pending requests in this list.'); + }); + + it('with the switch off the page stays, and the choice is kept for the next page', async () => { + const rows = { r1: pending('r1'), r2: pending('r2') }; + const { rerender, unmount } = render(); + const box = within(screen.getByTestId('approval-queue-open-next')).getByRole('checkbox'); + expect(box).toHaveAttribute('aria-checked', 'true'); + fireEvent.click(box); + expect(box).toHaveAttribute('aria-checked', 'false'); + + rerender(); + await new Promise((resolve) => setTimeout(resolve, 20)); + expect(where()).toBe(pageOf('r1')); + unmount(); + + render(); + expect(within(screen.getByTestId('approval-queue-open-next')).getByRole('checkbox')).toHaveAttribute('aria-checked', 'false'); + }); + + it('an action that leaves the request in the reader queue (more info asked) does not move', async () => { + const rows = { r1: pending('r1'), r2: pending('r2') }; + const { rerender } = render(); + rerender(); + await new Promise((resolve) => setTimeout(resolve, 20)); + expect(where()).toBe(pageOf('r1')); + }); + + it('a request first shown already decided does not move: only a change seen on this page does', async () => { + render(); + await new Promise((resolve) => setTimeout(resolve, 20)); + expect(where()).toBe(pageOf('r1')); + }); + + it('opened without the queue (a notification, a direct link): no switch, no counter, no move', async () => { + const rows = { r1: pending('r1') }; + const { rerender } = render(); + expect(screen.queryByTestId('approval-queue-open-next')).toBeNull(); + expect(position()).toBe('none'); + rerender(); + await new Promise((resolve) => setTimeout(resolve, 20)); + expect(where()).toBe(pageOf('r1')); + }); +}); From 56a03533041af5284461750edb7e8c23540b9048 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:10:46 +0000 Subject: [PATCH 3/7] test(app-shell): pin that turning open-next back on after a decision moves nothing Claude-Session: https://claude.ai/code/session_01WGufzgwLxpT1AVJJAwAvyR Co-authored-by: Claude --- .../approval-decision/approvalQueueAdvance-34586.test.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance-34586.test.tsx b/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance-34586.test.tsx index 709992bc9d4..85db62987c0 100644 --- a/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance-34586.test.tsx +++ b/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance-34586.test.tsx @@ -143,6 +143,11 @@ describe('the request page moves on after a decision (objectstack#34586)', () => rerender(); await new Promise((resolve) => setTimeout(resolve, 20)); expect(where()).toBe(pageOf('r1')); + // Turning it back on later moves nothing: the decision was seen while it was off. + fireEvent.click(box); + expect(box).toHaveAttribute('aria-checked', 'true'); + await new Promise((resolve) => setTimeout(resolve, 20)); + expect(where()).toBe(pageOf('r1')); unmount(); render(); From 885cedbf6aee26141e2f52bb900a134adcf535bf Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:19:56 +0000 Subject: [PATCH 4/7] fix(i18n): regenerate zh-Hant from zh-Hans, and split the open-next switch pins Claude-Session: https://claude.ai/code/session_01WGufzgwLxpT1AVJJAwAvyR Co-authored-by: Claude --- .../approvalQueueAdvance-34586.test.tsx | 20 ++++++++++++++----- ui/packages/i18n/src/locales/zh-Hant.ts | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance-34586.test.tsx b/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance-34586.test.tsx index 85db62987c0..a8f2068c5f8 100644 --- a/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance-34586.test.tsx +++ b/ui/packages/app-shell/src/views/approval-decision/approvalQueueAdvance-34586.test.tsx @@ -143,17 +143,27 @@ describe('the request page moves on after a decision (objectstack#34586)', () => rerender(); await new Promise((resolve) => setTimeout(resolve, 20)); expect(where()).toBe(pageOf('r1')); - // Turning it back on later moves nothing: the decision was seen while it was off. - fireEvent.click(box); - expect(box).toHaveAttribute('aria-checked', 'true'); - await new Promise((resolve) => setTimeout(resolve, 20)); - expect(where()).toBe(pageOf('r1')); unmount(); render(); expect(within(screen.getByTestId('approval-queue-open-next')).getByRole('checkbox')).toHaveAttribute('aria-checked', 'false'); }); + it('turning the switch back on after a decision it was off for moves nothing', async () => { + const rows = { r1: pending('r1'), r2: pending('r2') }; + const { rerender } = render(); + const box = within(screen.getByTestId('approval-queue-open-next')).getByRole('checkbox'); + fireEvent.click(box); + rerender(); + await new Promise((resolve) => setTimeout(resolve, 20)); + expect(where()).toBe(pageOf('r1')); + + fireEvent.click(box); + expect(box).toHaveAttribute('aria-checked', 'true'); + await new Promise((resolve) => setTimeout(resolve, 20)); + expect(where()).toBe(pageOf('r1')); + }); + it('an action that leaves the request in the reader queue (more info asked) does not move', async () => { const rows = { r1: pending('r1'), r2: pending('r2') }; const { rerender } = render(); diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index b6c01783d38..0078723d748 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -4598,7 +4598,7 @@ const zhHant = { progressBar: '決策進度', declaredActions: '操作', decisionPanelOffRequestPage: '審批決策面板僅在審批請求頁面上可用。', - openNextAfterDecision: '處理後打開下一條', + openNextAfterDecision: '處理後開啟下一條', queueDone: '這個列表裡的待審請求已全部處理完。', snapshotAsSubmitted: '提交時的內容', attachmentChip: '附件', From 4288d50e637c4e98f21437689154a9c7ac41c9f2 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:24:21 +0000 Subject: [PATCH 5/7] chore(changeset): declare the locale-key widening on Clause-2 Claude-Session: https://claude.ai/code/session_01WGufzgwLxpT1AVJJAwAvyR Co-authored-by: Claude --- .changeset/34586-approvals-queue-open-next.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/34586-approvals-queue-open-next.md b/.changeset/34586-approvals-queue-open-next.md index 62b429f3fc0..2aa0f771eb7 100644 --- a/.changeset/34586-approvals-queue-open-next.md +++ b/.changeset/34586-approvals-queue-open-next.md @@ -5,7 +5,7 @@ feat(console): the approvals inbox's pending queue steps from request to request, and opens the next request after a decision -Clause-②: no +Clause-②: yes (widening) — two new `approvalsInbox` keys in the `@object-ui/i18n` locale packs (`openNextAfterDecision`, `queueDone`; `TranslationKeys` grows); nothing removed or renamed Metadata-protocol: none From the Approvals Inbox's "My pending" tab, a request now opens with the queue as the list shows it, filtered and sorted: From dbe3c2894ea2ae342bc21333bfea8e6b22844838 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:40:05 +0000 Subject: [PATCH 6/7] refactor(app-shell): hand the counter step only the location fields its memo depends on Claude-Session: https://claude.ai/code/session_01WGufzgwLxpT1AVJJAwAvyR Co-authored-by: Claude --- ui/packages/app-shell/src/views/recordDrawerStack.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ui/packages/app-shell/src/views/recordDrawerStack.tsx b/ui/packages/app-shell/src/views/recordDrawerStack.tsx index ac0ce9131f3..4001bba1e3a 100644 --- a/ui/packages/app-shell/src/views/recordDrawerStack.tsx +++ b/ui/packages/app-shell/src/views/recordDrawerStack.tsx @@ -804,7 +804,11 @@ export function useRecordPageReturn(recordId: string | undefined): RecordPageRet if (!recordId || !siblings || index < 0) return {}; // The `from` state goes along unchanged: the next page has the same list. const go = (nextId: string) => () => { - const step = siblingRecordStep(location, recordId, nextId); + const step = siblingRecordStep( + { pathname: location.pathname, search: location.search, state: location.state }, + recordId, + nextId, + ); if (step === null) return; navigate(step.to, { replace: true, state: step.state }); }; From 144cc8fac4ebd042fe20ebe6e2f2490fb62fcefa Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:14:51 +0000 Subject: [PATCH 7/7] =?UTF-8?q?docs(changeset):=20name=20the=20app-shell?= =?UTF-8?q?=20export=20in=20the=20Clause-=E2=91=A1=20line?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01WGufzgwLxpT1AVJJAwAvyR Co-authored-by: Claude --- .changeset/34586-approvals-queue-open-next.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/34586-approvals-queue-open-next.md b/.changeset/34586-approvals-queue-open-next.md index 2aa0f771eb7..9383181a91c 100644 --- a/.changeset/34586-approvals-queue-open-next.md +++ b/.changeset/34586-approvals-queue-open-next.md @@ -5,7 +5,7 @@ feat(console): the approvals inbox's pending queue steps from request to request, and opens the next request after a decision -Clause-②: yes (widening) — two new `approvalsInbox` keys in the `@object-ui/i18n` locale packs (`openNextAfterDecision`, `queueDone`; `TranslationKeys` grows); nothing removed or renamed +Clause-②: yes (widening) — one new export, `approvalQueueState`, from `@object-ui/app-shell` (workspace-private: `"private": true`, not published; the console is its one consumer), and two new `approvalsInbox` keys in the `@object-ui/i18n` locale packs (`openNextAfterDecision`, `queueDone`; `TranslationKeys` grows); nothing removed or renamed Metadata-protocol: none From the Approvals Inbox's "My pending" tab, a request now opens with the queue as the list shows it, filtered and sorted: