Skip to content

Commit d09f2b3

Browse files
committed
fix(studio): the object create publishes pinned; a name this package holds offers Open
The list dialog's object create now passes publishCreated (If-None-Match: *), as the flow create does, and a taken identifier the package holds says so and opens that object's designer; one held elsewhere keeps its sentence and no Open. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QSeKYoFqGdRM9Qmg7M2o2B
1 parent 046762e commit d09f2b3

3 files changed

Lines changed: 78 additions & 13 deletions

File tree

‎ui/packages/app-shell/src/views/metadata-admin/MetadataListCreateDialog.pairCreate-36897.test.tsx‎

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ vi.mock('../studio-design/packages-io.js', async (importOriginal) => ({
4747
{ id: 'com.example.bare', namespace: null },
4848
],
4949
}));
50-
const publish = vi.fn(async () => ({ ok: true }));
50+
const publish = vi.fn(async (..._args: unknown[]) => ({ ok: true }));
5151
vi.mock('../studio-design/studioSaveBar.js', async (importOriginal) => ({
5252
...(await importOriginal<Record<string, unknown>>()),
53-
publishSavedItem: (...args: unknown[]) => publish(...(args as [])),
53+
publishSavedItem: (...args: unknown[]) => publish(...args),
5454
}));
5555
const taken = vi.fn(async (..._args: unknown[]): Promise<{ name: string; label: string } | null> => null);
5656
vi.mock('../studio-design/StudioPillarKit.js', async (importOriginal) => ({
@@ -63,8 +63,16 @@ vi.mock('../studio-design/newObjectJoinsAppMenu.js', async (importOriginal) => (
6363
addNewObjectToAppMenu: (...args: unknown[]) => joinMenu(...(args as [])),
6464
}));
6565

66+
/** objectstack#36904 — the package's own objects, read when an identifier is taken. */
67+
const surfaces = vi.fn(async (..._args: unknown[]): Promise<Array<{ type: string; name: string }>> => []);
68+
vi.mock('../studio-design/packageSurfaces.js', async (importOriginal) => ({
69+
...(await importOriginal<Record<string, unknown>>()),
70+
loadPackageSurfaces: (...args: unknown[]) => surfaces(...args),
71+
}));
72+
6673
import { MetadataListCreateDialog } from './MetadataListCreateDialog';
67-
import { t } from './i18n';
74+
import { publishCreated } from '../studio-design/studioSaveBar.js';
75+
import { t, tFormat } from './i18n';
6876

6977
afterEach(() => {
7078
cleanup();
@@ -73,7 +81,7 @@ afterEach(() => {
7381

7482
const L = 'en-US' as const;
7583

76-
function open(type: 'object' | 'flow', packageId: string, inPair: boolean) {
84+
function open(type: 'object' | 'flow', packageId: string, inPair: boolean, onOpenExisting?: (path: string) => void) {
7785
const onCreated = vi.fn();
7886
render(
7987
<MetadataListCreateDialog
@@ -84,6 +92,7 @@ function open(type: 'object' | 'flow', packageId: string, inPair: boolean) {
8492
inPair={inPair}
8593
locale={L}
8694
onCreated={onCreated}
95+
onOpenExisting={onOpenExisting}
8796
/>,
8897
);
8998
return onCreated;
@@ -108,7 +117,7 @@ describe('list 「新建」 lands in the paired .custom package on a read-only b
108117
expect([type, name]).toEqual(['object', 'hrx_leave_request']);
109118
expect(opts).toMatchObject({ mode: 'draft', packageId: 'com.vendor.hr.custom', ifNoneMatch: '*' });
110119
expect(body).toHaveProperty('sharingModel', 'public_read');
111-
expect(publish).toHaveBeenCalledWith(expect.anything(), { type: 'object', name: 'hrx_leave_request', packageId: 'com.vendor.hr.custom' }, false);
120+
expect(publish).toHaveBeenCalledWith(expect.anything(), { type: 'object', name: 'hrx_leave_request', packageId: 'com.vendor.hr.custom' }, false, publishCreated);
112121
expect(onCreated).toHaveBeenCalledWith({ name: 'hrx_leave_request', packageId: 'com.vendor.hr.custom' });
113122
expect(joinMenu).not.toHaveBeenCalled();
114123
});
@@ -181,9 +190,40 @@ describe('list 「新建」 for an object: the create the object designer no lon
181190
const onCreated = open('object', 'com.example.crm', false);
182191
fill('engine.studio.data.nameLabel', 'engine.studio.data.idLabel', 'Visit', 'visit');
183192
await waitFor(() => expect(taken).toHaveBeenCalled());
184-
expect(await screen.findByTestId('object-create-taken')).toHaveTextContent('crm_visit');
193+
const notice = await screen.findByTestId('object-create-taken');
194+
expect(notice).toHaveTextContent('crm_visit');
185195
expect(save).not.toHaveBeenCalled();
186196
expect(publish).not.toHaveBeenCalled();
187197
expect(onCreated).not.toHaveBeenCalled();
198+
// CONTROL (objectstack#36904): held outside this package, it names the holder and offers no Open.
199+
expect(notice).toHaveTextContent(
200+
tFormat('engine.studio.data.createTakenElsewhere', L, { label: 'Visit', name: 'crm_visit' }),
201+
);
202+
expect(screen.queryByTestId('object-create-open-existing')).toBeNull();
203+
});
204+
205+
// objectstack#36904 — the in-page create offered to open an object its rail held; the list's does too.
206+
it('an identifier this package holds says so, and Open goes to that object\'s designer', async () => {
207+
taken.mockResolvedValueOnce({ name: 'crm_visit', label: 'Visit' });
208+
surfaces.mockResolvedValueOnce([{ type: 'object', name: 'crm_visit' }]);
209+
const onOpenExisting = vi.fn();
210+
const onCreated = open('object', 'com.example.crm', false, onOpenExisting);
211+
fill('engine.studio.data.nameLabel', 'engine.studio.data.idLabel', 'Visit', 'visit');
212+
const notice = await screen.findByTestId('object-create-taken');
213+
expect(notice).toHaveTextContent(tFormat('engine.studio.data.createTaken', L, { label: 'Visit', name: 'crm_visit' }));
214+
expect(surfaces).toHaveBeenCalledWith(expect.anything(), 'object', 'com.example.crm', L);
215+
fireEvent.click(screen.getByTestId('object-create-open-existing'));
216+
expect(onOpenExisting).toHaveBeenCalledWith('/studio/com.example.crm/metadata/object/crm_visit');
217+
expect(save).not.toHaveBeenCalled();
218+
expect(onCreated).not.toHaveBeenCalled();
219+
});
220+
221+
// objectstack#36726 — as the flow create: no live row was there at the check, so the publish is `If-None-Match: *`.
222+
it('publishes the created object pinned, so a row published under the name since is refused', async () => {
223+
const onCreated = open('object', 'com.example.crm', false);
224+
fill('engine.studio.data.nameLabel', 'engine.studio.data.idLabel', 'Visit', 'visit');
225+
await waitFor(() => expect(onCreated).toHaveBeenCalled());
226+
expect(publish).toHaveBeenCalledTimes(1);
227+
expect(publish.mock.calls[0]?.[3]).toBe(publishCreated);
188228
});
189229
});

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ import { OWD_CREATE_MODELS, OWD_DEFAULT, type OwdCreateModel } from '../studio-d
3131
import { OWD_OPTION_DESC_KEY, OWD_OPTION_LABEL_KEY } from '../studio-design/DataPillarHelpers.js';
3232
import { buildFlowSkeleton, buildObjectSkeleton } from '../studio-design/skeletons.js';
3333
import { ensureCustomizationPackage, fetchPackages, prefixObjectName } from '../studio-design/packages-io.js';
34-
import { publishSavedItem } from '../studio-design/studioSaveBar.js';
34+
import { publishCreated, publishSavedItem } from '../studio-design/studioSaveBar.js';
35+
import { loadPackageSurfaces } from '../studio-design/packageSurfaces.js';
36+
import { studioItemPath } from '../studio-design/studioAddress.js';
3537
import { plainRefusal, type StudioRefusal } from '../studio-design/metadataError.js';
3638
import { addNewObjectToAppMenu } from '../studio-design/newObjectJoinsAppMenu.js';
3739
import { FLOW_PRESETS, flowPresetTrigger, type FlowPreset } from '../studio-design/flowPresets.js';
@@ -55,6 +57,12 @@ export interface MetadataListCreateDialogProps {
5557
locale: SupportedLocale;
5658
/** The item is live: where it was created. */
5759
onCreated: (created: { name: string; packageId: string }) => void;
60+
/**
61+
* objectstack#36903, objectstack#36904 — open the item already holding the
62+
* identifier, at its address (`studioItemPath`), when the package the create
63+
* writes to holds it. Without it the notice names the holder and offers no Open.
64+
*/
65+
onOpenExisting?: (path: string) => void;
5866
}
5967

6068
type Taken = { name: string; label: string };
@@ -80,12 +88,15 @@ async function createTarget(packageId: string, inPair: boolean, namespace: strin
8088
return { packageId: pair.packageId, namespace: pair.namespace };
8189
}
8290

83-
function ObjectCreate({ open, onOpenChange, packageId, inPair, locale, onCreated }: MetadataListCreateDialogProps) {
91+
function ObjectCreate({ open, onOpenChange, packageId, inPair, locale, onCreated, onOpenExisting }: MetadataListCreateDialogProps) {
8492
const client = useMetadataClient();
8593
const [owd, setOwd] = React.useState<OwdCreateModel>(OWD_DEFAULT);
8694
const [busy, setBusy] = React.useState(false);
8795
const [error, setError] = React.useState<StudioRefusal | null>(null);
88-
const [taken, setTaken] = React.useState<Taken | null>(null);
96+
// objectstack#36904 — `at`: the package the create writes to holds the
97+
// object with that identifier (published or a draft), so the notice offers
98+
// to open it there, as the Data pillar's in-page create did for its rail.
99+
const [taken, setTaken] = React.useState<(Taken & { at: string | null }) | null>(null);
89100
// The package's object-name namespace (framework#2694): the dialog previews
90101
// the stored name; on a read-only base the pair's, by the spec's pairing
91102
// rule, while the save prefixes with the namespace the ensure door answers.
@@ -121,14 +132,18 @@ function ObjectCreate({ open, onOpenChange, packageId, inPair, locale, onCreated
121132
const name = prefixObjectName(rawName, target.namespace);
122133
const held = await findTakenIdentifier(client, 'object', name, locale);
123134
if (held) {
124-
setTaken(held);
135+
const own = await loadPackageSurfaces(client, 'object', target.packageId, locale).catch(() => []);
136+
setTaken({ ...held, at: own.some((object) => object.name === name) ? target.packageId : null });
125137
return;
126138
}
127139
const body = buildObjectSkeleton(name, label, t('engine.studio.data.nameFieldLabel', locale), owd);
128140
await client.save('object', name, body, { mode: 'draft', packageId: target.packageId, ifNoneMatch: '*', surface: 'studio' });
129-
const live = await publishSavedItem(client, { type: 'object', name, packageId: target.packageId }, false);
141+
// objectstack#36726 — pinned `If-None-Match: *`, as the flow create is:
142+
// an object another writer published under the name since the check
143+
// above is refused, not replaced.
144+
const live = await publishSavedItem(client, { type: 'object', name, packageId: target.packageId }, false, publishCreated);
130145
if (!live.ok) {
131-
setError(plainRefusal(live.error));
146+
if ('error' in live) setError(plainRefusal(live.error));
132147
return;
133148
}
134149
toast.success(tFormat('engine.studio.save.done', locale, { items: label }));
@@ -186,7 +201,13 @@ function ObjectCreate({ open, onOpenChange, packageId, inPair, locale, onCreated
186201
{taken && (
187202
<CreateTakenNotice
188203
scope="object"
189-
sentence={tFormat('engine.studio.data.createTakenElsewhere', locale, { label: taken.label, name: taken.name })}
204+
sentence={tFormat(
205+
taken.at !== null ? 'engine.studio.data.createTaken' : 'engine.studio.data.createTakenElsewhere',
206+
locale,
207+
{ label: taken.label, name: taken.name },
208+
)}
209+
openLabel={tFormat('engine.studio.create.openExisting', locale, { label: taken.label })}
210+
onOpen={taken.at !== null && onOpenExisting ? () => onOpenExisting(studioItemPath(taken.at!, 'object', taken.name)) : undefined}
190211
/>
191212
)}
192213
{/* The object's record sharing (OWD): without it the object is

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,10 @@ function DefaultMetadataList({ type, appName }: { type: string; appName?: string
12241224
packageId={host.packageId}
12251225
inPair={createInPair}
12261226
locale={locale}
1227+
onOpenExisting={(path) => {
1228+
setCreateOpen(false);
1229+
navigate(path);
1230+
}}
12271231
onCreated={({ name, packageId }) => {
12281232
setCreateOpen(false);
12291233
refresh();

0 commit comments

Comments
 (0)