Skip to content
Merged
18 changes: 18 additions & 0 deletions .changeset/39630-design-mode-widget-new-dataset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@object-ui/app-shell": patch
"@object-ui/i18n": patch
---

feat(app-shell): in the app's design mode, a dashboard card's New dataset publishes the dataset at once into the dashboard's package and picks it for the card

Clause-②: no
Metadata-protocol: none

Who sees it: a workspace admin designing a dashboard in the app's design mode (the dashboard's Edit, or a dashboard opened from App Studio).

- **A selected card's dataset picker offers New dataset** in the design mode, as it does in App Studio. While no dataset reads one of the app's objects, the card panel says so in one sentence.
- **New dataset writes nothing until you name the dataset and press Create.** The dataset is then saved and published in the same act into the dashboard's own package (a writable app package, including a dashboard that an app's customization package owns), and picked for the card, so the dashboard you then save reads a published dataset.
- **A refused publish leaves no dataset or draft behind** and shows the server's reason in the dialog; the card stays unbound.
- **No entry where the dashboard's own package cannot hold the dataset**: an installed (read-only) app's dashboard, which the design mode saves as a customization of that app, offers no New dataset, because its cards read as the installed app's package and could not read a dataset held only in the customization package. Neither does a dashboard that names no package, or one the design mode refuses.
- App Studio's own New dataset is unchanged (it still saves a draft, published with the package).
- Known residue: a dataset created this way stays published if you then Cancel the dashboard edit.
27 changes: 27 additions & 0 deletions ui/packages/app-shell/src/views/DashboardInPageEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { describe, it, expect, vi } from 'vitest';
import '@objectstack/lint';
import '@objectstack/formula';
import {
datasetPublishFor,
filtersSectionLabel,
openDashboardForEdit,
withAddedWidget,
Expand Down Expand Up @@ -188,3 +189,29 @@ describe('the page\'s own buffer edits', () => {
expect(filtersSectionLabel('en-US')).toBe('Filters');
});
});

describe('where a card\'s New dataset publishes in the design mode (objectstack#39630)', () => {
it('a writable owning package: the dataset is published there', async () => {
const publish = datasetPublishFor({ kind: 'package', packageId: 'crm' });
expect(publish?.packageId).toBe('crm');
await expect(publish!.pickPackage()).resolves.toBe('crm');
});

it('a dashboard an app\'s customization pair owns is a writable package like any other', async () => {
const publish = datasetPublishFor({ kind: 'package', packageId: 'crm.custom' });
expect(publish?.packageId).toBe('crm.custom');
await expect(publish!.pickPackage()).resolves.toBe('crm.custom');
});

it('an installed (read-only) app\'s dashboard, saved as an override in its pair: no entry, listed pair or not', () => {
// Its cards read as the installed package, whose closure does not reach the pair (ADR-0150 D3).
expect(datasetPublishFor({ kind: 'customization', base: 'crm', basedOn: '3.0.0', pair: null })).toBeNull();
expect(datasetPublishFor({ kind: 'customization', base: 'crm', basedOn: '3.0.0', pair: 'crm.custom' })).toBeNull();
});

it('no package to name, or nothing open: no entry', () => {
expect(datasetPublishFor({ kind: 'unbound' })).toBeNull();
expect(datasetPublishFor(null)).toBeNull();
expect(datasetPublishFor(undefined)).toBeNull();
});
});
46 changes: 46 additions & 0 deletions ui/packages/app-shell/src/views/DashboardInPageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
* a menu entry may name apart from the app's (objectstack#39459): a gate
* that answers no refuses it at selection too, with the reason.
*
* objectstack#39630 — a card's dataset picker offers New dataset here too
* (ruling record 7408596103, A): the dataset is saved and published at once
* into the dashboard's own package ({@link datasetPublishFor}), then picked
* for the card, so the dashboard the bar's Save publishes reads a published
* dataset. A dashboard with no package of its own to write, or an installed
* app's (saved as an override in its customization pair), offers none.
*
* Out of scope here: undo, a business user's own copy, a new dashboard, chart
* drawing and drill-down.
*/
Expand Down Expand Up @@ -78,6 +85,7 @@ import { getDashboardForm } from './metadata-admin/dashboard-schema.js';
import { useMetadataLocale, type SupportedLocale } from './metadata-admin/i18n.js';
import type { MetadataSelection } from './metadata-admin/preview-registry.js';
import { ServedWidgetTextContext, servedWidgetTextOf } from './studio-design/servedDashboardText.js';
import { DatasetPublishAuthoringContext, type DatasetPublishAuthoring } from './studio-design/datasetCreate.js';
import { studioPackagePath } from './studio-design/studioAddress.js';

/** Where the editor would save, as read at open (nothing is written to open). */
Expand Down Expand Up @@ -226,6 +234,26 @@ export function withResizedWidget(
return { ...doc, widgets: next };
}

/**
* objectstack#39630 — where a card's New dataset writes in the design mode:
* the dashboard's own package, when the bar's Save writes the dashboard there
* (a writable package; a dashboard an app's customization pair owns is one),
* so the dataset and the dashboard that reads it land together and the card
* reads it as its own package's (ADR-0150 D3).
*
* `null`, so no entry is offered, where there is no such package: a dashboard
* bound to none, nothing open, and an installed (read-only) app's dashboard,
* whose Save writes an override into the app's customization pair. That
* override is still served, and its cards read, as the installed app's
* package, whose dependency closure does not reach the pair: a dataset made
* there would be refused to the card (409) in the editor and after the Save.
*/
export function datasetPublishFor(target: WritableDashboardEditTarget | null | undefined): DatasetPublishAuthoring | null {
if (!target || target.kind !== 'package') return null;
const packageId = target.packageId;
return { packageId, pickPackage: async () => packageId };
}

/** The label of the panel section that edits the page filters (`globalFilters`). */
export function filtersSectionLabel(locale: SupportedLocale): string | null {
const form = getDashboardForm(locale);
Expand Down Expand Up @@ -287,6 +315,9 @@ export function DashboardEditActions({ onAddCard }: { onAddCard: (type: string)
* served dashboard, `published` the stored document the edit opened, paired
* widget by widget ({@link servedWidgetTextOf}). Without the pair the title box
* shows the stored source and an edit there replaces it.
*
* objectstack#39630: `datasetPublish` ({@link DashboardInPageEdit.datasetPublish})
* is handed to the card panel's New dataset; absent, the panel offers none.
*/
export function DashboardEditPanel({
name,
Expand All @@ -299,9 +330,12 @@ export function DashboardEditPanel({
served,
published,
shipped = null,
datasetPublish = null,
}: {
name: string;
draft: Record<string, unknown>;
/** Where a card's New dataset publishes, `null` for no entry. */
datasetPublish?: DatasetPublishAuthoring | null;
/** The dashboard as the page serves it, in the session's language. */
served?: Record<string, unknown> | null;
/** The stored document the edit state opened, before any change. */
Expand Down Expand Up @@ -342,6 +376,7 @@ export function DashboardEditPanel({
data-testid="dashboard-edit-panel"
>
<ServedWidgetTextContext.Provider value={servedWidgets}>
<DatasetPublishAuthoringContext.Provider value={datasetPublish}>
{selection?.kind === 'widget' ? (
<DashboardWidgetInspector
type="dashboard"
Expand All @@ -366,6 +401,7 @@ export function DashboardEditPanel({
locale={locale}
/>
)}
</DatasetPublishAuthoringContext.Provider>
</ServedWidgetTextContext.Provider>
</aside>
);
Expand Down Expand Up @@ -488,6 +524,12 @@ export interface DashboardInPageEdit {
shipped: Record<string, unknown> | null;
/** A change to this dashboard is staged. */
dirty: boolean;
/**
* objectstack#39630 — where a card's New dataset publishes
* ({@link datasetPublishFor} of the save target), `null` unless editing or
* when there is no package to name.
*/
datasetPublish: DatasetPublishAuthoring | null;
selection: MetadataSelection | null;
revealFilters: boolean;
/** Enter the mode with this dashboard selected; `false` when the mode refuses (it says why). */
Expand Down Expand Up @@ -635,6 +677,9 @@ export function useDashboardInPageEdit({
[stageDraft],
);

const editTarget = editing ? current!.target : null;
const datasetPublish = React.useMemo(() => datasetPublishFor(editTarget), [editTarget]);

const enterOpening = mode?.enterOpening;
const open = React.useCallback(
() => (enterOpening && name ? enterOpening({ select: { type: 'dashboard', name } }) : false),
Expand All @@ -650,6 +695,7 @@ export function useDashboardInPageEdit({
published: editing ? current!.published : null,
shipped: editing ? current!.shipped : null,
dirty: change.value !== undefined,
datasetPublish,
selection: editing ? selection : null,
revealFilters,
open,
Expand Down
Loading
Loading