Skip to content

Commit 5727092

Browse files
fix(console): the approvals inbox status filter offers Cancelled (#37003)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> Fixes #36960 _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBTDAJKyXUan6fJCKsZUf5Pv)_ Clause-②: no Metadata-protocol: none ## 维护者速读 - 审批收件箱「我提交的」和「全部」两个页签里,状态筛选下拉框多了「已取消」一项;以前只有五种状态,已取消的审批单在列表里看得到却筛不出来,现在可以直接筛出。 - 属于审批收件箱的体验修补:替想找"没有结论就结束了"的审批单的提交人和管理员解决翻遍整页的问题。 - 出错时最坏是筛选项显示不对,用户仍可用「全部状态」浏览;改动只在前端下拉选项,可直接撤回。 - 无。 ## What changes - The approvals inbox status select (shown on **Submitted by me** and **All**) drew five hand-typed options and had no **Cancelled**, although cancelled rows show in the same list with their own badge and the server answers `GET /api/v1/approvals/requests?status=cancelled`. - The options are now one `SelectItem` per entry of the contract's `APPROVAL_STATUSES` (`@objectstack/spec/contracts`), labelled through the page's existing `statusLabel`. Order is unchanged for the five existing statuses; Cancelled comes last. A status the contract adds later is offered without a console change; `APPROVAL_STATUS_LABELS` is already `satisfies Record<ApprovalStatus, string>`, and `statusLabel` falls back to the raw token for a status it has no case for. - The diff in `ApprovalsInboxPage.tsx` is confined to the option list and one import name, so it stays clear of #36979 (the tab, filter, search and sort state moving into the address) on the same file: `overlap-check.mjs` answers `merges cleanly` against both `origin/main` and #36979. - Changeset: `@object-ui/console` patch (the published package that ships this page; `@objectstack/console` carries its built dist in the same fixed version group, the convention every console changeset follows). **Read first (by risk):** 1. `ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx`, the hunk inside the status `SelectContent` (the `APPROVAL_STATUSES.map` block): the one behaviour change. 2. `ui/apps/console/src/pages/system/ApprovalsInboxPage.statusFilterCancelled-36960.test.tsx`: the pins, with the real `approvalsApi` and a stubbed authenticated fetch. **Two-minute check:** `pnpm --dir ui exec vitest run apps/console/src/pages/system/ApprovalsInboxPage.statusFilterCancelled-36960.test.tsx` from the repo root (after building the `@objectstack/*` closure) answers `Tests 3 passed (3)`. In the browser: Approvals Inbox, tab **All**, open the status select: the last option is **Cancelled**, and choosing it leaves only cancelled rows. ## Tests New file `ApprovalsInboxPage.statusFilterCancelled-36960.test.tsx`, mounting the real page over the real `approvalsApi`, with only `createAuthenticatedFetch` stubbed, so the assertion is the request URL: - the option list is exactly `All statuses` plus one option per `APPROVAL_STATUSES` value, in contract order, with Cancelled last; - choosing **Cancelled** sends a request-list call whose `status` query value is `cancelled`. **Red on main, green here;** - control: choosing **Rejected** sends `status=rejected` and no `cancelled`. Green on both trees, so the Cancelled case cannot pass on a select that sends nothing or the same token for every option. ## Acceptance notes - **Other places in this page that might omit `cancelled`: none found.** `STATUS_CLASSES` and `statusLabel` both have it. The client-side status match (`r.status !== statusFilter`) is generic. The **Pending** tab draws no status select and lists only `pending` by design. The two counts (my pending, environment pending) are pending-only by design: the contract says a cancelled request leaves the pending count. The filter's default is `all`. The `ApprovalRequestRow.status` union includes `cancelled`. #36979's address parser validates `status` against the same `APPROVAL_STATUSES`, so `?status=cancelled` will round-trip once both land. - Observation, not filed (copy, outside the three filing classes): `statusLabel`'s English default for `returned` is "Returned for revision", while the contract's `APPROVAL_STATUS_LABELS.returned` is "Returned". The page keeps its own string. This PR leaves it unchanged. - A new test file rather than a describe in the tombstone file: the siblings stub `approvalsApi` and read argument objects, and this pin needs the real client so it can assert the wire URL. - `type-check` for `@object-ui/console` was not run locally. It compiles against every `@object-ui/*` package's built `dist/*.d.ts`, which this worktree does not have. `Type Check UI` in CI covers it. The test file was linted locally (0 errors, 0 warnings). ## Verification All readings below are on `objectstack-ai/objectstack` at head `c19a458204` unless a line names another commit. <details><summary>New pins: green with the fix, red on main's page source</summary> ``` with fix (c19a458): Tests 3 passed (3) main's page file (57445a6), git restore --source=57445a6998 for the page only: x lists "All statuses" and one option per APPROVAL_STATUSES value, Cancelled included x choosing Cancelled asks the server for status=cancelled Tests 2 failed | 1 passed (3) (the Rejected control passes) restore: blob == HEAD (ab2ff7f), git diff HEAD empty ``` </details> <details><summary>Ablation (scripts/ablation-replace.mjs)</summary> Anchor `{APPROVAL_STATUSES.map((s) => (` was replaced with a filter that drops `cancelled`. The page is imported from source, so there was no dist leg. ``` anchor x1 -> x0, replacement x0 -> x1, blob ab2ff7f -> aec5f8d94a7d (mutation landed) AssertionError: expected [ 'All statuses', 'Pending', …(4) ] to have a length of 7 but got 6 Tests 2 failed | 1 passed (3) restored: blob == HEAD (ab2ff7f) and git diff HEAD is empty ``` This ran at 8a5d1b5. The later commit only re-typed the test's pointer-event shim without `any` and left the assertions unchanged. </details> <details><summary>Sibling suites</summary> `pnpm --dir ui exec vitest run apps/console/src/pages/system/ApprovalsInboxPage`: `Test Files 20 passed (20) · Tests 107 passed (107)` (lock VERDICT command-exit 0), at 8a5d1b5. </details> <details><summary>Derived gate families (dispatch-gates --commands)</summary> 37 families were derived. All 36 non-vitest families were re-run at `c19a458204` and each exited 0. `pnpm --dir ui exec vitest run scripts/` exited 0 at 8a5d1b5 (`Test Files 172 passed | 2 skipped`). Reconciliation: `dispatch-gates --ran: 37 derived famil(ies) accounted for — 37 run, 0 NOT-MEASURED (a DERIVED zero)`. `check:new-line-citations` (ui): `0 new citation(s)`. Everything else runs in CI. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufziG2t1d9cfRQJDrHkB)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4c4a677 commit 5727092

3 files changed

Lines changed: 214 additions & 6 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@object-ui/console': patch
3+
---
4+
5+
fix(console): the approvals inbox status filter offers Cancelled
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On the **Submitted by me** and **All** tabs of the approvals inbox, the status filter listed Pending, Approved, Rejected, Recalled and Returned for revision, but not **Cancelled**, although cancelled requests show in the same list with their own badge and the server answers `GET /api/v1/approvals/requests?status=cancelled`. The filter now offers Cancelled, and choosing it lists only the cancelled requests.
11+
12+
The options are now drawn from the approval contract's status list (`APPROVAL_STATUSES` in `@objectstack/spec/contracts`) rather than typed out one by one, so a status the platform adds later appears in the filter without a console change. Each option keeps the label its badge shows.
13+
14+
Nothing to migrate.
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* Approvals Inbox — the status filter offers every status a row can show,
5+
* Cancelled included (objectstack#36960).
6+
*
7+
* The select on the paginated tabs ("Submitted by me", "All") listed five
8+
* statuses by hand. `cancelled` — the terminal state the platform writes when
9+
* it voids a request (objectstack#13568) — was missing, although its rows show
10+
* in the same list with their own badge and the server answers
11+
* `?status=cancelled`. The options now come from the contract's
12+
* `APPROVAL_STATUSES`.
13+
*
14+
* What this file pins, through the real page AND the real `approvalsApi`:
15+
* - the option list is exactly "All statuses" plus one entry per
16+
* `APPROVAL_STATUSES` value, labelled the way the badges are;
17+
* - choosing Cancelled sends `status=cancelled` on the wire;
18+
* - choosing an existing status (Rejected) still sends its own token — the
19+
* control that keeps the Cancelled case from passing on a select that
20+
* sends nothing, or the same thing for every option.
21+
*
22+
* The siblings stub `approvalsApi` and read the arguments the page handed it.
23+
* This file keeps it real and stubs the authenticated fetch underneath, so the
24+
* assertion is the request URL the server would receive, not an argument
25+
* object that a later serialisation step could still drop.
26+
*/
27+
28+
import '@testing-library/jest-dom/vitest';
29+
import { describe, it, expect, vi, beforeAll, beforeEach, afterEach } from 'vitest';
30+
import { render, screen, cleanup, fireEvent, waitFor } from '@testing-library/react';
31+
import { MemoryRouter, Routes, Route } from 'react-router-dom';
32+
import { APPROVAL_STATUSES } from '@objectstack/spec/contracts';
33+
34+
const APP = 'com.objectstack.account';
35+
36+
const { authFetch, ADAPTER, AUTH, I18N } = vi.hoisted(() => {
37+
const base = {
38+
process_name: 'leave_approval',
39+
process_label: 'Leave Approval',
40+
object_name: 'showcase_leave_request',
41+
object_label: 'Leave Request',
42+
submitted_at: '2026-09-01T00:00:00.000Z',
43+
created_at: '2026-09-01T00:00:00.000Z',
44+
};
45+
const rows = [
46+
{ ...base, id: 'req_ok', record_id: 'rec_ok', record_title: 'LR-00001', status: 'approved', submitter_id: 'u_a', submitter_name: 'Ada Approved' },
47+
{ ...base, id: 'req_void', record_id: 'rec_void', record_title: 'LR-00002', status: 'cancelled', cancel_reason: 'record_deleted', submitter_id: 'u_c', submitter_name: 'Cyd Cancelled' },
48+
];
49+
50+
// Every request the page makes goes through here. The request list answers
51+
// the rows; anything else answers an empty body, as the siblings' stub does.
52+
const authFetch = vi.fn(async (input: RequestInfo | URL) => {
53+
const url = String(input);
54+
const body = url.includes('/approvals/requests?')
55+
? { data: rows, total: rows.length }
56+
: {};
57+
return new Response(JSON.stringify(body), {
58+
status: 200,
59+
headers: { 'Content-Type': 'application/json' },
60+
});
61+
});
62+
63+
// STABLE singletons: a mocked hook that returns a fresh object per render
64+
// re-runs the page's load effect forever (see the sibling suites).
65+
const ADAPTER = { find: vi.fn(async () => ({ data: [] })) };
66+
const AUTH = { user: { id: 'u_1', email: 'approver@example.com' } };
67+
const I18N = {
68+
t: (key: string, options?: Record<string, unknown>) => String(options?.defaultValue ?? key),
69+
language: 'en',
70+
};
71+
72+
return { authFetch, ADAPTER, AUTH, I18N };
73+
});
74+
75+
vi.mock('@object-ui/i18n', async (importOriginal) => ({
76+
...(await importOriginal<Record<string, unknown>>()),
77+
useObjectTranslation: () => I18N,
78+
}));
79+
80+
vi.mock('@object-ui/auth', async (importOriginal) => ({
81+
...(await importOriginal<Record<string, unknown>>()),
82+
useAuth: () => AUTH,
83+
createAuthenticatedFetch: () => authFetch,
84+
TokenStorage: { get: () => null },
85+
}));
86+
87+
vi.mock('@object-ui/app-shell', async (importOriginal) => ({
88+
...(await importOriginal<Record<string, unknown>>()),
89+
useAdapter: () => ADAPTER,
90+
DeclaredActionsBar: () => null,
91+
isViaOverrideRow: () => false,
92+
}));
93+
94+
// `../../services/approvalsApi` stays REAL: the URL it builds is the observable.
95+
96+
// Imported after the mocks so the page picks them up.
97+
import { ApprovalsInboxPage } from './ApprovalsInboxPage';
98+
99+
function renderInbox() {
100+
return render(
101+
<MemoryRouter initialEntries={[`/apps/${APP}/system/approvals`]}>
102+
<Routes>
103+
<Route path="/apps/:appName/system/approvals" element={<ApprovalsInboxPage />} />
104+
</Routes>
105+
</MemoryRouter>,
106+
);
107+
}
108+
109+
/** The `status` query value of every request-list call made so far. */
110+
function listStatuses(): Array<string | null> {
111+
return authFetch.mock.calls
112+
.map(([input]) => String(input))
113+
.filter((url) => url.includes('/approvals/requests?'))
114+
.map((url) => new URL(url, 'http://inbox.test').searchParams.get('status'));
115+
}
116+
117+
/** Land on "All", where cancelled rows live, and open the status select. */
118+
async function openStatusSelectOnAllTab(): Promise<void> {
119+
renderInbox();
120+
const allTab = await screen.findByRole('tab', { name: /^All/ });
121+
fireEvent.mouseDown(allTab);
122+
fireEvent.click(allTab);
123+
// Each request renders twice (desktop table + mobile card): `findAll`.
124+
await screen.findAllByText('Cyd Cancelled');
125+
const trigger = (await screen.findAllByRole('combobox'))
126+
.find((el) => el.textContent?.includes('All statuses'));
127+
expect(trigger, 'the status select is drawn on the All tab').toBeTruthy();
128+
fireEvent.pointerDown(trigger!, { button: 0, ctrlKey: false, pointerType: 'mouse' });
129+
await screen.findByRole('option', { name: 'All statuses' });
130+
}
131+
132+
/** Choose `label` and wait for the list request that carries `token`. */
133+
async function choose(label: string, token: string): Promise<void> {
134+
fireEvent.click(screen.getByRole('option', { name: label }));
135+
await waitFor(() => expect(listStatuses()).toContain(token));
136+
}
137+
138+
beforeAll(() => {
139+
// Radix Select drives its trigger off pointer events, which the DOM shim
140+
// does not implement — the same shim the sibling sort-select pins install.
141+
class MockPointerEvent extends Event {
142+
button: number;
143+
ctrlKey: boolean;
144+
pointerType: string;
145+
constructor(type: string, props: PointerEventInit = {}) {
146+
super(type, props);
147+
this.button = props.button ?? 0;
148+
this.ctrlKey = props.ctrlKey ?? false;
149+
this.pointerType = props.pointerType ?? 'mouse';
150+
}
151+
}
152+
Object.assign(window, { PointerEvent: MockPointerEvent });
153+
Object.assign(HTMLElement.prototype, {
154+
hasPointerCapture: vi.fn(),
155+
releasePointerCapture: vi.fn(),
156+
scrollIntoView: vi.fn(),
157+
});
158+
});
159+
160+
beforeEach(() => {
161+
authFetch.mockClear();
162+
});
163+
afterEach(cleanup);
164+
165+
describe('Approvals Inbox — the status filter offers every contract status (objectstack#36960)', () => {
166+
it('lists "All statuses" and one option per APPROVAL_STATUSES value, Cancelled included', async () => {
167+
await openStatusSelectOnAllTab();
168+
const names = screen.getAllByRole('option').map((o) => o.textContent);
169+
expect(names).toHaveLength(1 + APPROVAL_STATUSES.length);
170+
expect(names).toEqual([
171+
'All statuses',
172+
'Pending',
173+
'Approved',
174+
'Rejected',
175+
'Recalled',
176+
'Returned for revision',
177+
'Cancelled',
178+
]);
179+
});
180+
181+
it('choosing Cancelled asks the server for status=cancelled', async () => {
182+
await openStatusSelectOnAllTab();
183+
expect(listStatuses()).not.toContain('cancelled');
184+
await choose('Cancelled', 'cancelled');
185+
});
186+
187+
it('control: choosing an existing status (Rejected) still sends its own token', async () => {
188+
await openStatusSelectOnAllTab();
189+
expect(listStatuses()).not.toContain('rejected');
190+
await choose('Rejected', 'rejected');
191+
expect(listStatuses()).not.toContain('cancelled');
192+
});
193+
});

‎ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import { toast } from 'sonner';
8080
import { useAuth } from '@object-ui/auth';
8181
import { declaredUserMessage } from '@object-ui/react';
8282
import { useDisplayLocale, useObjectTranslation } from '@object-ui/i18n';
83-
import { APPROVAL_STATUS_LABELS } from '@objectstack/spec/contracts';
83+
import { APPROVAL_STATUSES, APPROVAL_STATUS_LABELS } from '@objectstack/spec/contracts';
8484
import {
8585
CheckCircle2,
8686
XCircle,
@@ -1920,11 +1920,12 @@ function ApprovalsQueue() {
19201920
</SelectTrigger>
19211921
<SelectContent>
19221922
<SelectItem value="all">{tr('allStatuses', 'All statuses')}</SelectItem>
1923-
<SelectItem value="pending">{statusLabel('pending')}</SelectItem>
1924-
<SelectItem value="approved">{statusLabel('approved')}</SelectItem>
1925-
<SelectItem value="rejected">{statusLabel('rejected')}</SelectItem>
1926-
<SelectItem value="recalled">{statusLabel('recalled')}</SelectItem>
1927-
<SelectItem value="returned">{statusLabel('returned')}</SelectItem>
1923+
{/* One option per status the CONTRACT declares, so a state the
1924+
platform adds is offered the day it ships (a hand-typed list
1925+
missed `cancelled` while its rows already showed here). */}
1926+
{APPROVAL_STATUSES.map((s) => (
1927+
<SelectItem key={s} value={s}>{statusLabel(s)}</SelectItem>
1928+
))}
19281929
</SelectContent>
19291930
</Select>
19301931
)}

0 commit comments

Comments
 (0)