@malloy-publisher/sdk 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{RenderedResult-CBLHr32C.es.js → RenderedResult-DwB0-9Yx.es.js} +118 -119
- package/dist/{RenderedResult-B48wAjM8.cjs.js → RenderedResult-hKjFEqaN.cjs.js} +2 -2
- package/dist/{ServerProvider-DCV8BUWD.es.js → ServerProvider-CcSrGaRN.es.js} +1281 -1142
- package/dist/ServerProvider-Gbf1YPOP.cjs.js +1 -0
- package/dist/builder/index.cjs.js +112 -115
- package/dist/builder/index.es.js +11766 -11502
- package/dist/builder-entry.d.ts +1 -1
- package/dist/client/api.d.ts +170 -9
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +93 -89
- package/dist/client-entry.d.ts +2 -0
- package/dist/components/ApiErrorDisplay.d.ts +11 -0
- package/dist/components/AppDialog.d.ts +6 -6
- package/dist/components/Dashboard/DashboardGrid.d.ts +18 -3
- package/dist/components/Dashboard/DashboardTile.d.ts +12 -2
- package/dist/components/Dashboard/DashboardView.d.ts +38 -3
- package/dist/components/Dashboard/TileCard.d.ts +16 -2
- package/dist/components/Dashboard/dropValueUrlTags.d.ts +6 -0
- package/dist/components/Dashboard/index.d.ts +3 -2
- package/dist/components/Dashboard/telemetry.d.ts +2 -1
- package/dist/components/Dashboard/textSource.d.ts +19 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +7 -8
- package/dist/components/DashboardBuilder/BuilderDialogs.d.ts +25 -0
- package/dist/components/DashboardBuilder/BuilderGrid.d.ts +31 -0
- package/dist/components/DashboardBuilder/BuilderHeader.d.ts +17 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +14 -17
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +3 -1
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +15 -7
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +28 -2
- package/dist/components/DashboardBuilder/EditorSurface.d.ts +33 -0
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +6 -4
- package/dist/components/DashboardBuilder/InlineText.d.ts +1 -1
- package/dist/components/DashboardBuilder/NotebookEditor.d.ts +1 -1
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +4 -1
- package/dist/components/DashboardBuilder/TileFrame.d.ts +43 -6
- package/dist/components/DashboardBuilder/TileMenu.d.ts +6 -8
- package/dist/components/DashboardBuilder/builderReport.d.ts +13 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +0 -18
- package/dist/components/DashboardBuilder/documentSession.d.ts +2 -2
- package/dist/components/DashboardBuilder/imports.d.ts +19 -0
- package/dist/components/DashboardBuilder/inlineEdit.d.ts +18 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +3 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +1 -1
- package/dist/components/DashboardBuilder/sortable.d.ts +2 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +2 -0
- package/dist/components/DashboardBuilder/testing/resize.d.ts +7 -0
- package/dist/components/DashboardBuilder/tileDisplayTitle.d.ts +7 -0
- package/dist/components/DashboardBuilder/useBuilderSelection.d.ts +53 -0
- package/dist/components/DashboardBuilder/useBuilderSession.d.ts +4 -7
- package/dist/components/DashboardBuilder/useControlBindings.d.ts +30 -0
- package/dist/components/DashboardBuilder/useConversionConfirm.d.ts +20 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +2 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +3 -1
- package/dist/components/DashboardBuilder/useHostCopy.d.ts +26 -0
- package/dist/components/DashboardBuilder/useOpenDraftCommit.d.ts +17 -0
- package/dist/components/DashboardBuilder/useOpenedDocument.d.ts +71 -0
- package/dist/components/DashboardBuilder/useSaveChannel.d.ts +50 -0
- package/dist/components/DashboardBuilder/useTileEditing.d.ts +33 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +32 -0
- package/dist/components/Loading.d.ts +13 -0
- package/dist/components/Notebook/NotebookCell.d.ts +1 -5
- package/dist/components/Package/Package.d.ts +16 -1
- package/dist/components/Package/index.d.ts +1 -1
- package/dist/components/Prose.d.ts +1 -1
- package/dist/components/RenderedResult/loadRenderer.d.ts +7 -0
- package/dist/components/given/paramCodec.d.ts +8 -1
- package/dist/components/index.d.ts +1 -2
- package/dist/components/styles.d.ts +4 -4
- package/dist/hooks/givenValue.d.ts +6 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useCompiledDocument.d.ts +23 -0
- package/dist/hooks/useDocumentControls.d.ts +6 -1
- package/dist/hooks/useNearViewport.d.ts +16 -0
- package/dist/hooks/useQueryWithApiError.d.ts +7 -2
- package/dist/hooks/useSuggestOptions.d.ts +9 -2
- package/dist/index.cjs.js +14 -14
- package/dist/index.es.js +9760 -10363
- package/dist/text/index.es.js +1 -1
- package/dist/{text-entry-CbbBcZl8.es.js → text-entry-CA0LZ1xL.es.js} +8 -8
- package/dist/text-entry.d.ts +1 -1
- package/dist/theme/accent.d.ts +29 -0
- package/dist/theme/buildVegaThemeOverride.d.ts +3 -3
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/keys.d.ts +1 -1
- package/dist/theme/motion.d.ts +31 -0
- package/dist/theme/readChartAnnotations.d.ts +1 -1
- package/dist/theme/resolveTheme.d.ts +4 -4
- package/dist/theme/types.d.ts +33 -5
- package/dist/{DashboardTile-BFcxdv7R.es.js → useCompiledDocument-BU6d8FPp.es.js} +6978 -6289
- package/dist/useCompiledDocument-pOg2W-Yt.cjs.js +142 -0
- package/package.json +11 -11
- package/src/builder-entry.ts +1 -0
- package/src/client-entry.ts +8 -0
- package/src/clientEntry.spec.ts +17 -0
- package/src/components/ApiErrorDisplay.tsx +37 -18
- package/src/components/AppDialog.tsx +8 -7
- package/src/components/Dashboard/Dashboard.spec.tsx +3 -32
- package/src/components/Dashboard/Dashboard.tsx +2 -2
- package/src/components/Dashboard/DashboardGrid.tsx +23 -5
- package/src/components/Dashboard/DashboardTile.spec.tsx +97 -2
- package/src/components/Dashboard/DashboardTile.tsx +95 -31
- package/src/components/Dashboard/DashboardView.spec.tsx +156 -0
- package/src/components/Dashboard/DashboardView.tsx +165 -89
- package/src/components/Dashboard/RowsDialog.tsx +3 -2
- package/src/components/Dashboard/TileCard.tsx +17 -2
- package/src/components/Dashboard/dropValueUrlTags.spec.ts +177 -0
- package/src/components/Dashboard/dropValueUrlTags.ts +108 -0
- package/src/components/Dashboard/index.ts +11 -2
- package/src/components/Dashboard/telemetry.ts +2 -1
- package/src/components/Dashboard/textSource.spec.ts +36 -0
- package/src/components/Dashboard/textSource.ts +39 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +16 -56
- package/src/components/DashboardBuilder/BuilderDialogs.tsx +162 -0
- package/src/components/DashboardBuilder/BuilderGrid.tsx +245 -0
- package/src/components/DashboardBuilder/BuilderHeader.tsx +107 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +86 -113
- package/src/components/DashboardBuilder/ChartPicker.tsx +4 -1
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +5 -5
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +74 -83
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +62 -18
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +55 -108
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +10 -62
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +50 -57
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +53 -40
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +10 -8
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +227 -704
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +32 -52
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +1 -50
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +12 -18
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +4 -24
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +4 -4
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +8 -13
- package/src/components/DashboardBuilder/DashboardEditor.textSource.spec.tsx +317 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +142 -820
- package/src/components/DashboardBuilder/DrillDialog.tsx +2 -2
- package/src/components/DashboardBuilder/EditorSurface.tsx +471 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +13 -8
- package/src/components/DashboardBuilder/FilterStrip.tsx +117 -79
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +7 -9
- package/src/components/DashboardBuilder/InlineText.tsx +23 -17
- package/src/components/DashboardBuilder/NotebookEditor.tsx +3 -3
- package/src/components/DashboardBuilder/TextTileBody.tsx +5 -2
- package/src/components/DashboardBuilder/TileFrame.tsx +255 -90
- package/src/components/DashboardBuilder/TileMenu.tsx +41 -91
- package/src/components/DashboardBuilder/artifactBlock.spec.ts +1 -1
- package/src/components/DashboardBuilder/artifactTagParity.spec.ts +9 -4
- package/src/components/DashboardBuilder/builderReport.ts +74 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +0 -44
- package/src/components/DashboardBuilder/catalog.ts +0 -36
- package/src/components/DashboardBuilder/controls.spec.ts +1 -1
- package/src/components/DashboardBuilder/controls.ts +1 -1
- package/src/components/DashboardBuilder/documentSession.ts +3 -2
- package/src/components/DashboardBuilder/imports.spec.ts +61 -0
- package/src/components/DashboardBuilder/imports.ts +93 -0
- package/src/components/DashboardBuilder/inlineEdit.tsx +78 -0
- package/src/components/DashboardBuilder/legacyNotebook.ts +1 -1
- package/src/components/DashboardBuilder/malloyTree.ts +5 -1
- package/src/components/DashboardBuilder/newDashboard.ts +1 -1
- package/src/components/DashboardBuilder/preview.ts +1 -1
- package/src/components/DashboardBuilder/readDocument.spec.ts +36 -0
- package/src/components/DashboardBuilder/readDocument.ts +10 -4
- package/src/components/DashboardBuilder/readForEditor.ts +7 -2
- package/src/components/DashboardBuilder/sortable.spec.ts +25 -1
- package/src/components/DashboardBuilder/sortable.tsx +11 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +8 -3
- package/src/components/DashboardBuilder/testing/artifactTagParity.json +62 -6
- package/src/components/DashboardBuilder/testing/documentKindRule.json +40 -0
- package/src/components/DashboardBuilder/testing/inline.ts +1 -1
- package/src/components/DashboardBuilder/testing/resize.ts +48 -0
- package/src/components/DashboardBuilder/testing/urlRenderTags.json +62 -0
- package/src/components/DashboardBuilder/textTiles.spec.ts +43 -1
- package/src/components/DashboardBuilder/tileDisplayTitle.ts +13 -0
- package/src/components/DashboardBuilder/useBuilderSelection.ts +121 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +0 -85
- package/src/components/DashboardBuilder/useBuilderSession.ts +6 -43
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +32 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +11 -1
- package/src/components/DashboardBuilder/useControlBindings.ts +152 -0
- package/src/components/DashboardBuilder/useConversionConfirm.ts +55 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +5 -2
- package/src/components/DashboardBuilder/useDraft.ts +15 -2
- package/src/components/DashboardBuilder/useHostCopy.ts +104 -0
- package/src/components/DashboardBuilder/useOpenDraftCommit.ts +47 -0
- package/src/components/DashboardBuilder/useOpenedDocument.ts +314 -0
- package/src/components/DashboardBuilder/useSaveChannel.ts +275 -0
- package/src/components/DashboardBuilder/useTileEditing.ts +141 -0
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +146 -0
- package/src/components/DashboardBuilder/useTileResize.ts +133 -0
- package/src/components/DataAppViewer/DataAppViewer.tsx +7 -4
- package/src/components/DocumentCreate/guards.ts +1 -1
- package/src/components/Environment/Environment.tsx +0 -10
- package/src/components/Loading.tsx +14 -0
- package/src/components/Model/Model.tsx +16 -9
- package/src/components/Model/ModelExplorer.tsx +2 -2
- package/src/components/Notebook/Notebook.tsx +6 -2
- package/src/components/Notebook/NotebookCell.tsx +90 -215
- package/src/components/Package/Package.artifacts.spec.tsx +8 -12
- package/src/components/Package/Package.create.spec.tsx +22 -1
- package/src/components/Package/Package.tsx +51 -27
- package/src/components/Package/index.ts +1 -1
- package/src/components/Prose.spec.tsx +37 -0
- package/src/components/Prose.tsx +35 -5
- package/src/components/RenderedResult/RenderedResult.tsx +5 -7
- package/src/components/RenderedResult/ResultContainer.tsx +7 -2
- package/src/components/RenderedResult/ResultPanel.tsx +20 -5
- package/src/components/RenderedResult/loadRenderer.ts +42 -0
- package/src/components/given/GivenInput.spec.tsx +5 -5
- package/src/components/given/GivenInput.tsx +46 -38
- package/src/components/given/GivensPanel.tsx +2 -8
- package/src/components/given/paramCodec.ts +27 -1
- package/src/components/index.ts +1 -2
- package/src/components/styles.ts +4 -5
- package/src/hooks/givenValue.ts +9 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useCompiledDocument.spec.tsx +86 -0
- package/src/hooks/useCompiledDocument.ts +59 -0
- package/src/hooks/useDimensionalFilterRangeData.ts +3 -1
- package/src/hooks/useDocumentControls.ts +13 -1
- package/src/hooks/useNearViewport.spec.tsx +150 -0
- package/src/hooks/useNearViewport.ts +102 -0
- package/src/hooks/useQueryResult.ts +7 -1
- package/src/hooks/useQueryWithApiError.ts +10 -3
- package/src/hooks/useRawQueryData.ts +3 -1
- package/src/hooks/useSuggestOptions.dom.spec.ts +40 -1
- package/src/hooks/useSuggestOptions.ts +42 -10
- package/src/text-entry.ts +1 -1
- package/src/textEntry.spec.ts +2 -8
- package/src/theme/accent.spec.ts +116 -0
- package/src/theme/accent.ts +148 -0
- package/src/theme/buildTableCssVars.spec.ts +24 -0
- package/src/theme/buildTableCssVars.ts +1 -2
- package/src/theme/buildVegaThemeOverride.spec.ts +38 -2
- package/src/theme/buildVegaThemeOverride.ts +5 -5
- package/src/theme/defaults.ts +34 -0
- package/src/theme/index.ts +9 -0
- package/src/theme/keys.ts +6 -0
- package/src/theme/motion.ts +44 -0
- package/src/theme/readChartAnnotations.spec.ts +18 -0
- package/src/theme/readChartAnnotations.ts +1 -1
- package/src/theme/resolveTheme.spec.ts +73 -0
- package/src/theme/resolveTheme.ts +61 -20
- package/src/theme/types.ts +30 -5
- package/src/utils/queryClient.ts +8 -0
- package/dist/DashboardTile-sg8LjUk8.cjs.js +0 -137
- package/dist/ServerProvider-HRqT3w1C.cjs.js +0 -1
- package/dist/components/Dashboard/DashboardBar.d.ts +0 -21
- package/dist/components/Dashboard/ExploreDialog.d.ts +0 -20
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +0 -7
- package/dist/components/DashboardBuilder/SaveNotice.d.ts +0 -27
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +0 -32
- package/dist/components/DashboardBuilder/diff.d.ts +0 -35
- package/src/components/Dashboard/DashboardBar.tsx +0 -88
- package/src/components/Dashboard/ExploreDialog.tsx +0 -89
- package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +0 -194
- package/src/components/DashboardBuilder/DiffDialog.spec.tsx +0 -25
- package/src/components/DashboardBuilder/DiffDialog.tsx +0 -103
- package/src/components/DashboardBuilder/SaveNotice.tsx +0 -113
- package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +0 -87
- package/src/components/DashboardBuilder/SettingsPopover.tsx +0 -326
- package/src/components/DashboardBuilder/diff.spec.ts +0 -44
- package/src/components/DashboardBuilder/diff.ts +0 -93
- /package/dist/{components/DashboardBuilder → utils}/malloyText.d.ts +0 -0
- /package/src/{components/DashboardBuilder → utils}/malloyText.spec.ts +0 -0
- /package/src/{components/DashboardBuilder → utils}/malloyText.ts +0 -0
|
@@ -1,67 +1,38 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import { DragDropProvider } from "@dnd-kit/react";
|
|
5
4
|
import AddIcon from "@mui/icons-material/Add";
|
|
6
|
-
import { Alert,
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
useMemo,
|
|
11
|
-
useRef,
|
|
12
|
-
useState,
|
|
13
|
-
type ReactNode,
|
|
14
|
-
} from "react";
|
|
15
|
-
import {
|
|
16
|
-
DashboardGrid,
|
|
17
|
-
DEFAULT_COLUMNS,
|
|
18
|
-
nudgedSpan,
|
|
19
|
-
} from "../Dashboard/DashboardGrid";
|
|
20
|
-
import { tileTitle } from "../Dashboard/DashboardTile";
|
|
21
|
-
import type { TileHeadingSlots } from "../Dashboard/TileCard";
|
|
5
|
+
import { Alert, Button, Stack, Typography } from "@mui/material";
|
|
6
|
+
import { useMemo, useRef, useState, type ReactNode } from "react";
|
|
7
|
+
import { DEFAULT_COLUMNS, nudgedSpan } from "../Dashboard/DashboardGrid";
|
|
8
|
+
import type { TileChrome, TileHeadingSlots } from "../Dashboard/TileCard";
|
|
22
9
|
import type { SavesTo } from "./documentSession";
|
|
23
10
|
import type { BuilderEvent } from "./telemetry";
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
removeControl,
|
|
30
|
-
type BuilderControl,
|
|
31
|
-
type BuilderGiven,
|
|
32
|
-
type MappingRow,
|
|
33
|
-
} from "./controls";
|
|
34
|
-
import { UnsavedChangesDialog } from "../UnsavedChangesDialog";
|
|
11
|
+
import type { BuilderGiven } from "./controls";
|
|
12
|
+
import { BuilderDialogs } from "./BuilderDialogs";
|
|
13
|
+
import { BuilderGrid } from "./BuilderGrid";
|
|
14
|
+
import { BuilderHeader } from "./BuilderHeader";
|
|
15
|
+
import { builderReport } from "./builderReport";
|
|
35
16
|
import { BuilderToolbar } from "./BuilderToolbar";
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import { InlineText } from "./InlineText";
|
|
39
|
-
import { OpenDraftContext, type OpenDraftSink } from "./openDraft";
|
|
40
|
-
import { filterableFields, type PackageCatalog } from "./catalog";
|
|
17
|
+
import { OpenDraftContext } from "./openDraft";
|
|
18
|
+
import type { PackageCatalog } from "./catalog";
|
|
41
19
|
import {
|
|
42
20
|
isQueryTile,
|
|
43
|
-
isTextTile,
|
|
44
|
-
tileKey,
|
|
45
21
|
type DashboardDocument,
|
|
46
|
-
type DashboardTile,
|
|
47
|
-
type LocalGiven,
|
|
48
22
|
type QueryTile,
|
|
49
23
|
} from "./document";
|
|
50
|
-
import { AddTileDialog, type NewTile } from "./AddTileDialog";
|
|
51
|
-
import { SaveNotice } from "./SaveNotice";
|
|
52
|
-
import { DrillDialog } from "./DrillDialog";
|
|
53
|
-
import { FilterDialog } from "./FilterDialog";
|
|
54
|
-
import { SettingsPopover, settingsOf } from "./SettingsPopover";
|
|
55
24
|
import { FilterStrip } from "./FilterStrip";
|
|
56
|
-
import {
|
|
57
|
-
import {
|
|
58
|
-
import { GapTarget, GridGuides, TileFrame, TilePlaceholder } from "./TileFrame";
|
|
59
|
-
import { TextTileBody } from "./TextTileBody";
|
|
60
|
-
import { useTileReorder } from "./useTileReorder";
|
|
61
|
-
import { TileMenu } from "./TileMenu";
|
|
25
|
+
import { SELECTION_RING_PX } from "./TileFrame";
|
|
26
|
+
import { useBuilderSelection } from "./useBuilderSelection";
|
|
62
27
|
import { useBuilderSession } from "./useBuilderSession";
|
|
28
|
+
import { useControlBindings } from "./useControlBindings";
|
|
29
|
+
import { useConversionConfirm } from "./useConversionConfirm";
|
|
63
30
|
import { useDashboardEditor } from "./useDashboardEditor";
|
|
64
31
|
import type { SaveHandler } from "./useDocumentEditor";
|
|
32
|
+
import { useOpenDraftCommit } from "./useOpenDraftCommit";
|
|
33
|
+
import { useTileEditing } from "./useTileEditing";
|
|
34
|
+
import { useTileReorder } from "./useTileReorder";
|
|
35
|
+
import { useTileResize } from "./useTileResize";
|
|
65
36
|
|
|
66
37
|
export type { BuilderGiven } from "./controls";
|
|
67
38
|
|
|
@@ -106,8 +77,6 @@ export interface DashboardBuilderProps {
|
|
|
106
77
|
* the save, so it must write through the same channel and checks.
|
|
107
78
|
*/
|
|
108
79
|
onSave?: SaveHandler<DashboardDocument>;
|
|
109
|
-
/** Whether the save notice (View change, Undo save) is showing, for a host that must not replace the document under it. */
|
|
110
|
-
onSaveNoticeChange?: (showing: boolean) => void;
|
|
111
80
|
/**
|
|
112
81
|
* The document as it stands, on every edit — including the first render.
|
|
113
82
|
*
|
|
@@ -128,7 +97,12 @@ export interface DashboardBuilderProps {
|
|
|
128
97
|
* heading itself passes it on (`DashboardTile`'s `heading`), or the tile
|
|
129
98
|
* cannot be retitled on the page.
|
|
130
99
|
*/
|
|
131
|
-
renderTile?: (
|
|
100
|
+
renderTile?: (
|
|
101
|
+
tile: QueryTile,
|
|
102
|
+
heading?: TileHeadingSlots,
|
|
103
|
+
/** The document's tile chrome — bare on a notebook — so the live tile reads as the reader's. */
|
|
104
|
+
chrome?: TileChrome,
|
|
105
|
+
) => ReactNode;
|
|
132
106
|
/**
|
|
133
107
|
* The control row, in the slot the reader puts it — this is where a real
|
|
134
108
|
* `GivensPanel` goes.
|
|
@@ -201,12 +175,20 @@ export interface DashboardBuilderProps {
|
|
|
201
175
|
replaces?: string;
|
|
202
176
|
/** The document's file within the package, so a kind switch tags what its folder would otherwise misread. */
|
|
203
177
|
modelPath?: string;
|
|
178
|
+
/** The document is held as text, which the server reads by its tags rather than its folder: the tag always carries `kind=`. */
|
|
179
|
+
explicitKind?: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Why "Add filter" is off, or absent when it is on. A document kept as bare
|
|
182
|
+
* text has no `given:` of its own to write, so only the model's givens can
|
|
183
|
+
* be bound, from the chips.
|
|
184
|
+
*/
|
|
185
|
+
addFilterDisabledReason?: string;
|
|
204
186
|
/**
|
|
205
187
|
* The host's own extra actions for the edit bar, rendered beside undo, redo
|
|
206
|
-
* and save.
|
|
188
|
+
* and save.
|
|
207
189
|
*/
|
|
208
190
|
toolbar?: ReactNode;
|
|
209
|
-
/** Leave the builder:
|
|
191
|
+
/** Leave the builder, opted into: draws Close, which asks first when edits are unsaved. */
|
|
210
192
|
onExit?: () => void;
|
|
211
193
|
}
|
|
212
194
|
|
|
@@ -216,13 +198,12 @@ export function DashboardBuilder({
|
|
|
216
198
|
onSave,
|
|
217
199
|
onChange,
|
|
218
200
|
onDirtyChange,
|
|
219
|
-
|
|
201
|
+
onExit,
|
|
220
202
|
renderTile,
|
|
221
203
|
controls,
|
|
222
204
|
givens,
|
|
223
205
|
catalog,
|
|
224
206
|
toolbar,
|
|
225
|
-
onExit,
|
|
226
207
|
dashboards,
|
|
227
208
|
onEvent,
|
|
228
209
|
conversion,
|
|
@@ -230,6 +211,8 @@ export function DashboardBuilder({
|
|
|
230
211
|
saveLabel,
|
|
231
212
|
replaces,
|
|
232
213
|
modelPath,
|
|
214
|
+
explicitKind,
|
|
215
|
+
addFilterDisabledReason,
|
|
233
216
|
}: DashboardBuilderProps) {
|
|
234
217
|
const editor = useDashboardEditor({
|
|
235
218
|
source,
|
|
@@ -238,166 +221,94 @@ export function DashboardBuilder({
|
|
|
238
221
|
...(conversion ? { conversion } : {}),
|
|
239
222
|
...(replaces !== undefined ? { replaces } : {}),
|
|
240
223
|
...(modelPath !== undefined ? { modelPath } : {}),
|
|
224
|
+
...(explicitKind ? { explicitKind } : {}),
|
|
241
225
|
});
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
226
|
+
const gridBox = useRef<HTMLDivElement>(null);
|
|
227
|
+
const {
|
|
228
|
+
selected,
|
|
229
|
+
descriptionSelected,
|
|
230
|
+
selectTile,
|
|
231
|
+
deselectTile,
|
|
232
|
+
selectDescription,
|
|
233
|
+
clearSelection,
|
|
234
|
+
flash,
|
|
235
|
+
stepEditor,
|
|
236
|
+
} = useBuilderSelection({ editor, gridBox });
|
|
247
237
|
// A notebook is one column whatever the file says, and the builder never writes its width.
|
|
248
238
|
const notebook = editor.document.kind === "notebook";
|
|
249
239
|
const columns = notebook ? 1 : (editor.document.columns ?? DEFAULT_COLUMNS);
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
//
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
240
|
+
// The reader's tile chrome for this document: cards on a dashboard, bare
|
|
241
|
+
// flow on a notebook. Every tile, text block and the description take it,
|
|
242
|
+
// so editing a document draws it the way reading it does.
|
|
243
|
+
const chrome: TileChrome = notebook ? "none" : "card";
|
|
244
|
+
// The name a reader's view titles an untitled document with.
|
|
245
|
+
const documentSlug = modelPath
|
|
246
|
+
?.split("/")
|
|
247
|
+
.at(-1)
|
|
248
|
+
?.replace(/\.malloy$/, "");
|
|
249
|
+
const reorder = useTileReorder({
|
|
250
|
+
tiles: editor.document.tiles,
|
|
251
|
+
commit: (next) =>
|
|
252
|
+
editor.update((draft) => {
|
|
253
|
+
draft.tiles = next;
|
|
254
|
+
}),
|
|
255
|
+
onLanded: selectTile,
|
|
256
|
+
});
|
|
257
|
+
const { dragging } = reorder;
|
|
258
|
+
// Dragging a tile's right edge sets its width, written once on release.
|
|
259
|
+
const resizing = useTileResize({
|
|
260
|
+
tiles: editor.document.tiles,
|
|
261
|
+
columns,
|
|
262
|
+
gridBox,
|
|
263
|
+
onStart: selectTile,
|
|
264
|
+
commit: (index, span) =>
|
|
265
|
+
editor.update((draft) => {
|
|
266
|
+
const tile = draft.tiles[index];
|
|
267
|
+
if (tile) tile.colspan = span;
|
|
268
|
+
}),
|
|
269
|
+
});
|
|
270
|
+
const tiles = useTileEditing({
|
|
271
|
+
editor,
|
|
272
|
+
notebook,
|
|
273
|
+
columns,
|
|
274
|
+
modelPath,
|
|
275
|
+
selectTile,
|
|
276
|
+
deselectTile,
|
|
277
|
+
});
|
|
278
|
+
const { menu, addingTile, openAdd } = tiles;
|
|
279
|
+
const bindings = useControlBindings({
|
|
280
|
+
editor,
|
|
281
|
+
opened: document,
|
|
282
|
+
givens,
|
|
283
|
+
catalog,
|
|
284
|
+
});
|
|
285
|
+
const { filterDialog, setFilterDialog } = bindings;
|
|
276
286
|
// The clickable-cells window, for one tile's source.
|
|
277
287
|
const [drillSource, setDrillSource] = useState<string | undefined>(
|
|
278
288
|
undefined,
|
|
279
289
|
);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
() => settingsOf(editor.document),
|
|
288
|
-
[editor.document],
|
|
289
|
-
);
|
|
290
|
-
|
|
291
|
-
// Imported sources a tile or extension reads, which the settings cannot take off.
|
|
292
|
-
const sourcesInUse = useMemo(
|
|
293
|
-
() =>
|
|
294
|
-
new Set([
|
|
295
|
-
...editor.document.sources.map((source) => source.base),
|
|
296
|
-
...editor.document.tiles.filter(isQueryTile).map((t) => t.source),
|
|
297
|
-
]),
|
|
298
|
-
[editor.document],
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
// The givens the MODEL offers: the caller's list, less any the opened file
|
|
302
|
-
// declared itself. A caller gets that list from the server's manifest, which
|
|
303
|
-
// resolves givens across the file and its imports without saying which is
|
|
304
|
-
// which — so it names this file's own declarations too, and keeps naming a
|
|
305
|
-
// control after this document removes it, until a save is written and the
|
|
306
|
-
// package reloads. Without this, "Remove from dashboard" took the chip off
|
|
307
|
-
// and it came straight back, faint, labelled "from the model".
|
|
308
|
-
const modelGivens = useMemo(() => {
|
|
309
|
-
const ownDeclarations = new Set(
|
|
310
|
-
(document.localGivens ?? []).map((given) => given.name),
|
|
311
|
-
);
|
|
312
|
-
return (givens ?? []).filter((given) => !ownDeclarations.has(given.name));
|
|
313
|
-
}, [document, givens]);
|
|
314
|
-
// Every control the builder can offer: this file's own, then the model's.
|
|
315
|
-
const controlList = useMemo(
|
|
316
|
-
() => controlsOf(editor.document, modelGivens),
|
|
317
|
-
[editor.document, modelGivens],
|
|
318
|
-
);
|
|
319
|
-
// The fields a binding may name, PER SOURCE: the dimensions of the model
|
|
320
|
-
// source each of this file's extensions is built on, when the host knows
|
|
321
|
-
// them. A composite spans sources, so one list would call a field the second
|
|
322
|
-
// source has "unknown" and block the window on it. Undefined for a source
|
|
323
|
-
// the catalog does not have, and nothing checks that source's tiles.
|
|
324
|
-
const fieldsBySource = useMemo(
|
|
325
|
-
() =>
|
|
326
|
-
new Map(
|
|
327
|
-
editor.document.sources.map((source) => [
|
|
328
|
-
source.name,
|
|
329
|
-
filterableFields(catalog, source.base),
|
|
330
|
-
]),
|
|
331
|
-
),
|
|
332
|
-
[catalog, editor.document.sources],
|
|
333
|
-
);
|
|
334
|
-
const fieldsFor = useCallback(
|
|
335
|
-
(tile: QueryTile) =>
|
|
336
|
-
fieldsBySource.get(tile.source) ??
|
|
337
|
-
// A tile on an imported source with no extension of its own: its
|
|
338
|
-
// source IS a model source, and may be in the catalog directly.
|
|
339
|
-
filterableFields(catalog, tile.source),
|
|
340
|
-
[fieldsBySource, catalog],
|
|
341
|
-
);
|
|
342
|
-
// The catalog's view behind the tile whose menu is open, for the charts the
|
|
343
|
-
// picker may offer: a reference tile's base view, else a view of the tile's own name.
|
|
344
|
-
const menuAt =
|
|
345
|
-
menu === undefined ? undefined : editor.document.tiles[menu.index];
|
|
346
|
-
const menuTile = menuAt && isQueryTile(menuAt) ? menuAt : undefined;
|
|
347
|
-
const menuView = (() => {
|
|
348
|
-
if (!menuTile || !catalog) return undefined;
|
|
349
|
-
const base =
|
|
350
|
-
editor.document.sources.find((s) => s.name === menuTile.source)
|
|
351
|
-
?.base ?? menuTile.source;
|
|
352
|
-
const viewName =
|
|
353
|
-
menuTile.declaration.kind === "reference"
|
|
354
|
-
? menuTile.declaration.from
|
|
355
|
-
: menuTile.name;
|
|
356
|
-
return catalog.sources
|
|
357
|
-
.find((s) => s.name === base)
|
|
358
|
-
?.views.find((v) => v.name === viewName);
|
|
359
|
-
})();
|
|
360
|
-
// Bindings a tile's source cannot take, per control — a field it does not
|
|
361
|
-
// have, or one of a type the given cannot compare: marked on the chip, so a
|
|
362
|
-
// broken binding is seen before the package refuses it.
|
|
363
|
-
const unknownFieldsOf = (
|
|
364
|
-
name: string,
|
|
365
|
-
type: string | undefined,
|
|
366
|
-
): string[] => {
|
|
367
|
-
const out: string[] = [];
|
|
368
|
-
for (const tile of editor.document.tiles) {
|
|
369
|
-
if (!isQueryTile(tile)) continue;
|
|
370
|
-
const known = fieldsFor(tile);
|
|
371
|
-
if (!known) continue;
|
|
372
|
-
const types = new Map(known.map((field) => [field.name, field.type]));
|
|
373
|
-
for (const filter of tile.filters ?? []) {
|
|
374
|
-
if (filter.given !== name) continue;
|
|
375
|
-
if (
|
|
376
|
-
!types.has(filter.field) ||
|
|
377
|
-
!acceptsField(type, types.get(filter.field))
|
|
378
|
-
)
|
|
379
|
-
out.push(
|
|
380
|
-
`${filter.field} on ${tile.label ?? tile.name} (${
|
|
381
|
-
editor.document.sources.find((s) => s.name === tile.source)
|
|
382
|
-
?.base ?? tile.source
|
|
383
|
-
})`,
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return out;
|
|
388
|
-
};
|
|
389
|
-
// Model givens nothing binds yet: what "From the model" offers.
|
|
390
|
-
const available = useMemo(
|
|
391
|
-
() =>
|
|
392
|
-
controlList.filter((c) => c.origin === "model" && c.boundTiles === 0),
|
|
393
|
-
[controlList],
|
|
394
|
-
);
|
|
290
|
+
const { draftDirty, openDraft, prepare } = useOpenDraftCommit({
|
|
291
|
+
editorDirty: editor.dirty,
|
|
292
|
+
});
|
|
293
|
+
const { confirmConversion, prepareSave } = useConversionConfirm({
|
|
294
|
+
pendingOpen: editor.pendingOpen,
|
|
295
|
+
prepare,
|
|
296
|
+
});
|
|
395
297
|
|
|
396
298
|
const shortcuts = useMemo(
|
|
397
299
|
() => ({
|
|
398
300
|
// Escape drops the selection — unless the menu or the filter window is open, in which case the key is theirs and they close on it themselves.
|
|
399
301
|
escape: () => {
|
|
400
|
-
|
|
302
|
+
// Not while a menu or a window is open: the key is theirs, and
|
|
303
|
+
// they close on it themselves.
|
|
304
|
+
if (
|
|
305
|
+
!menu &&
|
|
306
|
+
!filterDialog &&
|
|
307
|
+
!addingTile &&
|
|
308
|
+
drillSource === undefined &&
|
|
309
|
+
confirmConversion === undefined
|
|
310
|
+
)
|
|
311
|
+
clearSelection();
|
|
401
312
|
},
|
|
402
313
|
nudge: (delta: 1 | -1) => {
|
|
403
314
|
// The drag's keyboard sensor also reads the arrows, and a drop would write the drag-start width back.
|
|
@@ -415,269 +326,50 @@ export function DashboardBuilder({
|
|
|
415
326
|
});
|
|
416
327
|
},
|
|
417
328
|
}),
|
|
418
|
-
[
|
|
329
|
+
[
|
|
330
|
+
editor,
|
|
331
|
+
menu,
|
|
332
|
+
filterDialog,
|
|
333
|
+
addingTile,
|
|
334
|
+
drillSource,
|
|
335
|
+
confirmConversion,
|
|
336
|
+
clearSelection,
|
|
337
|
+
selected,
|
|
338
|
+
columns,
|
|
339
|
+
notebook,
|
|
340
|
+
dragging,
|
|
341
|
+
],
|
|
419
342
|
);
|
|
420
|
-
useEffect(() => {
|
|
421
|
-
const before = lastDocument.current;
|
|
422
|
-
lastDocument.current = editor.document;
|
|
423
|
-
if (!stepping.current) return;
|
|
424
|
-
stepping.current = false;
|
|
425
|
-
const key = changedTileKey(before, editor.document);
|
|
426
|
-
if (key === undefined) return;
|
|
427
|
-
setFlash(key);
|
|
428
|
-
const target = Array.from(
|
|
429
|
-
gridBox.current?.querySelectorAll<HTMLElement>("[data-tile-key]") ??
|
|
430
|
-
[],
|
|
431
|
-
).find((element) => element.dataset.tileKey === key);
|
|
432
|
-
// jsdom has no layout, so no scrollIntoView.
|
|
433
|
-
target?.scrollIntoView?.({ block: "nearest", behavior: "smooth" });
|
|
434
|
-
}, [editor.document, gridBox]);
|
|
435
|
-
useEffect(() => {
|
|
436
|
-
if (flash === undefined) return;
|
|
437
|
-
const timer = setTimeout(() => setFlash(undefined), 1500);
|
|
438
|
-
return () => clearTimeout(timer);
|
|
439
|
-
}, [flash]);
|
|
440
|
-
const stepEditor = useMemo(
|
|
441
|
-
() => ({
|
|
442
|
-
...editor,
|
|
443
|
-
undo: () => {
|
|
444
|
-
stepping.current = true;
|
|
445
|
-
editor.undo();
|
|
446
|
-
},
|
|
447
|
-
redo: () => {
|
|
448
|
-
stepping.current = true;
|
|
449
|
-
editor.redo();
|
|
450
|
-
},
|
|
451
|
-
}),
|
|
452
|
-
[editor],
|
|
453
|
-
);
|
|
454
|
-
const [draftDirty, setDraftDirty] = useState(false);
|
|
455
|
-
const draftCommit = useRef<(() => boolean) | undefined>(undefined);
|
|
456
|
-
const afterCommit = useRef<(() => void) | undefined>(undefined);
|
|
457
|
-
const openDraft = useMemo<OpenDraftSink>(
|
|
458
|
-
() => ({ setDirty: setDraftDirty, commitRef: draftCommit }),
|
|
459
|
-
[],
|
|
460
|
-
);
|
|
461
|
-
// A save reads the committed document, so an open draft is committed first and the save runs once that has rendered.
|
|
462
|
-
const prepare = useCallback(
|
|
463
|
-
(run: () => Promise<void> | void): Promise<void> | void => {
|
|
464
|
-
if (!draftCommit.current) return run();
|
|
465
|
-
if (!draftCommit.current()) return;
|
|
466
|
-
return new Promise<void>((resolve) => {
|
|
467
|
-
afterCommit.current = () => resolve(run());
|
|
468
|
-
});
|
|
469
|
-
},
|
|
470
|
-
[],
|
|
471
|
-
);
|
|
472
|
-
useEffect(() => {
|
|
473
|
-
if (draftDirty || !afterCommit.current) return;
|
|
474
|
-
const run = afterCommit.current;
|
|
475
|
-
afterCommit.current = undefined;
|
|
476
|
-
run();
|
|
477
|
-
}, [draftDirty, editor.dirty]);
|
|
478
343
|
const session = useBuilderSession<DashboardDocument>({
|
|
479
344
|
editor: stepEditor,
|
|
480
345
|
extraDirty: draftDirty,
|
|
481
|
-
prepare,
|
|
346
|
+
prepare: prepareSave,
|
|
482
347
|
unit: { name: "tile", count: (document) => document.tiles.length },
|
|
483
348
|
onSave,
|
|
484
|
-
onExit,
|
|
485
349
|
onDirtyChange,
|
|
486
|
-
|
|
350
|
+
onExit,
|
|
487
351
|
onChange,
|
|
488
352
|
shortcuts,
|
|
489
|
-
report: {
|
|
353
|
+
report: builderReport({
|
|
490
354
|
size: editor.document.tiles.length,
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
? {
|
|
496
|
-
type: "notebook.saved",
|
|
497
|
-
cells: size,
|
|
498
|
-
structural,
|
|
499
|
-
converted: fromOpen,
|
|
500
|
-
where: savesTo,
|
|
501
|
-
durationMs,
|
|
502
|
-
}
|
|
503
|
-
: {
|
|
504
|
-
type: "dashboard.saved",
|
|
505
|
-
tiles: size,
|
|
506
|
-
structural,
|
|
507
|
-
where: savesTo,
|
|
508
|
-
durationMs,
|
|
509
|
-
},
|
|
510
|
-
),
|
|
511
|
-
refused: (reason) =>
|
|
512
|
-
onEvent?.({
|
|
513
|
-
type: notebook
|
|
514
|
-
? "notebook.save_refused"
|
|
515
|
-
: "dashboard.save_refused",
|
|
516
|
-
reason,
|
|
517
|
-
}),
|
|
518
|
-
undone: ({ size, structural, durationMs }) =>
|
|
519
|
-
onEvent?.(
|
|
520
|
-
notebook
|
|
521
|
-
? {
|
|
522
|
-
type: "notebook.save_undone",
|
|
523
|
-
cells: size,
|
|
524
|
-
structural,
|
|
525
|
-
where: savesTo,
|
|
526
|
-
durationMs,
|
|
527
|
-
}
|
|
528
|
-
: {
|
|
529
|
-
type: "dashboard.save_undone",
|
|
530
|
-
tiles: size,
|
|
531
|
-
structural,
|
|
532
|
-
where: savesTo,
|
|
533
|
-
durationMs,
|
|
534
|
-
},
|
|
535
|
-
),
|
|
536
|
-
undoRefused: (reason) =>
|
|
537
|
-
onEvent?.({
|
|
538
|
-
type: notebook
|
|
539
|
-
? "notebook.save_undo_refused"
|
|
540
|
-
: "dashboard.save_undo_refused",
|
|
541
|
-
reason,
|
|
542
|
-
}),
|
|
543
|
-
},
|
|
355
|
+
notebook,
|
|
356
|
+
savesTo,
|
|
357
|
+
onEvent,
|
|
358
|
+
}),
|
|
544
359
|
});
|
|
545
360
|
|
|
546
|
-
/** A tile from the picker: on the extension of its source, or a new one. */
|
|
547
|
-
const addTile = (tile: NewTile) => {
|
|
548
|
-
setAddingTile(false);
|
|
549
|
-
editor.update((draft) => {
|
|
550
|
-
let extension = draft.sources.find((s) => s.base === tile.base);
|
|
551
|
-
if (!extension) {
|
|
552
|
-
// A name of the file's own: the base's, suffixed, since an
|
|
553
|
-
// extension cannot share its base's name.
|
|
554
|
-
const taken = new Set(draft.sources.map((s) => s.name));
|
|
555
|
-
let name = `${tile.base}_tiles`;
|
|
556
|
-
for (let n = 2; taken.has(name); n++)
|
|
557
|
-
name = `${tile.base}_tiles_${n}`;
|
|
558
|
-
extension = { name, base: tile.base };
|
|
559
|
-
draft.sources.push(extension);
|
|
560
|
-
}
|
|
561
|
-
// The view's name in the extension: the base view's, suffixed,
|
|
562
|
-
// because an extension inherits its base's views and cannot redeclare
|
|
563
|
-
// one under the same name; then kept distinct from its siblings.
|
|
564
|
-
const used = new Set(
|
|
565
|
-
draft.tiles
|
|
566
|
-
.filter(isQueryTile)
|
|
567
|
-
.filter((t) => t.source === extension!.name)
|
|
568
|
-
.map((t) => t.name),
|
|
569
|
-
);
|
|
570
|
-
let name = `${tile.view}_tile`;
|
|
571
|
-
for (let n = 2; used.has(name); n++) name = `${tile.view}_tile_${n}`;
|
|
572
|
-
draft.tiles.splice(insertAt ?? draft.tiles.length, 0, {
|
|
573
|
-
name,
|
|
574
|
-
source: extension.name,
|
|
575
|
-
declaration: { kind: "reference", from: tile.view },
|
|
576
|
-
...(notebook ? {} : { colspan: tile.colspan }),
|
|
577
|
-
...(tile.label ? { label: tile.label } : {}),
|
|
578
|
-
...(tile.chart ? { chart: tile.chart } : {}),
|
|
579
|
-
...(tile.chartCarried ? { chartCarried: tile.chartCarried } : {}),
|
|
580
|
-
});
|
|
581
|
-
});
|
|
582
|
-
setSelected(insertAt ?? editor.document.tiles.length);
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
/** An empty text tile at the end, named for the first free `text_N`. */
|
|
586
|
-
const addText = () => {
|
|
587
|
-
setAddingTile(false);
|
|
588
|
-
editor.update((draft) => {
|
|
589
|
-
const taken = new Set(
|
|
590
|
-
draft.tiles.filter(isTextTile).map((t) => t.name),
|
|
591
|
-
);
|
|
592
|
-
let n = 1;
|
|
593
|
-
while (taken.has(`text_${n}`)) n++;
|
|
594
|
-
draft.tiles.splice(insertAt ?? draft.tiles.length, 0, {
|
|
595
|
-
kind: "text",
|
|
596
|
-
name: `text_${n}`,
|
|
597
|
-
markdown: "",
|
|
598
|
-
...(notebook ? {} : { colspan: columns }),
|
|
599
|
-
});
|
|
600
|
-
});
|
|
601
|
-
setSelected(insertAt ?? editor.document.tiles.length);
|
|
602
|
-
};
|
|
603
|
-
|
|
604
|
-
/** Change one tile where it stands, found by key so a preview order cannot misdirect it. */
|
|
605
|
-
const editTile = (key: string, change: (tile: DashboardTile) => void) =>
|
|
606
|
-
editor.update((draft) => {
|
|
607
|
-
const tile = draft.tiles.find((each) => tileKey(each) === key);
|
|
608
|
-
if (tile) change(tile);
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
/** A query tile's title and subtitle as fields on the tile, unless the model owns them. */
|
|
612
|
-
const headingOf = (
|
|
613
|
-
tile: QueryTile,
|
|
614
|
-
fallback: string,
|
|
615
|
-
): TileHeadingSlots | undefined => {
|
|
616
|
-
if (tile.declaration.kind === "inherited") return undefined;
|
|
617
|
-
const key = tileKey(tile);
|
|
618
|
-
const set = (field: "label" | "subtitle") => (next: string) =>
|
|
619
|
-
editTile(key, (each) => {
|
|
620
|
-
if (!isQueryTile(each)) return;
|
|
621
|
-
if (next === "") delete each[field];
|
|
622
|
-
else each[field] = next;
|
|
623
|
-
});
|
|
624
|
-
return {
|
|
625
|
-
title: (
|
|
626
|
-
<InlineText
|
|
627
|
-
value={tile.label ?? ""}
|
|
628
|
-
placeholder={fallback}
|
|
629
|
-
ariaLabel="Tile title"
|
|
630
|
-
onCommit={set("label")}
|
|
631
|
-
/>
|
|
632
|
-
),
|
|
633
|
-
subtitle: (
|
|
634
|
-
<InlineText
|
|
635
|
-
value={tile.subtitle ?? ""}
|
|
636
|
-
placeholder="Add a subtitle"
|
|
637
|
-
ariaLabel="Tile subtitle"
|
|
638
|
-
faintWhenEmpty
|
|
639
|
-
onCommit={set("subtitle")}
|
|
640
|
-
/>
|
|
641
|
-
),
|
|
642
|
-
};
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
const removeTile = (index: number) => {
|
|
646
|
-
setMenu(undefined);
|
|
647
|
-
setSelected(undefined);
|
|
648
|
-
editor.update((draft) => {
|
|
649
|
-
draft.tiles.splice(index, 1);
|
|
650
|
-
});
|
|
651
|
-
};
|
|
652
|
-
|
|
653
|
-
/** The filter window's result: bind, and declare when it is new or retagged. */
|
|
654
|
-
const applyFilter = (
|
|
655
|
-
given: string,
|
|
656
|
-
rows: MappingRow[],
|
|
657
|
-
declare?: LocalGiven,
|
|
658
|
-
) => {
|
|
659
|
-
setFilterDialog(undefined);
|
|
660
|
-
// One history entry for the whole filter, however many tiles it touches.
|
|
661
|
-
editor.update((draft) => {
|
|
662
|
-
if (declare) declareControl(draft, declare);
|
|
663
|
-
applyMapping(draft, given, rows);
|
|
664
|
-
});
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
/** Take a control off the dashboard: its declaration, if ours, and every binding. */
|
|
668
|
-
const dropControl = (given: string) => {
|
|
669
|
-
setFilterDialog(undefined);
|
|
670
|
-
editor.update((draft) => removeControl(draft, given));
|
|
671
|
-
};
|
|
672
|
-
|
|
673
|
-
// What the grid lays out: the document, except mid-gesture, where it is
|
|
674
|
-
// the preview — the tiles in their previewed order. So the row reflows under
|
|
675
|
-
// the pointer exactly as it will once the edit lands.
|
|
676
|
-
const shown = preview ?? editor.document.tiles;
|
|
677
|
-
// And, while a drag is live, the empty end of every row as a drop target.
|
|
678
|
-
// Not otherwise: a gap is only a place to land while something is in hand.
|
|
679
361
|
const empty = editor.document.tiles.length === 0;
|
|
680
|
-
|
|
362
|
+
// The builder's actions: on the title's line, at the right, above the
|
|
363
|
+
// description.
|
|
364
|
+
const actions = (
|
|
365
|
+
<BuilderToolbar
|
|
366
|
+
{...session.toolbarProps}
|
|
367
|
+
{...(toolbar ? { actions: toolbar } : {})}
|
|
368
|
+
{...(catalog ? { onAddTile: () => openAdd() } : {})}
|
|
369
|
+
savesTo={savesTo}
|
|
370
|
+
{...(saveLabel ? { saveLabel } : {})}
|
|
371
|
+
/>
|
|
372
|
+
);
|
|
681
373
|
return (
|
|
682
374
|
// The padding is for the SELECTION RING. An outline is painted outside
|
|
683
375
|
// the element's border box, so a selected tile's ring lands beyond the
|
|
@@ -688,99 +380,77 @@ export function DashboardBuilder({
|
|
|
688
380
|
// grid alone, so the header, the control row and the tiles all inset
|
|
689
381
|
// together and stay aligned with each other. 4px = the ring's 2px offset
|
|
690
382
|
// plus its 2px width.
|
|
691
|
-
// The bar carries its own gap to what it sits over, so the surface adds
|
|
692
|
-
// none between the two.
|
|
693
383
|
<OpenDraftContext.Provider value={openDraft}>
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
{...session.toolbarProps}
|
|
699
|
-
{...(toolbar ? { actions: toolbar } : {})}
|
|
700
|
-
{...(catalog ? { onAddTile: () => openAdd() } : {})}
|
|
701
|
-
onSettings={setSettingsAnchor}
|
|
702
|
-
savesTo={savesTo}
|
|
703
|
-
{...(saveLabel ? { saveLabel } : {})}
|
|
704
|
-
/>
|
|
705
|
-
|
|
384
|
+
{/* Pulled out by the ring's inset, so the content inside it lands on
|
|
385
|
+
the same edges as the reader's view: editing and reading are the same
|
|
386
|
+
page, and the margins must not move between them. */}
|
|
387
|
+
<Stack sx={{ gap: 0, mx: `-${SELECTION_RING_PX}px` }}>
|
|
706
388
|
{/* The ring's inset, minus the top: nothing at the top of this stack
|
|
707
|
-
can be selected (the prose and the control row are not tiles)
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
389
|
+
can be selected (the prose and the control row are not tiles). */}
|
|
390
|
+
<Stack
|
|
391
|
+
sx={{
|
|
392
|
+
gap: 2,
|
|
393
|
+
px: `${SELECTION_RING_PX}px`,
|
|
394
|
+
pb: `${SELECTION_RING_PX}px`,
|
|
395
|
+
}}
|
|
396
|
+
>
|
|
711
397
|
{editor.pendingOpen && (
|
|
712
398
|
<Alert severity="info">
|
|
713
399
|
This notebook is in the cell format. Saving rewrites it as
|
|
714
400
|
a layout notebook, and a named query run once becomes that
|
|
715
|
-
tile's view
|
|
401
|
+
tile's view.
|
|
716
402
|
</Alert>
|
|
717
403
|
)}
|
|
718
|
-
<
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
notebook ? "Notebook title" : "Dashboard title"
|
|
728
|
-
}
|
|
729
|
-
onCommit={(next) =>
|
|
730
|
-
editor.update((draft) => {
|
|
731
|
-
draft.title = next;
|
|
732
|
-
})
|
|
733
|
-
}
|
|
734
|
-
/>
|
|
735
|
-
</Typography>
|
|
736
|
-
<InlineMarkdown
|
|
737
|
-
variant="caption"
|
|
738
|
-
markdown={editor.document.description ?? ""}
|
|
739
|
-
placeholder="Add a description"
|
|
740
|
-
onCommit={(next) =>
|
|
741
|
-
editor.update((draft) => {
|
|
742
|
-
if (next.trim() === "") delete draft.description;
|
|
743
|
-
else draft.description = next;
|
|
744
|
-
})
|
|
745
|
-
}
|
|
746
|
-
/>
|
|
747
|
-
</Box>
|
|
404
|
+
<BuilderHeader
|
|
405
|
+
editor={editor}
|
|
406
|
+
notebook={notebook}
|
|
407
|
+
documentSlug={documentSlug}
|
|
408
|
+
chrome={chrome}
|
|
409
|
+
actions={actions}
|
|
410
|
+
descriptionSelected={descriptionSelected}
|
|
411
|
+
selectDescription={selectDescription}
|
|
412
|
+
/>
|
|
748
413
|
|
|
749
414
|
{empty ? (
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
415
|
+
<>
|
|
416
|
+
<Stack
|
|
417
|
+
sx={{
|
|
418
|
+
alignItems: "flex-start",
|
|
419
|
+
gap: 1,
|
|
420
|
+
py: 3,
|
|
421
|
+
px: 2,
|
|
422
|
+
border: 1,
|
|
423
|
+
borderStyle: "dashed",
|
|
424
|
+
borderColor: "divider",
|
|
425
|
+
borderRadius: 1,
|
|
426
|
+
}}
|
|
427
|
+
>
|
|
428
|
+
<Typography variant="body2">
|
|
429
|
+
This {notebook ? "notebook" : "dashboard"} is not
|
|
430
|
+
served until it has a tile.
|
|
431
|
+
</Typography>
|
|
432
|
+
{catalog && (
|
|
433
|
+
<Button
|
|
434
|
+
size="small"
|
|
435
|
+
startIcon={<AddIcon />}
|
|
436
|
+
onClick={() => openAdd()}
|
|
437
|
+
>
|
|
438
|
+
Add tile
|
|
439
|
+
</Button>
|
|
440
|
+
)}
|
|
441
|
+
</Stack>
|
|
442
|
+
</>
|
|
776
443
|
) : (
|
|
777
444
|
<FilterStrip
|
|
778
|
-
controls={controlList}
|
|
445
|
+
controls={bindings.controlList}
|
|
779
446
|
tileCount={editor.document.tiles.length}
|
|
780
|
-
unknownFieldsOf={unknownFieldsOf}
|
|
447
|
+
unknownFieldsOf={bindings.unknownFieldsOf}
|
|
781
448
|
onEdit={(control) => setFilterDialog({ control })}
|
|
782
449
|
onAdd={() => setFilterDialog({})}
|
|
783
|
-
|
|
450
|
+
{...(addFilterDisabledReason
|
|
451
|
+
? { addDisabledReason: addFilterDisabledReason }
|
|
452
|
+
: {})}
|
|
453
|
+
onRemove={bindings.dropControl}
|
|
784
454
|
>
|
|
785
455
|
{controls}
|
|
786
456
|
</FilterStrip>
|
|
@@ -792,186 +462,39 @@ export function DashboardBuilder({
|
|
|
792
462
|
<Alert severity="warning">{editor.error}</Alert>
|
|
793
463
|
)}
|
|
794
464
|
|
|
795
|
-
<
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
>
|
|
801
|
-
<Box ref={gridBox} sx={{ position: "relative" }}>
|
|
802
|
-
{!notebook && dragging && <GridGuides columns={columns} />}
|
|
803
|
-
|
|
804
|
-
<DashboardGrid
|
|
805
|
-
tiles={entries}
|
|
806
|
-
columns={columns}
|
|
807
|
-
keyOf={(entry) =>
|
|
808
|
-
entry.kind === "gap"
|
|
809
|
-
? gapId(entry.after)
|
|
810
|
-
: tileKey(entry.tile)
|
|
811
|
-
}
|
|
812
|
-
renderTile={(entry) => {
|
|
813
|
-
if (entry.kind === "gap")
|
|
814
|
-
return <GapTarget after={entry.after} />;
|
|
815
|
-
const { tile: each, index } = entry;
|
|
816
|
-
return (
|
|
817
|
-
<TileFrame
|
|
818
|
-
tile={each}
|
|
819
|
-
index={index}
|
|
820
|
-
selected={index === selected}
|
|
821
|
-
flash={tileKey(each) === flash}
|
|
822
|
-
menuOpen={menu?.index === index}
|
|
823
|
-
{...(notebook && catalog
|
|
824
|
-
? {
|
|
825
|
-
onInsertAfter: () =>
|
|
826
|
-
openAdd(index + 1),
|
|
827
|
-
}
|
|
828
|
-
: {})}
|
|
829
|
-
onSelect={() => setSelected(index)}
|
|
830
|
-
onOpenMenu={(anchor) => {
|
|
831
|
-
setSelected(index);
|
|
832
|
-
setMenu({ anchor, index });
|
|
833
|
-
}}
|
|
834
|
-
>
|
|
835
|
-
{isTextTile(each) ? (
|
|
836
|
-
<TextTileBody
|
|
837
|
-
tile={each}
|
|
838
|
-
onChange={(markdown) =>
|
|
839
|
-
editTile(tileKey(each), (tile) => {
|
|
840
|
-
if (isTextTile(tile))
|
|
841
|
-
tile.markdown = markdown;
|
|
842
|
-
})
|
|
843
|
-
}
|
|
844
|
-
/>
|
|
845
|
-
) : renderTile && !editor.pendingOpen ? (
|
|
846
|
-
// Until the conversion is saved the package has none of its views to run.
|
|
847
|
-
renderTile(
|
|
848
|
-
each,
|
|
849
|
-
headingOf(
|
|
850
|
-
each,
|
|
851
|
-
tileTitle(
|
|
852
|
-
`${each.source} -> ${each.name}`,
|
|
853
|
-
),
|
|
854
|
-
),
|
|
855
|
-
)
|
|
856
|
-
) : (
|
|
857
|
-
<TilePlaceholder
|
|
858
|
-
tile={each}
|
|
859
|
-
heading={headingOf(each, each.name)}
|
|
860
|
-
{...(editor.pendingOpen
|
|
861
|
-
? {
|
|
862
|
-
note: "Preview appears after you Save",
|
|
863
|
-
}
|
|
864
|
-
: {})}
|
|
865
|
-
/>
|
|
866
|
-
)}
|
|
867
|
-
</TileFrame>
|
|
868
|
-
);
|
|
869
|
-
}}
|
|
870
|
-
/>
|
|
871
|
-
</Box>
|
|
872
|
-
</DragDropProvider>
|
|
873
|
-
{notebook && catalog && !empty && (
|
|
874
|
-
<Button
|
|
875
|
-
size="small"
|
|
876
|
-
startIcon={<AddIcon />}
|
|
877
|
-
aria-label="Add tile at the end"
|
|
878
|
-
onClick={() => openAdd()}
|
|
879
|
-
sx={{ alignSelf: "center" }}
|
|
880
|
-
>
|
|
881
|
-
Add tile
|
|
882
|
-
</Button>
|
|
883
|
-
)}
|
|
884
|
-
<FilterDialog
|
|
885
|
-
open={filterDialog !== undefined}
|
|
886
|
-
document={editor.document}
|
|
887
|
-
{...(filterDialog?.control
|
|
888
|
-
? { control: filterDialog.control }
|
|
889
|
-
: {})}
|
|
890
|
-
available={available}
|
|
891
|
-
{...(catalog ? { fieldsFor } : {})}
|
|
892
|
-
onClose={() => setFilterDialog(undefined)}
|
|
893
|
-
onApply={applyFilter}
|
|
894
|
-
onRemove={dropControl}
|
|
895
|
-
/>
|
|
896
|
-
<TileMenu
|
|
897
|
-
anchor={menu?.anchor ?? null}
|
|
898
|
-
tile={
|
|
899
|
-
menu === undefined
|
|
900
|
-
? undefined
|
|
901
|
-
: editor.document.tiles[menu.index]
|
|
902
|
-
}
|
|
903
|
-
onClose={() => setMenu(undefined)}
|
|
904
|
-
onCommit={(next) => {
|
|
905
|
-
const at = menu?.index;
|
|
906
|
-
if (at === undefined) return;
|
|
907
|
-
editor.update((draft) => {
|
|
908
|
-
draft.tiles[at] = next;
|
|
909
|
-
});
|
|
910
|
-
}}
|
|
911
|
-
onRemove={() => {
|
|
912
|
-
if (menu !== undefined) removeTile(menu.index);
|
|
913
|
-
}}
|
|
914
|
-
{...(editor.document.tiles.length === 1 &&
|
|
915
|
-
editor.saved.tiles.length > 0
|
|
916
|
-
? {
|
|
917
|
-
removeBlocked:
|
|
918
|
-
"A saved dashboard needs at least one tile.",
|
|
919
|
-
}
|
|
920
|
-
: {})}
|
|
465
|
+
<BuilderGrid
|
|
466
|
+
editor={editor}
|
|
467
|
+
reorder={reorder}
|
|
468
|
+
resizing={resizing}
|
|
469
|
+
gridBox={gridBox}
|
|
921
470
|
columns={columns}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
471
|
+
notebook={notebook}
|
|
472
|
+
chrome={chrome}
|
|
473
|
+
canAdd={!!catalog}
|
|
474
|
+
selected={selected}
|
|
475
|
+
flash={flash}
|
|
476
|
+
menuIndex={menu?.index}
|
|
477
|
+
onSelect={selectTile}
|
|
478
|
+
onOpenMenu={(anchor, index) => {
|
|
479
|
+
selectTile(index);
|
|
480
|
+
tiles.setMenu({ anchor, index });
|
|
925
481
|
}}
|
|
482
|
+
openAdd={openAdd}
|
|
483
|
+
editTile={tiles.editTile}
|
|
484
|
+
{...(renderTile ? { renderTile } : {})}
|
|
926
485
|
/>
|
|
927
|
-
<
|
|
928
|
-
|
|
929
|
-
document={editor.document}
|
|
930
|
-
source={editor.document.sources.find(
|
|
931
|
-
(s) => s.name === drillSource,
|
|
932
|
-
)}
|
|
933
|
-
givenNames={controlList.map((c) => c.name)}
|
|
934
|
-
dashboards={dashboards ?? []}
|
|
935
|
-
onClose={() => setDrillSource(undefined)}
|
|
936
|
-
onApply={(drills) =>
|
|
937
|
-
editor.update((draft) => {
|
|
938
|
-
const kept = (draft.drills ?? []).filter(
|
|
939
|
-
(d) => d.source !== drillSource,
|
|
940
|
-
);
|
|
941
|
-
const next = [...kept, ...drills];
|
|
942
|
-
if (next.length === 0) delete draft.drills;
|
|
943
|
-
else draft.drills = next;
|
|
944
|
-
})
|
|
945
|
-
}
|
|
946
|
-
/>
|
|
947
|
-
<SettingsPopover
|
|
948
|
-
anchor={settingsAnchor}
|
|
949
|
-
settings={settings}
|
|
950
|
-
catalog={catalog}
|
|
951
|
-
inUse={sourcesInUse}
|
|
952
|
-
onClose={() => setSettingsAnchor(null)}
|
|
953
|
-
onCommit={(next) =>
|
|
954
|
-
editor.update((draft) => {
|
|
955
|
-
if (next.kind === undefined) delete draft.kind;
|
|
956
|
-
else draft.kind = next.kind;
|
|
957
|
-
if (next.columns === undefined) delete draft.columns;
|
|
958
|
-
else draft.columns = next.columns;
|
|
959
|
-
if (next.autorun === undefined) delete draft.autorun;
|
|
960
|
-
else draft.autorun = next.autorun;
|
|
961
|
-
draft.imports = next.imports;
|
|
962
|
-
})
|
|
963
|
-
}
|
|
964
|
-
/>
|
|
965
|
-
<AddTileDialog
|
|
966
|
-
open={addingTile}
|
|
967
|
-
document={editor.document}
|
|
486
|
+
<BuilderDialogs
|
|
487
|
+
editor={editor}
|
|
968
488
|
catalog={catalog}
|
|
969
489
|
columns={columns}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
490
|
+
dashboards={dashboards}
|
|
491
|
+
bindings={bindings}
|
|
492
|
+
tiles={tiles}
|
|
493
|
+
drillSource={drillSource}
|
|
494
|
+
setDrillSource={setDrillSource}
|
|
495
|
+
confirmConversion={confirmConversion}
|
|
496
|
+
exitDialog={session.exitGuard.dialog}
|
|
973
497
|
/>
|
|
974
|
-
<UnsavedChangesDialog {...session.exitGuard.dialog} />
|
|
975
498
|
</Stack>
|
|
976
499
|
</Stack>
|
|
977
500
|
</OpenDraftContext.Provider>
|