diff --git a/.changeset/35418-approval-timeline-system-notes.md b/.changeset/35418-approval-timeline-system-notes.md new file mode 100644 index 00000000000..4d3261ba5cb --- /dev/null +++ b/.changeset/35418-approval-timeline-system-notes.md @@ -0,0 +1,17 @@ +--- +'@objectstack/plugin-approvals': patch +'@object-ui/app-shell': patch +'@object-ui/i18n': patch +'@object-ui/console': patch +--- + +fix(approvals): the approval timeline names an unstaffed position by its label, and the platform's own rows read as the system's + +Clause-②: yes (widening) — @objectstack/plugin-approvals adds the optional `ApprovalServiceOptions.positionLabelSource`; @object-ui/i18n adds approvalsInbox.systemActor and approvalsInbox.actSystemNote; nothing removed +Metadata-protocol: none + +When a request goes to the organization's administrators because a position on its approver list has no holder, its timeline note named the position by its machine name ("岗位「crm_sales_manager」无人任职"). The note a reader is served now names it by its label: the reader's language pack (`positions..label`) first, else the position's declared `label`, else the name as before ("岗位「销售经理」无人任职"). The English the row stores for audit keeps the name. + +On the timeline, a row no person took read its actor as "—", and the routing, submitter-exclusion and no-approver notes read as "Commented". A row with no actor now reads its actor as "System", and a `comment` row with no actor reads as "System note". A person's comment keeps "Commented" and its author. + +New locale keys: `approvalsInbox.systemActor` and `approvalsInbox.actSystemNote`, in all eleven packs. diff --git a/content/docs/automation/approvals.mdx b/content/docs/automation/approvals.mdx index 3ca80825f6b..51f95502a7e 100644 --- a/content/docs/automation/approvals.mdx +++ b/content/docs/automation/approvals.mdx @@ -575,7 +575,11 @@ organization's capability, such as its owner, is on the slate for that. The request says why. Its timeline carries a note, for example *Routed to this organization's administrators because the approver slate named no one: position -'sales_manager' has no holder.*, and its node-config snapshot keeps the abandoned +'sales_manager' has no holder.* That English, with the position's name, is what +the row stores; a reader is served the note in their own language, and it names +the position by its label (the language pack's translation, else the position's +declared label), for example *岗位「销售经理」无人任职*. The timeline shows the +note as a system note, by the system. Its node-config snapshot keeps the abandoned slate and the same reason under `__resolvedFrom` (`admin_rescue:abandoned`, `admin_rescue:reason`). The abandoned slate is replaced, not kept beside them: a holder staffed into the position after the request opened does not receive it, diff --git a/packages/plugins/plugin-approvals/src/admin-rescue-named-slate.integration.test.ts b/packages/plugins/plugin-approvals/src/admin-rescue-named-slate.integration.test.ts index 0851f266d24..1c8d1c4ac0f 100644 --- a/packages/plugins/plugin-approvals/src/admin-rescue-named-slate.integration.test.ts +++ b/packages/plugins/plugin-approvals/src/admin-rescue-named-slate.integration.test.ts @@ -475,4 +475,75 @@ describe('an empty admin_rescue slate opens on the organization\'s administrator ]); }); }); + // [#35418] The note names an unheld position by its label, never by its + // machine name: the reader's pack (`positions..label`) first, else the + // position's declared `label`, else the name, as before. + describe('[#35418] the note names an unheld position by its label', () => { + let labelled: ApprovalService; + const declared: Record = { sales_manager: 'Sales Manager' }; + const noteFor = async (requestId: string, locale?: string) => + (await labelled.listActions(requestId, { ...as('u_sub', ORG), ...(locale ? { locale } : {}) })) + .filter((a) => a.action === 'comment' && !a.actor_id) + .map((a) => a.comment); + + beforeAll(() => { + const i18n = createMemoryI18n(); + for (const [locale, data] of Object.entries(ApprovalsTranslations)) { + i18n.loadTranslations(locale, data as Record); + } + // An app's pack, as `AppPlugin` loads it: zh-CN translates the position. + i18n.loadTranslations('zh-CN', { positions: { sales_manager: { label: '销售经理' } } }); + labelled = new ApprovalService({ + engine: engine as any, + clock: { now: () => new Date(now += 1000) }, + logger: { warn: () => {}, info: () => {}, error: () => {}, debug: () => {} } as any, + i18nServiceSource: () => i18n, + positionLabelSource: async (name) => declared[name], + }); + }); + + it('a zh-CN reader reads the translated label, and never the machine name', async () => { + const row = await open('label_zh', UNSTAFFED); + const [comment] = await noteFor(row.id, 'zh-CN'); + expect(comment).toBe('审批人名单未指向任何人,因此已转交本组织管理员处理:岗位「销售经理」无人任职。'); + expect(comment).not.toContain('sales_manager'); + }); + + it('a reader whose pack holds no translation reads the declared label', async () => { + const row = await open('label_en', UNSTAFFED); + expect(await noteFor(row.id, 'en')).toEqual([ + "Routed to this organization's administrators because the approver slate named no one: " + + "position 'Sales Manager' has no holder.", + ]); + expect((await noteFor(row.id, 'ja-JP'))[0]).toContain('役職「Sales Manager」'); + }); + + it('CONTROL: the stored row keeps the name, and a reader with no locale is served it', async () => { + const row = await open('label_stored', UNSTAFFED); + const ENGLISH = "Routed to this organization's administrators because the approver slate named no one: " + + "position 'sales_manager' has no holder."; + expect((await actionsOf(row.id)).find((a) => a.action === 'comment')?.comment).toBe(ENGLISH); + expect(await noteFor(row.id)).toEqual([ENGLISH]); + }); + + it('a position no pack and no declaration knows keeps its name, and a failing source does not fail the read', async () => { + const row = await open('label_unknown', UNSTAFFED); + const bare = new ApprovalService({ + engine: engine as any, + clock: { now: () => new Date(now += 1000) }, + logger: { warn: () => {}, info: () => {}, error: () => {}, debug: () => {} } as any, + i18nServiceSource: () => { + const i18n = createMemoryI18n(); + for (const [locale, data] of Object.entries(ApprovalsTranslations)) { + i18n.loadTranslations(locale, data as Record); + } + return i18n; + }, + positionLabelSource: async () => { throw new Error('metadata exploded'); }, + }); + const served = (await bare.listActions(row.id, { ...as('u_sub', ORG), locale: 'zh-CN' })) + .filter((a) => a.action === 'comment' && !a.actor_id); + expect(served.map((a) => a.comment)).toEqual(['审批人名单未指向任何人,因此已转交本组织管理员处理:岗位「sales_manager」无人任职。']); + }); + }); }); diff --git a/packages/plugins/plugin-approvals/src/admin-rescue-note.test.ts b/packages/plugins/plugin-approvals/src/admin-rescue-note.test.ts index a056145af62..9f5599f3fff 100644 --- a/packages/plugins/plugin-approvals/src/admin-rescue-note.test.ts +++ b/packages/plugins/plugin-approvals/src/admin-rescue-note.test.ts @@ -8,7 +8,9 @@ */ import { describe, it, expect } from 'vitest'; -import { adminRescueNoteOf, adminRescueNoteText, adminRescueReason, type ApprovalSentenceRender } from './admin-rescue-note.js'; +import { + adminRescueNoteOf, adminRescueNoteText, adminRescuePositions, adminRescueReason, type ApprovalSentenceRender, +} from './admin-rescue-note.js'; import { approvalMessages } from './translations/messages.js'; /** A render over one shipped locale of the catalog, `{{hole}}` filled the `t()` way. */ @@ -48,6 +50,22 @@ describe('[#25576] the admin_rescue note', () => { expect(adminRescueNoteText(note, renderIn('zh-CN', ['approvalAdminRescueNote']))).toBeUndefined(); }); + it('[#35418] names an unheld position by the label the reader is given, and only a position', () => { + const note = { abandoned: ['position:crm_sales_manager', 'position:crm_sales_director', 'team:crm_sales_manager'] }; + const label = (name: string) => (name === 'crm_sales_manager' ? '销售经理' : undefined); + expect(adminRescueNoteText(note, renderIn('zh-CN'), label)).toBe( + '审批人名单未指向任何人,因此已转交本组织管理员处理:岗位「销售经理」无人任职;' + + '岗位「crm_sales_director」无人任职;team「crm_sales_manager」未解析到任何人。', + ); + // A clause the pack lacks falls back to its English, labelled the same way. + expect(adminRescueNoteText({ abandoned: ['position:crm_sales_manager'] }, renderIn('zh-CN', ['approvalAdminRescuePositionUnheld']), label)) + .toBe("审批人名单未指向任何人,因此已转交本组织管理员处理:position '销售经理' has no holder。"); + // The stored English keeps the name. + expect(adminRescueNoteText(note)).toContain("position 'crm_sales_manager' has no holder"); + expect(adminRescuePositions({ abandoned: ['position:a', 'team:b', 'position:a', 'position:', 'u_1', 'position:c'] })) + .toEqual(['a', 'c']); + }); + it('reads only the shape it writes', () => { const good = { action_id: 'aact_1', abandoned: ['position:p'], fallback: 'not_declared' }; expect(adminRescueNoteOf({ __adminRescueNote: good })).toEqual(good); diff --git a/packages/plugins/plugin-approvals/src/admin-rescue-note.ts b/packages/plugins/plugin-approvals/src/admin-rescue-note.ts index 510a2afca78..e11c9296988 100644 --- a/packages/plugins/plugin-approvals/src/admin-rescue-note.ts +++ b/packages/plugins/plugin-approvals/src/admin-rescue-note.ts @@ -120,19 +120,32 @@ export function adminRescueReason( .map(english).join(enMessages.approvalAdminRescueReasonSeparator); } +/** + * [#35418] A position's display label for the reader, or `undefined` when none + * is known (the position's name then stands). + */ +export type PositionLabelOf = (positionName: string) => string | undefined; + /** * The note's text. With no `render`, the English the row stores; with one, * the reader's language, or `undefined` when the note sentence itself is not * rendered (the stored comment then stands). + * + * [#35418] With `positionLabel` too, an unheld position is named by the label + * it answers (`岗位「销售经理」无人任职`), never by its machine name + * (`crm_sales_manager`), wherever one is known. The stored English keeps the + * name: it is the audit text, and it identifies the position exactly. */ export function adminRescueNoteText(note: Omit): string; export function adminRescueNoteText( note: Omit, render: ApprovalSentenceRender, + positionLabel?: PositionLabelOf, ): string | undefined; export function adminRescueNoteText( note: Omit, render?: ApprovalSentenceRender, + positionLabel?: PositionLabelOf, ): string | undefined { const clauses = reasonClauses(note.abandoned, note.fallback, note.submitter_excluded); if (!render) { @@ -142,11 +155,30 @@ export function adminRescueNoteText( const separator = render(approvalMessageKey('approvalAdminRescueReasonSeparator'), {}) ?? enMessages.approvalAdminRescueReasonSeparator; const reason = clauses + .map((clause) => labelledPosition(clause, positionLabel)) .map((clause) => render(approvalMessageKey(clause.id), clause.params) ?? english(clause)) .join(separator); return render(approvalMessageKey('approvalAdminRescueNote'), { reason }); } +/** An unheld position's clause, its `value` the position's label where `positionLabel` knows one. */ +function labelledPosition(clause: Clause, positionLabel: PositionLabelOf | undefined): Clause { + if (clause.id !== 'approvalAdminRescuePositionUnheld' || !positionLabel) return clause; + const label = positionLabel(clause.params.value); + return label ? { ...clause, params: { ...clause.params, value: label } } : clause; +} + +/** The position names an admin_rescue note's abandoned slate holds, each once. */ +export function adminRescuePositions(note: Pick): string[] { + const names = new Set(); + for (const slot of note.abandoned) { + if (typeof slot === 'string' && slot.startsWith('position:') && slot.length > 'position:'.length) { + names.add(slot.slice('position:'.length)); + } + } + return [...names]; +} + /** * The note a parsed node-config snapshot carries, or `undefined` when it * carries none or one this module did not write (the stored comment stands). diff --git a/packages/plugins/plugin-approvals/src/approval-service.ts b/packages/plugins/plugin-approvals/src/approval-service.ts index f1d462d9861..8a910e24348 100644 --- a/packages/plugins/plugin-approvals/src/approval-service.ts +++ b/packages/plugins/plugin-approvals/src/approval-service.ts @@ -127,6 +127,7 @@ import { ADMIN_RESCUE_NOTE_SNAPSHOT_KEY, adminRescueNoteOf, adminRescueNoteText, + adminRescuePositions, adminRescueReason, type AdminRescueNote, } from './admin-rescue-note.js'; @@ -2074,6 +2075,17 @@ export interface ApprovalServiceOptions { * authored text the request snapshotted when it opened. */ i18nServiceSource?: () => ReaderLabelI18n | undefined; + /** + * [#35418] A position's declared `label`, by its name: what a timeline note + * names an unheld position by when the reader's language pack holds no + * `positions..label`. The plugin answers it from the `metadata` + * service (`get('position', name)`), read per call for the reason + * {@link ApprovalServiceOptions.i18nServiceSource} is. + * + * Absent, or answering `undefined`, the note names the position by its + * name, as before. + */ + positionLabelSource?: (positionName: string) => Promise; /** * [ADR-0142 D6] The `ownership-queue` service, through which a `queue` * approver expands to the queue's members at node entry. Resolved LAZILY @@ -2211,6 +2223,8 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega private readonly platformAdminStandings = new WeakMap>>(); /** [#24863] Lazily-resolved `i18n` service for the reader-locale display labels. */ private i18nServiceSource?: () => ReaderLabelI18n | undefined; + /** [#35418] A position's declared label, for a note that names an unheld position. */ + private positionLabelSource?: (positionName: string) => Promise; /** [ADR-0142 D6] Lazily-resolved `ownership-queue` service a `queue` approver expands through. */ private ownershipQueues?: () => ApproverQueueSource | undefined; /** [ADR-0157 D5] Lazily-resolved working-calendar service a `working_time` escalation counts through. */ @@ -2255,6 +2269,7 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega this.fieldVisibility = opts.fieldVisibility; this.messageTranslator = opts.messageTranslator; this.i18nServiceSource = opts.i18nServiceSource; + this.positionLabelSource = opts.positionLabelSource; this.ownershipQueues = opts.ownershipQueues; this.workCalendar = opts.workCalendar; this.recordReaderVisibleObjects = new Set( @@ -11346,13 +11361,41 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega if (row && text) row.comment = text; }; const rescue = adminRescueNoteOf(snapshot); - if (rescue) overlay(rescue.action_id, () => adminRescueNoteText(rescue, labels.sentence)); + if (rescue) { + const positionLabels = await this.notePositionLabels(adminRescuePositions(rescue), labels); + overlay(rescue.action_id, () => adminRescueNoteText(rescue, labels.sentence, (name) => positionLabels.get(name))); + } const exclusion = submitterExclusionNoteOf(snapshot); if (exclusion) overlay(exclusion.action_id, () => submitterExclusionNoteText(exclusion, labels.sentence)); const noApprover = noApproverNoteOf(snapshot); if (noApprover) overlay(noApprover.action_id, () => noApproverNoteText(noApprover, labels.sentence)); } + /** + * [#35418] The label a reader reads each of `positions` by: the reader's + * language pack (`positions..label`), else the position's declared + * `label` ({@link ApprovalServiceOptions.positionLabelSource}). A position + * neither answers is left out, and the note names it by its name. Display + * only: a failed read leaves the name standing, never fails the read. + */ + private async notePositionLabels( + positions: readonly string[], + labels: ReaderLabels, + ): Promise> { + const out = new Map(); + for (const name of positions) { + let label = labels.positionLabel(name); + if (!label && this.positionLabelSource) { + try { + const declared = await this.positionLabelSource(name); + if (typeof declared === 'string' && declared.trim()) label = declared; + } catch { /* display-only — the name stands */ } + } + if (label) out.set(name, label); + } + return out; + } + /** * `IFileAccessDelegate` — may this caller download a decision attachment? * (ADR-0104 D3 wave 2; declared by `sys_approval_action.fileAccessDelegate`.) diff --git a/packages/plugins/plugin-approvals/src/approvals-plugin.ts b/packages/plugins/plugin-approvals/src/approvals-plugin.ts index b5bf19aeb45..0778603e9fc 100644 --- a/packages/plugins/plugin-approvals/src/approvals-plugin.ts +++ b/packages/plugins/plugin-approvals/src/approvals-plugin.ts @@ -292,6 +292,18 @@ export class ApprovalsServicePlugin implements Plugin { // object labels in the reader's locale (`reader-locale-labels.ts`). // Without one, the door serves the labels as stored. i18nServiceSource: i18nService, + // [#35418] A position's declared label, for the timeline note that names + // an unheld position when the reader's pack holds no translation of it. + // Resolved LAZILY for the reason the providers above are; absent, the + // note names the position by its name. + positionLabelSource: async (positionName) => { + let metadata: { get?(type: string, name: string): Promise } | undefined; + try { metadata = ctx.getService('metadata'); } catch { return undefined; } + if (typeof metadata?.get !== 'function') return undefined; + const item = await metadata.get('position', positionName); + const label = (item as { label?: unknown } | undefined)?.label; + return typeof label === 'string' && label.trim() ? label : undefined; + }, // [ADR-0142 D6] The queue service a `queue` approver expands through. // Resolved LAZILY for the reason the providers above are: plugin-sharing // registers it and may start after this one. Absent, a queue approver diff --git a/packages/plugins/plugin-approvals/src/reader-locale-labels.test.ts b/packages/plugins/plugin-approvals/src/reader-locale-labels.test.ts index 0fbe2efd1af..3dac6086c58 100644 --- a/packages/plugins/plugin-approvals/src/reader-locale-labels.test.ts +++ b/packages/plugins/plugin-approvals/src/reader-locale-labels.test.ts @@ -28,6 +28,7 @@ import { flowLabelKey, flowNameOfProcess, localizeRequestLabels, + positionLabelKey, readerLabelsFor, type ReaderLabelI18n, } from './reader-locale-labels.js'; @@ -54,6 +55,7 @@ const ZH = { [flowLabelKey('account_approval')]: '客户审批', [approvalStepLabelKey('account_approval', 'manager_review')]: '经理审核', [objectLabelKey('account')]: '客户', + [positionLabelKey('crm_sales_manager')]: '销售经理', }; describe('[#24863] every key the reader asks is one the translation contract declares', () => { @@ -62,6 +64,7 @@ describe('[#24863] every key the reader asks is one the translation contract dec expect(approvalStepLabelKey('account_approval', 'manager_review')) .toBe('flows.account_approval.approvals.manager_review.label'); expect(objectLabelKey('account')).toBe('objects.account.label'); + expect(positionLabelKey('crm_sales_manager')).toBe('positions.crm_sales_manager.label'); }); it('a pack holding exactly those keys parses, and keeps each value at its address', () => { @@ -70,6 +73,7 @@ describe('[#24863] every key the reader asks is one the translation contract dec expect(result.data.flows.account_approval.label).toBe('客户审批'); expect(result.data.flows.account_approval.approvals.manager_review.label).toBe('经理审核'); expect(result.data.objects.account.label).toBe('客户'); + expect(result.data.positions.crm_sales_manager.label).toBe('销售经理'); }); it('control: the same round trip refuses a step key the face does not declare', () => { @@ -98,6 +102,7 @@ describe('[#24863] the pick', () => { expect(labels.flowLabel('account_approval')).toBe('客户审批'); expect(labels.stepLabel('account_approval', 'manager_review')).toBe('经理审核'); expect(labels.objectLabel('account')).toBe('客户'); + expect(labels.positionLabel('crm_sales_manager')).toBe('销售经理'); } }); diff --git a/packages/plugins/plugin-approvals/src/reader-locale-labels.ts b/packages/plugins/plugin-approvals/src/reader-locale-labels.ts index 71a2735c934..bb06321c133 100644 --- a/packages/plugins/plugin-approvals/src/reader-locale-labels.ts +++ b/packages/plugins/plugin-approvals/src/reader-locale-labels.ts @@ -41,7 +41,10 @@ * - the flow: `flows..label`, the `flows` face's own `label`; * - the step: `flows..approvals..label`, the face's key for an * `approval` node's step label (`translation.zod.ts`, `approvals`); - * - the object: `objects..label` (`objectLabelKey`). + * - the object: `objects..label` (`objectLabelKey`); + * - [#35418] a position: `positions..label`, the security catalog face's + * own `label` (`translation.zod.ts`, `positions`), which `translatePosition` + * overlays on every served `position` document. * * `` is the request's `process_name` without its `flow:` prefix, the * `Flow.name` the engine hands the node (`$flowName`), and `` is its @@ -82,6 +85,11 @@ export function approvalStepLabelKey(flowName: string, nodeId: string): string { return `flows.${flowName}.approvals.${nodeId}.label`; } +/** [#35418] The security catalog face's position label, `positions..label`. */ +export function positionLabelKey(positionName: string): string { + return `positions.${positionName}.label`; +} + /** * The flow a request's `process_name` names: `flow:account_approval` → * `account_approval`. `undefined` for anything without the prefix, or with @@ -98,6 +106,8 @@ export interface ReaderLabels { flowLabel(flowName: string): string | undefined; stepLabel(flowName: string, nodeId: string): string | undefined; objectLabel(objectName: string): string | undefined; + /** [#35418] A position's label, `positions..label`. */ + positionLabel(positionName: string): string | undefined; /** * [#25576] A catalog sentence (`messages.`) rendered with `params`, by * the same `t()` and the same negotiated locale. Not memoised: the params @@ -181,6 +191,7 @@ export function readerLabelsFor( flowLabel: (flowName) => pick(flowLabelKey(flowName)), stepLabel: (flowName, nodeId) => pick(approvalStepLabelKey(flowName, nodeId)), objectLabel: (objectName) => pick(objectLabelKey(objectName)), + positionLabel: (positionName) => pick(positionLabelKey(positionName)), sentence: (key, params) => render(key, params), }; } diff --git a/ui/packages/app-shell/src/utils/approvalSystemNote.ts b/ui/packages/app-shell/src/utils/approvalSystemNote.ts new file mode 100644 index 00000000000..a282ebed381 --- /dev/null +++ b/ui/packages/app-shell/src/utils/approvalSystemNote.ts @@ -0,0 +1,21 @@ +/** + * 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. + */ + +import type { ApprovalActionLite } from '../hooks/useRecordApprovals.js'; + +/** + * A note the platform wrote on the timeline, not a person's comment: a + * `comment` row with no actor. The server records no person on the rows no + * person took (ADR-0118 D1): the note on why a request went to the + * organization's administrators, that the submitter was left off the slate, + * or that no one can approve it yet. Any person's comment carries its author, + * so it never reads as one (objectstack#35418). + */ +export function isSystemNote(a: Pick): boolean { + return a.action === 'comment' && !a.actor_id; +} diff --git a/ui/packages/app-shell/src/views/approval-progress/ApprovalActionTimeline.systemNote-35418.test.tsx b/ui/packages/app-shell/src/views/approval-progress/ApprovalActionTimeline.systemNote-35418.test.tsx new file mode 100644 index 00000000000..d8260990f98 --- /dev/null +++ b/ui/packages/app-shell/src/views/approval-progress/ApprovalActionTimeline.systemNote-35418.test.tsx @@ -0,0 +1,95 @@ +/** + * 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. + */ + +/** + * objectstack#35418 — a row no person took reads as the platform's, not as + * a comment by "—". + * + * The server records no actor on the rows the platform writes (ADR-0118 D1): + * the note on why a request went to the organization's administrators, the + * submitter-exclusion and no-approver notes, an auto-cancel. The timeline + * drew the first three as "Commented · —". Now the actor reads "System", and + * a `comment` row with no actor reads "System note". A person's comment, with + * its author, keeps "Commented" (the live control in the same DOM). + */ + +import * as React from 'react'; +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { render, screen, cleanup } from '@testing-library/react'; +import { I18nProvider } from '@object-ui/i18n'; +import type { ApprovalActionLite } from '../../hooks/useRecordApprovals'; + +vi.mock('@object-ui/auth', async (importOriginal) => ({ + ...(await importOriginal>()), + createAuthenticatedFetch: () => vi.fn(), +})); +vi.mock('sonner', () => ({ + toast: Object.assign(vi.fn(), { success: vi.fn(), error: vi.fn() }), +})); + +import { ApprovalActionTimeline } from './ApprovalActionTimeline'; +import { isSystemNote } from '../../utils/approvalSystemNote'; + +afterEach(cleanup); + +const ACTIONS: ApprovalActionLite[] = [ + { id: 'a1', request_id: 'r1', action: 'submit', actor_id: 'u_amy', actor_name: 'Amy', created_at: '2026-11-19T08:00:00Z' }, + { + id: 'a2', request_id: 'r1', action: 'comment', actor_id: null, + comment: '审批人名单未指向任何人,因此已转交本组织管理员处理:岗位「销售经理」无人任职。', + created_at: '2026-11-19T08:00:00Z', + }, + { id: 'a3', request_id: 'r1', action: 'comment', actor_id: 'u_bob', actor_name: 'Bob', comment: 'Looks fine', created_at: '2026-11-19T09:00:00Z' }, + { id: 'a4', request_id: 'r1', action: 'cancel', actor_id: null, created_at: '2026-11-19T10:00:00Z' }, +]; + +function renderIn(language: string) { + return render( + + + , + ); +} + +/** The heading line of row `index`, as one string. */ +function line(index: number): string { + const rows = screen.getAllByRole('listitem'); + expect(rows).toHaveLength(ACTIONS.length); + return (rows[index].querySelector('div')?.textContent ?? '').replace(/\s+/g, ' '); +} + +describe('objectstack#35418 — the platform\'s rows on the approval timeline', () => { + it('a comment row with no actor is a system note; a person\'s comment stays a comment', () => { + expect(isSystemNote({ action: 'comment', actor_id: null })).toBe(true); + expect(isSystemNote({ action: 'comment', actor_id: undefined })).toBe(true); + expect(isSystemNote({ action: 'comment', actor_id: 'u_bob' })).toBe(false); + expect(isSystemNote({ action: 'cancel', actor_id: null })).toBe(false); + }); + + it('English: "System note · System", and a person\'s comment keeps "Commented · Bob"', () => { + renderIn('en'); + expect(line(1)).toContain('System note'); + expect(line(1)).toContain('System'); + expect(line(1)).not.toContain('Commented'); + expect(line(1)).not.toContain('—'); + expect(line(2)).toContain('Commented'); + expect(line(2)).toContain('Bob'); + // Any row no person took names the system as its actor, not "—". + expect(line(3)).toContain('System'); + expect(line(3)).not.toContain('—'); + }); + + it('zh-CN: 「系统说明 · 系统」,不写「评论」;本人评论仍是「评论 · Bob」', () => { + renderIn('zh'); + expect(line(1)).toContain('系统说明'); + expect(line(1)).toContain('系统'); + expect(line(1)).not.toContain('评论'); + expect(line(2)).toContain('评论'); + expect(line(2)).toContain('Bob'); + }); +}); diff --git a/ui/packages/app-shell/src/views/approval-progress/ApprovalActionTimeline.tsx b/ui/packages/app-shell/src/views/approval-progress/ApprovalActionTimeline.tsx index 51025c57efa..0b8a5bba958 100644 --- a/ui/packages/app-shell/src/views/approval-progress/ApprovalActionTimeline.tsx +++ b/ui/packages/app-shell/src/views/approval-progress/ApprovalActionTimeline.tsx @@ -31,6 +31,7 @@ import { useObjectTranslation } from '@object-ui/react'; import { Loader2, Paperclip, ShieldAlert } from 'lucide-react'; import type { ApprovalActionAttachmentLite, ApprovalActionLite } from '../../hooks/useRecordApprovals.js'; import { isViaOverrideRow } from '../../utils/approvalOverride.js'; +import { isSystemNote } from '../../utils/approvalSystemNote.js'; import { formatIdentity } from '../../utils/approverIdentity.js'; /** Timeline dot color per action kind — same palette as the Approval Center. */ @@ -100,7 +101,8 @@ export function ApprovalActionTimeline({ actions, loading = false, stepText }: A }, [authFetch, tr]); const actionText = (a: ApprovalActionLite): string => - a.action === 'submit' ? tr('actSubmit', 'Submitted') + isSystemNote(a) ? tr('actSystemNote', 'System note') + : a.action === 'submit' ? tr('actSubmit', 'Submitted') : a.action === 'approve' ? tr('actApprove', 'Approved') : a.action === 'reject' ? tr('actReject', 'Rejected') : a.action === 'recall' ? tr('actRecall', 'Recalled') @@ -116,7 +118,9 @@ export function ApprovalActionTimeline({ actions, loading = false, stepText }: A const actorName = (a: ApprovalActionLite): string => a.actor_id === 'system:sla' ? tr('systemSlaActor', 'System (SLA)') - : a.actor_name ?? formatIdentity(a.actor_id); + : !a.actor_id + ? tr('systemActor', 'System') + : a.actor_name ?? formatIdentity(a.actor_id); const actionStepText = (a: ApprovalActionLite): string | null => stepText?.(a) ?? null; diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index a8662a39b50..5d3641e1abd 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -4911,6 +4911,7 @@ const ar = { loadedOf: 'تم تحميل {{loaded}} من {{total}}', actEscalate: 'تصعيد SLA', systemSlaActor: 'النظام (SLA)', + systemActor: 'النظام', reassignBtn: 'إعادة إسناد', reassignTitle: 'تسليم هذه الموافقة لشخص آخر؟', reassignBody: 'ينتقل مقعدك كموافق إلى الشخص المختار — يتم إخطاره ويمكنه التصرف فورًا.', @@ -4943,6 +4944,7 @@ const ar = { actRemind: 'تذكير', actRequestInfo: 'طلب معلومات', actComment: 'تعليق', + actSystemNote: 'ملاحظة من النظام', stepProgress: 'خطوات الموافقة', prevRequest: 'السابق', nextRequest: 'التالي', diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index c28730afb03..3be3c0eede9 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -4497,6 +4497,7 @@ const de = { loadedOf: '{{loaded}} von {{total}} geladen', actEscalate: 'SLA eskaliert', systemSlaActor: 'System (SLA)', + systemActor: 'System', reassignBtn: 'Übergeben', reassignTitle: 'Diese Genehmigung an jemand anderen übergeben?', reassignBody: 'Ihr Genehmiger-Platz geht an die gewählte Person — sie wird benachrichtigt und kann sofort handeln.', @@ -4525,6 +4526,7 @@ const de = { actRemind: 'Erinnert', actRequestInfo: 'Rückfrage gestellt', actComment: 'Kommentiert', + actSystemNote: 'Systemhinweis', stepProgress: 'Genehmigungsschritte', prevRequest: 'Zurück', nextRequest: 'Weiter', diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index eb9bc691952..822655e7556 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -5450,6 +5450,7 @@ const en = { loadedOf: 'Loaded {{loaded}} of {{total}}', actEscalate: 'SLA escalated', systemSlaActor: 'System (SLA)', + systemActor: 'System', reassignBtn: 'Reassign', reassignTitle: 'Hand this approval to someone else?', reassignBody: 'Your approver slot moves to the person you pick — they are notified and can act immediately.', @@ -5478,6 +5479,7 @@ const en = { actRemind: 'Reminder sent', actRequestInfo: 'Requested more info', actComment: 'Commented', + actSystemNote: 'System note', stepProgress: 'Approval steps', prevRequest: 'Previous', nextRequest: 'Next', diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index 9c4f0fea8ed..fa05cbd846e 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -4601,6 +4601,7 @@ const es = { loadedOf: '{{loaded}} de {{total}} cargadas', actEscalate: 'SLA escalado', systemSlaActor: 'Sistema (SLA)', + systemActor: 'Sistema', reassignBtn: 'Reasignar', reassignTitle: '¿Pasar esta aprobación a otra persona?', reassignBody: 'Tu puesto de aprobador pasa a la persona elegida; se le notifica y puede actuar de inmediato.', @@ -4630,6 +4631,7 @@ const es = { actRemind: 'Recordatorio', actRequestInfo: 'Pidió más información', actComment: 'Comentó', + actSystemNote: 'Nota del sistema', stepProgress: 'Pasos de aprobación', prevRequest: 'Anterior', nextRequest: 'Siguiente', diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index 194ec44f701..ddd1c2e7b62 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -4597,6 +4597,7 @@ const fr = { loadedOf: '{{loaded}} sur {{total}} chargées', actEscalate: 'SLA escaladé', systemSlaActor: 'Système (SLA)', + systemActor: 'Système', reassignBtn: 'Réattribuer', reassignTitle: 'Confier cette approbation à quelqu\'un d\'autre ?', reassignBody: 'Votre place d\'approbateur passe à la personne choisie — elle est notifiée et peut agir immédiatement.', @@ -4626,6 +4627,7 @@ const fr = { actRemind: 'Relance', actRequestInfo: 'Infos demandées', actComment: 'Commentaire', + actSystemNote: 'Note du système', stepProgress: 'Étapes d\'approbation', prevRequest: 'Précédente', nextRequest: 'Suivante', diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index 77546734323..5c60d1dedae 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -4499,6 +4499,7 @@ const ja = { loadedOf: '{{total}} 件中 {{loaded}} 件を表示', actEscalate: 'SLAエスカレーション', systemSlaActor: 'システム(SLA)', + systemActor: 'システム', reassignBtn: '引き継ぎ', reassignTitle: 'この承認を他の人に引き継ぎますか?', reassignBody: 'あなたの承認枠は選択した相手に移ります。相手に通知され、すぐに対応できます。', @@ -4527,6 +4528,7 @@ const ja = { actRemind: 'リマインド', actRequestInfo: '追加情報を要求', actComment: 'コメント', + actSystemNote: 'システムからのお知らせ', stepProgress: '承認ステップ', prevRequest: '前へ', nextRequest: '次へ', diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index cf92773dbd9..010c521f83a 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -4496,6 +4496,7 @@ const ko = { loadedOf: '{{total}}개 중 {{loaded}}개 로드됨', actEscalate: 'SLA 에스컬레이션', systemSlaActor: '시스템(SLA)', + systemActor: '시스템', reassignBtn: '재할당', reassignTitle: '이 승인을 다른 사람에게 넘길까요?', reassignBody: '승인 슬롯이 선택한 사람에게 이동하며, 상대는 알림을 받고 즉시 처리할 수 있습니다.', @@ -4524,6 +4525,7 @@ const ko = { actRemind: '독촉', actRequestInfo: '보완 요청', actComment: '댓글', + actSystemNote: '시스템 안내', stepProgress: '승인 단계', prevRequest: '이전', nextRequest: '다음', diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index 2cc6ae0e496..bac211c2e89 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -4596,6 +4596,7 @@ const pt = { loadedOf: '{{loaded}} de {{total}} carregadas', actEscalate: 'SLA escalonado', systemSlaActor: 'Sistema (SLA)', + systemActor: 'Sistema', reassignBtn: 'Reatribuir', reassignTitle: 'Passar esta aprovação para outra pessoa?', reassignBody: 'Sua vaga de aprovador passa para a pessoa escolhida — ela é notificada e pode agir imediatamente.', @@ -4625,6 +4626,7 @@ const pt = { actRemind: 'Lembrete', actRequestInfo: 'Pediu mais informações', actComment: 'Comentou', + actSystemNote: 'Nota do sistema', stepProgress: 'Etapas de aprovação', prevRequest: 'Anterior', nextRequest: 'Próxima', diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index 73e8aaa2b9c..32293917b69 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -4714,6 +4714,7 @@ const ru = { loadedOf: 'Загружено {{loaded}} из {{total}}', actEscalate: 'Эскалация SLA', systemSlaActor: 'Система (SLA)', + systemActor: 'Система', reassignBtn: 'Передать', reassignTitle: 'Передать согласование другому?', reassignBody: 'Ваше место согласующего перейдёт выбранному человеку — он получит уведомление и сможет действовать сразу.', @@ -4744,6 +4745,7 @@ const ru = { actRemind: 'Напоминание', actRequestInfo: 'Запрошены данные', actComment: 'Комментарий', + actSystemNote: 'Системное сообщение', stepProgress: 'Шаги согласования', prevRequest: 'Назад', nextRequest: 'Далее', diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index ea8cb5bffb2..9471d21aca4 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -4756,6 +4756,7 @@ const zh = { loadedOf: '已加载 {{loaded}} / 共 {{total}} 条', actEscalate: 'SLA 升级', systemSlaActor: '系统(SLA)', + systemActor: '系统', reassignBtn: '转签', reassignTitle: '将该审批转签给其他人?', reassignBody: '你的审批席位将转移给所选人员,对方会收到通知并可立即处理。', @@ -4784,6 +4785,7 @@ const zh = { actRemind: '催办', actRequestInfo: '要求补充材料', actComment: '评论', + actSystemNote: '系统说明', stepProgress: '审批步骤', prevRequest: '上一条', nextRequest: '下一条', diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index 73654cf2632..ed7bcfbfe8c 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -4756,6 +4756,7 @@ const zhHant = { loadedOf: '已載入 {{loaded}} / 共 {{total}} 條', actEscalate: 'SLA 升級', systemSlaActor: '系統(SLA)', + systemActor: '系統', reassignBtn: '轉籤', reassignTitle: '將該審批轉籤給其他人?', reassignBody: '你的審批席位將轉移給所選人員,對方會收到通知並可立即處理。', @@ -4784,6 +4785,7 @@ const zhHant = { actRemind: '催辦', actRequestInfo: '要求補充材料', actComment: '評論', + actSystemNote: '系統說明', stepProgress: '審批步驟', prevRequest: '上一條', nextRequest: '下一條',