Skip to content

Commit f3d091d

Browse files
committed
test(app-shell,data-objectstack): pin the dataset Customize door, its used-by list, its publish refusal, and the references read (#30064)
Claude-Session: https://claude.ai/code/session_01QSeKYnE9YNkSZen7sijLA3 Co-authored-by: Claude <noreply@anthropic.com>
1 parent b3ce93d commit f3d091d

5 files changed

Lines changed: 367 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/data-objectstack': patch
4+
'@object-ui/i18n': patch
5+
---
6+
7+
feat(studio): customize a read-only package's dataset in the All metadata area, see what uses it before publishing, and read a refused publish at the dataset
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
- **Customize a dataset.** On a read-only base package, Studio's All metadata area opens a dataset in its form editor with the dataset designer and live preview, and offers Customize. The first saved edit copies the whole dataset into the base's paired `<base>.custom` package, declaring `overrides: { package, basedOn }`; the header's Publish applies it, and "Restore package original" on the override mark deletes the copy. On a writable package a dataset still opens the generic item page.
13+
- **What uses it.** While a dataset is customized, the editor lists the dashboards, reports and other items that name it, read from the References read, so the person sees what a published change reaches. A failed read says it failed and offers to read again; it never reads as "nothing uses it".
14+
- **A refused publish at the item.** A publish the server refuses for a dataset is placed on its measure or dimension and the designer's input (`Not published. Check Aggregate of the measure "Total Amount"`), in the Console's language, and shown at the dataset's editor as well as on its Pending changes entry. The server's own text stays under Details.
15+
- **References read fixed.** `MetadataClient.references()` now reads the route's declared answer (`{ references: [{ type, name, label, path, kind }] }`) and maps each element to `MetadataReference` (`fromType`, `fromName`, new optional `fromLabel` and `kind`). It used to read a key the route never serves, so Setup's References tab and Studio's item tools showed "Nothing in the metadata graph points at this item. Safe to delete." for every item. An answer the declaration refuses is now a failed read.

‎ui/packages/app-shell/src/views/studio-design/StudioBundleItemEditor.customize-28569.test.tsx‎

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
* - Restore deletes the pair's draft and row of that one member, and the
2525
* base's version reads back;
2626
* - a walled caller sees Customize disabled, and nothing is asked or sent.
27+
*
28+
* objectstack#30064 — a read-only base's dataset, in the same editor with the
29+
* type's registered designer (a probe here): the whole dataset written into
30+
* the pair, declared; what uses it listed from the references read before
31+
* anything is published, a failed read said as failed; a designer's blocking
32+
* issue holding the edit unsent; and a kept publish refusal shown at the item.
2733
*/
2834

2935
import '@testing-library/jest-dom/vitest';
@@ -90,6 +96,7 @@ const mockClient = vi.hoisted(() => ({
9096
srv.version += 1;
9197
return { success: true, version: `v${srv.version}`, state: 'draft' };
9298
}),
99+
references: vi.fn(async (_type: string, _name: string): Promise<unknown[]> => []),
93100
reset: vi.fn(async (type: string, name: string, opts: Record<string, unknown> = {}) => {
94101
srv.resets.push({ type, name, opts: clone(opts) });
95102
const map = opts.state === 'draft' ? srv.drafts : srv.rows;
@@ -115,6 +122,43 @@ import type { StudioBaseCustomization } from './StudioDesignSurface';
115122
import { ensureCustomizationPackage } from './packages-io';
116123
import { registerMetadataPreview } from '../metadata-admin/preview-registry';
117124
import { registerDefaultMetadataSchemas } from '../metadata-admin/default-schemas';
125+
import {
126+
registerMetadataDefaultInspector,
127+
type MetadataDefaultInspectorProps,
128+
} from '../metadata-admin/default-inspector-registry';
129+
import type { StudioRefusal } from './metadataError';
130+
131+
/**
132+
* The dataset's designer slot: the draft it is handed, its read-only gate, one
133+
* edit (the second measure's aggregate) and one blocking report.
134+
*/
135+
function DesignerProbe({ draft, onPatch, onBlockingIssuesChange, readOnly }: MetadataDefaultInspectorProps) {
136+
const measures = Array.isArray(draft.measures) ? (draft.measures as Array<Record<string, unknown>>) : [];
137+
return (
138+
<div data-testid="designer-probe" data-readonly={String(readOnly)}>
139+
<p data-testid="designer-probe-aggregate">{String(measures[1]?.aggregate ?? '')}</p>
140+
<button
141+
type="button"
142+
data-testid="designer-probe-avg"
143+
disabled={readOnly}
144+
onClick={() => onPatch({ measures: measures.map((m, i) => (i === 1 ? { ...m, aggregate: 'avg' } : m)) })}
145+
>
146+
avg
147+
</button>
148+
<button
149+
type="button"
150+
data-testid="designer-probe-blank-dimension"
151+
disabled={readOnly}
152+
onClick={() => {
153+
onPatch({ dimensions: [{ name: 'stage' }] });
154+
onBlockingIssuesChange?.(1);
155+
}}
156+
>
157+
blank
158+
</button>
159+
</div>
160+
);
161+
}
118162

119163
/** The preview slot, printing the live draft it is handed. */
120164
function PreviewProbe({ draft }: { draft: Record<string, unknown> }) {
@@ -134,6 +178,37 @@ const WELCOME_EN = {
134178
_packageId: BASE,
135179
};
136180
const WELCOME_ZH = { ...WELCOME_EN, locale: 'zh-CN', subject: '欢迎使用 HotCRM', bodyHtml: '<p>你好 {{user.name}}</p>' };
181+
const METRICS = {
182+
name: 'opportunity_metrics',
183+
label: 'Opportunity Metrics',
184+
object: 'crm_opportunity',
185+
dimensions: [{ name: 'stage', label: 'Stage', field: 'stage', type: 'string' }],
186+
measures: [
187+
{ name: 'opp_count', label: 'Opportunities', aggregate: 'count' },
188+
{ name: 'total_amount', label: 'Total Amount', aggregate: 'sum', field: 'amount' },
189+
],
190+
_packageId: BASE,
191+
};
192+
/** What the references read answers for the dataset (`client.references`, mapped from the served `references[]`). */
193+
const USED_BY = [
194+
{
195+
fromType: 'dashboard',
196+
fromName: 'pipeline_dashboard',
197+
fromLabel: 'Pipeline Dashboard',
198+
path: 'widgets[].dataset',
199+
kind: 'dashboard dataset',
200+
value: 'opportunity_metrics',
201+
},
202+
{
203+
fromType: 'dashboard',
204+
fromName: 'pipeline_dashboard',
205+
fromLabel: 'Pipeline Dashboard',
206+
path: 'widgets[].compare.dataset',
207+
kind: 'dashboard dataset',
208+
value: 'opportunity_metrics',
209+
},
210+
{ fromType: 'report', fromName: 'won_by_stage', path: 'dataset', kind: 'report dataset', value: 'opportunity_metrics' },
211+
];
137212
const BUNDLE_ZH = {
138213
name: 'hotcrm_zh',
139214
label: 'HotCRM zh-CN',
@@ -146,6 +221,7 @@ beforeAll(() => {
146221
registerDefaultMetadataSchemas();
147222
registerMetadataPreview('email_template', PreviewProbe as never);
148223
registerMetadataPreview('translation', PreviewProbe as never);
224+
registerMetadataDefaultInspector('dataset', DesignerProbe);
149225
});
150226

151227
beforeEach(() => {
@@ -155,6 +231,7 @@ beforeEach(() => {
155231
at(srv.rows, BASE).set(slot('email_template', 'welcome', 'zh-CN'), clone(WELCOME_ZH));
156232
at(srv.rows, BASE).set(slot('translation', 'hotcrm_zh'), clone(BUNDLE_ZH));
157233
at(srv.rows, WRITABLE).set(slot('email_template', 'welcome', 'zh-CN'), { ...clone(WELCOME_ZH), _packageId: WRITABLE });
234+
at(srv.rows, BASE).set(slot('dataset', 'opportunity_metrics'), clone(METRICS));
158235
srv.pairExists = false;
159236
srv.ensure.length = 0;
160237
srv.saves.length = 0;
@@ -196,13 +273,15 @@ function Host({
196273
packageId = BASE,
197274
walled = false,
198275
listedPair = null,
276+
publishRefusal = null,
199277
}: {
200278
type: string;
201279
name: string;
202280
member?: string;
203281
packageId?: string;
204282
walled?: boolean;
205283
listedPair?: string | null;
284+
publishRefusal?: StudioRefusal | null;
206285
}) {
207286
const readOnly = packageId === BASE;
208287
const [pairId, setPairId] = React.useState<string | null>(listedPair);
@@ -228,6 +307,7 @@ function Host({
228307
readOnly={readOnly}
229308
customization={customization}
230309
basePath={`/studio/${packageId}/metadata`}
310+
publishRefusal={publishRefusal}
231311
/>
232312
);
233313
}
@@ -437,3 +517,104 @@ describe('Customize a read-only base’s translation bundle (objectstack#28569)'
437517
await waitFor(() => expect(screen.queryByTestId('studio-bundle-editor-whole-bundle')).toBeNull());
438518
});
439519
});
520+
521+
describe('Customize a read-only base’s dataset (objectstack#30064)', () => {
522+
beforeEach(() => {
523+
mockClient.references.mockImplementation(async () => clone(USED_BY));
524+
});
525+
526+
it('opens the designer read-only, says the whole dataset is copied, and lists what uses it before anything is published', async () => {
527+
mount({ type: 'dataset', name: 'opportunity_metrics' });
528+
const probe = await screen.findByTestId('designer-probe', undefined, { timeout: 8000 });
529+
expect(probe).toHaveAttribute('data-readonly', 'true');
530+
expect(screen.getByTestId('designer-probe-aggregate')).toHaveTextContent('sum');
531+
expect(screen.getByTestId('studio-bundle-editor-whole-dataset')).toHaveTextContent(
532+
'Customizing a dataset copies HotCRM’s whole dataset into your customization',
533+
);
534+
const usedBy = await screen.findByTestId('studio-bundle-editor-used-by');
535+
await waitFor(() => expect(usedBy).toHaveAttribute('data-state', 'loaded'));
536+
expect(mockClient.references).toHaveBeenCalledWith('dataset', 'opportunity_metrics');
537+
// One entry per referring item: the dashboard binding it twice is one dashboard.
538+
const items = within(usedBy).getAllByTestId('studio-bundle-editor-used-by-item');
539+
expect(items.map((el) => [el.getAttribute('data-type'), el.getAttribute('data-name')])).toEqual([
540+
['dashboard', 'pipeline_dashboard'],
541+
['report', 'won_by_stage'],
542+
]);
543+
expect(items[0]).toHaveTextContent('Pipeline Dashboard');
544+
expect(items[1]).toHaveTextContent('won_by_stage');
545+
expect(usedBy).toHaveTextContent('reaches the 2 items built on this dataset');
546+
expect(srv.saves).toEqual([]);
547+
});
548+
549+
it('Customize and an edit in the designer write the whole dataset into the pair’s draft, declared; the base is untouched', async () => {
550+
mount({ type: 'dataset', name: 'opportunity_metrics' });
551+
await screen.findByTestId('designer-probe', undefined, { timeout: 8000 });
552+
await customize();
553+
await waitFor(() => expect(screen.getByTestId('designer-probe')).toHaveAttribute('data-readonly', 'false'));
554+
fireEvent.click(screen.getByTestId('designer-probe-avg'));
555+
await waitFor(() => expect(srv.saves).toHaveLength(1), { timeout: 5000 });
556+
expect(srv.ensure).toEqual([201]);
557+
const [save] = srv.saves;
558+
expect(save).toMatchObject({ type: 'dataset', name: 'opportunity_metrics' });
559+
expect(save.opts).toMatchObject({ mode: 'draft', packageId: PAIR, ifNoneMatch: '*' });
560+
const { _packageId: _dropped, ...whole } = clone(METRICS);
561+
expect(save.body).toEqual({
562+
...whole,
563+
measures: [whole.measures[0], { ...whole.measures[1], aggregate: 'avg' }],
564+
overrides: { package: BASE, basedOn: '4.0.0' },
565+
});
566+
expect(await screen.findByTestId('studio-override-chip')).toHaveTextContent('Overrides HotCRM');
567+
await waitFor(() => expect(screen.queryByTestId('studio-bundle-editor-whole-dataset')).toBeNull());
568+
// What uses it stays in view until the change is published.
569+
expect(screen.getByTestId('studio-bundle-editor-used-by')).toBeInTheDocument();
570+
expect(srv.rows.get(BASE)?.get(slot('dataset', 'opportunity_metrics'))).toEqual(METRICS);
571+
});
572+
573+
it('holds an edit the designer reports as blocking: nothing is sent', async () => {
574+
mount({ type: 'dataset', name: 'opportunity_metrics' });
575+
await screen.findByTestId('designer-probe', undefined, { timeout: 8000 });
576+
await customize();
577+
await waitFor(() => expect(screen.getByTestId('designer-probe')).toHaveAttribute('data-readonly', 'false'));
578+
fireEvent.click(screen.getByTestId('designer-probe-blank-dimension'));
579+
await sleep(2500);
580+
expect(srv.ensure).toEqual([]);
581+
expect(srv.saves).toEqual([]);
582+
});
583+
584+
it('a references read that failed says so and asks again; it never reads as nothing using the dataset', async () => {
585+
mockClient.references.mockRejectedValueOnce(Object.assign(new Error('Service Unavailable'), { status: 503 }));
586+
mount({ type: 'dataset', name: 'opportunity_metrics' });
587+
const usedBy = await screen.findByTestId('studio-bundle-editor-used-by', undefined, { timeout: 8000 });
588+
await waitFor(() => expect(usedBy).toHaveAttribute('data-state', 'error'));
589+
expect(within(usedBy).getByRole('alert')).toHaveTextContent('could not be read');
590+
expect(usedBy).not.toHaveTextContent('Nothing uses this dataset');
591+
fireEvent.click(within(usedBy).getByTestId('studio-bundle-editor-used-by-retry'));
592+
await waitFor(() => expect(usedBy).toHaveAttribute('data-state', 'loaded'));
593+
expect(within(usedBy).getAllByTestId('studio-bundle-editor-used-by-item')).toHaveLength(2);
594+
});
595+
596+
it('a read that answers no reference says nothing uses the dataset', async () => {
597+
mockClient.references.mockImplementation(async () => []);
598+
mount({ type: 'dataset', name: 'opportunity_metrics' });
599+
const usedBy = await screen.findByTestId('studio-bundle-editor-used-by', undefined, { timeout: 8000 });
600+
await waitFor(() => expect(usedBy).toHaveAttribute('data-state', 'loaded'));
601+
expect(usedBy).toHaveTextContent('Nothing uses this dataset yet');
602+
});
603+
604+
it('shows the refusal the header’s Publish kept for the dataset at the item, with the server’s text under Details', async () => {
605+
mount({
606+
type: 'dataset',
607+
name: 'opportunity_metrics',
608+
listedPair: PAIR,
609+
publishRefusal: {
610+
message: 'Not published. Check Aggregate of the measure “Total Amount”: Details say what to change.',
611+
target: null,
612+
input: 'Aggregate',
613+
detail: 'datasets.opportunity_metrics.measures[1].aggregate — aggregate "sum" over field "expected_revenue" is refused',
614+
},
615+
});
616+
const strip = await screen.findByTestId('studio-bundle-editor-publish-refusal', undefined, { timeout: 8000 });
617+
expect(within(strip).getByRole('alert')).toHaveTextContent('Check Aggregate of the measure “Total Amount”');
618+
expect(within(strip).getByTestId('studio-refusal-detail')).toHaveTextContent('expected_revenue');
619+
});
620+
});

‎ui/packages/app-shell/src/views/studio-design/metadataArea.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { describe, it, expect } from 'vitest';
1313
import {
1414
AREA_PILLAR_FOR_TYPE,
1515
STUDIO_ALL_PACKAGES_SEGMENT,
16+
areaItemOpensFormEditor,
1617
areaItemPillarPath,
1718
areaLocationRedirect,
1819
isStudioAllPackagesScope,
@@ -118,3 +119,31 @@ describe('areaItemPillarPath — a pillar type opens its pillar', () => {
118119
expect(open('flow', '?review=0')).not.toBeNull();
119120
});
120121
});
122+
123+
describe('areaItemOpensFormEditor — a read-only package’s dataset opens its Customize door (objectstack#30064)', () => {
124+
const at = (type: string, readOnly: boolean, search = '') => ({
125+
packageId: PKG,
126+
type,
127+
search: new URLSearchParams(search),
128+
readOnly,
129+
});
130+
131+
it('a dataset opens the form editor on a read-only package, and the generic page on a writable one', () => {
132+
expect(areaItemOpensFormEditor(at('dataset', true))).toBe(true);
133+
expect(areaItemOpensFormEditor(at('dataset', false))).toBe(false);
134+
expect(areaItemOpensFormEditor({ packageId: PKG, type: 'dataset', search: new URLSearchParams() })).toBe(false);
135+
});
136+
137+
it('keeps the form editor’s exceptions: the cross-package leg, the environment scope and the draft review', () => {
138+
expect(areaItemOpensFormEditor({ ...at('dataset', true), packageId: null })).toBe(false);
139+
expect(areaItemOpensFormEditor(at('dataset', true, 'scope=environment'))).toBe(false);
140+
expect(areaItemOpensFormEditor(at('dataset', true, 'review=1'))).toBe(false);
141+
});
142+
143+
it('leaves an email template and a translation where they were, on either kind of package', () => {
144+
for (const type of ['email_template', 'translation']) {
145+
expect(areaItemOpensFormEditor(at(type, true))).toBe(true);
146+
expect(areaItemOpensFormEditor(at(type, false))).toBe(true);
147+
}
148+
});
149+
});

‎ui/packages/app-shell/src/views/studio-design/metadataError.publishRefusal-26730.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,66 @@ describe('only the causal failures are kept (ADR-0067 D2)', () => {
169169
expect(causalPublishFailures([aborted('visit'), aborted('ticket')])).toEqual([aborted('visit')]);
170170
});
171171
});
172+
173+
describe('a refused dataset publish is placed on its measure or dimension (objectstack#30064)', () => {
174+
/** The measured refusal: `sum` over a formula field, as the authoring gate answers it. */
175+
const formulaMeasureRefused: PublishFailure = {
176+
type: 'dataset',
177+
name: 'opportunity_metrics',
178+
error: 'dataset/opportunity_metrics failed author-time validation: 1 issue',
179+
code: 'INVALID_METADATA',
180+
issues: [
181+
{
182+
path: 'datasets.opportunity_metrics.measures[1].aggregate',
183+
message:
184+
'aggregate "sum" over field "expected_revenue" (`formula` on object "crm_opportunity") is refused by the ' +
185+
'aggregate × field-type table: the number would depend on the SQL dialect',
186+
},
187+
],
188+
};
189+
const DATASET = {
190+
name: 'opportunity_metrics',
191+
object: 'crm_opportunity',
192+
dimensions: [{ name: 'stage', field: 'stage', type: 'string' }],
193+
measures: [
194+
{ name: 'opp_count', label: 'Opportunities', aggregate: 'count' },
195+
{ name: 'total_amount', label: 'Total Amount', aggregate: 'sum', field: 'expected_revenue' },
196+
],
197+
};
198+
199+
it('names the measure and the designer’s input, and keeps the engine text under Details', async () => {
200+
await loadStudioCatalogue('zh');
201+
const refusal = publishRefusal(formulaMeasureRefused, 'dataset', DATASET, 'zh');
202+
const input = t('engine.inspector.dataset.aggregate', 'zh');
203+
expect(refusal.message).toBe(
204+
tFormat('engine.studio.refusal.publishWhere', 'zh', {
205+
where: tFormat('engine.studio.refusal.datasetMeasureInput', 'zh', { member: 'Total Amount', input }),
206+
}),
207+
);
208+
expect(refusal.message).not.toMatch(/expected_revenue|formula|datasets\./);
209+
expect(refusal.target).toBeNull();
210+
expect(refusal.input).toBe(input);
211+
expect(refusal.detail).toBe(formatMetadataError({ message: formulaMeasureRefused.error, issues: formulaMeasureRefused.issues }));
212+
});
213+
214+
it('a dimension with no label is named by its name; a path under no member is left unplaced', () => {
215+
const dimension = publishRefusal(
216+
{ ...formulaMeasureRefused, issues: [{ path: 'datasets.opportunity_metrics.dimensions[0]', message: 'x' }] },
217+
'dataset',
218+
DATASET,
219+
'en',
220+
);
221+
expect(dimension.message).toBe(
222+
tFormat('engine.studio.refusal.publishWhere', 'en', {
223+
where: tFormat('engine.studio.refusal.datasetDimension', 'en', { member: 'stage' }),
224+
}),
225+
);
226+
const unplaced = publishRefusal(
227+
{ ...formulaMeasureRefused, issues: [{ path: 'datasets.opportunity_metrics.object', message: 'x' }] },
228+
'dataset',
229+
DATASET,
230+
'en',
231+
);
232+
expect(unplaced.message).toBe(t('engine.studio.refusal.publishUnlocated', 'en'));
233+
});
234+
});

0 commit comments

Comments
 (0)