Skip to content

Commit 0ada679

Browse files
committed
fix(console): the shared-view confirm and the Save as my view name use the view's tab label
A view's label is an I18nLabel with no default: read raw, a locale map printed [object Object] and a missing one an empty name. Both now take listLabel (viewTabLabel), so the dialog says what the tab says. The draft door's 409 is told apart by DraftConflictDialog's own predicate. Claude-Session: https://claude.ai/code/session_01L6bhgWyeXh2Keywo6oK1Nn Co-authored-by: Claude <noreply@anthropic.com>
1 parent da8b797 commit 0ada679

4 files changed

Lines changed: 68 additions & 4 deletions

File tree

‎ui/packages/app-shell/src/views/ObjectView.personalViews-29635.test.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,26 @@ describe('objectstack#30073 — a personal view\'s conditions are Filter panel r
790790
expect(draftOf('v1')).toEqual({});
791791
});
792792

793+
it.each([
794+
['no label', undefined, 'Leads copy'],
795+
['a label given as a locale map', { en: 'Hot list', 'zh-CN': '热门' }, 'Hot list copy'],
796+
])('objectstack#35955 L1-b S1 — 「Save as my view」 names the copy by the view\'s tab label when it has %s', async (_case, label, expected) => {
797+
const v1 = LEAD.listViews.v1 as Record<string, unknown>;
798+
const authored = v1.label;
799+
if (label === undefined) delete v1.label;
800+
else v1.label = label;
801+
try {
802+
mountLeads(romeLink('/apps/crm/crm_lead/view/v1'));
803+
await listToolbar();
804+
fireEvent.pointerDown(await screen.findByTestId('list-draft-save'), { button: 0, ctrlKey: false, pointerType: 'mouse' });
805+
fireEvent.click(await screen.findByTestId('list-draft-save-as'));
806+
// Never 「 copy」 or 「[object Object] copy」: the name the tab draws.
807+
expect(await screen.findByDisplayValue(expected)).toBeInTheDocument();
808+
} finally {
809+
v1.label = authored;
810+
}
811+
});
812+
793813
it('objectstack#35955 — the draft\'s row colour is saved too: into the reader\'s own view, and into a view of their own', async () => {
794814
const RED = { field: 'status', colors: { open: 'red' } };
795815
storeListState({ perView: { pv_mine: { sort: [{ field: 'name', order: 'desc' }], rowColor: RED } } });

‎ui/packages/app-shell/src/views/ObjectView.sharedViewSave-35955.test.tsx‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ vi.mock('./MetadataInspector', () => ({
6969
}));
7070
vi.mock('./RecordDetailView', () => ({ RecordDetailView: () => null }));
7171

72+
// The harness has no i18n provider, so `t` answers keys. The confirm's
73+
// question also carries the name it was handed, so the name can be read back
74+
// (objectstack#35955 L1-b S1).
75+
vi.mock('@object-ui/i18n', async (importOriginal) => {
76+
const actual = await importOriginal<typeof import('@object-ui/i18n')>();
77+
const React = await import('react');
78+
return {
79+
...actual,
80+
useObjectTranslation: (...args: Parameters<typeof actual.useObjectTranslation>) => {
81+
const bound = actual.useObjectTranslation(...args);
82+
const t = React.useMemo(() => ((key: string, options?: Record<string, unknown>) => {
83+
const out = (bound.t as (k: string, o?: unknown) => unknown)(key, options);
84+
return key === 'console.objectView.draft.saveToViewConfirm' ? `${String(out)} [${String(options?.name)}]` : out;
85+
}) as typeof bound.t, [bound.t]);
86+
return { ...bound, t };
87+
},
88+
};
89+
});
90+
7291
/** The props the list was last handed. */
7392
const listProps = vi.hoisted(() => ({ current: null as Record<string, any> | null }));
7493
vi.mock('@object-ui/plugin-list', async (importOriginal) => ({
@@ -242,6 +261,29 @@ describe('objectstack#35955 — Save to this view on a shared view: confirm, the
242261
await waitFor(() => expect(listProps.current?.onSaveView).toBeUndefined());
243262
});
244263

264+
it.each([
265+
// A stored view with no label reaches the page named by its name, which is
266+
// what its tab draws (`viewTabLabel`), never an empty 「“”」.
267+
['no label', undefined, `${OBJECT}.team_tasks`],
268+
['a label given as a locale map', { en: 'Team list', 'zh-CN': '团队列表' }, 'Team list'],
269+
['CONTROL: a plain label', 'Team tasks', 'Team tasks'],
270+
])('the confirm names the view as its tab does when it has %s (L1-b S1)', async (_case, label, expected) => {
271+
const view = SHARED as Record<string, unknown>;
272+
const authored = view.label;
273+
if (label === undefined) delete view.label;
274+
else view.label = label;
275+
try {
276+
mount(SHARED.name);
277+
await settle();
278+
await sortByAmount();
279+
await pressSave();
280+
// Never 「“”」 or 「[object Object]」.
281+
expect(await screen.findByText(`console.objectView.draft.saveToViewConfirm [${expected}]`)).toBeInTheDocument();
282+
} finally {
283+
view.label = authored;
284+
}
285+
});
286+
245287
it('cancelling the confirm writes nothing and keeps the draft', async () => {
246288
mount(SHARED.name);
247289
await settle();

‎ui/packages/app-shell/src/views/ObjectView.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,9 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
904904
const handleSaveToSharedView = async () => {
905905
if (!activeView || !canSaveToSharedView) return;
906906
const confirmed = await confirmHandler(
907-
t('console.objectView.draft.saveToViewConfirm', { name: (activeView as any).label ?? '' }),
907+
// The view's name as its tab draws it (objectstack#35955 L1-b S1): a
908+
// label is an I18nLabel with no default, so never the raw value.
909+
t('console.objectView.draft.saveToViewConfirm', { name: listLabel }),
908910
{
909911
title: t('console.objectView.draft.saveToViewConfirmTitle'),
910912
confirmText: t('console.objectView.draft.saveToViewConfirmButton'),
@@ -1614,7 +1616,7 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
16141616
? t('console.objectView.draft.saveAsMyView')
16151617
: t('view.rename', { defaultValue: 'Rename' })}
16161618
initialName={personalViewDialog?.mode === 'saveAs'
1617-
? t('console.objectView.draft.copyName', { name: activeView?.label ?? '' })
1619+
? t('console.objectView.draft.copyName', { name: listLabel })
16181620
: renamingPersonalView?.label ?? ''}
16191621
onSubmit={(name) => (personalViewDialog?.mode === 'rename'
16201622
? handleRenamePersonalView(personalViewDialog.viewId, name)

‎ui/packages/app-shell/src/views/runtime-metadata-persistence.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
*/
4040

4141
import { stripReadDecorations } from '@objectstack/spec/kernel';
42-
import { errorCodeIs } from '@object-ui/types';
4342
import { emitMetadataRefresh } from '../assistant/assistantBus.js';
4443
import { slugify } from './metadata-admin/createDerive.js';
44+
import { isDraftVersionConflict } from './metadata-admin/DraftConflictDialog.js';
4545
import { ensureCustomizationPackage, fetchListedPackageManifests } from './studio-design/packages-io.js';
4646

4747
/** The runtime-editable artifact types ADR-0034 unifies. `page` (a record
@@ -540,7 +540,7 @@ export async function saveAndPublishRuntimeMetadata(
540540
try {
541541
await ctx.metadataClient.save(type, name, body, { mode: 'draft', ifNoneMatch: '*' });
542542
} catch (err) {
543-
if ((err as { status?: unknown } | null)?.status === 409 && errorCodeIs(err, 'METADATA_CONFLICT')) {
543+
if (isDraftVersionConflict(err)) {
544544
return 'pending-draft';
545545
}
546546
throw err;

0 commit comments

Comments
 (0)