@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
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value as a Malloy literal: `'text'`, `42`, `true`, `@2024-01-31`,
|
|
3
|
+
* `@2024-01-31 09:30:00`, or `f'…'` for a `filter<…>` type.
|
|
4
|
+
*
|
|
5
|
+
* With `type` — a given's declared type — the value is spelled the way that
|
|
6
|
+
* type reads it, so `"42"` for a `number` given is `42` and `true` for a
|
|
7
|
+
* `boolean` is `true`. Without it the JavaScript type decides, which is what a
|
|
8
|
+
* clicked cell's value needs. Undefined when there is nothing to write: no
|
|
9
|
+
* value, or one the type cannot spell.
|
|
10
|
+
*/
|
|
11
|
+
export declare function malloyLiteral(value: unknown, type?: string): string | undefined;
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloy-publisher/sdk",
|
|
3
3
|
"description": "Malloy Publisher SDK",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
7
7
|
"module": "dist/index.es.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"typesVersions": {
|
|
10
10
|
"*": {
|
|
11
|
+
"builder": [
|
|
12
|
+
"dist/builder-entry.d.ts"
|
|
13
|
+
],
|
|
11
14
|
"client": [
|
|
12
15
|
"dist/client-entry.d.ts"
|
|
13
16
|
],
|
|
@@ -29,6 +32,12 @@
|
|
|
29
32
|
"require": "./dist/client/index.cjs.js",
|
|
30
33
|
"default": "./dist/client/index.es.js"
|
|
31
34
|
},
|
|
35
|
+
"./builder": {
|
|
36
|
+
"types": "./dist/builder-entry.d.ts",
|
|
37
|
+
"import": "./dist/builder/index.es.js",
|
|
38
|
+
"require": "./dist/builder/index.cjs.js",
|
|
39
|
+
"default": "./dist/builder/index.es.js"
|
|
40
|
+
},
|
|
32
41
|
"./client/*": {
|
|
33
42
|
"types": "./dist/client/*.d.ts",
|
|
34
43
|
"import": "./dist/client/*.js",
|
|
@@ -63,10 +72,7 @@
|
|
|
63
72
|
"generate-api-types": "bunx openapi-generator-cli generate -i ../../api-doc.yaml -g typescript-axios -o src/client/"
|
|
64
73
|
},
|
|
65
74
|
"peerDependencies": {
|
|
66
|
-
"
|
|
67
|
-
"react-dom": ">=19.1.0",
|
|
68
|
-
"react-router-dom": ">=7.6.2",
|
|
69
|
-
"@tanstack/react-query": ">=5.59.16",
|
|
75
|
+
"@malloydata/malloy": "^0.0.432",
|
|
70
76
|
"@malloydata/malloy-explorer": "0.0.338-dev260215172810",
|
|
71
77
|
"@malloydata/malloy-filter": "^0.0.432",
|
|
72
78
|
"@malloydata/malloy-interfaces": "^0.0.432",
|
|
@@ -74,23 +80,32 @@
|
|
|
74
80
|
"@malloydata/malloy-tag": "^0.0.432",
|
|
75
81
|
"@malloydata/render": "^0.0.432",
|
|
76
82
|
"@mui/icons-material": ">=7.1.1",
|
|
77
|
-
"@mui/x-date-pickers": ">=7.1.1",
|
|
78
83
|
"@mui/material": ">=7.1.1",
|
|
79
84
|
"@mui/system": ">=7.1.1",
|
|
85
|
+
"@mui/x-date-pickers": ">=7.1.1",
|
|
80
86
|
"@mui/x-tree-view": ">=7.16.0",
|
|
81
|
-
"
|
|
87
|
+
"@tanstack/react-query": ">=5.59.16",
|
|
88
|
+
"axios": ">=1.7.7",
|
|
89
|
+
"react": ">=19.1.0",
|
|
90
|
+
"react-dom": ">=19.1.0",
|
|
91
|
+
"react-router-dom": ">=7.6.2"
|
|
82
92
|
},
|
|
83
93
|
"dependencies": {
|
|
94
|
+
"@dnd-kit/collision": "^0.5.0",
|
|
95
|
+
"@dnd-kit/dom": "^0.5.0",
|
|
96
|
+
"@dnd-kit/helpers": "^0.5.0",
|
|
97
|
+
"@dnd-kit/react": "^0.5.0",
|
|
84
98
|
"@emotion/react": "^11.14.0",
|
|
85
99
|
"@emotion/styled": "^11.14.0",
|
|
86
100
|
"@react-spring/web": "^10.0.1",
|
|
87
101
|
"cron-parser": "^5.6.2",
|
|
88
102
|
"cronstrue": "^2.50.0",
|
|
89
|
-
"
|
|
90
|
-
"
|
|
103
|
+
"dayjs": "^1.11.13",
|
|
104
|
+
"markdown-to-jsx": "^7.7.6"
|
|
91
105
|
},
|
|
92
106
|
"devDependencies": {
|
|
93
107
|
"@happy-dom/global-registrator": "^20.11.1",
|
|
108
|
+
"@malloydata/malloy": "^0.0.432",
|
|
94
109
|
"@malloydata/malloy-explorer": "0.0.338-dev260215172810",
|
|
95
110
|
"@malloydata/malloy-filter": "^0.0.432",
|
|
96
111
|
"@malloydata/malloy-query-builder": "^0.0.432",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
// The dashboard builder's entry point, separate from the SDK's main entry on
|
|
5
|
+
// purpose: the builder reads Malloy files with the Malloy parser, and that
|
|
6
|
+
// parser is 440 KB gzipped. Most Console users never open the builder, so this
|
|
7
|
+
// module is what a host loads LAZILY (`React.lazy(() => import(
|
|
8
|
+
// "@malloy-publisher/sdk/builder"))`), and nothing reachable from the main
|
|
9
|
+
// entry imports it. One static import of the parser anywhere on the main path
|
|
10
|
+
// would hoist all of it into every page load.
|
|
11
|
+
//
|
|
12
|
+
// The parser's dependencies (antlr4ts -> assert -> util) read `process.env` at
|
|
13
|
+
// module scope, which a browser does not define. A bundler's `define` does not
|
|
14
|
+
// reach pre-bundled dependencies, so the shim has to exist at runtime, before
|
|
15
|
+
// the parser's chunk is evaluated — and the reader's `await import` runs after
|
|
16
|
+
// this module has, which is what makes this the right place for it.
|
|
17
|
+
declare const globalThis: { process?: { env?: Record<string, string> } };
|
|
18
|
+
if (typeof globalThis.process === "undefined") {
|
|
19
|
+
globalThis.process = { env: {} };
|
|
20
|
+
} else if (globalThis.process.env === undefined) {
|
|
21
|
+
globalThis.process.env = {};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { DashboardBuilder } from "./components/DashboardBuilder/DashboardBuilder";
|
|
25
|
+
export type {
|
|
26
|
+
BuilderGiven,
|
|
27
|
+
DashboardBuilderProps,
|
|
28
|
+
} from "./components/DashboardBuilder/DashboardBuilder";
|
|
29
|
+
export {
|
|
30
|
+
DashboardEditor,
|
|
31
|
+
type DashboardEditorProps,
|
|
32
|
+
} from "./components/DashboardBuilder/DashboardEditor";
|
|
33
|
+
export type {
|
|
34
|
+
DashboardDocument,
|
|
35
|
+
DashboardTile,
|
|
36
|
+
LocalGiven,
|
|
37
|
+
} from "./components/DashboardBuilder/document";
|
|
38
|
+
export {
|
|
39
|
+
readDashboardDocument,
|
|
40
|
+
readFailed,
|
|
41
|
+
type ReadResult,
|
|
42
|
+
} from "./components/DashboardBuilder/readDocument";
|
|
43
|
+
export {
|
|
44
|
+
spliceDashboardDocument,
|
|
45
|
+
spliceFailed,
|
|
46
|
+
type SpliceResult,
|
|
47
|
+
} from "./components/DashboardBuilder/spliceDocument";
|
|
48
|
+
export {
|
|
49
|
+
buildCatalog,
|
|
50
|
+
type PackageCatalog,
|
|
51
|
+
} from "./components/DashboardBuilder/catalog";
|
|
52
|
+
export type {
|
|
53
|
+
DashboardEvent,
|
|
54
|
+
DashboardEventHandler,
|
|
55
|
+
} from "./components/Dashboard/telemetry";
|
|
@@ -151,9 +151,9 @@ describe("the version reaches what the manifest drives", () => {
|
|
|
151
151
|
it("runs the tile's query against the same version", async () => {
|
|
152
152
|
render(dashboardAt("v2"), { wrapper: serverWrapper });
|
|
153
153
|
|
|
154
|
-
await waitFor(() => expect(cacheKeys("
|
|
154
|
+
await waitFor(() => expect(cacheKeys("queryResult").length).toBe(1));
|
|
155
155
|
expect(tileRequest()?.versionId).toBe("v2");
|
|
156
|
-
expect(cacheKeys("
|
|
156
|
+
expect(cacheKeys("queryResult")[0]).toContain('"v2"');
|
|
157
157
|
});
|
|
158
158
|
|
|
159
159
|
it("runs every composite tile against the same version", async () => {
|
|
@@ -171,9 +171,8 @@ describe("the version reaches what the manifest drives", () => {
|
|
|
171
171
|
|
|
172
172
|
render(dashboardAt("v2"), { wrapper: serverWrapper });
|
|
173
173
|
|
|
174
|
-
await waitFor(() => expect(cacheKeys("
|
|
175
|
-
for (const key of cacheKeys("
|
|
176
|
-
expect(key).toContain('"v2"');
|
|
174
|
+
await waitFor(() => expect(cacheKeys("queryResult").length).toBe(2));
|
|
175
|
+
for (const key of cacheKeys("queryResult")) expect(key).toContain('"v2"');
|
|
177
176
|
});
|
|
178
177
|
|
|
179
178
|
it("runs the control's suggest query against the same version", async () => {
|
|
@@ -195,7 +194,7 @@ describe("the version reaches what the manifest drives", () => {
|
|
|
195
194
|
const { rerender } = render(dashboardAt("v1"), {
|
|
196
195
|
wrapper: serverWrapper,
|
|
197
196
|
});
|
|
198
|
-
await waitFor(() => expect(cacheKeys("
|
|
197
|
+
await waitFor(() => expect(cacheKeys("queryResult").length).toBe(1));
|
|
199
198
|
|
|
200
199
|
fireEvent.change(await screen.findByLabelText("REGION"), {
|
|
201
200
|
target: { value: "CA" },
|
|
@@ -206,10 +205,8 @@ describe("the version reaches what the manifest drives", () => {
|
|
|
206
205
|
|
|
207
206
|
rerender(dashboardAt("v2"));
|
|
208
207
|
|
|
209
|
-
await waitFor(() => expect(cacheKeys("
|
|
210
|
-
const v2 = cacheKeys("
|
|
211
|
-
key.includes('"v2"'),
|
|
212
|
-
);
|
|
208
|
+
await waitFor(() => expect(cacheKeys("queryResult").length).toBe(3));
|
|
209
|
+
const v2 = cacheKeys("queryResult").filter((key) => key.includes('"v2"'));
|
|
213
210
|
expect(v2).toHaveLength(1);
|
|
214
211
|
expect(v2[0]).not.toContain("CA");
|
|
215
212
|
});
|
|
@@ -2,20 +2,34 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import { Alert, Box, Stack, Typography } from "@mui/material";
|
|
5
|
-
import
|
|
6
|
-
import { useCallback, useMemo } from "react";
|
|
5
|
+
import { useCallback, useMemo, useState } from "react";
|
|
7
6
|
import type { DashboardManifest } from "../../client";
|
|
8
|
-
import {
|
|
7
|
+
import { useDocumentControls } from "../../hooks/useDocumentControls";
|
|
9
8
|
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
10
|
-
import { useSuggestOptions } from "../../hooks/useSuggestOptions";
|
|
11
9
|
import { parseResourceUri } from "../../utils/formatting";
|
|
12
10
|
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
13
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
useDrill,
|
|
13
|
+
type DrillBinding,
|
|
14
|
+
type DrillClickPayload,
|
|
15
|
+
type DrillNavigation,
|
|
16
|
+
type DrillRowsRequest,
|
|
17
|
+
} from "../drill";
|
|
14
18
|
import { GivensPanel } from "../given";
|
|
19
|
+
import { Prose } from "../Prose";
|
|
20
|
+
import { givensToRequest } from "../given/paramCodec";
|
|
15
21
|
import { Loading } from "../Loading";
|
|
16
22
|
import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
|
|
17
23
|
import { useServer } from "../ServerProvider";
|
|
24
|
+
import { DashboardGrid, DEFAULT_COLUMNS } from "./DashboardGrid";
|
|
18
25
|
import { DashboardTile } from "./DashboardTile";
|
|
26
|
+
import { ExploreDialog } from "./ExploreDialog";
|
|
27
|
+
import { RowsDialog, stepsOf, type RowsRequest } from "./RowsDialog";
|
|
28
|
+
import type { DashboardEventHandler } from "./telemetry";
|
|
29
|
+
|
|
30
|
+
// The grid rule moved to `DashboardGrid`, which the builder shares.
|
|
31
|
+
// Re-exported so existing importers of it are unaffected.
|
|
32
|
+
export { DEFAULT_COLUMNS, tileGridColumn } from "./DashboardGrid";
|
|
19
33
|
|
|
20
34
|
export interface DashboardProps {
|
|
21
35
|
/** `publisher://environments/{env}/packages/{pkg}`, optionally `?versionId=`. */
|
|
@@ -58,26 +72,8 @@ export interface DashboardProps {
|
|
|
58
72
|
*/
|
|
59
73
|
height?: number;
|
|
60
74
|
maxResultSize?: number;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
/** Grid width when the dashboard declares no `# dashboard { columns=N }`. */
|
|
64
|
-
const DEFAULT_COLUMNS = 2;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* The `grid-column` one tile occupies: its `# colspan`, and a `# break` forcing
|
|
68
|
-
* it to start a fresh row.
|
|
69
|
-
*
|
|
70
|
-
* Clamped to the grid width the same way @malloydata/render clamps it, so one
|
|
71
|
-
* view laid out as a composite tile and as a `nest:` under `# dashboard` lands
|
|
72
|
-
* in the same place. A break is `1 / span N` — an explicit start line, which is
|
|
73
|
-
* what pushes the tile down to the next row; the renderer's grid does the same.
|
|
74
|
-
*/
|
|
75
|
-
export function tileGridColumn(
|
|
76
|
-
tile: { colspan?: number; break?: boolean },
|
|
77
|
-
columns: number,
|
|
78
|
-
): string {
|
|
79
|
-
const span = Math.min(tile.colspan ?? 1, columns);
|
|
80
|
-
return tile.break ? `1 / span ${span}` : `span ${span}`;
|
|
75
|
+
/** The rows shown and tiles explored, for the host to log or count. */
|
|
76
|
+
onEvent?: DashboardEventHandler;
|
|
81
77
|
}
|
|
82
78
|
|
|
83
79
|
/**
|
|
@@ -97,6 +93,7 @@ export function Dashboard({
|
|
|
97
93
|
onNavigate,
|
|
98
94
|
height,
|
|
99
95
|
maxResultSize,
|
|
96
|
+
onEvent,
|
|
100
97
|
}: DashboardProps) {
|
|
101
98
|
const parsed = parseResourceUri(resourceUri);
|
|
102
99
|
const { apiClients } = useServer();
|
|
@@ -143,85 +140,72 @@ export function Dashboard({
|
|
|
143
140
|
const manifest = manifestResponse?.data;
|
|
144
141
|
|
|
145
142
|
const specs = useMemo(() => manifest?.givens ?? [], [manifest]);
|
|
146
|
-
const declaredTypes = useMemo(
|
|
147
|
-
() =>
|
|
148
|
-
new Map(
|
|
149
|
-
specs
|
|
150
|
-
.filter((spec) => spec.name !== undefined)
|
|
151
|
-
.map((spec) => [spec.name as string, spec.type]),
|
|
152
|
-
),
|
|
153
|
-
[specs],
|
|
154
|
-
);
|
|
155
143
|
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
(next: Record<string, string>) => {
|
|
162
|
-
if (!isSuccess) return;
|
|
163
|
-
onGivensChange?.(next, Array.from(declaredTypes.keys()));
|
|
164
|
-
},
|
|
165
|
-
[isSuccess, onGivensChange, declaredTypes],
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
const { draft, applied, setGiven, reset, apply, pending } = useGivensState({
|
|
169
|
-
declaredTypes,
|
|
144
|
+
// The control row's state, options and `to=self` drill: the same hook the
|
|
145
|
+
// notebook uses, so a control behaves identically on both surfaces.
|
|
146
|
+
const controls = useDocumentControls({
|
|
147
|
+
specs,
|
|
148
|
+
loaded: isSuccess,
|
|
170
149
|
startingValues: manifest?.startingGivens,
|
|
171
150
|
params: givens,
|
|
172
|
-
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
// repeat. The host reasonably clears its query string, which is exactly the
|
|
180
|
-
// givens the drill just seeded for the dashboard now arriving.
|
|
181
|
-
onParamsChange: isSuccess ? reportGivens : undefined,
|
|
182
|
-
// Which document these edits belong to. Without it the edits are keyed by
|
|
183
|
-
// their starting VALUES alone, so two dashboards whose starting values
|
|
184
|
-
// coincide (the common case: both empty) look like one document, and the
|
|
185
|
-
// one you came from keeps filtering the one you drilled into.
|
|
186
|
-
// The version belongs in that identity too, so a swap between versions
|
|
187
|
-
// drops the edits a reader made to the one they came from. Only the
|
|
188
|
-
// EDITS: `initial` is `startingValues` merged with `params`, so a host
|
|
189
|
-
// that round-trips givens through its own URL hands them straight back
|
|
190
|
-
// and they still apply across the swap. That one is the host's call, and
|
|
191
|
-
// this key neither can nor should overrule it.
|
|
151
|
+
onGivensChange,
|
|
152
|
+
// Which document these edits belong to, version included: two
|
|
153
|
+
// dashboards whose starting values coincide (both empty, usually)
|
|
154
|
+
// would otherwise look like one document, and the one you came from
|
|
155
|
+
// would keep filtering the one you drilled into. Only the EDITS: a host
|
|
156
|
+
// that round-trips givens through its own URL hands them straight back,
|
|
157
|
+
// and they still apply across the swap.
|
|
192
158
|
documentKey: `${environmentName}/${packageName}/${versionId ?? ""}/${dashboard}`,
|
|
193
159
|
// Absent means autorun; only an explicit `autorun=false` batches.
|
|
194
160
|
autorun: manifest?.autorun !== false,
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
const {
|
|
198
|
-
options,
|
|
199
|
-
isLoading: optionsLoading,
|
|
200
|
-
failed: optionsFailed,
|
|
201
|
-
} = useSuggestOptions(
|
|
202
161
|
environmentName,
|
|
203
162
|
packageName,
|
|
204
|
-
manifest?.path,
|
|
205
|
-
specs,
|
|
163
|
+
modelPath: manifest?.path,
|
|
206
164
|
versionId,
|
|
207
|
-
// So a suggest over a gated or scoped source carries the givens it needs.
|
|
208
|
-
{ values: applied, declaredTypes },
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
// `to=self` filters in place. Which givens a tag may set, and setting one
|
|
212
|
-
// from a clicked cell, is the same on both surfaces, so it is shared.
|
|
213
|
-
const { canSelf, onSelf } = useDrillSelf({
|
|
214
|
-
declaredTypes,
|
|
215
|
-
setGiven,
|
|
216
165
|
documentName: dashboard,
|
|
217
166
|
});
|
|
167
|
+
const { applied, declaredTypes, canSelf, onSelf } = controls;
|
|
168
|
+
|
|
169
|
+
// The rows behind a clicked value, and a tile's query in the explorer —
|
|
170
|
+
// the two ways past a number. Composite tiles only: each names its
|
|
171
|
+
// source, which is what the rows are of and what the explorer opens on.
|
|
172
|
+
const [rows, setRows] = useState<RowsRequest | undefined>(undefined);
|
|
173
|
+
const [exploring, setExploring] = useState<string | undefined>(undefined);
|
|
174
|
+
const onRows = useCallback((request: DrillRowsRequest) => {
|
|
175
|
+
const steps = stepsOf(request.context);
|
|
176
|
+
if (steps === undefined) return;
|
|
177
|
+
setRows({
|
|
178
|
+
...steps,
|
|
179
|
+
field: request.field,
|
|
180
|
+
rawValue: request.rawValue,
|
|
181
|
+
label: request.label,
|
|
182
|
+
});
|
|
183
|
+
}, []);
|
|
184
|
+
|
|
185
|
+
// The whole applied row: a source's own `where:` may read any of it, and a
|
|
186
|
+
// given the rows query does not reference is ignored by the server.
|
|
187
|
+
const rowsGivens = useMemo(
|
|
188
|
+
() => givensToRequest(applied, declaredTypes),
|
|
189
|
+
[applied, declaredTypes],
|
|
190
|
+
);
|
|
218
191
|
|
|
219
192
|
const { drill, drillMenu } = useDrill({
|
|
220
193
|
onNavigate,
|
|
221
194
|
onSelf,
|
|
222
195
|
canSelf,
|
|
223
196
|
selfLabel: "Filter this dashboard",
|
|
197
|
+
onRows,
|
|
224
198
|
});
|
|
199
|
+
// Each tile's clicks carry the tile they came from, so the rows behind a
|
|
200
|
+
// value know which source to run against.
|
|
201
|
+
const drillFor = useCallback(
|
|
202
|
+
(tile: string): DrillBinding => ({
|
|
203
|
+
canDrill: drill.canDrill,
|
|
204
|
+
onClick: (payload: DrillClickPayload) =>
|
|
205
|
+
drill.onClick({ ...payload, context: tile }),
|
|
206
|
+
}),
|
|
207
|
+
[drill],
|
|
208
|
+
);
|
|
225
209
|
|
|
226
210
|
// After every hook, so the hook order does not depend on the URI.
|
|
227
211
|
if (!uriNamesBoth) {
|
|
@@ -271,21 +255,7 @@ export function Dashboard({
|
|
|
271
255
|
<Stack spacing={2}>
|
|
272
256
|
<DashboardHeader manifest={manifest} />
|
|
273
257
|
|
|
274
|
-
<GivensPanel
|
|
275
|
-
givens={specs}
|
|
276
|
-
values={draft}
|
|
277
|
-
onChange={setGiven}
|
|
278
|
-
onReset={reset}
|
|
279
|
-
layout="bar"
|
|
280
|
-
options={options}
|
|
281
|
-
optionsLoading={optionsLoading}
|
|
282
|
-
optionsFailed={optionsFailed}
|
|
283
|
-
apply={
|
|
284
|
-
manifest.autorun === false
|
|
285
|
-
? { onApply: apply, pending }
|
|
286
|
-
: undefined
|
|
287
|
-
}
|
|
288
|
-
/>
|
|
258
|
+
<GivensPanel {...controls.panel} layout="bar" />
|
|
289
259
|
|
|
290
260
|
{modelPath === undefined ? (
|
|
291
261
|
<Alert severity="error">
|
|
@@ -311,50 +281,40 @@ export function Dashboard({
|
|
|
311
281
|
// Composite form: each tile runs on its own and the results are
|
|
312
282
|
// combined into one grid here, since no single Malloy result spans
|
|
313
283
|
// them.
|
|
314
|
-
<
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
284
|
+
<DashboardGrid
|
|
285
|
+
tiles={tiles}
|
|
286
|
+
columns={columns}
|
|
287
|
+
// Position too, not the expression alone: `tiles=[…]` can repeat
|
|
288
|
+
// one, which is a typo rather than a request for two identical
|
|
289
|
+
// panels, and keying on the expression made the duplicate warn
|
|
290
|
+
// and reconcile onto its twin.
|
|
291
|
+
keyOf={(tile, index) => `${index}:${tile.query}`}
|
|
292
|
+
renderTile={(tile) => (
|
|
293
|
+
<DashboardTile
|
|
294
|
+
environmentName={environmentName}
|
|
295
|
+
packageName={packageName}
|
|
296
|
+
versionId={versionId}
|
|
297
|
+
modelPath={modelPath}
|
|
298
|
+
tile={tile.query}
|
|
299
|
+
label={tile.label}
|
|
300
|
+
subtitle={tile.subtitle}
|
|
301
|
+
borderless={tile.borderless}
|
|
302
|
+
givens={applied}
|
|
303
|
+
declaredTypes={declaredTypes}
|
|
304
|
+
givenNames={tile.givenNames}
|
|
305
|
+
height={height ?? TILE_MAX_HEIGHT}
|
|
306
|
+
maxResultSize={maxResultSize}
|
|
307
|
+
drill={drillFor(tile.query)}
|
|
308
|
+
onExplore={() => {
|
|
309
|
+
setExploring(tile.query);
|
|
310
|
+
onEvent?.({
|
|
311
|
+
type: "dashboard.explored",
|
|
312
|
+
tile: tile.query,
|
|
313
|
+
});
|
|
337
314
|
}}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
packageName={packageName}
|
|
342
|
-
versionId={versionId}
|
|
343
|
-
modelPath={modelPath}
|
|
344
|
-
tile={tile.query}
|
|
345
|
-
label={tile.label}
|
|
346
|
-
subtitle={tile.subtitle}
|
|
347
|
-
borderless={tile.borderless}
|
|
348
|
-
givens={applied}
|
|
349
|
-
declaredTypes={declaredTypes}
|
|
350
|
-
givenNames={tile.givenNames}
|
|
351
|
-
height={height ?? TILE_MAX_HEIGHT}
|
|
352
|
-
maxResultSize={maxResultSize}
|
|
353
|
-
drill={drill}
|
|
354
|
-
/>
|
|
355
|
-
</Box>
|
|
356
|
-
))}
|
|
357
|
-
</Box>
|
|
315
|
+
/>
|
|
316
|
+
)}
|
|
317
|
+
/>
|
|
358
318
|
) : (
|
|
359
319
|
<Alert severity="warning">
|
|
360
320
|
This dashboard names neither a query nor any tiles.
|
|
@@ -362,6 +322,38 @@ export function Dashboard({
|
|
|
362
322
|
)}
|
|
363
323
|
|
|
364
324
|
{drillMenu}
|
|
325
|
+
{modelPath !== undefined && (
|
|
326
|
+
<>
|
|
327
|
+
<RowsDialog
|
|
328
|
+
request={rows}
|
|
329
|
+
environmentName={environmentName}
|
|
330
|
+
packageName={packageName}
|
|
331
|
+
{...(versionId === undefined ? {} : { versionId })}
|
|
332
|
+
modelPath={modelPath}
|
|
333
|
+
givens={rowsGivens}
|
|
334
|
+
onClose={() => setRows(undefined)}
|
|
335
|
+
onDone={(ok, durationMs) => {
|
|
336
|
+
if (rows)
|
|
337
|
+
onEvent?.({
|
|
338
|
+
type: "dashboard.rows_shown",
|
|
339
|
+
source: rows.source,
|
|
340
|
+
view: rows.view,
|
|
341
|
+
field: rows.field,
|
|
342
|
+
ok,
|
|
343
|
+
durationMs,
|
|
344
|
+
});
|
|
345
|
+
}}
|
|
346
|
+
/>
|
|
347
|
+
<ExploreDialog
|
|
348
|
+
tile={exploring}
|
|
349
|
+
environmentName={environmentName}
|
|
350
|
+
packageName={packageName}
|
|
351
|
+
{...(versionId === undefined ? {} : { versionId })}
|
|
352
|
+
modelPath={modelPath}
|
|
353
|
+
onClose={() => setExploring(undefined)}
|
|
354
|
+
/>
|
|
355
|
+
</>
|
|
356
|
+
)}
|
|
365
357
|
</Stack>
|
|
366
358
|
);
|
|
367
359
|
}
|
|
@@ -381,41 +373,39 @@ export function Dashboard({
|
|
|
381
373
|
* format cannot express yet. This is the half that needs nothing new.
|
|
382
374
|
*/
|
|
383
375
|
function DashboardHeader({ manifest }: { manifest: DashboardManifest }) {
|
|
376
|
+
return (
|
|
377
|
+
<DashboardProse
|
|
378
|
+
title={manifest.title ?? manifest.name}
|
|
379
|
+
{...(manifest.description
|
|
380
|
+
? { description: manifest.description }
|
|
381
|
+
: {})}
|
|
382
|
+
/>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* The prose header itself, over the two fields it actually needs.
|
|
388
|
+
*
|
|
389
|
+
* Separate from {@link DashboardHeader} so the BUILDER can render the same
|
|
390
|
+
* header over a `DashboardDocument` — which carries `title` and `description`
|
|
391
|
+
* but is not a manifest. Same argument as {@link tileGridColumn}: what the
|
|
392
|
+
* builder shows a author is the thing a reader will see, and one component is
|
|
393
|
+
* what stops the two drifting. A builder that restated this markdown block
|
|
394
|
+
* would be one edit away from showing a different header than it writes.
|
|
395
|
+
*/
|
|
396
|
+
export function DashboardProse({
|
|
397
|
+
title,
|
|
398
|
+
description,
|
|
399
|
+
}: {
|
|
400
|
+
title: string;
|
|
401
|
+
description?: string;
|
|
402
|
+
}) {
|
|
384
403
|
return (
|
|
385
404
|
<Box>
|
|
386
405
|
<Typography variant="h5" sx={{ fontWeight: 600 }}>
|
|
387
|
-
{
|
|
406
|
+
{title}
|
|
388
407
|
</Typography>
|
|
389
|
-
{
|
|
390
|
-
<Box
|
|
391
|
-
sx={{
|
|
392
|
-
color: "text.secondary",
|
|
393
|
-
typography: "body2",
|
|
394
|
-
// The block starts flush under the title and ends flush
|
|
395
|
-
// against the controls, so a one-line description sits
|
|
396
|
-
// exactly where the old `Typography` put it and a longer one
|
|
397
|
-
// grows downward rather than pushing the title around.
|
|
398
|
-
"& > :first-of-type": { mt: 0 },
|
|
399
|
-
"& > :last-child": { mb: 0 },
|
|
400
|
-
// Headings in a description are section labels within the
|
|
401
|
-
// page, not competitors to its title, so they stay at body
|
|
402
|
-
// weight and size rather than MUI's h1..h6 scale.
|
|
403
|
-
"& h1, & h2, & h3, & h4, & h5, & h6": {
|
|
404
|
-
fontSize: "inherit",
|
|
405
|
-
fontWeight: 600,
|
|
406
|
-
m: "0.5em 0 0.25em",
|
|
407
|
-
},
|
|
408
|
-
"& p": { m: "0.5em 0" },
|
|
409
|
-
"& ul, & ol": { m: "0.5em 0", pl: 3 },
|
|
410
|
-
"& code": {
|
|
411
|
-
fontFamily: "monospace",
|
|
412
|
-
fontSize: "0.9em",
|
|
413
|
-
},
|
|
414
|
-
}}
|
|
415
|
-
>
|
|
416
|
-
<Markdown>{manifest.description}</Markdown>
|
|
417
|
-
</Box>
|
|
418
|
-
)}
|
|
408
|
+
{description && <Prose variant="caption">{description}</Prose>}
|
|
419
409
|
</Box>
|
|
420
410
|
);
|
|
421
411
|
}
|