Skip to content

Commit 9665274

Browse files
committed
wip(plugin-detail): related panels tests, changeset, header click guard
Claude-Session: https://claude.ai/code/session_01Utp6CaA9ZdTcj97mzGtHYt Co-authored-by: Claude <noreply@anthropic.com>
1 parent 289a86b commit 9665274

9 files changed

Lines changed: 511 additions & 52 deletions
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
'@object-ui/i18n': patch
4+
'@object-ui/app-shell': patch
5+
---
6+
7+
feat(plugin-detail)!: the record page's related panels lose collapse — the header opens the whole list, ⠿ + ⋯ on hover, ⋯ holds Hide alone, empty panels fold into one line, and the stored arrangement drops `collapsed`
8+
9+
Clause-②: yes (narrowing)
10+
Metadata-protocol: none
11+
12+
<!-- adr-0087: not-required (type-surface-only @object-ui/plugin-detail#RelatedArrangement.collapsed, @object-ui/plugin-detail#ResolvedRelatedArrangement.collapsed, @object-ui/plugin-detail#RelatedArrangementEdit) the narrowed members are a reader's per-browser layout preference and its edit vocabulary in a published ui package; no packages/spec schema, no metadata key, no registered node type and no sys_metadata shape names them, so there is nothing for `objectstack migrate meta` to rewrite. The stored preference moves to version 2 and a version-1 record reads as no choice. -->
13+
14+
The record page's related column is a stack of same-shaped panels (record page v4).
15+
16+
- **The panel header** is the title, then the count chip. The header row (or the chip) opens the panel's whole list; on hover the title's end shows › and its tooltip reads "View all N". On hover or focus the right end shows ⠿ (drag to reorder; focused, ⌥↑ / ⌥↓ move the panel), + and ⋯, which now holds Hide and nothing else. There is no collapse and no ⤢, and nothing is reserved on the left.
17+
- **Empty panels** (0 rows) fold into one line after the others: "N more empty lists · name · … · Expand". Expand draws them again in their places. The Related tab of an authored page keeps its own line.
18+
- **The compact row's first column** skips the foreign key that points back at the record on the page: a product's line items, whose name field is the product, are named by their next column.
19+
- **The stored arrangement** (`record.related.arrangement`, per reader × object) is `{ v, order, hidden, basedOn, seen }`. `collapsed` is removed with no compatibility read: a reader's earlier record reads as no choice, and the panels show in the default order.
20+
21+
**BREAKING** for a TypeScript consumer of `@object-ui/plugin-detail`'s arrangement API; nothing an author declares changes.
22+
23+
- FROM `RelatedArrangement.collapsed` / `ResolvedRelatedArrangement.collapsed` TO nothing: a panel has no collapsed state. Drop the member from any value you build.
24+
- FROM the `{ kind: 'collapse', id, collapsed }` edit TO `{ kind: 'hide', id }`, or no edit at all.
25+
- FROM `resolveRelatedArrangement(order, stored, now, defaultCollapsed)` / `editRelatedArrangement(order, stored, edit, now, defaultCollapsed)` TO the same calls without the last argument.
26+
- The i18n keys `detail.relatedCardMoveUp`, `detail.relatedCardMoveDown`, `detail.relatedCardCollapse` and `detail.relatedCardCount` leave every pack; `detail.relatedPanelViewAll`, `detail.relatedPanelReorder`, `detail.relatedPanelReorderHint` and `detail.relatedEmptyFold` arrive in all ten.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#27524, Target 10 — the stored arrangement of the record page's
11+
* related panels is `{ v, order, hidden, basedOn, seen }`. `collapsed` left
12+
* the shape with no compatibility read: a record of the earlier version (the
13+
* one that carried it) is "no choice", and the reader gets the default order
14+
* again. This file runs in the node project (no `window`).
15+
*/
16+
17+
import { describe, it, expect } from 'vitest';
18+
import {
19+
RECORD_RELATED_ARRANGEMENT_PREFERENCE,
20+
objectPreferenceScope,
21+
readWorkspacePreference,
22+
writeWorkspacePreference,
23+
} from './workspacePreference';
24+
25+
const lead = objectPreferenceScope('crm_lead');
26+
const KEY = 'os:pref:record.related.arrangement@object:crm_lead';
27+
28+
const memoryStorage = () => {
29+
const kept = new Map<string, string>();
30+
return {
31+
kept,
32+
getItem: (key: string) => kept.get(key) ?? null,
33+
setItem: (key: string, value: string) => void kept.set(key, value),
34+
};
35+
};
36+
37+
describe('record.related.arrangement — no `collapsed`, no compatibility read (objectstack#27524)', () => {
38+
it('writes { order, hidden, basedOn, seen } and the version, and reads it back', () => {
39+
const storage = memoryStorage();
40+
const value = { order: ['task.lead_id', 'note.parent_id'], hidden: ['call.lead_id'], basedOn: 'abcd1234', seen: { 'task.lead_id': 1 } };
41+
writeWorkspacePreference(RECORD_RELATED_ARRANGEMENT_PREFERENCE, lead, value, storage);
42+
const stored = JSON.parse(storage.kept.get(KEY)!);
43+
expect(Object.keys(stored).sort()).toEqual(['basedOn', 'hidden', 'order', 'seen', 'v']);
44+
expect(stored.v).toBe(2);
45+
expect(readWorkspacePreference(RECORD_RELATED_ARRANGEMENT_PREFERENCE, lead, storage)).toEqual(value);
46+
});
47+
48+
it('reads no choice from a record of the shape that carried `collapsed`', () => {
49+
const earlier = JSON.stringify({ order: ['note.parent_id'], collapsed: ['task.lead_id'], hidden: [], basedOn: 'abcd1234', v: 1 });
50+
const storage = { getItem: (key: string) => (key === KEY ? earlier : null) };
51+
expect(readWorkspacePreference(RECORD_RELATED_ARRANGEMENT_PREFERENCE, lead, storage)).toBeUndefined();
52+
});
53+
});

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,8 +2850,12 @@ export const RelatedList: React.FC<RelatedListProps> = ({
28502850
className={cn('group/panel-head flex h-9 items-center gap-1.5 px-3 text-[12.5px] font-semibold', open && 'cursor-pointer')}
28512851
data-related-panel-head=""
28522852
// The row is the target: a click on its free space opens the list
2853-
// too. Its own controls stop their clicks.
2854-
onClick={open ? () => open() : undefined}
2853+
// too. Its own controls stop their clicks; a click inside the ⋯
2854+
// menu's portaled content bubbles here through React yet lands
2855+
// outside the row in the DOM, and is not the row's.
2856+
onClick={open ? (event) => {
2857+
if (event.currentTarget.contains(event.target as Node)) open();
2858+
} : undefined}
28552859
>
28562860
{open ? (
28572861
<button

‎ui/packages/plugin-detail/src/__tests__/RelatedCardStack-27055.test.tsx‎

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
*/
88

99
/**
10-
* objectstack#27055, Targets 7 and 10 — the related column's cards in the
10+
* objectstack#27055, Targets 7 and 10 — the related column's panels in the
1111
* reader's arrangement, through `RecordPageColumns`. The related-list block
1212
* is stubbed (it draws its relationship id and the chrome it was handed), so
13-
* what is measured is the stack: the order the store says, a collapsed card
14-
* drawn without the list (no rows read), the keyboard moves of the `⋯` menu
15-
* written back through the host's setter, the hidden line and the
16-
* changed-default hint. The merge rules themselves are pinned in
17-
* `synth/__tests__/relatedArrangement-27055.test.ts`.
13+
* what is measured is the stack: the order the store says, the keyboard
14+
* moves the ⠿ handle hands each panel (objectstack#27524) written back
15+
* through the host's setter, the hidden line and the changed-default hint.
16+
* A panel no longer collapses (objectstack#27524, Target 1): its chrome
17+
* carries no collapse. The merge rules themselves are pinned in
18+
* `synth/__tests__/relatedArrangement-27055.test.ts`; the panel's own header
19+
* in `RelatedPanel.header-27524.test.tsx`.
1820
*/
1921

2022
import * as React from 'react';
@@ -37,7 +39,6 @@ function StubNode({ schema }: { schema: any }) {
3739
{p.objectName ?? schema?.type}
3840
{chrome?.onMoveUp && <button onClick={chrome.onMoveUp}>{`up ${p.objectName}`}</button>}
3941
{chrome?.onMoveDown && <button onClick={chrome.onMoveDown}>{`down ${p.objectName}`}</button>}
40-
{chrome && <button onClick={chrome.onCollapse}>{`collapse ${p.objectName}`}</button>}
4142
{chrome && <button onClick={chrome.onHide}>{`hide ${p.objectName}`}</button>}
4243
{chrome?.fresh && <span data-fresh="">new</span>}
4344
</section>
@@ -93,7 +94,7 @@ describe('RelatedCardStack — the reader arranges the related cards (objectstac
9394
expect(cardOrder(container)).toEqual(['call.lead_id', 'task.lead_id', 'note.parent_id']);
9495
});
9596

96-
it('上移 / 下移 write the new order through the host', () => {
97+
it('the handle’s ⌥↑ / ⌥↓ write the new order through the host', () => {
9798
const onWrite = vi.fn();
9899
const { container } = render(<Host onWrite={onWrite} />);
99100
fireEvent.click(screen.getByText('down task'));
@@ -104,16 +105,10 @@ describe('RelatedCardStack — the reader arranges the related cards (objectstac
104105
expect(screen.queryByText('down call')).toBeNull();
105106
});
106107

107-
it('a collapsed card is drawn without the list — it reads no rows', () => {
108+
it('a panel carries no collapse: every shown panel mounts its list (objectstack#27524, Target 1)', () => {
108109
const { container } = render(<Host />);
109-
fireEvent.click(screen.getByText('collapse note'));
110-
const collapsed = container.querySelector('[data-related-card-collapsed]');
111-
expect(collapsed?.getAttribute('data-related-card-id')).toBe('note.parent_id');
112-
// The list block for `note` is not mounted at all.
113-
expect(container.querySelector('[data-node="record:related_list"][data-related-card-id="note.parent_id"]')).toBeNull();
114-
// Expanding mounts it again.
115-
fireEvent.click(collapsed!.querySelector('button[aria-expanded="false"]')!);
116-
expect(container.querySelector('[data-node="record:related_list"][data-related-card-id="note.parent_id"]')).not.toBeNull();
110+
expect(container.querySelectorAll('[data-node="record:related_list"]')).toHaveLength(DEFAULT.length);
111+
expect(container.querySelector('[data-related-card-collapsed]')).toBeNull();
117112
});
118113

119114
it('a hidden card leaves the column; the last line brings them back', () => {

‎ui/packages/plugin-detail/src/__tests__/RelatedList.compactColumn-26678.test.tsx‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,22 @@ describe('RelatedList in the related column (objectstack#26678)', () => {
9898
expect(screen.queryByText(/View all/i)).not.toBeInTheDocument();
9999
});
100100

101-
it('offers ⤢ and the ⋯ menu only with the arranged stack\'s chrome, and ⤢ enlarges', async () => {
101+
it('offers the handle, the ⋯ menu and the way to the whole list only with the arranged stack\'s chrome (objectstack#27524)', async () => {
102102
renderList(true);
103103
await waitFor(() => expect(screen.getByText('Call Ada')).toBeInTheDocument());
104-
expect(document.querySelector('[data-related-card-enlarge]')).toBeNull();
104+
expect(document.querySelector('[data-related-panel-open]')).toBeNull();
105+
expect(document.querySelector('[data-related-panel-handle]')).toBeNull();
105106
expect(document.querySelector('[data-related-card-menu]')).toBeNull();
106107
document.body.innerHTML = '';
107108
const onEnlarge = vi.fn();
108-
renderList(true, { chrome: { id: 'task.lead_id', fresh: true, onCollapse: vi.fn(), onHide: vi.fn(), onEnlarge } });
109+
renderList(true, { chrome: { id: 'task.lead_id', fresh: true, onHide: vi.fn(), onEnlarge } });
109110
await waitFor(() => expect(screen.getByText('Call Ada')).toBeInTheDocument());
110-
(document.querySelector('[data-related-card-enlarge]') as HTMLButtonElement).click();
111-
(document.querySelector('[data-related-card-count]') as HTMLButtonElement).click();
111+
// No ⤢ any more: the header (title + count chip) opens the whole list.
112+
expect(document.querySelector('[data-related-card-enlarge]')).toBeNull();
113+
(document.querySelector('[data-related-panel-open]') as HTMLButtonElement).click();
114+
(document.querySelector('[data-related-card-count]') as HTMLElement).click();
112115
expect(onEnlarge).toHaveBeenCalledTimes(2);
116+
expect(document.querySelector('[data-related-panel-handle]')).not.toBeNull();
113117
expect(document.querySelector('[data-related-card-menu]')).not.toBeNull();
114118
expect(document.querySelector('[data-related-card-new]')).not.toBeNull();
115119
});

0 commit comments

Comments
 (0)