@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,113 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { useQueries } from "@tanstack/react-query";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { useServer } from "../ServerProvider";
|
|
7
|
+
import { canRetryRequest } from "./canRetry";
|
|
8
|
+
import { exportedSources } from "./exportedSources";
|
|
9
|
+
|
|
10
|
+
export interface DocumentChoice {
|
|
11
|
+
source: string;
|
|
12
|
+
view: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* What a new dashboard or notebook can start from: model -> the (source, view)
|
|
17
|
+
* pairs it declares. One `getModel` per model under its own key, read only
|
|
18
|
+
* while `enabled` (the dialog is open) and cached after, so opening it costs
|
|
19
|
+
* nothing until it is opened. A model whose lookup errors drops out of
|
|
20
|
+
* `choices` and is named in `failed` (once nothing is loading), so a caller can
|
|
21
|
+
* tell "every lookup failed" from "none exist"; `retry` refetches only those,
|
|
22
|
+
* and `canRetry` says whether any of them could succeed on a second attempt.
|
|
23
|
+
*/
|
|
24
|
+
export function useDocumentChoices({
|
|
25
|
+
environmentName,
|
|
26
|
+
packageName,
|
|
27
|
+
versionId,
|
|
28
|
+
models,
|
|
29
|
+
enabled,
|
|
30
|
+
}: {
|
|
31
|
+
environmentName: string;
|
|
32
|
+
packageName: string;
|
|
33
|
+
/** The package version the model list was read at. */
|
|
34
|
+
versionId?: string;
|
|
35
|
+
/** The package's model files, relative to its root. */
|
|
36
|
+
models: readonly string[];
|
|
37
|
+
enabled: boolean;
|
|
38
|
+
}): {
|
|
39
|
+
choices: Map<string, DocumentChoice[]>;
|
|
40
|
+
isLoading: boolean;
|
|
41
|
+
isSuccess: boolean;
|
|
42
|
+
/** Model paths whose lookup errored, in `models` order; empty while loading. */
|
|
43
|
+
failed: string[];
|
|
44
|
+
/** Refetches only the failed lookups. */
|
|
45
|
+
retry: () => void;
|
|
46
|
+
/** Whether a failed lookup could succeed if retried, by {@link canRetryRequest}. */
|
|
47
|
+
canRetry: boolean;
|
|
48
|
+
} {
|
|
49
|
+
const { apiClients, server } = useServer();
|
|
50
|
+
const results = useQueries({
|
|
51
|
+
queries: models.map((path) => ({
|
|
52
|
+
// `useQueries` bypasses `useQueryWithApiError`, so the server is added here to keep two servers' caches apart.
|
|
53
|
+
queryKey: [
|
|
54
|
+
"new-document-model",
|
|
55
|
+
environmentName,
|
|
56
|
+
packageName,
|
|
57
|
+
versionId,
|
|
58
|
+
path,
|
|
59
|
+
server,
|
|
60
|
+
],
|
|
61
|
+
queryFn: async () =>
|
|
62
|
+
(
|
|
63
|
+
await apiClients.models.getModel(
|
|
64
|
+
environmentName,
|
|
65
|
+
packageName,
|
|
66
|
+
path,
|
|
67
|
+
versionId,
|
|
68
|
+
)
|
|
69
|
+
).data,
|
|
70
|
+
enabled,
|
|
71
|
+
retry: false,
|
|
72
|
+
staleTime: 5 * 60 * 1000,
|
|
73
|
+
refetchOnWindowFocus: false,
|
|
74
|
+
})),
|
|
75
|
+
});
|
|
76
|
+
// `useQueries` returns a new array each render; its data changes when `dataUpdatedAt` does.
|
|
77
|
+
const version = results.map((q) => q.dataUpdatedAt).join();
|
|
78
|
+
const choices = useMemo(() => {
|
|
79
|
+
const out = new Map<string, DocumentChoice[]>();
|
|
80
|
+
results.forEach((result, i) => {
|
|
81
|
+
const pairs: DocumentChoice[] = [];
|
|
82
|
+
const exported = exportedSources(result.data?.modelInfo);
|
|
83
|
+
for (const source of result.data?.sources ?? []) {
|
|
84
|
+
if (typeof source.name !== "string" || !exported.has(source.name))
|
|
85
|
+
continue;
|
|
86
|
+
for (const view of source.views ?? [])
|
|
87
|
+
if (typeof view.name === "string")
|
|
88
|
+
pairs.push({ source: source.name, view: view.name });
|
|
89
|
+
}
|
|
90
|
+
if (pairs.length > 0) out.set(models[i], pairs);
|
|
91
|
+
});
|
|
92
|
+
return out;
|
|
93
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
+
}, [version, models]);
|
|
95
|
+
const isLoading = results.some((q) => q.isLoading);
|
|
96
|
+
const failed = isLoading ? [] : models.filter((_, i) => results[i]?.isError);
|
|
97
|
+
const canRetry =
|
|
98
|
+
!isLoading && results.some((q) => q.isError && canRetryRequest(q.error));
|
|
99
|
+
const retry = () => {
|
|
100
|
+
results.forEach((q) => {
|
|
101
|
+
if (q.isError) void q.refetch();
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
choices,
|
|
106
|
+
isLoading,
|
|
107
|
+
// A model that will not load drops out of the choices rather than failing the list.
|
|
108
|
+
isSuccess: results.length > 0 && results.every((q) => !q.isPending),
|
|
109
|
+
failed,
|
|
110
|
+
retry,
|
|
111
|
+
canRetry,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -54,7 +54,8 @@ export const isDocumentNotFound = (error: unknown): boolean =>
|
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* The kinds of document the SDK authors. A `dashboard` is a
|
|
57
|
-
* `dashboards/<slug>.malloy` file; a `notebook` is a
|
|
57
|
+
* `dashboards/<slug>.malloy` file; a `notebook` is a
|
|
58
|
+
* `notebooks/<slug>.malloy` file.
|
|
58
59
|
*/
|
|
59
60
|
export type DocumentType = "dashboard" | "notebook";
|
|
60
61
|
|
|
@@ -258,7 +258,7 @@ describe("a model that declares givens", () => {
|
|
|
258
258
|
});
|
|
259
259
|
|
|
260
260
|
describe("a model with no givens", () => {
|
|
261
|
-
it("renders no
|
|
261
|
+
it("renders no Filters row, and sends no givens key", async () => {
|
|
262
262
|
executeQueryModel.mockImplementation(() =>
|
|
263
263
|
Promise.resolve({ data: { result: JSON.stringify({}) } }),
|
|
264
264
|
);
|
|
@@ -273,7 +273,7 @@ describe("a model with no givens", () => {
|
|
|
273
273
|
|
|
274
274
|
// Nothing to wait on the label for, so wait on the button instead.
|
|
275
275
|
await screen.findByRole("button", { name: "Run" });
|
|
276
|
-
expect(screen.queryByText("
|
|
276
|
+
expect(screen.queryByText("Filters")).toBeNull();
|
|
277
277
|
run();
|
|
278
278
|
|
|
279
279
|
await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
|
|
13
13
|
import React, { useEffect, useState } from "react";
|
|
14
14
|
import { useMutationWithApiError } from "../../hooks/useQueryWithApiError";
|
|
15
|
+
import { loadQueryBuilder } from "../DashboardBuilder/loadMalloy";
|
|
15
16
|
import { parseResourceUri } from "../../utils/formatting";
|
|
16
17
|
// import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
17
18
|
import { useServer } from "../ServerProvider";
|
|
@@ -379,10 +380,7 @@ export function SourceExplorerComponent(props: SourceExplorerComponentProps) {
|
|
|
379
380
|
useEffect(() => {
|
|
380
381
|
let isMounted = true;
|
|
381
382
|
|
|
382
|
-
Promise.all([
|
|
383
|
-
import("@malloydata/malloy-explorer"),
|
|
384
|
-
import("@malloydata/malloy-query-builder"),
|
|
385
|
-
])
|
|
383
|
+
Promise.all([import("@malloydata/malloy-explorer"), loadQueryBuilder()])
|
|
386
384
|
.then(([explorerComponents, queryBuilder]) => {
|
|
387
385
|
if (isMounted) {
|
|
388
386
|
setExplorerComponents(explorerComponents);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
|
6
|
+
import { NarrowEditGate } from "./NarrowEditGate";
|
|
7
|
+
|
|
8
|
+
const stubWidth = (narrow: boolean) => {
|
|
9
|
+
window.matchMedia = ((query: string) => ({
|
|
10
|
+
matches: narrow && query.includes("max-width"),
|
|
11
|
+
media: query,
|
|
12
|
+
addEventListener: () => {},
|
|
13
|
+
removeEventListener: () => {},
|
|
14
|
+
addListener: () => {},
|
|
15
|
+
removeListener: () => {},
|
|
16
|
+
onchange: null,
|
|
17
|
+
dispatchEvent: () => false,
|
|
18
|
+
})) as unknown as typeof window.matchMedia;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// The stub is global and the preloaded DOM is shared across spec files.
|
|
22
|
+
const original = window.matchMedia;
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
window.matchMedia = original;
|
|
25
|
+
});
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
cleanup();
|
|
28
|
+
window.matchMedia = original;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("NarrowEditGate", () => {
|
|
32
|
+
it("renders the editor at once on a wide screen", () => {
|
|
33
|
+
stubWidth(false);
|
|
34
|
+
render(
|
|
35
|
+
<NarrowEditGate>
|
|
36
|
+
<p>the editor</p>
|
|
37
|
+
</NarrowEditGate>,
|
|
38
|
+
);
|
|
39
|
+
expect(screen.getByText("the editor")).toBeDefined();
|
|
40
|
+
expect(screen.queryByText(/works best on a larger screen/)).toBeNull();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("holds the editor back on a narrow screen until Edit anyway", () => {
|
|
44
|
+
stubWidth(true);
|
|
45
|
+
render(
|
|
46
|
+
<NarrowEditGate>
|
|
47
|
+
<p>the editor</p>
|
|
48
|
+
</NarrowEditGate>,
|
|
49
|
+
);
|
|
50
|
+
expect(screen.queryByText("the editor")).toBeNull();
|
|
51
|
+
expect(
|
|
52
|
+
screen.getByText("Editing works best on a larger screen"),
|
|
53
|
+
).toBeDefined();
|
|
54
|
+
fireEvent.click(screen.getByRole("button", { name: "Edit anyway" }));
|
|
55
|
+
expect(screen.getByText("the editor")).toBeDefined();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("decides once, so widening the window does not swap the editor away", () => {
|
|
59
|
+
stubWidth(false);
|
|
60
|
+
const view = render(
|
|
61
|
+
<NarrowEditGate>
|
|
62
|
+
<p>the editor</p>
|
|
63
|
+
</NarrowEditGate>,
|
|
64
|
+
);
|
|
65
|
+
stubWidth(true);
|
|
66
|
+
view.rerender(
|
|
67
|
+
<NarrowEditGate>
|
|
68
|
+
<p>the editor</p>
|
|
69
|
+
</NarrowEditGate>,
|
|
70
|
+
);
|
|
71
|
+
expect(screen.getByText("the editor")).toBeDefined();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Button, Stack, Typography } from "@mui/material";
|
|
5
|
+
import { useState, type ReactNode } from "react";
|
|
6
|
+
import { isNarrowScreen } from "../hooks/useNarrowScreen";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Wraps an editor: on a screen under 600px it shows a notice with "Edit anyway" first.
|
|
10
|
+
* Decided once at mount, so rotating a phone or resizing a window never swaps the editor out from under an edit.
|
|
11
|
+
*/
|
|
12
|
+
export function NarrowEditGate({ children }: { children: ReactNode }) {
|
|
13
|
+
const [narrow] = useState(isNarrowScreen);
|
|
14
|
+
const [proceed, setProceed] = useState(false);
|
|
15
|
+
if (!narrow || proceed) return <>{children}</>;
|
|
16
|
+
return (
|
|
17
|
+
<Stack sx={{ alignItems: "flex-start", gap: 1.5, py: 3 }}>
|
|
18
|
+
<Typography variant="h6">
|
|
19
|
+
Editing works best on a larger screen
|
|
20
|
+
</Typography>
|
|
21
|
+
<Typography variant="body2" color="text.secondary">
|
|
22
|
+
The editor is built for a wider window. You can still try it here.
|
|
23
|
+
</Typography>
|
|
24
|
+
<Button variant="outlined" onClick={() => setProceed(true)}>
|
|
25
|
+
Edit anyway
|
|
26
|
+
</Button>
|
|
27
|
+
</Stack>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { beforeEach, expect, it, mock } from "bun:test";
|
|
5
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
6
|
+
import {
|
|
7
|
+
clearCache,
|
|
8
|
+
mockServerProvider,
|
|
9
|
+
pending,
|
|
10
|
+
serverWrapper,
|
|
11
|
+
} from "../../../test/serverProvider";
|
|
12
|
+
import type { RawNotebook } from "../../client";
|
|
13
|
+
|
|
14
|
+
const LAYOUT = {
|
|
15
|
+
format: "malloy",
|
|
16
|
+
notebookCells: [{ type: "markdown", kind: "markdown", text: "Intro" }],
|
|
17
|
+
dashboard: {
|
|
18
|
+
name: "tour",
|
|
19
|
+
kind: "notebook",
|
|
20
|
+
path: "notebooks/tour.malloy",
|
|
21
|
+
dashboardColumns: 1,
|
|
22
|
+
tiles: [
|
|
23
|
+
{ kind: "text", name: "intro", markdown: "Layout **intro**" },
|
|
24
|
+
{ kind: "query", query: "orders -> by_month", label: "Monthly" },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
} as RawNotebook;
|
|
28
|
+
|
|
29
|
+
const TITLED = {
|
|
30
|
+
...LAYOUT,
|
|
31
|
+
dashboard: {
|
|
32
|
+
...LAYOUT.dashboard,
|
|
33
|
+
title: "Tour title",
|
|
34
|
+
description: "Tour **description**",
|
|
35
|
+
},
|
|
36
|
+
} as RawNotebook;
|
|
37
|
+
|
|
38
|
+
let served: RawNotebook = LAYOUT;
|
|
39
|
+
const getNotebook = mock(() => Promise.resolve({ data: served }));
|
|
40
|
+
const executeNotebookCell = mock(() => pending());
|
|
41
|
+
const executeQueryModel = mock(
|
|
42
|
+
(_env: string, _pkg: string, _path: string, _request: unknown) => pending(),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
mockServerProvider({
|
|
46
|
+
notebooks: { getNotebook, executeNotebookCell },
|
|
47
|
+
models: { executeQueryModel, getModel: () => pending() },
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const { default: Notebook } = await import("./Notebook");
|
|
51
|
+
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
served = LAYOUT;
|
|
54
|
+
clearCache();
|
|
55
|
+
executeNotebookCell.mockClear();
|
|
56
|
+
executeQueryModel.mockClear();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("renders a layout notebook as a bare dashboard grid", async () => {
|
|
60
|
+
const { container } = render(
|
|
61
|
+
<Notebook resourceUri="publisher://environments/env/packages/pkg/models/notebooks/tour.malloy" />,
|
|
62
|
+
{ wrapper: serverWrapper },
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect((await screen.findByText("intro")).tagName).toBe("STRONG");
|
|
66
|
+
expect(container.querySelector('[data-chrome="card"]')).toBeNull();
|
|
67
|
+
// Tiles run through the model query endpoint, not the cell endpoint.
|
|
68
|
+
await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
|
|
69
|
+
expect(executeQueryModel.mock.calls[0]?.[2]).toBe("notebooks/tour.malloy");
|
|
70
|
+
expect(executeNotebookCell).not.toHaveBeenCalled();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("shows a layout notebook's title and description above its tiles", async () => {
|
|
74
|
+
served = TITLED;
|
|
75
|
+
render(
|
|
76
|
+
<Notebook resourceUri="publisher://environments/env/packages/pkg/models/notebooks/tour.malloy" />,
|
|
77
|
+
{ wrapper: serverWrapper },
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
expect(
|
|
81
|
+
(await screen.findByRole("heading", { name: "Tour title" })).tagName,
|
|
82
|
+
).toBe("H5");
|
|
83
|
+
expect((await screen.findByText("description")).tagName).toBe("STRONG");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("draws no header for a layout notebook with no title or description", async () => {
|
|
87
|
+
render(
|
|
88
|
+
<Notebook resourceUri="publisher://environments/env/packages/pkg/models/notebooks/tour.malloy" />,
|
|
89
|
+
{ wrapper: serverWrapper },
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
await screen.findByText("intro");
|
|
93
|
+
expect(screen.queryByRole("heading", { name: "tour" })).toBeNull();
|
|
94
|
+
});
|
|
@@ -2,17 +2,19 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import "@malloydata/malloy-explorer/styles.css";
|
|
5
|
-
import { Stack, Typography } from "@mui/material";
|
|
5
|
+
import { Box, Stack, Typography } from "@mui/material";
|
|
6
6
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
7
|
import { planRun } from "./runPlan";
|
|
8
8
|
import { RawNotebook } from "../../client";
|
|
9
9
|
import { GivenValue } from "../../hooks/givenValue";
|
|
10
10
|
import { useDocumentControls } from "../../hooks/useDocumentControls";
|
|
11
11
|
import { useModelGivens } from "../../hooks/useModelGivens";
|
|
12
|
+
import { GIVEN_SETTLE_MS } from "../../hooks/useSettled";
|
|
12
13
|
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
13
14
|
import { parseResourceUri } from "../../utils/formatting";
|
|
14
15
|
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
15
16
|
import type { NavigationClick } from "../click_helper";
|
|
17
|
+
import { DashboardProse, DashboardView } from "../Dashboard/DashboardView";
|
|
16
18
|
import type { DrillNavigation } from "../drill";
|
|
17
19
|
import { GivensPanel } from "../given";
|
|
18
20
|
import { givensToParams, givensToRequest } from "../given/paramCodec";
|
|
@@ -26,19 +28,6 @@ import { EnhancedNotebookCell } from "./types";
|
|
|
26
28
|
// Maximum number of concurrent cell executions to avoid overwhelming the server
|
|
27
29
|
const MAX_CONCURRENT = 4;
|
|
28
30
|
|
|
29
|
-
/**
|
|
30
|
-
* How long a changed parameter has to stay changed before the notebook runs.
|
|
31
|
-
*
|
|
32
|
-
* Aborting the superseded run is not enough on its own: an abort cancels the
|
|
33
|
-
* HTTP request, but the cells already dispatched have reached the server and go
|
|
34
|
-
* on compiling and running against the customer's warehouse, and their answers
|
|
35
|
-
* are then thrown away. So autorun on a text control put one wave of doomed
|
|
36
|
-
* queries on that warehouse per keystroke. `origin/main` bounded the load by
|
|
37
|
-
* refusing to start a second run at all, which dropped the newest values;
|
|
38
|
-
* waiting for the value to settle bounds it without making that trade.
|
|
39
|
-
*/
|
|
40
|
-
const GIVEN_SETTLE_MS = 400;
|
|
41
|
-
|
|
42
31
|
/**
|
|
43
32
|
* The server's own explanation of why a cell would not run.
|
|
44
33
|
*
|
|
@@ -108,8 +97,69 @@ interface NotebookProps {
|
|
|
108
97
|
onDrillNavigate?: (target: DrillNavigation, event?: MouseEvent) => void;
|
|
109
98
|
}
|
|
110
99
|
|
|
100
|
+
/** The raw notebook, one cache entry per URI however many components ask. */
|
|
101
|
+
function useNotebookQuery(resourceUri: string) {
|
|
102
|
+
const { apiClients } = useServer();
|
|
103
|
+
const {
|
|
104
|
+
environmentName,
|
|
105
|
+
packageName,
|
|
106
|
+
versionId,
|
|
107
|
+
modelPath: notebookPath,
|
|
108
|
+
} = parseResourceUri(resourceUri);
|
|
109
|
+
return useQueryWithApiError<RawNotebook>({
|
|
110
|
+
queryKey: [resourceUri],
|
|
111
|
+
queryFn: async () => {
|
|
112
|
+
const response = await apiClients.notebooks.getNotebook(
|
|
113
|
+
environmentName,
|
|
114
|
+
packageName,
|
|
115
|
+
notebookPath,
|
|
116
|
+
versionId,
|
|
117
|
+
);
|
|
118
|
+
return response.data;
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
111
123
|
// Requires PackageProvider
|
|
112
|
-
export default function Notebook({
|
|
124
|
+
export default function Notebook(props: NotebookProps) {
|
|
125
|
+
const { data: notebook } = useNotebookQuery(props.resourceUri);
|
|
126
|
+
// A notebook written as a tile layout renders as a one-column dashboard.
|
|
127
|
+
if (notebook?.dashboard) {
|
|
128
|
+
const { environmentName, packageName, versionId, modelPath } =
|
|
129
|
+
parseResourceUri(props.resourceUri);
|
|
130
|
+
const { title, description } = notebook.dashboard;
|
|
131
|
+
return (
|
|
132
|
+
<CleanNotebookContainer>
|
|
133
|
+
<CleanNotebookSection>
|
|
134
|
+
{/* chrome="none" drops the view's own header, so the prose is drawn here. */}
|
|
135
|
+
{(title || description) && (
|
|
136
|
+
<Box sx={{ mb: 2 }}>
|
|
137
|
+
<DashboardProse
|
|
138
|
+
title={title ?? ""}
|
|
139
|
+
{...(description ? { description } : {})}
|
|
140
|
+
/>
|
|
141
|
+
</Box>
|
|
142
|
+
)}
|
|
143
|
+
<DashboardView
|
|
144
|
+
manifest={notebook.dashboard}
|
|
145
|
+
environmentName={environmentName}
|
|
146
|
+
packageName={packageName}
|
|
147
|
+
versionId={versionId}
|
|
148
|
+
documentName={modelPath}
|
|
149
|
+
givens={props.givens}
|
|
150
|
+
onGivensChange={props.onGivensChange}
|
|
151
|
+
onNavigate={props.onDrillNavigate}
|
|
152
|
+
maxResultSize={props.maxResultSize}
|
|
153
|
+
chrome="none"
|
|
154
|
+
/>
|
|
155
|
+
</CleanNotebookSection>
|
|
156
|
+
</CleanNotebookContainer>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
return <CellNotebook {...props} />;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function CellNotebook({
|
|
113
163
|
resourceUri,
|
|
114
164
|
maxResultSize = 0,
|
|
115
165
|
givens,
|
|
@@ -131,18 +181,7 @@ export default function Notebook({
|
|
|
131
181
|
isSuccess,
|
|
132
182
|
isError,
|
|
133
183
|
error,
|
|
134
|
-
} =
|
|
135
|
-
queryKey: [resourceUri],
|
|
136
|
-
queryFn: async () => {
|
|
137
|
-
const response = await apiClients.notebooks.getNotebook(
|
|
138
|
-
environmentName,
|
|
139
|
-
packageName,
|
|
140
|
-
notebookPath,
|
|
141
|
-
versionId,
|
|
142
|
-
);
|
|
143
|
-
return response.data;
|
|
144
|
-
},
|
|
145
|
-
});
|
|
184
|
+
} = useNotebookQuery(resourceUri);
|
|
146
185
|
|
|
147
186
|
// State to store executed cells with results
|
|
148
187
|
const [enhancedCells, setEnhancedCells] = useState<EnhancedNotebookCell[]>(
|