Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/37261-app-new-report-package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@object-ui/app-shell': patch
---

fix(app-shell): a new report made from an app's reports list is saved in the app's package, as a new view is

Clause-②: no
Metadata-protocol: none

Studio redesign (epic #36890).

- **New report from an app's reports list** now saves the report where a new view made in that app is saved: in the app's package when it is writable, or, for an installed app, in its customization package, so Studio's report list for that package shows it. Before, a report made this way belonged to no package. Reports opened from Studio's report list were already saved this way.
- **Where the app's customization package cannot be used** (for example, the deployment does not let a tenant administrator create one), the report is saved outside any package, as before, and a notice says Studio's report list does not show it. A new view falls back the same way.
- **Existing reports are not moved.** Only reports created from now on are placed in the app's package.
79 changes: 68 additions & 11 deletions ui/packages/app-shell/src/views/ReportNewPage-36692.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,10 @@ describe('the new-report page saves on its own (objectstack#36692)', () => {
expect(screen.queryByTestId('report-new-adds-to-menu')).toBeNull();
fireEvent.click(screen.getByText('save'));
await waitFor(() => expect(screen.getByTestId('where')).toHaveTextContent('/apps/crm/report/payment_analysis'));
expect(saveAndPublish).toHaveBeenCalledWith(
'report',
'payment_analysis',
{ ...DRAFT, name: 'payment_analysis' },
expect.objectContaining({ metadataClient: client }),
);
// objectstack#36906 — outside Studio it is saved where it was before: naming
// no package, and no package door is asked.
expect(client.save).not.toHaveBeenCalled();
expect(doors.listCalls).toBe(0);
expect(toastInfo).not.toHaveBeenCalled();
// objectstack#37261 — where it is saved is pinned by the app's-own-New
// describe below; here, that it was saved and published once.
expect(client.save).toHaveBeenCalledTimes(1);
expect(client.publish).toHaveBeenCalledTimes(1);
});

it('Close goes back to the reports index, writing nothing', async () => {
Expand Down Expand Up @@ -311,6 +304,70 @@ describe('reached with the design mode already on, the page draws no builder (ob
});
});

describe("the app's own New saves into the app's package, as a new view does (objectstack#37261)", () => {
// Opened from the app's reports index, outside Studio: the same rule as the
// Studio leg below and as a new view (`resolveRuntimeCreatePackage`).
async function saveFromApp() {
mount();
fireEvent.click(screen.getByText('save'));
await waitFor(() => expect(screen.getByTestId('where')).toHaveTextContent('/apps/crm/report/payment_analysis'));
}

it("from an app on a writable package, a new report names that package", async () => {
await saveFromApp();
expect(client.save).toHaveBeenCalledWith(
'report',
'payment_analysis',
{ ...DRAFT, name: 'payment_analysis' },
{ mode: 'draft', ifNoneMatch: '*', packageId: PKG },
);
expect(client.publish).toHaveBeenCalledWith('report', 'payment_analysis', { packageId: PKG });
expect(doors.ensure).not.toHaveBeenCalled();
expect(saveAndPublish).not.toHaveBeenCalled();
expect(toastInfo).not.toHaveBeenCalled();
});

it("on an installed (read-only) app, a new report names the base's customization package", async () => {
doors.listed = new Map([[PKG, { writable: false }]]);
doors.ensure.mockImplementation(async (base: string) => ({ packageId: `${base}.custom`, writable: true }));
await saveFromApp();
expect(doors.ensure).toHaveBeenCalledWith(PKG);
expect(client.save).toHaveBeenCalledWith(
'report',
'payment_analysis',
{ ...DRAFT, name: 'payment_analysis' },
{ mode: 'draft', ifNoneMatch: '*', packageId: `${PKG}.custom` },
);
expect(client.publish).toHaveBeenCalledWith('report', 'payment_analysis', { packageId: `${PKG}.custom` });
expect(saveAndPublish).not.toHaveBeenCalled();
expect(toastInfo).not.toHaveBeenCalled();
});

it('control: when the ensure door refuses, Save falls back to naming no package, and says so, as a new view does', async () => {
doors.listed = new Map([[PKG, { writable: false }]]);
doors.ensure.mockImplementation(async () => {
throw Object.assign(new Error('Forbidden'), { status: 403 });
});
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
try {
await saveFromApp();
expect(doors.ensure).toHaveBeenCalledWith(PKG);
expect(client.save).not.toHaveBeenCalled();
expect(saveAndPublish).toHaveBeenCalledWith(
'report',
'payment_analysis',
{ ...DRAFT, name: 'payment_analysis' },
expect.objectContaining({ metadataClient: client }),
);
expect(toastInfo).toHaveBeenCalledTimes(1);
expect(toastInfo).toHaveBeenCalledWith('report.builder.savedOutsideApp');
expect(warn).toHaveBeenCalledWith(expect.stringContaining('the report is saved naming no package'), expect.anything());
} finally {
warn.mockRestore();
}
});
});

describe("opened from Studio's report list (objectstack#36906, decision 13)", () => {
const studioList = '/studio/crm/metadata/report?q=pay';
const fromStudio = `?studio=${encodeURIComponent(studioList)}`;
Expand Down
21 changes: 11 additions & 10 deletions ui/packages/app-shell/src/views/ReportNewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ export function ReportNewPage({ dataSource }: { dataSource?: DataSource }) {
},
[navigate, appName, studioReturn, studioLeaveMessage],
);
// objectstack#36906 — a report made from Studio's report list is saved in
// the app's package, where that list finds it, as a new view made in an app
// objectstack#36906, objectstack#37261 — a new report is saved in the app's
// package, where Studio's report list finds it, as a new view made in an app
// is (`resolveRuntimeCreatePackage`): the package when it is writable, else
// its customization package through the ensure door, else, when neither can
// be had, naming no package, as before, and a notice says so. A report made
// from the app's own reports index is saved as before, naming no package.
// be had, naming no package, and a notice says so. One rule for both ways in:
// Studio's report list and the app's own reports index. Outside any app it
// names no package, as a view does.
const appPackageId = draftBarPackageOf(appName, apps as Parameters<typeof draftBarPackageOf>[1]);

const handleSave = React.useCallback(
Expand All @@ -149,19 +150,19 @@ export function ReportNewPage({ dataSource }: { dataSource?: DataSource }) {
}
const body = { ...draft, label, name };
const ctx = { metadataClient, dataSource: dataSource as any };
const packageId = studioReturn ? await resolveRuntimeCreatePackage(appPackageId, 'report') : null;
const packageId = await resolveRuntimeCreatePackage(appPackageId, 'report');
const outcome = packageId
? await saveAndPublishInPackage('report', name, body, packageId, ctx)
: await saveAndPublishRuntimeMetadata('report', name, body, ctx);
if (outcome === 'pending-draft') {
toast.error(t('form.saveError'), { description: t('report.builder.pendingDraft') });
return false;
}
// Opened from Studio, the app's package (or its customization package)
// could not be had, so the report was saved naming no package: the
// Studio list × goes back to does not show it. Say so, as a new view
// saved outside its app does (`onSavedOutsideApp`).
if (studioReturn && appPackageId && !packageId) toast.info(t('report.builder.savedOutsideApp'));
// The app's package (or its customization package) could not be had,
// so the report was saved naming no package: Studio's report list does
// not show it. Say so, whichever way the builder was opened, as a new
// view saved outside its app does (`onSavedOutsideApp`).
if (appPackageId && !packageId) toast.info(t('report.builder.savedOutsideApp'));
} catch (err) {
toast.error(t('form.saveError'), {
description: formatMetadataError(err),
Expand Down
Loading