Skip to content

Commit 90fefc3

Browse files
committed
refactor(ui): the related tab's condition row comes through a host slot
The repository keeps every registered node type authorable, so the list page's condition row is no longer registered as list-conditions. plugin-list exports ListConditionsBlock, plugin-detail reads it from RelatedListConditionsSlotContext, and the record page fills that slot with the block, loaded with the first tab that draws it. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgTKEPqtmiK9SGpHsmW
1 parent e1402cf commit 90fefc3

14 files changed

Lines changed: 176 additions & 103 deletions

File tree

‎.changeset/35892-related-tab-full-list.md‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
'@object-ui/plugin-list': patch
55
'@object-ui/plugin-detail': patch
66
'@object-ui/app-shell': patch
7-
'@object-ui/cli': patch
87
---
98

109
feat(ui): a record page's related tab is the child object's full list
1110

12-
Clause-②: yes (widening) — a new registry component `list-conditions` (`@object-ui/plugin-list`, host props only, no node keys) and its exported `ListConditionsHostProps`; new exports `ConditionDiscardButton` (`@object-ui/plugin-list`) and `withHeaderSortPick` (`@object-ui/core`); new i18n keys in every `@object-ui/i18n` locale pack (`listConditions.chips.discard`, `listConditions.chips.discardHint`, `detail.relatedNoMatches`, `detail.deleteRowsTitle`, `detail.deleteRowsConfirmation_*`, a count family); nothing removed or renamed
11+
Clause-②: yes (widening) — a new export `ListConditionsBlock` (`@object-ui/plugin-list`, the condition row as a host element, not a registered node type) and its `ListConditionsHostProps`; a new slot `RelatedListConditionsSlotContext` and its `RelatedListConditionsProps` (`@object-ui/plugin-detail`), which the record page fills (`@object-ui/app-shell`); new exports `ConditionDiscardButton` (`@object-ui/plugin-list`) and `withHeaderSortPick` (`@object-ui/core`); new i18n keys in every `@object-ui/i18n` locale pack (`listConditions.chips.discard`, `listConditions.chips.discardHint`, `detail.relatedNoMatches`, `detail.deleteRowsTitle`, `detail.deleteRowsConfirmation_*`, a count family); nothing removed or renamed
1312
Metadata-protocol: none
1413

1514
On a record page, a related list opened as its own tab now works like the object's list page:
@@ -24,5 +23,3 @@ On a record page, a related list opened as its own tab now works like the object
2423
Upgrade note: the header sort and the column widths and order that an earlier version remembered for a related tab in a reader's record-page preference (`sys_user_preference`) no longer apply: the tab opens in its declared order, and its column widths and order are now kept in the reader's browser, as the list page's are, so they start from the default once. Nothing stored is deleted. The default sort and columns of every related list are unchanged.
2524

2625
`@object-ui/core` adds `withHeaderSortPick`, the list page's rule for how a header sort joins an existing multi-level sort, now shared with the related tab. `@object-ui/app-shell`'s list Discard is drawn by `ConditionDiscardButton`; it looks and behaves as before.
27-
28-
`@object-ui/cli`'s known node types gain `list-conditions` (regenerated from the registry), so `objectui validate` knows the new block.

‎ui/apps/console/src/register-plugins.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ ComponentRegistry.registerLazy('object-gallery', () => import('@object-ui/plugin
5656
namespace: 'plugin-list',
5757
category: 'view',
5858
});
59-
// objectstack#35892 — the list page's condition row, for the record page's
60-
// related tab (`plugin-detail`, which cannot import this package).
61-
ComponentRegistry.registerLazy('list-conditions', () => import('@object-ui/plugin-list'), {
62-
namespace: 'plugin-list',
63-
category: 'Views',
64-
});
6559

6660
// The form and the object view: the shell takes their pure helpers from the
6761
// side-effect-free `/core` subpaths and draws their components behind

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ import type { ConsoleActionDispatch } from '../consoleActionDispatch.js';
8383
import { useRecordApprovals, openApprovalOf, isSubmitterOf } from '../hooks/useRecordApprovals.js';
8484
import { RecordAttachmentsPanel } from './RecordAttachmentsPanel.js';
8585
import { RecordApprovalsPanel } from './RecordApprovalsPanel.js';
86-
import { ApprovalBandOnceScope, RecordStageMenu } from '@object-ui/plugin-detail';
86+
import { ApprovalBandOnceScope, RecordStageMenu, RelatedListConditionsSlotContext } from '@object-ui/plugin-detail';
87+
import { renderRelatedListConditions } from './relatedListConditions.js';
8788
import { DeclaredActionsBar } from './DeclaredActionsBar.js';
8889
import {
8990
SYS_APPROVAL_REQUEST_OBJECT,
@@ -5583,6 +5584,8 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
55835584
attachments: !!(filesEnabled && !hasAttachments && pureRecordId),
55845585
});
55855586
const pageTree = (
5587+
// objectstack#35892 — a related tab draws the list page's condition row.
5588+
<RelatedListConditionsSlotContext.Provider value={renderRelatedListConditions}>
55865589
<RecordHeaderBarContext.Provider value={headerBarForRecord}>
55875590
<RecordHeaderStateContext.Provider value={recordHeaderState}>
55885591
<div ref={setPageRootEl} className="h-full bg-background overflow-hidden flex flex-col relative" data-record-page-root="">
@@ -6081,6 +6084,7 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
60816084
</div>
60826085
</RecordHeaderStateContext.Provider>
60836086
</RecordHeaderBarContext.Provider>
6087+
</RelatedListConditionsSlotContext.Provider>
60846088
);
60856089
// A drawer draws this view embedded and is its own host. A page is the host
60866090
// of the drawer its related rows and lookups open over it
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
* The condition row a record page's related tab draws (objectstack#35892):
11+
* the list page's own Sort and Filter, `@object-ui/plugin-list`'s
12+
* `ListConditionsBlock`. `@object-ui/plugin-detail` draws the tab but cannot
13+
* import `plugin-list` (which depends on it), so the record page hands the
14+
* block in through `RelatedListConditionsSlotContext`. It loads with the first
15+
* tab that draws it, as `plugin-list` loads for the list page.
16+
*/
17+
18+
import { lazy, Suspense } from 'react';
19+
import type { RelatedListConditionsProps } from '@object-ui/plugin-detail';
20+
21+
const ListConditionsBlock = lazy(() =>
22+
import('@object-ui/plugin-list').then((m) => ({ default: m.ListConditionsBlock })),
23+
);
24+
25+
/** The record page's `RelatedListConditionsSlotContext` value. */
26+
export function renderRelatedListConditions(props: RelatedListConditionsProps) {
27+
return (
28+
<Suspense fallback={null}>
29+
<ListConditionsBlock {...props} />
30+
</Suspense>
31+
);
32+
}

‎ui/packages/cli/src/utils/known-schema-types.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ export const KNOWN_SCHEMA_TYPES: readonly string[] = [
214214
'layout:page:card',
215215
'li',
216216
'list',
217-
'list-conditions',
218217
'list-view',
219218
'loading',
220219
'main',
@@ -289,7 +288,6 @@ export const KNOWN_SCHEMA_TYPES: readonly string[] = [
289288
'plugin-gantt:object-gantt',
290289
'plugin-grid:object-grid',
291290
'plugin-kanban:object-kanban',
292-
'plugin-list:list-conditions',
293291
'plugin-list:list-view',
294292
'plugin-list:object-gallery',
295293
'plugin-map:object-map',

‎ui/packages/plugin-detail/README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,9 @@ wiring exists to remove.
723723
On the record page, a related list opened as its own **tab** is the child
724724
object's full list (objectstack#35892). Its first row is the list's tile and
725725
name on the left and **+ Add** on the right; its second row is the list page's
726-
own condition row (`plugin-list` registers it as `list-conditions`, since that
727-
package depends on this one): **Sort** and **Filter**, with no view switch, no
726+
own condition row (`plugin-list`'s `ListConditionsBlock`, which the record page
727+
hands in through `RelatedListConditionsSlotContext`, since that package depends
728+
on this one; a host that supplies none gets no condition row): **Sort** and **Filter**, with no view switch, no
728729
view settings and no search. The table is the list page's grid: the column
729730
menu, cell editing where the reader may edit the child object, row selection
730731
with the floating bulk bar, and the footer row, whose calculations cover every

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

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import {
4848
Maximize2,
4949
} from 'lucide-react';
5050
import type { LucideIcon } from 'lucide-react';
51-
import type { DataSource, DeclaredNode, FieldMetadata } from '@object-ui/types';
51+
import type { DataSource, FieldMetadata } from '@object-ui/types';
5252
import type { ViewFilterElement } from '@objectstack/spec/ui';
5353
import { getCellRenderer, resolveCellRendererType, RecordPickerDialog, deriveLookupColumns, MaskedCellRenderer, RecordHoverCard, formatCurrency } from '@object-ui/fields';
5454
import {
@@ -86,7 +86,6 @@ import {
8686
type ActionResult,
8787
type FilterNode,
8888
withHeaderSortPick,
89-
ComponentRegistry,
9089
} from '@object-ui/core';
9190
import { useSafeFieldLabel, useRecordContext, useRecordPagePreferences, type RelatedListPreference } from '@object-ui/react';
9291
import { usePermissions } from '@object-ui/permissions';
@@ -101,6 +100,7 @@ import {
101100
RelatedCardCountContext,
102101
RelatedEnlargeContext,
103102
RelatedListCompactContext,
103+
RelatedListConditionsSlotContext,
104104
RelatedListEnlargedContext,
105105
RelatedListTotalReportContext,
106106
useSeenOnce,
@@ -1285,14 +1285,6 @@ const RELATED_TAB_COLUMNS_IN_PREFERENCES = false;
12851285
*/
12861286
export const RELATED_TAB_WINDOW = 50;
12871287

1288-
/**
1289-
* The condition row `plugin-list` registers (objectstack#35892); one node, so
1290-
* its identity never changes. Not an authored type (no page declares it, it
1291-
* reads only host props), so no `DeclaredNode` arm names it: the cast says
1292-
* this node is the host's, never a page's.
1293-
*/
1294-
const LIST_CONDITIONS_NODE = { type: 'list-conditions' } as unknown as DeclaredNode;
1295-
12961288
/** How far below the view the next window is asked for, as the list page asks (`LOAD_MORE_THRESHOLD_PX`). */
12971289
const RELATED_TAB_LOAD_AHEAD = '320px';
12981290

@@ -1585,9 +1577,9 @@ export const RelatedList: React.FC<RelatedListProps> = ({
15851577
discard: discardTabConditions,
15861578
} = useRelatedTabConditions(tabRecord, tabList ? ownRelationshipId : null);
15871579
const tabChanged = tabList && relatedTabConditionsChanged(tabConditions);
1588-
// Registered by `plugin-list`, which this package cannot import (it depends
1589-
// on this one): without it the tab draws no condition row.
1590-
const listConditionsRegistered = ComponentRegistry.has('list-conditions') || ComponentRegistry.hasLazy('list-conditions');
1580+
// Supplied by the host (`plugin-list`'s row, which this package cannot
1581+
// import: it depends on this one): without it the tab draws no condition row.
1582+
const renderListConditions = React.useContext(RelatedListConditionsSlotContext);
15911583
// The filter the reader set on the tab, ANDed with the list's own scope.
15921584
const tabFilterNode = tabList ? tabConditions.filterNode : undefined;
15931585
const tabFilterKey = tabFilterNode === undefined ? null : JSON.stringify(tabFilterNode);
@@ -4309,27 +4301,23 @@ export const RelatedList: React.FC<RelatedListProps> = ({
43094301
// full list (it was objectstack#35601's bare table). Row one: the child
43104302
// list's tile and name on the left; the child object's toolbar actions and
43114303
// 「+ 添加」, the one add entry (`addEntry`), on the right. Row two: the list
4312-
// page's own condition row (`list-conditions`, registered by `plugin-list`):
4304+
// page's own condition row (the host's `RelatedListConditionsSlotContext`):
43134305
// 「排序」 and 「筛选」, no view switch, view settings or search, and 「放弃」
43144306
// at its end while the reader changed anything. The tab title keeps the
43154307
// count of every child; the table's footer counts the matching ones. No
43164308
// 「在列表中打开」. The rows load as the page scrolls.
43174309
if (enlargedFace) {
4318-
const conditionRow = tabList && listConditionsRegistered ? (
4319-
<SchemaRenderer
4320-
schema={LIST_CONDITIONS_NODE}
4321-
objectName={api}
4322-
objectDef={objectSchema}
4323-
shownFields={tabShownFields}
4324-
sort={tabConditions.sort}
4325-
onSortChange={(sort: typeof tabConditions.sort) => patchTabConditions({ sort })}
4326-
filters={tabConditions.filters}
4327-
onFiltersChange={(filters: typeof tabConditions.filters, filterNode: unknown[] | undefined) =>
4328-
patchTabConditions({ filters, filterNode })}
4329-
dataSource={dataSource}
4330-
{...(tabChanged ? { onDiscard: discardTabConditions } : {})}
4331-
/>
4332-
) : null;
4310+
const conditionRow = tabList && renderListConditions ? renderListConditions({
4311+
objectName: api,
4312+
objectDef: objectSchema,
4313+
shownFields: tabShownFields,
4314+
sort: tabConditions.sort,
4315+
onSortChange: (sort) => patchTabConditions({ sort }),
4316+
filters: tabConditions.filters,
4317+
onFiltersChange: (filters, filterNode) => patchTabConditions({ filters, filterNode }),
4318+
dataSource,
4319+
...(tabChanged ? { onDiscard: discardTabConditions } : {}),
4320+
}) : null;
43334321
// A re-read after a new sort or filter dims the rows it replaces; the
43344322
// next window as the page scrolls does not.
43354323
const rereading = loading && !(tabGrows && currentPage > 0);

‎ui/packages/plugin-detail/src/__tests__/RelatedList.tab-35892.test.tsx‎

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
/**
1010
* objectstack#35892 — the record page's related tab is the child object's
11-
* full list: the list page's condition row (`list-conditions`, through the
12-
* registry), its grid with the column menu, cell editing, selection and the
11+
* full list: the list page's condition row (the host's, through
12+
* `RelatedListConditionsSlotContext`), its grid with the column menu, cell editing, selection and the
1313
* footer row, rows that load as the page scrolls, and 「Discard」 while the
1414
* reader changed anything. What they change holds for this visit to the
1515
* record: across a remount (another tab and back), not on another record.
@@ -20,29 +20,36 @@ import { describe, it, expect, vi, afterEach, beforeAll } from 'vitest';
2020
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
2121
import '@testing-library/jest-dom';
2222
import * as React from 'react';
23-
import { ComponentRegistry } from '@object-ui/core';
2423
import { RelatedList } from '../RelatedList';
25-
import { RelatedListEnlargedContext, RelatedListTotalReportContext } from '../relatedListCompact';
24+
import {
25+
RelatedListConditionsSlotContext,
26+
RelatedListEnlargedContext,
27+
RelatedListTotalReportContext,
28+
type RelatedListConditionsProps,
29+
} from '../relatedListCompact';
2630
import { resetRelatedTabConditionsForTests } from '../relatedTabConditions';
2731

28-
/** What `RelatedList` hands each `SchemaRenderer`, by node type. */
32+
/** What `RelatedList` hands each `SchemaRenderer` by node type, and the host's condition row its props. */
2933
const h = vi.hoisted(() => ({ byType: {} as Record<string, { schema: any; props: any }> }));
3034
vi.mock('@object-ui/react', async (importOriginal) => {
3135
const actual = await importOriginal<Record<string, any>>();
3236
function CapturingRenderer({ schema, ...props }: any) {
3337
h.byType[schema?.type] = { schema, props };
34-
if (schema?.type === 'list-conditions' && props.onDiscard) {
35-
return <button type="button" data-testid="condition-discard" onClick={props.onDiscard}>Discard</button>;
36-
}
3738
return null;
3839
}
3940
return { ...actual, SchemaRenderer: CapturingRenderer };
4041
});
4142

43+
/** The host's condition row (the record page passes `plugin-list`'s block). */
44+
function CapturingConditions(props: RelatedListConditionsProps) {
45+
h.byType.conditions = { schema: undefined, props };
46+
return props.onDiscard
47+
? <button type="button" data-testid="condition-discard" onClick={props.onDiscard}>Discard</button>
48+
: null;
49+
}
50+
4251
beforeAll(() => {
4352
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 1440 });
44-
// `plugin-list` registers it in the app; this package cannot import that one.
45-
if (!ComponentRegistry.has('list-conditions')) ComponentRegistry.register('list-conditions', () => null);
4653
});
4754

4855
afterEach(() => {
@@ -69,13 +76,17 @@ function dataSourceFor() {
6976
};
7077
}
7178

72-
function Tab({ parentId = 'O-1', dataSource, onTotal, onRowDelete }: {
79+
const renderCapturing = (props: RelatedListConditionsProps) => <CapturingConditions {...props} />;
80+
81+
function Tab({ parentId = 'O-1', dataSource, onTotal, onRowDelete, slot = renderCapturing }: {
7382
parentId?: string;
7483
dataSource: ReturnType<typeof dataSourceFor>;
7584
onTotal?: (n: number) => void;
7685
onRowDelete?: (row: any) => Promise<void> | void;
86+
slot?: ((props: RelatedListConditionsProps) => React.ReactNode) | null;
7787
}) {
7888
return (
89+
<RelatedListConditionsSlotContext.Provider value={slot}>
7990
<RelatedListTotalReportContext.Provider value={onTotal}>
8091
<RelatedListEnlargedContext.Provider value>
8192
<RelatedList
@@ -92,11 +103,12 @@ function Tab({ parentId = 'O-1', dataSource, onTotal, onRowDelete }: {
92103
/>
93104
</RelatedListEnlargedContext.Provider>
94105
</RelatedListTotalReportContext.Provider>
106+
</RelatedListConditionsSlotContext.Provider>
95107
);
96108
}
97109

98110
const lastFind = (find: ReturnType<typeof vi.fn>) => find.mock.calls[find.mock.calls.length - 1][1];
99-
const conditions = () => h.byType['list-conditions'];
111+
const conditions = () => h.byType.conditions;
100112
const grid = () => h.byType['object-grid'];
101113
const AMOUNT_OVER_600 = ['amount', '>', 600];
102114
const AMOUNT_GROUP = { id: 'root', logic: 'and' as const, conditions: [{ id: 'r1', field: 'amount', operator: '>', value: 600 }] };
@@ -108,9 +120,14 @@ describe('the related tab is the child object\'s full list (objectstack#35892)',
108120
expect(conditions().props).toMatchObject({ objectName: 'quote', shownFields: ['name', 'amount'], sort: [] });
109121
expect(conditions().props.objectDef?.fields).toEqual(FIELDS);
110122
expect(conditions().props).not.toHaveProperty('onDiscard');
111-
for (const key of ['sort', 'filters', 'onSortChange', 'onFiltersChange']) {
112-
expect(conditions().schema, `${key} is a host prop, never a node key`).not.toHaveProperty(key);
113-
}
123+
expect(h.byType['list-conditions'], 'a host element, never a node').toBeUndefined();
124+
});
125+
126+
it('a host that supplies no condition row gets the table without one', async () => {
127+
render(<Tab dataSource={dataSourceFor()} slot={null} />);
128+
await waitFor(() => expect(grid()?.schema.data.items).toHaveLength(12));
129+
expect(conditions()).toBeUndefined();
130+
expect(document.querySelector('[data-related-enlarged-conditions]')).toBeNull();
114131
});
115132

116133
it('hands the grid the list page\'s host keys: column menu, select-first cells, footer row, its query, selection', async () => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ export { RecordBodyTablesContext } from './relatedListCompact';
237237
// the host's editor through this slot.
238238
export { RecordBodyTableEditorSlotContext } from './relatedListCompact';
239239
export type { RecordBodyTableEditorSlot } from './relatedListCompact';
240+
// objectstack#35892 — the related tab's condition row, supplied by the host
241+
// (`plugin-list`'s `ListConditionsBlock`) through this slot.
242+
export { RelatedListConditionsSlotContext } from './relatedListCompact';
243+
export type { RelatedListConditionsProps } from './relatedListCompact';
240244
// objectstack#27056 — for the app-shell record drawer's prefetch: it warms
241245
// the next record's related counts before the reader steps to it.
242246
export { prefetchRelatedCounts, relatedCountTargetsIn } from './useRelatedCounts';

0 commit comments

Comments
 (0)