Skip to content

Commit 139b657

Browse files
committed
fix(app-shell): permission-set editor header shows the served (translated) label
Claude-Session: https://claude.ai/code/session_01JQwxbZMgz2QbrsLJv3RD41 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b8f596c commit 139b657

3 files changed

Lines changed: 176 additions & 4 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): the permission-set editor's header names the set by its translated label
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Setup → Permission Sets lists a set by the label the server serves for the viewer's locale (销售代表 under zh-CN), but opening it showed the authored label in the header ("Sales Representative"). The editor builds its draft from the layered read, which carries the authored text; the published list it already reads is the localized one. The header, on the Setup page and in the Studio Access pillar, now shows the served label while the draft's label is the published one. It is display only: a save sends the authored label unchanged, a set that was never published keeps its draft label, and an edit to the label shows the edit.
11+
12+
What to do: nothing.
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#26884 — the permission-set header names the set by the label
5+
* the published list serves. `GET /meta/permission` is localized at the REST
6+
* boundary (the server's permission-set translator), so under zh-CN Setup →
7+
* 权限集 lists the set as 销售代表; the layered read the editor's draft is
8+
* built from carries the authored text, and the header used to print that —
9+
* "Sales Representative" on a zh-CN page.
10+
*
11+
* The served label is display only: a save sends the authored label back
12+
* unchanged, a set the list does not hold keeps its draft label, and an edit
13+
* to the label shows the edit.
14+
*/
15+
16+
import { describe, it, expect, vi, afterEach } from 'vitest';
17+
import { render, screen, cleanup, fireEvent, waitFor, within } from '@testing-library/react';
18+
import { MemoryRouter } from 'react-router-dom';
19+
20+
interface Server {
21+
set: Record<string, unknown>;
22+
served: Array<Record<string, unknown>>;
23+
saved: Array<Record<string, unknown>>;
24+
}
25+
26+
function freshServer(served: Array<Record<string, unknown>>): Server {
27+
return {
28+
saved: [],
29+
served,
30+
set: {
31+
name: 'sales_rep',
32+
label: 'Sales Representative',
33+
objects: { a_account: { allowRead: true, allowCreate: true } },
34+
fields: {},
35+
},
36+
};
37+
}
38+
39+
function makeClient(server: Server) {
40+
return {
41+
layered: async () => ({ effective: server.set, code: null, overlay: null, overlayScope: null }),
42+
getDraft: async () => null,
43+
list: async (type: string) => {
44+
if (type === 'object') return [{ item: { name: 'a_account' } }];
45+
if (type === 'permission') return server.served;
46+
return [];
47+
},
48+
get: async (type: string) => (type === 'object' ? { fields: [{ name: 'name', label: 'Name' }] } : null),
49+
save: async (_t: string, _n: string, payload: Record<string, unknown>) => {
50+
server.saved.push(payload);
51+
server.set = payload;
52+
return payload;
53+
},
54+
} as any;
55+
}
56+
57+
let clientImpl: any;
58+
59+
vi.mock('./useMetadata', () => ({
60+
useMetadataClient: () => clientImpl,
61+
useMetadataTypes: () => ({
62+
loading: false,
63+
error: null,
64+
entries: [{ type: 'permission', label: 'Permission', allowEnvironmentOverlay: true }],
65+
}),
66+
}));
67+
68+
let localeFixture: 'zh-CN' | 'ja-JP' = 'zh-CN';
69+
vi.mock('./i18n', async (importOriginal) => ({
70+
...(await importOriginal<Record<string, unknown>>()),
71+
useMetadataLocale: () => localeFixture,
72+
}));
73+
74+
vi.mock('./AssignedUsersSection', () => ({ AssignedUsersSection: () => null }));
75+
76+
import { PermissionMatrixEditPage } from './PermissionMatrixEditor';
77+
78+
// The editor's `perm.*` rows live in `@object-ui/i18n`'s `studio` namespace,
79+
// whose `zh` catalogue is fetched on demand (objectstack#25922). Resident
80+
// before any case, so the zh chrome reads synchronously.
81+
import { loadStudioCatalogue } from '@object-ui/i18n/namespaces/studio';
82+
await loadStudioCatalogue('zh');
83+
84+
afterEach(() => {
85+
cleanup();
86+
localeFixture = 'zh-CN';
87+
});
88+
89+
function renderSet() {
90+
return render(
91+
<MemoryRouter>
92+
<PermissionMatrixEditPage type="permission" name="sales_rep" packageId="app.a" />
93+
</MemoryRouter>,
94+
);
95+
}
96+
97+
describe('PermissionMatrixEditPage — header shows the served label (objectstack#26884)', () => {
98+
it('zh-CN: the header reads the served 销售代表, and a save keeps the authored label', async () => {
99+
const server = freshServer([{ name: 'sales_rep', label: '销售代表' }]);
100+
clientImpl = makeClient(server);
101+
renderSet();
102+
103+
expect(await screen.findByText('销售代表')).toBeInTheDocument();
104+
expect(screen.queryByText('Sales Representative')).toBeNull();
105+
106+
// Any matrix edit → the autosave sends the draft (objectui#11787).
107+
const row = screen.getByText('a_account').closest('tr')!;
108+
fireEvent.click(within(row).getByRole('button', { name: /None|无/ }));
109+
await waitFor(() => expect(server.saved).toHaveLength(1), { timeout: 4000 });
110+
expect(server.saved[0].label).toBe('Sales Representative');
111+
// The header still names the set by the served label after the save.
112+
expect(screen.getByText('销售代表')).toBeInTheDocument();
113+
});
114+
115+
it('ja-JP: the header reads the label the served row carries', async () => {
116+
localeFixture = 'ja-JP';
117+
clientImpl = makeClient(freshServer([{ name: 'sales_rep', label: '営業担当' }]));
118+
renderSet();
119+
120+
expect(await screen.findByText('営業担当')).toBeInTheDocument();
121+
expect(screen.queryByText('Sales Representative')).toBeNull();
122+
});
123+
124+
it('a set the published list does not hold keeps its draft label', async () => {
125+
clientImpl = makeClient(freshServer([{ name: 'other_set', label: '其他' }]));
126+
renderSet();
127+
128+
expect(await screen.findByText('Sales Representative')).toBeInTheDocument();
129+
});
130+
131+
it('an edit to the label shows the edit, not the served label', async () => {
132+
clientImpl = makeClient(freshServer([{ name: 'sales_rep', label: '销售代表' }]));
133+
renderSet();
134+
135+
fireEvent.click(await screen.findByRole('button', { name: /销售代表/ }));
136+
fireEvent.change(screen.getByDisplayValue('Sales Representative'), { target: { value: 'Field Sales' } });
137+
expect(screen.getByText('Field Sales')).toBeInTheDocument();
138+
expect(screen.queryByText('销售代表')).toBeNull();
139+
});
140+
});

‎ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,13 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
732732
forget: forgetSetVersion,
733733
dialog: draftConflictDialog,
734734
} = useDraftSaveGuard(client, reloadSet);
735+
// The header's label as the published list serves it: that read is
736+
// localized at the REST boundary (the server's permission-set translator),
737+
// while the layered read the draft is built from carries the authored text.
738+
// Display only — never written into `draft`, so a save keeps the authored
739+
// label. `authored` is the published label it stands for; once the draft's
740+
// label differs (an edit, a pending draft) the header shows the draft's.
741+
const [servedLabel, setServedLabel] = React.useState<{ authored?: string; served: string } | null>(null);
735742
const [objects, setObjects] = React.useState<ObjectSummary[]>([]);
736743
const [fieldsByObject, setFieldsByObject] = React.useState<Record<string, FieldSummary[]>>({});
737744
const [expanded, setExpanded] = React.useState<Set<string>>(new Set());
@@ -780,10 +787,10 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
780787
// objectui#11799 — the same published read, held for the load below: a set
781788
// it does not list has never been published. The load runs after this
782789
// effect, so it reads this request rather than sending one of its own.
783-
const publishedSetsRef = React.useRef<Promise<Array<{ name?: string }>> | null>(null);
790+
const publishedSetsRef = React.useRef<Promise<Array<{ name?: string; label?: unknown }>> | null>(null);
784791
React.useEffect(() => {
785792
let cancelled = false;
786-
const published = client.list<{ name?: string }>('permission', {});
793+
const published = client.list<{ name?: string; label?: unknown }>('permission', {});
787794
publishedSetsRef.current = published;
788795
published
789796
.then((rows) => {
@@ -816,6 +823,7 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
816823
// that copy is the set being opened (the routed hop to it).
817824
setSaveRefusedAsLocked(null);
818825
setCloned((c) => (c && c.name === name ? c : null));
826+
setServedLabel(null);
819827
(async () => {
820828
try {
821829
// ADR-0086 P2 (D6): under the package door a set is draft/published
@@ -917,6 +925,15 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
917925
// live write is not pinned.
918926
if (pendingRead && packageId) recordSetRead(type, name, packageId, pendingRead.pin);
919927
else forgetSetVersion();
928+
// A draft-only set has no served row and keeps its draft label.
929+
const servedRow = publishedSets
930+
? (await publishedSets.catch(() => null))?.find((r) => r?.name === name)
931+
: undefined;
932+
if (cancelled) return;
933+
const authoredLabel = (lay?.effective ?? lay?.code)?.label;
934+
if (typeof servedRow?.label === 'string' && servedRow.label && servedRow.label !== authoredLabel) {
935+
setServedLabel({ authored: authoredLabel, served: servedRow.label });
936+
}
920937
} catch (err: any) {
921938
setError(err?.message ?? String(err));
922939
} finally {
@@ -1017,6 +1034,9 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
10171034
).length;
10181035
const saveHeld = celErrorTotal > 0 || rlsUnnamedCount > 0;
10191036

1037+
const headerLabel =
1038+
servedLabel && draft.label === servedLabel.authored ? servedLabel.served : draft.label;
1039+
10201040
// Dirty detection — cheap JSON snapshot comparison against the last
10211041
// loaded/saved baseline (same approach as ResourceEditPage). Every mutation
10221042
// funnels through setDraft (matrix checkboxes, header inputs, capabilities,
@@ -1929,7 +1949,7 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
19291949
testId="access-item-header"
19301950
leading={chrome.leading}
19311951
icon={Shield}
1932-
title={draft.label || name}
1952+
title={headerLabel || name}
19331953
apiName={name}
19341954
chips={
19351955
<>
@@ -2168,7 +2188,7 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
21682188
)}
21692189
{/* The api-name already sits in the PageShell breadcrumb (font-mono),
21702190
so the summary carries the human label — no need to repeat it. */}
2171-
<span className="font-medium truncate">{draft.label || draft.name}</span>
2191+
<span className="font-medium truncate">{headerLabel || draft.name}</span>
21722192
{provenanceBadgesEl}
21732193
{writable && (
21742194
<span className="text-xs text-muted-foreground shrink-0">{t('perm.basics.editHint')}</span>

0 commit comments

Comments
 (0)