@malloy-publisher/sdk 0.3.0 → 0.3.1
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 +8 -0
- package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +134 -0
- package/dist/DocumentStorageProvider-tGvodI8f.es.js +24268 -0
- package/dist/RenderedResult-CPi6uQWq.cjs.js +115 -0
- package/dist/RenderedResult-mDE-4u8S.es.js +542 -0
- package/dist/ServerProvider-CH71GsoL.cjs.js +1 -0
- package/dist/{ServerProvider-DSK9rfSY.es.js → ServerProvider-X2Ma0HRs.es.js} +486 -521
- package/dist/builder/index.cjs.js +105 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/index.es.js +9561 -0
- package/dist/builder-entry.d.ts +8 -0
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/Dashboard.d.ts +19 -14
- package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
- package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
- package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
- package/dist/components/Dashboard/TileCard.d.ts +44 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +7 -3
- package/dist/components/Dashboard/telemetry.d.ts +43 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +29 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +112 -0
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +32 -0
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
- package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
- package/dist/components/DashboardBuilder/controls.d.ts +157 -0
- package/dist/components/DashboardBuilder/diff.d.ts +35 -0
- package/dist/components/DashboardBuilder/document.d.ts +218 -0
- package/dist/components/DashboardBuilder/layout.d.ts +71 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
- package/dist/components/DashboardBuilder/preview.d.ts +60 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +44 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
- package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
- package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +7 -0
- package/dist/components/DocumentStorage/index.d.ts +1 -1
- package/dist/components/FloatingIconButton.d.ts +16 -0
- package/dist/components/Prose.d.ts +46 -0
- package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
- package/dist/components/RenderedResult/index.d.ts +1 -0
- package/dist/components/drill/index.d.ts +1 -1
- package/dist/components/drill/resolveDrill.d.ts +22 -0
- package/dist/components/drill/useDrill.d.ts +11 -2
- package/dist/components/index.d.ts +1 -0
- package/dist/components/styles.d.ts +0 -4
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useDocumentControls.d.ts +70 -0
- package/dist/hooks/useQueryResult.d.ts +40 -0
- package/dist/index.cjs.js +23 -270
- package/dist/index.es.js +16977 -41293
- package/dist/utils/malloyLiteral.d.ts +11 -0
- package/package.json +24 -9
- package/src/builder-entry.ts +55 -0
- package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
- package/src/components/Dashboard/Dashboard.tsx +165 -175
- package/src/components/Dashboard/DashboardGrid.tsx +124 -0
- package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
- package/src/components/Dashboard/DashboardTile.tsx +66 -123
- package/src/components/Dashboard/ExploreDialog.tsx +84 -0
- package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
- package/src/components/Dashboard/RowsDialog.tsx +234 -0
- package/src/components/Dashboard/TileCard.tsx +120 -0
- package/src/components/Dashboard/index.ts +2 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +70 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +33 -2
- package/src/components/Dashboard/telemetry.ts +44 -0
- package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
- package/src/components/DashboardBuilder/AddTileDialog.tsx +249 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +270 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +858 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +653 -0
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +211 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +493 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +129 -0
- package/src/components/DashboardBuilder/DrillDialog.tsx +281 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +581 -0
- package/src/components/DashboardBuilder/FilterStrip.tsx +125 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
- package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
- package/src/components/DashboardBuilder/catalog.ts +225 -0
- package/src/components/DashboardBuilder/controls.spec.ts +243 -0
- package/src/components/DashboardBuilder/controls.ts +398 -0
- package/src/components/DashboardBuilder/diff.spec.ts +44 -0
- package/src/components/DashboardBuilder/diff.ts +93 -0
- package/src/components/DashboardBuilder/document.ts +209 -0
- package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
- package/src/components/DashboardBuilder/layout.ts +143 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
- package/src/components/DashboardBuilder/malloyText.ts +151 -0
- package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
- package/src/components/DashboardBuilder/preview.spec.ts +149 -0
- package/src/components/DashboardBuilder/preview.ts +172 -0
- package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
- package/src/components/DashboardBuilder/readDocument.ts +467 -0
- package/src/components/DashboardBuilder/sortable.tsx +151 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +1108 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +1098 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +255 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +193 -0
- package/src/components/DashboardBuilder/useDraft.ts +43 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
- package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
- package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
- package/src/components/DashboardBuilder/useTileResize.ts +110 -0
- package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
- package/src/components/DocumentStorage/DocumentStorageProvider.tsx +12 -0
- package/src/components/DocumentStorage/index.ts +1 -0
- package/src/components/Environment/About.tsx +4 -36
- package/src/components/FloatingIconButton.tsx +41 -0
- package/src/components/Model/Model.tsx +6 -23
- package/src/components/Model/ModelCell.tsx +33 -72
- package/src/components/Notebook/Notebook.tsx +25 -88
- package/src/components/Notebook/NotebookCell.tsx +35 -183
- package/src/components/Prose.spec.tsx +85 -0
- package/src/components/Prose.tsx +179 -0
- package/src/components/QueryResult/QueryResult.tsx +15 -43
- package/src/components/RenderedResult/ResultContainer.tsx +4 -12
- package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
- package/src/components/RenderedResult/ResultPanel.tsx +73 -0
- package/src/components/RenderedResult/index.ts +1 -0
- package/src/components/drill/index.ts +1 -0
- package/src/components/drill/resolveDrill.ts +22 -1
- package/src/components/drill/useDrill.spec.tsx +94 -0
- package/src/components/drill/useDrill.tsx +52 -12
- package/src/components/given/GivensPanel.tsx +1 -1
- package/src/components/index.ts +6 -0
- package/src/components/styles.ts +0 -37
- package/src/hooks/index.ts +13 -0
- package/src/hooks/useDocumentControls.ts +170 -0
- package/src/hooks/useQueryResult.ts +82 -0
- package/src/utils/malloyLiteral.spec.ts +43 -0
- package/src/utils/malloyLiteral.ts +76 -0
- package/vite.config.ts +5 -0
- package/dist/ServerProvider-CGnLjzag.cjs.js +0 -1
|
@@ -3,18 +3,17 @@
|
|
|
3
3
|
|
|
4
4
|
import PlayArrowIcon from "@mui/icons-material/PlayArrow";
|
|
5
5
|
import SearchIcon from "@mui/icons-material/Search";
|
|
6
|
-
import { Box, Button,
|
|
6
|
+
import { Box, Button, Typography } from "@mui/material";
|
|
7
7
|
import React, { useEffect } from "react";
|
|
8
|
-
import {
|
|
8
|
+
import { useQueryResult } from "../../hooks/useQueryResult";
|
|
9
9
|
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
10
10
|
import { parseResourceUri } from "../../utils/formatting";
|
|
11
|
-
import {
|
|
11
|
+
import { FloatingIconButton } from "../FloatingIconButton";
|
|
12
12
|
import { highlight } from "../highlighter";
|
|
13
|
-
import
|
|
13
|
+
import { ResultPanel } from "../RenderedResult/ResultPanel";
|
|
14
14
|
import { MODEL_CELL_MAX_HEIGHT } from "../RenderedResult/resultSizing";
|
|
15
15
|
import ResultsDialog from "../ResultsDialog";
|
|
16
|
-
import {
|
|
17
|
-
import { CleanMetricCard, CleanNotebookCell } from "../styles";
|
|
16
|
+
import { CleanMetricCard } from "../styles";
|
|
18
17
|
|
|
19
18
|
interface ModelCellProps {
|
|
20
19
|
sourceName?: string;
|
|
@@ -40,29 +39,13 @@ export function ModelCell({
|
|
|
40
39
|
|
|
41
40
|
const { packageName, environmentName, versionId, modelPath } =
|
|
42
41
|
parseResourceUri(resourceUri);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
queryKey: ["namedQueryResult", resourceUri, queryName],
|
|
51
|
-
queryFn: () =>
|
|
52
|
-
apiClients.models.executeQueryModel(
|
|
53
|
-
environmentName,
|
|
54
|
-
packageName,
|
|
55
|
-
modelPath,
|
|
56
|
-
{
|
|
57
|
-
query: undefined,
|
|
58
|
-
sourceName: undefined,
|
|
59
|
-
queryName: queryName,
|
|
60
|
-
versionId: versionId,
|
|
61
|
-
},
|
|
62
|
-
),
|
|
63
|
-
enabled: runOnDemand ? hasRun : true, // Execute on demand or always
|
|
64
|
-
...CHART_RESULT_QUERY_OPTIONS,
|
|
65
|
-
});
|
|
42
|
+
// Run on demand or always; a query not yet asked for is not fetched.
|
|
43
|
+
const shouldRun = !runOnDemand || hasRun;
|
|
44
|
+
const state = useQueryResult(
|
|
45
|
+
{ environmentName, packageName, modelPath, versionId, queryName },
|
|
46
|
+
{ enabled: shouldRun },
|
|
47
|
+
);
|
|
48
|
+
const queryData = state.data;
|
|
66
49
|
|
|
67
50
|
const { mode } = usePublisherTheme();
|
|
68
51
|
useEffect(() => {
|
|
@@ -77,7 +60,7 @@ export function ModelCell({
|
|
|
77
60
|
}, [annotations, mode]);
|
|
78
61
|
|
|
79
62
|
return (
|
|
80
|
-
<
|
|
63
|
+
<Box>
|
|
81
64
|
{highlightedAnnotations && (
|
|
82
65
|
<Box sx={{ marginBottom: "16px" }}>
|
|
83
66
|
<Typography
|
|
@@ -110,29 +93,24 @@ export function ModelCell({
|
|
|
110
93
|
variant="body2"
|
|
111
94
|
sx={{
|
|
112
95
|
fontSize: "15px",
|
|
113
|
-
fontWeight:
|
|
114
|
-
color: "
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
96
|
+
fontWeight: 600,
|
|
97
|
+
color: "text.primary",
|
|
98
|
+
px: 2,
|
|
99
|
+
py: 1,
|
|
100
|
+
bgcolor: "action.hover",
|
|
101
|
+
borderRadius: 1.5,
|
|
102
|
+
border: 1,
|
|
103
|
+
borderColor: "divider",
|
|
119
104
|
}}
|
|
120
105
|
>
|
|
121
106
|
{queryName}
|
|
122
107
|
</Typography>
|
|
123
|
-
<
|
|
124
|
-
|
|
125
|
-
backgroundColor: "rgba(255, 255, 255, 0.9)",
|
|
126
|
-
"&:hover": {
|
|
127
|
-
backgroundColor: "rgba(255, 255, 255, 1)",
|
|
128
|
-
},
|
|
129
|
-
width: "32px",
|
|
130
|
-
height: "32px",
|
|
131
|
-
}}
|
|
108
|
+
<FloatingIconButton
|
|
109
|
+
aria-label="Expand results"
|
|
132
110
|
onClick={() => setResultsDialogOpen(true)}
|
|
133
111
|
>
|
|
134
|
-
<SearchIcon
|
|
135
|
-
</
|
|
112
|
+
<SearchIcon />
|
|
113
|
+
</FloatingIconButton>
|
|
136
114
|
</Box>
|
|
137
115
|
|
|
138
116
|
<CleanMetricCard
|
|
@@ -158,36 +136,19 @@ export function ModelCell({
|
|
|
158
136
|
variant="contained"
|
|
159
137
|
startIcon={<PlayArrowIcon />}
|
|
160
138
|
onClick={() => setHasRun(true)}
|
|
161
|
-
sx={{
|
|
162
|
-
backgroundColor: "#1976d2",
|
|
163
|
-
"&:hover": {
|
|
164
|
-
backgroundColor: "#1565c0",
|
|
165
|
-
},
|
|
166
|
-
textTransform: "none",
|
|
167
|
-
fontSize: "14px",
|
|
168
|
-
fontWeight: 600,
|
|
169
|
-
padding: "8px 24px",
|
|
170
|
-
}}
|
|
171
139
|
>
|
|
172
140
|
Run Query
|
|
173
141
|
</Button>
|
|
174
142
|
</Box>
|
|
175
143
|
)}
|
|
176
|
-
{
|
|
177
|
-
<
|
|
178
|
-
|
|
179
|
-
|
|
144
|
+
{shouldRun && (
|
|
145
|
+
<ResultPanel
|
|
146
|
+
state={state}
|
|
147
|
+
context={queryName}
|
|
148
|
+
maxHeight={MODEL_CELL_MAX_HEIGHT}
|
|
149
|
+
maxResultSize={maxResultSize}
|
|
150
|
+
/>
|
|
180
151
|
)}
|
|
181
|
-
{(!runOnDemand || hasRun) &&
|
|
182
|
-
isSuccess &&
|
|
183
|
-
queryData?.data?.result && (
|
|
184
|
-
<ResultContainer
|
|
185
|
-
result={queryData.data.result}
|
|
186
|
-
maxHeight={MODEL_CELL_MAX_HEIGHT}
|
|
187
|
-
maxResultSize={maxResultSize}
|
|
188
|
-
renderLogs={queryData.data.renderLogs}
|
|
189
|
-
/>
|
|
190
|
-
)}
|
|
191
152
|
</CleanMetricCard>
|
|
192
153
|
|
|
193
154
|
{/* Results Dialog */}
|
|
@@ -198,6 +159,6 @@ export function ModelCell({
|
|
|
198
159
|
renderLogs={queryData?.data?.renderLogs}
|
|
199
160
|
title={`Query: ${queryName}`}
|
|
200
161
|
/>
|
|
201
|
-
</
|
|
162
|
+
</Box>
|
|
202
163
|
);
|
|
203
164
|
}
|
|
@@ -3,18 +3,17 @@
|
|
|
3
3
|
|
|
4
4
|
import "@malloydata/malloy-explorer/styles.css";
|
|
5
5
|
import { Stack, Typography } from "@mui/material";
|
|
6
|
-
import { useCallback, useEffect,
|
|
6
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
7
7
|
import { planRun } from "./runPlan";
|
|
8
8
|
import { RawNotebook } from "../../client";
|
|
9
9
|
import { GivenValue } from "../../hooks/givenValue";
|
|
10
|
-
import {
|
|
10
|
+
import { useDocumentControls } from "../../hooks/useDocumentControls";
|
|
11
11
|
import { useModelGivens } from "../../hooks/useModelGivens";
|
|
12
12
|
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
13
|
-
import { useSuggestOptions } from "../../hooks/useSuggestOptions";
|
|
14
13
|
import { parseResourceUri } from "../../utils/formatting";
|
|
15
14
|
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
16
15
|
import type { NavigationClick } from "../click_helper";
|
|
17
|
-
import {
|
|
16
|
+
import type { DrillNavigation } from "../drill";
|
|
18
17
|
import { GivensPanel } from "../given";
|
|
19
18
|
import { givensToRequest } from "../given/paramCodec";
|
|
20
19
|
import { Loading } from "../Loading";
|
|
@@ -157,91 +156,38 @@ export default function Notebook({
|
|
|
157
156
|
const lastDocumentRef = useRef<string | undefined>(undefined);
|
|
158
157
|
const [executionError, setExecutionError] = useState<Error | null>(null);
|
|
159
158
|
|
|
160
|
-
// Model-level `given:` declarations, and the state behind their controls
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
// implementation rather than two that drift.
|
|
159
|
+
// Model-level `given:` declarations, and the state behind their controls:
|
|
160
|
+
// the same hook the dashboard uses, so both surfaces get URL-addressable
|
|
161
|
+
// parameters, Apply batching and `to=self` drill from one implementation.
|
|
164
162
|
const declaredGivens = useModelGivens(notebook);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
.filter((given) => given.name !== undefined)
|
|
170
|
-
.map((given) => [given.name as string, given.type]),
|
|
171
|
-
),
|
|
172
|
-
[declaredGivens],
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
// Silent until the notebook has actually loaded. Which givens exist is not
|
|
176
|
-
// known before then: `useModelGivens(undefined)` is empty, so a report in
|
|
177
|
-
// that window says "no values, and I manage nothing", which a host reasonably
|
|
178
|
-
// reads as "clear what you wrote". During an in-app navigation from one
|
|
179
|
-
// notebook to another that window sits between the two, and the parameters it
|
|
180
|
-
// would clear can belong to the notebook now ARRIVING. A notebook that
|
|
181
|
-
// genuinely declares no givens still reports, because by then the empty set
|
|
182
|
-
// is the answer rather than the absence of one.
|
|
183
|
-
const reportGivens = useCallback(
|
|
184
|
-
(next: Record<string, string>) => {
|
|
185
|
-
if (!isSuccess) return;
|
|
186
|
-
onGivensChange?.(next, Array.from(declaredTypes.keys()));
|
|
187
|
-
},
|
|
188
|
-
[isSuccess, onGivensChange, declaredTypes],
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
// Read off the notebook now that the server derives it: a file-level
|
|
192
|
-
// `## autorun=false` arrives as `RawNotebook.autorun`, the same field with
|
|
193
|
-
// the same default that a dashboard's `# artifact { autorun=false }`
|
|
194
|
-
// produces. This was hardcoded true while nothing populated the field, on
|
|
195
|
-
// the grounds that a spec declaring one nothing produces is a spec that
|
|
196
|
-
// lies; the reader has landed, so this is the follow-up that comment named.
|
|
197
|
-
//
|
|
198
|
-
// Absent means autorun, so only an explicit `false` batches. Batching
|
|
199
|
-
// matters more here than on a dashboard: one control change re-runs every
|
|
200
|
-
// cell in the document.
|
|
163
|
+
// A file-level `## autorun=false` arrives as `RawNotebook.autorun`, the same
|
|
164
|
+
// field with the same default a dashboard's `# artifact { autorun=false }`
|
|
165
|
+
// produces. Batching matters more here than on a dashboard: one control
|
|
166
|
+
// change re-runs every cell in the document.
|
|
201
167
|
const autorun = notebook?.autorun !== false;
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
//
|
|
168
|
+
const controls = useDocumentControls({
|
|
169
|
+
specs: declaredGivens,
|
|
170
|
+
loaded: isSuccess,
|
|
171
|
+
// Where the controls start, from a file-level `## givens { … }`.
|
|
206
172
|
startingValues: notebook?.startingGivens,
|
|
207
173
|
params: givens,
|
|
208
|
-
|
|
209
|
-
// dropped. `useGivensState` records what it last reported BEFORE calling
|
|
210
|
-
// out, so a report the callback throws away is remembered as delivered
|
|
211
|
-
// and never retried, leaving a parameter stranded in the host's URL.
|
|
212
|
-
// Passing undefined makes the hook skip the report entirely, which leaves
|
|
213
|
-
// its record untouched and the next real change still reportable.
|
|
214
|
-
onParamsChange: isSuccess ? reportGivens : undefined,
|
|
215
|
-
// Which notebook these edits belong to. Navigating between notebooks
|
|
216
|
-
// reuses this component, so without it one notebook's applied values
|
|
217
|
-
// carried into the next whenever both started from the same values.
|
|
174
|
+
onGivensChange,
|
|
218
175
|
documentKey: resourceUri,
|
|
219
176
|
autorun,
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
// A notebook's model path is the notebook itself: `suggest` queries run
|
|
223
|
-
// against the same model the cells do.
|
|
224
|
-
const {
|
|
225
|
-
options: givenOptions,
|
|
226
|
-
isLoading: givenOptionsLoading,
|
|
227
|
-
failed: givenOptionsFailed,
|
|
228
|
-
} = useSuggestOptions(
|
|
229
177
|
environmentName,
|
|
230
178
|
packageName,
|
|
231
|
-
|
|
232
|
-
|
|
179
|
+
// A notebook's model path is the notebook itself: `suggest` queries run
|
|
180
|
+
// against the same model the cells do.
|
|
181
|
+
modelPath: notebookPath,
|
|
233
182
|
versionId,
|
|
234
|
-
// So a suggest over a gated or scoped source carries the givens it needs.
|
|
235
|
-
{ values: applied, declaredTypes },
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
// `to=self` filters in place. Which givens a tag may set, and setting one
|
|
239
|
-
// from a clicked cell, is the same on both surfaces, so it is shared.
|
|
240
|
-
const { canSelf: canDrillSelf, onSelf: onDrillSelf } = useDrillSelf({
|
|
241
|
-
declaredTypes,
|
|
242
|
-
setGiven,
|
|
243
183
|
documentName: notebookPath,
|
|
244
184
|
});
|
|
185
|
+
const {
|
|
186
|
+
applied,
|
|
187
|
+
declaredTypes,
|
|
188
|
+
canSelf: canDrillSelf,
|
|
189
|
+
onSelf: onDrillSelf,
|
|
190
|
+
} = controls;
|
|
245
191
|
|
|
246
192
|
/**
|
|
247
193
|
* The `givens` query param for the notebook-cell GET: the same map the
|
|
@@ -558,16 +504,7 @@ export default function Notebook({
|
|
|
558
504
|
<CleanNotebookSection>
|
|
559
505
|
<Stack spacing={3} component="section">
|
|
560
506
|
{/* Parameters panel: the controls for `given:` declarations */}
|
|
561
|
-
<GivensPanel
|
|
562
|
-
givens={declaredGivens}
|
|
563
|
-
values={draft}
|
|
564
|
-
onChange={setGiven}
|
|
565
|
-
onReset={reset}
|
|
566
|
-
options={givenOptions}
|
|
567
|
-
optionsLoading={givenOptionsLoading}
|
|
568
|
-
optionsFailed={givenOptionsFailed}
|
|
569
|
-
apply={autorun ? undefined : { onApply: apply, pending }}
|
|
570
|
-
/>
|
|
507
|
+
<GivensPanel {...controls.panel} />
|
|
571
508
|
|
|
572
509
|
{/* Loading State */}
|
|
573
510
|
{!isSuccess && !isError && (
|
|
@@ -19,19 +19,20 @@ import {
|
|
|
19
19
|
Tooltip,
|
|
20
20
|
Typography,
|
|
21
21
|
} from "@mui/material";
|
|
22
|
-
import Markdown from "markdown-to-jsx";
|
|
23
22
|
import React, { useEffect, useState } from "react";
|
|
24
23
|
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
25
24
|
import { parseResourceUri } from "../../utils/formatting";
|
|
26
25
|
import { highlight } from "../highlighter";
|
|
27
26
|
import { ModelExplorerDialog } from "../Model/ModelExplorerDialog";
|
|
27
|
+
import { FloatingIconButton } from "../FloatingIconButton";
|
|
28
|
+
import { Prose } from "../Prose";
|
|
28
29
|
import type { NavigationClick } from "../click_helper";
|
|
29
30
|
import { useDrill, type DrillNavigation } from "../drill";
|
|
30
31
|
import { createEmbeddedQueryResult } from "../QueryResult/QueryResult";
|
|
31
32
|
import ResultContainer from "../RenderedResult/ResultContainer";
|
|
32
33
|
import { NOTEBOOK_CELL_MAX_HEIGHT } from "../RenderedResult/resultSizing";
|
|
33
34
|
import ResultsDialog from "../ResultsDialog";
|
|
34
|
-
import { CleanMetricCard
|
|
35
|
+
import { CleanMetricCard } from "../styles";
|
|
35
36
|
import { EnhancedNotebookCell } from "./types";
|
|
36
37
|
|
|
37
38
|
interface NotebookCellProps {
|
|
@@ -83,82 +84,6 @@ interface NotebookCellProps {
|
|
|
83
84
|
onDrillNavigate?: (target: DrillNavigation, event?: MouseEvent) => void;
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
interface NotebookMarkdownLinkProps {
|
|
87
|
-
href?: string;
|
|
88
|
-
title?: string;
|
|
89
|
-
children?: React.ReactNode;
|
|
90
|
-
envName: string;
|
|
91
|
-
pkgName: string;
|
|
92
|
-
sourceDir: string;
|
|
93
|
-
onNavigate?: (to: string, event?: NavigationClick) => void;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Links inside a rendered notebook/README are authored relative to the source
|
|
97
|
-
// file (e.g. `spielberg.malloynb`). A plain browser anchor resolves them
|
|
98
|
-
// against the current page URL, which drops the package segment for a README
|
|
99
|
-
// shown at the package route. Resolve relative links against the source file's
|
|
100
|
-
// own directory instead and route them through the SPA. External, hash, and
|
|
101
|
-
// absolute links stay as normal anchors.
|
|
102
|
-
function NotebookMarkdownLink({
|
|
103
|
-
href,
|
|
104
|
-
title,
|
|
105
|
-
children,
|
|
106
|
-
envName,
|
|
107
|
-
pkgName,
|
|
108
|
-
sourceDir,
|
|
109
|
-
onNavigate,
|
|
110
|
-
}: NotebookMarkdownLinkProps) {
|
|
111
|
-
const hasScheme = !!href && /^[a-z][a-z0-9+.-]*:/i.test(href);
|
|
112
|
-
const isInternalRelative =
|
|
113
|
-
!!href && !hasScheme && !href.startsWith("/") && !href.startsWith("#");
|
|
114
|
-
|
|
115
|
-
if (!isInternalRelative || !href) {
|
|
116
|
-
// External, absolute, or hash link: render a normal anchor. Only allow
|
|
117
|
-
// safe schemes so a crafted `javascript:`/`data:` href in a package
|
|
118
|
-
// README (packages can come from untrusted git/S3 sources) cannot run.
|
|
119
|
-
const isUnsafeScheme =
|
|
120
|
-
hasScheme && !/^(https?|mailto|tel):/i.test(href ?? "");
|
|
121
|
-
return (
|
|
122
|
-
<a
|
|
123
|
-
href={isUnsafeScheme ? undefined : href}
|
|
124
|
-
title={title}
|
|
125
|
-
{...(hasScheme
|
|
126
|
-
? { target: "_blank", rel: "noopener noreferrer" }
|
|
127
|
-
: {})}
|
|
128
|
-
>
|
|
129
|
-
{children}
|
|
130
|
-
</a>
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Resolve the relative href against the source file's directory (empty for a
|
|
135
|
-
// package-root README) via a dummy origin, which normalizes any `./`/`../`
|
|
136
|
-
// and clamps escapes at the package root, then prefix the package path.
|
|
137
|
-
const resolved = new URL(href, `https://malloy.invalid/${sourceDir}`);
|
|
138
|
-
const packageRelative =
|
|
139
|
-
resolved.pathname.slice(1) + resolved.search + resolved.hash;
|
|
140
|
-
const to = `/${envName}/${pkgName}/${packageRelative}`;
|
|
141
|
-
// With a host router (onNavigate) intercept and route through the SPA.
|
|
142
|
-
// Without one (router-free SDK embedding) the absolute href navigates on
|
|
143
|
-
// its own, so rendering a notebook needs no react-router context.
|
|
144
|
-
return (
|
|
145
|
-
<a
|
|
146
|
-
href={to}
|
|
147
|
-
title={title}
|
|
148
|
-
onClick={
|
|
149
|
-
onNavigate
|
|
150
|
-
? (event) => {
|
|
151
|
-
event.preventDefault();
|
|
152
|
-
onNavigate(to, event);
|
|
153
|
-
}
|
|
154
|
-
: undefined
|
|
155
|
-
}
|
|
156
|
-
>
|
|
157
|
-
{children}
|
|
158
|
-
</a>
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
87
|
export function NotebookCell({
|
|
163
88
|
cell,
|
|
164
89
|
hideCodeCellIcon,
|
|
@@ -189,6 +114,14 @@ export function NotebookCell({
|
|
|
189
114
|
|
|
190
115
|
const { environmentName, packageName, modelPath } =
|
|
191
116
|
parseResourceUri(resourceUri);
|
|
117
|
+
// Links in a markdown cell are authored relative to the notebook file, and
|
|
118
|
+
// route through the host when it gave us a way to.
|
|
119
|
+
const links = {
|
|
120
|
+
environmentName,
|
|
121
|
+
packageName,
|
|
122
|
+
sourcePath: modelPath,
|
|
123
|
+
onNavigate,
|
|
124
|
+
};
|
|
192
125
|
|
|
193
126
|
// `# drill` is declared on a model dimension, so a notebook cell that groups
|
|
194
127
|
// by that dimension is clickable for free: the same resolution, and the
|
|
@@ -219,26 +152,6 @@ export function NotebookCell({
|
|
|
219
152
|
// a shared model dimension and cannot know which document it fired in.
|
|
220
153
|
selfLabel: "Filter this notebook",
|
|
221
154
|
});
|
|
222
|
-
// Directory of the source file within the package (empty for a package-root
|
|
223
|
-
// README), used to resolve relative links the author wrote against it.
|
|
224
|
-
const sourceDir =
|
|
225
|
-
modelPath && modelPath.includes("/")
|
|
226
|
-
? modelPath.slice(0, modelPath.lastIndexOf("/") + 1)
|
|
227
|
-
: "";
|
|
228
|
-
const markdownOptions = {
|
|
229
|
-
overrides: {
|
|
230
|
-
a: {
|
|
231
|
-
component: NotebookMarkdownLink,
|
|
232
|
-
props: {
|
|
233
|
-
envName: environmentName,
|
|
234
|
-
pkgName: packageName,
|
|
235
|
-
sourceDir,
|
|
236
|
-
onNavigate,
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
};
|
|
241
|
-
|
|
242
155
|
// Regex to extract imported names from import statements
|
|
243
156
|
const IMPORT_NAMES_REGEX = /import\s*\{([^}]+)\}\s*from\s*['"`][^'"`]+['"`]/;
|
|
244
157
|
|
|
@@ -333,42 +246,17 @@ export function NotebookCell({
|
|
|
333
246
|
|
|
334
247
|
return (
|
|
335
248
|
(cell.type === "markdown" && (
|
|
336
|
-
<
|
|
337
|
-
<Box
|
|
338
|
-
sx={(theme) => ({
|
|
339
|
-
"& h1, & h2, & h3, & h4, & h5, & h6": {
|
|
340
|
-
fontWeight: "600",
|
|
341
|
-
color: theme.palette.text.primary,
|
|
342
|
-
marginBottom: "8px",
|
|
343
|
-
marginTop: "16px",
|
|
344
|
-
},
|
|
345
|
-
"& h1": { fontSize: "28px" },
|
|
346
|
-
"& h2": { fontSize: "24px" },
|
|
347
|
-
"& h3": { fontSize: "20px" },
|
|
348
|
-
"& p": {
|
|
349
|
-
color: theme.palette.text.primary,
|
|
350
|
-
lineHeight: "1.7",
|
|
351
|
-
marginBottom: "8px",
|
|
352
|
-
fontSize: "16px",
|
|
353
|
-
},
|
|
354
|
-
"& ul, & ol": {
|
|
355
|
-
color: theme.palette.text.primary,
|
|
356
|
-
lineHeight: "1.7",
|
|
357
|
-
marginBottom: "8px",
|
|
358
|
-
fontSize: "16px",
|
|
359
|
-
},
|
|
360
|
-
"& li": {
|
|
361
|
-
marginBottom: "4px",
|
|
362
|
-
},
|
|
363
|
-
})}
|
|
364
|
-
>
|
|
249
|
+
<Box>
|
|
250
|
+
<Box>
|
|
365
251
|
{index === 0 ? (
|
|
366
252
|
<Stack
|
|
367
253
|
direction="row"
|
|
368
254
|
alignItems="flex-start"
|
|
369
255
|
justifyContent="space-between"
|
|
370
256
|
>
|
|
371
|
-
<
|
|
257
|
+
<Prose variant="document" links={links}>
|
|
258
|
+
{cell.text}
|
|
259
|
+
</Prose>
|
|
372
260
|
<Tooltip title="Click to copy link">
|
|
373
261
|
<LinkOutlinedIcon
|
|
374
262
|
sx={{
|
|
@@ -382,7 +270,9 @@ export function NotebookCell({
|
|
|
382
270
|
</Tooltip>
|
|
383
271
|
</Stack>
|
|
384
272
|
) : (
|
|
385
|
-
<
|
|
273
|
+
<Prose variant="document" links={links}>
|
|
274
|
+
{cell.text}
|
|
275
|
+
</Prose>
|
|
386
276
|
)}
|
|
387
277
|
<Snackbar
|
|
388
278
|
open={copyMessage !== ""}
|
|
@@ -391,10 +281,10 @@ export function NotebookCell({
|
|
|
391
281
|
message={copyMessage}
|
|
392
282
|
/>
|
|
393
283
|
</Box>
|
|
394
|
-
</
|
|
284
|
+
</Box>
|
|
395
285
|
)) ||
|
|
396
286
|
(cell.type === "code" && (
|
|
397
|
-
<
|
|
287
|
+
<Box>
|
|
398
288
|
{(!hideCodeCellIcon ||
|
|
399
289
|
(!hideEmbeddingIcon && cell.result) ||
|
|
400
290
|
(cell.newSources && cell.newSources.length > 0)) && (
|
|
@@ -436,33 +326,13 @@ export function NotebookCell({
|
|
|
436
326
|
/>
|
|
437
327
|
)}
|
|
438
328
|
{hasValidImport && (
|
|
439
|
-
<
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
"&:hover": {
|
|
443
|
-
backgroundColor:
|
|
444
|
-
"rgba(255, 255, 255, 1)",
|
|
445
|
-
},
|
|
446
|
-
width: "32px",
|
|
447
|
-
height: "32px",
|
|
448
|
-
flexShrink: 0,
|
|
449
|
-
}}
|
|
329
|
+
<FloatingIconButton
|
|
330
|
+
aria-label="Data sources"
|
|
331
|
+
sx={{ flexShrink: 0 }}
|
|
450
332
|
onClick={() => setSourcesDialogOpen(true)}
|
|
451
333
|
>
|
|
452
|
-
<SearchIcon
|
|
453
|
-
|
|
454
|
-
fontSize: "18px",
|
|
455
|
-
// grey.700 is a dark warm grey
|
|
456
|
-
// that stays legible on the
|
|
457
|
-
// white-ish IconButton in both
|
|
458
|
-
// light and dark mode. The
|
|
459
|
-
// button background is
|
|
460
|
-
// hardcoded white, so the icon
|
|
461
|
-
// must be hardcoded dark.
|
|
462
|
-
color: "grey.700",
|
|
463
|
-
}}
|
|
464
|
-
/>
|
|
465
|
-
</IconButton>
|
|
334
|
+
<SearchIcon />
|
|
335
|
+
</FloatingIconButton>
|
|
466
336
|
)}
|
|
467
337
|
</Box>
|
|
468
338
|
</CleanMetricCard>
|
|
@@ -692,44 +562,26 @@ export function NotebookCell({
|
|
|
692
562
|
}}
|
|
693
563
|
>
|
|
694
564
|
{!hideCodeCellIcon && (
|
|
695
|
-
<
|
|
696
|
-
|
|
697
|
-
backgroundColor: "rgba(255, 255, 255, 0.9)",
|
|
698
|
-
"&:hover": {
|
|
699
|
-
backgroundColor: "rgba(255, 255, 255, 1)",
|
|
700
|
-
},
|
|
701
|
-
width: "32px",
|
|
702
|
-
height: "32px",
|
|
703
|
-
}}
|
|
565
|
+
<FloatingIconButton
|
|
566
|
+
aria-label="Malloy code"
|
|
704
567
|
onClick={(e) => {
|
|
705
568
|
e.stopPropagation();
|
|
706
569
|
setCodeDialogOpen(true);
|
|
707
570
|
}}
|
|
708
571
|
>
|
|
709
|
-
<CodeIcon
|
|
710
|
-
|
|
711
|
-
/>
|
|
712
|
-
</IconButton>
|
|
572
|
+
<CodeIcon />
|
|
573
|
+
</FloatingIconButton>
|
|
713
574
|
)}
|
|
714
|
-
<
|
|
715
|
-
|
|
716
|
-
backgroundColor: "rgba(255, 255, 255, 0.9)",
|
|
717
|
-
"&:hover": {
|
|
718
|
-
backgroundColor: "rgba(255, 255, 255, 1)",
|
|
719
|
-
},
|
|
720
|
-
width: "32px",
|
|
721
|
-
height: "32px",
|
|
722
|
-
}}
|
|
575
|
+
<FloatingIconButton
|
|
576
|
+
aria-label="Expand results"
|
|
723
577
|
onClick={() => setResultsDialogOpen(true)}
|
|
724
578
|
>
|
|
725
|
-
<SearchIcon
|
|
726
|
-
|
|
727
|
-
/>
|
|
728
|
-
</IconButton>
|
|
579
|
+
<SearchIcon />
|
|
580
|
+
</FloatingIconButton>
|
|
729
581
|
</Stack>
|
|
730
582
|
</CleanMetricCard>
|
|
731
583
|
)}
|
|
732
|
-
</
|
|
584
|
+
</Box>
|
|
733
585
|
))
|
|
734
586
|
);
|
|
735
587
|
}
|