diff --git a/.changeset/35483-approval-band-once.md b/.changeset/35483-approval-band-once.md new file mode 100644 index 00000000000..e18b0c813cb --- /dev/null +++ b/.changeset/35483-approval-band-once.md @@ -0,0 +1,10 @@ +--- +'@object-ui/plugin-detail': patch +--- + +fix(plugin-detail): a laid-out record page whose first details block draws no body still shows the approval band + +Clause-②: no +Metadata-protocol: none + +The laid-out record page draws the record's approval band ("Locked for approval" / "In approval · editable", with its recall lever and tally) once per page. It used to give the band to the first `record:details` node of the details column and tell every later one not to draw it, so on a slotted page whose `details` slot puts first a `record:details` the reader may not see (its `requiredPermissions` withheld) or one that draws its own header (`showHeader: true`), a locked record showed no band at all. The details column now draws the band by the first details body that reaches its place, the rule a page drawn as written already follows: the next part draws it. Every other page reads as before, the band stays above a body table, and whether the band reads locked or editable (a `lockRecord: false` approval node) is unchanged. diff --git a/ui/packages/plugin-detail/src/DetailView.tsx b/ui/packages/plugin-detail/src/DetailView.tsx index 998bd2b9dea..d4b87aa95c4 100644 --- a/ui/packages/plugin-detail/src/DetailView.tsx +++ b/ui/packages/plugin-detail/src/DetailView.tsx @@ -37,7 +37,7 @@ import { } from 'lucide-react'; import { DetailSection } from './DetailSection'; import { EmptySectionsFold, EmptySectionsLine } from './EmptySectionsFold'; -import { ApprovalBandContext, EmptySectionsLineContext, useApprovalBandOnce, useDefaultRecordPage } from './defaultRecordPage'; +import { EmptySectionsLineContext, useApprovalBandOnce, useDefaultRecordPage } from './defaultRecordPage'; import { DetailTabs } from './DetailTabs'; import { SectionGroup } from './SectionGroup'; import { HeaderHighlight } from './HeaderHighlight'; @@ -328,11 +328,9 @@ export const DetailView: React.FC = ({ // approval band below is live, per-viewer workflow state, not document // content, so it does not print. const isPrintPage = usePrintPage() !== null; - // objectstack#35253 — `false` on every details part of a split default page - // but the first: the approval band is the record's, drawn once per page. - // objectstack#35483 / objectstack#35484 — and on a page drawn as written, - // the first body to reach the band's place draws it (`ApprovalBandOnceScope`). - const drawsApprovalBand = React.useContext(ApprovalBandContext); + // objectstack#35253, objectstack#35483, objectstack#35484 — the approval + // band is the record's, drawn once per page: under a page's + // `ApprovalBandOnceScope` the first body to reach the band's place draws it. const approvalBandOnce = useApprovalBandOnce(); // objectstack#27055, objectstack#35019 — a record page's details body folds // its entirely empty sections into one line (`EmptySectionsLine`): every @@ -1763,12 +1761,11 @@ export const DetailView: React.FC = ({ status field through `record:details`, the way `record:path` leaves the current stage to it. - objectstack#35253 — and once per page: a default page split around a - body table draws it on its first details part only - (`ApprovalBandContext`), and on a page drawn as written by its - first details body (`ApprovalBandOnceScope`). */} - {inlineEdit && schema.showHeader === false && !isPrintPage && drawsApprovalBand && approvalBandOnce.mark} - {inlineEdit && schema.showHeader === false && !isPrintPage && drawsApprovalBand && approvalBandOnce.draws && (() => { + objectstack#35253 — and once per page: under the page's + `ApprovalBandOnceScope`, by the first details body that reaches + this place (objectstack#35483, objectstack#35484). */} + {inlineEdit && schema.showHeader === false && !isPrintPage && approvalBandOnce.mark} + {inlineEdit && schema.showHeader === false && !isPrintPage && approvalBandOnce.draws && (() => { // Two independent facts, not one (objectui#2902): // // isPending — an approval is running on this record. diff --git a/ui/packages/plugin-detail/src/RecordPageColumns.tsx b/ui/packages/plugin-detail/src/RecordPageColumns.tsx index a6d9ef63918..11cf792db84 100644 --- a/ui/packages/plugin-detail/src/RecordPageColumns.tsx +++ b/ui/packages/plugin-detail/src/RecordPageColumns.tsx @@ -23,7 +23,7 @@ import { } from './synth/recordPageColumns'; import { useDetailTranslation } from './useDetailTranslation'; import { RecordBodyTablesContext, RelatedEnlargeContext, RelatedListEnlargedContext } from './relatedListCompact'; -import { ApprovalBandContext, DefaultRecordPageContext, DetailsColumnCapContext } from './defaultRecordPage'; +import { ApprovalBandOnceScope, DefaultRecordPageContext, DetailsColumnCapContext } from './defaultRecordPage'; import { RECORD_TAB_OVERVIEW, RecordTabRow, type RecordTab, type RecordTabArrangeEdit } from './RecordTabRow'; import { RECORD_TAB_APPROVALS, @@ -245,22 +245,16 @@ function drawNodes(nodes: any[]): React.ReactNode { /** * The details column's nodes (objectstack#35253): the synthesized page splits * its details around a body table, one `record:details` per run of sections, - * and the record's approval band is drawn by the FIRST part alone — above the - * table — so the page shows one band, not one per part. A context provider - * adds no DOM, so the column's siblings stay siblings (`drawNodes`). + * and the record's approval band is drawn once per page — by the first details + * body that reaches the band's place (`ApprovalBandOnceScope`), above the + * table. objectstack#35483 / objectstack#35484 — the same rule as a page drawn + * as written: a first `record:details` that draws no body (withheld by its + * `requiredPermissions`, or drawing its own header) leaves the band to the next + * part instead of taking it off the page. A context provider adds no DOM, so + * the column's siblings stay siblings (`drawNodes`). */ function drawDetailsNodes(nodes: any[]): React.ReactNode { - const firstDetails = nodes.findIndex((node) => node?.type === 'record:details'); - return nodes.map((node, index) => { - const key = (node && typeof node === 'object' && node.id) || index; - const drawn = ; - if (node?.type !== 'record:details' || index === firstDetails) return drawn; - return ( - - {drawn} - - ); - }); + return {drawNodes(nodes)}; } const LINE_BUTTON = diff --git a/ui/packages/plugin-detail/src/__tests__/DetailView.approvalBandOnce-35484.test.tsx b/ui/packages/plugin-detail/src/__tests__/DetailView.approvalBandOnce-35484.test.tsx index 6911bcbcb1c..8bac0a4a8ea 100644 --- a/ui/packages/plugin-detail/src/__tests__/DetailView.approvalBandOnce-35484.test.tsx +++ b/ui/packages/plugin-detail/src/__tests__/DetailView.approvalBandOnce-35484.test.tsx @@ -16,15 +16,24 @@ * still reads editable, and a first node that draws no band leaves the band * to the next. Measured on the body the `record:details` block mounts * (`showHeader: false`, inline edit on); the host wiring is pinned in - * `app-shell/src/views/RecordDetailView.approvalBandOnce-35484.test.tsx`. + * `app-shell/src/views/RecordDetailView.recordOpenRequests-12701.test.tsx` + * (an authored page, drawn by the same host branch as the tabs fallback). + * The second describe draws the synthesized page's `page:tabs` fallback + * through the real renderers (objectstack#35483). */ import * as React from 'react'; -import { describe, it, expect, afterEach } from 'vitest'; -import { render, screen, cleanup } from '@testing-library/react'; -import { InlineEditProvider } from '@object-ui/react'; +import { describe, it, expect, afterEach, vi } from 'vitest'; +import { render, screen, cleanup, waitFor } from '@testing-library/react'; +import { InlineEditProvider, RecordContextProvider, SchemaRenderer } from '@object-ui/react'; +import '../index'; import { DetailView } from '../DetailView'; import { ApprovalBandOnceScope } from '../defaultRecordPage'; +import { buildDefaultPageColumns } from '../synth/recordPageColumns'; +import { buildDefaultPageSchema } from '../synth/buildDefaultPageSchema'; + +/** `useRecordEditable`'s explain probe, answered with its fail-open 501 (the binding suites do the same). */ +vi.stubGlobal('fetch', (async () => new Response(null, { status: 501 })) as unknown as typeof globalThis.fetch); afterEach(cleanup); @@ -97,3 +106,74 @@ describe('one approval band on a page drawn as written (objectstack#35484, objec expect(container.querySelectorAll('[data-approval-band-mark]').length).toBe(2); }); }); + +/** + * objectstack#35483 — the synthesized page that falls back to its `page:tabs` + * strip. `buildDefaultPageColumns` lays out every page the synthesizer writes + * on its own; a slotted page that places a `page:tabs` node in a strip slot + * (`highlights` here) carries two strips, which the partition cannot read, so + * the host draws the page as written, inside `ApprovalBandOnceScope`. Split + * around a body table, its 概览 tab holds two `record:details` parts: drawn by + * the real `record:details` and `page:tabs` renderers, the band is drawn once. + */ +describe('one approval band on the synthesized page\'s page:tabs fallback (objectstack#35483)', () => { + const quote = { + name: 'quote', + fields: { + name: { type: 'text', label: 'Name', group: 'basic' }, + terms: { type: 'textarea', label: 'Terms', group: 'terms' }, + }, + fieldGroups: [{ key: 'basic' }, { key: 'lines', relatedList: 'quote_line_item' }, { key: 'terms' }], + }; + const SECTIONS = [ + { name: 'basic', label: 'Basic', fields: ['name'] }, + { name: 'terms', label: 'Terms', fields: ['terms'] }, + ]; + const LINES = { objectName: 'quote_line_item', relationshipField: 'quote', title: 'Lines', isPrimary: true }; + const STRIP_TABS = { type: 'page:tabs', properties: { items: [{ label: 'Extra', value: 'extra', children: [] }] } }; + const fallback = (related: unknown[]) => + buildDefaultPageSchema(quote as any, { sections: SECTIONS as any, related: related as any, slots: { highlights: [STRIP_TABS] } as any }); + const overviewOf = (page: any) => page.regions[0].components.filter((n: any) => n.type === 'page:tabs').at(-1).properties.items[0].children; + const DATA = { id: 'Q1', name: 'Q-1', terms: 'net 30' }; + const drawLocked = (page: unknown, scoped = true) => + render( + + [], findOne: async () => DATA } as any} + > + {scoped ? : } + + , + ); + const marks = () => document.querySelectorAll('[data-approval-band-mark]'); + + it('the page cannot be laid out, and its overview holds two details parts around the body table', () => { + const page = fallback([LINES]); + expect(buildDefaultPageColumns(page)).toBeNull(); + expect(overviewOf(page).map((n: any) => n.type)).toEqual(['record:details', 'record:related_list', 'record:details']); + }); + + it('two details parts under the host scope: "Locked for approval" once', async () => { + drawLocked(fallback([LINES])); + await waitFor(() => expect(marks()).toHaveLength(2)); + expect(screen.getAllByText('Locked for approval')).toHaveLength(1); + }); + + it('CONTROL: the same page outside the scope draws it on each part (what the scope holds)', async () => { + drawLocked(fallback([LINES]), false); + await waitFor(() => expect(screen.getAllByText('Locked for approval')).toHaveLength(2)); + }); + + it('CONTROL: one details part on the fallback page draws its one band', async () => { + const page = fallback([]); + expect(buildDefaultPageColumns(page)).toBeNull(); + expect(overviewOf(page).map((n: any) => n.type)).toEqual(['record:details']); + drawLocked(page); + await waitFor(() => expect(marks()).toHaveLength(1)); + expect(screen.getAllByText('Locked for approval')).toHaveLength(1); + }); +}); diff --git a/ui/packages/plugin-detail/src/__tests__/RecordPageColumns.test.tsx b/ui/packages/plugin-detail/src/__tests__/RecordPageColumns.test.tsx index 02bcf25b384..52bde4065cd 100644 --- a/ui/packages/plugin-detail/src/__tests__/RecordPageColumns.test.tsx +++ b/ui/packages/plugin-detail/src/__tests__/RecordPageColumns.test.tsx @@ -15,10 +15,10 @@ * column beside the other tabs on a wide full page (objectstack#35890), and * that no width draws the right rail of summary cards any more. * - * One describe (objectstack#35253) opts each `record:details` stub into - * mounting the `DetailView` the real block mounts (`showHeader: false`, - * inline edit on), so the approval band it draws is measured on the laid-out - * page; every other describe keeps the bare stub. + * Two describes (objectstack#35253, objectstack#35483) opt each + * `record:details` stub into mounting the `DetailView` the real block mounts + * (`showHeader: false`, inline edit on), so the approval band it draws is + * measured on the laid-out page; every other describe keeps the bare stub. */ import * as React from 'react'; @@ -30,7 +30,7 @@ import { RecordContextProvider } from '@object-ui/react'; const harness = vi.hoisted(() => ({ /** Set by the objectstack#35253 describe: a `record:details` stub mounts `body`. */ detailBodies: false, - body: null as React.ComponentType | null, + body: null as React.ComponentType<{ schema: any }> | null, /** The content width every element reports (jsdom lays nothing out). */ width: 0, })); @@ -42,7 +42,7 @@ vi.mock('@object-ui/react', async (importOriginal) => { return (
{schema?.properties?.objectName ?? schema?.type} - {Body && } + {Body && }
); }; @@ -430,6 +430,101 @@ describe('RecordPageColumns — the approval band is drawn once per page (object }); }); +/** + * objectstack#35483 / objectstack#35484 — the band is not dropped when the + * FIRST details part draws no body. A slotted page's `details` slot places the + * author's own `record:details` nodes in the laid-out details column; the first + * may draw no band of its own: its `requiredPermissions` withheld (the real + * block draws its insufficient-permissions notice in place of the body, + * `record-blocks.requiredPermissions-gate.test.tsx`) or `showHeader: true` + * (the body draws its own header, and no band). The column draws the band once + * by the first body that reaches its place (`ApprovalBandOnceScope`), so the + * next part draws it. Before, every part after the first was told not to draw + * it and such a page showed no band at all, on a locked record. + */ +describe('RecordPageColumns — a first details part that draws no band leaves it to the next (objectstack#35483, objectstack#35484)', () => { + /** What `record:details` mounts for its node: the notice when withheld, else its body. */ + const PartBody = ({ schema }: { schema: any }) => { + const p = { ...schema, ...(schema?.properties ?? {}) }; + if (Array.isArray(p.requiredPermissions) && p.requiredPermissions.length > 0) { + return

Insufficient permissions to view details.

; + } + return ( + + ); + }; + beforeEach(() => { + harness.detailBodies = true; + harness.body = PartBody; + }); + afterEach(() => { + harness.detailBodies = false; + harness.body = null; + }); + + const quote = { name: 'quote', fields: { name: { type: 'text', label: 'Name' }, terms: { type: 'textarea', label: 'Terms' } } }; + const part = (id: string, props: Record = {}) => ({ + type: 'record:details', + id, + properties: { sections: [{ name: id, label: id, fields: [id === 'first' ? 'name' : 'terms'] }], ...props }, + }); + const slotted = (details: any[]) => buildDefaultPageColumns(buildDefaultPageSchema(quote, { slots: { details } } as any))!; + const drawPage = (columns: ReturnType, approval: { locked?: boolean; approvalPending?: boolean; canEdit?: boolean }) => + render( + + + , + ); + /** The details parts (by node id) whose subtree shows `text`. */ + const partsShowing = (container: HTMLElement, text: string) => + Array.from(column(container, 'details')!.querySelectorAll('[data-node="record:details"]')) + .map((node, index) => ({ node, index })) + .filter(({ node }) => node.textContent?.includes(text)) + .map(({ index }) => index); + + it('the slotted page lays its two details nodes out in the details column', () => { + expect(slotted([part('first'), part('second')]).details.map((n: any) => n.id)).toEqual(['first', 'second']); + }); + + for (const [why, props] of [ + ['withheld by its requiredPermissions', { requiredPermissions: ['quote.audit'] }], + ['drawing its own header', { showHeader: true }], + ] as const) { + it(`a first part ${why}: "Locked for approval" once, on the second part`, () => { + const { container } = drawPage(slotted([part('first', props), part('second')]), { locked: true }); + expect(screen.getAllByText('Locked for approval')).toHaveLength(1); + expect(partsShowing(container, 'Locked for approval')).toEqual([1]); + }); + } + + it('a `lockRecord: false` approval behind a withheld first part reads editable, once — never locked', () => { + drawPage(slotted([part('first', { requiredPermissions: ['quote.audit'] }), part('second')]), { approvalPending: true, locked: false, canEdit: true }); + expect(screen.queryByText('Locked for approval')).toBeNull(); + expect(screen.getAllByText('In approval · editable')).toHaveLength(1); + }); + + it('CONTROL: two drawing parts keep the band on the first, once', () => { + const { container } = drawPage(slotted([part('first'), part('second')]), { locked: true }); + expect(screen.getAllByText('Locked for approval')).toHaveLength(1); + expect(partsShowing(container, 'Locked for approval')).toEqual([0]); + }); + + it('CONTROL: a single slotted details part draws its one band', () => { + drawPage(slotted([part('first')]), { locked: true }); + expect(screen.getAllByText('Locked for approval')).toHaveLength(1); + }); + + it('CONTROL: a single withheld part draws no band and no body (nothing on the page reaches its place)', () => { + drawPage(slotted([part('first', { requiredPermissions: ['quote.audit'] })]), { locked: true }); + expect(screen.queryByText('Locked for approval')).toBeNull(); + expect(screen.getByText('Insufficient permissions to view details.')).toBeTruthy(); + }); +}); + /** * objectstack#36147 — the field area is one list wherever it sits beside other * tabs or is one of them: the drawer, the phone, the narrow page and the diff --git a/ui/packages/plugin-detail/src/defaultRecordPage.ts b/ui/packages/plugin-detail/src/defaultRecordPage.ts index a881ff6276c..c930b89e62d 100644 --- a/ui/packages/plugin-detail/src/defaultRecordPage.ts +++ b/ui/packages/plugin-detail/src/defaultRecordPage.ts @@ -48,36 +48,21 @@ export function useDefaultRecordPage(): boolean { export const EmptySectionsLineContext = React.createContext(false); /** - * Whether the `DetailView` drawn here draws the record's approval band (the - * "Locked for approval" / "In approval" status chip, its recall lever and its - * tally) when its own header is suppressed (objectstack#35253). - * - * The band is the RECORD's state, so a record page draws it once. The - * synthesized default page splits its details around a body table — one - * `record:details` node per run of sections — and every part used to draw it, - * so the page read as if two locks applied. The laid-out page - * (`RecordPageColumns`) sets `false` around every details part after the - * first, which keeps the band above the body table. Default `true`: a - * standalone `DetailView` and the drawer keep their band, and an authored - * page's details bodies draw one between them ({@link ApprovalBandOnceScope}). Whether the band reads locked or editable is untouched — that is - * `resolveApprovalLock`'s rule (a `lockRecord: false` node is never locked). - * - * Module-internal, the way `EmptySectionsLineContext` is: neither a - * `DetailView` prop nor a `DetailViewSchema` key, and not in the barrel. - */ -export const ApprovalBandContext = React.createContext(true); - -/** - * One approval band per page drawn as written (objectstack#35483, - * objectstack#35484). A page the host draws through one `SchemaRenderer` — an - * authored page, or a synthesized page whose strip cannot be laid out — cannot - * set {@link ApprovalBandContext} per details node, so each `record:details` - * body drew its own band. Under {@link ApprovalBandOnceScope} every body that - * reaches the band's place marks it, and only the FIRST mark in document order - * draws the band: a first node that draws no body leaves no mark, and a - * `lockRecord: false` first node draws its own (editable) band, the page's one. - * The band keeps its recall lever and its tally. Outside a scope every body - * draws its band as before. + * One approval band per record page (objectstack#35253, objectstack#35483, + * objectstack#35484): the band (the "Locked for approval" / "In approval" + * status chip, its recall lever and its tally, drawn by a `DetailView` whose + * own header is suppressed) is the RECORD's state, so a page draws it once, + * however many `record:details` bodies it places. Every page host mounts + * {@link ApprovalBandOnceScope} around its details: the laid-out page around + * its details column (`RecordPageColumns`), and the host around a page drawn + * as written (an authored page, or a synthesized page whose strip cannot be + * laid out). Under the scope every body that reaches the band's place marks + * it, and only the FIRST mark in document order draws the band: a first node + * that draws no body leaves no mark, and a `lockRecord: false` first node + * draws its own (editable) band, the page's one. The band keeps its recall + * lever and its tally. Outside a scope — a standalone `DetailView` (the `detail-view` + * node, an overlay panel) — every body draws its band as before. Whether the band reads locked + * or editable is untouched: that is `resolveApprovalLock`'s rule. */ export interface ApprovalBandOnce { /** Mark a body's band place; returns the unmark. `onChange` re-renders the body when the first mark moves. */