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
24 changes: 24 additions & 0 deletions .changeset/35595-35596-record-tabs-rail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@object-ui/app-shell': patch
'@object-ui/components': patch
'@object-ui/i18n': patch
'@object-ui/plugin-detail': patch
---

feat(record-page): one tab per related list, and an Overview rail that sums up the other tabs

Clause-②: no
Metadata-protocol: none

The record page's tab row and its right column are redrawn (supersedes objectstack#28469):

- **Tabs.** Overview, then one tab per related list in its order, then Attachments, Approvals and Activity last. Every tab is there at first paint and none moves when the counts land. A list with no records keeps its place, greyed, with no number. The width is the row's only fold: the tabs that do not fit go into 「更多 N ▾」, whose items keep their counts. Approvals carries a dot while a request waits, not a count. A tab that merges several tables (only an explicit page can write one) carries no count.
- **Overview.** The stage path and the key fields sit across the whole width on Overview only; every other tab draws its block in full in their place.
- **Right rail.** On Overview, the right column sums up the other tabs, in this order: Approvals, Attachments, Recent activity, then 「其他相关」 with a card for each related list that has records. Each card has a title (which opens its tab), a grey count and at most three rows. A card with nothing to show is not drawn, and there is no 「还有 N 个空关联」 line. Nothing in the rail is editable. A rail with no cards folds away. A drawer draws no rail and no right-column switch. The rail's rows come from the page's one read: it reads nothing more.
- **No band at the foot.** A page drawn as written that places no approvals or attachments panel gets them as tabs of its first tab strip, not as bands under the page. The header's approval tag opens the Approvals tab.
- **One approval band.** A page drawn as written whose details are split into several `record:details` nodes draws the record's approval band once, on the first body that reaches it, recall included.

- **Reader arrangement leaves with the cards.** The related cards' ⠿ handle, ⌥↑ / ⌥↓ and 「隐藏」 are gone with the cards, so a reader can no longer reorder or hide a related list on the page. An order or hides already stored still apply, and 「恢复默认顺序」 / 「显示」 still undo them.
- **`?tab=related` is retired.** The single 「Related」 tab is gone, so a saved link carrying `?tab=related` opens Overview.

`@object-ui/plugin-detail` adds `ApprovalBandOnceScope`. `@object-ui/i18n` adds the 「更多 N」 trigger and the rail's labels in every pack. Nothing an app authors changes.
44 changes: 34 additions & 10 deletions docs/qa/platform-checklist/areas/records-forms.json

Large diffs are not rendered by default.

591 changes: 591 additions & 0 deletions ui/e2e/record-tabs-rail-35595.spec.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ async function mountLeadPage() {
const objects = [LEAD, TASK];
const findOne = vi.fn(async () => ({ id: 'L1', name: 'Ada', company: 'Acme', city: 'Paris' }));
const dataSource = {
find: vi.fn(async () => ({ data: [] })),
// The lead has one task, so the right rail draws its card (objectstack#35596).
find: vi.fn(async (object: string) =>
object === 'task' ? { data: [{ id: 't1', subject: 'Call back' }], total: 1 } : { data: [] },
),
findOne,
create: vi.fn(async () => ({})),
update: vi.fn(async () => ({})),
Expand Down Expand Up @@ -170,11 +173,13 @@ afterEach(() => {
});

describe('objectui#12625 — the record page names its regions, header actions and section headers', () => {
it('the right column and its panels are named by their labels', async () => {
it('the right column and its cards are named by their labels; the 动态 tab by its label', async () => {
await mountLeadPage();
const right = screen.getByRole('complementary', { name: 'Right column' });
expect(right).toBeInTheDocument();
expect(within(right).getByRole('region', { name: 'Activity' })).toBeInTheDocument();
// objectstack#35595 / #35596 — the stream is the Activity tab; the rail's
// cards are regions named by their titles.
expect(screen.getByRole('tab', { name: /^Activity/ })).toBeInTheDocument();
expect(await within(right).findByRole('region', { name: 'Task' })).toBeInTheDocument();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ function makeMetadata() {

function tree(dataSource: any) {
return (
<MemoryRouter initialEntries={[`/app/demo/${OBJECT_NAME}/${RECORD_ID}?tab=timeline`]}>
// objectstack#35595 — the whole stream, composer included, is the 动态 tab's face; the 概览 rail shows a read-only peek.
<MemoryRouter initialEntries={[`/app/demo/${OBJECT_NAME}/${RECORD_ID}?related=timeline`]}>
<MetadataCtx.Provider value={makeMetadata()}>
<RecordDetailView
dataSource={dataSource}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ function makeMetadata() {
/** Render the console record page over the seeded `sys_activity` rows. */
const renderWith = (rows: Array<Record<string, any>>) =>
render(
<MemoryRouter initialEntries={[`/app/demo/${OBJECT_NAME}/${RECORD_ID}?tab=timeline`]}>
// objectstack#35595 — the whole stream, composer included, is the 动态 tab's face; the 概览 rail shows a read-only peek.
<MemoryRouter initialEntries={[`/app/demo/${OBJECT_NAME}/${RECORD_ID}?related=timeline`]}>
<MetadataCtx.Provider value={makeMetadata()}>
<RecordDetailView
dataSource={makeDataSource(rows)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,18 @@ describe('record header — the approval is the ONE button group (objectstack#35
expect(tag.tagName).toBe('BUTTON');
});

it('the tag opens the 审批 tab, where the approvals panel is drawn (objectstack#35595)', async () => {
stubApprovalsApi(pendingRequest({ can_act: true, is_submitter: false, can_override: false }));
const { container } = renderRecordPage();
const tag = await screen.findByTestId('record-approval-tag');
// CONTROL: 概览 draws no approvals panel and no tab face.
expect(container.querySelector('[data-testid="record-approvals-panel"]')).toBeNull();
expect(container.querySelector('[data-related-enlarged]')).toBeNull();
fireEvent.click(tag);
await waitFor(() => expect(container.querySelector('[data-related-enlarged="approvals"]')).not.toBeNull());
expect(container.querySelector('[role="tab"][data-record-tab="approvals"]')?.getAttribute('aria-selected')).toBe('true');
});

it('a reject from the record page requires its reason', async () => {
stubApprovalsApi(pendingRequest({ can_act: true, is_submitter: false, can_override: false }));
renderRecordPage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

import * as React from 'react';
import { describe, it, expect, vi, beforeAll, beforeEach, afterEach } from 'vitest';
import { render, screen, waitFor, cleanup, act, within } from '@testing-library/react';
import { render, screen, waitFor, cleanup, act, within, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
import { MetadataCtx, notifyDataChanged, useMutationInvalidationBridge } from '@object-ui/react';
Expand Down Expand Up @@ -259,10 +259,19 @@ async function settledPage(objects: readonly unknown[] = OBJECTS) {
renderPage(backend.ds, objects);
await waitFor(() => expect(parentReads(backend.ds)).toBe(1));
await screen.findByText('Seat licence');
await waitFor(() => expect(figureShown(backend.rollup())).toBe(true));
// objectstack#35595 — the key fields (the rollup among them) are the 概览
// tab's: the list's tab, open here, draws none.
expect(figureShown(backend.rollup())).toBe(false);
return backend;
}

/** Back to 概览, where the highlight strip draws the parent's rollup. */
async function toOverview() {
await act(async () => {
fireEvent.click(document.querySelector('[role="tab"][data-record-tab="overview"]') as HTMLElement);
});
}

beforeEach(() => {
cleanup();
RelatedCountStore._reset();
Expand Down Expand Up @@ -305,11 +314,14 @@ describe('RecordDetailView — a child write in a related list refreshes the par
await waitFor(() => expect(ds.delete).toHaveBeenCalledWith(CHILD, 'l-1'));
expect(rollup()).toBe(3000);
await waitFor(() => expect(parentReads(ds)).toBe(2));
await waitFor(() => expect(figureShown(3000)).toBe(true));
expect(figureShown(9000)).toBe(false);
// In place: the same header node, the list's face still the open one.
expect(document.querySelector(HEADER)).toBe(headerBefore);
expect(document.querySelector(`[data-related-enlarged="${CHILD}.${PARENT}"]`)).not.toBeNull();
// 概览 draws the re-read row: the recomputed total, with no read of its own.
await toOverview();
await waitFor(() => expect(figureShown(3000)).toBe(true));
expect(figureShown(9000)).toBe(false);
expect(parentReads(ds)).toBe(2);
});

it('a child update through the dataSource (the form overlay\'s save) re-reads the parent', async () => {
Expand All @@ -322,8 +334,9 @@ describe('RecordDetailView — a child write in a related list refreshes the par

expect(rollup()).toBe(12000);
await waitFor(() => expect(parentReads(ds)).toBe(2));
await waitFor(() => expect(figureShown(12000)).toBe(true));
expect(document.querySelector(HEADER)).toBe(headerBefore);
await toOverview();
await waitFor(() => expect(figureShown(12000)).toBe(true));
});

it('a child row action that bypasses the dataSource (an object-wide child change) re-reads the parent', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* ObjectUI
* Copyright (c) 2024-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* objectstack#35595 — a record page drawn as written (an authored page, or a
* synthesized one whose strip cannot be laid out) that does not place the
* record's approval or attachments panel gets them as tabs of its first
* `page:tabs` strip — 「附件」 then 「审批」, after its own tabs — and no longer
* at the page's foot. A page with no strip keeps the foot: there is nowhere
* else to put them. The page comes back by reference when nothing is added,
* so a page with nothing to add re-renders nothing.
*/

import { describe, it, expect } from 'vitest';
import { withFallbackRecordTabs } from './RecordDetailView';

const APPROVALS = { approvals: { available: true, requests: [{ id: 'r1' }], pendingRequest: { id: 'r1' } }, currentUserId: 'u1' };
const details = { type: 'record:details', properties: {} };

const authored = (tabs: Record<string, unknown>) => ({
type: 'record',
regions: [{ name: 'main', components: [{ type: 'page:header' }, tabs, { type: 'page:tabs', properties: { items: [{ label: 'Second', value: 'second', children: [] }] } }] }],
});
const firstTabs = (page: any) => page.regions[0].components[1];
const values = (tabs: any) => (tabs.properties?.items ?? tabs.items).map((item: any) => item.value);

describe('withFallbackRecordTabs (objectstack#35595)', () => {
it('appends 附件 then 审批 to the FIRST strip, after its own tabs; the second strip is untouched', () => {
const page = authored({ type: 'page:tabs', properties: { items: [{ label: 'Details', value: 'details', children: [details] }] } });
const out = withFallbackRecordTabs(page, { approvals: APPROVALS, attachments: true });
expect(out.approvals).toBe(true);
expect(out.attachments).toBe(true);
expect(values(firstTabs(out.page))).toEqual(['details', 'attachments', 'approvals']);
const items = firstTabs(out.page).properties.items;
expect(items[1].children).toEqual([{ type: 'record:attachments', properties: {} }]);
expect(items[2].children).toEqual([{ type: 'record:approvals', properties: APPROVALS }]);
expect(values(out.page.regions[0].components[2])).toEqual(['second']);
// The input is not mutated.
expect(values(firstTabs(page))).toEqual(['details']);
});

it('reads the strip\'s items in either spelling (`properties.items` or `items`)', () => {
const page = authored({ type: 'page:tabs', items: [{ label: 'Details', value: 'details', children: [details] }] });
const out = withFallbackRecordTabs(page, { approvals: null, attachments: true });
expect(values(firstTabs(out.page))).toEqual(['details', 'attachments']);
expect(out).toMatchObject({ approvals: false, attachments: true });
});

it('finds a strip nested in a component\'s children', () => {
const page = {
type: 'record',
regions: [{ name: 'main', components: [{ type: 'page:card', children: [{ type: 'page:tabs', properties: { items: [{ label: 'A', value: 'a', children: [] }] } }] }] }],
};
const out = withFallbackRecordTabs(page, { approvals: APPROVALS, attachments: false });
expect(values(out.page.regions[0].components[0].children[0])).toEqual(['a', 'approvals']);
expect(out).toMatchObject({ approvals: true, attachments: false });
});

it('a page with no strip keeps the foot: nothing is added and the page comes back by reference', () => {
const page = { type: 'record', regions: [{ name: 'main', components: [details] }] };
const out = withFallbackRecordTabs(page, { approvals: APPROVALS, attachments: true });
expect(out.page).toBe(page);
expect(out).toMatchObject({ approvals: false, attachments: false });
});

it('CONTROL: nothing to add returns the page by reference', () => {
const page = authored({ type: 'page:tabs', properties: { items: [{ label: 'Details', value: 'details', children: [details] }] } });
const out = withFallbackRecordTabs(page, { approvals: null, attachments: false });
expect(out.page).toBe(page);
expect(out).toMatchObject({ approvals: false, attachments: false });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ beforeEach(() => {
});
afterEach(() => { cleanup(); vi.unstubAllGlobals(); });

async function boot(answers: Answers = {}) {
async function boot(answers: Answers = {}, search = '') {
const { fetch, held } = heldTransport(answers);
vi.stubGlobal('fetch', fetch);
const ds = new ObjectStackAdapter({ baseUrl: BASE, fetch, autoReconnect: false });
Expand All @@ -209,7 +209,7 @@ async function boot(answers: Answers = {}) {
} as never;
const page = (id: string) => (
<React.StrictMode>
<MemoryRouter initialEntries={[`/apps/demo/${OBJECT}/record/c1`]}>
<MemoryRouter initialEntries={[`/apps/demo/${OBJECT}/record/c1${search}`]}>
<MetadataCtx.Provider value={metadata}>
<RecordDetailView dataSource={ds as never} objects={ALL as never} onEdit={() => {}} objectNameOverride={OBJECT} recordIdOverride={id} />
</MetadataCtx.Provider>
Expand All @@ -230,15 +230,22 @@ const NO_COMMENTS = { comments: [], reactions: { records: [] } };
const NO_ACTIVITY = { total: 0, records: [] };

const peekOf = (c: HTMLElement) => c.querySelector('[data-record-timeline-peek]') as HTMLElement;
/**
* objectstack#35595 / #35596 — the stream's whole face is the 动态 tab
* (`?related=timeline`). An empty stream draws no card on the 概览 rail, so
* its empty state is read there.
*/
const ON_TIMELINE = '?related=timeline';
const faceOf = (c: HTMLElement) => c.querySelector('[data-related-enlarged="timeline"]') as HTMLElement;
const failedSources = (c: HTMLElement) =>
Array.from(c.querySelectorAll('[data-failed-source]')).map((e) => e.getAttribute('data-failed-source'));
const retryButton = (c: HTMLElement) => c.querySelector('[data-feed-retry]') as HTMLButtonElement | null;
/** The 动态 tab's label, badge included. */
const timelineTab = (c: HTMLElement) =>
Array.from(c.querySelectorAll('[role="tab"]')).find((t) => /^Activity/.test(t.textContent ?? ''))?.textContent;
/** Open the record over an adapter that reads every stream on its own. */
async function bootDirect(answers: Answers) {
const booted = await boot(answers);
async function bootDirect(answers: Answers, search = '') {
const booted = await boot(answers, search);
Object.assign(booted.ds, { getRecordPage: undefined, prefetchRecordPage: undefined });
return booted;
}
Expand Down Expand Up @@ -336,11 +343,11 @@ describe('objectstack#29188 — controls', () => {
});

it('an empty 200 on direct reads still shows the empty state, with no notice', async () => {
const { held, open } = await bootDirect({});
const { held, open } = await bootDirect({}, ON_TIMELINE);
const view = open();
await settle(held);
expect(peekOf(view.container).textContent).toContain(EMPTY_ACTIVITY);
expect(failedSources(peekOf(view.container))).toEqual([]);
expect(faceOf(view.container).textContent).toContain(EMPTY_ACTIVITY);
expect(failedSources(faceOf(view.container))).toEqual([]);
});

it('a refused (403) discussion part keeps the no-permission state and offers no Retry', async () => {
Expand All @@ -359,7 +366,8 @@ describe('objectstack#29188 — controls', () => {

describe('objectstack#29188 — attachments (pin: main already shows the failure)', () => {
it('a 500 attachments part shows the panel\'s load-failure state with a Retry, and no count', async () => {
const { held, open } = await boot({ attachments: FAIL });
// objectstack#35595 — the panel is the 附件 tab's face.
const { held, open } = await boot({ attachments: FAIL }, '?related=attachments');
const view = open();
await settle(held);
expect(view.container.querySelector('[data-testid="record-attachments-unavailable"]')).not.toBeNull();
Expand Down Expand Up @@ -437,7 +445,7 @@ describe('objectstack#30145 — navigating away from a failed feed read does not
});

it('direct reads: A\'s sys_comment 500 settles after navigating to B, which stays clean', async () => {
const { held, open, navigate } = await bootDirect({ failGet: ['sys_comment@c1'] });
const { held, open, navigate } = await bootDirect({ failGet: ['sys_comment@c1'] }, ON_TIMELINE);
const view = open();
await idle();
const aComment = readsOf(held, 'sys_comment').filter((h) => !h.released);
Expand All @@ -450,11 +458,11 @@ describe('objectstack#30145 — navigating away from a failed feed read does not
if (pending.length === 0) break;
await release(pending);
}
expect(failedSources(peekOf(view.container))).toEqual([]);
expect(failedSources(faceOf(view.container))).toEqual([]);

await release(aComment);
await settle(held);
const peek = peekOf(view.container);
const peek = faceOf(view.container);
expect(failedSources(peek)).toEqual([]);
expect(retryButton(peek)).toBeNull();
expect(peek.textContent).toContain(EMPTY_ACTIVITY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ function makeMetadata(pages: any[]) {

function renderDetail(dataSource: any, pages: any[] = []) {
return render(
<MemoryRouter initialEntries={[`/app/demo/${OBJECT_NAME}/${RECORD_ID}?tab=timeline`]}>
// objectstack#35595 — the whole stream, composer included, is the 动态 tab's face; the 概览 rail shows a read-only peek.
<MemoryRouter initialEntries={[`/app/demo/${OBJECT_NAME}/${RECORD_ID}?related=timeline`]}>
<MetadataCtx.Provider value={makeMetadata(pages)}>
<RecordDetailView
dataSource={dataSource}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ function makeMetadata(pages: any[]) {
*/
function tree(dataSource: any, recordId: string, pages: any[] = []) {
return (
<MemoryRouter initialEntries={[`/app/demo/${OBJECT_NAME}/${recordId}?tab=timeline`]}>
// objectstack#35595 — the whole stream, composer included, is the 动态 tab's face; the 概览 rail shows a read-only peek.
<MemoryRouter initialEntries={[`/app/demo/${OBJECT_NAME}/${recordId}?related=timeline`]}>
<MetadataCtx.Provider value={makeMetadata(pages)}>
<RecordDetailView
dataSource={dataSource}
Expand Down
Loading
Loading