From e486b89fdbbe34f53f3b0162966612eb133da235 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 09:52:47 +0000 Subject: [PATCH 1/5] wip(approvals): name the request page by its record; outline reject; one time face Claude-Session: https://claude.ai/code/session_01L6bhgW5RH2VUXjRj9dZYH2 Co-authored-by: Claude --- .../src/views/DeclaredActionsBar.tsx | 15 +++- .../app-shell/src/views/RecordDetailView.tsx | 4 + .../approvalSubjectTitle.tsx | 78 +++++++++++++++++++ .../ApprovalActionTimeline.tsx | 12 ++- ui/packages/components/src/index.ts | 2 +- .../src/renderers/layout/containers.tsx | 13 +++- .../layout/record-header-bar-context.ts | 21 +++++ 7 files changed, 133 insertions(+), 12 deletions(-) create mode 100644 ui/packages/app-shell/src/views/approval-decision/approvalSubjectTitle.tsx diff --git a/ui/packages/app-shell/src/views/DeclaredActionsBar.tsx b/ui/packages/app-shell/src/views/DeclaredActionsBar.tsx index ad4606cc68a..3b8f4fabb51 100644 --- a/ui/packages/app-shell/src/views/DeclaredActionsBar.tsx +++ b/ui/packages/app-shell/src/views/DeclaredActionsBar.tsx @@ -338,9 +338,16 @@ const DeclaredActionButton: React.FC<{ * header row. */ headerTone?: 'primary' | 'secondary'; + /** + * A declared `danger` lever drawn as an outline button in the destructive + * text colour, the header group's secondary face, instead of a filled one + * (objectstack#35415): beside a filled `primary` decision, the approval + * must read as the page's strongest button, not the rejection. + */ + outlineDanger?: boolean; /** The reject dialog requires its `comment` (`requireRejectReason`). */ requireReason?: boolean; -}> = ({ action, objectName, record, asMenuItem = false, onDrawn, fill = false, headerTone, requireReason = false }) => { +}> = ({ action, objectName, record, asMenuItem = false, onDrawn, fill = false, headerTone, outlineDanger = false, requireReason = false }) => { const { execute } = useAction(); const [loading, setLoading] = useState(false); // Localize the SERVER-DECLARED strings through the `_actions..*` @@ -657,9 +664,10 @@ const DeclaredActionButton: React.FC<{ // one. Overrides take one warning treatment instead, the SAME for approve / // reject / reassign — the point being that it reads as "override", not as // "the decision you were assigned". + const secondaryDanger = declaredVariant === 'danger' && (headerTone === 'secondary' || outlineDanger); const variant = isOverride ? 'outline' - : headerTone === 'secondary' + : headerTone === 'secondary' || secondaryDanger ? 'outline' : declaredVariant === 'primary' ? 'default' @@ -760,7 +768,7 @@ const DeclaredActionButton: React.FC<{ className={cn( headerTone ? 'h-11 sm:h-8' : 'h-11 sm:h-9', fill && (disabledReason ? 'w-full sm:w-auto' : 'flex-1 sm:flex-none'), - headerTone === 'secondary' && declaredVariant === 'danger' && !isOverride + secondaryDanger && !isOverride && 'text-destructive hover:text-destructive', isOverride && 'border-amber-500/60 text-amber-700 hover:bg-amber-50 hover:text-amber-800 dark:text-amber-400 dark:hover:bg-amber-500/10 dark:hover:text-amber-300', @@ -1223,6 +1231,7 @@ const DeclaredActionsToolbar: React.FC< record={record} onDrawn={reportDrawn} fill + outlineDanger /> ))} {decisionOthers.map((action) => (foldDecisionOthers ? ( diff --git a/ui/packages/app-shell/src/views/RecordDetailView.tsx b/ui/packages/app-shell/src/views/RecordDetailView.tsx index 97bb18fe291..ffa7e599ffa 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.tsx @@ -92,6 +92,7 @@ import { RECORD_APPROVAL_EXCLUDED_ACTIONS, } from './recordApprovalActions.js'; import { useApprovalQueueAdvance } from './approval-decision/approvalQueueAdvance.js'; +import { approvalSubjectTitle } from './approval-decision/approvalSubjectTitle.js'; // Side-effect registration of `record:approvals` — synthesized record pages // reference the node whenever the record has approval requests (#3461), so // the type must resolve wherever this view renders, not only under hosts @@ -5542,6 +5543,9 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri // objectstack#35891 — the stage tag is the stage's menu: the default // page draws no stage bar, so the header is where the stage moves. stage: (parts) => , + // objectstack#35415 — an approval request's page is named by the record + // it asks a decision on, linked to it; else by the request's own title. + title: objectName === SYS_APPROVAL_REQUEST_OBJECT ? approvalSubjectTitle(readablePageRecord) : undefined, }; const sharedChrome = ( <> diff --git a/ui/packages/app-shell/src/views/approval-decision/approvalSubjectTitle.tsx b/ui/packages/app-shell/src/views/approval-decision/approvalSubjectTitle.tsx new file mode 100644 index 00000000000..33655229275 --- /dev/null +++ b/ui/packages/app-shell/src/views/approval-decision/approvalSubjectTitle.tsx @@ -0,0 +1,78 @@ +/** + * 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. + */ + +/** + * The approval request page's title: the business record the request is + * about, not the request itself. + * + * A request is a record that stands for another one. Its own declared title is + * the flow's label (`process_label`, the object's `nameField`), which every + * list and search result keeps; on the request's own page an approver reads + * the record they are deciding on, so the page header names it by the title + * the approvals get serves for it (`record_title`) and links to it, the way + * the "As submitted" card's "Open record" link does. + * + * Where the get serves no subject title (one it could not resolve), or serves + * the bare record id, the page keeps the request's own title: the header never + * names the subject by a raw id. + */ + +import * as React from 'react'; +import type { RecordHeaderTitle } from '@object-ui/components'; +import { useRelatedRecordActions } from '@object-ui/react'; + +/** A non-empty string value of `row[key]`, trimmed; `undefined` otherwise. */ +function textOf(row: Record, key: string): string | undefined { + const value = row[key]; + if (typeof value !== 'string') return undefined; + const text = value.trim(); + return text ? text : undefined; +} + +/** + * The subject's name as a link to the subject, through the host's record + * route; the bare name where the host routes to no record of that object. + * A plain left click is the host's in-app navigation; a modifier or middle + * click keeps the anchor's own new-tab behaviour. + */ +function ApprovalSubjectLink({ objectName, recordId, title }: { objectName: string; recordId: string; title: string }) { + const recordLinks = useRelatedRecordActions(); + const href = recordLinks?.recordHref ? recordLinks.recordHref(objectName, recordId) : null; + if (!href) return <>{title}; + return ( + { + if (!recordLinks?.openRecord || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; + event.preventDefault(); + recordLinks.openRecord(objectName, recordId); + }} + > + {title} + + ); +} + +/** + * The header title for an approval request row, or `undefined` to keep the + * request's own title. + */ +export function approvalSubjectTitle(request: unknown): RecordHeaderTitle | undefined { + if (!request || typeof request !== 'object') return undefined; + const row = request as Record; + const title = textOf(row, 'record_title'); + const objectName = textOf(row, 'object_name'); + const recordId = textOf(row, 'record_id'); + if (!title || !objectName || !recordId || title === recordId) return undefined; + return { + text: title, + node: , + }; +} 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 0b8a5bba958..4943b0ad9e4 100644 --- a/ui/packages/app-shell/src/views/approval-progress/ApprovalActionTimeline.tsx +++ b/ui/packages/app-shell/src/views/approval-progress/ApprovalActionTimeline.tsx @@ -25,6 +25,7 @@ import * as React from 'react'; import { toast } from 'sonner'; import { Badge } from '@object-ui/components'; +import { formatDateTime } from '@object-ui/core'; import { createAuthenticatedFetch } from '@object-ui/auth'; import { useDisplayLocale } from '@object-ui/i18n'; import { useObjectTranslation } from '@object-ui/react'; @@ -49,13 +50,16 @@ const ACTION_DOT: Record = { }; /** - * `locale` is REQUIRED: the timeline's action times used to be formatted with - * no tag, i.e. in the MACHINE's locale (objectui#9909). The timeline passes - * `useDisplayLocale()`. + * An action's time in the record page's one datetime face: core's compact + * face, the one the page's highlight chips and every `datetime` cell draw + * (objectstack#35415), in the host's display zone. `locale` is REQUIRED: the + * timeline's action times used to be formatted with no tag, i.e. in the + * MACHINE's locale (objectui#9909). The timeline passes `useDisplayLocale()`. */ function formatDate(s: string | null | undefined, locale: string): string { if (!s) return '—'; - try { return new Date(s).toLocaleString(locale); } catch { return s; } + const text = formatDateTime(s, { locale, style: 'compact' }); + return text === '—' ? s : text; } export interface ApprovalActionTimelineProps { diff --git a/ui/packages/components/src/index.ts b/ui/packages/components/src/index.ts index eb080851399..5c2136cf868 100644 --- a/ui/packages/components/src/index.ts +++ b/ui/packages/components/src/index.ts @@ -124,7 +124,7 @@ export type { PageHeaderPhoneFace } from './renderers/layout/page-header-phone-c // The record's one-row header (objectstack#35593): the host bar's two slots the // record header draws into, and the record state's tags and button group. export { RecordHeaderBarContext, RecordHeaderStateContext } from './renderers/layout/record-header-bar-context'; -export type { RecordHeaderBar, RecordHeaderGroupParts, RecordHeaderStageParts, RecordHeaderState } from './renderers/layout/record-header-bar-context'; +export type { RecordHeaderBar, RecordHeaderGroupParts, RecordHeaderStageParts, RecordHeaderState, RecordHeaderTitle } from './renderers/layout/record-header-bar-context'; export type { PageHeaderActionsProps } from './renderers/layout/containers'; // The form's host slots (objectstack#28104, objectstack#28106): the console's // create page names the fields an AI chat draft filled, and the form marks them diff --git a/ui/packages/components/src/renderers/layout/containers.tsx b/ui/packages/components/src/renderers/layout/containers.tsx index ff7ac757331..2470f1cb972 100644 --- a/ui/packages/components/src/renderers/layout/containers.tsx +++ b/ui/packages/components/src/renderers/layout/containers.tsx @@ -3406,6 +3406,11 @@ const PageHeaderRenderer: React.FC = ({ schema, className, ...props }) => { ? (titleCandidate.trim() ? titleCandidate : '') : (recordDisplayValueAt({ value: titleCandidate }, 'value') ?? '')) || placeholderTitle; + // The host's name for the record (`RecordHeaderState.title`), in both + // faces below, over every rung above; an empty one leaves them deciding. + const hostTitle = headerState?.title?.text?.trim() ? headerState.title : undefined; + const chipTitle = hostTitle ? hostTitle.text : resolvedTitle; + const chipTitleNode = hostTitle ? hostTitle.node : declaredFace; // The record's picture (objectui#11383, ruling A on hotcrm#1199). The // object names the field in its object-level `imageField`, and that // declaration is the ONLY channel: ⛔ no `page:header` prop, and no field @@ -3487,8 +3492,8 @@ const PageHeaderRenderer: React.FC = ({ schema, className, ...props }) => { const title = headerBar.titleSlot ? createPortal( = ({ schema, className, ...props }) => { >
React.ReactNode; + /** + * The name the header gives the record, where the host knows a better one + * than the object's declared title: a record that stands for another record + * (an approval request) is named by the record it stands for. Absent, or + * with an empty `text`: the title the header derives from the object's + * declaration, unchanged. + */ + title?: RecordHeaderTitle; +} + +/** + * The host's name for the record (`RecordHeaderState.title`). + */ +export interface RecordHeaderTitle { + /** The name, as plain text: what the title says and what a reader copies. */ + text: string; + /** + * Drawn inside the title's heading in place of `text`, such as a link to the + * record the name belongs to. Absent: `text`. + */ + node?: React.ReactNode; } /** From 3c717c2e379297a456ef9b058b9eb2afa050279c Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 09:59:27 +0000 Subject: [PATCH 2/5] test(approvals): pin the request page title, the band's reject face and the timeline's time face Claude-Session: https://claude.ai/code/session_01L6bhgW5RH2VUXjRj9dZYH2 Co-authored-by: Claude --- ...ApprovalsPanel.displayLocale-9909.test.tsx | 14 +- .../views/RecordDetailView.harness.test.tsx | 175 +++++++++++++++++- ...aredActionsBar.approverFold-34361.test.tsx | 21 +++ .../page-header-record-bar-35593.test.tsx | 31 ++++ 4 files changed, 238 insertions(+), 3 deletions(-) diff --git a/ui/packages/app-shell/src/views/RecordApprovalsPanel.displayLocale-9909.test.tsx b/ui/packages/app-shell/src/views/RecordApprovalsPanel.displayLocale-9909.test.tsx index 46f446ea1e6..8dcd310f5b6 100644 --- a/ui/packages/app-shell/src/views/RecordApprovalsPanel.displayLocale-9909.test.tsx +++ b/ui/packages/app-shell/src/views/RecordApprovalsPanel.displayLocale-9909.test.tsx @@ -23,6 +23,7 @@ import { describe, it, expect, vi, afterEach } from 'vitest'; import { render, screen, cleanup } from '@testing-library/react'; import { I18nProvider, LocalizationProvider } from '@object-ui/i18n'; import { isMachineLocale, recordLocaleArgumentsAsync } from '@object-ui/test-support'; +import { formatDateTime } from '@object-ui/core'; import type { ApprovalRequestLite } from '../hooks/useRecordApprovals'; vi.mock('@object-ui/auth', async (importOriginal) => ({ @@ -93,12 +94,13 @@ async function timelineUnder(locale: string): Promise { describe('approval timeline times follow the declared session locale (objectui#9909)', () => { it('says the de-DE face under a de-DE session', async () => { const text = await timelineUnder('de-DE'); - expect(text, `got: ${text}`).toMatch(/4\.3\.2020, 15:30:00/); + // The compact datetime face every `datetime` cell draws (objectstack#35415). + expect(text, `got: ${text}`).toMatch(/4\.3\.2020 3:30\spm/); }); it('keeps its en face under an en session', async () => { const text = await timelineUnder('en'); - expect(text, `got: ${text}`).toMatch(/3\/4\/2020, 3:30:00\sPM/); + expect(text, `got: ${text}`).toMatch(/3\/4\/2020 3:30\spm/); }); /** ⭐ THE PIN: the runner's own locale cannot satisfy it. */ @@ -114,3 +116,11 @@ describe('approval timeline times follow the declared session locale (objectui#9 expect(calls.filter(isMachineLocale), 'these call sites formatted in the machine locale').toEqual([]); }); }); + +describe('approval timeline times read the record page\'s one datetime face (objectstack#35415)', () => { + it('a zh-CN session reads the compact face a `datetime` field draws: no seconds, the 12-hour clock', async () => { + const text = await timelineUnder('zh-CN'); + expect(text, `got: ${text}`).toContain(formatDateTime(STORED, { locale: 'zh-CN', style: 'compact' })); + expect(text, `got: ${text}`).not.toMatch(/15:30:00/); + }); +}); diff --git a/ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx b/ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx index 1ced4d09113..ab76703c93d 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx @@ -47,7 +47,7 @@ import * as React from 'react'; import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll } from 'vitest'; import { render, waitFor, cleanup, screen, act, fireEvent } from '@testing-library/react'; -import { MemoryRouter, Route, Routes, BrowserRouter } from 'react-router-dom'; +import { MemoryRouter, Route, Routes, BrowserRouter, useLocation } from 'react-router-dom'; import { toast } from 'sonner'; import { RelatedCountStore } from '@object-ui/components'; import { ComponentRegistry } from '@object-ui/core'; @@ -3262,3 +3262,176 @@ describe('RecordDetailView.recordEditState-35599', () => { expect(view.container.querySelectorAll('[data-record-column="details"] [data-body-table-empty-add]').length).toBe(0); }); }); + +// ── RecordDetailView.approvalSubjectTitle-35415 ───────────────────────────── + +/** + * objectstack#35415 — an approval request's page is named by the business + * record the request asks a decision on, and the name opens that record. + * + * The request's own declared title is its flow's label (`process_label`, the + * object's `nameField`), which lists and search keep. On the request's page + * the H1 reads the subject's title the approvals get serves (`record_title`), + * as a link through the host's record route. Where the get serves none, or + * serves the bare record id, the H1 keeps the flow's label: the subject is + * never named by a raw id. + * + * Measured on the real `RecordDetailView` and the real `page:header` of the + * synthesized page, in the desktop top bar. Direction, written before the run: + * with the host's title not handed to the header, the two subject cases RED + * (`Invoice Sign-off`), every other case GREEN. + */ +describe('RecordDetailView.approvalSubjectTitle-35415', () => { + restoreAfterBlock(); + + const REQUEST_OBJECT = 'sys_approval_request'; + const REQ = 'req_35415'; + const FLOW_LABEL = 'Invoice Sign-off'; + const SUBJECT = 'Acceptance T-002 (mail thread link)'; + + const REQUEST_DEF = { + name: REQUEST_OBJECT, + label: 'Approval Request', + nameField: 'process_label', + fields: { + id: { label: 'Id', type: 'text' }, + process_label: { label: 'Flow', type: 'text' }, + object_name: { label: 'Object', type: 'text' }, + record_id: { label: 'Record', type: 'text' }, + status: { label: 'Status', type: 'text' }, + }, + }; + + const SERVED = { + id: REQ, + process_label: FLOW_LABEL, + object_name: 'purchase_request', + record_id: 'PR-2549', + status: 'pending', + }; + + function makeMetadata() { + const pages: any[] = []; + return { + objects: [], pages, loading: false, error: null, + refresh: async () => {}, invalidate: () => {}, + ensureType: async () => pages, getItem: async () => null, + getItemsByType: () => pages, + } as any; + } + + const h1 = () => document.querySelector('h1'); + + /** The subject's object, so the page's record route reaches it. */ + const SUBJECT_DEF = { + name: 'purchase_request', + label: 'Purchase Request', + nameField: 'name', + fields: { id: { label: 'Id', type: 'text' }, name: { label: 'Name', type: 'text' } }, + }; + + /** The address the router is at, read after a navigation. */ + let location = ''; + function LocationProbe() { + const here = useLocation(); + location = `${here.pathname}${here.search}`; + return null; + } + + function renderRequestPage(row: Record, objectDef: Record = REQUEST_DEF) { + const objectName = objectDef.name as string; + const ds = { + find: vi.fn(async () => ({ data: [], total: 0, hasMore: false, pageSize: 50 })), + findOne: vi.fn(async () => ({ ...row })), + create: vi.fn(async (_o: string, r: any) => r), + update: vi.fn(async () => ({})), + delete: vi.fn(async () => ({})), + getObjectSchema: async () => objectDef, + } as Record; + render( + + + + + + {}} + objectNameOverride={objectName} + recordIdOverride={REQ} + /> + )} + /> + + + + , + ); + return { ds }; + } + + beforeAll(() => { + Object.defineProperty(window, 'innerWidth', { configurable: true, value: 1280 }); + }); + + beforeEach(() => { + vi.stubGlobal('fetch', vi.fn(async () => ({ + ok: true, + status: 200, + json: async () => ({ allowed: true, data: [] }), + text: async () => '{}', + })) as never); + }); + + afterEach(() => { + cleanup(); + vi.unstubAllGlobals(); + }); + + describe('RecordDetailView — the approval request page is named by its record, which the name opens (objectstack#35415)', () => { + it('the H1 reads the served subject title, not the flow label, and links to the subject record', async () => { + renderRequestPage({ ...SERVED, record_title: SUBJECT }); + await waitFor(() => expect(h1()?.textContent).toBe(SUBJECT)); + const link = h1()!.querySelector('a[data-testid="approval-subject-title-link"]'); + expect(link?.getAttribute('href')).toMatch(/^\/apps\/demo\/purchase_request\/record\/PR-2549(\?|$)/); + }); + + it('a plain click on the name opens the subject record in the app, through the page\'s own record route', async () => { + // The page's `openRecord` decides how: a full-page navigation, or the + // record drawer one level down where the page hosts one. Either way the + // subject record is what gets opened, and the anchor's own navigation + // is not followed. + const { ds } = renderRequestPage({ ...SERVED, record_title: SUBJECT }); + await waitFor(() => expect(h1()?.querySelector('a')).not.toBeNull()); + const notFollowed = fireEvent.click(h1()!.querySelector('a')!, { button: 0 }); + expect(notFollowed).toBe(false); + await waitFor(() => { + const opened = /^\/apps\/demo\/purchase_request\/record\/PR-2549(\?|$)/.test(location) + || ds.findOne.mock.calls.some((call: unknown[]) => call[0] === 'purchase_request' && call[1] === 'PR-2549'); + expect(opened, `at ${location}; reads ${JSON.stringify(ds.findOne.mock.calls)}`).toBe(true); + }); + }); + + it('no subject title served: the H1 keeps the flow label, with no link', async () => { + renderRequestPage({ ...SERVED }); + await waitFor(() => expect(h1()?.textContent).toBe(FLOW_LABEL)); + expect(h1()!.querySelector('a')).toBeNull(); + }); + + it('a subject title that is the bare record id: the H1 keeps the flow label and never prints the id', async () => { + renderRequestPage({ ...SERVED, record_title: 'PR-2549' }); + await waitFor(() => expect(h1()?.textContent).toBe(FLOW_LABEL)); + expect(h1()!.textContent).not.toContain('PR-2549'); + }); + + it('CONTROL — another object with the same fields keeps its own declared title', async () => { + const other = { ...REQUEST_DEF, name: 'flow_ticket_35415', label: 'Ticket' }; + renderRequestPage({ ...SERVED, record_title: SUBJECT }, other); + await waitFor(() => expect(h1()?.textContent).toBe(FLOW_LABEL)); + }); + }); +}); diff --git a/ui/packages/app-shell/src/views/__tests__/DeclaredActionsBar.approverFold-34361.test.tsx b/ui/packages/app-shell/src/views/__tests__/DeclaredActionsBar.approverFold-34361.test.tsx index 884fedcaaef..d04a8bede02 100644 --- a/ui/packages/app-shell/src/views/__tests__/DeclaredActionsBar.approverFold-34361.test.tsx +++ b/ui/packages/app-shell/src/views/__tests__/DeclaredActionsBar.approverFold-34361.test.tsx @@ -386,3 +386,24 @@ describe('DeclaredActionsBar — the approver band names its menu entry (objects expect(trigger.querySelector('svg.lucide-chevron-down')).toBeTruthy(); }); }); + +// objectstack#35415 — in the approver's band the approval is the strongest +// button: Approve filled, Reject an outline button in the destructive text +// colour (the header group's secondary face), never a second filled one. +describe('DeclaredActionsBar — the approver band leads with a filled Approve, Reject outlined (objectstack#35415)', () => { + it('draws Approve filled and Reject as a destructive outline', async () => { + renderBar(APPROVER); + await waitFor(() => expect(screen.getByTestId('declared-actions-decision-menu')).toBeInTheDocument()); + const approve = screen.getByTestId('declared-action-approval_approve'); + const reject = screen.getByTestId('declared-action-approval_reject'); + expect(approve.className).toContain('bg-primary'); + expect(reject.className).not.toContain('bg-destructive'); + expect(reject.className).toContain('border'); + expect(reject.className).toContain('text-destructive'); + }); + + it('CONTROL — a host that does not ask for the fold keeps the declared filled danger face', () => { + renderBar(APPROVER, { foldDecisions: false }); + expect(screen.getByTestId('declared-action-approval_reject').className).toContain('bg-destructive'); + }); +}); diff --git a/ui/packages/components/src/__tests__/page-header-record-bar-35593.test.tsx b/ui/packages/components/src/__tests__/page-header-record-bar-35593.test.tsx index d43e6fda0ab..d931c997080 100644 --- a/ui/packages/components/src/__tests__/page-header-record-bar-35593.test.tsx +++ b/ui/packages/components/src/__tests__/page-header-record-bar-35593.test.tsx @@ -195,3 +195,34 @@ describe('the record state\'s ONE group (objectstack#35593)', () => { await waitFor(() => expect(document.querySelector('[data-record-header-tags] [data-testid="state-tag"]')).toBeTruthy()); }); }); + +// objectstack#35415 — the host's name for the record (`RecordHeaderState.title`) +// is the heading in both faces, its node drawn inside the H1; absent or empty, +// the header's own title stands. +describe('the record state\'s title (objectstack#35415)', () => { + const HOST_TITLE = { text: 'Acceptance T-002', node: Acceptance T-002 }; + + it('in the host bar: the H1 draws the host\'s node in place of the record\'s own name', async () => { + renderHeader({ bar: vi.fn(), state: { title: HOST_TITLE } }); + const titleSlot = screen.getByTestId('title-slot'); + await waitFor(() => expect(titleSlot.querySelector('h1')?.textContent).toBe('Acceptance T-002')); + expect(titleSlot.querySelector('h1 [data-testid="host-title-node"]')?.getAttribute('href')).toBe('/subject'); + expect(titleSlot.textContent).not.toContain('Mira Costa'); + }); + + it('without a host bar: the header row\'s H1 is the host\'s name too', async () => { + renderHeader({ state: { title: HOST_TITLE } }); + await waitFor(() => expect(document.querySelector('header h1')?.textContent).toBe('Acceptance T-002')); + expect(document.querySelector('header h1 [data-testid="host-title-node"]')).toBeTruthy(); + }); + + it('a host title with no node draws its text', async () => { + renderHeader({ state: { title: { text: 'Acceptance T-002' } } }); + await waitFor(() => expect(document.querySelector('header h1')?.textContent).toBe('Acceptance T-002')); + }); + + it('CONTROL — an empty host title leaves the record\'s own name', async () => { + renderHeader({ state: { title: { text: ' ', node: ignored } } }); + await waitFor(() => expect(document.querySelector('header h1')?.textContent).toBe('Mira Costa')); + }); +}); From d0a6bf9c01c5122ee8baa9bc1d8dd99f00b04daa Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 10:00:59 +0000 Subject: [PATCH 3/5] docs(approvals): say where the request page names its record; changeset Claude-Session: https://claude.ai/code/session_01L6bhgW5RH2VUXjRj9dZYH2 Co-authored-by: Claude --- .../35415-approval-request-names-its-record.md | 16 ++++++++++++++++ .../src/sys-approval-request.object.ts | 9 +++++---- .../src/sys-approval-request.page.ts | 5 ++++- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 .changeset/35415-approval-request-names-its-record.md diff --git a/.changeset/35415-approval-request-names-its-record.md b/.changeset/35415-approval-request-names-its-record.md new file mode 100644 index 00000000000..36715334e99 --- /dev/null +++ b/.changeset/35415-approval-request-names-its-record.md @@ -0,0 +1,16 @@ +--- +'@object-ui/components': patch +'@object-ui/app-shell': patch +'@objectstack/plugin-approvals': patch +--- + +fix(console): the approval request page is named by the record it asks a decision on, and its reject button no longer outweighs approve + +Clause-②: yes (widening) +Metadata-protocol: none + +- **The page title.** An approval request's page used to be titled by its flow's label ("Purchase approval"), which the strip under it repeated as its Flow chip, while the business record the approver decides on had no title at all. The page header now reads the record's title the approvals get serves (`record_title`), linked to that record: a plain click opens it in the app, as the "As submitted" card's "Open record" link does, and a modifier or middle click opens it in a new tab. Where the get serves no title for the record, or serves only its id, the header keeps the flow's label, so the page never names the record by a raw id. The flow stays named once, by the strip's Flow chip; no subtitle is added, because it would repeat that chip. The request object's declared title (`nameField: 'process_label'`) is unchanged, so lists, search, recent items and the breadcrumb still name a request by its flow. +- **`RecordHeaderState.title`** (`@object-ui/components`, new optional member, with its type `RecordHeaderTitle`). A host that knows a better name for the record than the object's declared title hands `{ text, node? }`; `page:header` draws `node` (or `text`) inside its H1, in the host's top bar and in its own row alike. Absent, or with an empty `text`, the header's own title stands exactly as before. +- **The decision band.** In the approver's band (the request page, and the business record page's approval band), Approve stays the filled primary button and Reject is drawn as an outline button in the destructive text colour, the face the record header already gives a secondary danger lever. A host that does not ask for the band's fold keeps the declared filled danger face. +- **One time format.** The approval timeline's action times use the compact datetime face the page's highlight chips and every `datetime` cell draw (`2026/11/10 下午8:25` under zh-CN), in the host's display time zone, instead of the browser's long form with seconds. +- `@objectstack/plugin-approvals`: comments only, saying where the request page now names its record. diff --git a/packages/plugins/plugin-approvals/src/sys-approval-request.object.ts b/packages/plugins/plugin-approvals/src/sys-approval-request.object.ts index 2abdb335b86..bb40f05518d 100644 --- a/packages/plugins/plugin-approvals/src/sys-approval-request.object.ts +++ b/packages/plugins/plugin-approvals/src/sys-approval-request.object.ts @@ -66,10 +66,11 @@ export const SysApprovalRequest = ObjectSchema.create({ // page fell through to the since-retired `titleFormat`, the machine name and // the raw subject record id. // - // The title names no subject record. The request page names the subject on - // the card the `record_id` / `object_name` pair draws in the Details tab, - // which says so when the reader may not read the record or it was deleted; - // a title cannot, so a bare record id is never shown there. + // The title names no subject record: lists and search name a request by its + // flow. On the request's own page the console's header names the subject by + // the `record_title` the approvals get serves for it, linked to it, and + // keeps this title where the get serves none (objectstack#35415), so a bare + // record id is never shown there either. // // Where `process_label` is empty — a row written before the column, until the // boot fill labels it (`display-label-backfill.ts`) — the retired diff --git a/packages/plugins/plugin-approvals/src/sys-approval-request.page.ts b/packages/plugins/plugin-approvals/src/sys-approval-request.page.ts index 066dfa92191..577be3fa786 100644 --- a/packages/plugins/plugin-approvals/src/sys-approval-request.page.ts +++ b/packages/plugins/plugin-approvals/src/sys-approval-request.page.ts @@ -85,7 +85,10 @@ export const SysApprovalRequestDetailPage: Page = { name: 'main', width: 'full', components: [ - // ── The record header: the request's title, and every action placed + // ── The record header: the request's title (the console names the + // request by the business record it is about, linked to it, wherever + // the approvals get serves that record's title, objectstack#35415; + // else by the flow's label, the object's `nameField`), and every action placed // on the object at `record_header` / `record_more`, read live, as the // synthesized header drew them. The object places none of its own, so // only an action another package places there shows (a bare header From 6e1742b36ee687560486f9345e920b0f0f16a3b6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 10:26:42 +0000 Subject: [PATCH 4/5] test(components): keep the host-title pins apart from the bar-budget block Claude-Session: https://claude.ai/code/session_01L6bhgW5RH2VUXjRj9dZYH2 Co-authored-by: Claude --- .../page-header-record-bar-35593.test.tsx | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/ui/packages/components/src/__tests__/page-header-record-bar-35593.test.tsx b/ui/packages/components/src/__tests__/page-header-record-bar-35593.test.tsx index d931c997080..e4556900b26 100644 --- a/ui/packages/components/src/__tests__/page-header-record-bar-35593.test.tsx +++ b/ui/packages/components/src/__tests__/page-header-record-bar-35593.test.tsx @@ -165,37 +165,6 @@ describe('page:header in the host bar (objectstack#35593)', () => { }); }); -describe('the record state\'s ONE group (objectstack#35593)', () => { - it('hands the group the record\'s row and the record\'s actions as ⋯ items, and draws what it returns', async () => { - const seen: RecordHeaderGroupParts[] = []; - const group = (parts: RecordHeaderGroupParts) => { - seen.push(parts); - return ; - }; - renderHeader({ bar: vi.fn(), state: { group } }); - const actionSlot = screen.getByTestId('action-slot'); - await waitFor(() => expect(actionSlot.querySelector('[data-testid="state-lead"]')).toBeTruthy()); - - const last = seen[seen.length - 1]; - expect(last.face).toBe('row'); - expect(last.recordRow).toBeTruthy(); - expect(last.recordMenuItems).toBeTruthy(); - // The group took the row: the record's own inline buttons are not drawn. - expect(inlineButtons(actionSlot)).not.toContain('Convert'); - }); - - it('a group that returns the record\'s row draws the record\'s row unchanged', async () => { - renderHeader({ bar: vi.fn(), state: { group: (parts) => parts.recordRow } }); - const actionSlot = screen.getByTestId('action-slot'); - await waitFor(() => expect(inlineButtons(actionSlot)).toContain('Convert')); - }); - - it('without a host bar the state\'s tags sit under the record\'s name', async () => { - renderHeader({ state: { tags: 审批中 } }); - await waitFor(() => expect(document.querySelector('[data-record-header-tags] [data-testid="state-tag"]')).toBeTruthy()); - }); -}); - // objectstack#35415 — the host's name for the record (`RecordHeaderState.title`) // is the heading in both faces, its node drawn inside the H1; absent or empty, // the header's own title stands. @@ -226,3 +195,34 @@ describe('the record state\'s title (objectstack#35415)', () => { await waitFor(() => expect(document.querySelector('header h1')?.textContent).toBe('Mira Costa')); }); }); + +describe('the record state\'s ONE group (objectstack#35593)', () => { + it('hands the group the record\'s row and the record\'s actions as ⋯ items, and draws what it returns', async () => { + const seen: RecordHeaderGroupParts[] = []; + const group = (parts: RecordHeaderGroupParts) => { + seen.push(parts); + return ; + }; + renderHeader({ bar: vi.fn(), state: { group } }); + const actionSlot = screen.getByTestId('action-slot'); + await waitFor(() => expect(actionSlot.querySelector('[data-testid="state-lead"]')).toBeTruthy()); + + const last = seen[seen.length - 1]; + expect(last.face).toBe('row'); + expect(last.recordRow).toBeTruthy(); + expect(last.recordMenuItems).toBeTruthy(); + // The group took the row: the record's own inline buttons are not drawn. + expect(inlineButtons(actionSlot)).not.toContain('Convert'); + }); + + it('a group that returns the record\'s row draws the record\'s row unchanged', async () => { + renderHeader({ bar: vi.fn(), state: { group: (parts) => parts.recordRow } }); + const actionSlot = screen.getByTestId('action-slot'); + await waitFor(() => expect(inlineButtons(actionSlot)).toContain('Convert')); + }); + + it('without a host bar the state\'s tags sit under the record\'s name', async () => { + renderHeader({ state: { tags: 审批中 } }); + await waitFor(() => expect(document.querySelector('[data-record-header-tags] [data-testid="state-tag"]')).toBeTruthy()); + }); +}); From 88775b7e5bcf30d1177ec6e94f51e8f121c5ad20 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 14:10:16 +0000 Subject: [PATCH 5/5] fix(approvals): the request page's title links its record only where the page read it The approval request page's title named the subject record and linked to it whatever the page's own read of that record answered, so a refused (403) or platform-deleted subject still drew a link in the H1 while the record card on the same page drew none (objectui#11878, objectui#12489, objectui#12557 pins). The title now links only once one of the page's reads returned the record: `SubmittedRecord`'s current read and `RecordPreviewCard`'s read report what they found through `RecordReadReportContext`, which `RecordDetailView` provides on an approval request's page only. The title makes no read itself. A refused, unresolvable or deleted subject is named as plain text. The served-page pins that read the H1 as the flow label, or counted one link to the subject on the page, now read the subject's title and count the card's link and the H1's; the refused and deleted pins also check the H1 is plain. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01L6bhgW5RH2VUXjRj9dZYH2 --- ...35415-approval-request-names-its-record.md | 2 +- ...lsInboxPage.opensServedPage-12484.test.tsx | 7 +- ...Source.servedPageRecordLink-12557.test.tsx | 44 ++++++++-- ...e.servedPageReferenceStates-12489.test.tsx | 24 ++++-- .../views/RecordDetailView.harness.test.tsx | 52 ++++-------- .../app-shell/src/views/RecordDetailView.tsx | 17 +++- .../approval-decision/SubmittedRecord.tsx | 15 +++- .../approvalSubjectTitle.test.tsx | 83 +++++++++++++++++++ .../approvalSubjectTitle.tsx | 23 +++-- .../approval-decision/recordReadReport.ts | 53 ++++++++++++ .../record-preview/RecordPreviewCard.tsx | 4 + 11 files changed, 259 insertions(+), 65 deletions(-) create mode 100644 ui/packages/app-shell/src/views/approval-decision/approvalSubjectTitle.test.tsx create mode 100644 ui/packages/app-shell/src/views/approval-decision/recordReadReport.ts diff --git a/.changeset/35415-approval-request-names-its-record.md b/.changeset/35415-approval-request-names-its-record.md index 36715334e99..dc2e7b038ff 100644 --- a/.changeset/35415-approval-request-names-its-record.md +++ b/.changeset/35415-approval-request-names-its-record.md @@ -9,7 +9,7 @@ fix(console): the approval request page is named by the record it asks a decisio Clause-②: yes (widening) Metadata-protocol: none -- **The page title.** An approval request's page used to be titled by its flow's label ("Purchase approval"), which the strip under it repeated as its Flow chip, while the business record the approver decides on had no title at all. The page header now reads the record's title the approvals get serves (`record_title`), linked to that record: a plain click opens it in the app, as the "As submitted" card's "Open record" link does, and a modifier or middle click opens it in a new tab. Where the get serves no title for the record, or serves only its id, the header keeps the flow's label, so the page never names the record by a raw id. The flow stays named once, by the strip's Flow chip; no subtitle is added, because it would repeat that chip. The request object's declared title (`nameField: 'process_label'`) is unchanged, so lists, search, recent items and the breadcrumb still name a request by its flow. +- **The page title.** An approval request's page used to be titled by its flow's label ("Purchase approval"), which the strip under it repeated as its Flow chip, while the business record the approver decides on had no title at all. The page header now reads the record's title the approvals get serves (`record_title`), linked to that record once the page itself has read it: a plain click opens it in the app, as the "As submitted" card's "Open record" link does, and a modifier or middle click opens it in a new tab. Where the page's read of the record is refused or finds nothing, or the platform says the record was deleted, the title is plain text with no link, as the record card on the same page draws it. The title makes no read of its own: the reads the page already makes report what they found. Where the get serves no title for the record, or serves only its id, the header keeps the flow's label, so the page never names the record by a raw id. The flow stays named once, by the strip's Flow chip; no subtitle is added, because it would repeat that chip. The request object's declared title (`nameField: 'process_label'`) is unchanged, so lists, search, recent items and the breadcrumb still name a request by its flow. - **`RecordHeaderState.title`** (`@object-ui/components`, new optional member, with its type `RecordHeaderTitle`). A host that knows a better name for the record than the object's declared title hands `{ text, node? }`; `page:header` draws `node` (or `text`) inside its H1, in the host's top bar and in its own row alike. Absent, or with an empty `text`, the header's own title stands exactly as before. - **The decision band.** In the approver's band (the request page, and the business record page's approval band), Approve stays the filled primary button and Reject is drawn as an outline button in the destructive text colour, the face the record header already gives a secondary danger lever. A host that does not ask for the band's fold keeps the declared filled danger face. - **One time format.** The approval timeline's action times use the compact datetime face the page's highlight chips and every `datetime` cell draw (`2026/11/10 下午8:25` under zh-CN), in the host's display time zone, instead of the browser's long form with seconds. diff --git a/ui/apps/console/src/pages/system/ApprovalsInboxPage.opensServedPage-12484.test.tsx b/ui/apps/console/src/pages/system/ApprovalsInboxPage.opensServedPage-12484.test.tsx index 35e8821a5a0..eee6bb97499 100644 --- a/ui/apps/console/src/pages/system/ApprovalsInboxPage.opensServedPage-12484.test.tsx +++ b/ui/apps/console/src/pages/system/ApprovalsInboxPage.opensServedPage-12484.test.tsx @@ -287,10 +287,13 @@ async function inboxRow(): Promise { return row; } -/** The served page has drawn: its decision panel and its H1. */ +/** + * The served page has drawn: its decision panel and its H1, which names the + * request by the record it asks a decision on (objectstack#35415). + */ async function servedPage(): Promise { await screen.findByTestId('approval-decision-panel', undefined, { timeout: 8000 }); - expect((await screen.findByRole('heading', { level: 1 }, { timeout: 8000 })).textContent).toBe(ROW.process_label); + expect((await screen.findByRole('heading', { level: 1 }, { timeout: 8000 })).textContent).toBe(ROW.record_title); } /** The served get was read; the sheet's own reads were not, and no sheet (a dialog) is mounted. */ diff --git a/ui/apps/console/src/services/approvalRequestsDataSource.servedPageRecordLink-12557.test.tsx b/ui/apps/console/src/services/approvalRequestsDataSource.servedPageRecordLink-12557.test.tsx index ffc19b62ee6..f6994ac5a97 100644 --- a/ui/apps/console/src/services/approvalRequestsDataSource.servedPageRecordLink-12557.test.tsx +++ b/ui/apps/console/src/services/approvalRequestsDataSource.servedPageRecordLink-12557.test.tsx @@ -282,27 +282,49 @@ describe('the served request page links a readable target to its record (objectu expect(PageSchema.safeParse(SERVED_PAGE).success).toBe(true); }); - it('readable: one link to the app-scoped record path, named by the card title, inside the card', async () => { + it('readable: one link to the app-scoped record path inside the card, named by the card title; the page H1 is the other (objectstack#35415)', async () => { const id = 'Rd4bl3RecordQQQQ'; targetAnswer = async (rid) => ({ id: rid, name: TARGET_TITLE, amount: 12500 }); const { container } = openServedPage({ record_id: id, status: 'pending', record_title: TARGET_TITLE }); const card = await settledCard(container); expect(card.getAttribute('data-record-preview')).toBe('readable'); + // The card's link, and the page H1, which names the request by its + // record and links to it once the page has read it (objectstack#35415). + await waitFor(() => expect(linksTo(recordPath(id))).toHaveLength(2), { timeout: 8000 }); const links = linksTo(recordPath(id)); - expect(links).toHaveLength(1); - expect(card.contains(links[0])).toBe(true); - expect(screen.getByRole('link', { name: TARGET_TITLE })).toBe(links[0]); + const inCard = links.filter((a) => card.contains(a)); + expect(inCard).toHaveLength(1); + expect(within(card).getByRole('link', { name: TARGET_TITLE })).toBe(inCard[0]); + const h1 = screen.getByRole('heading', { level: 1 }); + expect(h1.textContent).toBe(TARGET_TITLE); + expect(links.filter((a) => h1.contains(a))).toHaveLength(1); }); - it('readable: a plain click opens the record in a drawer over the page, and the page stays put', async () => { + it('readable: a plain click on the page H1 opens the record in the same drawer, and the page stays put (objectstack#35415)', async () => { const id = 'Rd4bl3RecordQQQQ'; targetAnswer = async (rid) => ({ id: rid, name: TARGET_TITLE, amount: 12500 }); const { container } = openServedPage({ record_id: id, status: 'pending', record_title: TARGET_TITLE }); await settledCard(container); const requestPath = `/apps/${APP}/${APPROVAL_REQUEST_OBJECT}/record/${REQ}`; - const notPrevented = fireEvent.click(screen.getByRole('link', { name: TARGET_TITLE }), { button: 0 }); + const h1 = screen.getByRole('heading', { level: 1 }); + const titleLink = await waitFor(() => within(h1).getByRole('link', { name: TARGET_TITLE }), { timeout: 8000 }); + const notPrevented = fireEvent.click(titleLink, { button: 0 }); + expect(notPrevented).toBe(false); + const drawer = await screen.findByRole('dialog', undefined, { timeout: 8000 }); + await waitFor(() => expect(within(drawer).getAllByText(TARGET_TITLE).length).toBeGreaterThan(0), { timeout: 8000 }); + expect(screen.getByTestId('router-pathname').textContent).toBe(requestPath); + }); + + it('readable: a plain click opens the record in a drawer over the page, and the page stays put', async () => { + const id = 'Rd4bl3RecordQQQQ'; + targetAnswer = async (rid) => ({ id: rid, name: TARGET_TITLE, amount: 12500 }); + const { container } = openServedPage({ record_id: id, status: 'pending', record_title: TARGET_TITLE }); + const card = await settledCard(container); + const requestPath = `/apps/${APP}/${APPROVAL_REQUEST_OBJECT}/record/${REQ}`; + + const notPrevented = fireEvent.click(within(card).getByRole('link', { name: TARGET_TITLE }), { button: 0 }); expect(notPrevented).toBe(false); // The drawer opens with the target record in it … const drawer = await screen.findByRole('dialog', undefined, { timeout: 8000 }); @@ -311,16 +333,16 @@ describe('the served request page links a readable target to its record (objectu // … over the request page: the router did not move. expect(screen.getByTestId('router-pathname').textContent).toBe(requestPath); // The href still names the record path, for a new tab or a copied link. - expect(linksTo(recordPath(id))).toHaveLength(1); + expect(linksTo(recordPath(id)).filter((a) => card.contains(a))).toHaveLength(1); }); it('readable: a modified click is the browser\'s — not intercepted, no drawer', async () => { const id = 'Rd4bl3RecordQQQQ'; targetAnswer = async (rid) => ({ id: rid, name: TARGET_TITLE, amount: 12500 }); const { container } = openServedPage({ record_id: id, status: 'pending', record_title: TARGET_TITLE }); - await settledCard(container); + const card = await settledCard(container); - const link = screen.getByRole('link', { name: TARGET_TITLE }); + const link = within(card).getByRole('link', { name: TARGET_TITLE }); const notPrevented = fireEvent.click(link, { button: 0, metaKey: true }); expect(notPrevented).toBe(true); expect(new URL(link.getAttribute('href') as string, 'http://test.local').pathname).toBe(recordPath(id)); @@ -336,6 +358,10 @@ describe('the served request page links a readable target to its record (objectu expect(card.getAttribute('data-record-preview')).toBe('unreadable'); expect(card.querySelectorAll('a[href]')).toHaveLength(0); expect(linksTo(recordPath(id))).toHaveLength(0); + // The H1 names the record by the title the get served, as plain text (objectstack#35415). + const h1 = screen.getByRole('heading', { level: 1 }); + expect(h1.textContent).toBe('INV-2020'); + expect(h1.querySelectorAll('a[href]')).toHaveLength(0); }); it('CONTROL: unresolvable (the target read resolves with no record) draws no link to the target anywhere', async () => { diff --git a/ui/apps/console/src/services/approvalRequestsDataSource.servedPageReferenceStates-12489.test.tsx b/ui/apps/console/src/services/approvalRequestsDataSource.servedPageReferenceStates-12489.test.tsx index 24ec702a534..474730a8da5 100644 --- a/ui/apps/console/src/services/approvalRequestsDataSource.servedPageReferenceStates-12489.test.tsx +++ b/ui/apps/console/src/services/approvalRequestsDataSource.servedPageReferenceStates-12489.test.tsx @@ -319,21 +319,23 @@ describe('the served request page draws the four reference states the sheet draw expect(PageSchema.safeParse(SERVED_PAGE).success).toBe(true); }); - it('readable (sheet: recordLink): one link to the record path, inside the card, named by its title', async () => { + it('readable (sheet: recordLink): one link to the record path inside the card, named by its title; the H1 names and links the record too', async () => { const id = 'Rd4bl3Rec12489QQ'; targetAnswer = async (rid) => ({ id: rid, name: TARGET_TITLE, amount: 12500 }); const { container } = openServedPage({ record_id: id, status: 'pending', record_title: TARGET_TITLE }); const card = await settledCard(container); expect(card.getAttribute('data-record-preview')).toBe('readable'); - const links = linksTo(recordPath(id)); - expect(links).toHaveLength(1); - expect(card.contains(links[0])).toBe(true); - expect(links[0].textContent).toContain(TARGET_TITLE); + await waitFor(() => expect(linksTo(recordPath(id))).toHaveLength(2), { timeout: 8000 }); + const inCard = linksTo(recordPath(id)).filter((a) => card.contains(a)); + expect(inCard).toHaveLength(1); + expect(inCard[0].textContent).toContain(TARGET_TITLE); expect(container.querySelector('[data-record-pointer="deleted"]')).toBeNull(); - // The H1 names the flow by its label: not the subject's id, not `flow:NAME`. + // The H1 names the request by its record, linked once the page read it + // (objectstack#35415): not the subject's id, not `flow:NAME`. const h1 = await pageTitle(); - expect(h1.textContent).toBe(FLOW_LABEL); + expect(h1.textContent).toBe(TARGET_TITLE); + expect(linksTo(recordPath(id)).filter((a) => h1.contains(a))).toHaveLength(1); expect(h1.textContent).not.toContain(id); expect(h1.textContent).not.toContain(FLOW_SOURCE); }); @@ -375,8 +377,12 @@ describe('the served request page draws the four reference states the sheet draw expect(tab?.textContent).not.toContain(id); // …and nowhere on the page, the H1 included: the counterpart of the sheet's // drawer case "tombstones the same reference in the drawer — not one click - // deeper" (`ApprovalsInboxPage.tombstone.test.tsx`, objectui#7108). - expect((await pageTitle()).textContent).toBe(FLOW_LABEL); + // deeper" (`ApprovalsInboxPage.tombstone.test.tsx`, objectui#7108). The H1 + // names the record by the title the get served, as plain text: the page + // never read it, so it links nowhere (objectstack#35415). + const h1 = await pageTitle(); + expect(h1.textContent).toBe('INV-3030'); + expect(h1.querySelectorAll('a[href]')).toHaveLength(0); expect(document.body.innerHTML).not.toContain(id); }); diff --git a/ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx b/ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx index ab76703c93d..a6b8621667d 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx @@ -47,7 +47,7 @@ import * as React from 'react'; import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll } from 'vitest'; import { render, waitFor, cleanup, screen, act, fireEvent } from '@testing-library/react'; -import { MemoryRouter, Route, Routes, BrowserRouter, useLocation } from 'react-router-dom'; +import { MemoryRouter, Route, Routes, BrowserRouter } from 'react-router-dom'; import { toast } from 'sonner'; import { RelatedCountStore } from '@object-ui/components'; import { ComponentRegistry } from '@object-ui/core'; @@ -3271,14 +3271,20 @@ describe('RecordDetailView.recordEditState-35599', () => { * * The request's own declared title is its flow's label (`process_label`, the * object's `nameField`), which lists and search keep. On the request's page - * the H1 reads the subject's title the approvals get serves (`record_title`), - * as a link through the host's record route. Where the get serves none, or - * serves the bare record id, the H1 keeps the flow's label: the subject is - * never named by a raw id. + * the H1 reads the subject's title the approvals get serves (`record_title`). + * Where the get serves none, or serves the bare record id, the H1 keeps the + * flow's label: the subject is never named by a raw id. + * + * The name links to the subject only once one of the page's own reads of it + * returned the record (`recordReadReport.ts`). This synthesized page draws no + * reader of the subject, so here the name is plain text; the link and its + * click are pinned on the served page, where the record card reads it + * (`approvalRequestsDataSource.servedPageRecordLink-12557.test.tsx`), and on + * the title itself (`approvalSubjectTitle.test.tsx`). * * Measured on the real `RecordDetailView` and the real `page:header` of the * synthesized page, in the desktop top bar. Direction, written before the run: - * with the host's title not handed to the header, the two subject cases RED + * with the host's title not handed to the header, the subject case REDs * (`Invoice Sign-off`), every other case GREEN. */ describe('RecordDetailView.approvalSubjectTitle-35415', () => { @@ -3330,14 +3336,6 @@ describe('RecordDetailView.approvalSubjectTitle-35415', () => { fields: { id: { label: 'Id', type: 'text' }, name: { label: 'Name', type: 'text' } }, }; - /** The address the router is at, read after a navigation. */ - let location = ''; - function LocationProbe() { - const here = useLocation(); - location = `${here.pathname}${here.search}`; - return null; - } - function renderRequestPage(row: Record, objectDef: Record = REQUEST_DEF) { const objectName = objectDef.name as string; const ds = { @@ -3352,7 +3350,6 @@ describe('RecordDetailView.approvalSubjectTitle-35415', () => { - { }); describe('RecordDetailView — the approval request page is named by its record, which the name opens (objectstack#35415)', () => { - it('the H1 reads the served subject title, not the flow label, and links to the subject record', async () => { - renderRequestPage({ ...SERVED, record_title: SUBJECT }); - await waitFor(() => expect(h1()?.textContent).toBe(SUBJECT)); - const link = h1()!.querySelector('a[data-testid="approval-subject-title-link"]'); - expect(link?.getAttribute('href')).toMatch(/^\/apps\/demo\/purchase_request\/record\/PR-2549(\?|$)/); - }); - - it('a plain click on the name opens the subject record in the app, through the page\'s own record route', async () => { - // The page's `openRecord` decides how: a full-page navigation, or the - // record drawer one level down where the page hosts one. Either way the - // subject record is what gets opened, and the anchor's own navigation - // is not followed. + it('the H1 reads the served subject title, not the flow label; unread by the page, it links nowhere', async () => { const { ds } = renderRequestPage({ ...SERVED, record_title: SUBJECT }); - await waitFor(() => expect(h1()?.querySelector('a')).not.toBeNull()); - const notFollowed = fireEvent.click(h1()!.querySelector('a')!, { button: 0 }); - expect(notFollowed).toBe(false); - await waitFor(() => { - const opened = /^\/apps\/demo\/purchase_request\/record\/PR-2549(\?|$)/.test(location) - || ds.findOne.mock.calls.some((call: unknown[]) => call[0] === 'purchase_request' && call[1] === 'PR-2549'); - expect(opened, `at ${location}; reads ${JSON.stringify(ds.findOne.mock.calls)}`).toBe(true); - }); + await waitFor(() => expect(h1()?.textContent).toBe(SUBJECT)); + expect(h1()!.querySelector('a')).toBeNull(); + // The title reads nothing itself. + expect(ds.findOne.mock.calls.some((call: unknown[]) => call[0] === 'purchase_request')).toBe(false); }); it('no subject title served: the H1 keeps the flow label, with no link', async () => { diff --git a/ui/packages/app-shell/src/views/RecordDetailView.tsx b/ui/packages/app-shell/src/views/RecordDetailView.tsx index aa217c26bf4..983b57378d3 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.tsx @@ -92,6 +92,7 @@ import { } from './recordApprovalActions.js'; import { useApprovalQueueAdvance } from './approval-decision/approvalQueueAdvance.js'; import { approvalSubjectTitle } from './approval-decision/approvalSubjectTitle.js'; +import { RecordReadReportContext, recordReadKey, type RecordReadReport } from './approval-decision/recordReadReport.js'; // Side-effect registration of `record:approvals` — synthesized record pages // reference the node whenever the record has approval requests (#3461), so // the type must resolve wherever this view renders, not only under hosts @@ -1586,6 +1587,18 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri // re-render never republishes an equal row as a new object to the page. const readablePageRecord = readableRow(pageRecord, perms, objectName); + // objectstack#35415 — on an approval request's page, what the page's own + // reads of a record learned (`recordReadReport.ts`): the title links to the + // record the request is about only where one of them read it. Keyed by + // `object::id`; collected only on that page, so no other page re-renders on + // its cards' reads. + const [readRecords, setReadRecords] = useState>>({}); + const reportRecordRead = useCallback((target, id, readable) => { + const key = recordReadKey(target, id); + setReadRecords((prev) => (prev[key] === readable ? prev : { ...prev, [key]: readable })); + }, []); + const isRecordRead = (target: string, id: string) => readRecords[recordReadKey(target, id)] === true; + // Derive a human-readable record title from the loaded record so // favourites (record:*) and the breadcrumb show e.g. "Acme Corporation" // instead of the raw record id. It reads `readablePageRecord` above, so a @@ -5567,7 +5580,7 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri stage: (parts) => , // objectstack#35415 — an approval request's page is named by the record // it asks a decision on, linked to it; else by the request's own title. - title: objectName === SYS_APPROVAL_REQUEST_OBJECT ? approvalSubjectTitle(readablePageRecord) : undefined, + title: objectName === SYS_APPROVAL_REQUEST_OBJECT ? approvalSubjectTitle(readablePageRecord, isRecordRead) : undefined, }; const sharedChrome = ( <> @@ -5589,6 +5602,7 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri const pageTree = ( +
{pageBar} {/* In a pane, the record's ⊟ goes into the pane's own top bar. */} @@ -6083,6 +6097,7 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri onClose={() => setFlowRefusal(s => ({ ...s, open: false }))} />
+
); diff --git a/ui/packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx b/ui/packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx index b29ae9f3146..ae34508e0e0 100644 --- a/ui/packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx +++ b/ui/packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx @@ -111,6 +111,7 @@ import { ExternalLink, Paperclip } from 'lucide-react'; import { deriveRecordDetailSections } from '../recordDetailSections.js'; import { deriveRelatedLists } from '../../utils/deriveRelatedLists.js'; import { servedObjectLabel, servedObjectPluralLabel } from '../../hooks/servedObjectLabel.js'; +import { useReportRecordRead } from './recordReadReport.js'; import { distinctLabels, planSubmittedRecord, @@ -184,9 +185,17 @@ function useCurrentRecord(objectName: string | null, recordId: string | null): C }; }, [key, objectName, recordId, canRead, dataSource, invalidation]); - if (key === null || !canRead) return { status: 'unreadable' }; - if (!answer || answer.key !== key) return { status: 'loading' }; - return answer.row ? { status: 'readable', row: answer.row } : { status: 'unreadable' }; + const state: CurrentRecordState = + key === null || !canRead + ? { status: 'unreadable' } + : !answer || answer.key !== key + ? { status: 'loading' } + : answer.row + ? { status: 'readable', row: answer.row } + : { status: 'unreadable' }; + // What this read learned, for the page's title link (objectstack#35415). + useReportRecordRead(objectName, recordId, state.status); + return state; } /** diff --git a/ui/packages/app-shell/src/views/approval-decision/approvalSubjectTitle.test.tsx b/ui/packages/app-shell/src/views/approval-decision/approvalSubjectTitle.test.tsx new file mode 100644 index 00000000000..6ee13f86b00 --- /dev/null +++ b/ui/packages/app-shell/src/views/approval-decision/approvalSubjectTitle.test.tsx @@ -0,0 +1,83 @@ +/** + * 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#35415 — the approval request page's title: the record the + * request is about, linked to it only where the page read it. + * + * Direction, written before the run: with the read gate removed (the link + * drawn whatever `isReadable` says), the "not read" case REDs; with the click + * handed to the anchor, the plain-click case REDs. + */ + +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { render, cleanup, fireEvent } from '@testing-library/react'; +import { RelatedRecordActionsProvider, type RelatedRecordActionsValue } from '@object-ui/react'; +import { approvalSubjectTitle } from './approvalSubjectTitle.js'; + +const ROW = { id: 'req_1', process_label: 'Invoice Sign-off', object_name: 'invoice', record_id: 'inv_1', record_title: 'INV-1010' }; + +function host() { + const openRecord = vi.fn<(objectName: string, recordId: string | number) => void>(); + const value: RelatedRecordActionsValue = { + resolve: () => ({}), + recordHref: (objectName, recordId) => `/apps/demo/${objectName}/record/${recordId}`, + openRecord, + }; + return Object.assign(value, { openRecord }); +} + +function drawn(readable: boolean, value: RelatedRecordActionsValue | null = host()) { + const title = approvalSubjectTitle(ROW, () => readable); + const node = value ? {title?.node} : title?.node; + const { container } = render(

{node}

); + return { title, h1: container.querySelector('h1') as HTMLElement }; +} + +afterEach(() => cleanup()); + +describe('approvalSubjectTitle (objectstack#35415)', () => { + it('read by the page: the record title, as a link to the record through the host route', () => { + const { title, h1 } = drawn(true); + expect(title?.text).toBe('INV-1010'); + expect(h1.textContent).toBe('INV-1010'); + expect(h1.querySelector('a')?.getAttribute('href')).toBe('/apps/demo/invoice/record/inv_1'); + }); + + it('not read by the page (refused, unresolvable, deleted, or not yet): the record title as plain text', () => { + const { title, h1 } = drawn(false); + expect(title?.text).toBe('INV-1010'); + expect(h1.textContent).toBe('INV-1010'); + expect(h1.querySelector('a')).toBeNull(); + }); + + it('a host that routes to no record: plain text', () => { + const { h1 } = drawn(true, { resolve: () => ({}), recordHref: () => null }); + expect(h1.textContent).toBe('INV-1010'); + expect(h1.querySelector('a')).toBeNull(); + }); + + it('a plain left click is the host\'s openRecord; a modifier click is the browser\'s', () => { + const value = host(); + const { h1 } = drawn(true, value); + const link = h1.querySelector('a') as HTMLAnchorElement; + expect(fireEvent.click(link, { button: 0 })).toBe(false); + expect(value.openRecord).toHaveBeenCalledWith('invoice', 'inv_1'); + value.openRecord.mockClear(); + expect(fireEvent.click(link, { button: 0, metaKey: true })).toBe(true); + expect(value.openRecord).not.toHaveBeenCalled(); + }); + + it('no record title, or one that is the bare record id: undefined, so the page keeps its own title', () => { + const { record_title: _t, ...untitled } = ROW; + expect(approvalSubjectTitle(untitled, () => true)).toBeUndefined(); + expect(approvalSubjectTitle({ ...ROW, record_title: 'inv_1' }, () => true)).toBeUndefined(); + expect(approvalSubjectTitle({ ...ROW, object_name: '' }, () => true)).toBeUndefined(); + expect(approvalSubjectTitle(null, () => true)).toBeUndefined(); + }); +}); diff --git a/ui/packages/app-shell/src/views/approval-decision/approvalSubjectTitle.tsx b/ui/packages/app-shell/src/views/approval-decision/approvalSubjectTitle.tsx index 33655229275..3907d0451c0 100644 --- a/ui/packages/app-shell/src/views/approval-decision/approvalSubjectTitle.tsx +++ b/ui/packages/app-shell/src/views/approval-decision/approvalSubjectTitle.tsx @@ -20,6 +20,13 @@ * Where the get serves no subject title (one it could not resolve), or serves * the bare record id, the page keeps the request's own title: the header never * names the subject by a raw id. + * + * The name links only where the page itself read the record, the rule the "As + * submitted" card's link and the record pointer card's title follow + * (objectui#12557, objectui#11878): the page's own reads report what they + * learned (`recordReadReport.ts`), and the title reads nothing itself. A + * refused or unresolvable subject, and one the platform asserted deleted (which + * the page never reads), is named as plain text. */ import * as React from 'react'; @@ -40,9 +47,9 @@ function textOf(row: Record, key: string): string | undefined { * A plain left click is the host's in-app navigation; a modifier or middle * click keeps the anchor's own new-tab behaviour. */ -function ApprovalSubjectLink({ objectName, recordId, title }: { objectName: string; recordId: string; title: string }) { +function ApprovalSubjectLink({ objectName, recordId, title, readable }: { objectName: string; recordId: string; title: string; readable: boolean }) { const recordLinks = useRelatedRecordActions(); - const href = recordLinks?.recordHref ? recordLinks.recordHref(objectName, recordId) : null; + const href = readable && recordLinks?.recordHref ? recordLinks.recordHref(objectName, recordId) : null; if (!href) return <>{title}; return ( boolean, +): RecordHeaderTitle | undefined { if (!request || typeof request !== 'object') return undefined; const row = request as Record; const title = textOf(row, 'record_title'); @@ -73,6 +84,8 @@ export function approvalSubjectTitle(request: unknown): RecordHeaderTitle | unde if (!title || !objectName || !recordId || title === recordId) return undefined; return { text: title, - node: , + node: ( + + ), }; } diff --git a/ui/packages/app-shell/src/views/approval-decision/recordReadReport.ts b/ui/packages/app-shell/src/views/approval-decision/recordReadReport.ts new file mode 100644 index 00000000000..d891be1d3d0 --- /dev/null +++ b/ui/packages/app-shell/src/views/approval-decision/recordReadReport.ts @@ -0,0 +1,53 @@ +/** + * 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. + */ + +/** + * What the page's own record reads learned about a record (objectstack#35415). + * + * The approval request page links its title to the record the request is + * about only where the page itself could read that record: the same rule the + * "As submitted" card's "Open record" link and the record pointer card's title + * follow (objectui#12557, objectui#11878). A refused or unresolvable target, + * and one the platform asserted deleted (which the page never reads), yields + * no link. + * + * The title does not read the record again. The reads the page already makes + * (`SubmittedRecord`'s current read, `RecordPreviewCard`'s read) report each + * answer here, and the host that provides the report collects them. No + * provider (every page but the request page): reporting does nothing. + */ + +import * as React from 'react'; + +/** Called with each settled read: the record read (`true`) or it did not (`false`). */ +export type RecordReadReport = (objectName: string, recordId: string, readable: boolean) => void; + +export const RecordReadReportContext = React.createContext(null); + +/** The key a report is collected under. */ +export function recordReadKey(objectName: string, recordId: string): string { + return `${objectName}::${recordId}`; +} + +/** + * Report a read's answer to the page's collector, once it has settled. Pass + * `null` for either half while the read addresses nothing, and `'loading'` + * until it answers. + */ +export function useReportRecordRead( + objectName: string | null | undefined, + recordId: string | null | undefined, + status: 'loading' | 'readable' | 'unreadable' | 'absent', +): void { + const report = React.useContext(RecordReadReportContext); + React.useEffect(() => { + if (!report || !objectName || !recordId) return; + if (status !== 'readable' && status !== 'unreadable') return; + report(objectName, recordId, status === 'readable'); + }, [report, objectName, recordId, status]); +} diff --git a/ui/packages/app-shell/src/views/record-preview/RecordPreviewCard.tsx b/ui/packages/app-shell/src/views/record-preview/RecordPreviewCard.tsx index 833666f60ba..0151868f971 100644 --- a/ui/packages/app-shell/src/views/record-preview/RecordPreviewCard.tsx +++ b/ui/packages/app-shell/src/views/record-preview/RecordPreviewCard.tsx @@ -120,6 +120,7 @@ import { import type { QueryParams } from '@object-ui/types'; import { Link2Off, Loader2 } from 'lucide-react'; import { servedObjectLabel } from '../../hooks/servedObjectLabel.js'; +import { useReportRecordRead } from '../approval-decision/recordReadReport.js'; /** * The one read the card makes. Structural, so the console's adapter satisfies @@ -226,6 +227,9 @@ export function RecordPreviewCard({ objectName, recordId, dataSource, className const { objectLabel } = useObjectLabel(); // The host's record-URL builder (see "The link" in the module header). const recordLinks = useRelatedRecordActions(); + // What this read learned, for a page that links the same record elsewhere + // only where it reads (objectstack#35415, `recordReadReport.ts`). + useReportRecordRead(targetObject, targetRecord, answer && answer.key === targetKey ? answer.status : 'loading'); if (targetObject === null) { return ;