Skip to content

Commit 464325f

Browse files
committed
fix(ui): Setup metadata lists lead with the label and clamp descriptions
Claude-Session: https://claude.ai/code/session_01L9qibwpXbWKjEuA5DF45BL Co-authored-by: Claude <noreply@anthropic.com>
1 parent a248e7f commit 464325f

3 files changed

Lines changed: 168 additions & 1 deletion

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(setup): metadata lists under Setup take their title from the sidebar, lead with the label, and keep rows short
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A metadata list under Setup (Positions, Permission Sets and the other catalog pages) titled itself with the type's singular label ("Position"), led each row with the API name, and let a long description wrap a row to several lines on a phone. Under Setup the page now takes its title from the app's own navigation entry that opens it, so it reads as the sidebar row that opened it ("Positions", in the served language), and falls back to the type's label when no entry opens exactly that page. Each row leads with the item's label, with its API name beneath it in small monospace type, in place of a separate Label column; an item with no label keeps its API name as the link. A description shows two lines at most, with the whole text on hover. The same page outside Setup is unchanged.
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/**
2+
* objectstack#27356 (row 5) — a metadata list under Setup reads as an admin
3+
* list: the header names the page as the app's navigation entry that opens it
4+
* does ("Positions", not the type's singular "Position"), each row leads with
5+
* the item's label with the API name beneath it, and a description takes two
6+
* lines at most, so a row stays one row on a phone.
7+
*
8+
* The same page outside Setup is the control: the API name column, the Label
9+
* column and the type's label as the title, as before.
10+
*/
11+
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
12+
import { render, cleanup, screen, within } from '@testing-library/react';
13+
import '@testing-library/jest-dom';
14+
import * as React from 'react';
15+
import { MemoryRouter, Routes, Route } from 'react-router-dom';
16+
// The activation column waits on `audienceAnchorsOf`'s dynamic import of this
17+
// exact specifier; loaded here so its cost lands in the import phase.
18+
import '@objectstack/spec/identity';
19+
20+
const TYPE = 'position';
21+
const LONG = 'Leads the sales organization and gives the final sign-off on the largest deals of the quarter.';
22+
const ITEMS: Record<string, unknown>[] = [
23+
{ name: 'sales_director', label: 'Sales Director', description: LONG, _packageId: 'com.example.crm' },
24+
{ name: 'unlabelled', _packageId: 'com.example.crm' },
25+
];
26+
27+
/** Stable singleton — the page's load effect keys on the client identity. */
28+
const CLIENT = {
29+
list: async (type: string) => (type === TYPE ? ITEMS : []),
30+
};
31+
32+
const ENTRY = { type: TYPE, label: 'Position', domain: 'security', allowEnvironmentOverlay: false, allowRuntimeCreate: true };
33+
34+
/** The served Setup app: its Access Control group names the list "Positions". */
35+
let APP: unknown = null;
36+
37+
vi.mock('./useMetadata', async (importOriginal) => ({
38+
...(await importOriginal<Record<string, unknown>>()),
39+
useMetadataClient: () => CLIENT,
40+
useMetadataTypes: () => ({ loading: false, error: null, entries: [ENTRY] }),
41+
}));
42+
43+
vi.mock('./i18n', async (importOriginal) => ({
44+
...(await importOriginal<Record<string, unknown>>()),
45+
useMetadataLocale: () => 'en-US',
46+
}));
47+
48+
vi.mock('../../hooks/useCanAuthorMetadata', () => ({
49+
useCanAuthorMetadata: () => true,
50+
}));
51+
52+
vi.mock('../../hooks/useTenancyPosture', async (importOriginal) => ({
53+
...(await importOriginal<Record<string, unknown>>()),
54+
useTenancyPosture: () => 'single',
55+
}));
56+
57+
vi.mock('../../providers/ExpressionProvider', async (importOriginal) => {
58+
const actual = await importOriginal<Record<string, any>>();
59+
return { ...actual, useExpressionContext: () => ({ ...actual.useExpressionContext(), app: APP }) };
60+
});
61+
62+
// Imported AFTER the mocks so the page picks them up.
63+
import { MetadataResourceListPage } from './ResourceListPage';
64+
65+
beforeEach(() => {
66+
APP = {
67+
name: 'setup',
68+
navigation: [
69+
{
70+
id: 'grp_access',
71+
type: 'group',
72+
label: 'Access Control',
73+
children: [
74+
{ id: 'nav_positions', type: 'url', label: 'Positions', url: '/apps/setup/metadata/position?scope=environment' },
75+
{ id: 'nav_permission_sets', type: 'url', label: 'Permission Sets', url: '/apps/setup/metadata/permission?scope=environment' },
76+
],
77+
},
78+
],
79+
};
80+
vi.stubGlobal(
81+
'fetch',
82+
vi.fn(async () =>
83+
new Response(JSON.stringify({ records: [], hasMore: false }), {
84+
status: 200,
85+
headers: { 'Content-Type': 'application/json' },
86+
}),
87+
),
88+
);
89+
});
90+
afterEach(() => {
91+
cleanup();
92+
vi.unstubAllGlobals();
93+
});
94+
95+
function mount(appName: string) {
96+
return render(
97+
<MemoryRouter initialEntries={[`/apps/${appName}/metadata/${TYPE}?scope=environment`]}>
98+
<Routes>
99+
<Route path="/apps/:appName/metadata/:type" element={<MetadataResourceListPage />} />
100+
</Routes>
101+
</MemoryRouter>,
102+
);
103+
}
104+
105+
const headers = () => Array.from(document.querySelectorAll('thead th')).map((th) => th.textContent);
106+
107+
describe('a metadata list under Setup leads with labels (objectstack#27356 row 5)', () => {
108+
it('titles the page as the navigation entry that opens it', async () => {
109+
mount('setup');
110+
await screen.findByRole('link', { name: 'Sales Director' });
111+
const header = screen.getByTestId('metadata-list-setup-header');
112+
expect(within(header).getByRole('heading', { level: 1 }).textContent).toBe('Positions');
113+
});
114+
115+
it('falls back to the type label when no entry opens exactly this page', async () => {
116+
APP = { name: 'setup', navigation: [{ id: 'nav_users', type: 'url', label: 'Users', url: '/apps/setup/sys_user' }] };
117+
mount('setup');
118+
await screen.findByRole('link', { name: 'Sales Director' });
119+
const header = screen.getByTestId('metadata-list-setup-header');
120+
expect(within(header).getByRole('heading', { level: 1 }).textContent).toBe('Position');
121+
});
122+
123+
it('leads each row with the label, the API name beneath it, and no separate Label column', async () => {
124+
mount('setup');
125+
const link = await screen.findByRole('link', { name: 'Sales Director' });
126+
const row = screen.getByTestId('metadata-row-sales_director');
127+
expect(within(row).getByTestId('metadata-row-api-name').textContent).toBe('sales_director');
128+
expect(link).not.toHaveClass('font-mono');
129+
expect(headers()[0]).toBe('Label');
130+
expect(headers().filter((h) => h === 'Label')).toHaveLength(1);
131+
expect(headers()).not.toContain('Name');
132+
133+
// An item with no label keeps its API name as the link.
134+
const bare = screen.getByTestId('metadata-row-unlabelled');
135+
expect(within(bare).getByRole('link', { name: 'unlabelled' })).toHaveClass('font-mono');
136+
expect(within(bare).queryByTestId('metadata-row-api-name')).toBeNull();
137+
});
138+
139+
it('clamps a description to two lines and keeps the whole text on hover', async () => {
140+
mount('setup');
141+
await screen.findByRole('link', { name: 'Sales Director' });
142+
const row = screen.getByTestId('metadata-row-sales_director');
143+
const clamp = within(row).getByText(LONG);
144+
expect(clamp).toHaveClass('line-clamp-2');
145+
expect(clamp).toHaveAttribute('title', LONG);
146+
});
147+
148+
it('CONTROL — outside Setup the page keeps the API name column, the Label column and the type title', async () => {
149+
mount('studio');
150+
const link = await screen.findByRole('link', { name: 'sales_director' });
151+
expect(link).toHaveClass('font-mono');
152+
expect(headers().slice(0, 2)).toEqual(['Name', 'Label']);
153+
expect(screen.queryAllByTestId('metadata-row-api-name')).toHaveLength(0);
154+
expect(screen.getByText(LONG)).not.toHaveClass('line-clamp-2');
155+
});
156+
});

‎ui/packages/app-shell/src/views/metadata-admin/ResourceListPage.setupPosture-12606.test.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ const FILTERED_TILE = t('engine.list.filtered', 'en-US');
9393
describe('the metadata-type page under the Setup route (objectui#12606)', () => {
9494
it('renders no breadcrumb and no stat tiles, and says the count in the header’s description', async () => {
9595
const { container } = mount('setup');
96-
await screen.findByRole('link', { name: 'everyone' });
96+
// Under Setup a row's link is its label (objectstack#27356).
97+
await screen.findByRole('link', { name: 'Everyone' });
9798

9899
const header = screen.getByTestId('metadata-list-setup-header');
99100
expect(header.getAttribute('data-posture')).toBe('setup');

0 commit comments

Comments
 (0)