Skip to content

Commit 3d25eec

Browse files
committed
fix(app-shell,react,plugin-detail): fold the admin override levers into one menu and draw Recall once
For a viewer who holds no approver slot but may override, the record page's approval bar becomes one status line (pending, waiting on whom), the levers without an override arm as buttons, and one marked menu with every lever the override flag admits. The approver's bar is unchanged. The record page now tells the DetailView approval band that it draws the declared Recall itself (new optional InlineEditContext member approvalRecallDrawnByHost), and the band keeps its lock badge only. Claude-Session: https://claude.ai/code/session_014N3u93mMkVGhq6DBKXqx4J Co-authored-by: Claude <noreply@anthropic.com>
1 parent a4eae06 commit 3d25eec

9 files changed

Lines changed: 676 additions & 13 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/react': patch
4+
'@object-ui/plugin-detail': patch
5+
---
6+
7+
fix(app-shell,react,plugin-detail): on a record under approval, an administrator who is not the approver sees one status line and one override menu instead of five buttons above the title, and Recall is drawn once
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
- **`@object-ui/app-shell`:** for a viewer who holds no approver slot but may override, the record page's approval bar is now one line: the request's pending status and who the step waits on, the levers that have no override arm (Reply) as buttons, and one marked menu holding every lever the override flag admits (Override Approve, Override Reject, Override Reassign, and Recall). The approver's own bar is unchanged. Who may override, the override notice each lever shows, and the request each lever sends are unchanged. `DeclaredActionsBar` takes a new optional `foldOverrides` prop for this; a host that does not pass it renders as before.
13+
- **`@object-ui/react`:** `InlineEditProvider` and the `InlineEditContext` value gain an optional `approvalRecallDrawnByHost`. It is optional so every existing host keeps its behaviour: absent means `false`, and then the approval band draws its own Recall exactly as before. A host that draws the pending request's declared Recall itself sets it to `true`.
14+
- **`@object-ui/plugin-detail`:** the DetailView approval band leaves out its Recall button when the host says it draws one, and keeps its lock badge and tally. The record page sets the signal whenever it shows the approval bar, so Recall appears once on the page.
15+
16+
What to do: nothing.

‎ui/packages/app-shell/src/views/DeclaredActionsBar.tsx‎

Lines changed: 204 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232

3333
import React, { useCallback, useMemo, useState } from 'react';
3434
import {
35+
Badge,
3536
Button,
37+
DropdownMenu,
38+
DropdownMenuContent,
39+
DropdownMenuItem,
40+
DropdownMenuTrigger,
3641
Separator,
3742
cn,
3843
hasDeclaredVisibilityGate,
@@ -54,7 +59,7 @@ import {
5459
import type { ActionDef } from '@object-ui/core';
5560
import type { ConsoleActionDispatch } from '../consoleActionDispatch.js';
5661
import { useObjectTranslation } from '@object-ui/i18n';
57-
import { Loader2, ShieldAlert } from 'lucide-react';
62+
import { Loader2, MoreHorizontal, ShieldAlert } from 'lucide-react';
5863
import { useConsoleActionRuntime } from '../hooks/useConsoleActionRuntime.js';
5964
import { useAdapter } from '../providers/AdapterProvider.js';
6065
// Straight from `@object-ui/react`, NOT through `../providers/MetadataProvider`
@@ -74,7 +79,12 @@ import {
7479
readDecisionOutputRegistry,
7580
} from '../utils/decisionOutputParams.js';
7681
import { getIcon } from '../utils/getIcon.js';
77-
import { isOverrideDecision, bypassedApproverNames } from '../utils/approvalOverride.js';
82+
import {
83+
actionAdmittedByOverride,
84+
bypassedApproverNames,
85+
isOverrideDecision,
86+
isOverrideOnlyViewer,
87+
} from '../utils/approvalOverride.js';
7888
import {
7989
approverCopyFrom,
8090
approverDisplay,
@@ -117,6 +127,26 @@ export interface DeclaredActionsBarProps {
117127
* returns null when empty), so the host never gets an orphan divider.
118128
*/
119129
label?: string;
130+
/**
131+
* Fold the admin-override levers into one menu for a viewer who holds no
132+
* approver slot but may override (objectstack#25877).
133+
*
134+
* For that viewer every lever the override flag admits — approve, reject,
135+
* reassign, and recall, whose gate ORs the flag in too — is the exception
136+
* path, and a row of them drawn as buttons is the most prominent thing on
137+
* the page. With this set, such a viewer sees one status line instead
138+
* (pending, and who the step waits on), the levers the override flag does
139+
* NOT admit (reply) as buttons, and the folded ones behind a single marked
140+
* menu. The set is read off each action's own `visible` gate
141+
* (`actionAdmittedByOverride`), not off a name list, so a lever shipped as
142+
* metadata alone folds the same way.
143+
*
144+
* Placement only: every folded lever keeps its own `visible` / `disabled` /
145+
* capability gates, its override framing and its dialog, and the request it
146+
* sends is unchanged. A viewer who CAN act (the approver) and any viewer the
147+
* server sent no `viewer` block for render exactly as without it.
148+
*/
149+
foldOverrides?: boolean;
120150
}
121151

122152
/**
@@ -148,7 +178,13 @@ const DeclaredActionButton: React.FC<{
148178
action: ActionDef;
149179
objectName: string;
150180
record: any;
151-
}> = ({ action, objectName, record }) => {
181+
/**
182+
* Draw the lever as an item of the override menu instead of a button
183+
* (objectstack#25877). Every gate, label and dispatch above the render is
184+
* shared, so the two forms cannot disagree about what the lever does.
185+
*/
186+
asMenuItem?: boolean;
187+
}> = ({ action, objectName, record, asMenuItem = false }) => {
152188
const { execute } = useAction();
153189
const [loading, setLoading] = useState(false);
154190
// Localize the SERVER-DECLARED strings through the `_actions.<name>.*`
@@ -227,6 +263,7 @@ const DeclaredActionButton: React.FC<{
227263
const isDisabledPred = useCondition(toPredicateInput(action.disabled), predicateRecord);
228264
// Called up here with the other hooks: the `visible` gate below returns early.
229265
const reasonId = React.useId();
266+
const labelId = React.useId();
230267

231268
/**
232269
* Is the button this viewer is looking at an ADMIN OVERRIDE (objectui#5178)?
@@ -513,6 +550,48 @@ const DeclaredActionButton: React.FC<{
513550
? String(t('actions.notAvailableForRecord', { defaultValue: 'Not available for this record' }))
514551
: undefined;
515552

553+
if (asMenuItem) {
554+
// The menu form of the same lever (objectstack#25877). Shaped like the
555+
// page header's overflow items (`PageHeaderActions`): `preventDefault` on
556+
// select keeps the menu mounted while the action's own dialog takes over,
557+
// and a disabled item states its reason as a visible second line, because
558+
// a tooltip inside a menu is unreachable from the keyboard (a disabled
559+
// item is skipped by arrow-key focus).
560+
return (
561+
<DropdownMenuItem
562+
disabled={disabledByPredicate || loading}
563+
aria-labelledby={disabledReason ? labelId : undefined}
564+
aria-describedby={disabledReason ? reasonId : undefined}
565+
onSelect={(event) => {
566+
event.preventDefault();
567+
void handleClick();
568+
}}
569+
className={cn(
570+
'gap-2',
571+
isOverride && 'text-amber-700 focus:text-amber-800 dark:text-amber-400 dark:focus:text-amber-300',
572+
)}
573+
data-testid={`declared-action-${action.name}`}
574+
data-override-decision={isOverride ? 'true' : undefined}
575+
>
576+
{loading
577+
? <Loader2 className="h-4 w-4 animate-spin" />
578+
: isOverride
579+
? <ShieldAlert className="h-4 w-4" />
580+
: iconName
581+
? React.createElement(getIcon(iconName), { className: 'h-4 w-4' })
582+
: null}
583+
{disabledReason ? (
584+
<span className="flex min-w-0 flex-col">
585+
<span id={labelId}>{label}</span>
586+
<span id={reasonId} className="text-xs text-muted-foreground">{disabledReason}</span>
587+
</span>
588+
) : (
589+
<span>{label}</span>
590+
)}
591+
</DropdownMenuItem>
592+
);
593+
}
594+
516595
const button = (
517596
<Button
518597
type="button"
@@ -578,6 +657,51 @@ const DeclaredActionButton: React.FC<{
578657
);
579658
};
580659

660+
/**
661+
* The status line that replaces the override levers for a viewer who holds no
662+
* approver slot (objectstack#25877): the request is pending, and who the step
663+
* waits on, by name.
664+
*
665+
* The names are the same slate, resolved the same way, as the override notice
666+
* each folded lever shows (`bypassedApproverNames` over the shared approver
667+
* directory), so the line and the dialog never name different people. An
668+
* unstaffed step has no one to name, and then the line says pending alone.
669+
*/
670+
const ApprovalWaitingStatus: React.FC<{ record: any }> = ({ record }) => {
671+
const { t } = useObjectTranslation();
672+
const refs = useMemo(() => unresolvedApproverRefs(record), [record]);
673+
const directory = useApproverDirectory(refs);
674+
const names = useMemo(() => {
675+
const copy = approverCopyFrom(t as unknown as Parameters<typeof approverCopyFrom>[0]);
676+
const shown = bypassedApproverNames(record, (id) => {
677+
const display = approverDisplay(id, { resolved: directory[id], copy });
678+
return display.detail ? `${display.label} · ${display.detail}` : display.label;
679+
});
680+
return Array.from(new Set(shown));
681+
}, [record, directory, t]);
682+
return (
683+
<div
684+
className="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-sm"
685+
data-testid="declared-actions-approval-status"
686+
>
687+
<Badge
688+
variant="outline"
689+
className="border-amber-300 bg-amber-50 text-amber-800 dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-300"
690+
>
691+
{String(t('approvalsInbox.statusPending', { defaultValue: 'Pending' }))}
692+
</Badge>
693+
{names.length > 0 && (
694+
<span className="min-w-0 text-muted-foreground">
695+
{String(t('approvalsInbox.waitingOn', { defaultValue: 'Waiting on' }))}{' '}
696+
<span className="text-foreground">
697+
{names.join(String(t('approvalsInbox.approverNameSeparator', { defaultValue: ', ' })))}
698+
</span>
699+
</span>
700+
)}
701+
</div>
702+
);
703+
};
704+
581705
/**
582706
* The located set, capability-gated — and the toolbar it draws.
583707
*
@@ -629,22 +753,95 @@ const DeclaredActionButton: React.FC<{
629753
* declared capability, and gets no new exposure either.
630754
*/
631755
const DeclaredActionsToolbar: React.FC<
632-
Pick<DeclaredActionsBarProps, 'objectName' | 'record' | 'className' | 'label'> & {
756+
Pick<DeclaredActionsBarProps, 'objectName' | 'record' | 'className' | 'label' | 'foldOverrides'> & {
633757
/** The located set, pre-filtered by `location` / `exclude`, ungated. */
634758
actions: ActionDef[];
635759
}
636-
> = ({ actions, objectName, record, className, label }) => {
760+
> = ({ actions, objectName, record, className, label, foldOverrides }) => {
637761
const { t } = useObjectTranslation();
638762
const mayInvoke = useCapabilityGate();
639763
const permitted = useMemo(
640764
() => actions.filter((action) => mayInvoke(action.requiredPermissions)),
641765
[actions, mayInvoke],
642766
);
767+
// objectstack#25877 — which of the permitted levers fold into the override
768+
// menu. Only for a viewer admitted through the override door alone
769+
// (`can_act: false`, `can_override: true`), and only the levers whose own
770+
// gate ORs that flag in; everything else stays a button. The split runs on
771+
// the capability-gated set, so a lever the gate removed is in neither half.
772+
const folded = useMemo(
773+
() => (foldOverrides && isOverrideOnlyViewer(record)
774+
? permitted.filter((action) => actionAdmittedByOverride(action))
775+
: []),
776+
[foldOverrides, record, permitted],
777+
);
643778

644779
// Nothing this viewer may invoke renders nothing — no toolbar chrome, no
645780
// orphan divider, same degrade as "nothing declared at this location".
646781
if (permitted.length === 0) return null;
647782

783+
if (folded.length > 0) {
784+
const inline = permitted.filter((action) => !folded.includes(action));
785+
const overrideMenuLabel = String(t('approvalsInbox.viaOverrideChip', { defaultValue: 'Admin override' }));
786+
return (
787+
<div className={cn('space-y-2', className)} data-approval-override-folded="">
788+
{label && (
789+
<>
790+
<Separator />
791+
<div className="text-xs font-medium text-muted-foreground">{label}</div>
792+
</>
793+
)}
794+
<div className="flex flex-row flex-wrap items-center gap-2">
795+
<ApprovalWaitingStatus record={record} />
796+
<div
797+
role="toolbar"
798+
aria-label={label || t('common.actions')}
799+
className="ml-auto flex flex-row flex-wrap items-center gap-2"
800+
>
801+
{inline.map((action) => (
802+
<DeclaredActionButton
803+
key={action.name}
804+
action={action}
805+
objectName={objectName}
806+
record={record}
807+
/>
808+
))}
809+
<DropdownMenu>
810+
<DropdownMenuTrigger asChild>
811+
{/* One marked control for the whole exception path: the
812+
override shield the folded levers wear, in the same amber,
813+
beside the overflow glyph. */}
814+
<Button
815+
type="button"
816+
variant="outline"
817+
size="sm"
818+
className="gap-1 px-2 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"
819+
aria-label={overrideMenuLabel}
820+
title={overrideMenuLabel}
821+
data-testid="declared-actions-override-menu"
822+
>
823+
<ShieldAlert className="h-4 w-4" />
824+
<MoreHorizontal className="h-4 w-4" />
825+
</Button>
826+
</DropdownMenuTrigger>
827+
<DropdownMenuContent align="end" className="min-w-48">
828+
{folded.map((action) => (
829+
<DeclaredActionButton
830+
key={action.name}
831+
action={action}
832+
objectName={objectName}
833+
record={record}
834+
asMenuItem
835+
/>
836+
))}
837+
</DropdownMenuContent>
838+
</DropdownMenu>
839+
</div>
840+
</div>
841+
</div>
842+
);
843+
}
844+
648845
return (
649846
<div className={cn('space-y-2', className)}>
650847
{label && (
@@ -676,6 +873,7 @@ export function DeclaredActionsBar({
676873
exclude,
677874
className,
678875
label,
876+
foldOverrides,
679877
}: DeclaredActionsBarProps) {
680878
const dataSource = useAdapter();
681879
// Fetch the object def (and its declared actions) unless the host passed
@@ -730,6 +928,7 @@ export function DeclaredActionsBar({
730928
record={record}
731929
className={className}
732930
label={label}
931+
foldOverrides={foldOverrides}
733932
/>
734933
{runtime.dialogs}
735934
</ActionProvider>

‎ui/packages/app-shell/src/views/RecordDetailView.approvalDeclaredActions.test.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,15 @@ describe('record page decision actions — gating is the SERVER\'s (objectui#305
471471
stubApprovalsApi(pendingRequest({ can_act: false, is_submitter: false, can_override: true }));
472472
renderRecordPage();
473473

474-
await waitFor(() => expect(decisionButton('approval_approve')).toBeTruthy());
475-
expect(decisionButton('approval_reject')).toBeTruthy();
476-
expect(decisionButton('approval_reassign')).toBeTruthy();
474+
// objectstack#25877 — for an admin who holds no slot the record page folds
475+
// the rescue levers into one marked menu, so they are read from there.
476+
const trigger = await screen.findByTestId('declared-actions-override-menu');
477+
expect(decisionButton('approval_approve'), 'folded, not a button').toBeNull();
478+
fireEvent.pointerDown(trigger, { button: 0, ctrlKey: false, pointerType: 'mouse' });
479+
await screen.findByRole('menu');
480+
expect(decisionButton('approval_approve')?.getAttribute('role')).toBe('menuitem');
481+
expect(decisionButton('approval_reject')?.getAttribute('role')).toBe('menuitem');
482+
expect(decisionButton('approval_reassign')?.getAttribute('role')).toBe('menuitem');
477483
expect(decisionButton('approval_send_back')).toBeNull();
478484
expect(decisionButton('approval_request_info')).toBeNull();
479485
});

‎ui/packages/app-shell/src/views/RecordDetailView.approvalRecallGate.test.tsx‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ vi.mock('@object-ui/react', async (importOriginal) => {
9191
data-testid="inline-probe"
9292
data-approval-is-submitter={String(inline?.approvalIsSubmitter)}
9393
data-approval-pending={String(inline?.approvalPending)}
94+
data-approval-recall-drawn-by-host={String(inline?.approvalRecallDrawnByHost)}
9495
/>
9596
);
9697
};
@@ -286,3 +287,30 @@ describe('record page → band: who may see recall (objectui#6464)', () => {
286287
expect(probe.getAttribute('data-approval-is-submitter')).toBe('undefined');
287288
});
288289
});
290+
291+
/**
292+
* Recall is drawn ONCE per page (objectstack#25877). The page's declared
293+
* decision bar carries `approval_recall`, so whenever the page mounts that bar
294+
* it must tell the band below to keep its lock badge only, and whenever it
295+
* does not, the band stays the recall lever. `DetailView.approvalRecallHostDrawn`
296+
* measures the band; this measures the seam.
297+
*/
298+
describe('record page → band: who draws recall (objectstack#25877)', () => {
299+
it('tells the band the page draws recall when the decision bar is up', async () => {
300+
stubApprovalsApi(pendingRequest({ viewer: { can_act: false, is_submitter: true, can_override: false } }));
301+
renderRecordPage();
302+
303+
const probe = await settledProbe(true);
304+
await waitFor(() =>
305+
expect(probe.getAttribute('data-approval-recall-drawn-by-host')).toBe('true'),
306+
);
307+
});
308+
309+
it('leaves the band as the recall lever when there is no approvals API', async () => {
310+
stubApprovalsApi(null, 404);
311+
renderRecordPage();
312+
313+
const probe = await settledProbe(true);
314+
expect(probe.getAttribute('data-approval-recall-drawn-by-host')).toBe('false');
315+
});
316+
});

0 commit comments

Comments
 (0)