@malloy-publisher/sdk 0.9.1 → 0.9.2
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/{Dashboard-H1kJlDFo.es.js → DashboardTile-BFcxdv7R.es.js} +15918 -17760
- package/dist/DashboardTile-sg8LjUk8.cjs.js +137 -0
- package/dist/RenderedResult-B48wAjM8.cjs.js +141 -0
- package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-CBLHr32C.es.js} +193 -183
- package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-DCV8BUWD.es.js} +529 -521
- package/dist/ServerProvider-HRqT3w1C.cjs.js +1 -0
- package/dist/builder/index.cjs.js +146 -58
- package/dist/builder/index.es.js +9076 -6479
- package/dist/builder-entry.d.ts +4 -0
- package/dist/client/api.d.ts +77 -47
- package/dist/client/configuration.d.ts +1 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.es.js +84 -82
- package/dist/components/Dashboard/Dashboard.d.ts +8 -15
- package/dist/components/Dashboard/DashboardGrid.d.ts +23 -6
- package/dist/components/Dashboard/DashboardTile.d.ts +10 -1
- package/dist/components/Dashboard/DashboardView.d.ts +36 -0
- package/dist/components/Dashboard/TileCard.d.ts +15 -4
- package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
- package/dist/components/Dashboard/index.d.ts +3 -0
- package/dist/components/Dashboard/telemetry.d.ts +15 -3
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -1
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +16 -5
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +29 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +48 -21
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +17 -4
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +2 -10
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +3 -1
- package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
- package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
- package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
- package/dist/components/DashboardBuilder/SaveNotice.d.ts +27 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +19 -7
- package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +7 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +14 -12
- package/dist/components/DashboardBuilder/TileMenu.d.ts +11 -3
- package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +4 -0
- package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
- package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
- package/dist/components/DashboardBuilder/controls.d.ts +2 -2
- package/dist/components/DashboardBuilder/document.d.ts +42 -26
- package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
- package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
- package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -5
- package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
- package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
- package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
- package/dist/components/DashboardBuilder/preview.d.ts +24 -4
- package/dist/components/DashboardBuilder/readDocument.d.ts +4 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +14 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +13 -13
- package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
- package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
- package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
- package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
- package/dist/components/DashboardBuilder/useBuilderSession.d.ts +89 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +17 -55
- package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
- package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
- package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
- package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
- package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
- package/dist/components/DocumentCreate/events.d.ts +10 -0
- package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
- package/dist/components/DocumentCreate/guards.d.ts +12 -0
- package/dist/components/DocumentCreate/index.d.ts +6 -0
- package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
- package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
- package/dist/components/NarrowEditGate.d.ts +8 -0
- package/dist/components/Notebook/Notebook.d.ts +1 -1
- package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
- package/dist/components/Package/Package.d.ts +1 -0
- package/dist/components/Package/documentLocation.d.ts +28 -0
- package/dist/components/Package/index.d.ts +4 -0
- package/dist/components/Package/useDocumentLocation.d.ts +12 -0
- package/dist/components/PackageSection.d.ts +2 -2
- package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
- package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
- package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
- package/dist/components/ServerProvider.d.ts +2 -1
- package/dist/components/UnsavedChangesDialog.d.ts +9 -0
- package/dist/components/given/GivensPanel.d.ts +2 -2
- package/dist/components/index.d.ts +2 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useNarrowScreen.d.ts +4 -0
- package/dist/hooks/useQueryResult.d.ts +2 -0
- package/dist/hooks/useSettled.d.ts +14 -0
- package/dist/index.cjs.js +23 -24
- package/dist/index.es.js +9714 -7072
- package/dist/text/index.cjs.js +1 -0
- package/dist/text/index.d.ts +2 -0
- package/dist/text/index.es.js +6 -0
- package/dist/text-entry-BJwltZiy.cjs.js +7 -0
- package/dist/text-entry-CbbBcZl8.es.js +196 -0
- package/dist/text-entry.d.ts +2 -0
- package/dist/utils/clock.d.ts +2 -0
- package/package.json +10 -1
- package/src/builder-entry.ts +35 -0
- package/src/components/Dashboard/Dashboard.tsx +27 -278
- package/src/components/Dashboard/DashboardGrid.tsx +68 -7
- package/src/components/Dashboard/DashboardTile.spec.tsx +24 -0
- package/src/components/Dashboard/DashboardTile.tsx +31 -4
- package/src/components/Dashboard/DashboardView.spec.tsx +212 -0
- package/src/components/Dashboard/DashboardView.tsx +352 -0
- package/src/components/Dashboard/RowsDialog.tsx +1 -1
- package/src/components/Dashboard/TileCard.tsx +44 -10
- package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
- package/src/components/Dashboard/TileFilterTag.tsx +78 -0
- package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
- package/src/components/Dashboard/index.ts +3 -0
- package/src/components/Dashboard/telemetry.ts +16 -5
- package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +137 -111
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +85 -27
- package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
- package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
- package/src/components/DashboardBuilder/ChartPicker.tsx +153 -0
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +192 -0
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +329 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +363 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +194 -0
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +157 -0
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +124 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +103 -78
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +177 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +610 -315
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +58 -8
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +191 -0
- package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +316 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +56 -10
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +5 -22
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +96 -14
- package/src/components/DashboardBuilder/DashboardEditor.tsx +482 -332
- package/src/components/DashboardBuilder/DiffDialog.spec.tsx +25 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +5 -24
- package/src/components/DashboardBuilder/DrillDialog.tsx +1 -1
- package/src/components/DashboardBuilder/FilterDialog.tsx +10 -3
- package/src/components/DashboardBuilder/FilterStrip.tsx +26 -4
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +184 -0
- package/src/components/DashboardBuilder/InlineText.tsx +106 -0
- package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
- package/src/components/DashboardBuilder/SaveNotice.tsx +113 -0
- package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +87 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +225 -67
- package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
- package/src/components/DashboardBuilder/TextTileBody.tsx +28 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +89 -115
- package/src/components/DashboardBuilder/TileMenu.tsx +168 -90
- package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
- package/src/components/DashboardBuilder/annotationText.ts +17 -0
- package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
- package/src/components/DashboardBuilder/artifactTagParity.spec.ts +41 -0
- package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +2 -0
- package/src/components/DashboardBuilder/catalog.ts +61 -21
- package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
- package/src/components/DashboardBuilder/changedTile.ts +28 -0
- package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
- package/src/components/DashboardBuilder/chartLine.ts +121 -0
- package/src/components/DashboardBuilder/controls.spec.ts +21 -10
- package/src/components/DashboardBuilder/controls.ts +22 -8
- package/src/components/DashboardBuilder/document.ts +53 -5
- package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
- package/src/components/DashboardBuilder/documentSession.ts +257 -0
- package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
- package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
- package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
- package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
- package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
- package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
- package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
- package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +48 -0
- package/src/components/DashboardBuilder/malloyText.ts +181 -27
- package/src/components/DashboardBuilder/malloyTree.ts +155 -7
- package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
- package/src/components/DashboardBuilder/newDashboard.ts +30 -3
- package/src/components/DashboardBuilder/openDraft.ts +52 -0
- package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
- package/src/components/DashboardBuilder/preview.spec.ts +159 -12
- package/src/components/DashboardBuilder/preview.ts +83 -9
- package/src/components/DashboardBuilder/readDocument.spec.ts +139 -27
- package/src/components/DashboardBuilder/readDocument.ts +130 -44
- package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
- package/src/components/DashboardBuilder/readForEditor.ts +47 -0
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
- package/src/components/DashboardBuilder/sortable.spec.ts +65 -0
- package/src/components/DashboardBuilder/sortable.tsx +2 -12
- package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
- package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
- package/src/components/DashboardBuilder/spliceDocument.ts +762 -130
- package/src/components/DashboardBuilder/spliceResult.ts +15 -0
- package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
- package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
- package/src/components/DashboardBuilder/tagParse.ts +103 -0
- package/src/components/DashboardBuilder/telemetry.ts +47 -0
- package/src/components/DashboardBuilder/testing/artifactTagParity.json +197 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
- package/src/components/DashboardBuilder/testing/inline.ts +25 -0
- package/src/components/DashboardBuilder/textTiles.spec.ts +718 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +335 -0
- package/src/components/DashboardBuilder/useBuilderSession.ts +292 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +65 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +36 -10
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
- package/src/components/DashboardBuilder/useDashboardEditor.ts +54 -181
- package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
- package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
- package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
- package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
- package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
- package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
- package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
- package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
- package/src/components/DocumentCreate/canRetry.ts +19 -0
- package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
- package/src/components/DocumentCreate/createDocument.ts +159 -0
- package/src/components/DocumentCreate/documentPath.ts +40 -0
- package/src/components/DocumentCreate/events.ts +15 -0
- package/src/components/DocumentCreate/exportedSources.ts +25 -0
- package/src/components/DocumentCreate/guards.ts +45 -0
- package/src/components/DocumentCreate/index.ts +27 -0
- package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
- package/src/components/DocumentCreate/newNotebook.ts +44 -0
- package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
- package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
- package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
- package/src/components/Model/ModelExplorer.spec.tsx +2 -2
- package/src/components/Model/SourcesExplorer.tsx +2 -4
- package/src/components/NarrowEditGate.spec.tsx +73 -0
- package/src/components/NarrowEditGate.tsx +29 -0
- package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
- package/src/components/Notebook/Notebook.tsx +66 -27
- package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
- package/src/components/Package/NewDocumentDialog.tsx +401 -0
- package/src/components/Package/Package.artifacts.spec.tsx +190 -0
- package/src/components/Package/Package.create.spec.tsx +380 -0
- package/src/components/Package/Package.notebooks.spec.tsx +18 -0
- package/src/components/Package/Package.tsx +366 -171
- package/src/components/Package/documentLocation.spec.ts +81 -0
- package/src/components/Package/documentLocation.ts +55 -0
- package/src/components/Package/index.ts +13 -0
- package/src/components/Package/useDocumentLocation.ts +59 -0
- package/src/components/PackageSection.tsx +2 -2
- package/src/components/RenderedResult/RenderedResult.tsx +18 -1
- package/src/components/RenderedResult/ResultContainer.tsx +44 -11
- package/src/components/RenderedResult/ResultPanel.tsx +4 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
- package/src/components/RenderedResult/resultSizing.ts +14 -3
- package/src/components/ServerProvider.tsx +2 -1
- package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
- package/src/components/UnsavedChangesDialog.tsx +49 -0
- package/src/components/given/GivensPanel.spec.tsx +6 -6
- package/src/components/given/GivensPanel.tsx +3 -3
- package/src/components/index.ts +2 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useNarrowScreen.ts +21 -0
- package/src/hooks/useQueryResult.ts +16 -0
- package/src/hooks/useSettled.spec.ts +41 -0
- package/src/hooks/useSettled.ts +27 -0
- package/src/mainEntry.spec.ts +145 -0
- package/src/text-entry.ts +12 -0
- package/src/textEntry.spec.ts +118 -0
- package/src/utils/clock.spec.ts +12 -0
- package/src/utils/clock.ts +6 -0
- package/vite.config.ts +4 -0
- package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
- package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
- package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
- package/dist/components/DashboardBuilder/useTileResize.d.ts +0 -29
- package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +0 -121
- package/src/components/DashboardBuilder/useTileResize.ts +0 -110
- package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
- package/src/components/Package/NewDashboardDialog.tsx +0 -265
|
@@ -1,42 +1,53 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import CheckIcon from "@mui/icons-material/Check";
|
|
5
4
|
import { Alert, Box, Button, Stack, Typography } from "@mui/material";
|
|
6
5
|
import { useQueryClient } from "@tanstack/react-query";
|
|
7
6
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
|
+
import type { DashboardManifest, Given } from "../../client";
|
|
8
|
+
import { modelResultsKey } from "../../hooks/useQueryResult";
|
|
8
9
|
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
9
10
|
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
10
11
|
import { DashboardTile, tileTitle } from "../Dashboard/DashboardTile";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from "../Dashboard/telemetry";
|
|
12
|
+
import { tileIgnoredFilterLabels } from "../Dashboard/TileFilterTag";
|
|
13
|
+
import type { BuilderEvent } from "./telemetry";
|
|
14
|
+
import { now } from "../../utils/clock";
|
|
15
|
+
import { encodeResourceUri } from "../../utils/formatting";
|
|
16
16
|
import { useDocumentControls } from "../../hooks/useDocumentControls";
|
|
17
|
-
import { parseResourceUri } from "../../utils/formatting";
|
|
18
17
|
import {
|
|
19
18
|
isDocumentNotFound,
|
|
20
19
|
useOptionalDocumentStorage,
|
|
21
|
-
type DocumentLocator,
|
|
22
20
|
type Workspace,
|
|
23
21
|
} from "../DocumentStorage";
|
|
24
22
|
import { GivensPanel } from "../given";
|
|
25
|
-
import { SecondaryButton } from "../buttons";
|
|
26
23
|
import { DashboardBar } from "../Dashboard/DashboardBar";
|
|
24
|
+
import type { TileHeadingSlots } from "../Dashboard/TileCard";
|
|
27
25
|
import { Loading } from "../Loading";
|
|
28
26
|
import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
|
|
29
27
|
import { useServer } from "../ServerProvider";
|
|
30
28
|
import {
|
|
31
29
|
buildCatalog,
|
|
30
|
+
isDashboardModel,
|
|
32
31
|
visibleToDashboard,
|
|
33
32
|
type PackageCatalog,
|
|
34
33
|
} from "./catalog";
|
|
34
|
+
import { locatorFor } from "../DocumentCreate/documentPath";
|
|
35
35
|
import { DashboardBuilder } from "./DashboardBuilder";
|
|
36
|
-
import type { DashboardDocument } from "./document";
|
|
37
|
-
import { previewGivens, previewTileQuery } from "./preview";
|
|
38
|
-
import {
|
|
39
|
-
|
|
36
|
+
import type { DashboardDocument, DocumentKind, QueryTile } from "./document";
|
|
37
|
+
import { previewGivens, previewTileQuery, tileExpressionKey } from "./preview";
|
|
38
|
+
import {
|
|
39
|
+
chooseWorkspace,
|
|
40
|
+
expectedHashFor,
|
|
41
|
+
resolveEditorTarget,
|
|
42
|
+
saveCaption,
|
|
43
|
+
saveTarget,
|
|
44
|
+
storageErrorMessage,
|
|
45
|
+
withWorkspace,
|
|
46
|
+
writePackageFile,
|
|
47
|
+
type SavesTo,
|
|
48
|
+
} from "./documentSession";
|
|
49
|
+
import { readForEditor } from "./readForEditor";
|
|
50
|
+
import type { SaveContext, SaveHandler } from "./useDocumentEditor";
|
|
40
51
|
|
|
41
52
|
/**
|
|
42
53
|
* The builder, opened on a package dashboard, with everything a host has to
|
|
@@ -75,13 +86,25 @@ export type DashboardEditorProps = (
|
|
|
75
86
|
dashboardName: string;
|
|
76
87
|
}
|
|
77
88
|
) & {
|
|
78
|
-
/** Leave the editor:
|
|
89
|
+
/** Leave the editor: its "Close", which asks first when edits are unsaved. Absent, no such button. */
|
|
79
90
|
onExit?: () => void;
|
|
80
91
|
/**
|
|
81
92
|
* What the editor does — opened, saved, refused — for the host to log or
|
|
82
|
-
* count; see `DashboardEvent`.
|
|
93
|
+
* count; see `DashboardEvent`. A notebook reports `NotebookEvent`s instead.
|
|
94
|
+
*/
|
|
95
|
+
onEvent?: (event: BuilderEvent) => void;
|
|
96
|
+
/**
|
|
97
|
+
* What the document is to the host: its storage locator and event names.
|
|
98
|
+
* Default `dashboard`. A notebook is a dashboard with one column, and is
|
|
99
|
+
* read with the authoring flag and served through the notebook endpoint.
|
|
83
100
|
*/
|
|
84
|
-
|
|
101
|
+
kind?: DocumentKind;
|
|
102
|
+
/**
|
|
103
|
+
* The document's file within the package, when it is not where its kind
|
|
104
|
+
* puts a new one (`dashboards/<slug>.malloy`, `notebooks/<slug>.malloy`):
|
|
105
|
+
* the kind comes from the file's own tag, so a document may sit in either.
|
|
106
|
+
*/
|
|
107
|
+
path?: string;
|
|
85
108
|
/**
|
|
86
109
|
* Whether there are edits the record does not have, on every change and
|
|
87
110
|
* whenever the editor opens a document.
|
|
@@ -93,53 +116,30 @@ export type DashboardEditorProps = (
|
|
|
93
116
|
onDirtyChange?: (dirty: boolean) => void;
|
|
94
117
|
};
|
|
95
118
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
modelPath: string,
|
|
102
|
-
): DocumentLocator => ({
|
|
103
|
-
workspace,
|
|
104
|
-
type: "dashboard",
|
|
105
|
-
path: `${environmentName}/${packageName}/${modelPath}`,
|
|
106
|
-
});
|
|
119
|
+
const LEGACY_REFUSAL =
|
|
120
|
+
"a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` notebook under notebooks/ to edit it here.";
|
|
121
|
+
|
|
122
|
+
const WITHHELD_REFUSAL =
|
|
123
|
+
"the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";
|
|
107
124
|
|
|
108
125
|
export function DashboardEditor(props: DashboardEditorProps) {
|
|
109
|
-
const { onExit, onEvent, onDirtyChange } = props;
|
|
110
|
-
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (!("resourceUri" in props)) return undefined;
|
|
119
|
-
try {
|
|
120
|
-
return parseResourceUri(props.resourceUri);
|
|
121
|
-
} catch {
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
})();
|
|
125
|
-
const environmentName =
|
|
126
|
-
"resourceUri" in props
|
|
127
|
-
? (parsed?.environmentName ?? "")
|
|
128
|
-
: props.environmentName;
|
|
129
|
-
const packageName =
|
|
130
|
-
"resourceUri" in props ? (parsed?.packageName ?? "") : props.packageName;
|
|
126
|
+
const { onExit, onEvent, onDirtyChange, kind = "dashboard", path } = props;
|
|
127
|
+
const notebook = kind === "notebook";
|
|
128
|
+
// Degraded, not thrown, on a bad URI: a throw in a render body takes the host's whole tree down.
|
|
129
|
+
const {
|
|
130
|
+
environmentName,
|
|
131
|
+
packageName,
|
|
132
|
+
versionId,
|
|
133
|
+
namesBoth: uriNamesBoth,
|
|
134
|
+
} = resolveEditorTarget(props);
|
|
131
135
|
const dashboardName =
|
|
132
136
|
"resourceUri" in props ? props.dashboard : props.dashboardName;
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const uriNamesBoth =
|
|
138
|
-
"resourceUri" in props
|
|
139
|
-
? !!parsed?.environmentName && !!parsed?.packageName
|
|
140
|
-
: true;
|
|
137
|
+
const noun = notebook ? "notebook" : "dashboard";
|
|
138
|
+
const refusedEvent = notebook
|
|
139
|
+
? ("notebook.open_refused" as const)
|
|
140
|
+
: ("dashboard.open_refused" as const);
|
|
141
141
|
|
|
142
|
-
const { apiClients, mutable } = useServer();
|
|
142
|
+
const { apiClients, mutable, isLoadingStatus } = useServer();
|
|
143
143
|
const queryClient = useQueryClient();
|
|
144
144
|
// When the editor was asked for — or the reader chose what to open — so
|
|
145
145
|
// "opened" can say how long it took. Read through refs by the open effect,
|
|
@@ -150,7 +150,8 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
150
150
|
const onDirtyChangeRef = useRef(onDirtyChange);
|
|
151
151
|
onDirtyChangeRef.current = onDirtyChange;
|
|
152
152
|
const storage = useOptionalDocumentStorage()?.documentStorage;
|
|
153
|
-
const
|
|
153
|
+
const legacyFormat = notebook && /\.malloynb$/i.test(dashboardName);
|
|
154
|
+
const modelPath = path ?? `${kind}s/${dashboardName}.malloy`;
|
|
154
155
|
|
|
155
156
|
// The file as the package has it. `sourceText` rides on the compiled model.
|
|
156
157
|
const modelQuery = useQueryWithApiError({
|
|
@@ -160,15 +161,18 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
160
161
|
packageName,
|
|
161
162
|
modelPath,
|
|
162
163
|
versionId,
|
|
164
|
+
notebook,
|
|
163
165
|
],
|
|
166
|
+
// A curated package otherwise withholds the text of a notebook reading an off-surface source.
|
|
164
167
|
queryFn: () =>
|
|
165
168
|
apiClients.models.getModel(
|
|
166
169
|
environmentName,
|
|
167
170
|
packageName,
|
|
168
171
|
modelPath,
|
|
169
172
|
versionId,
|
|
173
|
+
notebook ? true : undefined,
|
|
170
174
|
),
|
|
171
|
-
enabled: uriNamesBoth,
|
|
175
|
+
enabled: uriNamesBoth && !legacyFormat,
|
|
172
176
|
});
|
|
173
177
|
const packageText = (
|
|
174
178
|
modelQuery.data?.data as { sourceText?: string } | undefined
|
|
@@ -198,18 +202,15 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
198
202
|
// Asking for writeable only would hide it and fall back to the
|
|
199
203
|
// package, which on a server that takes writes means publishing a
|
|
200
204
|
// deploy of the record over the record.
|
|
201
|
-
const
|
|
202
|
-
// The record when one declares itself, and otherwise the first
|
|
203
|
-
// writeable one, which is what the editor has always taken.
|
|
204
|
-
const chosen =
|
|
205
|
-
all.find((candidate) => candidate.authoritative) ??
|
|
206
|
-
all.find((candidate) => candidate.writeable);
|
|
205
|
+
const chosen = chooseWorkspace(await storage.listWorkspaces(false));
|
|
207
206
|
if (stale) return;
|
|
208
207
|
setWorkspace(chosen);
|
|
209
|
-
|
|
208
|
+
// Only a notebook's record is read: a copy beside the package is never offered back.
|
|
209
|
+
if (chosen !== undefined && (!notebook || chosen.authoritative)) {
|
|
210
210
|
const text = await storage
|
|
211
211
|
.getDocument(
|
|
212
|
-
|
|
212
|
+
locatorFor(
|
|
213
|
+
kind,
|
|
213
214
|
chosen.name,
|
|
214
215
|
environmentName,
|
|
215
216
|
packageName,
|
|
@@ -234,7 +235,7 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
234
235
|
return () => {
|
|
235
236
|
stale = true;
|
|
236
237
|
};
|
|
237
|
-
}, [storage, environmentName, packageName, modelPath]);
|
|
238
|
+
}, [storage, kind, notebook, environmentName, packageName, modelPath]);
|
|
238
239
|
|
|
239
240
|
// The host's copy is the record: the editor opens it, writes back to it,
|
|
240
241
|
// and never offers to "resume" it, because a record is not a pending edit.
|
|
@@ -251,10 +252,19 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
251
252
|
? draft !== undefined
|
|
252
253
|
: resume === true && draft !== undefined;
|
|
253
254
|
const [opened, setOpened] = useState<
|
|
254
|
-
| {
|
|
255
|
+
| {
|
|
256
|
+
source: string;
|
|
257
|
+
document: DashboardDocument;
|
|
258
|
+
conversion?: { from: string; to: string };
|
|
259
|
+
/** The package file when this opened, which a draft's save overwrites. */
|
|
260
|
+
packageText?: string;
|
|
261
|
+
generation: number;
|
|
262
|
+
}
|
|
255
263
|
| undefined
|
|
256
264
|
>(undefined);
|
|
257
|
-
const [openError, setOpenError] = useState<string | undefined>(
|
|
265
|
+
const [openError, setOpenError] = useState<string | undefined>(
|
|
266
|
+
legacyFormat ? LEGACY_REFUSAL : undefined,
|
|
267
|
+
);
|
|
258
268
|
// The package's hash after this editor's last write, as the server computed
|
|
259
269
|
// it: the base the next save is spliced against.
|
|
260
270
|
const savedHashRef = useRef<string | undefined>(undefined);
|
|
@@ -287,6 +297,8 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
287
297
|
// Whether the builder holds edits the record does not have, and the version
|
|
288
298
|
// being held back because of them.
|
|
289
299
|
const [dirty, setDirty] = useState(false);
|
|
300
|
+
// A save that can still be undone is held like an edit, until the next edit: remounting on a newer version would drop the offer silently.
|
|
301
|
+
const [undoOffered, setUndoOffered] = useState(false);
|
|
290
302
|
const [accepted, setAccepted] = useState<string | undefined>(undefined);
|
|
291
303
|
// The text on this channel the editor has already reckoned with: what it
|
|
292
304
|
// opened, and what it wrote. Compared against the CHANNEL rather than
|
|
@@ -300,7 +312,10 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
300
312
|
// save rather than the text the builder was opened with.
|
|
301
313
|
const current = opened?.source;
|
|
302
314
|
const holding =
|
|
303
|
-
incoming &&
|
|
315
|
+
incoming &&
|
|
316
|
+
(dirty || undoOffered) &&
|
|
317
|
+
current !== undefined &&
|
|
318
|
+
latest !== accepted;
|
|
304
319
|
const opening = holding ? current : incoming ? latest : (current ?? latest);
|
|
305
320
|
const held = holding ? latest : undefined;
|
|
306
321
|
|
|
@@ -325,46 +340,101 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
325
340
|
let stale = false;
|
|
326
341
|
const packageAtOpen = packageNowRef.current;
|
|
327
342
|
const latestAtOpen = latestRef.current;
|
|
328
|
-
void
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
343
|
+
void readForEditor(opening, modelPath)
|
|
344
|
+
.then((result) => {
|
|
345
|
+
if (stale) return;
|
|
346
|
+
if (result.ok === false) {
|
|
347
|
+
setOpenError(result.reason);
|
|
348
|
+
onEventRef.current?.({
|
|
349
|
+
type: refusedEvent,
|
|
350
|
+
reason: result.reason,
|
|
351
|
+
});
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
setOpenError(undefined);
|
|
355
|
+
// A different document is open, so what this editor wrote before is
|
|
356
|
+
// no longer the base anything is spliced against; the package file
|
|
357
|
+
// the reader is now answering for is the one current at this open.
|
|
358
|
+
savedHashRef.current = undefined;
|
|
359
|
+
packageBaseRef.current = packageAtOpen;
|
|
360
|
+
setWrote(undefined);
|
|
361
|
+
setAccepted(undefined);
|
|
362
|
+
setSeen(latestAtOpen);
|
|
363
|
+
setOpened((previous) => ({
|
|
364
|
+
source: opening,
|
|
365
|
+
document: result.document,
|
|
366
|
+
...(result.conversion ? { conversion: result.conversion } : {}),
|
|
367
|
+
...(packageAtOpen !== undefined
|
|
368
|
+
? { packageText: packageAtOpen }
|
|
369
|
+
: {}),
|
|
370
|
+
generation: (previous?.generation ?? 0) + 1,
|
|
371
|
+
}));
|
|
372
|
+
onEventRef.current?.(
|
|
373
|
+
notebook || result.document.kind === "notebook"
|
|
374
|
+
? {
|
|
375
|
+
type: "notebook.opened",
|
|
376
|
+
from:
|
|
377
|
+
fromRef.current === "package" ? "package" : "record",
|
|
378
|
+
cells: result.document.tiles.length,
|
|
379
|
+
durationMs: now() - startedAt.current,
|
|
380
|
+
}
|
|
381
|
+
: {
|
|
382
|
+
type: "dashboard.opened",
|
|
383
|
+
from: fromRef.current,
|
|
384
|
+
tiles: result.document.tiles.length,
|
|
385
|
+
durationMs: now() - startedAt.current,
|
|
386
|
+
},
|
|
387
|
+
);
|
|
388
|
+
})
|
|
389
|
+
.catch((error: unknown) => {
|
|
390
|
+
if (stale) return;
|
|
391
|
+
const reason = `Could not read the ${noun}: ${error instanceof Error ? error.message : String(error)}`;
|
|
334
392
|
setOpenError(reason);
|
|
335
|
-
onEventRef.current?.({ type:
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
setOpenError(undefined);
|
|
339
|
-
// A different document is open, so what this editor wrote before is
|
|
340
|
-
// no longer the base anything is spliced against; the package file
|
|
341
|
-
// the reader is now answering for is the one current at this open.
|
|
342
|
-
savedHashRef.current = undefined;
|
|
343
|
-
packageBaseRef.current = packageAtOpen;
|
|
344
|
-
setWrote(undefined);
|
|
345
|
-
setAccepted(undefined);
|
|
346
|
-
setSeen(latestAtOpen);
|
|
347
|
-
setOpened((previous) => ({
|
|
348
|
-
source: opening,
|
|
349
|
-
document: result.document,
|
|
350
|
-
generation: (previous?.generation ?? 0) + 1,
|
|
351
|
-
}));
|
|
352
|
-
onEventRef.current?.({
|
|
353
|
-
type: "dashboard.opened",
|
|
354
|
-
from: fromRef.current,
|
|
355
|
-
tiles: result.document.tiles.length,
|
|
356
|
-
durationMs: now() - startedAt.current,
|
|
393
|
+
onEventRef.current?.({ type: refusedEvent, reason });
|
|
357
394
|
});
|
|
358
|
-
});
|
|
359
395
|
return () => {
|
|
360
396
|
stale = true;
|
|
361
397
|
};
|
|
362
|
-
}, [
|
|
398
|
+
}, [
|
|
399
|
+
opening,
|
|
400
|
+
modelPath,
|
|
401
|
+
draftChecked,
|
|
402
|
+
blockedOnRecord,
|
|
403
|
+
notebook,
|
|
404
|
+
noun,
|
|
405
|
+
refusedEvent,
|
|
406
|
+
]);
|
|
407
|
+
|
|
408
|
+
useEffect(() => {
|
|
409
|
+
if (legacyFormat)
|
|
410
|
+
onEventRef.current?.({
|
|
411
|
+
type: "notebook.open_refused",
|
|
412
|
+
reason: LEGACY_REFUSAL,
|
|
413
|
+
});
|
|
414
|
+
}, [legacyFormat]);
|
|
415
|
+
|
|
416
|
+
const withheld =
|
|
417
|
+
notebook &&
|
|
418
|
+
!opened &&
|
|
419
|
+
draftChecked &&
|
|
420
|
+
!fromDraft &&
|
|
421
|
+
modelQuery.isSuccess &&
|
|
422
|
+
!modelQuery.isFetching &&
|
|
423
|
+
packageText === undefined;
|
|
424
|
+
useEffect(() => {
|
|
425
|
+
if (!withheld) return;
|
|
426
|
+
setOpenError(WITHHELD_REFUSAL);
|
|
427
|
+
onEventRef.current?.({
|
|
428
|
+
type: "notebook.open_refused",
|
|
429
|
+
reason: WITHHELD_REFUSAL,
|
|
430
|
+
});
|
|
431
|
+
}, [withheld]);
|
|
363
432
|
|
|
364
433
|
const locator =
|
|
365
434
|
workspace === undefined
|
|
366
435
|
? undefined
|
|
367
|
-
:
|
|
436
|
+
: locatorFor(
|
|
437
|
+
kind,
|
|
368
438
|
workspace.name,
|
|
369
439
|
environmentName,
|
|
370
440
|
packageName,
|
|
@@ -408,75 +478,82 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
408
478
|
// editing moves the fetch past that file, and a hash taken from it
|
|
409
479
|
// would match, be accepted, and overwrite the change the reader was
|
|
410
480
|
// just told about.
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
481
|
+
const expectedHash = await expectedHashFor(
|
|
482
|
+
savedHashRef.current,
|
|
483
|
+
packageBaseRef.current,
|
|
484
|
+
);
|
|
415
485
|
if (expectedHash === undefined)
|
|
416
486
|
throw new Error("The package file is still loading; try again.");
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
487
|
+
const modelKey = [
|
|
488
|
+
"dashboard-editor-model",
|
|
489
|
+
environmentName,
|
|
490
|
+
packageName,
|
|
491
|
+
modelPath,
|
|
492
|
+
versionId,
|
|
493
|
+
notebook,
|
|
494
|
+
];
|
|
495
|
+
await writePackageFile({
|
|
496
|
+
apiClients,
|
|
497
|
+
queryClient,
|
|
498
|
+
environmentName,
|
|
499
|
+
packageName,
|
|
500
|
+
modelPath,
|
|
501
|
+
source,
|
|
502
|
+
expectedHash,
|
|
503
|
+
// A refused write usually means the file moved: fetching it offers the reader that version instead of re-saving against a base the server keeps rejecting.
|
|
504
|
+
invalidateOnError: [modelKey],
|
|
505
|
+
afterWrite: async (contentHash) => {
|
|
506
|
+
setOpened((previous) => previous && { ...previous, source });
|
|
507
|
+
setWrote({ text: source, onFetch: fetchedAtRef.current });
|
|
508
|
+
setSeen(source);
|
|
509
|
+
savedHashRef.current = contentHash;
|
|
510
|
+
setSupersedeFailure(undefined);
|
|
511
|
+
if (storage && locator) {
|
|
512
|
+
try {
|
|
513
|
+
await storage.deleteDocument(locator);
|
|
514
|
+
setDraft(undefined);
|
|
515
|
+
setOffered(false);
|
|
516
|
+
} catch (error) {
|
|
517
|
+
// Only absence means the copy is gone; any other rejection leaves it there, so the state must keep saying so.
|
|
518
|
+
if (isDocumentNotFound(error)) {
|
|
519
|
+
setDraft(undefined);
|
|
520
|
+
setOffered(false);
|
|
521
|
+
} else setSupersedeFailure(storageErrorMessage(error));
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
// The package is what is open now even if the copy survived the supersede; reading the channel off a stale copy would put the builder back on the text this save replaced.
|
|
525
|
+
setResume(false);
|
|
526
|
+
},
|
|
527
|
+
invalidate: [
|
|
528
|
+
{ queryKey: modelKey, wait: true },
|
|
529
|
+
// A cached result is keyed on the query text, not the file, so a changed chart would otherwise be drawn from the old rows.
|
|
530
|
+
{
|
|
531
|
+
queryKey: modelResultsKey({
|
|
532
|
+
environmentName,
|
|
533
|
+
packageName,
|
|
534
|
+
versionId,
|
|
535
|
+
modelPath,
|
|
536
|
+
}),
|
|
537
|
+
},
|
|
538
|
+
{ queryKey: ["dashboard-editor-manifest"] },
|
|
539
|
+
{ queryKey: ["dashboards"] },
|
|
540
|
+
{ queryKey: ["dashboard"] },
|
|
541
|
+
// The notebook viewer keys its read on the resource URI.
|
|
542
|
+
...(notebook
|
|
543
|
+
? [
|
|
544
|
+
{
|
|
545
|
+
queryKey: [
|
|
546
|
+
encodeResourceUri({
|
|
547
|
+
environmentName,
|
|
548
|
+
packageName,
|
|
549
|
+
modelPath,
|
|
550
|
+
}),
|
|
551
|
+
],
|
|
552
|
+
},
|
|
553
|
+
]
|
|
554
|
+
: []),
|
|
472
555
|
],
|
|
473
556
|
});
|
|
474
|
-
for (const key of [
|
|
475
|
-
"dashboard-editor-manifest",
|
|
476
|
-
"dashboards",
|
|
477
|
-
"dashboard",
|
|
478
|
-
])
|
|
479
|
-
void queryClient.invalidateQueries({ queryKey: [key] });
|
|
480
557
|
},
|
|
481
558
|
[
|
|
482
559
|
apiClients,
|
|
@@ -484,53 +561,37 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
484
561
|
packageName,
|
|
485
562
|
modelPath,
|
|
486
563
|
versionId,
|
|
564
|
+
notebook,
|
|
487
565
|
storage,
|
|
488
566
|
locator,
|
|
489
567
|
queryClient,
|
|
490
568
|
],
|
|
491
569
|
);
|
|
492
|
-
// `authoritative` wins outright rather than breaking a tie: a host whose
|
|
493
|
-
// store is the record may well sit on a server that reports itself
|
|
494
|
-
// writable, and writing the package there would edit a deploy of the
|
|
495
|
-
// record instead of the record.
|
|
496
|
-
const savesTo = authoritative ? "host" : mutable ? "package" : "browser";
|
|
497
570
|
const canWriteWorkspace = workspace?.writeable === true;
|
|
498
|
-
//
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
571
|
+
// Unknown while `/status` loads, and a package write needs a yes.
|
|
572
|
+
const takesWrites = mutable === true;
|
|
573
|
+
const { savesTo, pinnedPackageSave, writer } = saveTarget({
|
|
574
|
+
authoritative,
|
|
575
|
+
mutable: takesWrites,
|
|
576
|
+
...(versionId !== undefined ? { versionId } : {}),
|
|
577
|
+
// A notebook reads back only the record, so a copy anywhere else would be a write nobody sees.
|
|
578
|
+
canStore:
|
|
579
|
+
!!storage &&
|
|
580
|
+
!!locator &&
|
|
581
|
+
canWriteWorkspace &&
|
|
582
|
+
(!notebook || authoritative),
|
|
583
|
+
readFailed: readFailure !== undefined,
|
|
584
|
+
});
|
|
585
|
+
const save =
|
|
586
|
+
writer === "storage"
|
|
508
587
|
? saveToStorage
|
|
509
|
-
:
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
: mutable
|
|
513
|
-
? saveToPackage
|
|
514
|
-
: storage && locator && canWriteWorkspace
|
|
515
|
-
? saveToStorage
|
|
516
|
-
: undefined;
|
|
517
|
-
// A copy that could not be read is not a copy that is not there. Saving on
|
|
518
|
-
// that belief is what rewinds the record, so Save is off until a reader can
|
|
519
|
-
// be told what actually happened.
|
|
520
|
-
const save = readFailure === undefined ? writer : undefined;
|
|
588
|
+
: writer === "package"
|
|
589
|
+
? saveToPackage
|
|
590
|
+
: undefined;
|
|
521
591
|
const workspaceName = workspace?.name;
|
|
522
592
|
const reportEvent = useCallback(
|
|
523
|
-
(event:
|
|
524
|
-
|
|
525
|
-
// package was not taken by one, and naming it there would say the
|
|
526
|
-
// record moved somewhere it did not.
|
|
527
|
-
onEventRef.current?.(
|
|
528
|
-
event.type === "dashboard.saved" &&
|
|
529
|
-
event.where !== "package" &&
|
|
530
|
-
workspaceName !== undefined
|
|
531
|
-
? { ...event, workspace: workspaceName }
|
|
532
|
-
: event,
|
|
533
|
-
);
|
|
593
|
+
(event: BuilderEvent) => {
|
|
594
|
+
onEventRef.current?.(withWorkspace(event, workspaceName));
|
|
534
595
|
},
|
|
535
596
|
[workspaceName],
|
|
536
597
|
);
|
|
@@ -551,30 +612,57 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
551
612
|
setAccepted(held);
|
|
552
613
|
};
|
|
553
614
|
|
|
615
|
+
const saveLabel =
|
|
616
|
+
savesTo === "host" && workspace?.description
|
|
617
|
+
? workspace.description
|
|
618
|
+
: undefined;
|
|
619
|
+
const caption =
|
|
620
|
+
!authoritative && mutable === undefined
|
|
621
|
+
? isLoadingStatus
|
|
622
|
+
? "Checking whether this server takes writes."
|
|
623
|
+
: "This server did not say whether it takes writes, so Save is off."
|
|
624
|
+
: saveCaption({
|
|
625
|
+
authoritative,
|
|
626
|
+
mutable: takesWrites,
|
|
627
|
+
pinnedPackageSave,
|
|
628
|
+
...(workspace ? { workspace } : {}),
|
|
629
|
+
...(readFailure !== undefined ? { readFailure } : {}),
|
|
630
|
+
...(versionId !== undefined ? { versionId } : {}),
|
|
631
|
+
});
|
|
632
|
+
// The description is already the Save caption, so the note does not repeat it.
|
|
633
|
+
const note = caption === saveLabel ? "" : caption;
|
|
634
|
+
|
|
554
635
|
// After every hook, so the hook order does not depend on the URI. Same
|
|
555
636
|
// reasoning as `Dashboard`'s own check.
|
|
556
637
|
if (!uriNamesBoth && "resourceUri" in props)
|
|
557
638
|
return (
|
|
558
639
|
<Alert severity="error" sx={{ m: 2 }}>
|
|
559
|
-
A
|
|
640
|
+
A {noun} resource URI must name an environment and a package.
|
|
560
641
|
Received: {props.resourceUri}
|
|
561
642
|
</Alert>
|
|
562
643
|
);
|
|
563
|
-
if (
|
|
644
|
+
if (openError)
|
|
645
|
+
return (
|
|
646
|
+
<Alert severity="error" sx={{ m: 2 }}>
|
|
647
|
+
This {noun} cannot be opened in the builder: {openError}
|
|
648
|
+
</Alert>
|
|
649
|
+
);
|
|
650
|
+
// Only before an open: after one, a failed refetch is a banner above the builder so unsaved edits survive it.
|
|
651
|
+
if (modelQuery.isError && !opened)
|
|
564
652
|
return (
|
|
565
653
|
<ApiErrorDisplay
|
|
566
654
|
error={modelQuery.error}
|
|
567
|
-
context=
|
|
655
|
+
context={`Opening the ${noun}`}
|
|
568
656
|
/>
|
|
569
657
|
);
|
|
570
|
-
if (!packageText || !draftChecked)
|
|
658
|
+
if (!opened && (!packageText || !draftChecked))
|
|
571
659
|
// The bar first, so the page it is opening into is already the right
|
|
572
660
|
// shape: the reader's view had a bar in this spot, and a spinner where
|
|
573
661
|
// the bar was made the switch look like a page reload.
|
|
574
662
|
return (
|
|
575
663
|
<Stack sx={{ gap: 2 }}>
|
|
576
664
|
<DashboardBar />
|
|
577
|
-
<Loading text=
|
|
665
|
+
<Loading text={`Opening the ${noun}…`} />
|
|
578
666
|
</Stack>
|
|
579
667
|
);
|
|
580
668
|
// Where the host's copy IS the document, a copy that could not be read
|
|
@@ -583,37 +671,40 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
583
671
|
if (blockedOnRecord)
|
|
584
672
|
return (
|
|
585
673
|
<Alert severity="error" sx={{ m: 2 }}>
|
|
586
|
-
This
|
|
674
|
+
This {noun} cannot be opened: {readFailure}
|
|
587
675
|
</Alert>
|
|
588
676
|
);
|
|
589
|
-
if (openError)
|
|
590
|
-
return (
|
|
591
|
-
<Alert severity="error" sx={{ m: 2 }}>
|
|
592
|
-
This dashboard cannot be opened in the builder: {openError}
|
|
593
|
-
</Alert>
|
|
594
|
-
);
|
|
595
|
-
|
|
596
677
|
const draftDiffers = draft !== undefined && draft !== packageText;
|
|
597
678
|
return (
|
|
598
679
|
<Stack sx={{ gap: 2 }}>
|
|
599
|
-
{
|
|
600
|
-
<Alert
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
<Stack direction="row" sx={{ gap: 1 }}>
|
|
604
|
-
<Button size="small" onClick={() => choose(true)}>
|
|
605
|
-
Resume
|
|
606
|
-
</Button>
|
|
607
|
-
<Button size="small" onClick={() => choose(false)}>
|
|
608
|
-
Start from the package
|
|
609
|
-
</Button>
|
|
610
|
-
</Stack>
|
|
611
|
-
}
|
|
612
|
-
>
|
|
613
|
-
You have edits to this dashboard saved in this browser that the
|
|
614
|
-
package does not have.
|
|
680
|
+
{modelQuery.isError && (
|
|
681
|
+
<Alert severity="warning">
|
|
682
|
+
The {noun} could not be re-read from the server:{" "}
|
|
683
|
+
{modelQuery.error?.message}. Your edits are still here.
|
|
615
684
|
</Alert>
|
|
616
685
|
)}
|
|
686
|
+
{!notebook &&
|
|
687
|
+
!authoritative &&
|
|
688
|
+
offered &&
|
|
689
|
+
draftDiffers &&
|
|
690
|
+
resume === undefined && (
|
|
691
|
+
<Alert
|
|
692
|
+
severity="info"
|
|
693
|
+
action={
|
|
694
|
+
<Stack direction="row" sx={{ gap: 1 }}>
|
|
695
|
+
<Button size="small" onClick={() => choose(true)}>
|
|
696
|
+
Resume
|
|
697
|
+
</Button>
|
|
698
|
+
<Button size="small" onClick={() => choose(false)}>
|
|
699
|
+
Start from the package
|
|
700
|
+
</Button>
|
|
701
|
+
</Stack>
|
|
702
|
+
}
|
|
703
|
+
>
|
|
704
|
+
You have edits to this dashboard saved in this browser that
|
|
705
|
+
the package does not have.
|
|
706
|
+
</Alert>
|
|
707
|
+
)}
|
|
617
708
|
{held !== undefined && (
|
|
618
709
|
<Alert
|
|
619
710
|
severity="warning"
|
|
@@ -623,11 +714,13 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
623
714
|
</Button>
|
|
624
715
|
}
|
|
625
716
|
>
|
|
626
|
-
{
|
|
627
|
-
? "This dashboard changed since you opened it.
|
|
628
|
-
: savesTo === "
|
|
629
|
-
? "This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and
|
|
630
|
-
:
|
|
717
|
+
{!dirty
|
|
718
|
+
? "This dashboard changed since you opened it. Loading the new version drops Undo save."
|
|
719
|
+
: savesTo === "package"
|
|
720
|
+
? "This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and until you do, saving is refused."
|
|
721
|
+
: savesTo === "host"
|
|
722
|
+
? "This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and saving keeps yours and writes over it."
|
|
723
|
+
: "The package's copy of this dashboard changed since you opened it. Your edits are still here; loading the new version replaces them."}
|
|
631
724
|
</Alert>
|
|
632
725
|
)}
|
|
633
726
|
{supersedeFailure !== undefined && (
|
|
@@ -640,74 +733,36 @@ export function DashboardEditor(props: DashboardEditorProps) {
|
|
|
640
733
|
{opened && (
|
|
641
734
|
<Surface
|
|
642
735
|
key={opened.generation}
|
|
736
|
+
kind={kind}
|
|
643
737
|
environmentName={environmentName}
|
|
644
738
|
packageName={packageName}
|
|
645
739
|
modelPath={modelPath}
|
|
646
740
|
slug={dashboardName}
|
|
741
|
+
modelGivens={
|
|
742
|
+
(modelQuery.data?.data as { givens?: Given[] } | undefined)
|
|
743
|
+
?.givens
|
|
744
|
+
}
|
|
647
745
|
{...(versionId !== undefined ? { versionId } : {})}
|
|
648
746
|
opened={opened}
|
|
747
|
+
{...(fromDraft &&
|
|
748
|
+
writer === "package" &&
|
|
749
|
+
opened.packageText !== undefined
|
|
750
|
+
? { replaces: opened.packageText }
|
|
751
|
+
: {})}
|
|
649
752
|
onSave={save}
|
|
650
753
|
onDirtyChange={reportDirty}
|
|
754
|
+
onSaveNoticeChange={setUndoOffered}
|
|
651
755
|
savesTo={savesTo}
|
|
756
|
+
{...(saveLabel ? { saveLabel } : {})}
|
|
652
757
|
{...(onEvent ? { onEvent: reportEvent } : {})}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
<SecondaryButton
|
|
656
|
-
label="Done editing"
|
|
657
|
-
icon={<CheckIcon />}
|
|
658
|
-
onClick={onExit}
|
|
659
|
-
/>
|
|
660
|
-
)
|
|
661
|
-
}
|
|
662
|
-
note={caption({
|
|
663
|
-
authoritative,
|
|
664
|
-
mutable,
|
|
665
|
-
pinnedPackageSave,
|
|
666
|
-
...(workspace ? { workspace } : {}),
|
|
667
|
-
...(readFailure !== undefined ? { readFailure } : {}),
|
|
668
|
-
...(versionId !== undefined ? { versionId } : {}),
|
|
669
|
-
})}
|
|
758
|
+
{...(onExit ? { onExit } : {})}
|
|
759
|
+
note={note}
|
|
670
760
|
/>
|
|
671
761
|
)}
|
|
672
762
|
</Stack>
|
|
673
763
|
);
|
|
674
764
|
}
|
|
675
765
|
|
|
676
|
-
/**
|
|
677
|
-
* What the toolbar says about where Save goes, in the backend's own words
|
|
678
|
-
* wherever it has any: a workspace carries a `description` precisely so the
|
|
679
|
-
* editor does not have to guess, and "this browser" is one host's answer
|
|
680
|
-
* rather than the interface's.
|
|
681
|
-
*/
|
|
682
|
-
function caption({
|
|
683
|
-
authoritative,
|
|
684
|
-
mutable,
|
|
685
|
-
pinnedPackageSave,
|
|
686
|
-
workspace,
|
|
687
|
-
readFailure,
|
|
688
|
-
versionId,
|
|
689
|
-
}: {
|
|
690
|
-
authoritative: boolean;
|
|
691
|
-
mutable: boolean;
|
|
692
|
-
pinnedPackageSave: boolean;
|
|
693
|
-
workspace?: Workspace;
|
|
694
|
-
readFailure?: string;
|
|
695
|
-
versionId?: string;
|
|
696
|
-
}): string {
|
|
697
|
-
if (readFailure !== undefined)
|
|
698
|
-
return `The saved copy could not be read, so Save is off: ${readFailure}`;
|
|
699
|
-
if (authoritative && workspace)
|
|
700
|
-
return workspace.writeable
|
|
701
|
-
? workspace.description
|
|
702
|
-
: `${workspace.description}: you cannot save into it.`;
|
|
703
|
-
if (pinnedPackageSave)
|
|
704
|
-
return `Reading version ${versionId}: a version is a fixed point in history, so Save is off.`;
|
|
705
|
-
if (mutable) return "Save writes the file into the package.";
|
|
706
|
-
if (workspace)
|
|
707
|
-
return `${workspace.description}: this server does not take writes.`;
|
|
708
|
-
return "This server does not take writes.";
|
|
709
|
-
}
|
|
710
|
-
|
|
711
766
|
/**
|
|
712
767
|
* The builder under a real control row, with the controls driving the tiles,
|
|
713
768
|
* both following the LIVE document rather than the saved file.
|
|
@@ -720,66 +775,113 @@ function caption({
|
|
|
720
775
|
* a literal, so it works the moment it is added.
|
|
721
776
|
*/
|
|
722
777
|
function Surface({
|
|
778
|
+
kind,
|
|
779
|
+
modelGivens,
|
|
723
780
|
environmentName,
|
|
724
781
|
packageName,
|
|
725
782
|
modelPath,
|
|
726
783
|
slug,
|
|
727
784
|
versionId,
|
|
728
785
|
opened,
|
|
786
|
+
replaces,
|
|
729
787
|
onSave,
|
|
730
788
|
onDirtyChange,
|
|
789
|
+
onSaveNoticeChange,
|
|
731
790
|
onEvent,
|
|
732
791
|
savesTo,
|
|
733
|
-
|
|
792
|
+
saveLabel,
|
|
793
|
+
onExit,
|
|
734
794
|
note,
|
|
735
795
|
}: {
|
|
796
|
+
kind: DocumentKind;
|
|
797
|
+
/** The model's own givens, for a cell-format notebook whose manifest the server cannot build until it is saved. */
|
|
798
|
+
modelGivens?: Given[];
|
|
736
799
|
environmentName: string;
|
|
737
800
|
packageName: string;
|
|
738
801
|
modelPath: string;
|
|
739
802
|
slug: string;
|
|
740
803
|
versionId?: string;
|
|
741
|
-
opened: {
|
|
804
|
+
opened: {
|
|
805
|
+
source: string;
|
|
806
|
+
document: DashboardDocument;
|
|
807
|
+
conversion?: { from: string; to: string };
|
|
808
|
+
generation: number;
|
|
809
|
+
};
|
|
810
|
+
replaces?: string;
|
|
742
811
|
onSave?: (source: string) => Promise<void>;
|
|
743
812
|
onDirtyChange: (dirty: boolean) => void;
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
813
|
+
onSaveNoticeChange: (showing: boolean) => void;
|
|
814
|
+
onEvent?: (event: BuilderEvent) => void;
|
|
815
|
+
savesTo: SavesTo;
|
|
816
|
+
saveLabel?: string;
|
|
817
|
+
onExit?: () => void;
|
|
747
818
|
note: string;
|
|
748
819
|
}) {
|
|
749
820
|
const { apiClients } = useServer();
|
|
821
|
+
const notebook = kind === "notebook";
|
|
750
822
|
|
|
751
|
-
|
|
823
|
+
// The server serves a dashboard only once the package file has a tile, so
|
|
824
|
+
// an empty start becomes servable when a save puts the first one there.
|
|
825
|
+
const [served, setServed] = useState(opened.document.tiles.length > 0);
|
|
826
|
+
useEffect(
|
|
827
|
+
() => setServed(opened.document.tiles.length > 0),
|
|
828
|
+
[opened.generation, opened.document],
|
|
829
|
+
);
|
|
830
|
+
|
|
831
|
+
const { data, isSuccess, isError } = useQueryWithApiError({
|
|
752
832
|
queryKey: [
|
|
753
833
|
"dashboard-editor-manifest",
|
|
754
834
|
environmentName,
|
|
755
835
|
packageName,
|
|
756
836
|
slug,
|
|
757
837
|
versionId,
|
|
838
|
+
kind,
|
|
758
839
|
],
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
840
|
+
// A layout notebook's manifest rides on its notebook read; one in the cell format has only the tag's starting values until it is saved.
|
|
841
|
+
queryFn: async (): Promise<DashboardManifest> => {
|
|
842
|
+
if (!notebook)
|
|
843
|
+
return (
|
|
844
|
+
await apiClients.dashboards.getDashboard(
|
|
845
|
+
environmentName,
|
|
846
|
+
packageName,
|
|
847
|
+
slug,
|
|
848
|
+
versionId,
|
|
849
|
+
)
|
|
850
|
+
).data;
|
|
851
|
+
const read = (
|
|
852
|
+
await apiClients.notebooks.getNotebook(
|
|
853
|
+
environmentName,
|
|
854
|
+
packageName,
|
|
855
|
+
modelPath,
|
|
856
|
+
versionId,
|
|
857
|
+
)
|
|
858
|
+
).data;
|
|
859
|
+
return (
|
|
860
|
+
read.dashboard ?? {
|
|
861
|
+
...(read.startingGivens
|
|
862
|
+
? { startingGivens: read.startingGivens }
|
|
863
|
+
: {}),
|
|
864
|
+
...(read.autorun === undefined ? {} : { autorun: read.autorun }),
|
|
865
|
+
}
|
|
866
|
+
);
|
|
867
|
+
},
|
|
868
|
+
// The server does not serve a dashboard with no tiles, so asking would 404.
|
|
869
|
+
enabled: served,
|
|
766
870
|
});
|
|
767
|
-
const manifest = data
|
|
871
|
+
const manifest = data;
|
|
768
872
|
|
|
769
873
|
// The package's other dashboards, by slug: where a clicked cell can go.
|
|
770
874
|
const { data: dashboardList } = useQueryWithApiError({
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
packageName,
|
|
775
|
-
versionId,
|
|
776
|
-
],
|
|
875
|
+
// Shares the listing the page's location lookup already fetches.
|
|
876
|
+
queryKey: ["dashboards", environmentName, packageName, versionId],
|
|
877
|
+
staleTime: 60_000,
|
|
777
878
|
queryFn: () =>
|
|
778
879
|
apiClients.dashboards.listDashboards(
|
|
779
880
|
environmentName,
|
|
780
881
|
packageName,
|
|
781
882
|
versionId,
|
|
782
883
|
),
|
|
884
|
+
enabled: !notebook,
|
|
783
885
|
});
|
|
784
886
|
const otherDashboards = useMemo(
|
|
785
887
|
() =>
|
|
@@ -818,7 +920,14 @@ function Surface({
|
|
|
818
920
|
packageName,
|
|
819
921
|
versionId,
|
|
820
922
|
)
|
|
821
|
-
).data.filter(
|
|
923
|
+
).data.filter(
|
|
924
|
+
// The catalog leaves dashboards out, and this file's own text is already fetched above.
|
|
925
|
+
(m) =>
|
|
926
|
+
m.path &&
|
|
927
|
+
!m.error &&
|
|
928
|
+
!isDashboardModel(m.path) &&
|
|
929
|
+
!m.path.startsWith("notebooks/"),
|
|
930
|
+
);
|
|
822
931
|
// One model that fails to load (a reload racing this fetch, say)
|
|
823
932
|
// costs the catalog that model's sources, not every suggestion.
|
|
824
933
|
const settled = await Promise.allSettled(
|
|
@@ -838,7 +947,25 @@ function Surface({
|
|
|
838
947
|
|
|
839
948
|
const [doc, setDoc] = useState(opened.document);
|
|
840
949
|
useEffect(() => setDoc(opened.document), [opened.document]);
|
|
841
|
-
|
|
950
|
+
// Only a package write can make the package serve it; a copy in the host's store does not.
|
|
951
|
+
const saveThenServe = useMemo<SaveHandler<DashboardDocument> | undefined>(
|
|
952
|
+
() =>
|
|
953
|
+
onSave && savesTo === "package"
|
|
954
|
+
? async (
|
|
955
|
+
source: string,
|
|
956
|
+
context: SaveContext<DashboardDocument>,
|
|
957
|
+
) => {
|
|
958
|
+
await onSave(source);
|
|
959
|
+
// An undone first save writes back a file with no tile, which the server stops serving.
|
|
960
|
+
setServed(context.document.tiles.length > 0);
|
|
961
|
+
}
|
|
962
|
+
: onSave,
|
|
963
|
+
[onSave, savesTo],
|
|
964
|
+
);
|
|
965
|
+
const modelSpecs = useMemo(
|
|
966
|
+
() => manifest?.givens ?? (opened.conversion ? (modelGivens ?? []) : []),
|
|
967
|
+
[manifest, opened.conversion, modelGivens],
|
|
968
|
+
);
|
|
842
969
|
const runnable = useMemo(
|
|
843
970
|
() =>
|
|
844
971
|
new Set(
|
|
@@ -856,7 +983,7 @@ function Surface({
|
|
|
856
983
|
specs,
|
|
857
984
|
loaded: isSuccess,
|
|
858
985
|
startingValues: manifest?.startingGivens,
|
|
859
|
-
documentKey: `${environmentName}/${packageName}/${versionId ?? ""}/${slug}/edit`,
|
|
986
|
+
documentKey: `${environmentName}/${packageName}/${versionId ?? ""}/${notebook ? "notebook/" : ""}${slug}/edit`,
|
|
860
987
|
autorun: manifest?.autorun !== false,
|
|
861
988
|
environmentName,
|
|
862
989
|
packageName,
|
|
@@ -865,10 +992,33 @@ function Surface({
|
|
|
865
992
|
documentName: slug,
|
|
866
993
|
});
|
|
867
994
|
|
|
995
|
+
const manifestSettled = !served || isSuccess || isError;
|
|
996
|
+
// What the saved file's compiled tiles read, keyed as the server keys a tile expression.
|
|
997
|
+
const servedReads = useMemo(
|
|
998
|
+
() =>
|
|
999
|
+
new Map(
|
|
1000
|
+
(manifest?.tiles ?? []).flatMap((tile) =>
|
|
1001
|
+
tile.kind !== "text" && tile.query && tile.givenNames
|
|
1002
|
+
? [[tileExpressionKey(tile.query), tile.givenNames] as const]
|
|
1003
|
+
: [],
|
|
1004
|
+
),
|
|
1005
|
+
),
|
|
1006
|
+
[manifest],
|
|
1007
|
+
);
|
|
868
1008
|
const renderTile = useMemo(
|
|
869
1009
|
() =>
|
|
870
|
-
function LiveTile(tile:
|
|
871
|
-
|
|
1010
|
+
function LiveTile(tile: QueryTile, heading?: TileHeadingSlots) {
|
|
1011
|
+
// The bindings a tile runs with come from the manifest; running before it lands queries every tile once unbound and again bound.
|
|
1012
|
+
if (!manifestSettled) return <Loading text="Running…" />;
|
|
1013
|
+
const query = previewTileQuery(
|
|
1014
|
+
doc,
|
|
1015
|
+
tile,
|
|
1016
|
+
runnable,
|
|
1017
|
+
applied,
|
|
1018
|
+
servedReads.get(
|
|
1019
|
+
tileExpressionKey(`${tile.source} -> ${tile.name}`),
|
|
1020
|
+
),
|
|
1021
|
+
);
|
|
872
1022
|
return (
|
|
873
1023
|
<DashboardTile
|
|
874
1024
|
environmentName={environmentName}
|
|
@@ -876,27 +1026,35 @@ function Surface({
|
|
|
876
1026
|
versionId={versionId}
|
|
877
1027
|
modelPath={modelPath}
|
|
878
1028
|
tile={query.expression}
|
|
1029
|
+
{...(query.annotation
|
|
1030
|
+
? { annotation: query.annotation }
|
|
1031
|
+
: {})}
|
|
879
1032
|
label={
|
|
880
1033
|
tile.label ?? tileTitle(`${tile.source} -> ${tile.name}`)
|
|
881
1034
|
}
|
|
882
1035
|
subtitle={tile.subtitle}
|
|
1036
|
+
{...(heading ? { heading } : {})}
|
|
883
1037
|
borderless={tile.borderless}
|
|
884
1038
|
givens={applied}
|
|
885
1039
|
declaredTypes={declaredTypes}
|
|
886
1040
|
givenNames={query.givenNames}
|
|
1041
|
+
ignoredFilters={tileIgnoredFilterLabels(query.reads, specs)}
|
|
887
1042
|
height={TILE_MAX_HEIGHT}
|
|
888
1043
|
/>
|
|
889
1044
|
);
|
|
890
1045
|
},
|
|
891
1046
|
[
|
|
892
1047
|
doc,
|
|
1048
|
+
manifestSettled,
|
|
893
1049
|
runnable,
|
|
1050
|
+
servedReads,
|
|
894
1051
|
environmentName,
|
|
895
1052
|
packageName,
|
|
896
1053
|
versionId,
|
|
897
1054
|
modelPath,
|
|
898
1055
|
applied,
|
|
899
1056
|
declaredTypes,
|
|
1057
|
+
specs,
|
|
900
1058
|
],
|
|
901
1059
|
);
|
|
902
1060
|
|
|
@@ -918,15 +1076,20 @@ function Surface({
|
|
|
918
1076
|
}))}
|
|
919
1077
|
onChange={setDoc}
|
|
920
1078
|
onDirtyChange={onDirtyChange}
|
|
1079
|
+
onSaveNoticeChange={onSaveNoticeChange}
|
|
1080
|
+
{...(opened.conversion ? { conversion: opened.conversion } : {})}
|
|
921
1081
|
{...(catalog ? { catalog } : {})}
|
|
922
1082
|
dashboards={otherDashboards}
|
|
923
1083
|
{...(onEvent ? { onEvent } : {})}
|
|
924
|
-
|
|
1084
|
+
{...(onExit ? { onExit } : {})}
|
|
925
1085
|
controls={
|
|
926
1086
|
isSuccess ? <GivensPanel {...panel} layout="bar" /> : undefined
|
|
927
1087
|
}
|
|
928
|
-
{...(
|
|
1088
|
+
{...(saveThenServe ? { onSave: saveThenServe } : {})}
|
|
929
1089
|
savesTo={savesTo}
|
|
1090
|
+
{...(saveLabel ? { saveLabel } : {})}
|
|
1091
|
+
{...(replaces !== undefined ? { replaces } : {})}
|
|
1092
|
+
modelPath={modelPath}
|
|
930
1093
|
/>
|
|
931
1094
|
<Box sx={{ px: 0.5 }}>
|
|
932
1095
|
<Typography variant="caption" sx={{ opacity: 0.7 }}>
|
|
@@ -936,16 +1099,3 @@ function Surface({
|
|
|
936
1099
|
</Stack>
|
|
937
1100
|
);
|
|
938
1101
|
}
|
|
939
|
-
|
|
940
|
-
/** What a storage backend said went wrong, for a reader who has to act on it. */
|
|
941
|
-
function storageErrorMessage(error: unknown): string {
|
|
942
|
-
return error instanceof Error ? error.message : String(error);
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
/** The server's own reason for a refused write, when it gave one. */
|
|
946
|
-
function apiErrorMessage(error: unknown): string {
|
|
947
|
-
const data = (error as { response?: { data?: { message?: string } } })
|
|
948
|
-
.response?.data;
|
|
949
|
-
if (data?.message) return data.message;
|
|
950
|
-
return error instanceof Error ? error.message : String(error);
|
|
951
|
-
}
|