Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .changeset/34361-approver-band-fold.md
Original file line number Diff line number Diff line change
@@ -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`.
66 changes: 66 additions & 0 deletions ui/packages/app-shell/src/utils/approvalDecisionFold.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
74 changes: 74 additions & 0 deletions ui/packages/app-shell/src/utils/approvalDecisionFold.ts
Original file line number Diff line number Diff line change
@@ -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<string> = 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;
}
Loading
Loading