Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/36499-record-tab-config-installed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
'@object-ui/components': patch
---

feat(console): 「Configure tabs」 on an installed object writes its paired `.custom` package, marks where each tab comes from, and opens the record's 「…」

Clause-②: yes (widening)
Metadata-protocol: none

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.

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.

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.

The write is one shared helper, `saveObjectExtensionArrangement`, which replaces only the arrangement keys a caller returns (`relatedLists` here; `fieldGroups` for a field-layout editor).

`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 「…」.

New language-pack keys under `designMode.recordTabs` (`pairNotWritable`, `builtinMoves`, `sourceBase`, `sourcePackage`, `sourceEnvironment`) in all eleven console locales.
8 changes: 5 additions & 3 deletions ui/packages/app-shell/src/views/RecordDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5331,12 +5331,14 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
: onEdit({ id: pureRecordId }, objectName)),
} as any);
}
// objectstack#36499 — 「Configure tabs」, the first of the host's entries
// in the `⋯`, for an administrator who may arrange this object's tabs
// (`useRecordTabsConfig`'s gate: never on a phone, a drawer or a pane).
// objectstack#36499 — 「Configure tabs」, the first item of the `⋯`
// (`leadsMenu`, ahead of Refresh), for an administrator who may arrange
// this object's tabs (`useRecordTabsConfig`'s gate: never on a phone, a
// drawer or a pane).
if (tabsConfig.offered && !tabsConfig.active && !recordEditState) {
items.push({
name: RECORD_TABS_CONFIG_ACTION,
leadsMenu: true,
label: t('designMode.recordTabs.entry', { defaultValue: 'Configure tabs' }),
icon: 'panels-top-left',
type: 'script',
Expand Down
166 changes: 141 additions & 25 deletions ui/packages/app-shell/src/views/RecordTabsConfig.tsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* 「Configure tabs」 on an installed object (objectstack#36499, card items 4
* and 7): offered where Studio opens the base read-only and the customization
* door does not wall this caller off; every tab moves (another package's list
* and the built-in tabs too), a related tab hides, a built-in one does not;
* each related tab names where it comes from; 「Save」 writes the paired
* `.custom` extension's `relatedLists` through the ensure door's answer.
*
* Real subjects: `useRecordTabsConfig`, `RecordTabsEditor`, `saveRecordTabs`,
* `saveObjectExtensionArrangement`. Fakes: the gates' answers, the walled
* verdict, the package list and the ensure door, the metadata client (it
* records what is written) and the deployment's languages.
*/

import '@testing-library/jest-dom/vitest';
import * as React from 'react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';

const session = vi.hoisted(() => ({ view: true as boolean, walled: false as boolean }));
vi.mock('@object-ui/i18n', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useObjectTranslation: () => ({
t: (k: string, o?: Record<string, unknown>) =>
String(o?.defaultValue ?? k).replace(/\{\{(\w+)\}\}/g, (_hole, name: string) => String(o?.[name] ?? '')),
language: 'en',
}),
}));

const dragEnd = vi.hoisted(() => ({ current: null as null | ((event: unknown) => void) }));
vi.mock('@dnd-kit/core', async (importOriginal) => {
const real = await importOriginal<typeof import('@dnd-kit/core')>();
const { createElement } = await import('react');
return {
...real,
DndContext: (props: React.ComponentProps<typeof real.DndContext>) => {
dragEnd.current = props.onDragEnd as never;
return createElement(real.DndContext, props);
},
};
});

vi.mock('sonner', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
toast: { error: vi.fn(), success: vi.fn() },
}));

vi.mock('../../hooks/useStudioDesignGate', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useStudioDesignGate: () => null,
useStudioEntryGate: (path: string | null) => (session.view && path ? { path, posture: 'view' } : null),
}));

vi.mock('../studio-design/StudioCustomizeControls', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useCustomizeDoorWalled: () => session.walled,
}));

const BASE = 'app.hotcrm';
const PAIR = 'app.hotcrm.custom';

const written = vi.hoisted(() => [] as Array<[string, ...unknown[]]>);
const client = vi.hoisted(() => ({
layered: async () => {
const code = { name: 'lead', relatedLists: [{ list: 'contact', label: 'Contacts' }] };
return { code, effective: code };
},
get: async () => null,
save: async (...args: unknown[]) => {
written.push(['save', ...args]);
return {};
},
publish: async (...args: unknown[]) => {
written.push(['publish', ...args]);
return {};
},
reset: async () => ({}),
}));
vi.mock('../metadata-admin/useMetadata', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useMetadataClient: () => client,
}));
vi.mock('../studio-design/packages-io', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
fetchListedPackageManifests: async () =>
new Map([
['app.hotcrm', { id: 'app.hotcrm', name: 'HotCRM', writable: false, manifest: {} }],
['com.marketing', { id: 'com.marketing', name: 'Marketing', writable: false, manifest: {} }],
]),
ensureCustomizationPackage: async (base: string) => {
written.push(['ensure', base]);
return { basePackageId: base, packageId: 'app.hotcrm.custom', namespace: 'crm_custom', created: true, writable: true };
},
}));

import { useRecordTabsConfig } from '../RecordTabsConfig';
import { __resetDefaultLocale } from '../../layout/designModeMenuSave';

const toLead = { type: 'lookup', reference: 'lead' };
const OBJECTS: Record<string, unknown>[] = [
{ name: 'lead', label: 'Lead', _packageId: BASE, relatedLists: [{ list: 'contact', label: 'Contacts' }] },
{ name: 'contact', label: 'Contact', _packageId: BASE, fields: { lead: toLead } },
{ name: 'campaign_member', label: 'Campaign member', _packageId: 'com.marketing', fields: { lead: toLead } },
{ name: 'survey', label: 'Survey', _packageId: PAIR, fields: { lead: toLead } },
];

function Harness() {
const config = useRecordTabsConfig({
objectDef: OBJECTS[0],
objects: OBJECTS,
enabled: true,
titleOf: (list) => list.title || `${list.childLabel}s`,
});
return (
<MemoryRouter>
<span data-testid="offered">{String(config.offered)}</span>
{config.offered && !config.active && (
<button type="button" onClick={config.enter}>
enter
</button>
)}
{config.bar}
{config.editor}
</MemoryRouter>
);
}

const flush = () =>
act(async () => {
await new Promise((r) => setTimeout(r, 0));
});

beforeEach(() => {
written.length = 0;
session.view = true;
session.walled = false;
__resetDefaultLocale();
vi.stubGlobal(
'fetch',
vi.fn(async () => ({ ok: true, json: async () => ({ data: { locales: [{ code: 'en', isDefault: true }] } }) })),
);
});
afterEach(() => {
cleanup();
vi.unstubAllGlobals();
});

async function open() {
render(<Harness />);
fireEvent.click(screen.getByText('enter'));
await waitFor(() => expect(screen.getByTestId('record-tabs-config-bar')).toHaveAttribute('data-ready', 'true'));
await flush();
}

const shownTabs = () =>
Array.from(screen.getByTestId('record-tabs-editor').querySelectorAll('[data-record-tabs-tab]')).map((el) =>
el.getAttribute('data-record-tabs-tab'),
);

describe('「Configure tabs」 on an installed object (objectstack#36499)', () => {
it('is offered where Studio opens the base read-only, and not where the customization door walls this caller off', () => {
render(<Harness />);
expect(screen.getByTestId('offered')).toHaveTextContent('true');
cleanup();
session.walled = true;
render(<Harness />);
expect(screen.getByTestId('offered')).toHaveTextContent('false');
cleanup();
session.walled = false;
session.view = false;
render(<Harness />);
expect(screen.getByTestId('offered')).toHaveTextContent('false');
});

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 () => {
await open();
expect(shownTabs()).toEqual(['contact.lead', 'campaign_member.lead', 'survey.lead', 'sys_approval_request', 'sys_activity']);
const editor = screen.getByTestId('record-tabs-editor');
for (const id of ['contact.lead', 'campaign_member.lead', 'sys_activity']) {
expect(editor.querySelector(`[data-record-tabs-tab="${id}"] [data-record-tabs-handle]`)).not.toBeNull();
}
const tab = (id: string) => editor.querySelector(`[data-record-tabs-tab="${id}"]`) as HTMLElement;
expect(within(tab('campaign_member.lead')).getByRole('button', { name: 'Hide Campaign members' })).toBeEnabled();
expect(tab('sys_activity').querySelector('[data-record-tabs-hide]')).toBeNull();
expect(tab('contact.lead').querySelector('[data-record-tabs-source="base"]')).toHaveTextContent('Original package');
expect(tab('campaign_member.lead').querySelector('[data-record-tabs-source="package"]')).toHaveTextContent('From Marketing');
expect(tab('survey.lead').querySelector('[data-record-tabs-source="environment"]')).toHaveTextContent('This environment');
});

it("Save writes the pair's extension of the object, through the ensure door's answer, and publishes it", async () => {
await open();
fireEvent.click(screen.getByRole('button', { name: 'Hide Campaign members' }));
act(() => dragEnd.current?.({ active: { id: 'sys_activity' }, over: { id: 'contact.lead' } }));
expect(shownTabs()).toEqual(['sys_activity', 'contact.lead', 'survey.lead', 'sys_approval_request']);
fireEvent.click(screen.getByTestId('record-tabs-config-save'));
await flush();
await flush();
expect(written).toEqual([
['ensure', BASE],
[
'save',
'object_extension',
'lead',
{
extend: 'lead',
relatedLists: [
'sys_activity',
{ list: 'contact', label: 'Contacts' },
'survey',
'sys_approval_request',
{ list: 'campaign_member', hidden: true },
],
},
{ mode: 'draft', packageId: PAIR, ifNoneMatch: '*' },
],
['publish', 'object_extension', 'lead', { packageId: PAIR }],
]);
expect(screen.queryByTestId('record-tabs-config-bar')).toBeNull();
});
});
Loading
Loading