Skip to content

Commit f2078e3

Browse files
fix(plugin-detail): the record page's empty-sections line follows the remembered show-empty-fields choice (#35233)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgEdwjBmjmPjaieDs6mot1QR)_ repo:objectstack#5 · os-bill · session_01Utp6CaTDynWQQPWZNZBKq6 Fixes #35166 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:记录页底部那条「地址 · 转化 · N 个空分区 · 展开」空分区行,改为读写读者已记住的「显示空字段」选择(与各分区自己的「显示 N 个空字段」行同一个 `showEmptyFields`,按用户 + 对象存)。默认页与编排页都生效;顺手改正 `RecordDetailView.tsx` 一处过时注释。 - 为什么改:读者选过「显示空字段」,空分区行仍每次折叠;展开后关页即忘,每次进记录都得再点一次。 - 风险与回滚:只动 `plugin-detail` 一个组件 + 一处传参;无宿主偏好存储(未登录、无 bridge)时行为与原来一致(组件自身状态)。注意:展开/收起这条行就是同一个选择,所以会一并展开/收起各分区内的空字段。回滚即 revert 本 PR。 - 先看:`ui/packages/plugin-detail/src/EmptySectionsFold.tsx` 的 `EmptySectionsLine`(`remembered` 一段)→ `DetailView.tsx` 传 `objectName` 一行 → 测试文件末尾新 describe。 - 两分钟验证:登录 console,打开任一有空分区的记录,点空分区行「展开」,刷新页面,预期该行仍是展开(「收起」)状态,换同对象另一条记录也一样。 - 需要你做的:无,席位落地。 ## What changes - `EmptySectionsLine` (`ui/packages/plugin-detail/src/EmptySectionsFold.tsx`) takes the page's `objectName` and, under a host record-page preference store (`useRecordPagePreferences`), reads its expanded state from that object's `showEmptyFields` entry and writes an expand or collapse back to it — the same entry and the same local-state fallback `DetailSection` uses (objectstack#25883). With no store or no object name it keeps its own state, as before. - `DetailView` passes `schema.objectName` to the line. Both page kinds reach the line through this one call site: the synthesized default page (`DefaultRecordPageContext`) and every `record:details` body (`EmptySectionsLineContext`, which hands `ctx.objectName` down as `schema.objectName`). - `ui/packages/app-shell/src/views/RecordDetailView.tsx`: the comment that listed the empty-sections line as a default-page-only face now says every `record:details` body draws it. - Changeset: `@object-ui/plugin-detail` patch. One choice, not two: expanding the line sets `showEmptyFields: true`, which also opens each section's own empty fields (sections read the same entry). The card asks for "the same remembered 「显示空字段」 choice"; no new preference key was added. ## Tests New top-level `describe` in `ui/packages/plugin-detail/src/__tests__/EmptySectionsLine.authoredPage-35019.test.tsx` (the line's existing harness), run for both page kinds (authored page; default page via `DefaultRecordPageContext`): - a remembered `showEmptyFields: true` opens the line and every empty field shows; - CONTROL: another object's remembered choice leaves the line folded; - expanding writes `['crm_opportunity', { showEmptyFields: true }]`, survives a remount; collapsing writes `false`, also survives; - CONTROL: with no host store the line's state is forgotten on unmount. Ablation (one-shot, not kept): `EmptySectionsFold.tsx` replaced by its `ec227fc7` bytes (`grep -c useRecordPagePreferences` → 0) ⇒ `Tests 4 failed | 13 passed (17)` — exactly the two remembered-true and the two remount cases, both page kinds; the three controls stay green. Restored with `git checkout HEAD --`, `git diff HEAD` empty, marker count back to 2. ## Acceptance notes - Follow-up (out of scope per dispatch): `EmptySectionsFold` (the whole-body fold a standalone `detail-view` draws) keeps `revealed` in `useState(false)` and does not read the remembered choice either. ## Verification All at head `2b539819`: <details><summary>Local subset</summary> - `pnpm --filter @object-ui/plugin-detail run type-check` + `pnpm --filter @object-ui/plugin-detail test` under the verify lock: `VERDICT command-exit 0`, `Test Files 386 passed | 1 skipped (387)`, `Tests 3477 passed | 18 skipped (3495)` (run at `aa63bf8b`; the later commit adds only the changeset). - eslint on the four changed files: exit 0, 0 errors (warnings pre-existing). - `dispatch-gates --commands`: 39 derived families, all run, all exit 0; `dispatch-gates --ran`: `39 run, 0 NOT-MEASURED`. </details> Every family CI runs: read from this PR's check-runs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CaTDynWQQPWZNZBKq6 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3e4d531 commit f2078e3

5 files changed

Lines changed: 157 additions & 6 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
---
4+
5+
fix(plugin-detail): a record page's empty-sections line follows the reader's remembered "show empty fields" choice
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A reader who chose "show empty fields" for an object found the record page's closing empty-sections line ("Deal Narrative · Notes & Next Steps · 2 empty sections · Expand") folded again on every visit, on the default record page and on an authored one alike, and expanding the line was forgotten as soon as the page closed.
11+
12+
The line now reads and writes the same remembered choice each section's own "Show N empty fields" row already uses, kept per user and object. With "show empty fields" remembered, the line opens on its own, on both page kinds. Expanding or collapsing the line is that choice: it is remembered for every record of the object, after a reload and on another device, and it also opens or folds each section's own empty fields, since it is one choice.
13+
14+
What does not change: with no signed-in user or no host preference store, the line keeps its own state, forgotten when the page closes, as before. Edit mode and a print page still draw every section. No metadata key, value or default changes.

‎ui/packages/app-shell/src/views/RecordDetailView.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5559,8 +5559,9 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
55595559
) : pageColumns ? null : (
55605560
// objectstack#27055 — a synthesized page whose strip cannot
55615561
// be laid out keeps the record page v3 face as its tab strip
5562-
// (frameless sections, the empty-sections line, the
5563-
// highlight grid); an authored page keeps its own face.
5562+
// (frameless sections, the highlight grid); an authored page
5563+
// keeps its own face. Every `record:details` body, authored
5564+
// or not, draws the empty-sections line (objectstack#35019).
55645565
<DefaultRecordPageContext.Provider value={!assignedPage && !namedPageBlocked}>
55655566
<RecordBodyTablesContext.Provider value={bodyTableIds}>
55665567
{/* A page drawn as its strip is drawn as written: the

‎ui/packages/plugin-detail/src/DetailView.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,7 @@ export const DetailView: React.FC<DetailViewProps> = ({
21502150
sections={schema.sections ?? []}
21512151
data={{ ...data, ...editedValues }}
21522152
isEditing={isInlineEditing}
2153+
objectName={schema.objectName}
21532154
renderSection={renderSectionAt}
21542155
/>
21552156
) : foldEmptySections(schema.sections!.map(renderSectionAt));

‎ui/packages/plugin-detail/src/EmptySectionsFold.tsx‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import * as React from 'react';
1010
import { Eye, EyeOff } from 'lucide-react';
1111
import { Button } from '@object-ui/components';
12-
import { usePrintPage } from '@object-ui/react';
12+
import { usePrintPage, useRecordPagePreferences } from '@object-ui/react';
1313
import type { DetailViewSection } from '@object-ui/types';
1414
import { hasCellValue } from './emptiness';
1515
import { useDetailTranslation } from './useDetailTranslation';
@@ -143,6 +143,11 @@ export interface EmptySectionsLineProps {
143143
/** The record as the sections read it (record plus the inline-edit draft). */
144144
data: Record<string, unknown> | null | undefined;
145145
isEditing: boolean;
146+
/**
147+
* The object the record page shows; the line reads and writes the reader's
148+
* remembered "show empty fields" choice for it (objectstack#35166).
149+
*/
150+
objectName?: string;
146151
/** Draw one section (its error boundary included) at its index. */
147152
renderSection: (section: DetailViewSection, index: number) => React.ReactNode;
148153
}
@@ -161,16 +166,38 @@ export interface EmptySectionsLineProps {
161166
* section is empty the line names them all, so it takes that fold's place on
162167
* those bodies. Edit mode and a print page draw every section, for the
163168
* reasons that fold gives.
169+
*
170+
* Expanded or not is the reader's one remembered "show empty fields" choice
171+
* for the object (objectstack#35166), the same `showEmptyFields` entry each
172+
* section's own row reads (`DetailSection`, objectstack#25883): a reader who
173+
* chose to see empty fields finds the line open on every record page of the
174+
* object, default or authored, and expanding or collapsing the line writes
175+
* that choice back. With no host store or no object name the line keeps its
176+
* own state, forgotten on unmount, as before.
164177
*/
165178
export const EmptySectionsLine: React.FC<EmptySectionsLineProps> = ({
166179
sections,
167180
data,
168181
isEditing,
182+
objectName,
169183
renderSection,
170184
}) => {
171185
const { t } = useDetailTranslation();
172186
const isPrintPage = usePrintPage() !== null;
173-
const [revealed, setRevealed] = React.useState(false);
187+
const recordPagePreferences = useRecordPagePreferences();
188+
const [localRevealed, setLocalRevealed] = React.useState(false);
189+
const remembered =
190+
recordPagePreferences && objectName
191+
? {
192+
shown: recordPagePreferences.get(objectName).showEmptyFields === true,
193+
set: (shown: boolean) => recordPagePreferences.update(objectName, { showEmptyFields: shown }),
194+
}
195+
: null;
196+
const revealed = remembered ? remembered.shown : localRevealed;
197+
const toggleRevealed = () => {
198+
if (remembered) remembered.set(!remembered.shown);
199+
else setLocalRevealed((r) => !r);
200+
};
174201
const folded = isEditing || isPrintPage ? [] : sections.map((section) => isFoldableEmptySection(section, data));
175202
const foldedCount = folded.filter(Boolean).length;
176203
if (foldedCount === 0) return <>{sections.map(renderSection)}</>;
@@ -192,7 +219,7 @@ export const EmptySectionsLine: React.FC<EmptySectionsLineProps> = ({
192219
<button
193220
type="button"
194221
aria-expanded={revealed}
195-
onClick={() => setRevealed((r) => !r)}
222+
onClick={toggleRevealed}
196223
className="inline-flex min-h-[44px] min-w-[44px] items-center justify-center sm:min-h-0 sm:min-w-0 rounded-sm font-medium text-primary hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
197224
>
198225
{revealed

‎ui/packages/plugin-detail/src/__tests__/EmptySectionsLine.authoredPage-35019.test.tsx‎

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ import * as React from 'react';
3737
import { describe, it, expect, vi, afterEach } from 'vitest';
3838
import { render, screen, cleanup, fireEvent, within } from '@testing-library/react';
3939
import '@testing-library/jest-dom';
40-
import { InlineEditProvider, PrintPageProvider, RecordContextProvider } from '@object-ui/react';
40+
import {
41+
InlineEditProvider,
42+
PrintPageProvider,
43+
RecordContextProvider,
44+
RecordPagePreferencesProvider,
45+
type RecordPagePreference,
46+
type RecordPagePreferencesStore,
47+
} from '@object-ui/react';
4148
import type { DetailViewSchema, DetailViewSection } from '@object-ui/types';
4249
import { RecordDetailsRenderer } from '../renderers/record-details';
4350
import { DetailView } from '../DetailView';
51+
import { DefaultRecordPageContext } from '../defaultRecordPage';
4452

4553
/** `useRecordEditable`'s explain probe, answered with its fail-open 501 (the binding suites do the same). */
4654
vi.stubGlobal('fetch', (async () => new Response(null, { status: 501 })) as unknown as typeof globalThis.fetch);
@@ -285,3 +293,103 @@ describe('objectstack#35019 — CONTROL: a standalone DetailView keeps a card pe
285293
expect(screen.getByRole('button', { name: /Show 6 empty fields/ })).toBeInTheDocument();
286294
});
287295
});
296+
297+
/**
298+
* objectstack#35166 — the line follows the reader's ONE remembered "show empty
299+
* fields" choice for the object (`showEmptyFields`, the entry each section's
300+
* own row reads, objectstack#25883), on both page kinds: a reader who chose to
301+
* see empty fields finds the line open, and an expand or collapse of the line
302+
* is that choice, remembered across a remount.
303+
*/
304+
describe('objectstack#35166 — the empty-sections line follows the remembered "show empty fields" choice', () => {
305+
/** An in-memory host store; `writes` records every update. */
306+
function memoryStore(initial: Record<string, RecordPagePreference> = {}) {
307+
const state: Record<string, RecordPagePreference> = { ...initial };
308+
const writes: Array<[string, RecordPagePreference]> = [];
309+
const listeners = new Set<() => void>();
310+
const store: RecordPagePreferencesStore = {
311+
get: (objectName) => state[objectName] ?? {},
312+
update: (objectName, patch) => {
313+
writes.push([objectName, patch]);
314+
state[objectName] = { ...(state[objectName] ?? {}), ...patch };
315+
listeners.forEach((l) => l());
316+
},
317+
};
318+
return { store, writes, listeners };
319+
}
320+
321+
/** A host that hands down a new store value per change, as the console's provider does. */
322+
function Host({ mem, children }: { mem: ReturnType<typeof memoryStore>; children: React.ReactNode }) {
323+
const [version, setVersion] = React.useState(0);
324+
React.useEffect(() => {
325+
const l = () => setVersion((v) => v + 1);
326+
mem.listeners.add(l);
327+
return () => {
328+
mem.listeners.delete(l);
329+
};
330+
}, [mem]);
331+
const value = React.useMemo<RecordPagePreferencesStore>(
332+
() => ({ get: (o) => mem.store.get(o), update: (o, p) => mem.store.update(o, p) }),
333+
// eslint-disable-next-line react-hooks/exhaustive-deps -- `version` is the change signal
334+
[mem, version],
335+
);
336+
return <RecordPagePreferencesProvider value={value}>{children}</RecordPagePreferencesProvider>;
337+
}
338+
339+
const PAGE_KINDS = [
340+
['authored page', (node: React.ReactNode) => node],
341+
[
342+
'default page',
343+
(node: React.ReactNode) => <DefaultRecordPageContext.Provider value>{node}</DefaultRecordPageContext.Provider>,
344+
],
345+
] as const;
346+
347+
const renderUnder = (mem: ReturnType<typeof memoryStore>, kind: (node: React.ReactNode) => React.ReactNode) =>
348+
renderAuthoredPage(authoredSections, DEAL, (node) => <Host mem={mem}>{kind(node)}</Host>);
349+
350+
for (const [kindName, kind] of PAGE_KINDS) {
351+
it(`${kindName}: a remembered "show empty fields" opens the line, and every empty field shows`, () => {
352+
renderUnder(memoryStore({ crm_opportunity: { showEmptyFields: true } }), kind);
353+
354+
expect(lineToggle().getAttribute('aria-expanded')).toBe('true');
355+
for (const label of ['Customer Background', 'Payment Terms', 'Next Step']) {
356+
expect(screen.getByText(label)).toBeInTheDocument();
357+
}
358+
});
359+
360+
it(`${kindName}: CONTROL — another object's remembered choice leaves the line folded`, () => {
361+
renderUnder(memoryStore({ crm_account: { showEmptyFields: true } }), kind);
362+
363+
expect(lineToggle().getAttribute('aria-expanded')).toBe('false');
364+
expect(screen.queryByText('Customer Background')).toBeNull();
365+
});
366+
367+
it(`${kindName}: expanding is remembered across a remount, and collapsing too`, () => {
368+
const mem = memoryStore();
369+
const first = renderUnder(mem, kind);
370+
expect(lineToggle().getAttribute('aria-expanded')).toBe('false');
371+
fireEvent.click(lineToggle());
372+
expect(mem.writes).toEqual([['crm_opportunity', { showEmptyFields: true }]]);
373+
first.unmount();
374+
375+
const second = renderUnder(mem, kind);
376+
expect(lineToggle().getAttribute('aria-expanded')).toBe('true');
377+
fireEvent.click(lineToggle());
378+
expect(mem.writes.at(-1)).toEqual(['crm_opportunity', { showEmptyFields: false }]);
379+
second.unmount();
380+
381+
renderUnder(mem, kind);
382+
expect(lineToggle().getAttribute('aria-expanded')).toBe('false');
383+
});
384+
}
385+
386+
it('CONTROL: with no host store the line keeps its own state, forgotten on unmount', () => {
387+
const first = renderAuthoredPage();
388+
fireEvent.click(lineToggle());
389+
expect(lineToggle().getAttribute('aria-expanded')).toBe('true');
390+
first.unmount();
391+
392+
renderAuthoredPage();
393+
expect(lineToggle().getAttribute('aria-expanded')).toBe('false');
394+
});
395+
});

0 commit comments

Comments
 (0)