@malloy-publisher/sdk 0.0.382-dev → 0.2.0
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/README.md +115 -95
- package/TREE_SHAKING.md +16 -11
- package/bunfig.toml +7 -0
- package/dist/ServerProvider-CTopDUWW.cjs.js +1 -0
- package/dist/ServerProvider-DUFPY6Rv.es.js +4072 -0
- package/dist/client/api.d.ts +3718 -1507
- 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 +85 -59
- package/dist/components/Connections/EditConnectionDialog.d.ts +2 -1
- package/dist/components/Connections/common.d.ts +8 -2
- package/dist/components/Dashboard/Dashboard.d.ts +49 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +48 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/DataAppViewer/DataAppViewer.d.ts +23 -0
- package/dist/components/DataAppViewer/index.d.ts +1 -0
- package/dist/components/Environment/Environment.d.ts +6 -0
- package/dist/components/Environment/index.d.ts +2 -0
- package/dist/components/Home/AddEnvironmentDialog.d.ts +1 -0
- package/dist/components/Home/DeleteEnvironmentDialog.d.ts +5 -0
- package/dist/components/Home/EditEnvironmentDialog.d.ts +7 -0
- package/dist/components/Home/Home.d.ts +2 -2
- package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +14 -0
- package/dist/components/Materializations/CreateMaterializationDialog.d.ts +10 -0
- package/dist/components/Materializations/DeleteMaterializationDialog.d.ts +7 -0
- package/dist/components/Materializations/EnvironmentMaterializations.d.ts +7 -0
- package/dist/components/Materializations/ManifestView.d.ts +13 -0
- package/dist/components/Materializations/MaterializationDetailDialog.d.ts +9 -0
- package/dist/components/Materializations/MaterializationRunsList.d.ts +15 -0
- package/dist/components/Materializations/Materializations.d.ts +7 -0
- package/dist/components/Materializations/ScheduleCard.d.ts +20 -0
- package/dist/components/Materializations/SectionLabel.d.ts +10 -0
- package/dist/components/Materializations/SetScheduleDialog.d.ts +11 -0
- package/dist/components/Materializations/TriggerChip.d.ts +10 -0
- package/dist/components/Materializations/cron.d.ts +23 -0
- package/dist/components/Materializations/index.d.ts +2 -0
- package/dist/components/Materializations/utils.d.ts +46 -0
- package/dist/components/Notebook/Notebook.d.ts +47 -4
- package/dist/components/Notebook/NotebookCell.d.ts +37 -1
- package/dist/components/Notebook/runPlan.d.ts +29 -0
- package/dist/components/Notebook/types.d.ts +10 -0
- package/dist/components/Package/ContentTypeIcon.d.ts +31 -0
- package/dist/components/Package/Package.d.ts +1 -4
- package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
- package/dist/components/RenderedResult/ResultContainer.d.ts +5 -1
- package/dist/components/RenderedResult/renderLogs.d.ts +6 -0
- package/dist/components/ResultsDialog.d.ts +6 -1
- package/dist/components/ServerProvider.d.ts +28 -4
- package/dist/components/click_helper.d.ts +10 -1
- package/dist/components/drill/index.d.ts +3 -0
- package/dist/components/drill/markDrillableCells.d.ts +55 -0
- package/dist/components/drill/resolveDrill.d.ts +139 -0
- package/dist/components/drill/useDrill.d.ts +63 -0
- package/dist/components/given/GivenInput.d.ts +52 -0
- package/dist/components/given/GivensPanel.d.ts +47 -0
- package/dist/components/given/filterValue.d.ts +97 -0
- package/dist/components/given/index.d.ts +2 -0
- package/dist/components/given/paramCodec.d.ts +60 -0
- package/dist/components/given/utils.d.ts +17 -0
- package/dist/components/highlighter.d.ts +6 -1
- package/dist/components/index.d.ts +7 -2
- package/dist/components/styles.d.ts +47 -0
- package/dist/constants/docLinks.d.ts +12 -0
- package/dist/{core-YNpOLuB1.cjs.js → core-hLahnv0W.cjs.js} +1 -1
- package/dist/{core-CjeTkq8O.es.js → core-lb28vQkR.es.js} +1 -1
- package/dist/github-dark-BKL9xNgN.cjs.js +1 -0
- package/dist/github-dark-DenFmJkN.es.js +4 -0
- package/dist/hooks/givenValue.d.ts +10 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/useDimensionFiltersFromSpec.d.ts +3 -3
- package/dist/hooks/useDimensionFiltersQuery.d.ts +3 -3
- package/dist/hooks/useDimensionalFilterRangeData.d.ts +4 -4
- package/dist/hooks/useGivensState.d.ts +64 -0
- package/dist/hooks/useModelGivens.d.ts +10 -0
- package/dist/hooks/useSuggestOptions.d.ts +78 -0
- package/dist/index-DvEanVgc.cjs.js +339 -0
- package/dist/{index-DRDu9kIV.es.js → index-txw04ZbN.es.js} +40531 -27964
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.es.js +79 -48
- package/dist/malloy-explorer.css +12 -1
- package/dist/sdk.css +1 -1
- package/dist/theme/ThemeContext.d.ts +45 -0
- package/dist/theme/buildMalloyExplicitTheme.d.ts +34 -0
- package/dist/theme/buildTableCssVars.d.ts +25 -0
- package/dist/theme/buildVegaThemeOverride.d.ts +16 -0
- package/dist/theme/defaults.d.ts +7 -0
- package/dist/theme/index.d.ts +8 -0
- package/dist/theme/keys.d.ts +20 -0
- package/dist/theme/readChartAnnotations.d.ts +23 -0
- package/dist/theme/resolveTheme.d.ts +22 -0
- package/dist/theme/types.d.ts +70 -0
- package/dist/utils/dataAppEmbed.d.ts +44 -0
- package/dist/utils/formatting.d.ts +1 -1
- package/dist/utils/malloyString.d.ts +7 -0
- package/dist/utils/parsing.d.ts +2 -2
- package/dist/utils/queryClient.d.ts +5 -0
- package/package.json +19 -8
- package/src/client-entry.ts +3 -0
- package/src/components/AnalyzePackageButton.tsx +9 -3
- package/src/components/ApiErrorDisplay.tsx +3 -0
- package/src/components/Connections/AddConnectionDialog.tsx +30 -2
- package/src/components/Connections/DeleteConnectionDialog.tsx +14 -3
- package/src/components/Connections/EditConnectionDialog.tsx +33 -4
- package/src/components/Connections/common.ts +64 -1
- package/src/components/DOMElement/DOMElement.tsx +3 -0
- package/src/components/DOMElement/index.ts +3 -0
- package/src/components/Dashboard/Dashboard.tsx +398 -0
- package/src/components/Dashboard/DashboardTile.tsx +153 -0
- package/src/components/Dashboard/index.ts +5 -0
- package/src/components/DataAppViewer/DataAppViewer.tsx +214 -0
- package/src/components/DataAppViewer/index.ts +4 -0
- package/src/components/{Project → Environment}/About.tsx +11 -4
- package/src/components/Environment/AddPackageDialog.tsx +202 -0
- package/src/components/{Project → Environment}/ConnectionExplorer.tsx +17 -14
- package/src/components/Environment/Connections.tsx +391 -0
- package/src/components/{Project → Environment}/DeletePackageDialog.tsx +8 -4
- package/src/components/{Project → Environment}/EditPackageDialog.tsx +21 -13
- package/src/components/Environment/Environment.tsx +89 -0
- package/src/components/Environment/Packages.tsx +206 -0
- package/src/components/Environment/index.ts +5 -0
- package/src/components/Home/{AddProjectDialog.tsx → AddEnvironmentDialog.tsx} +25 -19
- package/src/components/Home/{DeleteProjectDialog.tsx → DeleteEnvironmentDialog.tsx} +20 -15
- package/src/components/Home/{EditProjectDialog.tsx → EditEnvironmentDialog.tsx} +35 -28
- package/src/components/Home/Home.tsx +386 -408
- package/src/components/Home/index.ts +3 -0
- package/src/components/Loading.tsx +3 -0
- package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +179 -0
- package/src/components/Materializations/CreateMaterializationDialog.tsx +112 -0
- package/src/components/Materializations/DeleteMaterializationDialog.tsx +109 -0
- package/src/components/Materializations/EnvironmentMaterializations.tsx +267 -0
- package/src/components/Materializations/ManifestView.tsx +87 -0
- package/src/components/Materializations/MaterializationDetailDialog.tsx +259 -0
- package/src/components/Materializations/MaterializationRunsList.tsx +256 -0
- package/src/components/Materializations/Materializations.tsx +355 -0
- package/src/components/Materializations/ScheduleCard.tsx +231 -0
- package/src/components/Materializations/SectionLabel.tsx +30 -0
- package/src/components/Materializations/SetScheduleDialog.tsx +162 -0
- package/src/components/Materializations/TriggerChip.tsx +44 -0
- package/src/components/Materializations/cron.ts +124 -0
- package/src/components/Materializations/index.ts +5 -0
- package/src/components/Materializations/utils.ts +145 -0
- package/src/components/Model/Model.tsx +44 -2
- package/src/components/Model/ModelCell.tsx +14 -5
- package/src/components/Model/ModelExplorer.tsx +3 -0
- package/src/components/Model/ModelExplorerDialog.tsx +4 -1
- package/src/components/Model/SourcesExplorer.tsx +9 -6
- package/src/components/Model/index.ts +3 -0
- package/src/components/Model/useModelData.ts +6 -3
- package/src/components/Notebook/Notebook.tsx +475 -339
- package/src/components/Notebook/NotebookCell.tsx +264 -25
- package/src/components/Notebook/index.ts +3 -0
- package/src/components/Notebook/runPlan.spec.ts +155 -0
- package/src/components/Notebook/runPlan.ts +67 -0
- package/src/components/Notebook/types.ts +14 -0
- package/src/components/Package/ContentTypeIcon.spec.ts +91 -0
- package/src/components/Package/ContentTypeIcon.tsx +177 -0
- package/src/components/Package/FileTreeView.tsx +3 -0
- package/src/components/Package/Models.tsx +7 -4
- package/src/components/Package/Package.tsx +666 -59
- package/src/components/Package/index.ts +3 -0
- package/src/components/QueryResult/QueryResult.tsx +17 -8
- package/src/components/QueryResult/index.ts +3 -0
- package/src/components/RenderedResult/RenderedResult.tsx +685 -67
- package/src/components/RenderedResult/ResultContainer.tsx +71 -2
- package/src/components/RenderedResult/index.ts +3 -0
- package/src/components/RenderedResult/renderLogs.spec.ts +58 -0
- package/src/components/RenderedResult/renderLogs.ts +43 -0
- package/src/components/ResultsDialog.tsx +13 -1
- package/src/components/ServerProvider.tsx +175 -51
- package/src/components/Workbook/BrowserWorkbookStorage.ts +3 -0
- package/src/components/Workbook/EditableMalloyCell.tsx +3 -0
- package/src/components/Workbook/ModelPicker.tsx +7 -4
- package/src/components/Workbook/MutableCell.tsx +10 -5
- package/src/components/Workbook/Workbook.tsx +8 -5
- package/src/components/Workbook/WorkbookList.tsx +3 -0
- package/src/components/Workbook/WorkbookManager.ts +3 -0
- package/src/components/Workbook/WorkbookStorage.ts +3 -0
- package/src/components/Workbook/WorkbookStorageProvider.tsx +3 -0
- package/src/components/Workbook/index.ts +3 -0
- package/src/components/click_helper.ts +17 -1
- package/src/components/drill/index.ts +28 -0
- package/src/components/drill/markDrillableCells.dom.spec.ts +313 -0
- package/src/components/drill/markDrillableCells.spec.ts +109 -0
- package/src/components/drill/markDrillableCells.ts +314 -0
- package/src/components/drill/resolveDrill.spec.ts +449 -0
- package/src/components/drill/resolveDrill.ts +375 -0
- package/src/components/drill/useDrill.tsx +203 -0
- package/src/components/filter/DimensionFilter.tsx +3 -0
- package/src/components/filter/index.ts +3 -0
- package/src/components/filter/utils.ts +16 -5
- package/src/components/given/GivenInput.spec.tsx +689 -0
- package/src/components/given/GivenInput.tsx +801 -0
- package/src/components/given/GivensPanel.spec.tsx +175 -0
- package/src/components/given/GivensPanel.tsx +195 -0
- package/src/components/given/filterValue.spec.ts +364 -0
- package/src/components/given/filterValue.ts +207 -0
- package/src/components/given/index.ts +9 -0
- package/src/components/given/paramCodec.spec.ts +857 -0
- package/src/components/given/paramCodec.ts +483 -0
- package/src/components/given/utils.spec.ts +60 -0
- package/src/components/given/utils.ts +79 -0
- package/src/components/highlighter.ts +22 -5
- package/src/components/index.ts +10 -2
- package/src/components/styles.ts +82 -33
- package/src/constants/docLinks.spec.ts +54 -0
- package/src/constants/docLinks.ts +46 -0
- package/src/hooks/givenValue.ts +13 -0
- package/src/hooks/index.ts +13 -0
- package/src/hooks/useDimensionFilters.ts +4 -7
- package/src/hooks/useDimensionFiltersFromSpec.ts +8 -5
- package/src/hooks/useDimensionFiltersQuery.ts +10 -13
- package/src/hooks/useDimensionalFilterRangeData.ts +11 -14
- package/src/hooks/useGivensState.spec.ts +449 -0
- package/src/hooks/useGivensState.ts +340 -0
- package/src/hooks/useModelGivens.ts +29 -0
- package/src/hooks/useQueryWithApiError.ts +3 -0
- package/src/hooks/useRawQueryData.ts +6 -3
- package/src/hooks/useSuggestOptions.spec.ts +112 -0
- package/src/hooks/useSuggestOptions.ts +263 -0
- package/src/index.ts +10 -1
- package/src/react-app-env.d.ts +3 -0
- package/src/theme/ThemeContext.tsx +86 -0
- package/src/theme/buildMalloyExplicitTheme.ts +61 -0
- package/src/theme/buildTableCssVars.spec.ts +67 -0
- package/src/theme/buildTableCssVars.ts +67 -0
- package/src/theme/buildVegaThemeOverride.spec.ts +56 -0
- package/src/theme/buildVegaThemeOverride.ts +47 -0
- package/src/theme/defaults.ts +78 -0
- package/src/theme/index.ts +11 -0
- package/src/theme/keys.ts +32 -0
- package/src/theme/readChartAnnotations.spec.ts +58 -0
- package/src/theme/readChartAnnotations.ts +69 -0
- package/src/theme/resolveTheme.spec.ts +160 -0
- package/src/theme/resolveTheme.ts +121 -0
- package/src/theme/types.ts +79 -0
- package/src/utils/dataAppEmbed.spec.ts +63 -0
- package/src/utils/dataAppEmbed.ts +84 -0
- package/src/utils/formatting.spec.ts +25 -21
- package/src/utils/formatting.ts +11 -7
- package/src/utils/malloyString.spec.ts +24 -0
- package/src/utils/malloyString.ts +12 -0
- package/src/utils/parsing.spec.ts +26 -19
- package/src/utils/parsing.ts +11 -6
- package/src/utils/queryClient.ts +17 -0
- package/test/README.md +141 -0
- package/test/setup.ts +29 -0
- package/tsconfig.json +12 -1
- package/tsconfig.spec.json +22 -0
- package/vite.config.ts +3 -0
- package/dist/ServerProvider-lOQXDlqB.cjs.js +0 -1
- package/dist/ServerProvider-on-8FH5Z.es.js +0 -3060
- package/dist/components/Home/AddProjectDialog.d.ts +0 -1
- package/dist/components/Home/DeleteProjectDialog.d.ts +0 -5
- package/dist/components/Home/EditProjectDialog.d.ts +0 -7
- package/dist/components/Package/Config.d.ts +0 -5
- package/dist/components/Package/Databases.d.ts +0 -5
- package/dist/components/Package/Notebooks.d.ts +0 -6
- package/dist/components/Project/Project.d.ts +0 -6
- package/dist/components/Project/index.d.ts +0 -2
- package/dist/index-BOLBP6_i.cjs.js +0 -233
- package/src/components/Package/Config.tsx +0 -97
- package/src/components/Package/Connections.tsx +0 -373
- package/src/components/Package/Databases.tsx +0 -228
- package/src/components/Package/Notebooks.tsx +0 -77
- package/src/components/Project/AddPackageDialog.tsx +0 -159
- package/src/components/Project/Packages.tsx +0 -191
- package/src/components/Project/Project.tsx +0 -52
- package/src/components/Project/index.ts +0 -2
- /package/dist/components/{Project → Environment}/About.d.ts +0 -0
- /package/dist/components/{Project → Environment}/AddPackageDialog.d.ts +0 -0
- /package/dist/components/{Project → Environment}/ConnectionExplorer.d.ts +0 -0
- /package/dist/components/{Package → Environment}/Connections.d.ts +0 -0
- /package/dist/components/{Project → Environment}/DeletePackageDialog.d.ts +0 -0
- /package/dist/components/{Project → Environment}/EditPackageDialog.d.ts +0 -0
- /package/dist/components/{Project → Environment}/Packages.d.ts +0 -0
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
1
4
|
import CloseIcon from "@mui/icons-material/Close";
|
|
2
5
|
import CodeIcon from "@mui/icons-material/Code";
|
|
3
6
|
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
|
|
@@ -10,6 +13,7 @@ import {
|
|
|
10
13
|
DialogContent,
|
|
11
14
|
DialogTitle,
|
|
12
15
|
IconButton,
|
|
16
|
+
LinearProgress,
|
|
13
17
|
Snackbar,
|
|
14
18
|
Stack,
|
|
15
19
|
Tooltip,
|
|
@@ -17,14 +21,25 @@ import {
|
|
|
17
21
|
} from "@mui/material";
|
|
18
22
|
import Markdown from "markdown-to-jsx";
|
|
19
23
|
import React, { useEffect, useState } from "react";
|
|
24
|
+
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
25
|
+
import { parseResourceUri } from "../../utils/formatting";
|
|
20
26
|
import { highlight } from "../highlighter";
|
|
21
27
|
import { ModelExplorerDialog } from "../Model/ModelExplorerDialog";
|
|
28
|
+
import type { NavigationClick } from "../click_helper";
|
|
29
|
+
import { useDrill, type DrillNavigation } from "../drill";
|
|
22
30
|
import { createEmbeddedQueryResult } from "../QueryResult/QueryResult";
|
|
23
31
|
import ResultContainer from "../RenderedResult/ResultContainer";
|
|
24
32
|
import ResultsDialog from "../ResultsDialog";
|
|
25
33
|
import { CleanMetricCard, CleanNotebookCell } from "../styles";
|
|
26
34
|
import { EnhancedNotebookCell } from "./types";
|
|
27
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Cap for a cell result that lays itself out: a table, mostly. Tall enough for
|
|
38
|
+
* a screenful of rows, after which the cell scrolls rather than the page
|
|
39
|
+
* turning into one long table.
|
|
40
|
+
*/
|
|
41
|
+
const CELL_MAX_HEIGHT = 700;
|
|
42
|
+
|
|
28
43
|
interface NotebookCellProps {
|
|
29
44
|
cell: EnhancedNotebookCell;
|
|
30
45
|
expandCodeCell?: boolean;
|
|
@@ -35,6 +50,119 @@ interface NotebookCellProps {
|
|
|
35
50
|
index: number;
|
|
36
51
|
maxResultSize?: number;
|
|
37
52
|
isExecuting?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* A re-run is coming but has not started, i.e. the given-settle window.
|
|
55
|
+
* Separate from `isExecuting` because the spinner below is gated on
|
|
56
|
+
* `!cell.result`, so on a re-run (where a result IS present) it renders
|
|
57
|
+
* nothing at all, which is exactly the case the settle window needs to
|
|
58
|
+
* signal: the values on screen are already stale.
|
|
59
|
+
*/
|
|
60
|
+
pendingRerun?: boolean;
|
|
61
|
+
// Takes the modifier subset rather than a synthetic event, so a drill click
|
|
62
|
+
// (which the Malloy renderer reports as a DOM event) can navigate without
|
|
63
|
+
// being converted into a React one first.
|
|
64
|
+
onNavigate?: (to: string, event?: NavigationClick) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Applies a `# drill { to=self }` in place, by setting the named parameter
|
|
67
|
+
* on the notebook that owns this cell. Omitted when the notebook declares no
|
|
68
|
+
* givens, which makes a self-drill inert rather than an error.
|
|
69
|
+
*
|
|
70
|
+
* Takes the clicked value unencoded: only the notebook knows the declared
|
|
71
|
+
* type of the given being set, and the encoding depends on it.
|
|
72
|
+
*/
|
|
73
|
+
onDrillSelf?: (given: string, rawValue: unknown) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Whether the owning notebook declares a given, so a `to=self` drill onto it
|
|
76
|
+
* can be honoured. Without it every self-drill reads as clickable and the
|
|
77
|
+
* refusal only shows up in the console.
|
|
78
|
+
*/
|
|
79
|
+
canDrillSelf?: (given: string) => boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Opens a `# drill { to=<dashboard> }` destination, seeded with the clicked
|
|
82
|
+
* value. Distinct from {@link onNavigate}, which routes a markdown link and
|
|
83
|
+
* takes a URL: this one takes a destination and the givens to seed, and only
|
|
84
|
+
* the host knows how to turn those into a route.
|
|
85
|
+
*
|
|
86
|
+
* Omitted on a host with no dashboard route, which makes a cross-dashboard
|
|
87
|
+
* drill inert rather than dead-ended, and removes the affordance with it.
|
|
88
|
+
*/
|
|
89
|
+
onDrillNavigate?: (target: DrillNavigation, event?: MouseEvent) => void;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface NotebookMarkdownLinkProps {
|
|
93
|
+
href?: string;
|
|
94
|
+
title?: string;
|
|
95
|
+
children?: React.ReactNode;
|
|
96
|
+
envName: string;
|
|
97
|
+
pkgName: string;
|
|
98
|
+
sourceDir: string;
|
|
99
|
+
onNavigate?: (to: string, event?: NavigationClick) => void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Links inside a rendered notebook/README are authored relative to the source
|
|
103
|
+
// file (e.g. `spielberg.malloynb`). A plain browser anchor resolves them
|
|
104
|
+
// against the current page URL, which drops the package segment for a README
|
|
105
|
+
// shown at the package route. Resolve relative links against the source file's
|
|
106
|
+
// own directory instead and route them through the SPA. External, hash, and
|
|
107
|
+
// absolute links stay as normal anchors.
|
|
108
|
+
function NotebookMarkdownLink({
|
|
109
|
+
href,
|
|
110
|
+
title,
|
|
111
|
+
children,
|
|
112
|
+
envName,
|
|
113
|
+
pkgName,
|
|
114
|
+
sourceDir,
|
|
115
|
+
onNavigate,
|
|
116
|
+
}: NotebookMarkdownLinkProps) {
|
|
117
|
+
const hasScheme = !!href && /^[a-z][a-z0-9+.-]*:/i.test(href);
|
|
118
|
+
const isInternalRelative =
|
|
119
|
+
!!href && !hasScheme && !href.startsWith("/") && !href.startsWith("#");
|
|
120
|
+
|
|
121
|
+
if (!isInternalRelative || !href) {
|
|
122
|
+
// External, absolute, or hash link: render a normal anchor. Only allow
|
|
123
|
+
// safe schemes so a crafted `javascript:`/`data:` href in a package
|
|
124
|
+
// README (packages can come from untrusted git/S3 sources) cannot run.
|
|
125
|
+
const isUnsafeScheme =
|
|
126
|
+
hasScheme && !/^(https?|mailto|tel):/i.test(href ?? "");
|
|
127
|
+
return (
|
|
128
|
+
<a
|
|
129
|
+
href={isUnsafeScheme ? undefined : href}
|
|
130
|
+
title={title}
|
|
131
|
+
{...(hasScheme
|
|
132
|
+
? { target: "_blank", rel: "noopener noreferrer" }
|
|
133
|
+
: {})}
|
|
134
|
+
>
|
|
135
|
+
{children}
|
|
136
|
+
</a>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Resolve the relative href against the source file's directory (empty for a
|
|
141
|
+
// package-root README) via a dummy origin, which normalizes any `./`/`../`
|
|
142
|
+
// and clamps escapes at the package root, then prefix the package path.
|
|
143
|
+
const resolved = new URL(href, `https://malloy.invalid/${sourceDir}`);
|
|
144
|
+
const packageRelative =
|
|
145
|
+
resolved.pathname.slice(1) + resolved.search + resolved.hash;
|
|
146
|
+
const to = `/${envName}/${pkgName}/${packageRelative}`;
|
|
147
|
+
// With a host router (onNavigate) intercept and route through the SPA.
|
|
148
|
+
// Without one (router-free SDK embedding) the absolute href navigates on
|
|
149
|
+
// its own, so rendering a notebook needs no react-router context.
|
|
150
|
+
return (
|
|
151
|
+
<a
|
|
152
|
+
href={to}
|
|
153
|
+
title={title}
|
|
154
|
+
onClick={
|
|
155
|
+
onNavigate
|
|
156
|
+
? (event) => {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
onNavigate(to, event);
|
|
159
|
+
}
|
|
160
|
+
: undefined
|
|
161
|
+
}
|
|
162
|
+
>
|
|
163
|
+
{children}
|
|
164
|
+
</a>
|
|
165
|
+
);
|
|
38
166
|
}
|
|
39
167
|
|
|
40
168
|
export function NotebookCell({
|
|
@@ -45,6 +173,11 @@ export function NotebookCell({
|
|
|
45
173
|
index,
|
|
46
174
|
maxResultSize,
|
|
47
175
|
isExecuting,
|
|
176
|
+
pendingRerun,
|
|
177
|
+
onNavigate,
|
|
178
|
+
onDrillSelf,
|
|
179
|
+
canDrillSelf,
|
|
180
|
+
onDrillNavigate,
|
|
48
181
|
}: NotebookCellProps) {
|
|
49
182
|
const [codeDialogOpen, setCodeDialogOpen] = React.useState<boolean>(false);
|
|
50
183
|
const [embeddingDialogOpen, setEmbeddingDialogOpen] =
|
|
@@ -60,6 +193,58 @@ export function NotebookCell({
|
|
|
60
193
|
|
|
61
194
|
const [copyMessage, setCopyMessage] = useState("");
|
|
62
195
|
|
|
196
|
+
const { environmentName, packageName, modelPath } =
|
|
197
|
+
parseResourceUri(resourceUri);
|
|
198
|
+
|
|
199
|
+
// `# drill` is declared on a model dimension, so a notebook cell that groups
|
|
200
|
+
// by that dimension is clickable for free: the same resolution, and the
|
|
201
|
+
// same hook, the dashboard viewer uses.
|
|
202
|
+
const { drill, drillMenu } = useDrill({
|
|
203
|
+
// The dashboards route now exists, so a `# drill { to=<dashboard> }` from
|
|
204
|
+
// a notebook cell is honoured: the host turns the destination and its
|
|
205
|
+
// seeded givens into `/{env}/{pkg}/dashboards/<slug>?GIVEN=value`. Passed
|
|
206
|
+
// through rather than built here, because only the host knows its routing.
|
|
207
|
+
//
|
|
208
|
+
// Still optional, and the reason matters: a host without a dashboard
|
|
209
|
+
// route omits it, which makes a named destination non-honorable and
|
|
210
|
+
// removes the AFFORDANCE along with the navigation. That is
|
|
211
|
+
// `markDrillableCells`'s principle, that a destination the surface cannot
|
|
212
|
+
// reach never becomes a link, and it is why this is a prop rather than
|
|
213
|
+
// something the cell assumes.
|
|
214
|
+
//
|
|
215
|
+
// Wiring it also makes `drillMenu` reachable for the first time: a menu
|
|
216
|
+
// opens only for two or more honorable destinations, so until there was a
|
|
217
|
+
// second one every drillable cell applied its filter on the first click.
|
|
218
|
+
onNavigate: onDrillNavigate,
|
|
219
|
+
onSelf: onDrillSelf,
|
|
220
|
+
// Only the notebook knows which givens it declares, and a self-drill onto
|
|
221
|
+
// one it does not is refused. Asking here keeps the affordance honest
|
|
222
|
+
// instead of painting a link whose click only logs a warning.
|
|
223
|
+
canSelf: canDrillSelf,
|
|
224
|
+
// The reader is in a notebook, so `to=self` says so: the drill tag is on
|
|
225
|
+
// a shared model dimension and cannot know which document it fired in.
|
|
226
|
+
selfLabel: "Filter this notebook",
|
|
227
|
+
});
|
|
228
|
+
// Directory of the source file within the package (empty for a package-root
|
|
229
|
+
// README), used to resolve relative links the author wrote against it.
|
|
230
|
+
const sourceDir =
|
|
231
|
+
modelPath && modelPath.includes("/")
|
|
232
|
+
? modelPath.slice(0, modelPath.lastIndexOf("/") + 1)
|
|
233
|
+
: "";
|
|
234
|
+
const markdownOptions = {
|
|
235
|
+
overrides: {
|
|
236
|
+
a: {
|
|
237
|
+
component: NotebookMarkdownLink,
|
|
238
|
+
props: {
|
|
239
|
+
envName: environmentName,
|
|
240
|
+
pkgName: packageName,
|
|
241
|
+
sourceDir,
|
|
242
|
+
onNavigate,
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
|
|
63
248
|
// Regex to extract imported names from import statements
|
|
64
249
|
const IMPORT_NAMES_REGEX = /import\s*\{([^}]+)\}\s*from\s*['"`][^'"`]+['"`]/;
|
|
65
250
|
|
|
@@ -130,18 +315,19 @@ export function NotebookCell({
|
|
|
130
315
|
resourceUri: resourceUri,
|
|
131
316
|
});
|
|
132
317
|
|
|
318
|
+
const { mode } = usePublisherTheme();
|
|
133
319
|
useEffect(() => {
|
|
134
320
|
if (cell.type === "code")
|
|
135
|
-
highlight(filterMalloyCode(cell.text), "malloy").then((code) => {
|
|
321
|
+
highlight(filterMalloyCode(cell.text), "malloy", mode).then((code) => {
|
|
136
322
|
setHighlightedMalloyCode(code);
|
|
137
323
|
});
|
|
138
|
-
}, [cell]);
|
|
324
|
+
}, [cell, mode]);
|
|
139
325
|
|
|
140
326
|
useEffect(() => {
|
|
141
|
-
highlight(queryResultCodeSnippet, "typescript").then((code) => {
|
|
327
|
+
highlight(queryResultCodeSnippet, "typescript", mode).then((code) => {
|
|
142
328
|
setHighlightedEmbedCode(code);
|
|
143
329
|
});
|
|
144
|
-
}, [queryResultCodeSnippet]);
|
|
330
|
+
}, [queryResultCodeSnippet, mode]);
|
|
145
331
|
|
|
146
332
|
const copyToClipboard = () => {
|
|
147
333
|
const url = window.location.href;
|
|
@@ -155,10 +341,10 @@ export function NotebookCell({
|
|
|
155
341
|
(cell.type === "markdown" && (
|
|
156
342
|
<CleanNotebookCell>
|
|
157
343
|
<Box
|
|
158
|
-
sx={{
|
|
344
|
+
sx={(theme) => ({
|
|
159
345
|
"& h1, & h2, & h3, & h4, & h5, & h6": {
|
|
160
346
|
fontWeight: "600",
|
|
161
|
-
color:
|
|
347
|
+
color: theme.palette.text.primary,
|
|
162
348
|
marginBottom: "8px",
|
|
163
349
|
marginTop: "16px",
|
|
164
350
|
},
|
|
@@ -166,13 +352,13 @@ export function NotebookCell({
|
|
|
166
352
|
"& h2": { fontSize: "24px" },
|
|
167
353
|
"& h3": { fontSize: "20px" },
|
|
168
354
|
"& p": {
|
|
169
|
-
color:
|
|
355
|
+
color: theme.palette.text.primary,
|
|
170
356
|
lineHeight: "1.7",
|
|
171
357
|
marginBottom: "8px",
|
|
172
358
|
fontSize: "16px",
|
|
173
359
|
},
|
|
174
360
|
"& ul, & ol": {
|
|
175
|
-
color:
|
|
361
|
+
color: theme.palette.text.primary,
|
|
176
362
|
lineHeight: "1.7",
|
|
177
363
|
marginBottom: "8px",
|
|
178
364
|
fontSize: "16px",
|
|
@@ -180,7 +366,7 @@ export function NotebookCell({
|
|
|
180
366
|
"& li": {
|
|
181
367
|
marginBottom: "4px",
|
|
182
368
|
},
|
|
183
|
-
}}
|
|
369
|
+
})}
|
|
184
370
|
>
|
|
185
371
|
{index === 0 ? (
|
|
186
372
|
<Stack
|
|
@@ -188,12 +374,12 @@ export function NotebookCell({
|
|
|
188
374
|
alignItems="flex-start"
|
|
189
375
|
justifyContent="space-between"
|
|
190
376
|
>
|
|
191
|
-
<Markdown>{cell.text}</Markdown>
|
|
377
|
+
<Markdown options={markdownOptions}>{cell.text}</Markdown>
|
|
192
378
|
<Tooltip title="Click to copy link">
|
|
193
379
|
<LinkOutlinedIcon
|
|
194
380
|
sx={{
|
|
195
381
|
fontSize: "24px",
|
|
196
|
-
color: "
|
|
382
|
+
color: "text.secondary",
|
|
197
383
|
cursor: "pointer",
|
|
198
384
|
marginTop: "26px",
|
|
199
385
|
}}
|
|
@@ -202,7 +388,7 @@ export function NotebookCell({
|
|
|
202
388
|
</Tooltip>
|
|
203
389
|
</Stack>
|
|
204
390
|
) : (
|
|
205
|
-
<Markdown>{cell.text}</Markdown>
|
|
391
|
+
<Markdown options={markdownOptions}>{cell.text}</Markdown>
|
|
206
392
|
)}
|
|
207
393
|
<Snackbar
|
|
208
394
|
open={copyMessage !== ""}
|
|
@@ -270,7 +456,17 @@ export function NotebookCell({
|
|
|
270
456
|
onClick={() => setSourcesDialogOpen(true)}
|
|
271
457
|
>
|
|
272
458
|
<SearchIcon
|
|
273
|
-
sx={{
|
|
459
|
+
sx={{
|
|
460
|
+
fontSize: "18px",
|
|
461
|
+
// grey.700 is a dark warm grey
|
|
462
|
+
// that stays legible on the
|
|
463
|
+
// white-ish IconButton in both
|
|
464
|
+
// light and dark mode. The
|
|
465
|
+
// button background is
|
|
466
|
+
// hardcoded white, so the icon
|
|
467
|
+
// must be hardcoded dark.
|
|
468
|
+
color: "grey.700",
|
|
469
|
+
}}
|
|
274
470
|
/>
|
|
275
471
|
</IconButton>
|
|
276
472
|
)}
|
|
@@ -308,15 +504,15 @@ export function NotebookCell({
|
|
|
308
504
|
Malloy Code
|
|
309
505
|
<IconButton
|
|
310
506
|
onClick={() => setCodeDialogOpen(false)}
|
|
311
|
-
sx={{ color: "
|
|
507
|
+
sx={{ color: "text.secondary" }}
|
|
312
508
|
>
|
|
313
509
|
<CloseIcon />
|
|
314
510
|
</IconButton>
|
|
315
511
|
</DialogTitle>
|
|
316
512
|
<DialogContent>
|
|
317
513
|
<Box
|
|
318
|
-
sx={{
|
|
319
|
-
border:
|
|
514
|
+
sx={(theme) => ({
|
|
515
|
+
border: `1px solid ${theme.palette.divider}`,
|
|
320
516
|
borderRadius: "8px",
|
|
321
517
|
padding: "16px",
|
|
322
518
|
fontFamily: "monospace",
|
|
@@ -324,8 +520,9 @@ export function NotebookCell({
|
|
|
324
520
|
lineHeight: "1.5",
|
|
325
521
|
overflow: "auto",
|
|
326
522
|
maxHeight: "70vh",
|
|
327
|
-
backgroundColor:
|
|
328
|
-
|
|
523
|
+
backgroundColor: theme.palette.background.paper,
|
|
524
|
+
color: theme.palette.text.primary,
|
|
525
|
+
})}
|
|
329
526
|
>
|
|
330
527
|
<pre
|
|
331
528
|
className="code-display"
|
|
@@ -357,7 +554,7 @@ export function NotebookCell({
|
|
|
357
554
|
Embeddable Code
|
|
358
555
|
<IconButton
|
|
359
556
|
onClick={() => setEmbeddingDialogOpen(false)}
|
|
360
|
-
sx={{ color: "
|
|
557
|
+
sx={{ color: "text.secondary" }}
|
|
361
558
|
>
|
|
362
559
|
<CloseIcon />
|
|
363
560
|
</IconButton>
|
|
@@ -388,7 +585,7 @@ export function NotebookCell({
|
|
|
388
585
|
width: "24px",
|
|
389
586
|
height: "24px",
|
|
390
587
|
marginLeft: "8px",
|
|
391
|
-
color: "
|
|
588
|
+
color: "text.secondary",
|
|
392
589
|
}}
|
|
393
590
|
onClick={() => {
|
|
394
591
|
navigator.clipboard.writeText(
|
|
@@ -409,11 +606,16 @@ export function NotebookCell({
|
|
|
409
606
|
onClose={() => setResultsDialogOpen(false)}
|
|
410
607
|
result={cell.result || ""}
|
|
411
608
|
title="Results"
|
|
609
|
+
drill={drill}
|
|
412
610
|
/>
|
|
413
611
|
|
|
414
612
|
{/* Loading state for executing code cells (not import cells) */}
|
|
415
613
|
{isExecuting &&
|
|
416
614
|
!cell.result &&
|
|
615
|
+
/* A failed cell keeps `isExecuting` (it is notebook-wide, not
|
|
616
|
+
per cell), so without this the error card below renders under
|
|
617
|
+
a spinner and the cell reads as still loading. */
|
|
618
|
+
!cell.error &&
|
|
417
619
|
!hasValidImport &&
|
|
418
620
|
!(cell.newSources && cell.newSources.length > 0) && (
|
|
419
621
|
<CleanMetricCard
|
|
@@ -428,6 +630,33 @@ export function NotebookCell({
|
|
|
428
630
|
</CleanMetricCard>
|
|
429
631
|
)}
|
|
430
632
|
|
|
633
|
+
{!cell.result && cell.error && (
|
|
634
|
+
<CleanMetricCard sx={{ p: 2 }}>
|
|
635
|
+
<Typography variant="body2" sx={{ color: "error.main" }}>
|
|
636
|
+
This cell could not be run.
|
|
637
|
+
</Typography>
|
|
638
|
+
<Typography
|
|
639
|
+
variant="body2"
|
|
640
|
+
component="pre"
|
|
641
|
+
sx={{
|
|
642
|
+
color: "text.secondary",
|
|
643
|
+
whiteSpace: "pre-wrap",
|
|
644
|
+
m: 0,
|
|
645
|
+
mt: 1,
|
|
646
|
+
}}
|
|
647
|
+
>
|
|
648
|
+
{cell.error}
|
|
649
|
+
</Typography>
|
|
650
|
+
</CleanMetricCard>
|
|
651
|
+
)}
|
|
652
|
+
|
|
653
|
+
{cell.result && pendingRerun && (
|
|
654
|
+
<LinearProgress
|
|
655
|
+
aria-label="a re-run is pending"
|
|
656
|
+
sx={{ mb: 1, height: 2, borderRadius: 1 }}
|
|
657
|
+
/>
|
|
658
|
+
)}
|
|
659
|
+
|
|
431
660
|
{cell.result && (
|
|
432
661
|
<CleanMetricCard
|
|
433
662
|
sx={{
|
|
@@ -441,16 +670,26 @@ export function NotebookCell({
|
|
|
441
670
|
>
|
|
442
671
|
<ResultContainer
|
|
443
672
|
result={cell.result}
|
|
444
|
-
maxHeight={
|
|
673
|
+
maxHeight={CELL_MAX_HEIGHT}
|
|
445
674
|
maxResultSize={maxResultSize}
|
|
675
|
+
drill={drill}
|
|
446
676
|
/>
|
|
447
677
|
</Box>
|
|
678
|
+
{drillMenu}
|
|
448
679
|
|
|
449
|
-
{/* Top right corner controls
|
|
680
|
+
{/* Top right corner controls.
|
|
681
|
+
`top: -12px` lifts the buttons above the
|
|
682
|
+
CleanMetricCard's inner ResultContainer so the
|
|
683
|
+
dashboard panel (which now paints slate in dark
|
|
684
|
+
mode) doesn't bisect them. The icons were already
|
|
685
|
+
visually overlapping the panel's top edge in
|
|
686
|
+
light mode too, but the white-on-white made it
|
|
687
|
+
invisible; in dark mode the contrast made the
|
|
688
|
+
clipping obvious. */}
|
|
450
689
|
<Stack
|
|
451
690
|
sx={{
|
|
452
691
|
position: "absolute",
|
|
453
|
-
top: "
|
|
692
|
+
top: "-12px",
|
|
454
693
|
right: "8px",
|
|
455
694
|
flexDirection: "row",
|
|
456
695
|
gap: "8px",
|
|
@@ -474,7 +713,7 @@ export function NotebookCell({
|
|
|
474
713
|
}}
|
|
475
714
|
>
|
|
476
715
|
<CodeIcon
|
|
477
|
-
sx={{ fontSize: "18px", color: "
|
|
716
|
+
sx={{ fontSize: "18px", color: "grey.700" }}
|
|
478
717
|
/>
|
|
479
718
|
</IconButton>
|
|
480
719
|
)}
|
|
@@ -490,7 +729,7 @@ export function NotebookCell({
|
|
|
490
729
|
onClick={() => setResultsDialogOpen(true)}
|
|
491
730
|
>
|
|
492
731
|
<SearchIcon
|
|
493
|
-
sx={{ fontSize: "18px", color: "
|
|
732
|
+
sx={{ fontSize: "18px", color: "grey.700" }}
|
|
494
733
|
/>
|
|
495
734
|
</IconButton>
|
|
496
735
|
</Stack>
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { planRun } from "./runPlan";
|
|
6
|
+
|
|
7
|
+
const DOC = "uri|1";
|
|
8
|
+
const key = (givens: string) => `${DOC}|${givens}`;
|
|
9
|
+
|
|
10
|
+
describe("planRun", () => {
|
|
11
|
+
it("disarms a pending run when the notebook is not loaded", () => {
|
|
12
|
+
// Handled here rather than by an early return in the effect, because an
|
|
13
|
+
// early return skipped the cancellation: navigating away inside the
|
|
14
|
+
// settle window left a timer holding the previous notebook's closure.
|
|
15
|
+
expect(
|
|
16
|
+
planRun({
|
|
17
|
+
ready: false,
|
|
18
|
+
lastRunKey: key(""),
|
|
19
|
+
pendingKey: key("REGION=West"),
|
|
20
|
+
runKey: key("REGION=West"),
|
|
21
|
+
documentKey: DOC,
|
|
22
|
+
}),
|
|
23
|
+
).toEqual({ cancelPending: true, dispatch: "none" });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("does nothing at all when there is nothing pending and nothing loaded", () => {
|
|
27
|
+
expect(
|
|
28
|
+
planRun({
|
|
29
|
+
ready: false,
|
|
30
|
+
lastRunKey: null,
|
|
31
|
+
pendingKey: undefined,
|
|
32
|
+
runKey: key(""),
|
|
33
|
+
documentKey: DOC,
|
|
34
|
+
}),
|
|
35
|
+
).toEqual({ cancelPending: false, dispatch: "none" });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("runs the first pass immediately", () => {
|
|
39
|
+
expect(
|
|
40
|
+
planRun({
|
|
41
|
+
ready: true,
|
|
42
|
+
lastRunKey: null,
|
|
43
|
+
pendingKey: undefined,
|
|
44
|
+
runKey: key(""),
|
|
45
|
+
documentKey: DOC,
|
|
46
|
+
}),
|
|
47
|
+
).toEqual({ cancelPending: false, dispatch: "now" });
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("makes a changed parameter wait for the value to settle", () => {
|
|
51
|
+
expect(
|
|
52
|
+
planRun({
|
|
53
|
+
ready: true,
|
|
54
|
+
lastRunKey: key(""),
|
|
55
|
+
pendingKey: undefined,
|
|
56
|
+
runKey: key("REGION=West"),
|
|
57
|
+
documentKey: DOC,
|
|
58
|
+
}),
|
|
59
|
+
).toEqual({ cancelPending: false, dispatch: "settle" });
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("does not make a different notebook wait", () => {
|
|
63
|
+
// A document change is not a burst, so delaying it is only a blank screen.
|
|
64
|
+
expect(
|
|
65
|
+
planRun({
|
|
66
|
+
ready: true,
|
|
67
|
+
lastRunKey: "uri|1|",
|
|
68
|
+
pendingKey: undefined,
|
|
69
|
+
runKey: "other|1|",
|
|
70
|
+
documentKey: "other|1",
|
|
71
|
+
}).dispatch,
|
|
72
|
+
).toBe("now");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("does not make a package reload wait", () => {
|
|
76
|
+
// A reload bumps the generation, which changes the document key.
|
|
77
|
+
expect(
|
|
78
|
+
planRun({
|
|
79
|
+
ready: true,
|
|
80
|
+
lastRunKey: "uri|1|REGION=West",
|
|
81
|
+
pendingKey: undefined,
|
|
82
|
+
runKey: "uri|2|REGION=West",
|
|
83
|
+
documentKey: "uri|2",
|
|
84
|
+
}).dispatch,
|
|
85
|
+
).toBe("now");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("lets a pending run for the same key finish its clock", () => {
|
|
89
|
+
// Restarting it on every unrelated re-render could hold it off forever.
|
|
90
|
+
expect(
|
|
91
|
+
planRun({
|
|
92
|
+
ready: true,
|
|
93
|
+
lastRunKey: key(""),
|
|
94
|
+
pendingKey: key("REGION=West"),
|
|
95
|
+
runKey: key("REGION=West"),
|
|
96
|
+
documentKey: DOC,
|
|
97
|
+
}),
|
|
98
|
+
).toEqual({ cancelPending: false, dispatch: "none" });
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("supersedes a pending run when the value changes again", () => {
|
|
102
|
+
expect(
|
|
103
|
+
planRun({
|
|
104
|
+
ready: true,
|
|
105
|
+
lastRunKey: key(""),
|
|
106
|
+
pendingKey: key("REGION=We"),
|
|
107
|
+
runKey: key("REGION=West"),
|
|
108
|
+
documentKey: DOC,
|
|
109
|
+
}),
|
|
110
|
+
).toEqual({ cancelPending: true, dispatch: "settle" });
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("cancels a pending run when the user reverts to what already ran", () => {
|
|
114
|
+
// The defect this function was extracted for. Typing a value and deleting
|
|
115
|
+
// it again inside the settle window lands on an already-run key. Cancelling
|
|
116
|
+
// has to happen even though there is nothing to dispatch, or the abandoned
|
|
117
|
+
// value's results arrive and nothing is left to correct them.
|
|
118
|
+
expect(
|
|
119
|
+
planRun({
|
|
120
|
+
ready: true,
|
|
121
|
+
lastRunKey: key(""),
|
|
122
|
+
pendingKey: key("REGION=West"),
|
|
123
|
+
runKey: key(""),
|
|
124
|
+
documentKey: DOC,
|
|
125
|
+
}),
|
|
126
|
+
).toEqual({ cancelPending: true, dispatch: "none" });
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("cancels a pending run when the DOCUMENT changes under it", () => {
|
|
130
|
+
// The reachable case the first table missed: a parameter edit arms a
|
|
131
|
+
// timer, then the reader navigates to another notebook inside the window.
|
|
132
|
+
// The pending run belongs to the notebook they just left.
|
|
133
|
+
expect(
|
|
134
|
+
planRun({
|
|
135
|
+
ready: true,
|
|
136
|
+
lastRunKey: "uri|1|",
|
|
137
|
+
pendingKey: "uri|1|REGION=West",
|
|
138
|
+
runKey: "other|1|",
|
|
139
|
+
documentKey: "other|1",
|
|
140
|
+
}),
|
|
141
|
+
).toEqual({ cancelPending: true, dispatch: "now" });
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("does nothing when the state is unchanged", () => {
|
|
145
|
+
expect(
|
|
146
|
+
planRun({
|
|
147
|
+
ready: true,
|
|
148
|
+
lastRunKey: key("REGION=West"),
|
|
149
|
+
pendingKey: undefined,
|
|
150
|
+
runKey: key("REGION=West"),
|
|
151
|
+
documentKey: DOC,
|
|
152
|
+
}),
|
|
153
|
+
).toEqual({ cancelPending: false, dispatch: "none" });
|
|
154
|
+
});
|
|
155
|
+
});
|