@malloy-publisher/sdk 0.9.0 → 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 +82 -48
- 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
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Alert,
|
|
6
|
+
Button,
|
|
7
|
+
MenuItem,
|
|
8
|
+
Stack,
|
|
9
|
+
TextField,
|
|
10
|
+
Tooltip,
|
|
11
|
+
} from "@mui/material";
|
|
12
|
+
import { useEffect, useMemo, useState } from "react";
|
|
13
|
+
import {
|
|
14
|
+
createDocument,
|
|
15
|
+
documentPathForTitle,
|
|
16
|
+
MAX_SLUG_ATTEMPTS,
|
|
17
|
+
newDocumentProblem,
|
|
18
|
+
useDocumentChoices,
|
|
19
|
+
type CreatedDocument,
|
|
20
|
+
type CreateTarget,
|
|
21
|
+
type DocumentCreatedEvent,
|
|
22
|
+
} from "../DocumentCreate";
|
|
23
|
+
import { canRetryRequest } from "../DocumentCreate/canRetry";
|
|
24
|
+
import type { DocumentType } from "../DocumentStorage/DocumentStorage";
|
|
25
|
+
import { AppDialog } from "../AppDialog";
|
|
26
|
+
|
|
27
|
+
const KIND_LABEL: Record<DocumentType, string> = {
|
|
28
|
+
dashboard: "Dashboard",
|
|
29
|
+
notebook: "Notebook",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export interface NewDocumentDialogProps {
|
|
33
|
+
open: boolean;
|
|
34
|
+
/** Which kind the dialog opens on. */
|
|
35
|
+
kind: DocumentType;
|
|
36
|
+
/** Whether the reader may switch to the other kind. Default true. */
|
|
37
|
+
allowKindChange?: boolean;
|
|
38
|
+
environmentName: string;
|
|
39
|
+
packageName: string;
|
|
40
|
+
versionId?: string;
|
|
41
|
+
/** The package's model files, relative to its root, to pick a source from. */
|
|
42
|
+
models: readonly string[];
|
|
43
|
+
/** The host is still listing `models`, so an empty list is not yet "no models". */
|
|
44
|
+
modelsLoading?: boolean;
|
|
45
|
+
/** The host's listing of `models` failed, so an empty list is not "no models". */
|
|
46
|
+
modelsError?: unknown;
|
|
47
|
+
/** Lists the models again; offered when `modelsError` is one a retry can clear. */
|
|
48
|
+
onRetryModels?: () => void;
|
|
49
|
+
/** Where the file is written, and (on the package route) which names are taken. */
|
|
50
|
+
target: CreateTarget;
|
|
51
|
+
/** The line under the title on the storage route, saying where the host keeps the new file. */
|
|
52
|
+
savedAs?: string;
|
|
53
|
+
onClose: () => void;
|
|
54
|
+
onCreated: (created: CreatedDocument) => void;
|
|
55
|
+
onEvent?: (event: DocumentCreatedEvent) => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A new dashboard or notebook: pick the model, the view its first tile or
|
|
60
|
+
* query shows, and a title. The file is the one the builder would write, so
|
|
61
|
+
* everything after this is the builder's; the host opens it from `onCreated`.
|
|
62
|
+
*/
|
|
63
|
+
export function NewDocumentDialog({
|
|
64
|
+
open,
|
|
65
|
+
kind: initialKind,
|
|
66
|
+
allowKindChange = true,
|
|
67
|
+
environmentName,
|
|
68
|
+
packageName,
|
|
69
|
+
versionId,
|
|
70
|
+
models,
|
|
71
|
+
modelsLoading = false,
|
|
72
|
+
modelsError,
|
|
73
|
+
onRetryModels,
|
|
74
|
+
target,
|
|
75
|
+
savedAs,
|
|
76
|
+
onClose,
|
|
77
|
+
onCreated,
|
|
78
|
+
onEvent,
|
|
79
|
+
}: NewDocumentDialogProps) {
|
|
80
|
+
const [kind, setKind] = useState<DocumentType>(initialKind);
|
|
81
|
+
const [modelPath, setModelPath] = useState("");
|
|
82
|
+
/** The chosen view, as `source::view` — one value, so the pair is always valid. */
|
|
83
|
+
const [tile, setTile] = useState("");
|
|
84
|
+
const [title, setTitle] = useState("");
|
|
85
|
+
const [touchedTitle, setTouchedTitle] = useState(false);
|
|
86
|
+
const [attempted, setAttempted] = useState(false);
|
|
87
|
+
const [busy, setBusy] = useState(false);
|
|
88
|
+
const [failure, setFailure] = useState<string | undefined>(undefined);
|
|
89
|
+
const modelsFailed = modelsError !== undefined && modelsError !== null;
|
|
90
|
+
|
|
91
|
+
// Every model at once rather than the chosen one: a model that declares no
|
|
92
|
+
// source with a view cannot start a document, and the only way to offer a
|
|
93
|
+
// list without those is to know before the reader picks.
|
|
94
|
+
const { choices, isLoading, isSuccess, failed, retry, canRetry } =
|
|
95
|
+
useDocumentChoices({
|
|
96
|
+
environmentName,
|
|
97
|
+
packageName,
|
|
98
|
+
...(versionId !== undefined ? { versionId } : {}),
|
|
99
|
+
models,
|
|
100
|
+
enabled: open && models.length > 0,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const tiles = useMemo(
|
|
104
|
+
() => choices.get(modelPath) ?? [],
|
|
105
|
+
[choices, modelPath],
|
|
106
|
+
);
|
|
107
|
+
const chosen = tiles.find((t) => `${t.source}::${t.view}` === tile);
|
|
108
|
+
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (open) setKind(initialKind);
|
|
111
|
+
}, [open, initialKind]);
|
|
112
|
+
|
|
113
|
+
// Everything with one answer answers itself: a package with one usable
|
|
114
|
+
// model, a model with one view, and a title taken from that view.
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (!open) return;
|
|
117
|
+
const usable = [...choices.keys()];
|
|
118
|
+
if (modelPath === "" && usable.length > 0) setModelPath(usable[0]);
|
|
119
|
+
}, [open, choices, modelPath]);
|
|
120
|
+
|
|
121
|
+
// Only a pick not yet made is filled in: a picked view that leaves the list stays unpicked, never swapped.
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
if (!open || tiles.length === 0 || tile !== "") return;
|
|
124
|
+
setTile(`${tiles[0].source}::${tiles[0].view}`);
|
|
125
|
+
}, [open, tiles, tile]);
|
|
126
|
+
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (!open || touchedTitle || chosen === undefined) return;
|
|
129
|
+
setTitle(chosen.view.replace(/_/g, " "));
|
|
130
|
+
}, [open, touchedTitle, chosen]);
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (open) return;
|
|
134
|
+
// Reset on close, so the next open starts from the package again.
|
|
135
|
+
setModelPath("");
|
|
136
|
+
setTile("");
|
|
137
|
+
setTitle("");
|
|
138
|
+
setTouchedTitle(false);
|
|
139
|
+
setAttempted(false);
|
|
140
|
+
setFailure(undefined);
|
|
141
|
+
}, [open]);
|
|
142
|
+
|
|
143
|
+
// The first name the package listing leaves free; the storage route checks
|
|
144
|
+
// each name against the store itself when it writes.
|
|
145
|
+
const path = useMemo(() => {
|
|
146
|
+
if (title.trim() === "") return undefined;
|
|
147
|
+
for (let n = 1; n <= MAX_SLUG_ATTEMPTS; n++) {
|
|
148
|
+
const candidate = documentPathForTitle(kind, title, n);
|
|
149
|
+
if (!target.existing?.includes(candidate)) return candidate;
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
}, [kind, title, target]);
|
|
153
|
+
const problem =
|
|
154
|
+
chosen === undefined
|
|
155
|
+
? undefined
|
|
156
|
+
: newDocumentProblem(kind, {
|
|
157
|
+
title,
|
|
158
|
+
modelPath,
|
|
159
|
+
source: chosen.source,
|
|
160
|
+
view: chosen.view,
|
|
161
|
+
});
|
|
162
|
+
const titleProblem =
|
|
163
|
+
problem ??
|
|
164
|
+
(title.trim() !== "" && path === undefined
|
|
165
|
+
? "No free file name for this title; choose another."
|
|
166
|
+
: undefined);
|
|
167
|
+
// A blank title is said only once Create is pressed; anything else as it is typed.
|
|
168
|
+
const showTitleProblem =
|
|
169
|
+
titleProblem !== undefined && (attempted || title.trim() !== "");
|
|
170
|
+
|
|
171
|
+
const loading = modelsLoading || isLoading;
|
|
172
|
+
const unread = choices.size === 0 && (modelsFailed || failed.length > 0);
|
|
173
|
+
// Create is off only when nothing typed could make it succeed; the title is checked on press.
|
|
174
|
+
const blocked = loading
|
|
175
|
+
? "Loading model views"
|
|
176
|
+
: unread
|
|
177
|
+
? "Couldn't read the model views to start from"
|
|
178
|
+
: choices.size === 0
|
|
179
|
+
? "No model view to start from yet"
|
|
180
|
+
: chosen === undefined
|
|
181
|
+
? "Pick a view to start from"
|
|
182
|
+
: undefined;
|
|
183
|
+
const label = KIND_LABEL[kind].toLowerCase();
|
|
184
|
+
const createLabel = busy ? `Creating ${label}…` : `Create ${label}`;
|
|
185
|
+
const first = kind === "dashboard" ? "First tile" : "First query";
|
|
186
|
+
const picked = tile !== "" && chosen === undefined && tiles.length > 0;
|
|
187
|
+
|
|
188
|
+
const create = async () => {
|
|
189
|
+
if (blocked !== undefined || chosen === undefined || busy) return;
|
|
190
|
+
if (titleProblem !== undefined) {
|
|
191
|
+
setAttempted(true);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
setBusy(true);
|
|
195
|
+
setFailure(undefined);
|
|
196
|
+
try {
|
|
197
|
+
const created = await createDocument({
|
|
198
|
+
kind,
|
|
199
|
+
document: {
|
|
200
|
+
title,
|
|
201
|
+
modelPath,
|
|
202
|
+
source: chosen.source,
|
|
203
|
+
view: chosen.view,
|
|
204
|
+
},
|
|
205
|
+
target,
|
|
206
|
+
...(onEvent ? { onEvent } : {}),
|
|
207
|
+
});
|
|
208
|
+
onCreated(created);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
const message = (
|
|
211
|
+
error as { response?: { data?: { message?: string } } }
|
|
212
|
+
).response?.data?.message;
|
|
213
|
+
setFailure(
|
|
214
|
+
message ?? (error instanceof Error ? error.message : String(error)),
|
|
215
|
+
);
|
|
216
|
+
} finally {
|
|
217
|
+
setBusy(false);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const retryButton = (onRetry: () => void) => (
|
|
222
|
+
<Button color="inherit" size="small" onClick={onRetry}>
|
|
223
|
+
Retry
|
|
224
|
+
</Button>
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<AppDialog
|
|
229
|
+
open={open}
|
|
230
|
+
// A write in flight is not abandoned by Escape or a backdrop click.
|
|
231
|
+
onClose={busy ? () => {} : onClose}
|
|
232
|
+
title={`New ${label}`}
|
|
233
|
+
description={
|
|
234
|
+
kind === "dashboard"
|
|
235
|
+
? "A dashboard is a Malloy file in the package. Pick what its first tile shows; the rest is the builder."
|
|
236
|
+
: "A notebook is a Malloy file in the package that mixes text and queries. Pick what its first query runs; the rest is the builder."
|
|
237
|
+
}
|
|
238
|
+
actions={
|
|
239
|
+
<>
|
|
240
|
+
<Button onClick={onClose} disabled={busy}>
|
|
241
|
+
Cancel
|
|
242
|
+
</Button>
|
|
243
|
+
{/* A disabled button fires no events, so the tooltip hangs on a wrapper. */}
|
|
244
|
+
<Tooltip title={busy ? "" : (blocked ?? "")}>
|
|
245
|
+
<span>
|
|
246
|
+
<Button
|
|
247
|
+
variant="contained"
|
|
248
|
+
disabled={busy || blocked !== undefined}
|
|
249
|
+
aria-label={
|
|
250
|
+
!busy && blocked !== undefined
|
|
251
|
+
? `${createLabel}: ${blocked}`
|
|
252
|
+
: createLabel
|
|
253
|
+
}
|
|
254
|
+
onClick={() => void create()}
|
|
255
|
+
>
|
|
256
|
+
{createLabel}
|
|
257
|
+
</Button>
|
|
258
|
+
</span>
|
|
259
|
+
</Tooltip>
|
|
260
|
+
</>
|
|
261
|
+
}
|
|
262
|
+
>
|
|
263
|
+
<Stack sx={{ gap: 2, pt: 1 }}>
|
|
264
|
+
{modelsFailed ? (
|
|
265
|
+
<Alert
|
|
266
|
+
severity="error"
|
|
267
|
+
action={
|
|
268
|
+
onRetryModels && canRetryRequest(modelsError)
|
|
269
|
+
? retryButton(onRetryModels)
|
|
270
|
+
: undefined
|
|
271
|
+
}
|
|
272
|
+
>
|
|
273
|
+
Couldn't read this package's models, so no view is
|
|
274
|
+
listed to start from.
|
|
275
|
+
</Alert>
|
|
276
|
+
) : models.length === 0 ? (
|
|
277
|
+
!modelsLoading && (
|
|
278
|
+
<Alert severity="info">
|
|
279
|
+
This package has no models yet. Add a .malloy file that
|
|
280
|
+
declares a source with a view, then create a {label} from
|
|
281
|
+
it.
|
|
282
|
+
</Alert>
|
|
283
|
+
)
|
|
284
|
+
) : failed.length > 0 ? (
|
|
285
|
+
<Alert
|
|
286
|
+
severity="warning"
|
|
287
|
+
action={canRetry ? retryButton(retry) : undefined}
|
|
288
|
+
>
|
|
289
|
+
Couldn't read {failed.join(", ")}, so{" "}
|
|
290
|
+
{failed.length === 1 ? "its" : "their"} views aren't
|
|
291
|
+
listed.
|
|
292
|
+
</Alert>
|
|
293
|
+
) : (
|
|
294
|
+
isSuccess &&
|
|
295
|
+
choices.size === 0 && (
|
|
296
|
+
<Alert severity="info">
|
|
297
|
+
A {label} starts from a view of a source, and no model in
|
|
298
|
+
this package declares one yet. Add a view to a source in a
|
|
299
|
+
model file and this list fills in.
|
|
300
|
+
</Alert>
|
|
301
|
+
)
|
|
302
|
+
)}
|
|
303
|
+
{allowKindChange && (
|
|
304
|
+
<TextField
|
|
305
|
+
select
|
|
306
|
+
size="small"
|
|
307
|
+
label="Type"
|
|
308
|
+
value={kind}
|
|
309
|
+
disabled={busy}
|
|
310
|
+
onChange={(event) =>
|
|
311
|
+
setKind(event.target.value as DocumentType)
|
|
312
|
+
}
|
|
313
|
+
inputProps={{ "aria-label": "Type" }}
|
|
314
|
+
>
|
|
315
|
+
{(Object.keys(KIND_LABEL) as DocumentType[]).map((k) => (
|
|
316
|
+
<MenuItem key={k} value={k}>
|
|
317
|
+
{KIND_LABEL[k]}
|
|
318
|
+
</MenuItem>
|
|
319
|
+
))}
|
|
320
|
+
</TextField>
|
|
321
|
+
)}
|
|
322
|
+
<TextField
|
|
323
|
+
select
|
|
324
|
+
size="small"
|
|
325
|
+
label="Model"
|
|
326
|
+
value={choices.has(modelPath) ? modelPath : ""}
|
|
327
|
+
disabled={choices.size === 0 || busy}
|
|
328
|
+
onChange={(event) => {
|
|
329
|
+
setModelPath(event.target.value);
|
|
330
|
+
setTile("");
|
|
331
|
+
}}
|
|
332
|
+
inputProps={{ "aria-label": "Model" }}
|
|
333
|
+
helperText={
|
|
334
|
+
loading
|
|
335
|
+
? "Reading the package's models…"
|
|
336
|
+
: choices.size === 1
|
|
337
|
+
? "The only model with a view to start from."
|
|
338
|
+
: "Models with a view to start from."
|
|
339
|
+
}
|
|
340
|
+
>
|
|
341
|
+
{[...choices.keys()].map((modelFile) => (
|
|
342
|
+
<MenuItem key={modelFile} value={modelFile}>
|
|
343
|
+
{modelFile}
|
|
344
|
+
</MenuItem>
|
|
345
|
+
))}
|
|
346
|
+
</TextField>
|
|
347
|
+
{/* One field, not two: the file needs a view OF a source, so the
|
|
348
|
+
pair is the thing being chosen. */}
|
|
349
|
+
<TextField
|
|
350
|
+
select
|
|
351
|
+
size="small"
|
|
352
|
+
label={first}
|
|
353
|
+
value={chosen ? tile : ""}
|
|
354
|
+
disabled={tiles.length === 0 || busy}
|
|
355
|
+
onChange={(event) => setTile(event.target.value)}
|
|
356
|
+
inputProps={{ "aria-label": first }}
|
|
357
|
+
error={picked}
|
|
358
|
+
helperText={
|
|
359
|
+
picked
|
|
360
|
+
? "The view you picked is no longer in this model; pick another."
|
|
361
|
+
: tiles.length === 1
|
|
362
|
+
? "The only view this model offers; more are added in the builder."
|
|
363
|
+
: "A view of a source; more are added in the builder."
|
|
364
|
+
}
|
|
365
|
+
>
|
|
366
|
+
{tiles.map((option) => (
|
|
367
|
+
<MenuItem
|
|
368
|
+
key={`${option.source}::${option.view}`}
|
|
369
|
+
value={`${option.source}::${option.view}`}
|
|
370
|
+
>
|
|
371
|
+
{option.source} → {option.view}
|
|
372
|
+
</MenuItem>
|
|
373
|
+
))}
|
|
374
|
+
</TextField>
|
|
375
|
+
<TextField
|
|
376
|
+
size="small"
|
|
377
|
+
label="Title"
|
|
378
|
+
value={title}
|
|
379
|
+
disabled={busy}
|
|
380
|
+
onChange={(event) => {
|
|
381
|
+
setTouchedTitle(true);
|
|
382
|
+
setTitle(event.target.value);
|
|
383
|
+
}}
|
|
384
|
+
inputProps={{ "aria-label": `${KIND_LABEL[kind]} title` }}
|
|
385
|
+
error={showTitleProblem}
|
|
386
|
+
helperText={
|
|
387
|
+
showTitleProblem
|
|
388
|
+
? titleProblem
|
|
389
|
+
: path
|
|
390
|
+
? target.route === "package"
|
|
391
|
+
? `Written as ${path}, and opened in the builder.`
|
|
392
|
+
: (savedAs ??
|
|
393
|
+
`Saved as a new ${label} in the host's store, and opened in the builder.`)
|
|
394
|
+
: "Names the file too."
|
|
395
|
+
}
|
|
396
|
+
/>
|
|
397
|
+
{failure && <Alert severity="error">{failure}</Alert>}
|
|
398
|
+
</Stack>
|
|
399
|
+
</AppDialog>
|
|
400
|
+
);
|
|
401
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/** The package page's one Artifacts list: dashboards and notebooks, named by one rule. */
|
|
5
|
+
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
6
|
+
import { afterEach, beforeEach, expect, it, mock } from "bun:test";
|
|
7
|
+
import type { ReactNode } from "react";
|
|
8
|
+
import {
|
|
9
|
+
clearCache,
|
|
10
|
+
mockServerProvider,
|
|
11
|
+
pending,
|
|
12
|
+
serverWrapper,
|
|
13
|
+
} from "../../../test/serverProvider";
|
|
14
|
+
import type {
|
|
15
|
+
DocumentLocator,
|
|
16
|
+
DocumentStorage,
|
|
17
|
+
} from "../DocumentStorage/DocumentStorage";
|
|
18
|
+
import { DocumentStorageProvider } from "../DocumentStorage/DocumentStorageProvider";
|
|
19
|
+
|
|
20
|
+
let dashboards: { name: string; path: string; title?: string }[] = [];
|
|
21
|
+
let notebooks: { path: string; title?: string }[] = [];
|
|
22
|
+
const listDashboards = mock((_e: string, _p: string, _v?: string) =>
|
|
23
|
+
Promise.resolve({ data: dashboards }),
|
|
24
|
+
);
|
|
25
|
+
const listNotebooks = mock((_e: string, _p: string, _v?: string) =>
|
|
26
|
+
Promise.resolve({ data: notebooks }),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
mockServerProvider(
|
|
30
|
+
{
|
|
31
|
+
packages: { getPackage: pending },
|
|
32
|
+
notebooks: { listNotebooks, getNotebook: pending },
|
|
33
|
+
models: { listModels: () => Promise.resolve({ data: [] }) },
|
|
34
|
+
databases: { listDatabases: () => Promise.resolve({ data: [] }) },
|
|
35
|
+
dataApps: { listDataApps: () => Promise.resolve({ data: [] }) },
|
|
36
|
+
dashboards: { listDashboards },
|
|
37
|
+
materializations: {
|
|
38
|
+
listMaterializations: () => Promise.resolve({ data: [] }),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{ mutable: true },
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const { default: Package } = await import("./Package");
|
|
45
|
+
|
|
46
|
+
const onClick = mock((_to: string) => {});
|
|
47
|
+
|
|
48
|
+
function mount(storage?: DocumentStorage) {
|
|
49
|
+
const wrap = ({ children }: { children: ReactNode }) =>
|
|
50
|
+
serverWrapper({
|
|
51
|
+
children: storage ? (
|
|
52
|
+
<DocumentStorageProvider documentStorage={storage}>
|
|
53
|
+
{children}
|
|
54
|
+
</DocumentStorageProvider>
|
|
55
|
+
) : (
|
|
56
|
+
children
|
|
57
|
+
),
|
|
58
|
+
});
|
|
59
|
+
return render(
|
|
60
|
+
<Package
|
|
61
|
+
resourceUri="publisher://environments/env/packages/pkg"
|
|
62
|
+
onClickPackageFile={onClick}
|
|
63
|
+
/>,
|
|
64
|
+
{ wrapper: wrap },
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The artifact rows' text, top to bottom. */
|
|
69
|
+
const rows = async () => {
|
|
70
|
+
await screen.findByRole("heading", { name: "Artifacts" });
|
|
71
|
+
const section = screen.getByRole("region", { name: "Artifacts" });
|
|
72
|
+
return Array.from(section.querySelectorAll('[role="button"]'))
|
|
73
|
+
.map((row) => row.textContent ?? "")
|
|
74
|
+
.filter((text) => text !== "New");
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
beforeEach(() => {
|
|
78
|
+
clearCache();
|
|
79
|
+
dashboards = [];
|
|
80
|
+
notebooks = [];
|
|
81
|
+
onClick.mockClear();
|
|
82
|
+
listDashboards.mockClear();
|
|
83
|
+
listNotebooks.mockClear();
|
|
84
|
+
});
|
|
85
|
+
afterEach(cleanup);
|
|
86
|
+
|
|
87
|
+
it("lists a dashboard and a notebook in one section, each with its kind, ordered by what is shown", async () => {
|
|
88
|
+
dashboards = [
|
|
89
|
+
{ name: "overview", path: "dashboards/overview.malloy", title: "Zebra" },
|
|
90
|
+
];
|
|
91
|
+
notebooks = [
|
|
92
|
+
{ path: "notebooks/tour.malloy", title: "Aardvark" },
|
|
93
|
+
{ path: "notebooks/plain.malloy", title: "notebooks/plain.malloy" },
|
|
94
|
+
];
|
|
95
|
+
mount();
|
|
96
|
+
|
|
97
|
+
expect(await rows()).toEqual([
|
|
98
|
+
"AardvarkNotebook",
|
|
99
|
+
"plainNotebook",
|
|
100
|
+
"ZebraDashboard",
|
|
101
|
+
]);
|
|
102
|
+
expect(screen.queryByRole("heading", { name: "Dashboards" })).toBeNull();
|
|
103
|
+
expect(screen.queryByRole("heading", { name: "Notebooks" })).toBeNull();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("shows the folder only to tell two files with one slug apart, and opens each by its kind", async () => {
|
|
107
|
+
dashboards = [{ name: "story", path: "dashboards/story.malloy" }];
|
|
108
|
+
notebooks = [
|
|
109
|
+
{ path: "notebooks/story.malloy" },
|
|
110
|
+
{ path: "notebooks/solo.malloy" },
|
|
111
|
+
];
|
|
112
|
+
mount();
|
|
113
|
+
|
|
114
|
+
expect(await rows()).toEqual([
|
|
115
|
+
"solo" + "Notebook",
|
|
116
|
+
"story" + "dashboards/story.malloy" + "Dashboard",
|
|
117
|
+
"story" + "notebooks/story.malloy" + "Notebook",
|
|
118
|
+
]);
|
|
119
|
+
fireEvent.click(screen.getByText("dashboards/story.malloy"));
|
|
120
|
+
fireEvent.click(screen.getByText("notebooks/story.malloy"));
|
|
121
|
+
expect(onClick.mock.calls.map((call) => call[0])).toEqual([
|
|
122
|
+
"/env/pkg/dashboards/story",
|
|
123
|
+
"/env/pkg/notebooks/story",
|
|
124
|
+
]);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("keeps a titled .malloynb's path as its secondary text", async () => {
|
|
128
|
+
notebooks = [{ path: "orders.malloynb", title: "Orders" }];
|
|
129
|
+
mount();
|
|
130
|
+
|
|
131
|
+
expect(await rows()).toEqual(["Ordersorders.malloynbNotebook"]);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("says so when either list fails, and still lists the other", async () => {
|
|
135
|
+
dashboards = [{ name: "overview", path: "dashboards/overview.malloy" }];
|
|
136
|
+
listNotebooks.mockImplementationOnce(() =>
|
|
137
|
+
Promise.reject({ response: { status: 501 } }),
|
|
138
|
+
);
|
|
139
|
+
mount();
|
|
140
|
+
|
|
141
|
+
expect(
|
|
142
|
+
await screen.findByText(/Could not list some artifacts/),
|
|
143
|
+
).toBeDefined();
|
|
144
|
+
expect(await rows()).toEqual(["overviewDashboard"]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("treats a 404 on the notebooks list as none, without an error", async () => {
|
|
148
|
+
dashboards = [{ name: "overview", path: "dashboards/overview.malloy" }];
|
|
149
|
+
listNotebooks.mockImplementationOnce(() =>
|
|
150
|
+
Promise.reject({ response: { status: 404 } }),
|
|
151
|
+
);
|
|
152
|
+
mount();
|
|
153
|
+
|
|
154
|
+
expect(await rows()).toEqual(["overviewDashboard"]);
|
|
155
|
+
expect(screen.queryByText(/Could not list/)).toBeNull();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("lists host drafts of both kinds, each opening its own editor", async () => {
|
|
159
|
+
const draft = (
|
|
160
|
+
type: "dashboard" | "notebook",
|
|
161
|
+
slug: string,
|
|
162
|
+
): DocumentLocator => ({
|
|
163
|
+
workspace: "browser",
|
|
164
|
+
type,
|
|
165
|
+
path: `env/pkg/${type}s/${slug}.malloy`,
|
|
166
|
+
});
|
|
167
|
+
const stored = [draft("dashboard", "d-one"), draft("notebook", "n-one")];
|
|
168
|
+
const storage: DocumentStorage = {
|
|
169
|
+
listWorkspaces: async () => [
|
|
170
|
+
{ name: "browser", writeable: true, description: "This browser" },
|
|
171
|
+
],
|
|
172
|
+
listDocuments: async (_workspace, type) =>
|
|
173
|
+
stored.filter((locator) => locator.type === type),
|
|
174
|
+
getDocument: async () => {
|
|
175
|
+
throw new Error("absent");
|
|
176
|
+
},
|
|
177
|
+
saveDocument: async () => {},
|
|
178
|
+
deleteDocument: async () => {},
|
|
179
|
+
moveDocument: async () => {},
|
|
180
|
+
};
|
|
181
|
+
dashboards = [{ name: "overview", path: "dashboards/overview.malloy" }];
|
|
182
|
+
mount(storage);
|
|
183
|
+
|
|
184
|
+
fireEvent.click(await screen.findByText("d-one"));
|
|
185
|
+
fireEvent.click(await screen.findByText("n-one"));
|
|
186
|
+
expect(onClick.mock.calls.map((call) => call[0])).toEqual([
|
|
187
|
+
"/env/pkg/dashboards/d-one/edit",
|
|
188
|
+
"/env/pkg/notebooks/n-one/edit",
|
|
189
|
+
]);
|
|
190
|
+
});
|