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
14 changes: 14 additions & 0 deletions .changeset/35941-owner-once-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@object-ui/plugin-detail': patch
---

fix(plugin-detail): the record page names the owner once when a details section already shows the owner field

Clause-②: no
Metadata-protocol: none

On the default record page, the meta line at the foot of the details column (created · updated · owner · id) always named the record's owner, and a details section usually showed the `owner_id` field as well: in a declared field group, in the "Other" group that collects fields no declared group takes, or in the derived section of an object that declares no groups. So the owner was shown twice. The meta line already left the owner out when the highlight strip showed it, and the default page no longer draws a strip, so that rule never applied.

The meta line now also leaves the owner out when a details section of the page's own record draws the `owner_id` row. The owner then shows once, as the section's field, where it can also be changed. The sections report the rows they actually draw, so the owner stays on the meta line whenever no section draws it: the field is hidden, the reader may not read it, a `visibleWhen` hides it or its group, or its section is collapsed. When a collapsed section holding it is opened, the owner moves from the meta line to that section. The field groups are drawn as declared. The highlight strip rule is unchanged.

This changes the laid-out default record page, the one `RecordPageColumns` draws. A default page whose tab strip cannot be laid out keeps the strip-only rule. No metadata key, value or default changes, and no prop, export or locale key is added.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@
* - until objectstack#35891 the phone header drew four highlights (the
* owner past them, so the meta line named it) and the desktop strip all
* five (the strip named the owner, the meta line did not);
* - the default page draws no strip now, so at 390 px and at 1440 px the
* meta line names the owner.
* - the default page draws no strip now, and the body's details sections
* draw `owner_id` (here in the auto-derived section, the object declaring
* no field groups).
*
* objectstack#35941 supersedes the pin this file held, "no strip, and the meta
* line names the owner": the maintainer's ruling (card comment 7056427422,
* option A, 「底部行不再显示」) is that when the body renders `owner_id` the
* meta line leaves the owner out, so the owner appears once, as the body
* field. #28909's intent is unchanged: the owner is on the page at every
* width, exactly once. Both halves are pinned at 390 px and at 1440 px: the
* body draws the owner (the meta line does not), and an object whose body
* draws no `owner_id` (the field is `hidden`) keeps the owner on the meta
* line.
*/

import * as React from 'react';
Expand Down Expand Up @@ -124,14 +135,22 @@ function metadataFor(objects: unknown[]) {
} as never;
}

function mountPage() {
/** The same lead whose body draws no `owner_id`: the field is hidden. */
const OBJECTS_OWNER_HIDDEN = [
{
...OBJECTS[0],
fields: { ...OBJECTS[0].fields, owner_id: { ...OBJECTS[0].fields.owner_id, hidden: true } },
},
];

function mountPage(objects: unknown[] = OBJECTS) {
render(
<MemoryRouter initialEntries={[`/apps/${APP}/${LEAD}/record/r-1`]}>
<MetadataCtx.Provider value={metadataFor(OBJECTS)}>
<MetadataCtx.Provider value={metadataFor(objects)}>
<Routes>
<Route
path="/apps/:appName/:objectName/record/:recordId"
element={<RecordDetailView dataSource={makeDataSource() as never} objects={OBJECTS} onEdit={() => {}} />}
element={<RecordDetailView dataSource={makeDataSource() as never} objects={objects as never} onEdit={() => {}} />}
/>
</Routes>
</MetadataCtx.Provider>
Expand All @@ -154,6 +173,8 @@ async function metaLineLoaded(): Promise<HTMLElement> {
}

const ownerEntry = (metaLine: HTMLElement) => metaLine.querySelector('[data-record-meta-owner]');
/** How many times the owner's name is painted on the whole page. */
const ownerCount = () => document.body.textContent!.split('Ada Admin').length - 1;

beforeEach(() => {
cleanup();
Expand Down Expand Up @@ -182,19 +203,36 @@ describe('the owner at every width, once (objectstack#28909)', () => {
// Until objectstack#35891 the default page drew a strip of the declared
// highlights: four on a phone (the owner past them, so the meta line named
// it) and all five on a desktop (the strip named the owner, the meta line
// did not). The default page draws no strip now, at any width, so the meta
// line names the owner at both.
// did not). The default page draws no strip now, at any width. The body
// draws `owner_id`, so the owner is that field and the meta line leaves it
// out (objectstack#35941, ruling 7056427422).
it.each([
['a phone', 390],
['a desktop', 1440],
])('on %s: no strip, and the meta line names the owner', async (_face, width) => {
])('on %s: no strip, the body draws the owner, and the meta line does not', async (_face, width) => {
setWidth(width);
mountPage();
const metaLine = await metaLineLoaded();
expect(document.querySelector('[data-highlights-face]')).toBeNull();
await waitFor(() => expect(ownerCount()).toBe(1));
expect(ownerEntry(metaLine)).toBeNull();
expect(metaLine.textContent).not.toContain('Ada Admin');
// The rest of the meta line is still drawn.
expect(metaLine.querySelector('[data-record-meta-id]')!.textContent).toBe('r-1');
});

it.each([
['a phone', 390],
['a desktop', 1440],
])('on %s: a body that draws no owner_id keeps the owner on the meta line', async (_face, width) => {
setWidth(width);
mountPage(OBJECTS_OWNER_HIDDEN);
const metaLine = await metaLineLoaded();
expect(document.querySelector('[data-highlights-face]')).toBeNull();
const owner = ownerEntry(metaLine);
expect(owner).toBeTruthy();
expect(owner!.textContent).toContain('Ada Admin');
expect(ownerCount()).toBe(1);
// The rest of the meta line is still drawn.
expect(metaLine.querySelector('[data-record-meta-id]')!.textContent).toBe('r-1');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/**
* 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#35941 — the record page names the owner ONCE when its body draws
* `owner_id`.
*
* The maintainer's ruling (7056427422, option A): when a field group on the
* record page renders `owner_id`, the bottom meta line leaves the owner out,
* so the owner appears once, as the body field, where it can be changed; when
* no group renders it, the meta line shows the owner as before; the body's
* groups stay as declared.
*
* The page is composed here the way `RecordDetailView` composes the default
* page: the sections from `deriveRecordDetailSections` (the declared groups,
* the "Other" bucket, or the auto split), the page from
* `buildDefaultPageSchema`, its columns from `buildDefaultPageColumns`, and
* `RecordPageColumns` drawing the real `record:details` block with the
* `RecordMetaFooter` closing the details column. So "the body draws the owner"
* is read from the sections the block actually mounts, and the owner is
* counted over the whole page.
*
* The strip half of the rule (a highlight strip that draws the owner) is
* pinned in `@object-ui/plugin-detail`'s `RecordMetaFooter.ownerOnce-28868`
* and `RecordMetaFooter.drawnStrip-28909`, unchanged.
*/

import * as React from 'react';
import { describe, it, expect, beforeAll, beforeEach, afterEach, vi } from 'vitest';
import { render, cleanup, fireEvent, within } from '@testing-library/react';
import { RecordContextProvider } from '@object-ui/react';
// Module scope, so the registry's cold transform lands in the import phase.
import {
RecordMetaFooter,
RecordPageColumns,
buildDefaultPageColumns,
buildDefaultPageSchema,
} from '@object-ui/plugin-detail';
import { deriveRecordDetailSections } from './recordDetailSections';

const OBJECT = 'os_35941_contact';
const OWNER_NAME = 'Ada Owner';

/** Distinct values, so every value is read off the page by what it paints. */
const RECORD = {
id: 'C-35941',
name: 'Grace Hopper',
email: 'grace@example.com',
phone: 'phone-value',
owner_id: { id: 'u-ada', name: OWNER_NAME },
created_at: '2026-10-16T00:00:00.000Z',
updated_at: '2026-10-18T00:00:00.000Z',
};

const FIELDS = {
name: { type: 'text', label: 'Name' },
email: { type: 'email', label: 'Email' },
phone: { type: 'text', label: 'Phone' },
owner_id: { type: 'lookup', label: 'Owner', reference: 'sys_user' },
};

type ObjectDef = { name: string; fields: Record<string, Record<string, unknown>>; fieldGroups?: unknown[] };

/** The default record page of `objectDef`, laid out wide, with its meta line. */
function renderDefaultPage(objectDef: ObjectDef) {
const sections = deriveRecordDetailSections(objectDef, { moreDetails: 'More details', ungrouped: 'Other' });
type SynthOptions = NonNullable<Parameters<typeof buildDefaultPageSchema>[1]>;
const page = buildDefaultPageSchema(objectDef as Parameters<typeof buildDefaultPageSchema>[0], {
sections: sections as SynthOptions['sections'],
});
const columns = buildDefaultPageColumns(page);
expect(columns, 'the default page must lay out into columns').not.toBeNull();
const dataSource = { getObjectSchema: async () => objectDef };
return render(
<RecordContextProvider
objectName={objectDef.name}
recordId={RECORD.id}
data={RECORD}
objectSchema={objectDef}
dataSource={dataSource as never}
>
<RecordPageColumns
tier="wide"
columns={columns!}
footer={<RecordMetaFooter data={RECORD} objectSchema={objectDef} objectName={objectDef.name} />}
/>
</RecordContextProvider>,
);
}

const footerOf = (container: HTMLElement) =>
container.querySelector('[data-testid="record-meta-footer"]') as HTMLElement | null;
const footerOwner = (container: HTMLElement) => footerOf(container)?.querySelector('[data-record-meta-owner]') ?? null;
const detailsColumn = (container: HTMLElement) =>
container.querySelector('[data-record-column="details"]') as HTMLElement;
/** How many times the owner's name is painted on the whole page. */
const ownerCount = (container: HTMLElement) => container.textContent!.split(OWNER_NAME).length - 1;

beforeAll(() => Object.defineProperty(window, 'innerWidth', { configurable: true, value: 1280 }));

beforeEach(() => {
// `useRecordEditable` asks the explain endpoint; its answer is orthogonal to
// which fields the body draws, so a double answers it.
vi.stubGlobal('fetch', vi.fn(async () => ({
ok: true,
status: 200,
json: async () => ({ allowed: true }),
text: async () => '{"allowed":true}',
})) as never);
});

afterEach(() => {
cleanup();
vi.unstubAllGlobals();
});

describe('the body draws owner_id: the meta line leaves the owner out (objectstack#35941)', () => {
it('a declared group holding owner_id: the owner is painted once, in the body', () => {
const { container } = renderDefaultPage({
name: OBJECT,
fieldGroups: [
{ key: 'basics', label: 'Basics' },
{ key: 'ownership', label: 'Ownership' },
],
fields: {
name: { ...FIELDS.name, group: 'basics' },
email: { ...FIELDS.email, group: 'basics' },
phone: { ...FIELDS.phone, group: 'basics' },
owner_id: { ...FIELDS.owner_id, group: 'ownership' },
},
});
// Live control: the body and the meta line both drew.
expect(within(detailsColumn(container)).getByText('grace@example.com')).toBeTruthy();
expect(footerOf(container)!.querySelector('[data-record-meta-id]')!.textContent).toBe('C-35941');

expect(footerOwner(container)).toBeNull();
expect(ownerCount(container)).toBe(1);
// The group stays as declared: its heading and the owner row are there.
expect(within(detailsColumn(container)).getByText('Ownership')).toBeTruthy();
expect(footerOf(container)!.textContent).not.toContain(OWNER_NAME);
});

it('no declared groups: owner_id lands in the auto-derived section, and is painted once', () => {
const { container } = renderDefaultPage({ name: OBJECT, fields: FIELDS });
expect(within(detailsColumn(container)).getByText('grace@example.com')).toBeTruthy();
expect(footerOf(container)).not.toBeNull();

expect(footerOwner(container)).toBeNull();
expect(ownerCount(container)).toBe(1);
});

it('declared groups that leave owner_id out: it lands in the "Other" bucket, and is painted once', () => {
const { container } = renderDefaultPage({
name: OBJECT,
fieldGroups: [{ key: 'basics', label: 'Basics' }],
fields: {
name: { ...FIELDS.name, group: 'basics' },
email: { ...FIELDS.email, group: 'basics' },
phone: FIELDS.phone,
owner_id: FIELDS.owner_id,
},
});
expect(within(detailsColumn(container)).getByText('Other')).toBeTruthy();

expect(footerOwner(container)).toBeNull();
expect(ownerCount(container)).toBe(1);
});
});

describe('the body does not draw owner_id: the meta line keeps the owner (objectstack#35941)', () => {
it('groups that leave owner_id out, and owner_id drawn nowhere else (hidden): the owner is on the meta line', () => {
const { container } = renderDefaultPage({
name: OBJECT,
fieldGroups: [{ key: 'basics', label: 'Basics' }],
fields: {
name: { ...FIELDS.name, group: 'basics' },
email: { ...FIELDS.email, group: 'basics' },
phone: { ...FIELDS.phone, group: 'basics' },
owner_id: { ...FIELDS.owner_id, hidden: true },
},
});
expect(within(detailsColumn(container)).getByText('grace@example.com')).toBeTruthy();

expect(footerOwner(container)).not.toBeNull();
expect(footerOwner(container)!.textContent).toContain(OWNER_NAME);
expect(ownerCount(container)).toBe(1);
});

it('a collapsed group holding owner_id: the owner is on the meta line until the group opens, then in the body', () => {
const { container } = renderDefaultPage({
name: OBJECT,
fieldGroups: [
{ key: 'basics', label: 'Basics' },
{ key: 'ownership', label: 'Ownership', collapse: 'collapsed' },
],
fields: {
name: { ...FIELDS.name, group: 'basics' },
email: { ...FIELDS.email, group: 'basics' },
phone: { ...FIELDS.phone, group: 'basics' },
owner_id: { ...FIELDS.owner_id, group: 'ownership' },
},
});
// Collapsed, the group draws its heading and no rows.
expect(footerOwner(container)).not.toBeNull();
expect(ownerCount(container)).toBe(1);

fireEvent.click(within(detailsColumn(container)).getByRole('button', { name: /Ownership/ }));
expect(footerOwner(container)).toBeNull();
expect(ownerCount(container)).toBe(1);
});
});
16 changes: 16 additions & 0 deletions ui/packages/plugin-detail/src/DetailSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ import { InlineFieldInput } from './InlineFieldInput';
import { headerColorClass } from './headerColor';
import { DetailsColumnCapContext, framelessSectionColumns, useDefaultRecordPage } from './defaultRecordPage';
import { hasCellValue } from './emptiness';
import { RecordPageProvenanceContext } from './recordPageProvenance';
import { useReportBodyFields } from './recordBodyFields';
import {
enrichDetailField,
isComputedDetailField,
Expand Down Expand Up @@ -140,6 +142,9 @@ export function framelessSpanClass(span: number | undefined, columns: 1 | 2 | 3)
*/
const ignoreReadOnlyChange = (): void => {};

/** What a section reports while it draws no row of the page's record. */
const NO_REPORTED_FIELDS: readonly string[] = [];

/**
* Whether a key pressed on a copy-on-activate row is the ROW's own activation
* (objectui#12569): Enter or Space, aimed at the row itself.
Expand Down Expand Up @@ -482,6 +487,17 @@ export const DetailSection: React.FC<DetailSectionProps> = ({
undefined,
objectSchema?.fields,
);
// objectstack#35941 — the page's meta line leaves the owner out when the
// body draws `owner_id`, so the body says which rows it draws: the rows of
// the grid below, none while its content is collapsed away (the faces
// below mount it only open: the frameless face and the card disclosure;
// the card that cannot collapse always draws it), and only for the page's
// own record.
const drawsPageRecord = React.useContext(RecordPageProvenanceContext);
const drawsContent = !isCollapsed || (!frameless && !section.collapsible);
useReportBodyFields(
drawsPageRecord && drawsContent ? layoutFields.map((field) => field.name) : NO_REPORTED_FIELDS,
);
// Never render more columns than there are visible fields — the object-wide
// column count (objectui#2578) can exceed a section's visible count when
// empty fields are hidden; a lone field shouldn't sit at 1/N width.
Expand Down
Loading
Loading