Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/35483-approval-band-once.md
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 9 additions & 12 deletions ui/packages/plugin-detail/src/DetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -328,11 +328,9 @@ export const DetailView: React.FC<DetailViewProps> = ({
// 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
Expand Down Expand Up @@ -1763,12 +1761,11 @@ export const DetailView: React.FC<DetailViewProps> = ({
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.
Expand Down
24 changes: 9 additions & 15 deletions ui/packages/plugin-detail/src/RecordPageColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = <SchemaRenderer key={key} schema={toRenderableSchema(node)} />;
if (node?.type !== 'record:details' || index === firstDetails) return drawn;
return (
<ApprovalBandContext.Provider key={key} value={false}>
{drawn}
</ApprovalBandContext.Provider>
);
});
return <ApprovalBandOnceScope>{drawNodes(nodes)}</ApprovalBandOnceScope>;
}

const LINE_BUTTON =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(
<InlineEditProvider canEdit={false} locked>
<RecordContextProvider
objectName="quote"
recordId="Q1"
data={DATA}
objectSchema={quote as any}
dataSource={{ find: async () => [], findOne: async () => DATA } as any}
>
{scoped ? <ApprovalBandOnceScope><SchemaRenderer schema={page as any} /></ApprovalBandOnceScope> : <SchemaRenderer schema={page as any} />}
</RecordContextProvider>
</InlineEditProvider>,
);
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);
});
});
107 changes: 101 additions & 6 deletions ui/packages/plugin-detail/src/__tests__/RecordPageColumns.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
}));
Expand All @@ -42,7 +42,7 @@ vi.mock('@object-ui/react', async (importOriginal) => {
return (
<div data-node={schema?.type} data-cap={React.useContext(DetailsColumnCapContext)}>
{schema?.properties?.objectName ?? schema?.type}
{Body && <Body />}
{Body && <Body schema={schema} />}
</div>
);
};
Expand Down Expand Up @@ -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 <p role="status">Insufficient permissions to view details.</p>;
}
return (
<DetailView
schema={{ type: 'detail-view', objectName: 'quote', showHeader: p.showHeader ?? false, data: { id: 'Q1', name: 'Q-1' }, sections: [] } as any}
inlineEdit
recordFromHost
/>
);
};
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<string, unknown> = {}) => ({
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<typeof slotted>, approval: { locked?: boolean; approvalPending?: boolean; canEdit?: boolean }) =>
render(
<InlineEditProvider canEdit={approval.canEdit ?? false} locked={approval.locked} approvalPending={approval.approvalPending}>
<RecordPageColumns tier="wide" columns={columns} />
</InlineEditProvider>,
);
/** 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
Expand Down
Loading
Loading