From 5e618c26fcd3cfde45df3f4e39b76bae4730e872 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 14:03:34 +0000 Subject: [PATCH 1/8] feat(app-shell): design mode's dashboard widget offers New dataset, published into the dashboard's save target Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_016WV4cypQd6ZDPDmXL5MaWR --- .../src/views/DashboardInPageEditor.tsx | 54 +++++++++++ .../app-shell/src/views/DashboardView.tsx | 1 + .../inspectors/DashboardWidgetInspector.tsx | 18 +++- .../src/views/studio-design/datasetCreate.tsx | 94 +++++++++++++++---- ui/packages/i18n/src/namespaces/studio/en.ts | 5 + ui/packages/i18n/src/namespaces/studio/zh.ts | 5 + 6 files changed, 152 insertions(+), 25 deletions(-) diff --git a/ui/packages/app-shell/src/views/DashboardInPageEditor.tsx b/ui/packages/app-shell/src/views/DashboardInPageEditor.tsx index 7a2c8ecac6d..1dd9133291e 100644 --- a/ui/packages/app-shell/src/views/DashboardInPageEditor.tsx +++ b/ui/packages/app-shell/src/views/DashboardInPageEditor.tsx @@ -40,6 +40,12 @@ * 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 package this dashboard's Save writes ({@link datasetPublishFor}), + * then picked for the card, so the dashboard the bar's Save publishes reads a + * published dataset. A dashboard with no package to name offers none. + * * Out of scope here: undo, a business user's own copy, a new dashboard, chart * drawing and drill-down. */ @@ -78,6 +84,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). */ @@ -226,6 +233,35 @@ export function withResizedWidget( return { ...doc, widgets: next }; } +/** + * objectstack#39630 — where a card's New dataset writes in the design mode: + * the package the bar's Save writes this dashboard to, so the dataset and the + * dashboard that reads it land together. The owning package when writable; + * for an installed (read-only) base, its customization pair, asked of the + * ensure door (which creates it on first use) only when the author presses + * Create, as the dashboard's own Save asks it; the door's refusal is the + * dialog's error and nothing is written. `null` where there is no package to + * name (a dashboard bound to none, or nothing open): no entry is offered. + */ +export function datasetPublishFor( + target: WritableDashboardEditTarget | null | undefined, + doors?: Pick, +): DatasetPublishAuthoring | null { + if (!target || target.kind === 'unbound') return null; + if (target.kind === 'package') { + const packageId = target.packageId; + return { packageId, pickPackage: async () => packageId }; + } + return { + // The app's objects are its base's: the pair holds only what was customized. + packageId: target.base, + pickPackage: async () => { + const saveTarget = await ensureDashboardSaveTarget(target, doors); + return saveTarget.kind === 'unbound' ? null : saveTarget.packageId; + }, + }; +} + /** The label of the panel section that edits the page filters (`globalFilters`). */ export function filtersSectionLabel(locale: SupportedLocale): string | null { const form = getDashboardForm(locale); @@ -287,6 +323,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, @@ -299,9 +338,12 @@ export function DashboardEditPanel({ served, published, shipped = null, + datasetPublish = null, }: { name: string; draft: Record; + /** 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 | null; /** The stored document the edit state opened, before any change. */ @@ -342,6 +384,7 @@ export function DashboardEditPanel({ data-testid="dashboard-edit-panel" > + {selection?.kind === 'widget' ? ( )} + ); @@ -488,6 +532,12 @@ export interface DashboardInPageEdit { shipped: Record | 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). */ @@ -635,6 +685,9 @@ export function useDashboardInPageEdit({ [stageDraft], ); + const editTarget = editing ? current!.target : null; + const datasetPublish = React.useMemo(() => datasetPublishFor(editTarget, doors), [editTarget, doors]); + const enterOpening = mode?.enterOpening; const open = React.useCallback( () => (enterOpening && name ? enterOpening({ select: { type: 'dashboard', name } }) : false), @@ -650,6 +703,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, diff --git a/ui/packages/app-shell/src/views/DashboardView.tsx b/ui/packages/app-shell/src/views/DashboardView.tsx index a33fc1cc3eb..1c3cda33109 100644 --- a/ui/packages/app-shell/src/views/DashboardView.tsx +++ b/ui/packages/app-shell/src/views/DashboardView.tsx @@ -568,6 +568,7 @@ export function DashboardView({ dataSource }: { dataSource?: any }) { served={dashboard as Record | undefined} published={edit.published} shipped={edit.shipped} + datasetPublish={edit.datasetPublish} /> )} diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/DashboardWidgetInspector.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/DashboardWidgetInspector.tsx index 574a32e50ef..bbdbed86fcd 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/DashboardWidgetInspector.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/DashboardWidgetInspector.tsx @@ -56,7 +56,11 @@ import { useDatasetCatalog, useDatasetSemantics, type DatasetDimensionInfo } fro import { datasetLabelOptions, packageDatasetsFirst } from './dataset-picker-options.js'; import { shownLabel, writtenLabel, servedLabelNote, useLabelLanguage } from './servedLabel.js'; import { useServedWidgetText } from '../../studio-design/servedDashboardText.js'; -import { DatasetCreateEntry, useStudioDatasetAuthoring } from '../../studio-design/datasetCreate.js'; +import { + DatasetCreateEntry, + useDatasetPublishAuthoring, + useStudioDatasetAuthoring, +} from '../../studio-design/datasetCreate.js'; import type { ObjectFieldInfo } from '../previews/useObjectFields.js'; import { widgetMissingInputs } from '../../studio-design/metadataError.js'; import { WIDGET_TYPE_IDS, WIDGET_TYPE_META } from '../previews/widget-types.js'; @@ -160,7 +164,11 @@ export function DashboardWidgetInspector({ // objectstack#27518 — in the Studio (its authoring context is present) the // catalog is the draft-overlaid one, this package's datasets first, and the // New dataset entry sits under the picker. + // objectstack#39630 — in the app's design mode the entry publishes at once + // into the dashboard's save target; the catalog stays the published one. const datasetAuthoring = useStudioDatasetAuthoring(); + const datasetPublish = useDatasetPublishAuthoring(); + const leadPackageId = datasetAuthoring?.packageId ?? datasetPublish?.packageId; const catalog = useDatasetCatalog(undefined, { previewDrafts: datasetAuthoring !== null }); const semantics = useDatasetSemantics(datasetName || undefined, catalog); @@ -173,13 +181,13 @@ export function DashboardWidgetInspector({ // on hover (`nameOnHover` on each combo below). const datasetComboOptions: InspectorComboOption[] = React.useMemo(() => { const opts: InspectorComboOption[] = datasetLabelOptions( - packageDatasetsFirst(catalog.datasets, datasetAuthoring?.packageId), + packageDatasetsFirst(catalog.datasets, leadPackageId), ); if (datasetName && !opts.some((o) => o.value === datasetName)) { opts.push({ value: datasetName, label: datasetName }); } return opts; - }, [catalog.datasets, datasetName, datasetAuthoring?.packageId]); + }, [catalog.datasets, datasetName, leadPackageId]); const measureOptions: ObjectFieldInfo[] = React.useMemo( () => datasetMeasureOptions(semantics.measures, locale), [semantics.measures, locale], @@ -455,9 +463,9 @@ export function DashboardWidgetInspector({

{t('engine.inspector.widget.datasetHint', locale)}

- {datasetAuthoring && !readOnly && ( + {!readOnly && (datasetAuthoring || datasetPublish) && ( patchWidget({ dataset: name } as Partial)} locale={locale} diff --git a/ui/packages/app-shell/src/views/studio-design/datasetCreate.tsx b/ui/packages/app-shell/src/views/studio-design/datasetCreate.tsx index 252afc17893..c0c8a6c2a83 100644 --- a/ui/packages/app-shell/src/views/studio-design/datasetCreate.tsx +++ b/ui/packages/app-shell/src/views/studio-design/datasetCreate.tsx @@ -20,9 +20,14 @@ * the author's name, label and object, one dimension per picked group-by * field and one `sum` measure per picked number field. * - * Studio only: Studio's All-metadata area (`StudioMetadataArea`) provides - * {@link StudioDatasetAuthoringContext} on a writable package, and a picker - * outside it (Setup's editors, a read-only package) has no entry. + * Where the entry is: Studio's All-metadata area (`StudioMetadataArea`) + * provides {@link StudioDatasetAuthoringContext} on a writable package (a + * draft, published with the package), and the app's design mode + * (`DashboardInPageEditor`, objectstack#39630) provides + * {@link DatasetPublishAuthoringContext} where the dashboard has a package to + * save in (saved and published at once, as the dashboard's own Save is). A + * picker under neither (Setup's editors, a read-only package with no + * customization target) has no entry. * * Internal to app-shell: not exported from the package root. */ @@ -158,6 +163,33 @@ export interface DatasetPublishTarget { pickPackage: () => Promise; } +/** + * objectstack#39630 — the app's design mode's New dataset, beside a dashboard + * widget's dataset picker: saved and published at once in the package the + * design mode's Save writes the dashboard to ({@link DatasetPublishTarget}), + * so the dashboard the author then saves reads a published dataset. + */ +export interface DatasetPublishAuthoring extends DatasetPublishTarget { + /** + * The package whose objects are the dashboard's app's objects: the dialog + * opens on its one object, the hint reads its objects, its datasets lead + * the picker. For a customization target, the base it customizes. + */ + packageId: string; +} + +/** + * Provided by the design mode's dashboard panel where the dashboard has a + * package to save in. Unlike {@link StudioDatasetAuthoringContext} it changes + * no picker's world: a dataset made here is published, so the catalog stays + * the published one. + */ +export const DatasetPublishAuthoringContext = React.createContext(null); + +export function useDatasetPublishAuthoring(): DatasetPublishAuthoring | null { + return React.useContext(DatasetPublishAuthoringContext); +} + /** The three metadata doors {@link saveAndPublishDataset} writes through. */ export interface DatasetPublishClient { save(type: string, name: string, body: unknown, options: Record): Promise; @@ -256,8 +288,9 @@ function toggled(set: ReadonlySet, name: string, on: boolean): Set void; + /** What will read the published dataset, as its description says: a report, or a dashboard widget's chart. */ + readBy?: 'report' | 'widget'; /** The object the dialog opens on, when the picker knows it. */ initialObject?: string; /** The objects the server serves: a name outside them is refused here. */ @@ -419,13 +455,18 @@ export function NewDatasetDialog({ extra: fieldsForm, }; // One dialog per write, each saying what its Create does (objectui#11787): - // the report builder's is published at once and says Create; the Studio's is - // a draft and says Save as draft. + // the report builder's and the design mode's are published at once and say + // Create; the Studio's is a draft and says Save as draft. return publishTo ? ( ) : ( @@ -439,21 +480,29 @@ export function NewDatasetDialog({ } /** - * The entry a dataset picker shows in the Studio: a line saying no dataset - * reads this package's objects yet, while that is so (whatever else the - * catalog holds), and the New dataset button with its dialog. The dialog opens - * on the package's object when it has exactly one. A create reloads the - * picker's catalog, then hands the new name to `onCreated` for the picker to - * bind. + * How a picker's entry writes: the Studio's draft (`authoring`), or saved and + * published at once in the design mode's target (`publishTo`, objectstack#39630). + */ +export type DatasetCreateEntryWrite = + | { authoring: StudioDatasetAuthoring; publishTo?: undefined } + | { authoring?: undefined; publishTo: DatasetPublishAuthoring }; + +/** + * The entry a dataset picker shows in the Studio, or in the app's design + * mode: a line saying no dataset reads this package's (the app's) objects + * yet, while that is so (whatever else the catalog holds), and the New + * dataset button with its dialog. The dialog opens on the package's object + * when it has exactly one. A create reloads the picker's catalog, then hands + * the new name to `onCreated` for the picker to bind. */ export function DatasetCreateEntry({ authoring, + publishTo, catalog, onCreated, locale, testId, -}: { - authoring: StudioDatasetAuthoring; +}: DatasetCreateEntryWrite & { catalog: UseDatasetCatalogResult; onCreated: (name: string) => void; locale: SupportedLocale; @@ -461,19 +510,24 @@ export function DatasetCreateEntry({ }): React.ReactElement { const objects = useObjectCatalog(); const [open, setOpen] = React.useState(false); + const packageId = authoring ? authoring.packageId : publishTo.packageId; const served = objects.status === 'loaded' ? objects.data : null; const knownObjects = React.useMemo(() => new Set((served ?? []).map((o) => o.name)), [served]); const packageObjects = React.useMemo( - () => (served ?? []).filter((o) => o.packageId === authoring.packageId && !o.isSystem).map((o) => o.name), - [served, authoring.packageId], + () => (served ?? []).filter((o) => o.packageId === packageId && !o.isSystem).map((o) => o.name), + [served, packageId], ); const unread = served !== null && !catalog.loading && !readsAnyObject(catalog.datasets, new Set(packageObjects)); + // The Studio says "this package"; the app's design mode, where a package is not named, says "this app". + const hint = authoring + ? 'engine.studio.interfaces.newDataset.noPackageDatasets' + : 'engine.studio.interfaces.newDataset.noAppDatasets'; return (
{unread && (

- {t('engine.studio.interfaces.newDataset.noPackageDatasets', locale)} + {t(hint, locale)}

)}