From 9fdc30a2d3e9db60fdbd32c6bd6c9f3a1bcf8b3b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:29:53 +0000 Subject: [PATCH 1/2] feat(app-shell): fold the approver's decision band on a record under approval Ruling A: the decisions stay buttons, every other lever goes behind one menu, and a status line names the task, the step and the submitter. Both call sites (record page, request page) draw the same band. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01WGufzg2evNa1V3zxrQq3KX --- .../src/utils/approvalDecisionFold.ts | 74 +++++++ .../src/views/DeclaredActionsBar.tsx | 207 +++++++++++++++++- .../app-shell/src/views/RecordDetailView.tsx | 9 +- .../ApprovalDecisionPanel.tsx | 3 + ui/packages/i18n/src/locales/ar.ts | 4 + ui/packages/i18n/src/locales/de.ts | 4 + ui/packages/i18n/src/locales/en.ts | 7 + ui/packages/i18n/src/locales/es.ts | 4 + ui/packages/i18n/src/locales/fr.ts | 4 + ui/packages/i18n/src/locales/ja.ts | 4 + ui/packages/i18n/src/locales/ko.ts | 4 + ui/packages/i18n/src/locales/pt-BR.ts | 4 + ui/packages/i18n/src/locales/ru.ts | 4 + ui/packages/i18n/src/locales/zh-Hans.ts | 4 + ui/packages/i18n/src/locales/zh-Hant.ts | 4 + 15 files changed, 333 insertions(+), 7 deletions(-) create mode 100644 ui/packages/app-shell/src/utils/approvalDecisionFold.ts diff --git a/ui/packages/app-shell/src/utils/approvalDecisionFold.ts b/ui/packages/app-shell/src/utils/approvalDecisionFold.ts new file mode 100644 index 00000000000..99b38f5e8ec --- /dev/null +++ b/ui/packages/app-shell/src/utils/approvalDecisionFold.ts @@ -0,0 +1,74 @@ +/** + * 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. + */ + +/** + * approvalDecisionFold — which of a pending request's declared actions the + * APPROVER's band draws as buttons, and which go behind its one menu + * (objectstack#34361, ruling A). + * + * The band keeps the step's two decisions in view and folds every other lever + * (reassign, send back, request info, reply, and the submitter's own levers + * for a viewer who is both). Which actions are "the decisions" is read off the + * metadata each action already declares — its `variant` — never off an + * action-name list, so an action shipped as metadata alone lands in the menu + * unless its author marks it `primary` or `danger`. That is the same principle + * the admin-override fold follows (`actionAdmittedByOverride` reads each + * action's own `visible` gate). + * + * Placement only: nothing here decides who may act. The server's `viewer` + * block and each action's own `visible` / `disabled` / capability gates stay + * the authority, unchanged. + */ + +/** The spec action `variant` values that keep an action out of the fold. */ +const LEAD_VARIANTS: ReadonlySet = new Set(['primary', 'danger']); + +/** + * Does this declared action stay a button on the approver's band? + * + * True for an action whose declared `variant` is `primary` or `danger` + * (today `approval_approve` and `approval_reject`); every other action, + * including one that declares no variant, belongs in the menu. + */ +export function isLeadDecision(action: unknown): boolean { + if (!action || typeof action !== 'object') return false; + const variant = (action as { variant?: unknown }).variant; + return typeof variant === 'string' && LEAD_VARIANTS.has(variant); +} + +/** + * May this viewer act on the request as one of its approvers? + * + * Reads the server's `viewer.can_act` and nothing else, strictly: a backend + * that sent no `viewer` block, or one without `can_act`, cannot tell, and + * "cannot tell" keeps today's unfolded bar. The override-only administrator + * (`can_act: false`) and the submitter who holds no slot both read `false`. + */ +export function isActingApprover(record: unknown): boolean { + if (!record || typeof record !== 'object') return false; + const viewer = (record as { viewer?: unknown }).viewer; + if (!viewer || typeof viewer !== 'object') return false; + return (viewer as { can_act?: unknown }).can_act === true; +} + +/** + * The 1-based number of the request's current step on its served route + * (`flow_route.steps`, the list every step line draws), or `undefined` when + * the route is absent or names no current step. + */ +export function currentStepNumber(record: unknown): number | undefined { + if (!record || typeof record !== 'object') return undefined; + const route = (record as { flow_route?: unknown }).flow_route; + if (!route || typeof route !== 'object') return undefined; + const steps = (route as { steps?: unknown }).steps; + if (!Array.isArray(steps)) return undefined; + const index = steps.findIndex( + (step) => !!step && typeof step === 'object' && (step as { state?: unknown }).state === 'current', + ); + return index >= 0 ? index + 1 : undefined; +} diff --git a/ui/packages/app-shell/src/views/DeclaredActionsBar.tsx b/ui/packages/app-shell/src/views/DeclaredActionsBar.tsx index 1fac4fe090b..5414bddc5c9 100644 --- a/ui/packages/app-shell/src/views/DeclaredActionsBar.tsx +++ b/ui/packages/app-shell/src/views/DeclaredActionsBar.tsx @@ -85,6 +85,7 @@ import { isOverrideDecision, isOverrideOnlyViewer, } from '../utils/approvalOverride.js'; +import { currentStepNumber, isActingApprover, isLeadDecision } from '../utils/approvalDecisionFold.js'; import { approverCopyFrom, approverDisplay, @@ -147,6 +148,22 @@ export interface DeclaredActionsBarProps { * server sent no `viewer` block for render exactly as without it. */ foldOverrides?: boolean; + /** + * Fold the approver's own band (objectstack#34361, ruling A): for a viewer + * the server says can act (`viewer.can_act === true`) and more than two + * shown actions, one status line naming the task, the step and the + * submitter, the decisions as the only buttons, and every other lever + * behind one neutral menu. + * + * "The decisions" are the actions whose declared `variant` is `primary` or + * `danger` (`isLeadDecision`), not a name list, so an action shipped as + * metadata alone lands in the menu. Placement only, like `foldOverrides`: + * every folded lever keeps its own gates and dialog, and the request it + * sends is unchanged. A viewer who cannot act (the submitter alone, the + * override-only administrator, a backend that sent no `viewer` block) + * renders exactly as without it. + */ + foldDecisions?: boolean; /** * Told which declared actions the bar DRAWS for this viewer, by name, each * time that set changes, and an empty list when the bar goes away @@ -254,6 +271,11 @@ function useReportDrawn( }, [name, drawn, onDrawn]); } +/** Own-key presence on a plain record, never the prototype chain. */ +function hasOwnKey(record: Readonly>, key: string): boolean { + return Object.prototype.hasOwnProperty.call(record, key); +} + /** * One declared-action button. Extracted so the `visible` CEL predicate can be * evaluated with a hook (rules-of-hooks) and so the dispatch can carry the @@ -273,7 +295,12 @@ const DeclaredActionButton: React.FC<{ asMenuItem?: boolean; /** The toolbar's drawn-set reporter (objectstack#25877). */ onDrawn?: (name: string, drawn: boolean) => void; -}> = ({ action, objectName, record, asMenuItem = false, onDrawn }) => { + /** + * Share the row's width below `sm` (objectstack#34361): the approver band's + * decisions sit side by side at equal width on a phone. + */ + fill?: boolean; +}> = ({ action, objectName, record, asMenuItem = false, onDrawn, fill = false }) => { const { execute } = useAction(); const [loading, setLoading] = useState(false); // Localize the SERVER-DECLARED strings through the `_actions..*` @@ -685,6 +712,7 @@ const DeclaredActionButton: React.FC<{ // Below `sm` a 44 px touch target (objectstack#29071). className={cn( 'h-11 sm:h-9', + fill && (disabledReason ? 'w-full sm:w-auto' : 'flex-1 sm:flex-none'), isOverride && 'border-amber-500/60 text-amber-700 hover:bg-amber-50 hover:text-amber-800 dark:text-amber-400 dark:hover:bg-amber-500/10 dark:hover:text-amber-300', pressed !== undefined && 'aria-pressed:bg-accent aria-pressed:text-accent-foreground hover:aria-pressed:bg-accent', @@ -728,7 +756,10 @@ const DeclaredActionButton: React.FC<{ tabIndex={0} aria-describedby={reasonId} data-disabled-reason="" - className="inline-flex rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2" + className={cn( + 'inline-flex rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2', + fill && 'flex-1 sm:flex-none', + )} > {button} {disabledReason} @@ -749,8 +780,67 @@ const DeclaredActionButton: React.FC<{ * each folded lever shows (`bypassedApproverNames` over the shared approver * directory), so the line and the dialog never name different people. An * unstaffed step has no one to name, and then the line says pending alone. + * + * `forApprover` is the approver band's line (objectstack#34361): the task is + * theirs, so it names the task, the step (its number on the served route and + * its label) and who submitted, instead of who the step waits on. */ -const ApprovalWaitingStatus: React.FC<{ record: any }> = ({ record }) => { +const ApprovalWaitingStatus: React.FC<{ record: any; forApprover?: boolean }> = ({ record, forApprover = false }) => { + if (forApprover) return ; + return ; +}; + +/** + * The approver band's status line: 「待你审批 · 第 N 步 · STEP · 提交人 NAME」. + * Every part but the first is drawn only when the served row carries it: the + * step number off `flow_route` (`currentStepNumber`), the step's label off + * `step_label`, and the submitter as "you" when the server's `viewer` block + * says so, else by the name the server resolved. + */ +const ApproverTaskStatus: React.FC<{ record: any }> = ({ record }) => { + const { t } = useObjectTranslation(); + const row = record != null && typeof record === 'object' ? (record as Record) : {}; + const stepNumber = currentStepNumber(row); + const stepLabel = typeof row.step_label === 'string' ? row.step_label.trim() : ''; + const submitterName = typeof row.submitter_name === 'string' ? row.submitter_name.trim() : ''; + const submittedByViewer = row.viewer?.is_submitter === true; + const parts: Array<{ key: string; text: string }> = []; + if (stepNumber !== undefined) { + parts.push({ + key: 'step', + text: String(t('approvalsInbox.stepNumber', { defaultValue: 'Step {{n}}', n: stepNumber })), + }); + } + if (stepLabel) parts.push({ key: 'label', text: stepLabel }); + if (submittedByViewer) { + parts.push({ key: 'submitter', text: String(t('approvalsInbox.submittedByYou', { defaultValue: 'You submitted this' })) }); + } else if (submitterName) { + parts.push({ + key: 'submitter', + text: String(t('approvalsInbox.submittedByName', { defaultValue: 'Submitted by {{name}}', name: submitterName })), + }); + } + return ( +
+ + {String(t('approvalsInbox.awaitingYourDecision', { defaultValue: 'Awaiting your approval' }))} + + {parts.map((part) => ( + + + {part.text} + + ))} +
+ ); +}; + +/** The override-only viewer's line (objectstack#25877): pending, and who the step waits on. */ +const OverrideWaitingStatus: React.FC<{ record: any }> = ({ record }) => { const { t } = useObjectTranslation(); const refs = useMemo(() => unresolvedApproverRefs(record), [record]); const directory = useApproverDirectory(refs); @@ -854,12 +944,12 @@ const DeclaredActionVisibilityProbe: React.FC<{ const DeclaredActionsToolbar: React.FC< Pick< DeclaredActionsBarProps, - 'objectName' | 'record' | 'className' | 'label' | 'foldOverrides' | 'onDrawnActionsChange' + 'objectName' | 'record' | 'className' | 'label' | 'foldOverrides' | 'foldDecisions' | 'onDrawnActionsChange' > & { /** The located set, pre-filtered by `location` / `exclude`, ungated. */ actions: ActionDef[]; } -> = ({ actions, objectName, record, className, label, foldOverrides, onDrawnActionsChange }) => { +> = ({ actions, objectName, record, className, label, foldOverrides, foldDecisions, onDrawnActionsChange }) => { const { t } = useObjectTranslation(); const mayInvoke = useCapabilityGate(); const permitted = useMemo( @@ -883,8 +973,10 @@ const DeclaredActionsToolbar: React.FC< // the set is read against `permitted`, so a lever the capability gate // removed never counts however it last reported. const [drawnByName, setDrawnByName] = useState>>({}); + // A `false` verdict is recorded too, so "every lever has reported" can be + // read off the keys (the approver fold below waits on it). const reportDrawn = useCallback((name: string, isDrawn: boolean) => { - setDrawnByName((prev) => ((prev[name] ?? false) === isDrawn ? prev : { ...prev, [name]: isDrawn })); + setDrawnByName((prev) => (hasOwnKey(prev, name) && prev[name] === isDrawn ? prev : { ...prev, [name]: isDrawn })); }, []); const drawnNames = permitted .map((action) => action.name) @@ -899,10 +991,111 @@ const DeclaredActionsToolbar: React.FC< React.useEffect(() => () => onDrawnRef.current?.([]), []); const foldedDrawn = folded.some((action) => !!action.name && drawnByName[action.name] === true); + // objectstack#34361 (ruling A) — the approver's band. For a viewer the + // server says can act, the decisions (`isLeadDecision`: a `primary` or + // `danger` variant) stay buttons and every other permitted lever folds into + // one menu, once more than two levers are shown. Until every lever has + // reported its `visible` verdict the count is unknown and the band folds, + // so the common case never paints a flat row first. Disjoint from the + // override fold by construction: that viewer's `can_act` is `false`. + const decisionLeads = foldDecisions && folded.length === 0 && isActingApprover(record) + ? permitted.filter((action) => isLeadDecision(action)) + : []; + const decisionBand = decisionLeads.length > 0; + const decisionOthers = decisionBand ? permitted.filter((action) => !decisionLeads.includes(action)) : []; + const everyLeverReported = permitted.every((action) => !action.name || hasOwnKey(drawnByName, action.name)); + const foldDecisionOthers = decisionOthers.length > 0 && (!everyLeverReported || drawnNames.length > 2); + const decisionOthersDrawn = decisionOthers.some((action) => !!action.name && drawnByName[action.name] === true); + // Nothing this viewer may invoke renders nothing — no toolbar chrome, no // orphan divider, same degrade as "nothing declared at this location". if (permitted.length === 0) return null; + if (decisionBand) { + const moreLabel = String(t('approvalsInbox.moreDecisionActions', { defaultValue: 'More approval actions' })); + return ( +
+ {label && ( + <> + +
{label}
+ + )} + {/* Phone: the status line on top, then one row — the decisions at + equal width and the menu at its end. From `sm` up: one row, the + line at the start and the levers at the end. */} +
+ +
+ {decisionLeads.map((action) => ( + + ))} + {decisionOthers.map((action) => (foldDecisionOthers ? ( + + ) : ( + + )))} + {/* As in the override fold: the trigger appears once a folded + lever is actually shown, so no empty menu is left behind. A + neutral control — the amber shield marks the exception path + only. */} + {foldDecisionOthers && decisionOthersDrawn && ( + + + + + + {decisionOthers.map((action) => ( + + ))} + + + )} +
+
+
+ ); + } + if (folded.length > 0) { const inline = permitted.filter((action) => !folded.includes(action)); const overrideMenuLabel = String(t('approvalsInbox.viaOverrideChip', { defaultValue: 'Admin override' })); @@ -1011,6 +1204,7 @@ export function DeclaredActionsBar({ className, label, foldOverrides, + foldDecisions, onDrawnActionsChange, }: DeclaredActionsBarProps) { const dataSource = useAdapter(); @@ -1067,6 +1261,7 @@ export function DeclaredActionsBar({ className={className} label={label} foldOverrides={foldOverrides} + foldDecisions={foldDecisions} onDrawnActionsChange={onDrawnActionsChange} /> {runtime.dialogs} diff --git a/ui/packages/app-shell/src/views/RecordDetailView.tsx b/ui/packages/app-shell/src/views/RecordDetailView.tsx index a9e43cb9454..10ca7ea7e37 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.tsx @@ -5451,7 +5451,13 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri marked menu; the approver's own bar is unchanged. While the bar draws the request's Recall, it is the page's one Recall: `onDrawnActionsChange` is how the page learns that and tells - the DetailView band below to keep its lock badge only. */} + the DetailView band below to keep its lock badge only. + + objectstack#34361 (ruling A) — for the approver themselves, + `foldDecisions` draws one band: a status line naming the + task, the step and the submitter, the decisions as the only + buttons, and every other lever in one menu. The request page + (`ApprovalDecisionPanel`) draws the same band. */} {approvalBarMounted && ( )} diff --git a/ui/packages/app-shell/src/views/approval-decision/ApprovalDecisionPanel.tsx b/ui/packages/app-shell/src/views/approval-decision/ApprovalDecisionPanel.tsx index c4c16a2d185..01ed5573df3 100644 --- a/ui/packages/app-shell/src/views/approval-decision/ApprovalDecisionPanel.tsx +++ b/ui/packages/app-shell/src/views/approval-decision/ApprovalDecisionPanel.tsx @@ -374,11 +374,14 @@ export function ApprovalDecisionPanel({ request, className }: ApprovalDecisionPa {progress && } + {/* The approver's band, the same one the business record page draws + (objectstack#34361). */} ); diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index 25c3804a5b1..8c9f4a1f12e 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -4753,6 +4753,10 @@ const ar = { approveOneBody: 'ستتم الموافقة على الطلب بهويتك. لإضافة تعليق أو مرفق، افتح الطلب.', flowOrigin: 'بدأها التدفق', submittedByYou: 'مقدَّم منك', + awaitingYourDecision: 'بانتظار موافقتك', + stepNumber: 'الخطوة {{n}}', + submittedByName: 'مقدَّم من {{name}}', + moreDecisionActions: 'إجراءات موافقة أخرى', sortBy: 'ترتيب', sortRecent: 'الأحدث أولاً', sortOldest: 'الأقدم أولاً', diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index 91f9d77be0c..b5d6ff0f150 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -4356,6 +4356,10 @@ const de = { approveOneBody: 'Die Anfrage wird mit Ihrer Identität genehmigt. Um einen Kommentar oder Anhang hinzuzufügen, öffnen Sie die Anfrage.', flowOrigin: 'Vom Flow gestartet', submittedByYou: 'Von Ihnen eingereicht', + awaitingYourDecision: 'Wartet auf Ihre Genehmigung', + stepNumber: 'Schritt {{n}}', + submittedByName: 'Eingereicht von {{name}}', + moreDecisionActions: 'Weitere Genehmigungsaktionen', sortBy: 'Sortieren', sortRecent: 'Neueste zuerst', sortOldest: 'Älteste zuerst', diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index 399f5a34f49..f60de714e44 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -5292,6 +5292,13 @@ const en = { approveOneBody: 'This approves the request with your identity. To add a comment or attachment, open the request instead.', flowOrigin: 'Flow-initiated', submittedByYou: 'You submitted this', + // The approver band's status line and menu on a record under approval + // (objectstack#34361): the task, the step number on the served route, + // the submitter by name, and the menu holding every non-decision lever. + awaitingYourDecision: 'Awaiting your approval', + stepNumber: 'Step {{n}}', + submittedByName: 'Submitted by {{name}}', + moreDecisionActions: 'More approval actions', sortBy: 'Sort', sortRecent: 'Newest first', sortOldest: 'Oldest first', diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index 2c4e59cde03..bf97b48439d 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -4456,6 +4456,10 @@ const es = { approveOneBody: 'Esto aprueba la solicitud con tu identidad. Para añadir un comentario o un adjunto, abre la solicitud.', flowOrigin: 'Iniciada por flujo', submittedByYou: 'Enviado por ti', + awaitingYourDecision: 'Pendiente de tu aprobación', + stepNumber: 'Paso {{n}}', + submittedByName: 'Enviado por {{name}}', + moreDecisionActions: 'Más acciones de aprobación', sortBy: 'Ordenar', sortRecent: 'Más recientes primero', sortOldest: 'Más antiguas primero', diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index 195c11068ac..4333b140eb1 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -4452,6 +4452,10 @@ const fr = { approveOneBody: 'Cette action approuve la demande en votre nom. Pour ajouter un commentaire ou une pièce jointe, ouvrez la demande.', flowOrigin: 'Initiée par un flux', submittedByYou: 'Soumis par vous', + awaitingYourDecision: 'En attente de votre approbation', + stepNumber: 'Étape {{n}}', + submittedByName: 'Soumis par {{name}}', + moreDecisionActions: 'Autres actions d’approbation', sortBy: 'Trier', sortRecent: 'Plus récentes d’abord', sortOldest: 'Plus anciennes d’abord', diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index 3abb7feb40d..46cdcc9a961 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -4358,6 +4358,10 @@ const ja = { approveOneBody: 'あなたの名義でこのリクエストを承認します。コメントや添付を付ける場合は、リクエストを開いて操作してください。', flowOrigin: 'フロー起動', submittedByYou: 'あなたが提出', + awaitingYourDecision: 'あなたの承認待ち', + stepNumber: 'ステップ {{n}}', + submittedByName: '申請者 {{name}}', + moreDecisionActions: 'その他の承認操作', sortBy: '並び替え', sortRecent: '新しい順', sortOldest: '古い順', diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index f2d0bff50fe..10ece353f6e 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -4355,6 +4355,10 @@ const ko = { approveOneBody: '내 이름으로 이 요청을 승인합니다. 의견이나 첨부 파일을 추가하려면 요청을 열어 처리하세요.', flowOrigin: '플로우 시작', submittedByYou: '내가 제출함', + awaitingYourDecision: '내 승인 대기 중', + stepNumber: '{{n}}단계', + submittedByName: '제출자 {{name}}', + moreDecisionActions: '기타 승인 작업', sortBy: '정렬', sortRecent: '최신순', sortOldest: '오래된순', diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index b3f5e8e11e1..af00a1d2bb9 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -4451,6 +4451,10 @@ const pt = { approveOneBody: 'Isso aprova a solicitação com a sua identidade. Para adicionar um comentário ou anexo, abra a solicitação.', flowOrigin: 'Iniciada por fluxo', submittedByYou: 'Enviado por você', + awaitingYourDecision: 'Aguardando sua aprovação', + stepNumber: 'Etapa {{n}}', + submittedByName: 'Enviado por {{name}}', + moreDecisionActions: 'Mais ações de aprovação', sortBy: 'Ordenar', sortRecent: 'Mais recentes primeiro', sortOldest: 'Mais antigas primeiro', diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index 42eb479a1b6..c6ec2de9566 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -4565,6 +4565,10 @@ const ru = { approveOneBody: 'Запрос будет согласован от вашего имени. Чтобы добавить комментарий или вложение, откройте запрос.', flowOrigin: 'Инициировано потоком', submittedByYou: 'Отправлено вами', + awaitingYourDecision: 'Ожидает вашего согласования', + stepNumber: 'Шаг {{n}}', + submittedByName: 'Отправитель: {{name}}', + moreDecisionActions: 'Другие действия согласования', sortBy: 'Сортировка', sortRecent: 'Сначала новые', sortOldest: 'Сначала старые', diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index f618d296900..53e0dedfba9 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -4605,6 +4605,10 @@ const zh = { approveOneBody: '将以你的身份通过该请求。如需填写审批意见或附件,请打开该请求处理。', flowOrigin: '流程发起', submittedByYou: '由你提交', + awaitingYourDecision: '待你审批', + stepNumber: '第 {{n}} 步', + submittedByName: '提交人 {{name}}', + moreDecisionActions: '更多审批操作', sortBy: '排序', sortRecent: '最新优先', sortOldest: '最早优先', diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index 1a20cc8cc7b..0a61742f5b2 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -4605,6 +4605,10 @@ const zhHant = { approveOneBody: '將以你的身份通過該請求。如需填寫審批意見或附件,請開啟該請求處理。', flowOrigin: '流程發起', submittedByYou: '由你提交', + awaitingYourDecision: '待你審批', + stepNumber: '第 {{n}} 步', + submittedByName: '提交人 {{name}}', + moreDecisionActions: '更多審批操作', sortBy: '排序', sortRecent: '最新優先', sortOldest: '最早優先', From 01a894fecd0ff12f105c2f0e48df314bfa4ee6d0 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:45:19 +0000 Subject: [PATCH 2/2] test(app-shell): pin the approver band fold on both call sites, add changeset The record page's approver tests read the folded levers from the band's menu; new pins cover the approver, approver+submitter, submitter-only and override-only viewers, the variant-driven split and the request page. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01WGufzg2evNa1V3zxrQq3KX --- .changeset/34361-approver-band-fold.md | 21 + .../src/utils/approvalDecisionFold.test.ts | 66 ++++ ...etailView.approvalDeclaredActions.test.tsx | 25 +- ...aredActionsBar.approverFold-34361.test.tsx | 374 ++++++++++++++++++ 4 files changed, 485 insertions(+), 1 deletion(-) create mode 100644 .changeset/34361-approver-band-fold.md create mode 100644 ui/packages/app-shell/src/utils/approvalDecisionFold.test.ts create mode 100644 ui/packages/app-shell/src/views/__tests__/DeclaredActionsBar.approverFold-34361.test.tsx diff --git a/.changeset/34361-approver-band-fold.md b/.changeset/34361-approver-band-fold.md new file mode 100644 index 00000000000..34f775cea68 --- /dev/null +++ b/.changeset/34361-approver-band-fold.md @@ -0,0 +1,21 @@ +--- +'@object-ui/app-shell': patch +'@object-ui/i18n': patch +--- + +feat(app-shell): a record under approval shows the approver one folded band: a status line, the two decisions as buttons, and one menu for the rest + +Clause-②: yes (widening — new @object-ui/i18n en keys only; no metadata/schema accept set) +Metadata-protocol: none + +An approver who opens a record under approval used to see every declared decision action as its own button above the page body (Approve, Reject, Reassign, Send back, Request info, Reply, and Recall for an approver who also submitted), beside the record's own action row in the header. The band is now folded for any viewer the server says can act (`viewer.can_act === true`) once more than two of its actions are shown: + +- a status line names the task, the step's number on the served route and its label, and the submitter ("You submitted this" for an approver who also submitted); +- the actions whose declared `variant` is `primary` or `danger` (today Approve and Reject) stay buttons; on a phone they share one row at equal width; +- every other action, including one declared with no variant, goes into one neutral "More approval actions" menu. Reply stays in that menu, so it is reachable on every layout. + +The business record page and the approval request page draw the same band. Each folded action keeps its own `visible`, `disabled` and permission gates and its own dialog, and sends the same request. Menu actions still count as drawn for `onDrawnActionsChange`. The record's header actions do not move. + +Unchanged: the submitter who holds no slot, the override-only administrator (who keeps the existing admin-override fold), a backend that sends no `viewer` block, and any host that does not pass the new `foldDecisions` prop to `DeclaredActionsBar`. + +New `@object-ui/i18n` keys, in every pack: `approvalsInbox.awaitingYourDecision`, `approvalsInbox.stepNumber`, `approvalsInbox.submittedByName`, `approvalsInbox.moreDecisionActions`. diff --git a/ui/packages/app-shell/src/utils/approvalDecisionFold.test.ts b/ui/packages/app-shell/src/utils/approvalDecisionFold.test.ts new file mode 100644 index 00000000000..666468ee6e7 --- /dev/null +++ b/ui/packages/app-shell/src/utils/approvalDecisionFold.test.ts @@ -0,0 +1,66 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * approvalDecisionFold (objectstack#34361) — the three readings the approver + * band makes off metadata and the served request row. + */ + +import { describe, it, expect } from 'vitest'; +import { currentStepNumber, isActingApprover, isLeadDecision } from './approvalDecisionFold'; + +describe('isLeadDecision (objectstack#34361)', () => { + it('keeps a primary or danger action out of the fold', () => { + expect(isLeadDecision({ name: 'approval_approve', variant: 'primary' })).toBe(true); + expect(isLeadDecision({ name: 'approval_reject', variant: 'danger' })).toBe(true); + }); + + it('folds an action that declares no variant, or any other variant', () => { + expect(isLeadDecision({ name: 'approval_reassign' })).toBe(false); + expect(isLeadDecision({ name: 'approval_comment', variant: 'secondary' })).toBe(false); + expect(isLeadDecision({ name: 'x', variant: 'ghost' })).toBe(false); + expect(isLeadDecision(null)).toBe(false); + }); + + it('reads the variant, not the name', () => { + // A name the shipped set uses for a decision, without the variant, folds. + expect(isLeadDecision({ name: 'approval_approve' })).toBe(false); + // A metadata-only action an author marks primary stays a button. + expect(isLeadDecision({ name: 'approval_escalate', variant: 'primary' })).toBe(true); + }); +}); + +describe('isActingApprover (objectstack#34361)', () => { + it('is true only for an explicit can_act: true', () => { + expect(isActingApprover({ viewer: { can_act: true, is_submitter: true } })).toBe(true); + expect(isActingApprover({ viewer: { can_act: false, can_override: true } })).toBe(false); + expect(isActingApprover({ viewer: { can_act: false, is_submitter: true } })).toBe(false); + }); + + it('cannot tell without a viewer block, and reads that as no', () => { + expect(isActingApprover({})).toBe(false); + expect(isActingApprover({ viewer: {} })).toBe(false); + expect(isActingApprover({ viewer: { can_act: 'true' } })).toBe(false); + expect(isActingApprover(null)).toBe(false); + }); +}); + +describe('currentStepNumber (objectstack#34361)', () => { + it('numbers the current step on the served route from 1', () => { + const route = { + steps: [ + { id: 'a', label: 'Manager', state: 'done' }, + { id: 'b', label: 'Finance', state: 'current' }, + { id: 'c', label: 'CFO', state: 'upcoming' }, + ], + ahead: 'end', + }; + expect(currentStepNumber({ flow_route: route })).toBe(2); + }); + + it('says nothing when the route is absent or names no current step', () => { + expect(currentStepNumber({})).toBeUndefined(); + expect(currentStepNumber({ flow_route: { steps: [{ id: 'a', state: 'done' }] } })).toBeUndefined(); + expect(currentStepNumber({ flow_route: { steps: 'nope' } })).toBeUndefined(); + expect(currentStepNumber(undefined)).toBeUndefined(); + }); +}); diff --git a/ui/packages/app-shell/src/views/RecordDetailView.approvalDeclaredActions.test.tsx b/ui/packages/app-shell/src/views/RecordDetailView.approvalDeclaredActions.test.tsx index 49dacb7bd2e..cb7625f1c55 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.approvalDeclaredActions.test.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.approvalDeclaredActions.test.tsx @@ -361,6 +361,20 @@ function renderRecordPage() { const decisionButton = (name: string) => screen.queryByTestId(`declared-action-${name}`); +/** + * objectstack#34361 (ruling A) — the approver's band keeps the two decisions + * as buttons and folds every other lever into one menu, so those levers are + * read from the open menu. + */ +async function openDecisionMenu() { + const trigger = await screen.findByTestId('declared-actions-decision-menu'); + fireEvent.pointerDown(trigger, { button: 0, ctrlKey: false, pointerType: 'mouse' }); + return screen.findByRole('menu'); +} + +/** The approver's levers that the band folds behind its menu. */ +const APPROVER_FOLDED = ['approval_reassign', 'approval_send_back', 'approval_request_info']; + beforeEach(() => { cleanup(); authFetchSpy.mockClear(); @@ -377,16 +391,23 @@ describe('record page decision actions — a GROUP approver (objectui#3055)', () renderRecordPage(); await waitFor(() => expect(decisionButton('approval_approve')).toBeTruthy()); + expect(decisionButton('approval_approve')?.tagName).toBe('BUTTON'); + expect(decisionButton('approval_reject')?.tagName).toBe('BUTTON'); + await openDecisionMenu(); for (const name of APPROVER_DECISIONS) { expect(decisionButton(name), `${name} must be offered to a pending approver`).toBeTruthy(); } + for (const name of APPROVER_FOLDED) { + expect(decisionButton(name)?.getAttribute('role'), `${name} sits in the band's menu`).toBe('menuitem'); + } }); it('offers reassign / send back / request info — the three that had NO entry point', async () => { stubApprovalsApi(pendingRequest({ can_act: true, is_submitter: false, can_override: false })); renderRecordPage(); - await waitFor(() => expect(decisionButton('approval_reassign')).toBeTruthy()); + await openDecisionMenu(); + expect(decisionButton('approval_reassign')).toBeTruthy(); expect(decisionButton('approval_send_back')).toBeTruthy(); expect(decisionButton('approval_request_info')).toBeTruthy(); }); @@ -416,6 +437,7 @@ describe('record page decision actions — a GROUP approver (objectui#3055)', () it('dispatches the decision on the REQUEST, not on the business record it is opened on', async () => { stubApprovalsApi(pendingRequest({ can_act: true, is_submitter: false, can_override: false })); renderRecordPage(); + await openDecisionMenu(); await waitFor(() => expect(decisionButton('approval_send_back')).toBeTruthy()); authFetchSpy.mockClear(); @@ -437,6 +459,7 @@ describe('record page decision actions — a GROUP approver (objectui#3055)', () it('sends a declared decision output as its `outputs.` param, for the door to fold', async () => { stubApprovalsApi(pendingRequest({ can_act: true, is_submitter: false, can_override: false })); renderRecordPage(); + await openDecisionMenu(); await waitFor(() => expect(decisionButton('approval_send_back')).toBeTruthy()); authFetchSpy.mockClear(); diff --git a/ui/packages/app-shell/src/views/__tests__/DeclaredActionsBar.approverFold-34361.test.tsx b/ui/packages/app-shell/src/views/__tests__/DeclaredActionsBar.approverFold-34361.test.tsx new file mode 100644 index 00000000000..291d59bd921 --- /dev/null +++ b/ui/packages/app-shell/src/views/__tests__/DeclaredActionsBar.approverFold-34361.test.tsx @@ -0,0 +1,374 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * DeclaredActionsBar — `foldDecisions`, the approver's band (objectstack#34361, + * ruling A). + * + * The reported page: an approver who also submitted opened a customer record + * under approval and saw seven approval buttons above the title, plus the + * record's own row in the header — "two menus", with no way to tell which row + * is the task. + * + * What these pin: + * + * 1. a viewer who can act gets ONE status line (the task, the step, the + * submitter), the decisions (`primary` / `danger` variant) as the only + * buttons, and ONE neutral menu holding every other lever — reply and, + * for an approver who also submitted, recall included; + * 2. the split reads each action's declared `variant`, not a name list: an + * action declared without one lands in the menu; + * 3. a viewer who cannot act (the submitter alone, the override-only admin) + * and a host that does not ask for the fold render as before; + * 4. menu levers still count as drawn for `onDrawnActionsChange`; + * 5. the request page (`ApprovalDecisionPanel`) draws the same band. + * + * Nothing here is a permission assertion: every lever keeps its own gates, + * and the request it sends is unchanged. + */ + +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { render, screen, fireEvent, waitFor, within, cleanup } from '@testing-library/react'; +import React from 'react'; + +const executeSpy = vi.fn().mockResolvedValue({ success: true }); +const metadataItems = vi.hoisted(() => ({ byName: {} as Record })); + +// Only the dispatch and the metadata read are stubbed; the predicate entry +// stays real, as in the sibling DeclaredActionsBar suites. +vi.mock('@object-ui/react', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + ActionProvider: ({ children }: { children: React.ReactNode }) => <>{children}, + useAction: () => ({ execute: executeSpy }), + useMetadataItem: (_type: string, name?: string) => ({ + item: name ? metadataItems.byName[name] ?? null : null, + loading: false, + error: null, + }), + }; +}); + +vi.mock('../../hooks/useConsoleActionRuntime', () => ({ + useConsoleActionRuntime: () => ({ actionProviderProps: {}, dialogs: null }), +})); +vi.mock('../../providers/AdapterProvider', () => ({ useAdapter: () => ({}) })); +vi.mock('../../utils/getIcon', () => ({ + getIcon: (name: string) => () => , +})); + +// Interpolating `t` over `defaultValue`, so the status line reads as composed +// English. +vi.mock('@object-ui/i18n', async (importOriginal) => ({ + ...(await importOriginal>()), + useObjectLabel: () => ({ + actionLabel: (_o: unknown, _n: unknown, fallback: string) => fallback, + actionConfirm: (_o: unknown, _n: unknown, fallback?: string) => fallback, + actionSuccess: (_o: unknown, _n: unknown, fallback?: string) => fallback, + }), + useObjectTranslation: () => ({ + t: (key: string, options?: any) => + String(options?.defaultValue ?? key).replace( + /\{\{(\w+)\}\}/g, + (_m: string, name: string) => String(options?.[name] ?? ''), + ), + language: 'en', + }), + pickLocalized: (value: unknown) => (typeof value === 'string' ? value : ''), +})); + +import { AdapterCtx } from '@object-ui/react'; +import { DeclaredActionsBar } from '../DeclaredActionsBar'; +import { ApprovalDecisionPanel } from '../approval-decision/ApprovalDecisionPanel'; +import { resetApproverDirectoryCache } from '../../hooks/useApproverDirectory'; + +// Reduced gate spellings (the sibling fold suite's reasoning): the shipped +// predicates are pinned verbatim in `utils/approvalOverride.test.ts`. +const DECISION_VISIBLE = 'record.viewer.can_act || record.viewer.can_override'; +const APPROVER_ONLY_VISIBLE = 'record.viewer.can_act'; +const RECALL_VISIBLE = + '(record.status == "pending" || record.status == "returned") && record.viewer.is_submitter' + + ' || record.viewer.can_override'; +const REMIND_VISIBLE = 'record.status == "pending" && record.viewer.is_submitter'; +const REPLY_VISIBLE = 'record.viewer.can_act || record.status == "pending" && record.viewer.is_submitter'; + +const api = (verb: string) => ({ + type: 'api', + method: 'POST', + target: `/api/v1/approvals/requests/{id}/${verb}`, + params: [{ name: 'comment', label: 'Comment', type: 'textarea' }], + locations: ['record_section'], +}); + +/** The shipped set, in declaration order, with its declared variants. */ +const ACTIONS = [ + { name: 'approval_approve', label: 'Approve', variant: 'primary', visible: DECISION_VISIBLE, ...api('approve') }, + { name: 'approval_reject', label: 'Reject', variant: 'danger', visible: DECISION_VISIBLE, ...api('reject') }, + { name: 'approval_reassign', label: 'Reassign', visible: DECISION_VISIBLE, ...api('reassign') }, + { name: 'approval_send_back', label: 'Send back', visible: APPROVER_ONLY_VISIBLE, ...api('revise') }, + { name: 'approval_request_info', label: 'Request info', visible: APPROVER_ONLY_VISIBLE, ...api('request-info') }, + { name: 'approval_remind', label: 'Remind', visible: REMIND_VISIBLE, ...api('remind') }, + { name: 'approval_recall', label: 'Recall', visible: RECALL_VISIBLE, ...api('recall') }, + { name: 'approval_comment', label: 'Reply', visible: REPLY_VISIBLE, ...api('comment') }, +] as any[]; + +const LEADS = ['approval_approve', 'approval_reject']; +const APPROVER_MENU = ['approval_reassign', 'approval_send_back', 'approval_request_info', 'approval_comment']; + +const REQUEST = { + id: 'req_1', + status: 'pending', + object_name: 'account', + record_id: 'acc_1', + submitter_id: 'u_owner', + submitter_name: 'Account Owner', + step_label: 'Finance review', + pending_approvers: ['u_fin'], + pending_approver_names: { u_fin: 'Finance Lead' }, + flow_route: { + steps: [ + { id: 'mgr', label: 'Manager review', state: 'done' }, + { id: 'fin', label: 'Finance review', state: 'current' }, + { id: 'cfo', label: 'CFO review', state: 'upcoming' }, + ], + ahead: 'end', + }, +}; + +const APPROVER = { can_act: true, is_submitter: false, can_override: false }; +const APPROVER_SUBMITTER = { can_act: true, is_submitter: true, can_override: false }; +const SUBMITTER_ONLY = { can_act: false, is_submitter: true, can_override: false }; +const ADMIN_ONLY = { can_act: false, is_submitter: false, can_override: true }; + +function renderBar( + viewer: Record, + { + foldDecisions = true, + foldOverrides = true, + actions = ACTIONS, + onDrawnActionsChange, + exclude, + }: { + foldDecisions?: boolean; + foldOverrides?: boolean; + actions?: any[]; + onDrawnActionsChange?: (names: string[]) => void; + exclude?: string[]; + } = {}, +) { + return render( + + + , + ); +} + +function openDecisionMenu() { + const trigger = screen.getByTestId('declared-actions-decision-menu'); + fireEvent.pointerDown(trigger, { button: 0, ctrlKey: false, pointerType: 'mouse' }); + return screen.findByRole('menu'); +} + +const menuNames = (menu: HTMLElement) => + within(menu).getAllByRole('menuitem').map((item) => item.getAttribute('data-testid')?.replace('declared-action-', '')); + +/** The last set the bar reported. */ +function lastReport(spy: ReturnType): string[] { + return spy.mock.calls.at(-1)?.[0] ?? []; +} + +beforeEach(() => { + executeSpy.mockClear(); + resetApproverDirectoryCache(); + metadataItems.byName = {}; +}); + +describe('DeclaredActionsBar — foldDecisions, the approver band (objectstack#34361)', () => { + it('gives the approver a status line, the two decisions as buttons, and every other lever in one menu', async () => { + renderBar(APPROVER); + + await waitFor(() => expect(screen.getByTestId('declared-actions-decision-menu')).toBeInTheDocument()); + const status = screen.getByTestId('declared-actions-approval-status'); + expect(status.getAttribute('data-approval-status')).toBe('approver'); + expect(status.textContent).toContain('Awaiting your approval'); + expect(status.textContent).toContain('Step 2'); + expect(status.textContent).toContain('Finance review'); + expect(status.textContent).toContain('Submitted by Account Owner'); + + for (const name of LEADS) { + expect(screen.getByTestId(`declared-action-${name}`).tagName, `${name} stays a button`).toBe('BUTTON'); + } + for (const name of APPROVER_MENU) { + expect(screen.queryByTestId(`declared-action-${name}`), `${name} must not be a button`).toBeNull(); + } + + const trigger = screen.getByTestId('declared-actions-decision-menu'); + expect(trigger).toHaveAccessibleName('More approval actions'); + // Neutral: the amber shield marks the override path only. + expect(trigger.className).not.toContain('amber'); + + const menu = await openDecisionMenu(); + // Declaration order; reply is in the menu, so it is always reachable. + expect(menuNames(menu)).toEqual(APPROVER_MENU); + }); + + it('draws the decisions at equal width on a phone, with the menu at the row end', async () => { + renderBar(APPROVER); + await waitFor(() => expect(screen.getByTestId('declared-actions-decision-menu')).toBeInTheDocument()); + for (const name of LEADS) { + expect(screen.getByTestId(`declared-action-${name}`).className).toContain('flex-1'); + } + const trigger = screen.getByTestId('declared-actions-decision-menu'); + expect(trigger.className).toContain('shrink-0'); + const toolbar = screen.getByRole('toolbar'); + expect(toolbar.lastElementChild).toBe(trigger); + }); + + it('dispatches a menu lever exactly as its button would', async () => { + renderBar(APPROVER); + await waitFor(() => expect(screen.getByTestId('declared-actions-decision-menu')).toBeInTheDocument()); + const menu = await openDecisionMenu(); + fireEvent.click(within(menu).getByTestId('declared-action-approval_comment')); + await waitFor(() => expect(executeSpy).toHaveBeenCalledTimes(1)); + + const dispatch = executeSpy.mock.calls[0][0]; + expect(dispatch.name).toBe('approval_comment'); + expect(dispatch.target).toBe('/api/v1/approvals/requests/{id}/comment'); + expect(dispatch.params._rowRecord.id).toBe('req_1'); + expect(dispatch.overrideNotice).toBeUndefined(); + }); + + it('folds the submitter levers too for an approver who also submitted', async () => { + renderBar(APPROVER_SUBMITTER); + await waitFor(() => expect(screen.getByTestId('declared-actions-decision-menu')).toBeInTheDocument()); + const status = screen.getByTestId('declared-actions-approval-status'); + expect(status.textContent).toContain('You submitted this'); + expect(status.textContent).not.toContain('Submitted by Account Owner'); + for (const name of LEADS) { + expect(screen.getByTestId(`declared-action-${name}`).tagName).toBe('BUTTON'); + } + expect(screen.queryByTestId('declared-action-approval_recall')).toBeNull(); + + const menu = await openDecisionMenu(); + expect(menuNames(menu)).toEqual([ + 'approval_reassign', + 'approval_send_back', + 'approval_request_info', + 'approval_remind', + 'approval_recall', + 'approval_comment', + ]); + }); + + it('lands an action declared without a variant in the menu, not as a button', async () => { + const escalate = { name: 'approval_escalate', label: 'Escalate', visible: APPROVER_ONLY_VISIBLE, ...api('escalate') }; + renderBar(APPROVER, { actions: [...ACTIONS, escalate] }); + await waitFor(() => expect(screen.getByTestId('declared-actions-decision-menu')).toBeInTheDocument()); + expect(screen.queryByTestId('declared-action-approval_escalate')).toBeNull(); + const menu = await openDecisionMenu(); + expect(menuNames(menu)).toContain('approval_escalate'); + }); + + it("leaves the submitter-only viewer's bar unchanged", () => { + renderBar(SUBMITTER_ONLY); + expect(screen.queryByTestId('declared-actions-decision-menu')).toBeNull(); + expect(screen.queryByTestId('declared-actions-approval-status')).toBeNull(); + for (const name of ['approval_remind', 'approval_recall', 'approval_comment']) { + expect(screen.getByTestId(`declared-action-${name}`).tagName).toBe('BUTTON'); + } + for (const name of [...LEADS, 'approval_reassign']) { + expect(screen.queryByTestId(`declared-action-${name}`)).toBeNull(); + } + }); + + it('leaves the override-only admin on the override fold, unchanged', async () => { + renderBar(ADMIN_ONLY); + expect(screen.queryByTestId('declared-actions-decision-menu')).toBeNull(); + expect(screen.getByTestId('declared-actions-override-menu')).toBeInTheDocument(); + const status = screen.getByTestId('declared-actions-approval-status'); + expect(status.getAttribute('data-approval-status')).toBeNull(); + expect(status.textContent).toContain('Waiting on'); + expect(status.textContent).not.toContain('Awaiting your approval'); + }); + + it('leaves a host that does not ask for the fold unchanged', () => { + renderBar(APPROVER, { foldDecisions: false }); + expect(screen.queryByTestId('declared-actions-decision-menu')).toBeNull(); + expect(screen.queryByTestId('declared-actions-approval-status')).toBeNull(); + for (const name of [...LEADS, ...APPROVER_MENU]) { + expect(screen.getByTestId(`declared-action-${name}`).tagName).toBe('BUTTON'); + } + }); + + it('keeps the levers as buttons when no more than two are shown', async () => { + // Approve and Reply only: nothing worth a menu. + renderBar(APPROVER, { actions: [ACTIONS[0], ACTIONS[7]] }); + await waitFor(() => expect(screen.getByTestId('declared-action-approval_comment').tagName).toBe('BUTTON')); + expect(screen.getByTestId('declared-action-approval_approve').tagName).toBe('BUTTON'); + expect(screen.queryByTestId('declared-actions-decision-menu')).toBeNull(); + // Still the approver's band: the task is named. + expect(screen.getByTestId('declared-actions-approval-status').textContent).toContain('Awaiting your approval'); + }); + + it('reports the menu levers as drawn, never a hidden one, and an empty set on unmount', async () => { + const spy = vi.fn(); + const { unmount } = renderBar(APPROVER, { onDrawnActionsChange: spy }); + await waitFor(() => expect([...lastReport(spy)].sort()).toEqual([...LEADS, ...APPROVER_MENU].sort())); + // Recall and remind are the submitter's: not drawn for this approver. + expect(lastReport(spy)).not.toContain('approval_recall'); + + cleanup(); + spy.mockClear(); + renderBar(APPROVER_SUBMITTER, { onDrawnActionsChange: spy }); + await waitFor(() => expect(lastReport(spy)).toContain('approval_recall')); + unmount(); + }); + + it('reports an empty set when the band goes away', async () => { + const spy = vi.fn(); + const { unmount } = renderBar(APPROVER_SUBMITTER, { onDrawnActionsChange: spy }); + await waitFor(() => expect(lastReport(spy)).toContain('approval_recall')); + unmount(); + expect(lastReport(spy)).toEqual([]); + }); +}); + +describe('ApprovalDecisionPanel — the request page draws the same band (objectstack#34361)', () => { + it('folds the approver levers on the request page as on the record page', async () => { + metadataItems.byName = { sys_approval_request: { name: 'sys_approval_request', actions: ACTIONS } }; + render( + + + , + ); + + const panel = screen.getByTestId('approval-decision-panel'); + await waitFor(() => expect(within(panel).getByTestId('declared-actions-decision-menu')).toBeInTheDocument()); + expect(within(panel).getByTestId('declared-actions-approval-status').textContent).toContain('Awaiting your approval'); + for (const name of LEADS) { + expect(within(panel).getByTestId(`declared-action-${name}`).tagName).toBe('BUTTON'); + } + // The request page excludes nothing, so remind sits in the menu with the rest. + for (const name of ['approval_reassign', 'approval_remind', 'approval_recall', 'approval_comment']) { + expect(within(panel).queryByTestId(`declared-action-${name}`)).toBeNull(); + } + const menu = await openDecisionMenu(); + expect(menuNames(menu)).toEqual([ + 'approval_reassign', + 'approval_send_back', + 'approval_request_info', + 'approval_remind', + 'approval_recall', + 'approval_comment', + ]); + }); +});