@malloy-publisher/sdk 0.3.0 → 0.4.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 +22 -9
- package/dist/DocumentStorageProvider-CyOJ0hqf.es.js +24443 -0
- package/dist/DocumentStorageProvider-DGPQEd_l.cjs.js +134 -0
- package/dist/RenderedResult-BnPzJ9Jf.es.js +549 -0
- package/dist/RenderedResult-Dp22kZsQ.cjs.js +115 -0
- package/dist/{ServerProvider-DSK9rfSY.es.js → ServerProvider-BWOEKg0O.es.js} +1256 -1318
- package/dist/ServerProvider-Cc489A3f.cjs.js +1 -0
- package/dist/builder/index.cjs.js +105 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/index.es.js +9482 -0
- package/dist/builder-entry.d.ts +8 -0
- package/dist/client/api.d.ts +100 -42
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/AppDialog.d.ts +30 -0
- package/dist/components/BackLink.d.ts +32 -0
- package/dist/components/Dashboard/Dashboard.d.ts +19 -14
- package/dist/components/Dashboard/DashboardBar.d.ts +21 -0
- 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 +48 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +31 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +118 -0
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +30 -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/newDashboard.d.ts +17 -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 +53 -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/ItemRow.d.ts +38 -0
- package/dist/components/Materializations/MaterializationDetailDialog.d.ts +1 -2
- package/dist/components/Materializations/MaterializationRunsList.d.ts +1 -5
- package/dist/components/Materializations/Materializations.d.ts +7 -3
- package/dist/components/Materializations/ScopeButton.d.ts +18 -0
- package/dist/components/Materializations/SectionLabel.d.ts +7 -4
- package/dist/components/Materializations/TriggerLabel.d.ts +14 -0
- package/dist/components/Materializations/index.d.ts +0 -1
- package/dist/components/Package/ContentTypeIcon.d.ts +3 -5
- package/dist/components/Package/NewDashboardDialog.d.ts +18 -0
- package/dist/components/Package/index.d.ts +0 -1
- package/dist/components/PackageSection.d.ts +23 -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/buttons.d.ts +53 -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 +6 -0
- package/dist/components/styles.d.ts +49 -44
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useCrudMutation.d.ts +42 -0
- package/dist/hooks/useDocumentControls.d.ts +70 -0
- package/dist/hooks/useQueryResult.d.ts +40 -0
- package/dist/index.cjs.js +22 -273
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +16888 -44451
- package/dist/telemetry/consoleEvents.d.ts +60 -0
- package/dist/utils/malloyLiteral.d.ts +11 -0
- package/dist/utils/sha256.d.ts +2 -0
- package/package.json +24 -9
- package/src/builder-entry.ts +55 -0
- package/src/components/AppDialog.tsx +115 -0
- package/src/components/BackLink.tsx +83 -0
- package/src/components/Connections/AddConnectionDialog.tsx +50 -70
- package/src/components/Connections/DeleteConnectionDialog.tsx +23 -50
- package/src/components/Connections/EditConnectionDialog.tsx +54 -73
- package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
- package/src/components/Dashboard/Dashboard.tsx +165 -175
- package/src/components/Dashboard/DashboardBar.tsx +88 -0
- 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 +51 -0
- package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
- package/src/components/DashboardBuilder/AddTileDialog.tsx +247 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +852 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +666 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +188 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +567 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +122 -0
- package/src/components/DashboardBuilder/DrillDialog.tsx +269 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +562 -0
- package/src/components/DashboardBuilder/FilterStrip.tsx +126 -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/newDashboard.spec.ts +40 -0
- package/src/components/DashboardBuilder/newDashboard.ts +48 -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 +1161 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +1135 -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 +311 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +201 -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 +16 -62
- package/src/components/Environment/AddPackageDialog.tsx +85 -154
- package/src/components/Environment/Connections.tsx +125 -205
- package/src/components/Environment/DeletePackageDialog.tsx +32 -77
- package/src/components/Environment/EditPackageDialog.tsx +46 -58
- package/src/components/Environment/Environment.tsx +34 -36
- package/src/components/Environment/Packages.tsx +63 -128
- package/src/components/FloatingIconButton.tsx +41 -0
- package/src/components/Home/AddEnvironmentDialog.tsx +47 -70
- package/src/components/Home/DeleteEnvironmentDialog.tsx +32 -77
- package/src/components/Home/EditEnvironmentDialog.tsx +47 -61
- package/src/components/Home/Home.tsx +101 -214
- package/src/components/ItemRow.tsx +165 -0
- package/src/components/Materializations/CreateMaterializationDialog.tsx +34 -51
- package/src/components/Materializations/DeleteMaterializationDialog.tsx +31 -53
- package/src/components/Materializations/MaterializationDetailDialog.tsx +60 -69
- package/src/components/Materializations/MaterializationRunsList.tsx +29 -42
- package/src/components/Materializations/Materializations.tsx +137 -140
- package/src/components/Materializations/ScopeButton.tsx +85 -0
- package/src/components/Materializations/SectionLabel.tsx +7 -4
- package/src/components/Materializations/SetScheduleDialog.tsx +48 -89
- package/src/components/Materializations/TriggerLabel.tsx +36 -0
- package/src/components/Materializations/cron.spec.ts +113 -0
- package/src/components/Materializations/index.ts +0 -1
- package/src/components/Materializations/utils.spec.ts +182 -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/Package/ContentTypeIcon.spec.ts +22 -37
- package/src/components/Package/ContentTypeIcon.tsx +10 -12
- package/src/components/Package/NewDashboardDialog.spec.tsx +129 -0
- package/src/components/Package/NewDashboardDialog.tsx +265 -0
- package/src/components/Package/Package.tsx +179 -238
- package/src/components/Package/index.ts +0 -1
- package/src/components/PackageSection.tsx +85 -0
- 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/RenderedResult.lifecycle.spec.tsx +198 -0
- package/src/components/RenderedResult/RenderedResult.tsx +22 -8
- 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/ResultsDialog.tsx +8 -32
- package/src/components/buttons.tsx +114 -0
- package/src/components/designSystem.spec.tsx +316 -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/given/paramCodec.spec.ts +1 -1
- package/src/components/index.ts +16 -0
- package/src/components/styles.ts +49 -122
- package/src/hooks/index.ts +13 -0
- package/src/hooks/useCrudMutation.spec.tsx +119 -0
- package/src/hooks/useCrudMutation.tsx +85 -0
- package/src/hooks/useDocumentControls.ts +170 -0
- package/src/hooks/useQueryResult.ts +82 -0
- package/src/index.ts +9 -0
- package/src/telemetry/consoleEvents.spec.ts +130 -0
- package/src/telemetry/consoleEvents.ts +124 -0
- package/src/theme/defaults.ts +34 -23
- package/src/theme/resolveTheme.spec.ts +9 -4
- package/src/theme/resolveTheme.ts +12 -8
- package/src/utils/malloyLiteral.spec.ts +43 -0
- package/src/utils/malloyLiteral.ts +76 -0
- package/src/utils/sha256.ts +13 -0
- package/test/README.md +1 -1
- package/test/serverProvider.tsx +5 -2
- package/vite.config.ts +5 -0
- package/dist/ServerProvider-CGnLjzag.cjs.js +0 -1
- package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +0 -14
- package/dist/components/Materializations/EnvironmentMaterializations.d.ts +0 -7
- package/dist/components/Materializations/ScheduleCard.d.ts +0 -20
- package/dist/components/Materializations/TriggerChip.d.ts +0 -10
- package/dist/components/Package/Models.d.ts +0 -6
- package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +0 -179
- package/src/components/Materializations/EnvironmentMaterializations.tsx +0 -267
- package/src/components/Materializations/ScheduleCard.tsx +0 -231
- package/src/components/Materializations/TriggerChip.tsx +0 -44
- package/src/components/Package/Models.tsx +0 -71
|
@@ -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
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import { describe, expect, it } from "bun:test";
|
|
5
|
-
import {
|
|
6
|
-
import { CONTENT_TINT
|
|
5
|
+
import { PALETTE } from "../styles";
|
|
6
|
+
import { CONTENT_TINT } from "./ContentTypeIcon";
|
|
7
7
|
|
|
8
8
|
/** Relative luminance, WCAG 2.x definition. */
|
|
9
9
|
function luminance(hex: string): number {
|
|
@@ -34,18 +34,6 @@ describe("CONTENT_TINT", () => {
|
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
/**
|
|
38
|
-
* Content types whose colour predates this bar. `report` is backed by
|
|
39
|
-
* `MALLOY_BRAND.teal` at 2.5:1, which is below it; that is inherited from the
|
|
40
|
-
* logo and is a brand decision rather than a component one.
|
|
41
|
-
*
|
|
42
|
-
* Keyed by content TYPE rather than by colour, which is the whole point. A new
|
|
43
|
-
* type handed teal is not grandfathered and fails, and fixing teal one day
|
|
44
|
-
* leaves this entry merely unused rather than turning a correct fix into a red
|
|
45
|
-
* suite.
|
|
46
|
-
*/
|
|
47
|
-
const GRANDFATHERED: ContentType[] = ["report"];
|
|
48
|
-
|
|
49
37
|
describe("CONTENT_TINT contrast", () => {
|
|
50
38
|
/**
|
|
51
39
|
* Every tint fills a 32px backplate behind an 18px white glyph, so it has to
|
|
@@ -58,34 +46,31 @@ describe("CONTENT_TINT contrast", () => {
|
|
|
58
46
|
* what actually get painted. Asserting the accent palette alone left three of
|
|
59
47
|
* the six painted values unchecked.
|
|
60
48
|
*/
|
|
61
|
-
it.each(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// Guards the exception list against drift: a grandfathered name that no
|
|
70
|
-
// longer matches a `ContentType` fails here rather than silently exempting
|
|
71
|
-
// nothing. It does NOT catch the list being emptied, which passes
|
|
72
|
-
// vacuously; that case is caught instead by the contrast assertion for the
|
|
73
|
-
// type that stops being skipped, and an empty list is the desired end state
|
|
74
|
-
// anyway.
|
|
75
|
-
it("grandfathers only types that exist", () => {
|
|
76
|
-
for (const type of GRANDFATHERED) {
|
|
77
|
-
expect(CONTENT_TINT).toHaveProperty(type);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
49
|
+
it.each(Object.entries(CONTENT_TINT))(
|
|
50
|
+
"%s clears 3:1 against white",
|
|
51
|
+
(_type, hex) => {
|
|
52
|
+
expect(contrastWithWhite(hex)).toBeGreaterThanOrEqual(3);
|
|
53
|
+
},
|
|
54
|
+
);
|
|
80
55
|
});
|
|
81
56
|
|
|
82
|
-
describe("
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
|
|
57
|
+
describe("PALETTE", () => {
|
|
58
|
+
// Every hue holds the bar, whether or not it is assigned to a content type
|
|
59
|
+
// yet — so picking one for a new plate is always safe, and there is no
|
|
60
|
+
// exception list to grandfather anything into. There used to be one: the
|
|
61
|
+
// logo's teal sat at 2.5:1 and painted a row whose glyph did not meet the
|
|
62
|
+
// standard.
|
|
63
|
+
it.each(Object.entries(PALETTE))(
|
|
86
64
|
"%s clears 3:1 against white",
|
|
87
65
|
(_name, hex) => {
|
|
88
66
|
expect(contrastWithWhite(hex)).toBeGreaterThanOrEqual(3);
|
|
89
67
|
},
|
|
90
68
|
);
|
|
69
|
+
|
|
70
|
+
// Two kinds of thing painted the same colour is the failure the tints exist
|
|
71
|
+
// to prevent, so the palette they are drawn from must not repeat itself.
|
|
72
|
+
it("has no duplicate hues", () => {
|
|
73
|
+
const values = Object.values(PALETTE);
|
|
74
|
+
expect(new Set(values).size).toBe(values.length);
|
|
75
|
+
});
|
|
91
76
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import SvgIcon, { SvgIconProps } from "@mui/material/SvgIcon";
|
|
5
|
-
import {
|
|
5
|
+
import { PALETTE } from "../styles";
|
|
6
6
|
|
|
7
7
|
export type ContentType =
|
|
8
8
|
| "report"
|
|
@@ -17,23 +17,21 @@ export type ContentType =
|
|
|
17
17
|
* a page that lists all six, a shared color reads as a shared kind, and the
|
|
18
18
|
* glyphs are small enough that color does most of the telling apart.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* seniority ranking: dashboards are the newest thing a package can hold, and
|
|
24
|
-
* Package Data is among the oldest and takes an accent.
|
|
20
|
+
* Six hues from `PALETTE`, spaced far enough apart to survive being 18px of
|
|
21
|
+
* white on a 32px plate, and disjoint from the three `SURFACE_TINT` uses so a
|
|
22
|
+
* colour means one kind of thing everywhere in the Console.
|
|
25
23
|
*
|
|
26
24
|
* Exhaustive by type rather than by a default, so adding a `ContentType` is a
|
|
27
25
|
* compile error here instead of a row that silently paints itself the same as
|
|
28
26
|
* its neighbour.
|
|
29
27
|
*/
|
|
30
28
|
export const CONTENT_TINT: Record<ContentType, string> = {
|
|
31
|
-
dashboard:
|
|
32
|
-
report:
|
|
33
|
-
model:
|
|
34
|
-
dataApp:
|
|
35
|
-
data:
|
|
36
|
-
materialization:
|
|
29
|
+
dashboard: PALETTE.blue,
|
|
30
|
+
report: PALETTE.violet,
|
|
31
|
+
model: PALETTE.cyan,
|
|
32
|
+
dataApp: PALETTE.pink,
|
|
33
|
+
data: PALETTE.lime,
|
|
34
|
+
materialization: PALETTE.amber,
|
|
37
35
|
};
|
|
38
36
|
|
|
39
37
|
interface ContentTypeIconProps extends Omit<SvgIconProps, "fontSize"> {
|