Skip to content

Commit 5061397

Browse files
committed
fix(app-shell): Studio Access pillar polish — plain-words draft race refusal, OWD banner clears on revert, live rail label, field table count and sticky name column
Claude-Session: https://claude.ai/code/session_01JQwxbYZa5ViBSW4Et4fr91 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 07d18e6 commit 5061397

10 files changed

Lines changed: 341 additions & 8 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/i18n': patch
3+
'@object-ui/app-shell': patch
4+
---
5+
6+
fix(app-shell): four small fixes to the Studio Access pillar
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
- **A create that loses the race to a draft says so in plain words.** When a draft permission set with the same identifier appears between Studio's check and its save, the server refuses the save. Studio used to show the server's sentence about the "first-write pin" and `If-None-Match`. It now reads the refusal by its code and says that a draft with that identifier already exists. New key `engine.studio.access.createDraftTaken` in `@object-ui/i18n` (en, zh).
12+
- **The sharing-baseline (OWD) overview drops a refusal once its edits are undone.** After a refused save, putting every row back to its loaded value ("No changes") now removes the refusal. An edit that is still unsaved keeps it.
13+
- **The Access list follows a label change at once.** A draft save of the open permission set re-reads the list, so a renamed set shows its new label without a publish or a reload.
14+
- **The field table under an expanded object stays readable when the matrix scrolls sideways.** The "shown / total" count sits beside the field filter instead of at the far end of the row, and the field-name column stays pinned to the left edge.
15+
16+
What to do: nothing. Nothing a permission set or object declares changes.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#26846 — the field sub-table under an expanded object stays
5+
* readable when the matrix scrolls sideways (its floor is wider than the
6+
* Studio content column at 1440 px):
7+
*
8+
* - the "visible / total" count sits beside the filter it counts, not at the
9+
* far end of the row, where it fell past the visible edge;
10+
* - the field-name column, header and rows, is pinned to the left edge of the
11+
* scroll container over an opaque background.
12+
*
13+
* jsdom lays nothing out, so this pins the structure and the classes the
14+
* browser reads; it is no screenshot.
15+
*/
16+
17+
import '@testing-library/jest-dom/vitest';
18+
import { afterEach, describe, expect, it, vi } from 'vitest';
19+
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
20+
import { MemoryRouter } from 'react-router-dom';
21+
import { t } from './i18n';
22+
23+
// `withPreviewDrafts` answers the client itself, not a promise (objectstack#26840).
24+
type FakeClient = Record<string, (...args: never[]) => unknown>;
25+
26+
let clientImpl: FakeClient;
27+
28+
vi.mock('./useMetadata', () => ({
29+
useMetadataClient: () => clientImpl,
30+
useMetadataTypes: () => ({
31+
loading: false,
32+
error: null,
33+
entries: [{ type: 'permission', label: 'Permission', allowEnvironmentOverlay: true }],
34+
}),
35+
}));
36+
37+
vi.mock('./AssignedUsersSection', () => ({ AssignedUsersSection: () => null }));
38+
39+
import { PermissionMatrixEditPage } from './PermissionMatrixEditor';
40+
41+
afterEach(cleanup);
42+
43+
// Eight fields, so the filter shows (threshold is > 6).
44+
const FIELDS = ['amount', 'email', 'name', 'notes', 'phone', 'region', 'revenue', 'status'];
45+
46+
function makeClient(): FakeClient {
47+
return {
48+
layered: async () => ({
49+
effective: { name: 'project_editor', label: 'Project editor', objects: { a_project: { allowRead: true } }, fields: {} },
50+
code: null,
51+
overlay: null,
52+
overlayScope: null,
53+
}),
54+
getDraft: async () => null,
55+
withPreviewDrafts() { return this; },
56+
list: async (type: string) => (type === 'object' ? [{ item: { name: 'a_project' } }] : []),
57+
get: async (type: string) => (type === 'object' ? { fields: FIELDS.map((name) => ({ name })) } : null),
58+
save: async (_type: string, _name: string, payload: Record<string, unknown>) => payload,
59+
};
60+
}
61+
62+
async function renderExpanded() {
63+
clientImpl = makeClient();
64+
render(
65+
<MemoryRouter>
66+
<PermissionMatrixEditPage type="permission" name="project_editor" packageId="app.a" />
67+
</MemoryRouter>,
68+
);
69+
fireEvent.click(await screen.findByRole('button', { name: /a_project/ }));
70+
await screen.findByLabelText('a_project.notes readable');
71+
}
72+
73+
const PINNED = ['sticky', 'left-0', 'bg-background'];
74+
75+
describe('the field sub-table when the matrix scrolls sideways (objectstack#26846)', () => {
76+
it('the count sits right after the filter, not pushed to the far end of the row', async () => {
77+
await renderExpanded();
78+
const count = screen.getByTestId('perm-field-count-a_project');
79+
expect(count).toHaveTextContent('8 / 8');
80+
expect(count.previousElementSibling).toBe(screen.getByLabelText(t('perm.field.filter', 'en')));
81+
expect(count).not.toHaveClass('ml-auto');
82+
expect(count).toHaveClass('shrink-0', 'whitespace-nowrap');
83+
});
84+
85+
it('the field-name column is pinned left, header and every row', async () => {
86+
await renderExpanded();
87+
const header = screen.getByRole('columnheader', { name: t('perm.field.col.name', 'en') });
88+
expect(header).toHaveClass(...PINNED);
89+
for (const f of FIELDS) {
90+
expect(screen.getByTestId(`perm-field-name-a_project-${f}`)).toHaveClass(...PINNED);
91+
}
92+
// CONTROL: the boxes beside it scroll; only the name column is pinned.
93+
expect(screen.getByLabelText('a_project.notes readable').closest('td')).not.toHaveClass('sticky');
94+
});
95+
});

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,6 +2974,13 @@ function StudioObjectRow({
29742974
);
29752975
}
29762976

2977+
/**
2978+
* objectstack#26846 — the field sub-table's name cell, header and rows alike:
2979+
* pinned to the left edge of the matrix's scroll container, over an opaque
2980+
* background so the boxes scrolling under it do not show through.
2981+
*/
2982+
const FIELD_NAME_CELL = 'sticky left-0 z-[1] bg-background pr-2';
2983+
29772984
/**
29782985
* The inherited look, shared by object and field boxes: grey with a dashed
29792986
* edge, so a box that draws a grant the set inherits never reads as one the
@@ -3131,6 +3138,10 @@ function FieldsSubTable({
31313138
<div className="space-y-2">
31323139
{/* Field toolbar (B4): filter + bulk over the visible field set. The
31333140
filter only appears once one-by-one would actually hurt. */}
3141+
{/* objectstack#26846 — the count sits beside the filter it counts. At
3142+
the far end of the row it sat past the visible edge whenever the
3143+
matrix scrolled sideways (its floor is wider than the Studio
3144+
content column at 1440 px). */}
31343145
<div className="flex flex-wrap items-center gap-2">
31353146
{fields.length > 6 && (
31363147
<Input
@@ -3141,6 +3152,12 @@ function FieldsSubTable({
31413152
className="h-7 w-44 text-xs"
31423153
/>
31433154
)}
3155+
<span
3156+
data-testid={`perm-field-count-${objectName}`}
3157+
className="shrink-0 whitespace-nowrap text-[11px] tabular-nums text-muted-foreground"
3158+
>
3159+
{visible.length} / {fields.length}
3160+
</span>
31443161
{writable && (
31453162
<div className="flex items-center gap-1">
31463163
<Button
@@ -3172,9 +3189,6 @@ function FieldsSubTable({
31723189
</Button>
31733190
</div>
31743191
)}
3175-
<span className="ml-auto text-[11px] text-muted-foreground">
3176-
{visible.length} / {fields.length}
3177-
</span>
31783192
</div>
31793193
{/* objectstack#26597 — what a grey box means, said once per sub-table. */}
31803194
{visible.some((f) => fieldsState[`${objectName}.${f.name}`] === undefined) && (
@@ -3188,7 +3202,9 @@ function FieldsSubTable({
31883202
<table className="w-full text-xs">
31893203
<thead>
31903204
<tr className="text-muted-foreground">
3191-
<th className="text-left py-1 font-medium">{t('perm.field.col.name')}</th>
3205+
{/* objectstack#26846 — the name column stays in view while the
3206+
matrix scrolls sideways (FIELD_NAME_CELL). */}
3207+
<th className={cn('text-left py-1 font-medium', FIELD_NAME_CELL)}>{t('perm.field.col.name')}</th>
31923208
<th className="px-2 py-1 font-medium w-16 text-center" title={t('perm.field.read')}>{t('perm.field.read')}</th>
31933209
<th className="px-2 py-1 font-medium w-16 text-center" title={t('perm.field.edit')}>{t('perm.field.edit')}</th>
31943210
<th className="px-2 py-1 font-medium text-left" title={t('perm.field.when.tip')}>{t('perm.field.when')}</th>
@@ -3204,7 +3220,7 @@ function FieldsSubTable({
32043220
return (
32053221
<React.Fragment key={f.name}>
32063222
<tr className="border-t border-muted">
3207-
<td className="py-1">
3223+
<td className={cn('py-1', FIELD_NAME_CELL)} data-testid={`perm-field-name-${objectName}-${f.name}`}>
32083224
{f.label ?? f.name}
32093225
{f.label && (
32103226
<span className="ml-1 text-muted-foreground">({f.name})</span>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#26846 — a refused OWD save's banner answers the edits it was
5+
* sent. Reverting every row to its loaded value ("No changes") takes it away;
6+
* CONTROL: an edit that is still dirty keeps it.
7+
*/
8+
9+
import '@testing-library/jest-dom/vitest';
10+
import * as React from 'react';
11+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
12+
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
13+
import { t } from '../metadata-admin/i18n';
14+
import { PackageOwdOverviewPanel } from './PackageOwdOverviewPanel';
15+
16+
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
17+
18+
const REFUSAL = 'object/crm_memo: a controlled_by_parent object needs exactly one required master_detail field';
19+
const CBP = t('engine.studio.settings.sharingControlledByParent', 'en-US');
20+
const PRIVATE = t('engine.studio.settings.sharingPrivate', 'en-US');
21+
const PUBLIC_READ = t('engine.studio.settings.sharingPublicRead', 'en-US');
22+
23+
function makeClient() {
24+
const body = { name: 'crm_memo', label: 'Memo', sharingModel: 'private', fields: {} };
25+
return {
26+
list: async (type: string) => (type === 'object' ? [{ name: 'crm_memo', label: 'Memo' }] : []),
27+
listDrafts: async () => [],
28+
layered: async () => ({ effective: body, code: null }),
29+
getDraft: async () => null,
30+
save: vi.fn(async () => {
31+
throw Object.assign(new Error(REFUSAL), { status: 422, code: 'VALIDATION_ERROR' });
32+
}),
33+
} as unknown as React.ComponentProps<typeof PackageOwdOverviewPanel>['client'];
34+
}
35+
36+
async function pick(label: string) {
37+
fireEvent.keyDown(screen.getByTestId('owd-internal-crm_memo'), { key: 'ArrowDown' });
38+
fireEvent.click(within(await screen.findByRole('listbox')).getByRole('option', { name: label }));
39+
}
40+
41+
async function refuseOnce() {
42+
render(<PackageOwdOverviewPanel client={makeClient()} packageId="com.example.crm" locale="en-US" />);
43+
await screen.findByTestId('owd-row-crm_memo');
44+
await pick(CBP);
45+
fireEvent.click(screen.getByTestId('owd-save'));
46+
await screen.findByText(new RegExp(REFUSAL));
47+
}
48+
49+
beforeEach(() => {
50+
Element.prototype.scrollIntoView = vi.fn();
51+
});
52+
afterEach(cleanup);
53+
54+
describe('PackageOwdOverviewPanel — the refusal banner and the revert (objectstack#26846)', () => {
55+
it('reverting the refused edit to the loaded value clears the banner', async () => {
56+
await refuseOnce();
57+
await pick(PRIVATE);
58+
expect(screen.getByTestId('owd-save')).toHaveTextContent(t('engine.studio.owd.saveNone', 'en-US'));
59+
await waitFor(() => expect(screen.queryByText(new RegExp(REFUSAL))).toBeNull());
60+
});
61+
62+
it('CONTROL: an edit that is still dirty keeps the banner', async () => {
63+
await refuseOnce();
64+
await pick(PUBLIC_READ);
65+
expect(screen.getByTestId('owd-dirty-crm_memo')).toBeInTheDocument();
66+
expect(screen.getByText(new RegExp(REFUSAL))).toBeInTheDocument();
67+
});
68+
});

‎ui/packages/app-shell/src/views/studio-design/PackageOwdOverviewPanel.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ export function PackageOwdOverviewPanel({
334334
},
335335
[],
336336
);
337+
// objectstack#26846 — a refusal answers the edits it was sent. Once every
338+
// row is back at its loaded value ("No changes") there is nothing left for
339+
// it to judge, so it goes; an edit that stays dirty keeps it.
340+
React.useEffect(() => {
341+
if (!isDirty) setSaveError(null);
342+
}, [isDirty]);
337343

338344
const doSave = React.useCallback(async () => {
339345
const changed = rowState.filter((s) => s.dirty);

‎ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.accessCreateTaken-26836.test.tsx‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
* - Create over a published id another package holds: refused, nothing
1616
* written, and no "Open".
1717
* - Create over a draft id: refused before the save, and the save still
18-
* carries the first-write pin for a draft that lands after the check.
18+
* carries the first-write pin for a draft that lands after the check;
19+
* that pin's refusal reads in the author's words (objectstack#26846).
1920
* - A fresh id: created as before.
2021
* - Discard: a published set's draft goes and the matrix reads the live
2122
* set again; a never-published set leaves the rail.
@@ -221,10 +222,29 @@ describe('objectstack#26836 — "+ New" over a taken identifier', () => {
221222
const dialog = await openCreate('Project Editor');
222223
await waitFor(() => expect(clientImpl.save).toHaveBeenCalledTimes(1));
223224
expect(clientImpl.save.mock.calls[0][3]).toMatchObject({ mode: 'draft', packageId: PKG, ifNoneMatch: '*' });
224-
expect(await within(dialog).findByText(/asserted that no draft row exists/)).toBeInTheDocument();
225+
// objectstack#26846 — read by its code, in the author's words: the door's
226+
// sentence about the pin never reaches the dialog.
227+
expect(
228+
await within(dialog).findByText(tFormat('engine.studio.access.createDraftTaken', 'en', { name: 'project_editor' })),
229+
).toBeInTheDocument();
230+
expect(within(dialog).queryByText(/asserted that no draft row exists/)).toBeNull();
225231
expect(clientImpl.drafts.project_editor.body.label).toBe('Somebody else');
226232
});
227233

234+
it('CONTROL (objectstack#26846): a refusal with another code keeps its own text', async () => {
235+
clientImpl = makeClient();
236+
renderAccess();
237+
await screen.findByTestId('access-empty', undefined, { timeout: 8000 });
238+
clientImpl.save.mockRejectedValueOnce(
239+
Object.assign(new Error('permission/project_editor: label is too long'), { status: 422, code: 'VALIDATION_ERROR' }),
240+
);
241+
const dialog = await openCreate('Project Editor');
242+
expect(await within(dialog).findByText(/label is too long/)).toBeInTheDocument();
243+
expect(
244+
within(dialog).queryByText(tFormat('engine.studio.access.createDraftTaken', 'en', { name: 'project_editor' })),
245+
).toBeNull();
246+
});
247+
228248
it('a fresh identifier: created as a draft, as before, and opened', async () => {
229249
clientImpl = makeClient({ published: { project_editor: { pkg: PKG, body: EDITOR } } });
230250
renderAccess();

0 commit comments

Comments
 (0)