Skip to content

Commit 326a42d

Browse files
committed
feat(console): a child list another package brings is not hidden by the parent's relatedLists, and Studio shows it with its source
Flips the hiding #35923 shipped (Sales ruling 7073014077): an unplaced list whose child belongs to another package than the parent shows at the end of the tabs, before a trailing approvals / stream run; a placed one sits at the entry the server splices in. A child of the parent's own package, or one no package owns, is still the parent's to list. Studio's tab-list editor shows such a list read-only with a from-package badge and previews it where the record page draws it. Claude-Session: https://claude.ai/code/session_01L6bhgUxeTKkCvZ2iariHQf Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d78eba1 commit 326a42d

10 files changed

Lines changed: 274 additions & 18 deletions

File tree

‎packages/objectql/src/registry.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ export {
216216
* tenant authored it — the same D9.2a rule as the scalars. A patch reaches
217217
* the owner's own fields only (`ownFields`): one naming any other field,
218218
* a field an extension adds included, is skipped here; the fold names it.
219+
* - `place` [#35901] is not read here: the fold applies every extension's
220+
* placements once, after this merge has run for all of them
221+
* (`applyExtensionPlacements`, registry-extension-placement.ts), so an
222+
* anchor names the object as served.
219223
*
220224
* **Every other top-level prop on `extension` is silently discarded.**
221225
* `merged` starts as `{ ...base }` and nothing outside the list above is ever
@@ -228,7 +232,7 @@ export {
228232
* Declarative authors never reach that silence, though: `ObjectExtensionSchema`
229233
* (`packages/spec/src/data/object.zod.ts`) is `.strict()` — its shape is
230234
* exactly `extend` / `fields` / `fieldPatches` / `label` / `pluralLabel` /
231-
* `description` / `validations` / `indexes` / `priority`, so an `objectExtensions` entry
235+
* `description` / `validations` / `indexes` / `place` / `priority`, so an `objectExtensions` entry
232236
* naming `tenancy`, `permissions`, or any other key outside that list fails
233237
* LOUDLY at authoring time with a prescription (#4001; the same rule is
234238
* documented at `content/docs/data-modeling/object-extensions.mdx`). This
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* objectstack#35901 — a declared `relatedLists` does not hide a child list
3+
* ANOTHER package brings (Sales ruling 7073014077, flipping the hiding
4+
* objectstack#35897 shipped under ruling 7072511859): the package places it
5+
* with its object extension's `place`, which the server splices into the
6+
* parent's `relatedLists`; an unplaced one is kept after the listed lists, so
7+
* the page draws it at the end of the tabs. A child of the parent's own
8+
* package, or one no package owns, is still the parent's to list. Each row's
9+
* control differs from it by one `_packageId`.
10+
*/
11+
import { describe, it, expect } from 'vitest';
12+
import { deriveRelatedLists } from '../deriveRelatedLists';
13+
14+
const account = { name: 'account', label: 'Account', _packageId: 'com.vendor.crm', fields: { name: { type: 'text' } } };
15+
const childOf = (name: string, packageId?: string) => ({
16+
name,
17+
label: name,
18+
...(packageId !== undefined ? { _packageId: packageId } : {}),
19+
fields: { account_id: { type: 'lookup', reference: 'account' } },
20+
});
21+
const contact = childOf('contact', 'com.vendor.crm');
22+
const opportunity = childOf('opportunity', 'com.vendor.crm');
23+
24+
const names = (parent: Record<string, unknown>, objects: unknown[], includeHidden = false) =>
25+
deriveRelatedLists(parent, objects as never, { includeHidden }).map((r) => r.childObject);
26+
27+
describe('relatedLists — a child list another package brings (objectstack#35901)', () => {
28+
const declared = { ...account, relatedLists: ['opportunity', 'contact'] };
29+
30+
it('an unplaced one is kept, after the listed lists', () => {
31+
expect(names(declared, [account, contact, childOf('contract', 'com.acme.contracts'), opportunity])).toEqual([
32+
'opportunity', 'contact', 'contract',
33+
]);
34+
});
35+
36+
it('control: a child of the parent\'s own package is hidden, as objectstack#35897 shipped', () => {
37+
expect(names(declared, [account, contact, childOf('contract', 'com.vendor.crm'), opportunity])).toEqual([
38+
'opportunity', 'contact',
39+
]);
40+
});
41+
42+
it('control: a child no package owns (absent or bound to none) is hidden too', () => {
43+
expect(names(declared, [account, contact, childOf('contract'), opportunity])).toEqual(['opportunity', 'contact']);
44+
expect(names(declared, [account, contact, childOf('contract', 'sys_metadata'), opportunity])).toEqual(['opportunity', 'contact']);
45+
});
46+
47+
it('a placed one (the server spliced it into relatedLists) sits at its entry', () => {
48+
const placed = { ...account, relatedLists: ['opportunity', 'contract', 'contact'] };
49+
expect(names(placed, [account, contact, childOf('contract', 'com.acme.contracts'), opportunity])).toEqual([
50+
'opportunity', 'contract', 'contact',
51+
]);
52+
});
53+
54+
it('the authoring surface carries its source package, and never flags it unlisted', () => {
55+
const lists = deriveRelatedLists(declared, [account, contact, childOf('contract', 'com.acme.contracts'), opportunity] as never, { includeHidden: true });
56+
const contract = lists.find((r) => r.childObject === 'contract')!;
57+
expect(contract.fromPackage).toBe('com.acme.contracts');
58+
expect(contract.isUnlisted).toBeUndefined();
59+
// The record page asks for no hidden relationships, so no source rides along.
60+
expect(deriveRelatedLists(declared, [account, childOf('contract', 'com.acme.contracts')] as never)[0].fromPackage).toBeUndefined();
61+
});
62+
63+
it('undeclared: every list shows, as before', () => {
64+
expect(names(account, [account, contact, childOf('contract', 'com.acme.contracts'), opportunity])).toEqual([
65+
'contact', 'contract', 'opportunity',
66+
]);
67+
});
68+
});

‎ui/packages/app-shell/src/utils/deriveRelatedLists.ts‎

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@
6868
* `isUnlisted`). A body table (`isPrimary`) is the field groups' to place
6969
* and is kept, after the listed ones, with no tab of its own (no
7070
* `keepsTab`) unless an entry names it. Undeclared or empty: every list, as
71-
* before. The three built-in tab names (`RECORD_PAGE_BUILTIN_TABS` in
71+
* before. A side list ANOTHER package brings (the child and the parent
72+
* belong to different packages, objectstack#35901) is the exception: the
73+
* declared list does not hide it; that package places it (the server
74+
* splices its `place` into `relatedLists`), and an unplaced one is kept
75+
* after the listed ones, so the page draws it at the end of the tabs.
76+
* The three built-in tab names (`RECORD_PAGE_BUILTIN_TABS` in
7277
* `@objectstack/spec/data`) name the page's own tabs, never a child list;
7378
* the synthesized page places those (`buildDefaultTabs`).
7479
* - An entry's own TITLE and COLUMNS (objectstack#35899): the object form
@@ -197,9 +202,19 @@ export interface DerivedRelatedList {
197202
* True when the parent DECLARES `relatedLists` and no entry names this side
198203
* list (objectstack#35897), so the record page shows no tab for it — present
199204
* only when the caller asked for hidden relationships
200-
* ({@link DeriveRelatedListsOptions.includeHidden}), as `isHidden` is.
205+
* ({@link DeriveRelatedListsOptions.includeHidden}), as `isHidden` is. Never
206+
* on a list another package brings (objectstack#35901): that one shows.
201207
*/
202208
isUnlisted?: true;
209+
/**
210+
* The package the child object belongs to, when it is another package than
211+
* the parent's (objectstack#35901): a list that package brings, which the
212+
* parent's `relatedLists` does not hide and the package places itself.
213+
* Present only for the authoring surface
214+
* ({@link DeriveRelatedListsOptions.includeHidden}), which shows it read-only
215+
* with its source.
216+
*/
217+
fromPackage?: string;
203218
}
204219

205220
/**
@@ -261,6 +276,34 @@ interface MergedObjectLike {
261276
* records can never be read on any record page.
262277
*/
263278
enable?: { apiEnabled?: boolean };
279+
/**
280+
* The package that owns the object, as the server serves it (the registry
281+
* stamps its owner's package id; `'sys_metadata'` marks a definition bound
282+
* to no package). Read to tell a child list another package brings
283+
* (objectstack#35901).
284+
*/
285+
_packageId?: unknown;
286+
}
287+
288+
/** The package an object belongs to, or `undefined` for none (absent, empty, or bound to no package). */
289+
function packageOf(object: MergedObjectLike | null | undefined): string | undefined {
290+
const id = object?._packageId;
291+
return typeof id === 'string' && id !== '' && id !== NO_PACKAGE ? id : undefined;
292+
}
293+
294+
/** The `_packageId` the server stamps on a definition bound to no package. */
295+
const NO_PACKAGE = 'sys_metadata';
296+
297+
/**
298+
* objectstack#35901 — does `child` come from another package than `parent`?
299+
* Both must belong to a package, and the two differ. A child of the parent's
300+
* own package, or one no package owns, is not: those stay the parent's to
301+
* list (objectstack#35897).
302+
*/
303+
function isOtherPackageChild(child: MergedObjectLike, parent: MergedObjectLike): boolean {
304+
const childPackage = packageOf(child);
305+
const parentPackage = packageOf(parent);
306+
return childPackage !== undefined && parentPackage !== undefined && childPackage !== parentPackage;
264307
}
265308

266309
/**
@@ -429,7 +472,7 @@ export function deriveRelatedLists(
429472
// Working entries carry the FK label and the list's name so we can
430473
// disambiguate multi-FK children after the full sweep; both are stripped
431474
// from the returned descriptors.
432-
type Working = DerivedRelatedList & { _fkLabel: string; _listLabel: string };
475+
type Working = DerivedRelatedList & { _fkLabel: string; _listLabel: string; _otherPackage: boolean };
433476
const owned: Working[] = [];
434477
const referenced: Working[] = [];
435478

@@ -454,6 +497,8 @@ export function deriveRelatedLists(
454497
// rather than once per FK.
455498
const inheritedSort = inheritedListViewSort(child.list);
456499
const childLabel = child.label || child.name;
500+
// objectstack#35901 — a list another package brings is not the parent's to hide.
501+
const otherPackage = isOtherPackageChild(child, objectDef);
457502
const childListLabel = (listLabel && listLabel(child as MergedObjectLike & { name: string })) || childLabel;
458503
for (const [fieldName, fieldDef] of fieldEntries(child.fields)) {
459504
if (!fieldDef) continue;
@@ -492,6 +537,8 @@ export function deriveRelatedLists(
492537
...(hidden ? { isHidden: true as const } : {}),
493538
_fkLabel: (typeof fieldDef.label === 'string' && fieldDef.label) || fieldName,
494539
_listLabel: childListLabel,
540+
_otherPackage: otherPackage,
541+
...(otherPackage && options?.includeHidden ? { fromPackage: packageOf(child) } : {}),
495542
...(typeof fieldDef.relatedListTitle === 'string' && fieldDef.relatedListTitle
496543
? { title: fieldDef.relatedListTitle }
497544
: {}),
@@ -537,6 +584,14 @@ export function deriveRelatedLists(
537584
if (list.isPrimary) {
538585
const { keepsTab: _unlistedTab, ...bodyOnly } = list;
539586
all.push(bodyOnly);
587+
} else if (list._otherPackage) {
588+
// objectstack#35901 — a side list another package brings is not
589+
// hidden by the parent's list: that package places it with its object
590+
// extension's `place` (which the server splices into `relatedLists`,
591+
// so a placed one is named above); unplaced, it shows at the end of
592+
// the tabs (`arrangeDeclaredTabs`). Sales ruling 7073014077 flips the
593+
// hiding objectstack#35897 shipped (ruling 7072511859).
594+
all.push(list);
540595
} else if (options?.includeHidden) all.push({ ...list, isUnlisted: true });
541596
continue;
542597
}
@@ -557,7 +612,7 @@ export function deriveRelatedLists(
557612
const counts: Record<string, number> = {};
558613
for (const r of all) counts[r.childObject] = (counts[r.childObject] || 0) + 1;
559614

560-
return all.map(({ _fkLabel, _listLabel, ...rest }) => {
615+
return all.map(({ _fkLabel, _listLabel, _otherPackage, ...rest }) => {
561616
if (!rest.title && counts[rest.childObject] > 1) {
562617
return { ...rest, title: `${_listLabel} · ${_fkLabel}` };
563618
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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#35901 — the object settings panel shows a child list ANOTHER
11+
* package brings read-only, with its source: it is not one of this object's
12+
* entries (its package places it), so it stays in the unlisted rows with a
13+
* "from <package>" badge, and the preview draws it at the end of the tabs,
14+
* before a trailing activity-stream tab. Control: a child of this object's
15+
* own package carries no badge and the preview leaves it out.
16+
*/
17+
18+
import '@testing-library/jest-dom/vitest';
19+
import React from 'react';
20+
import { describe, it, expect, afterEach } from 'vitest';
21+
import { render, screen, cleanup, within } from '@testing-library/react';
22+
import { MetadataCtx, type MetadataContextValue } from '@object-ui/react';
23+
import { ObjectSettingsPanel } from './ObjectSettingsPanel';
24+
25+
afterEach(cleanup);
26+
27+
type Row = Record<string, unknown>;
28+
29+
const account: Row = { name: 'account', label: 'Account', _packageId: 'com.vendor.crm', fields: { name: { type: 'text', label: 'Name' } } };
30+
const child = (name: string, label: string, packageId: string): Row => ({
31+
name,
32+
label,
33+
_packageId: packageId,
34+
fields: { account_id: { type: 'lookup', reference: 'account', label: 'Account' } },
35+
});
36+
37+
function store(objects: Row[]): MetadataContextValue {
38+
return {
39+
apps: [],
40+
objects,
41+
dashboards: [],
42+
reports: [],
43+
pages: [],
44+
loading: false,
45+
error: null,
46+
refresh: async () => {},
47+
invalidate: () => {},
48+
ensureType: async () => [],
49+
getItem: async () => null,
50+
getItemsByType: () => [],
51+
getTypeStatus: () => 'ready',
52+
};
53+
}
54+
55+
function renderPanel(objects: Row[], draft: Row) {
56+
const value = store(objects);
57+
return render(
58+
<MetadataCtx.Provider value={value}>
59+
<ObjectSettingsPanel name="account" draft={draft} onPatch={() => {}} locale="en-US" />
60+
</MetadataCtx.Provider>,
61+
);
62+
}
63+
64+
describe('objectstack#35901 — a child list another package brings, in the settings panel', () => {
65+
const draft: Row = { name: 'account', label: 'Account', fields: account.fields, relatedLists: ['contact', 'sys_activity'] };
66+
67+
it('shows it unlisted with its source, and previews it at the end of the tabs', () => {
68+
renderPanel([account, child('contact', 'Contact', 'com.vendor.crm'), child('contract', 'Contract', 'com.acme.contracts')], draft);
69+
const row = screen.getByTestId('related-lists-tail-row-contract.account_id');
70+
expect(within(row).getByTestId('related-lists-from-package')).toHaveTextContent('from com.acme.contracts');
71+
expect(screen.getByTestId('related-lists-preview-side')).toHaveTextContent('Contact · Contract · Activity · Approvals');
72+
});
73+
74+
it('control: a child of this object\'s own package has no badge and does not show', () => {
75+
renderPanel([account, child('contact', 'Contact', 'com.vendor.crm'), child('contract', 'Contract', 'com.vendor.crm')], draft);
76+
const row = screen.getByTestId('related-lists-tail-row-contract.account_id');
77+
expect(within(row).queryByTestId('related-lists-from-package')).toBeNull();
78+
expect(screen.getByTestId('related-lists-preview-side')).not.toHaveTextContent('Contract');
79+
});
80+
});

‎ui/packages/app-shell/src/views/studio-design/RelatedListsEditor.tsx‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,22 @@ import {
6767
function Badges({ named, locale }: { named: readonly DerivedRelatedList[]; locale?: SupportedLocale }) {
6868
const hidden = named.length > 0 && named.every((r) => r.isHidden);
6969
const primary = !hidden && named.length > 0 && named.every((r) => r.isPrimary);
70-
if (!hidden && !primary) return null;
70+
// objectstack#35901 — a list another package brings: shown read-only with its source.
71+
const fromPackage = named.find((r) => r.fromPackage !== undefined)?.fromPackage;
72+
if (!hidden && !primary && fromPackage === undefined) return null;
7173
return (
72-
<span className="ml-1 rounded bg-muted px-1 text-[10px] text-muted-foreground">
73-
{hidden ? t('engine.studio.settings.relatedListsHidden', locale) : t('engine.studio.settings.relatedListsPrimary', locale)}
74-
</span>
74+
<>
75+
{(hidden || primary) && (
76+
<span className="ml-1 rounded bg-muted px-1 text-[10px] text-muted-foreground">
77+
{hidden ? t('engine.studio.settings.relatedListsHidden', locale) : t('engine.studio.settings.relatedListsPrimary', locale)}
78+
</span>
79+
)}
80+
{fromPackage !== undefined && (
81+
<span className="ml-1 rounded bg-muted px-1 text-[10px] text-muted-foreground" data-testid="related-lists-from-package">
82+
{tFormat('engine.studio.settings.relatedListsFromPackage', locale, { package: fromPackage })}
83+
</span>
84+
)}
85+
</>
7586
);
7687
}
7788

@@ -227,27 +238,38 @@ export function RelatedListsEditor({
227238
}),
228239
];
229240

230-
// What the record page will draw: its own derivation, over what a write keeps.
231-
const preview = deriveRelatedLists({ ...draft, name, relatedLists: listed }, catalog as never[]);
241+
// What the record page will draw: its own derivation, over what a write keeps
242+
// (with the served object's package, so a list another package brings shows
243+
// as it will, objectstack#35901).
244+
const servedPackage = catalog.find((o) => (o as { name?: unknown }).name === name)?._packageId;
245+
const preview = deriveRelatedLists(
246+
{ ...draft, name, relatedLists: listed, ...(servedPackage !== undefined ? { _packageId: servedPackage } : {}) },
247+
catalog as never[],
248+
);
232249
const body = preview.filter((r) => r.isPrimary);
233250
const side = preview.filter((r) => !r.isPrimary);
234251
// The tab strip after the overview: the listed tabs in order, then
235252
// approvals and the activity stream when they are not listed. Attachments
236253
// show only when listed and the object enables files.
237254
const tabs: string[] = [];
238255
const placedSide = new Set<DerivedRelatedList>();
256+
// Where the unlisted side lists go (objectstack#35901: before a trailing run
257+
// of listed approvals / stream tabs, as the record page arranges them).
258+
let unlistedAt = 0;
239259
for (const entry of listedNames) {
240260
if (isRecordPageBuiltinTab(entry)) {
241261
if (entry !== 'sys_attachment' || filesOn) tabs.push(builtinLabel(entry));
262+
if (entry !== 'sys_approval_request' && entry !== 'sys_activity') unlistedAt = tabs.length;
242263
continue;
243264
}
244265
for (const r of side) {
245266
if (placedSide.has(r) || !named(entry).some((n) => n.childObject === r.childObject && n.referenceField === r.referenceField)) continue;
246267
placedSide.add(r);
247268
tabs.push(relationshipLabel(r));
248269
}
270+
unlistedAt = tabs.length;
249271
}
250-
for (const r of side) if (!placedSide.has(r)) tabs.push(relationshipLabel(r));
272+
tabs.splice(unlistedAt, 0, ...side.filter((r) => !placedSide.has(r)).map(relationshipLabel));
251273
if (listedNames.length === 0 && filesOn) tabs.push(builtinLabel('sys_attachment'));
252274
for (const tab of ['sys_approval_request', 'sys_activity'] as const) {
253275
if (!listedNames.includes(tab)) tabs.push(builtinLabel(tab));

‎ui/packages/app-shell/src/views/studio-design/relatedListVocabulary.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ type ObjectDoc = Record<string, unknown>;
4949
* the draft adds is an inbound relationship too.
5050
*/
5151
export function catalogWithDraft(objects: readonly unknown[], name: string, draft: ObjectDoc): ObjectDoc[] {
52-
const own = { ...draft, name };
52+
const own: ObjectDoc = { ...draft, name };
5353
let replaced = false;
5454
const out: ObjectDoc[] = [];
5555
for (const o of objects) {
5656
if (!o || typeof o !== 'object') continue;
5757
if ((o as ObjectDoc).name === name) {
58-
out.push(own);
58+
// objectstack#35901 — the served object's package rides along, so a
59+
// child list another package brings is told apart (`fromPackage`).
60+
const served = (o as ObjectDoc)._packageId;
61+
out.push(own._packageId === undefined && served !== undefined ? { ...own, _packageId: served } : own);
5962
replaced = true;
6063
} else {
6164
out.push(o as ObjectDoc);
@@ -69,7 +72,10 @@ export function catalogWithDraft(objects: readonly unknown[], name: string, draf
6972
export function inboundRelationships(name: string, catalog: readonly ObjectDoc[]): DerivedRelatedList[] {
7073
// The derived order is the order with NO declared entries: the stored
7174
// `relatedLists` must not reorder the vocabulary it is judged against.
72-
return deriveRelatedLists({ name }, catalog as never[], { includeHidden: true });
75+
// objectstack#35901 — the parent's package (as the catalog holds it) tells a
76+
// child list another package brings, which the editor shows with its source.
77+
const packageId = catalog.find((o) => o.name === name)?._packageId;
78+
return deriveRelatedLists({ name, ...(packageId !== undefined ? { _packageId: packageId } : {}) }, catalog as never[], { includeHidden: true });
7379
}
7480

7581
/**

0 commit comments

Comments
 (0)