Skip to content

Commit 8695703

Browse files
fix(console): a partly failed bulk approve names each failed row with its reason (#37282)
repo:objectstack#4 · os-justin · session_01QSeKYnagJvGbCtNg2PhvgW Fixes #36855 Clause-②: yes (narrowing) Metadata-protocol: none Skills-docs: none — no page under `skills/` or `content/docs/` names the Approval Center's bulk-failure string or teaches overriding it ## 维护者速读 - 审批中心里批量通过或驳回时,若部分失败,审批人现在能看到每条失败记录及其失败原因;失败太多时点“查看全部”可在弹窗里看到每一条。 - 替“批量处理审批的审批人”解决:以前只列出记录名,不说为什么失败,无从下手。 - 只改提示文案和一个只读弹窗,不改审批结果;出错最多是提示不完整,可直接撤回本改动。旧的一条提示文案退役(随 19.0.0 大版本):自行改写过它的部署,改写不再生效。 - 无 ## What changes `runBulk` in `ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx` caught each failure with a bare `catch` and kept only the record title. Now each failure keeps `{ id, title, reason }`, where `reason` is `humanizeError(err, tr('actionFailed', 'Action failed'))`: the same reader the single-row Approve and Reject use. It returns the server's `userMessage` (via `declaredUserMessage`) when the refusal carries one, else the page's localized line for the refusal (not allowed, already decided, no longer exists), else the error's own text (`approvalsApi.call` always sets one as `CODE: message`, so a 500 reads `APPROVAL_APPROVE_FAILED: ` plus the server's text). The generic `Action failed` is reached only by an error with no message. The partial-failure toast is now titled "N succeeded, M failed" and its description lists the first three failed rows, one per line, as "title: reason". The toast stays until dismissed (`duration: Infinity`, close button), whatever the count. When more than three fail, it carries a "Show all (M)" action. The action closes over that run's own list: it puts that list into the dialog and opens it, so a toast still on screen after a later run shows its own rows. The dialog lists every failed row with its reason. The page dismisses its failure toasts on unmount, because their action opens a dialog that lives in the page. The dialog is rendered outside the bulk bar, so it survives the selection being cleared. The console had no existing overflow pattern for a bulk toast. The nearest ones (`AppManagementPage` bulk toggle, the Studio save bar) put all lines into one toast with no cap, which is what this card asks to avoid. So I used a toast action plus an `AlertDialog`, built from components the page already imports. Locale packs (`ui/packages/i18n/src/locales/*.ts`, all 11): `approvalsInbox.bulkPartial` is replaced by `bulkPartialSummary`, `bulkFailureLine`, `bulkFailuresShowAll`, `bulkFailuresTitle`, `bulkFailuresBody` and `close`. Key parity holds. `zh-Hant.ts` is regenerated from zh-Hans (`gen:zh-hant`). `bulkFailureLine` is added to the `untranslated-identity` allowlist as a format string (holes and a colon), the same as `listConditions.chips.pattern`. Read first, by risk: 1. `ApprovalsInboxPage.tsx`, the `runBulk` hunk: the reason reader and the overflow branch of the toast options. 2. `ApprovalsInboxPage.tsx`, the new `AlertDialog` after the bulk action bar. 3. `ApprovalsInboxPage.inlineActionsVisible-34587.test.tsx`: the stub translator now interpolates `{{name}}` holes. No existing assertion in that file used a hole. Two-minute check: `cd ui && pnpm exec vitest run apps/console/src/pages/system/ApprovalsInboxPage.inlineActionsVisible-34587.test.tsx` should report 10 passed. The four cases under "a partly failed bulk approve says why each row failed" are the new pins. ## Tests New top-level `describe` in the shared inbox harness file `ApprovalsInboxPage.inlineActionsVisible-34587.test.tsx`, beside the #36463 refusal pin: - one refused row out of two: the toast reads `1 succeeded, 1 failed`, and its description is `Bulk Invoice 2:` followed by the server's marked `userMessage`, with no overflow action; - CONTROL: all three rows succeed, so there is one success toast, no error toast and no failure list; - six rows with five failures (mixed marked `userMessage` and 409 already-decided): the toast lists the first three with reasons, its action reads `Show all (5)` and the toast is sticky. Clicking the action opens the dialog, and every one of the five rows appears with its own reason. The succeeding row does not appear. - two runs on one page, first with five failures, then clean: the first toast's `Show all (5)` still opens `Not decided: 5` with rows 1 to 5. This is the L1 repro; it read `Not decided: 0` and an empty list before. Ablation through `scripts/ablation-replace.mjs`: the reason was replaced with `''`. The mutation landed (anchor 1 to 0, blob d21c880 to 8724dfc2388a). Two pins went red (`expected 'Bulk Invoice 2: ' to be 'Bulk Invoice 2: ...'`, Tests 2 failed / 7 passed). The file was restored, blob equal to HEAD and `git diff HEAD` empty. Second ablation (own-run list), on head e1ea082. Two held mutations through `scripts/ablation-replace.mjs` put back the shared-state design: the action's `setBulkFailures(failures);` became `void failures;`, and `setBulkFailures(failures);` was written at the end of every run. Both landed (blob a729e1d to 7cfb74cd2d70 to c783de858825). The two-run pin went red, with the dialog reading `Not decided: 0`, which is the L1 repro (Tests 1 failed / 9 passed). Restored with `--restore`: blob equal to the HEAD blob a729e1d, `git diff HEAD` empty. ## Removed translation keys `approvalsInbox.bulkPartial` (`@object-ui/i18n`, released in 18.6.0) is retired from all eleven packs it shipped in: ar, de, en, es, fr, ja, ko, pt-BR, ru, zh-Hans and zh-Hant. This follows the 19.0.0 key-retirement ruling (7153171432 / 7153326968). It is **BREAKING** only for a host that overrides that key: the override is no longer shown. The changeset carries the ADR-0087 disposition `not-required (no-migration-prescription)`. No reader is left. On head 935499b, `git grep` for `bulkPartial` (excluding `bulkPartialSummary`) across `ui packages apps examples skills` gave exit 1, no hits. Every dynamic `approvalsInbox.` + key construction is a wrapper: five definitions in four files (the console page's `tr`, `RecordApprovalsPanel`, two in `ApprovalDecisionPanel`, `ApprovalActionTimeline`). None of them is called with a non-literal key (`git grep` exit 1). The release tag `@object-ui/i18n@18.6.0` carries the key in all 11 packs. ## Acceptance notes - `humanizeError`'s last fallback is `err.message || fallback`. A refusal with no `userMessage` and no recognised code or status therefore shows the error's own message, exactly as the single-row Approve does today. That keeps one reader, as the card asks. It is not narrowed here. - The bulk Reject path shares `runBulk`, so it gets the same feedback. ## Verification Code and test runs were on head 935499b. Head b646804 adds only the changeset declaration; its gates are listed below. <details><summary>Tests</summary> - `cd ui && pnpm exec vitest run apps/console/src/pages/system/ApprovalsInboxPage packages/i18n/src/__tests__/{untranslated-identity-4376,zh-hant-generated,all-locales-key-parity,en-zh-key-parity}.test.ts`: Test Files 25 passed (25), Tests 185 passed (185). - An earlier run of the whole i18n package plus the inbox files, on aafd923: 130 of 132 files passed. The 2 failures (zh-Hant stale, `bulkFailureLine` identity) were fixed in 935499b and re-run green. - `pnpm --filter @object-ui/console type-check` and `pnpm --filter @object-ui/i18n type-check`: exit 0. The console tsconfig includes `src`, so the test file is compiled. </details> <details><summary>Derived gates</summary> - `dispatch-gates --commands` derived 41 families. 40 exited 0. - `pnpm --dir ui exec vitest run scripts/` first hit a lock queue-timeout (exit 99, never ran). The re-run on 935499b exited 0: Test Files 172 passed, 2 skipped. - `--ran` reconciliation: 41 derived, 41 run, 0 NOT-MEASURED, 0 UNRUN. - The derivation on the final head is identical to the first one. - Head b646804 / c98f1ce (changeset declaration only): the derivation is unchanged at 41 families. The 40 non-vitest families were re-run and 39 exited 0. `check:type-check-debt` first exited 3: PREREQUISITE NOT MET, because its closure build lost the lock queue to this PR's own dogfood run. Re-run under the lock it exited 0 (130/133 type-checked, 0 re-measured above record). `check-adr-0087-registration` (1 declared-breaking changeset, disposition `not-required (no-migration-prescription)`), `check-changeset-no-major`, `check-empty-changeset` and `check:nul-bytes` were re-run on c98f1ce and exited 0. `pnpm --dir ui exec vitest run scripts/` was not re-run after the changeset-only commits; its reading is from 935499b. </details> <details><summary>Round 3 (L1 S1/S2, head bc98914)</summary> - S1: the toast's "Show all" action now closes over its own run's list (`setBulkFailures(failures)` runs in `onClick`, not at the end of every run). The page dismisses its sticky failure toasts on unmount. - N2 taken: every partial-failure toast stays until dismissed, not only an overflowing one. - N6 taken in this body. N1, N3, N4 and N5 were not taken; N1 sits in the declaration text, which this round leaves untouched. - S2: the changeset now names the error's own text as the last fallback. - `ApprovalsInboxPage.inlineActionsVisible-34587.test.tsx`: Tests 10 passed (10). All inbox files (`apps/console/src/pages/system/ApprovalsInboxPage`, with the console type-check first): Test Files 21 passed (21), Tests 120 passed (120). Type-check exit 0. - Derived gates on bc98914: 41 derived, 41 run, all exit 0. `vitest run scripts/` and `check:type-check-debt` ran under the lock. `--ran` gives 0 NOT-MEASURED, 0 UNRUN. - overlap-check: VERDICT clean exit 0 before the push. - Dogfood on bc98914: VERDICT command-exit 0, Test Files 487 passed | 3 skipped (490), Tests 4128 passed | 68 skipped (4196). </details> <details><summary>Dogfood battery (owed by the narrowing arm)</summary> - The `@objectstack/dogfood^...` closure was built, then `pnpm --filter @objectstack/dogfood test` ran under the lock on head b646804. VERDICT command-exit 0. Test Files 487 passed, 3 skipped (490). Tests 4128 passed, 68 skipped (4196). - The final head c98f1ce differs from that head only by one line in the changeset. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYnagJvGbCtNg2PhvgW)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 91138ec commit 8695703

15 files changed

Lines changed: 349 additions & 21 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
'@object-ui/console': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
fix(console): a partly failed bulk approve or reject in the Approval Center says why each row failed
7+
8+
Clause-②: yes (narrowing)
9+
Metadata-protocol: none
10+
Skills-docs: none — no page under `skills/` or `content/docs/` names the Approval Center's bulk-failure string or teaches overriding it
11+
12+
<!-- adr-0087: not-required (no-migration-prescription) the narrowing is one console string retired from the approvalsInbox locale namespace of @object-ui/i18n; no packages/spec schema, registered node type, stored row or metadata key names it, nothing a metadata author writes changes, and a host that overrode it has nothing to rewrite: its override is simply no longer shown -->
13+
14+
**BREAKING** for a host that overrides `approvalsInbox.bulkPartial`, listed under "Removed translation keys" below: it is retired in 19.0.0, and an override of it no longer applies.
15+
16+
A bulk approve or reject that partly fails used to show "3 succeeded, 2 failed: Quote A, Quote B": at most three record titles, and no reason. Each failed row now keeps its refusal's text, read the way the single-row Approve reads it: the server's `userMessage` (already in the decider's language) when the refusal carries one, else the page's line for the refusal (not allowed, already decided, no longer exists), else the error's own text as the console's approvals client reports it (`CODE: message`; a server failure, for example, reads `APPROVAL_APPROVE_FAILED: ` followed by the server's text). The generic "Action failed" shows only for an error that carries no text at all.
17+
18+
The error toast reads "N succeeded, M failed" and lists the first three failed rows, one per line, each as "title: reason". It stays until dismissed. When more rows fail, it carries a "Show all (M)" action, which opens a dialog listing every failed row of that run with its reason, even after a later bulk run. The toasts are dismissed when the Approval Center is left.
19+
20+
`@object-ui/i18n`: the `approvalsInbox` namespace gains `bulkPartialSummary`, `bulkFailureLine`, `bulkFailuresShowAll`, `bulkFailuresTitle`, `bulkFailuresBody` and `close`, in every locale pack.
21+
22+
Removed translation keys (approvalsInbox namespace of `@object-ui/i18n`, released in 18.6.0; no code reads it since the partial-failure toast became a summary plus per-row lines). It is removed from all eleven packs it shipped in, `ar`, `de`, `en`, `es`, `fr`, `ja`, `ko`, `pt-BR`, `ru`, `zh-Hans` and `zh-Hant`:
23+
24+
- `approvalsInbox.bulkPartial` (ar, de, en, es, fr, ja, ko, pt-BR, ru, zh-Hans, zh-Hant)
25+
26+
An override of this key no longer applies; delete it, or move its wording to `approvalsInbox.bulkPartialSummary` (no `{{which}}` hole: the failed rows are listed below the summary).

‎ui/apps/console/src/pages/system/ApprovalsInboxPage.inlineActionsVisible-34587.test.tsx‎

Lines changed: 162 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import '@testing-library/jest-dom/vitest';
2424
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
25-
import { render, screen, cleanup, waitFor, within, fireEvent } from '@testing-library/react';
25+
import { render, screen, cleanup, waitFor, within, fireEvent, act } from '@testing-library/react';
2626
import { MemoryRouter, Routes, Route } from 'react-router-dom';
2727

2828
const APP = 'com.objectstack.account';
@@ -71,7 +71,10 @@ const { approvalsApiStub, ADAPTER, AUTH, I18N } = vi.hoisted(() => {
7171
};
7272
const AUTH = { user: { id: 'u_1', email: 'approver@example.com' } };
7373
const I18N = {
74-
t: (key: string, options?: Record<string, unknown>) => String(options?.defaultValue ?? key),
74+
// Interpolates like i18next, so a line built from values shows them.
75+
t: (key: string, options?: Record<string, unknown>) =>
76+
String(options?.defaultValue ?? key).replace(/\{\{(\w+)\}\}/g, (whole, name: string) =>
77+
options && name in options ? String(options[name]) : whole),
7578
language: 'en',
7679
};
7780

@@ -239,3 +242,160 @@ describe('Approvals Inbox — a marked decide refusal is shown as written (objec
239242
expect(await approveQuickFailingWith(refusal())).toBe('You are not allowed to perform this action.');
240243
});
241244
});
245+
246+
// A bulk approve that partly fails names each failed row WITH its reason —
247+
// the refusal's own text (`userMessage` first, through the same reader the
248+
// inline Approve uses above), else the page's generic line. When more rows
249+
// fail than the toast lists, its "Show all" action opens a dialog listing
250+
// every one.
251+
describe('Approvals Inbox — a partly failed bulk approve says why each row failed', () => {
252+
const MARKED = '此请求由您提交,而其审批步骤不允许提交人批准自己的请求,因此您不能批准它。';
253+
const markedRefusal = () => Object.assign(new Error('FORBIDDEN: submitter cannot approve'), {
254+
code: 'FORBIDDEN',
255+
status: 403,
256+
details: { code: 'FORBIDDEN', error: 'refused', userMessage: MARKED },
257+
});
258+
const decidedRefusal = () => Object.assign(new Error('INVALID_STATE: already decided'), {
259+
code: 'INVALID_STATE',
260+
status: 409,
261+
details: { code: 'INVALID_STATE', error: 'already decided' },
262+
});
263+
const ALREADY_DECIDED = 'This request was already decided. Refresh the list.';
264+
265+
const row = (n: number) => ({
266+
id: `req_${n}`,
267+
record_id: `inv_${n}`,
268+
record_title: `Bulk Invoice ${n}`,
269+
process_name: 'invoice_approval',
270+
process_label: 'Invoice Approval',
271+
object_name: 'showcase_invoice',
272+
object_label: 'Invoice',
273+
status: 'pending',
274+
pending_approvers: ['u_1'],
275+
submitter_id: 'u_2',
276+
submitter_name: 'Sam Submitter',
277+
// Newest first is the inbox's order: row 1 is the newest, so it lists first.
278+
submitted_at: `2026-08-${String(30 - n).padStart(2, '0')}T00:00:00.000Z`,
279+
});
280+
281+
let originalList: ReturnType<typeof approvalsApiStub.listRequests.getMockImplementation>;
282+
beforeEach(() => { originalList = approvalsApiStub.listRequests.getMockImplementation(); });
283+
afterEach(() => {
284+
approvalsApiStub.listRequests.mockImplementation(originalList!);
285+
approvalsApiStub.approve.mockReset();
286+
approvalsApiStub.approve.mockImplementation(async () => ({ data: row(0), finalized: true }) as any);
287+
});
288+
289+
/** Render `count` actionable rows; the returned function runs one bulk approve. */
290+
async function renderRows(count: number) {
291+
const rows = Array.from({ length: count }, (_, i) => row(i + 1));
292+
approvalsApiStub.listRequests.mockImplementation(async () => ({ data: rows }) as any);
293+
render(
294+
<MemoryRouter initialEntries={[`/apps/${APP}/system/approvals`]}>
295+
<Routes>
296+
<Route path="/apps/:appName/system/approvals" element={<ApprovalsInboxPage />} />
297+
</Routes>
298+
</MemoryRouter>,
299+
);
300+
const box = await screen.findByTestId('approvals-inbox-table-scroller');
301+
/** Select every row, confirm a bulk approve in which the `fail` rows are refused. */
302+
return async (fail: Record<string, () => Error>) => {
303+
const before = approvalsApiStub.approve.mock.calls.length;
304+
approvalsApiStub.approve.mockImplementation((async (id: string) => {
305+
if (fail[id]) throw fail[id]();
306+
return { data: rows.find(r => r.id === id), finalized: true };
307+
}) as any);
308+
for (const r of rows) {
309+
const link = await within(box).findByRole('link', { name: r.record_title });
310+
const tr = link.closest('tr') as HTMLElement;
311+
fireEvent.click(within(tr).getByRole('checkbox', { name: 'Select request' }));
312+
}
313+
fireEvent.click(await screen.findByRole('button', { name: `Approve ${count}` }));
314+
const dialog = await screen.findByRole('alertdialog');
315+
fireEvent.click(within(dialog).getByRole('button', { name: `Approve ${count}` }));
316+
await waitFor(() => expect(approvalsApiStub.approve).toHaveBeenCalledTimes(before + count));
317+
await waitFor(() => expect(screen.queryByRole('alertdialog')).toBeNull());
318+
// The run is over once the selection it cleared is gone.
319+
await waitFor(() => expect(screen.queryByRole('button', { name: `Approve ${count}` })).toBeNull());
320+
};
321+
}
322+
323+
async function bulkApprove(count: number, fail: Record<string, () => Error>) {
324+
await (await renderRows(count))(fail);
325+
}
326+
327+
it('one refused row: the toast names that row with its marked reason', async () => {
328+
await bulkApprove(2, { req_2: markedRefusal });
329+
await waitFor(() => expect(toasts.error).toHaveBeenCalledTimes(1));
330+
const [title, options] = toasts.error.mock.calls[0] as [string, Record<string, any>];
331+
expect(title).toBe('1 succeeded, 1 failed');
332+
// The failed row, and why — the server's marked text, not a bare title.
333+
expect(options.description).toBe(`Bulk Invoice 2: ${MARKED}`);
334+
expect(toasts.success).not.toHaveBeenCalled();
335+
// Everything fits in the toast: no overflow action; it still stays until
336+
// dismissed, so the reasons can be read.
337+
expect(options.action).toBeUndefined();
338+
expect(options.duration).toBe(Infinity);
339+
});
340+
341+
it('CONTROL: every row succeeds — a success toast and no failure feedback', async () => {
342+
await bulkApprove(3, {});
343+
await waitFor(() => expect(toasts.success).toHaveBeenCalledTimes(1));
344+
expect(toasts.error).not.toHaveBeenCalled();
345+
expect(screen.queryByTestId('approvals-bulk-failures')).toBeNull();
346+
});
347+
348+
it('more failures than the toast lists: "Show all" reaches every row and its reason', async () => {
349+
await bulkApprove(6, {
350+
req_1: markedRefusal, req_2: decidedRefusal, req_3: decidedRefusal,
351+
req_4: markedRefusal, req_5: decidedRefusal,
352+
});
353+
await waitFor(() => expect(toasts.error).toHaveBeenCalledTimes(1));
354+
const [title, options] = toasts.error.mock.calls[0] as [string, Record<string, any>];
355+
expect(title).toBe('1 succeeded, 5 failed');
356+
// The toast lists the first three, each with its reason …
357+
expect(options.description).toBe([
358+
`Bulk Invoice 1: ${MARKED}`,
359+
`Bulk Invoice 2: ${ALREADY_DECIDED}`,
360+
`Bulk Invoice 3: ${ALREADY_DECIDED}`,
361+
].join('\n'));
362+
expect(options.action.label).toBe('Show all (5)');
363+
// The toast stays until dismissed, so its action cannot time out.
364+
expect(options.duration).toBe(Infinity);
365+
act(() => options.action.onClick());
366+
const list = await screen.findByTestId('approvals-bulk-failures');
367+
const items = within(list).getAllByRole('listitem');
368+
expect(items).toHaveLength(5);
369+
const expected: Array<[string, string]> = [
370+
['Bulk Invoice 1', MARKED], ['Bulk Invoice 2', ALREADY_DECIDED], ['Bulk Invoice 3', ALREADY_DECIDED],
371+
['Bulk Invoice 4', MARKED], ['Bulk Invoice 5', ALREADY_DECIDED],
372+
];
373+
for (const [title, reason] of expected) {
374+
const item = items.find(li => li.textContent?.startsWith(title));
375+
expect(item, title).toBeDefined();
376+
expect(item).toHaveTextContent(reason);
377+
}
378+
expect(within(list).queryByText('Bulk Invoice 6')).toBeNull();
379+
});
380+
381+
it("a toast's \"Show all\" opens its own run's rows, not a later run's", async () => {
382+
const runBulk = await renderRows(6);
383+
await runBulk({
384+
req_1: markedRefusal, req_2: decidedRefusal, req_3: decidedRefusal,
385+
req_4: markedRefusal, req_5: decidedRefusal,
386+
});
387+
await waitFor(() => expect(toasts.error).toHaveBeenCalledTimes(1));
388+
const first = toasts.error.mock.calls[0][1] as Record<string, any>;
389+
expect(first.action.label).toBe('Show all (5)');
390+
// A second, clean run while the first toast is still up.
391+
await runBulk({});
392+
await waitFor(() => expect(toasts.success).toHaveBeenCalledTimes(1));
393+
act(() => first.action.onClick());
394+
const dialog = await screen.findByRole('alertdialog');
395+
expect(within(dialog).getByText('Not decided: 5')).toBeInTheDocument();
396+
const items = within(within(dialog).getByTestId('approvals-bulk-failures')).getAllByRole('listitem');
397+
expect(items.map(li => li.firstElementChild?.textContent)).toEqual([
398+
'Bulk Invoice 1', 'Bulk Invoice 2', 'Bulk Invoice 3', 'Bulk Invoice 4', 'Bulk Invoice 5',
399+
]);
400+
});
401+
});

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

Lines changed: 94 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ type TabKey = InboxUrlState['tab'];
116116
/** Server page size for the paginated tabs (submitted / all). */
117117
const PAGE_SIZE = 50;
118118

119+
/** One row a bulk approve / reject could not decide, and the refusal's reason. */
120+
interface BulkFailure {
121+
id: string;
122+
title: string;
123+
reason: string;
124+
}
125+
126+
/**
127+
* How many failed rows a bulk run's toast lists before the rest move behind
128+
* its "Show all" action (the dialog lists every one).
129+
*/
130+
const BULK_FAILURES_IN_TOAST = 3;
131+
119132
/**
120133
* Semantic status colors (green = approved, amber = waiting, red = rejected,
121134
* slate = recalled, violet = returned for revision) — variant-based Badge
@@ -1093,6 +1106,23 @@ function ApprovalsQueue() {
10931106
// Bulk selection (only meaningful on "pending" tab where the user can act)
10941107
const [selectedRowIds, setSelectedRowIds] = useState<Set<string>>(new Set());
10951108
const [bulkRunning, setBulkRunning] = useState(false);
1109+
/**
1110+
* The failed rows the "Show all" dialog lists, each with the refusal's
1111+
* reason. A toast carries the first few; its "Show all" action puts ITS OWN
1112+
* run's list here and opens the dialog, so a toast still on screen after a
1113+
* later run never shows that later run's rows (or an empty list).
1114+
*/
1115+
const [bulkFailures, setBulkFailures] = useState<BulkFailure[]>([]);
1116+
const [bulkFailuresOpen, setBulkFailuresOpen] = useState(false);
1117+
/**
1118+
* The partial-failure toasts this page raised and has not seen dismissed.
1119+
* They stay until dismissed, and their action opens this page's dialog, so
1120+
* they leave with the page.
1121+
*/
1122+
const bulkFailureToasts = useRef(new Set<string | number>());
1123+
useEffect(() => () => {
1124+
for (const id of bulkFailureToasts.current) toast.dismiss(id);
1125+
}, []);
10961126

10971127
// Inline decision confirmations (row-level quick action / mobile card /
10981128
// keyboard). BOTH decisions confirm before executing (#2762 P0-2): the
@@ -1473,16 +1503,23 @@ function ApprovalsQueue() {
14731503
if (targets.length === 0) return;
14741504
setBulkRunning(true);
14751505
let ok = 0;
1476-
const failures: string[] = [];
1506+
const failures: BulkFailure[] = [];
14771507
for (const r of targets) {
14781508
const pending = new Set(r.pending_approvers || []);
14791509
const actor = identities.find(i => pending.has(i)) || user?.id || '';
14801510
try {
14811511
const fn = kind === 'approve' ? approvalsApi.approve : approvalsApi.reject;
14821512
await fn(r.id, { actor_id: actor, ...decisionComment(comment) });
14831513
ok++;
1484-
} catch {
1485-
failures.push(r.record_title || formatIdentity(r.record_id));
1514+
} catch (err: any) {
1515+
// Each failure keeps its refusal's own text, read the way the
1516+
// single-row Approve reads it (`userMessage` first, else the page's
1517+
// generic line) — a bare title says which row, never why.
1518+
failures.push({
1519+
id: r.id,
1520+
title: r.record_title || formatIdentity(r.record_id),
1521+
reason: humanizeError(err, tr('actionFailed', 'Action failed')),
1522+
});
14861523
}
14871524
}
14881525
setBulkRunning(false);
@@ -1492,14 +1529,37 @@ function ApprovalsQueue() {
14921529
? tr('bulkApproved', 'Approved {{count}} requests', { count: ok })
14931530
: tr('bulkRejected', 'Rejected {{count}} requests', { count: ok }));
14941531
} else {
1495-
const shown = failures.slice(0, 3).join(', ');
1496-
toast.error(tr('bulkPartial', '{{ok}} succeeded, {{fail}} failed: {{which}}', {
1497-
ok, fail: failures.length, which: shown + (failures.length > 3 ? '…' : ''),
1498-
}));
1532+
const lines = failures.slice(0, BULK_FAILURES_IN_TOAST).map(f =>
1533+
tr('bulkFailureLine', '{{title}}: {{reason}}', { title: f.title, reason: f.reason }));
1534+
const overflow = failures.length > BULK_FAILURES_IN_TOAST;
1535+
// The toast stays until dismissed: a row per line with its reason is
1536+
// more than a few seconds' reading, and the overflow's "Show all" must
1537+
// not time out.
1538+
const toastId = toast.error(tr('bulkPartialSummary', '{{ok}} succeeded, {{fail}} failed', { ok, fail: failures.length }), {
1539+
description: lines.join('\n'),
1540+
classNames: { description: 'whitespace-pre-line' },
1541+
duration: Infinity,
1542+
closeButton: true,
1543+
onDismiss: () => { bulkFailureToasts.current.delete(toastId); },
1544+
// More failures than the toast shows: the rest are one click away.
1545+
// The action closes over THIS run's list, never the page's latest.
1546+
...(overflow
1547+
? {
1548+
action: {
1549+
label: tr('bulkFailuresShowAll', 'Show all ({{n}})', { n: failures.length }),
1550+
onClick: () => {
1551+
setBulkFailures(failures);
1552+
setBulkFailuresOpen(true);
1553+
},
1554+
},
1555+
}
1556+
: {}),
1557+
});
1558+
if (toastId != null) bulkFailureToasts.current.add(toastId);
14991559
}
15001560
void load();
15011561
refreshBadge();
1502-
}, [actionableSelectedRows, identities, user?.id, load, refreshBadge, tr]);
1562+
}, [actionableSelectedRows, identities, user?.id, load, refreshBadge, humanizeError, tr]);
15031563

15041564
/** Confirmed row-level approve (from the shared dialog). */
15051565
const inlineApprove = useCallback(async (r: ApprovalRequestRow) => {
@@ -2063,6 +2123,32 @@ function ApprovalsQueue() {
20632123
</div>
20642124
)}
20652125

2126+
{/* Every failed row of the last bulk run, with its reason — the
2127+
toast's "Show all" opens it when the failures overflow the toast. */}
2128+
<AlertDialog open={bulkFailuresOpen} onOpenChange={setBulkFailuresOpen}>
2129+
<AlertDialogContent>
2130+
<AlertDialogHeader>
2131+
<AlertDialogTitle>
2132+
{tr('bulkFailuresTitle', 'Not decided: {{n}}', { n: bulkFailures.length })}
2133+
</AlertDialogTitle>
2134+
<AlertDialogDescription>
2135+
{tr('bulkFailuresBody', 'These requests were left as they were. Each one says why.')}
2136+
</AlertDialogDescription>
2137+
</AlertDialogHeader>
2138+
<ul data-testid="approvals-bulk-failures" className="max-h-[50vh] overflow-y-auto space-y-2 text-sm">
2139+
{bulkFailures.map(f => (
2140+
<li key={f.id}>
2141+
<span className="font-medium">{f.title}</span>
2142+
<span className="block text-muted-foreground">{f.reason}</span>
2143+
</li>
2144+
))}
2145+
</ul>
2146+
<AlertDialogFooter>
2147+
<AlertDialogCancel>{tr('close', 'Close')}</AlertDialogCancel>
2148+
</AlertDialogFooter>
2149+
</AlertDialogContent>
2150+
</AlertDialog>
2151+
20662152
{loading ? (
20672153
<div className="space-y-2">
20682154
<Skeleton className="h-10 w-full" />

‎ui/packages/i18n/src/__tests__/untranslated-identity-4376.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ const LEGITIMATE_IDENTITIES: Record<string, string> = {
154154
'collaboration.userStatusTitle': '{{name}} ({{status}}) — holes and parentheses only.',
155155
'chatbot.build.nextStepQuote': '“{{step}}” — a hole in quote marks; ko quotes with the same curly marks as en (objectui#12724).',
156156
'console.assignedWork.row': '{{object}} · {{field}} — two holes and a middle dot, no prose (objectstack#30205).',
157+
'approvalsInbox.bulkFailureLine': '{{title}}: {{reason}} — holes and a colon; zh/ja set a fullwidth colon, ko/ru/ar keep `: `.',
157158
'listConditions.chips.pattern': '{{field}}: {{value}} — holes and a colon; zh/ja set a fullwidth colon, ko/ru/ar keep `: `.',
158159
'console.assignedWork.failure': '{{object}} {{id}}: {{message}} — holes and a colon; zh sets a fullwidth colon, ja/ko/ru/ar keep `: ` (objectstack#30205).',
159160
};

0 commit comments

Comments
 (0)