Skip to content

Commit d7411fa

Browse files
feat(console): configure tabs on installed objects, into the paired .custom package (#36499, PR 2 of 2) (#36624)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9Wq5utqEodnDCBh6heq37AG)_ Fixes #36499 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:管理员在已安装(只读)应用的记录页「…」第一项就能「配置页签」,可拖动全部页签、隐藏或恢复关联页签,每个页签标明来自原包、其他包还是本环境;保存后所有人看到新排列,原包不动。自建应用的入口也挪到「…」第一项。 - 为什么做:本卡「记录页就地配置页签」的第二个也是最后一个合并请求,替管理员省去进 Studio 改已安装对象的绕路。 - 出错会怎样:只影响已安装对象记录页的页签排列,写在该应用配对的定制包里;管理员可再次进入配置改回,原包始终不变。定制总览读接口暂不列出页签排列,已另开卡跟进(定制总览列出页签排列)。 - 要你做什么:无(是否允许在已安装对象上隐藏附件、审批、动态三个内置页签,已另开决策卡等你裁定)。 ## What changes **Installed objects (card items 4 and 7).** On the record page of an object whose package is installed read-only, 「Configure tabs」 is now offered too. The gate is PR 1's admin gate (Studio opens the object, posture `view` here) plus `useCustomizeDoorWalled()`: where the customization door is walled (`group` / `isolated`), the entry is not offered. The edit state is the same one PR 1 built: the design-mode shell from #36437, reused unchanged. - Every tab can be moved: the object's own lists, a list another package brings, and the built-in 附件 / 审批 / 动态. - A related tab can be hidden and shown again. A built-in tab cannot be hidden here, because the `.custom` list cannot hide it (spec: "cannot be hidden here"). An attachments tab the base does not draw waits in 「Hidden」 and can be shown from there. - Each related tab carries a source mark: 「Original package」, 「From PACKAGE」 or 「This environment」. - 「Save」 writes the `relatedLists` of the pair's object extension (`object_extension`, filed under the object's name, in the base's paired `.custom` package), in #36498's shape. The write lists every shown tab in order (a built-in by its bare name) and then every hidden related tab as `{ list, hidden: true }`. A tab the list does not name is served after the named ones. - The pair is resolved through the ensure door (`POST /packages/:id/ensure-customization`). That door creates the pair on the first save, as Studio does. A pair the server does not list as writable is refused before any write. **One shared writer.** `views/objectExtensionArrangementSave.ts`, `saveObjectExtensionArrangement`, is the only write of an installed object's arrangement keys (`CUSTOM_ARRANGEMENT_KEYS`). - It reads the pair's STORED extension and the object as stored (the layered read). - It replaces only the keys its caller returns. Every other key is kept: `fields`, `fieldPatches`, `place`, the other arrangement key. - It saves a draft with the first-write pin (`ifNoneMatch: '*'`), then publishes. A refused publish discards that draft. - It announces the refresh through the door. The field-layout editor in #36505 is meant to be its second caller (`fieldGroups`). #36505 is not implemented here. `resolveRecordTabsSaveTarget` now answers `{ kind: 'package' } | { kind: 'pair' }`. **The 「…」 entry is the first item (card item 1).** `page:header` (`containers.tsx`): a host overflow entry that declares `leadsMenu: true` is drawn first, ahead of Refresh, with a separator. Only host entries can claim this place; an authored action cannot. The record page's 「Configure tabs」 declares it, on self-built and installed objects alike. No other entry declares it, so no other menu changes. **A stored title is kept (fix to PR 1's write).** Since #36574, the served `relatedLists` labels are translated for the reader. PR 1 wrote the editor's labels back as they were, which would have stored a reader's translation as the title. Now a tab's stored label is written unless the administrator renamed it (`recordTabLabelToWrite`). This holds on both paths. **i18n.** New keys under `designMode.recordTabs`: `pairNotWritable`, `builtinMoves`, `sourceBase`, `sourcePackage`, `sourceEnvironment`. They are added to all eleven locales; zh-Hant is regenerated by `gen-zh-hant`. ## Tests New files, named for the card: - `ui/packages/app-shell/src/views/__tests__/objectExtensionArrangementSave-36499.test.ts` (6) - `ui/packages/app-shell/src/views/__tests__/recordTabsInstalled-36499.test.ts` (7) - `ui/packages/app-shell/src/views/__tests__/RecordTabsConfigInstalled-36499.test.tsx` (3) **Existing tests changed** (both are PR 1's): - `ui/packages/app-shell/src/views/__tests__/recordTabsConfigSave-36499.test.ts`: - the doors gain `ensureCustomization` and `client.get`; - TEXTS gains `pairNotWritable`; - the read-only refusal case is replaced by the pair target; - the seam test expects the pair target. - `ui/packages/components/src/__tests__/page-header-overflow-close-36499.test.tsx`: - `renderHeader` takes `headerSystemActions`; - a new describe has 2 cases for `leadsMenu`. Ablations. The fix was committed first. Each mutation was written with `ablation-replace.mjs`, and each restore was proven by blob == HEAD. - Dropping the `leadsMenu` flag: 1 test red. - `recordTabLabelToWrite` returning the served label: 2 tests red. <details><summary>Test and gate runs at head c7f9b58 (all through os-verify-lock)</summary> - The card's files plus PR 1's: 7 files, 44/44 passed. - `packages/app-shell/src/views/RecordDetailView.*`: 99 files, 826/826 passed. - components `page-header*`, `layout-containers*`, `horizontal-overflow*`, `page-tabs*`, plus plugin-detail `RecordPageColumns*` and `RecordRelatedListRenderer*`: 64 files, 598/598 passed. - i18n `src/__tests__`: 106 files, 1978 passed and 13 skipped. - `ui/scripts/` (a derived family): 174 files, 5127 passed and 2 skipped. - `type-check` (both `tsconfig.json` and `tsconfig.test.json`) for app-shell, components and i18n: exit 0. - `dispatch-gates --commands`: 41 derived families, all run, all exit 0. `--ran` reconciles them as 41 run, 0 NOT-MEASURED. - The 40 `ui` lint-workflow checks, including `check:spec-symbols`, `check:i18n-keys`, `check:i18n-drift` and `check:metadata-write-doors`: exit 0. - `check:doc-examples`, `check:doc-snippets` and `check:readme-exports` first answered PRECONDITION NOT MET because `@object-ui/cli` was not built. After building it, all three gave exit 0. - `check:new-line-citations`: exit 0. - `check:test-source-alias` and `check:nul-bytes` (both derived): exit 0. - eslint with the ADR-0054 `no-synthetic-event-trigger` ratchet, on the 24 changed ui files: exit 0. </details> At head 28193db (patch round 1, after a merge of main): own and PR 1 files plus `DataPillar.panelHold-27629` 8 files 49/49; `ui/scripts/` 5127 passed and 2 skipped; app-shell and components `type-check` exit 0; 41 derived families exit 0, with `--ran` reporting 0 NOT-MEASURED; `check:i18n-keys`, `check:i18n-drift`, `check:spec-symbols`, `check:new-line-citations` and the three `check:vi-mock-*` checks exit 0. The large neighbour suites (RecordDetailView.*, i18n, page-header) were not re-run locally after this merge; CI runs them. ## Acceptance notes - **The customizations read does not list an arrangement: moved to #36626** (seat routing, 2026-11-23 04:26Z). After the save, `GET /api/v1/packages/com.example.showcase/customizations` answered `200` with every list empty. The extension itself is there: `GET /api/v1/meta/object_extension/showcase_account?package=com.example.showcase.custom` answers it. The read's contract is strict and names exactly three member kinds, `extensions.kind` = `field` | `validation` | `index`, so a `relatedLists`-only extension (and a `fieldGroups`-only one, for #36505) has no entry to appear as. Making it appear is a spec and runtime change, carried by #36626, not by this PR. - **H2 (a per-tab source on `_relatedListsArrangement`) does not hold; the narrow gap below is an accepted deviation** (seat routing, 2026-11-23 04:26Z; no card). The decoration carries `{ packageId, hidden, unlisted }` and nothing per tab. The source marks are derived from data the client already has: - the child object's `_packageId`: the base means the original package; `sys_metadata` or a `.custom` package means this environment; anything else means that package; - a relationship field named `__c` means this environment. The remaining gap: a relationship field that another package's extension adds to a base-owned child object shows as 「Original package」. Closing it needs a per-tab source from the server. No spec or server change is made here. - **Built-in tabs stay locked here: hiding them goes to decision card #36627** (seat routing, 2026-11-23 04:26Z). On installed objects 附件 / 审批 / 动态 can be moved but not hidden: the spec says the `.custom` list cannot hide them ("cannot be hidden here"). They are not renamable either, on either path: a built-in entry is a bare name in the spec's shape and carries no label, so there is no place to store a rename. Seat ruling 7089839334 (no spec card for hiding 审批/动态 on self-built objects) is unchanged. - **Translated labels.** PR 1 combined with #36574 would have written a reader's translated tab title into the stored definition on any save. Fixed on both paths; see What changes. - **Visible effect beyond the card.** 「Configure tabs」 now sits above Refresh in every record 「…」 where it is offered, including on self-built objects (PR 1 placed it after Refresh). No other menu entry moves. - **Observation, not filed.** For an installed object, the layered read's `code` layer (`GET /meta/object/showcase_account/layers?package=com.example.showcase`) answered the extension-folded `relatedLists`, while the showcase source declares none. The writer reads entries in the order extension first, then owner, so this does not change what is written. I note it because a reader of `code` would take the result for the package's own definition. - **CI patch round 1 (head 28193db).** At c7f9b58, `Test UI (13/16)` went red on one test that this change does not touch: `DataPillar.panelHold-27629` › "Show me" reopens the action…, a 3000 ms `waitFor` on the held line. That test was last changed by #36597 on main. No file in its import graph is in this diff, and the dom project runs `isolate: true`, so no other file's mocks reach it. Under os-verify-lock it passed alone (5/5) and with all 41 `DataPillar.*` files on 4 workers (209/209). The merge group's CI for #36597 and the later runs on main are green. I read it as a timing flake in a loaded shard (that file took 10 s there), not a defect of this change, so no code or test was changed for it. The new head is a merge of main (3110de5), which re-runs CI. - **H1 holds.** The extension is written as `object_extension` in the pair, and only `relatedLists` is replaced (unit: `objectExtensionArrangementSave-36499` keeps `fields`, `fieldPatches`, `place` and `fieldGroups`). Live: the second save in the browser pass read back the first save's extension and replaced only its list. ## Verification Browser pass at head `0aacc5aad`, with the same code as this head; the merge of main brought in no file this change reads. - Booted example app: `examples/app-showcase` (`objectstack dev --ui --seed-admin`, own port and DB). The console was rebuilt from this branch. - Installed read-only package: `com.example.showcase` (type app, `writable: false`). - Object: `showcase_account`, record Northwind. - Before the first save: no `com.example.showcase.custom` package existed, and the customizations read was empty. - To show a tab from another package, the run's DB holds a QA package `com.qa.tabs` with an object `qtab_visit` that looks up `showcase_account`. It exists only in the run's DB. <details><summary>Admin, 1440: reorder, hide, save, reload</summary> - 「…」 read `Configure tabs, Refresh, Share, Change Owner, Delete`. - Editor chips: - `showcase_contact` [Original package] - `showcase_field_zoo.f_lookup` [Original package] - `showcase_field_zoo.f_lookups` [Original package] - `qtab_visit` [From Tabs QA] - 审批 - 动态 - I dragged Visits first, hid 「Field Zoo · Lookup → Accounts (multiple)」 and saved. The writes, in order: - `POST /api/v1/packages/com.example.showcase/ensure-customization` - `PUT /api/v1/meta/object_extension/showcase_account?mode=draft&package=com.example.showcase.custom` - `POST /api/v1/meta/object_extension/showcase_account/publish?package=com.example.showcase.custom` - Nothing was written to `com.example.showcase`. - Tabs after save and after a reload: `Details, Visits, Contacts, Field Zoo, Activity`. - The pair's extension then read `{"extend":"showcase_account","relatedLists":["qtab_visit","showcase_contact","showcase_field_zoo.f_lookup","sys_approval_request","sys_activity",{"list":"showcase_field_zoo.f_lookups","hidden":true}]}`. - The served object carries `_relatedListsArrangement: {"packageId":"com.example.showcase.custom","hidden":["showcase_field_zoo.f_lookups"],"unlisted":"shown"}`. </details> <details><summary>Original package unchanged</summary> - `GET /meta/object/showcase_account/layers?package=com.example.showcase` answers `overlay: null`, `draft: null`, `provenance: package`, `editable: false`. - `GET /meta/object_extension?package=com.example.showcase` answers `items: []`. - `git status examples/` is clean. - The customizations read: see Acceptance notes. </details> <details><summary>Another account (plain member), 1440 and 1280</summary> - 「…」 read `Refresh, Share`: no entry. - The member's served object carries the same `relatedLists` and the same `_relatedListsArrangement`. - Tabs drawn: `Details, Field Zoo, Activity`. The multi-lookup tab is hidden. Visits and Contacts are not drawn because the member has no read on `qtab_visit` and `showcase_contact` (`403 PERMISSION_DENIED` on the data read), as before this change. </details> <details><summary>Admin, 1280: second save over the existing extension</summary> - The menu's first item is 「Configure tabs」. - On reopening, the editor shows the saved order and 「Field Zoo · Lookup → Accounts (multiple)」 in 「Hidden」. - I moved 动态 ahead of 审批, showed the hidden tab again and saved. The same three writes followed (ensure, pinned draft, publish). - After a reload: `Details, Visits, Contacts, Field Zoo · Lookup → Account, Field Zoo · Lookup → Accounts (multiple), Activity`. - A separate drag (not saved) moved 动态 to the very front, so built-ins move to any place. </details> <details><summary>Self-built path (PR 1), admin, 1280</summary> - On `qtab_account` (package `com.qa.tabs`, writable), 「…」 read `Configure tabs, Refresh, …`. - Chips carry no source mark. - I dragged People first and saved. The writes were `PUT /meta/object/qtab_account?mode=draft&package=com.qa.tabs`, then `POST …/publish?package=com.qa.tabs`. - After a reload: `People, Deals, Tickets, Attachments, Activity`. </details> The 「This environment」 mark is covered by `RecordTabsConfigInstalled-36499` and `recordTabsInstalled-36499`. It was not set up in the browser. Screenshots (`/mnt/project-files/objectstack-seat2/shots/36499-pr2/`): - `01-admin-1440-menu-first-item.png`: 「Configure tabs」 first in 「…」 on the installed object - `02-admin-1440-installed-edit-state.png`: the edit state with source marks - `03-admin-1440-installed-moved-hidden.png`: Visits moved first, multi-lookup tab in 「Hidden」 - `04-admin-1440-installed-after-reload.png`: after save and reload - `05-member-1440-installed-menu-no-entry.png`, `05-member-1280-installed-menu-no-entry.png`: the member's 「…」 and tabs - `06-admin-1280-menu-first-item.png`: the entry first at 1280 - `07-admin-1280-installed-reopened.png`: reopened on the saved arrangement - `08-admin-1280-installed-moved-restored.png`: 动态 moved, hidden tab shown again - `09-admin-1280-installed-after-reload.png`: after the second save and reload - `10-admin-1280-selfbuilt-edit.png`, `11-admin-1280-selfbuilt-after-reload.png`: the self-built path Files to read first, by risk: 1. `ui/packages/app-shell/src/views/objectExtensionArrangementSave.ts`: which keys are kept and which are replaced, the pinned draft, publish, and the discard on a refused publish. 2. `ui/packages/app-shell/src/views/recordTabsInstalled.ts`, `installedTabsEntries`: what the pair's list holds (built-ins bare, hidden related tabs, kept unknown entries, stored labels). 3. `ui/packages/components/src/renderers/layout/containers.tsx`: `leadsMenu`, in the record bar and in the state-group menu. Two-minute check: in `examples/app-showcase`, run `objectstack dev --ui --seed-admin`. As admin, open any Account record and open 「…」. The first item is 「Configure tabs」. Hide a tab, drag another, and save. `GET /api/v1/meta/object_extension/showcase_account?package=com.example.showcase.custom` answers the new `relatedLists`. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmP8GZoB2rUETxwNEDv)_ <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmP8GZoB2rUETxwNEDv --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 17f3db8 commit d7411fa

25 files changed

Lines changed: 1418 additions & 77 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
'@object-ui/components': patch
5+
---
6+
7+
feat(console): 「Configure tabs」 on an installed object writes its paired `.custom` package, marks where each tab comes from, and opens the record's 「…」
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
On the record page of an object of an installed (read-only) package, a workspace administrator who may author metadata now finds 「Configure tabs」 too, where the customization door does not wall them off (the walled `group` / `isolated` postures leave it to the platform operator). Its 「Save」 writes the `relatedLists` of the object extension of the base's paired `.custom` package in the spec's shape (ADR-0146 D10): every shown tab in order, a built-in tab by its bare name, and every hidden related tab written `{ list, hidden: true }`; the pair is created on the first save by the ensure door, as Studio creates it. The extension is written over what the pair stores, with only its `relatedLists` replaced (`fields`, `fieldPatches`, `place` and `fieldGroups` kept), as a draft with the first-write pin, then published; a refused publish discards that draft. The original package is not written.
13+
14+
On an installed object every tab can be moved: the object's own lists, a list another package brings, and the built-in 附件 / 审批 / 动态. A related tab can be hidden and shown again; a built-in tab cannot be hidden there (the `.custom` list cannot hide it), and an attachments tab the base hides waits in 「Hidden」, from which it can be shown. Each related tab is marked 「Original package」, 「From <package>」 or 「This environment」, read from the child object's package and the relationship field.
15+
16+
A tab's stored title is kept when the administrator did not rename it, on self-built and installed objects alike: the name the editor shows is the served one, which the read translates for the reader's language.
17+
18+
The write is one shared helper, `saveObjectExtensionArrangement`, which replaces only the arrangement keys a caller returns (`relatedLists` here; `fieldGroups` for a field-layout editor).
19+
20+
`page:header`: a host `⋯` entry declaring `leadsMenu: true` is drawn first, ahead of Refresh; an authored action cannot claim the place. The record page's 「Configure tabs」 declares it, so it is the first item of the record's 「…」.
21+
22+
New language-pack keys under `designMode.recordTabs` (`pairNotWritable`, `builtinMoves`, `sourceBase`, `sourcePackage`, `sourceEnvironment`) in all eleven console locales.

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5331,12 +5331,14 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
53315331
: onEdit({ id: pureRecordId }, objectName)),
53325332
} as any);
53335333
}
5334-
// objectstack#36499 — 「Configure tabs」, the first of the host's entries
5335-
// in the `⋯`, for an administrator who may arrange this object's tabs
5336-
// (`useRecordTabsConfig`'s gate: never on a phone, a drawer or a pane).
5334+
// objectstack#36499 — 「Configure tabs」, the first item of the `⋯`
5335+
// (`leadsMenu`, ahead of Refresh), for an administrator who may arrange
5336+
// this object's tabs (`useRecordTabsConfig`'s gate: never on a phone, a
5337+
// drawer or a pane).
53375338
if (tabsConfig.offered && !tabsConfig.active && !recordEditState) {
53385339
items.push({
53395340
name: RECORD_TABS_CONFIG_ACTION,
5341+
leadsMenu: true,
53405342
label: t('designMode.recordTabs.entry', { defaultValue: 'Configure tabs' }),
53415343
icon: 'panels-top-left',
53425344
type: 'script',

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

Lines changed: 141 additions & 25 deletions
Large diffs are not rendered by default.
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* 「Configure tabs」 on an installed object (objectstack#36499, card items 4
5+
* and 7): offered where Studio opens the base read-only and the customization
6+
* door does not wall this caller off; every tab moves (another package's list
7+
* and the built-in tabs too), a related tab hides, a built-in one does not;
8+
* each related tab names where it comes from; 「Save」 writes the paired
9+
* `.custom` extension's `relatedLists` through the ensure door's answer.
10+
*
11+
* Real subjects: `useRecordTabsConfig`, `RecordTabsEditor`, `saveRecordTabs`,
12+
* `saveObjectExtensionArrangement`. Fakes: the gates' answers, the walled
13+
* verdict, the package list and the ensure door, the metadata client (it
14+
* records what is written) and the deployment's languages.
15+
*/
16+
17+
import '@testing-library/jest-dom/vitest';
18+
import * as React from 'react';
19+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
20+
import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
21+
import { MemoryRouter } from 'react-router-dom';
22+
23+
const session = vi.hoisted(() => ({ view: true as boolean, walled: false as boolean }));
24+
vi.mock('@object-ui/i18n', async (importOriginal) => ({
25+
...(await importOriginal<Record<string, unknown>>()),
26+
useObjectTranslation: () => ({
27+
t: (k: string, o?: Record<string, unknown>) =>
28+
String(o?.defaultValue ?? k).replace(/\{\{(\w+)\}\}/g, (_hole, name: string) => String(o?.[name] ?? '')),
29+
language: 'en',
30+
}),
31+
}));
32+
33+
const dragEnd = vi.hoisted(() => ({ current: null as null | ((event: unknown) => void) }));
34+
vi.mock('@dnd-kit/core', async (importOriginal) => {
35+
const real = await importOriginal<typeof import('@dnd-kit/core')>();
36+
const { createElement } = await import('react');
37+
return {
38+
...real,
39+
DndContext: (props: React.ComponentProps<typeof real.DndContext>) => {
40+
dragEnd.current = props.onDragEnd as never;
41+
return createElement(real.DndContext, props);
42+
},
43+
};
44+
});
45+
46+
vi.mock('sonner', async (importOriginal) => ({
47+
...(await importOriginal<Record<string, unknown>>()),
48+
toast: { error: vi.fn(), success: vi.fn() },
49+
}));
50+
51+
vi.mock('../../hooks/useStudioDesignGate', async (importOriginal) => ({
52+
...(await importOriginal<Record<string, unknown>>()),
53+
useStudioDesignGate: () => null,
54+
useStudioEntryGate: (path: string | null) => (session.view && path ? { path, posture: 'view' } : null),
55+
}));
56+
57+
vi.mock('../studio-design/StudioCustomizeControls', async (importOriginal) => ({
58+
...(await importOriginal<Record<string, unknown>>()),
59+
useCustomizeDoorWalled: () => session.walled,
60+
}));
61+
62+
const BASE = 'app.hotcrm';
63+
const PAIR = 'app.hotcrm.custom';
64+
65+
const written = vi.hoisted(() => [] as Array<[string, ...unknown[]]>);
66+
const client = vi.hoisted(() => ({
67+
layered: async () => {
68+
const code = { name: 'lead', relatedLists: [{ list: 'contact', label: 'Contacts' }] };
69+
return { code, effective: code };
70+
},
71+
get: async () => null,
72+
save: async (...args: unknown[]) => {
73+
written.push(['save', ...args]);
74+
return {};
75+
},
76+
publish: async (...args: unknown[]) => {
77+
written.push(['publish', ...args]);
78+
return {};
79+
},
80+
reset: async () => ({}),
81+
}));
82+
vi.mock('../metadata-admin/useMetadata', async (importOriginal) => ({
83+
...(await importOriginal<Record<string, unknown>>()),
84+
useMetadataClient: () => client,
85+
}));
86+
vi.mock('../studio-design/packages-io', async (importOriginal) => ({
87+
...(await importOriginal<Record<string, unknown>>()),
88+
fetchListedPackageManifests: async () =>
89+
new Map([
90+
['app.hotcrm', { id: 'app.hotcrm', name: 'HotCRM', writable: false, manifest: {} }],
91+
['com.marketing', { id: 'com.marketing', name: 'Marketing', writable: false, manifest: {} }],
92+
]),
93+
ensureCustomizationPackage: async (base: string) => {
94+
written.push(['ensure', base]);
95+
return { basePackageId: base, packageId: 'app.hotcrm.custom', namespace: 'crm_custom', created: true, writable: true };
96+
},
97+
}));
98+
99+
import { useRecordTabsConfig } from '../RecordTabsConfig';
100+
import { __resetDefaultLocale } from '../../layout/designModeMenuSave';
101+
102+
const toLead = { type: 'lookup', reference: 'lead' };
103+
const OBJECTS: Record<string, unknown>[] = [
104+
{ name: 'lead', label: 'Lead', _packageId: BASE, relatedLists: [{ list: 'contact', label: 'Contacts' }] },
105+
{ name: 'contact', label: 'Contact', _packageId: BASE, fields: { lead: toLead } },
106+
{ name: 'campaign_member', label: 'Campaign member', _packageId: 'com.marketing', fields: { lead: toLead } },
107+
{ name: 'survey', label: 'Survey', _packageId: PAIR, fields: { lead: toLead } },
108+
];
109+
110+
function Harness() {
111+
const config = useRecordTabsConfig({
112+
objectDef: OBJECTS[0],
113+
objects: OBJECTS,
114+
enabled: true,
115+
titleOf: (list) => list.title || `${list.childLabel}s`,
116+
});
117+
return (
118+
<MemoryRouter>
119+
<span data-testid="offered">{String(config.offered)}</span>
120+
{config.offered && !config.active && (
121+
<button type="button" onClick={config.enter}>
122+
enter
123+
</button>
124+
)}
125+
{config.bar}
126+
{config.editor}
127+
</MemoryRouter>
128+
);
129+
}
130+
131+
const flush = () =>
132+
act(async () => {
133+
await new Promise((r) => setTimeout(r, 0));
134+
});
135+
136+
beforeEach(() => {
137+
written.length = 0;
138+
session.view = true;
139+
session.walled = false;
140+
__resetDefaultLocale();
141+
vi.stubGlobal(
142+
'fetch',
143+
vi.fn(async () => ({ ok: true, json: async () => ({ data: { locales: [{ code: 'en', isDefault: true }] } }) })),
144+
);
145+
});
146+
afterEach(() => {
147+
cleanup();
148+
vi.unstubAllGlobals();
149+
});
150+
151+
async function open() {
152+
render(<Harness />);
153+
fireEvent.click(screen.getByText('enter'));
154+
await waitFor(() => expect(screen.getByTestId('record-tabs-config-bar')).toHaveAttribute('data-ready', 'true'));
155+
await flush();
156+
}
157+
158+
const shownTabs = () =>
159+
Array.from(screen.getByTestId('record-tabs-editor').querySelectorAll('[data-record-tabs-tab]')).map((el) =>
160+
el.getAttribute('data-record-tabs-tab'),
161+
);
162+
163+
describe('「Configure tabs」 on an installed object (objectstack#36499)', () => {
164+
it('is offered where Studio opens the base read-only, and not where the customization door walls this caller off', () => {
165+
render(<Harness />);
166+
expect(screen.getByTestId('offered')).toHaveTextContent('true');
167+
cleanup();
168+
session.walled = true;
169+
render(<Harness />);
170+
expect(screen.getByTestId('offered')).toHaveTextContent('false');
171+
cleanup();
172+
session.walled = false;
173+
session.view = false;
174+
render(<Harness />);
175+
expect(screen.getByTestId('offered')).toHaveTextContent('false');
176+
});
177+
178+
it("every tab moves, another package's and the built-in ones too; a related tab hides, a built-in one does not; each related tab names its source", async () => {
179+
await open();
180+
expect(shownTabs()).toEqual(['contact.lead', 'campaign_member.lead', 'survey.lead', 'sys_approval_request', 'sys_activity']);
181+
const editor = screen.getByTestId('record-tabs-editor');
182+
for (const id of ['contact.lead', 'campaign_member.lead', 'sys_activity']) {
183+
expect(editor.querySelector(`[data-record-tabs-tab="${id}"] [data-record-tabs-handle]`)).not.toBeNull();
184+
}
185+
const tab = (id: string) => editor.querySelector(`[data-record-tabs-tab="${id}"]`) as HTMLElement;
186+
expect(within(tab('campaign_member.lead')).getByRole('button', { name: 'Hide Campaign members' })).toBeEnabled();
187+
expect(tab('sys_activity').querySelector('[data-record-tabs-hide]')).toBeNull();
188+
expect(tab('contact.lead').querySelector('[data-record-tabs-source="base"]')).toHaveTextContent('Original package');
189+
expect(tab('campaign_member.lead').querySelector('[data-record-tabs-source="package"]')).toHaveTextContent('From Marketing');
190+
expect(tab('survey.lead').querySelector('[data-record-tabs-source="environment"]')).toHaveTextContent('This environment');
191+
});
192+
193+
it("Save writes the pair's extension of the object, through the ensure door's answer, and publishes it", async () => {
194+
await open();
195+
fireEvent.click(screen.getByRole('button', { name: 'Hide Campaign members' }));
196+
act(() => dragEnd.current?.({ active: { id: 'sys_activity' }, over: { id: 'contact.lead' } }));
197+
expect(shownTabs()).toEqual(['sys_activity', 'contact.lead', 'survey.lead', 'sys_approval_request']);
198+
fireEvent.click(screen.getByTestId('record-tabs-config-save'));
199+
await flush();
200+
await flush();
201+
expect(written).toEqual([
202+
['ensure', BASE],
203+
[
204+
'save',
205+
'object_extension',
206+
'lead',
207+
{
208+
extend: 'lead',
209+
relatedLists: [
210+
'sys_activity',
211+
{ list: 'contact', label: 'Contacts' },
212+
'survey',
213+
'sys_approval_request',
214+
{ list: 'campaign_member', hidden: true },
215+
],
216+
},
217+
{ mode: 'draft', packageId: PAIR, ifNoneMatch: '*' },
218+
],
219+
['publish', 'object_extension', 'lead', { packageId: PAIR }],
220+
]);
221+
expect(screen.queryByTestId('record-tabs-config-bar')).toBeNull();
222+
});
223+
});

0 commit comments

Comments
 (0)