@malloy-publisher/sdk 0.0.382-dev → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -95
- package/TREE_SHAKING.md +16 -11
- package/bunfig.toml +7 -0
- package/dist/ServerProvider-CTopDUWW.cjs.js +1 -0
- package/dist/ServerProvider-DUFPY6Rv.es.js +4072 -0
- package/dist/client/api.d.ts +3718 -1507
- package/dist/client/configuration.d.ts +1 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.es.js +85 -59
- package/dist/components/Connections/EditConnectionDialog.d.ts +2 -1
- package/dist/components/Connections/common.d.ts +8 -2
- package/dist/components/Dashboard/Dashboard.d.ts +49 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +48 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/DataAppViewer/DataAppViewer.d.ts +23 -0
- package/dist/components/DataAppViewer/index.d.ts +1 -0
- package/dist/components/Environment/Environment.d.ts +6 -0
- package/dist/components/Environment/index.d.ts +2 -0
- package/dist/components/Home/AddEnvironmentDialog.d.ts +1 -0
- package/dist/components/Home/DeleteEnvironmentDialog.d.ts +5 -0
- package/dist/components/Home/EditEnvironmentDialog.d.ts +7 -0
- package/dist/components/Home/Home.d.ts +2 -2
- package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +14 -0
- package/dist/components/Materializations/CreateMaterializationDialog.d.ts +10 -0
- package/dist/components/Materializations/DeleteMaterializationDialog.d.ts +7 -0
- package/dist/components/Materializations/EnvironmentMaterializations.d.ts +7 -0
- package/dist/components/Materializations/ManifestView.d.ts +13 -0
- package/dist/components/Materializations/MaterializationDetailDialog.d.ts +9 -0
- package/dist/components/Materializations/MaterializationRunsList.d.ts +15 -0
- package/dist/components/Materializations/Materializations.d.ts +7 -0
- package/dist/components/Materializations/ScheduleCard.d.ts +20 -0
- package/dist/components/Materializations/SectionLabel.d.ts +10 -0
- package/dist/components/Materializations/SetScheduleDialog.d.ts +11 -0
- package/dist/components/Materializations/TriggerChip.d.ts +10 -0
- package/dist/components/Materializations/cron.d.ts +23 -0
- package/dist/components/Materializations/index.d.ts +2 -0
- package/dist/components/Materializations/utils.d.ts +46 -0
- package/dist/components/Notebook/Notebook.d.ts +47 -4
- package/dist/components/Notebook/NotebookCell.d.ts +37 -1
- package/dist/components/Notebook/runPlan.d.ts +29 -0
- package/dist/components/Notebook/types.d.ts +10 -0
- package/dist/components/Package/ContentTypeIcon.d.ts +31 -0
- package/dist/components/Package/Package.d.ts +1 -4
- package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
- package/dist/components/RenderedResult/ResultContainer.d.ts +5 -1
- package/dist/components/RenderedResult/renderLogs.d.ts +6 -0
- package/dist/components/ResultsDialog.d.ts +6 -1
- package/dist/components/ServerProvider.d.ts +28 -4
- package/dist/components/click_helper.d.ts +10 -1
- package/dist/components/drill/index.d.ts +3 -0
- package/dist/components/drill/markDrillableCells.d.ts +55 -0
- package/dist/components/drill/resolveDrill.d.ts +139 -0
- package/dist/components/drill/useDrill.d.ts +63 -0
- package/dist/components/given/GivenInput.d.ts +52 -0
- package/dist/components/given/GivensPanel.d.ts +47 -0
- package/dist/components/given/filterValue.d.ts +97 -0
- package/dist/components/given/index.d.ts +2 -0
- package/dist/components/given/paramCodec.d.ts +60 -0
- package/dist/components/given/utils.d.ts +17 -0
- package/dist/components/highlighter.d.ts +6 -1
- package/dist/components/index.d.ts +7 -2
- package/dist/components/styles.d.ts +47 -0
- package/dist/constants/docLinks.d.ts +12 -0
- package/dist/{core-YNpOLuB1.cjs.js → core-hLahnv0W.cjs.js} +1 -1
- package/dist/{core-CjeTkq8O.es.js → core-lb28vQkR.es.js} +1 -1
- package/dist/github-dark-BKL9xNgN.cjs.js +1 -0
- package/dist/github-dark-DenFmJkN.es.js +4 -0
- package/dist/hooks/givenValue.d.ts +10 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/useDimensionFiltersFromSpec.d.ts +3 -3
- package/dist/hooks/useDimensionFiltersQuery.d.ts +3 -3
- package/dist/hooks/useDimensionalFilterRangeData.d.ts +4 -4
- package/dist/hooks/useGivensState.d.ts +64 -0
- package/dist/hooks/useModelGivens.d.ts +10 -0
- package/dist/hooks/useSuggestOptions.d.ts +78 -0
- package/dist/index-DvEanVgc.cjs.js +339 -0
- package/dist/{index-DRDu9kIV.es.js → index-txw04ZbN.es.js} +40531 -27964
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.es.js +79 -48
- package/dist/malloy-explorer.css +12 -1
- package/dist/sdk.css +1 -1
- package/dist/theme/ThemeContext.d.ts +45 -0
- package/dist/theme/buildMalloyExplicitTheme.d.ts +34 -0
- package/dist/theme/buildTableCssVars.d.ts +25 -0
- package/dist/theme/buildVegaThemeOverride.d.ts +16 -0
- package/dist/theme/defaults.d.ts +7 -0
- package/dist/theme/index.d.ts +8 -0
- package/dist/theme/keys.d.ts +20 -0
- package/dist/theme/readChartAnnotations.d.ts +23 -0
- package/dist/theme/resolveTheme.d.ts +22 -0
- package/dist/theme/types.d.ts +70 -0
- package/dist/utils/dataAppEmbed.d.ts +44 -0
- package/dist/utils/formatting.d.ts +1 -1
- package/dist/utils/malloyString.d.ts +7 -0
- package/dist/utils/parsing.d.ts +2 -2
- package/dist/utils/queryClient.d.ts +5 -0
- package/package.json +19 -8
- package/src/client-entry.ts +3 -0
- package/src/components/AnalyzePackageButton.tsx +9 -3
- package/src/components/ApiErrorDisplay.tsx +3 -0
- package/src/components/Connections/AddConnectionDialog.tsx +30 -2
- package/src/components/Connections/DeleteConnectionDialog.tsx +14 -3
- package/src/components/Connections/EditConnectionDialog.tsx +33 -4
- package/src/components/Connections/common.ts +64 -1
- package/src/components/DOMElement/DOMElement.tsx +3 -0
- package/src/components/DOMElement/index.ts +3 -0
- package/src/components/Dashboard/Dashboard.tsx +398 -0
- package/src/components/Dashboard/DashboardTile.tsx +153 -0
- package/src/components/Dashboard/index.ts +5 -0
- package/src/components/DataAppViewer/DataAppViewer.tsx +214 -0
- package/src/components/DataAppViewer/index.ts +4 -0
- package/src/components/{Project → Environment}/About.tsx +11 -4
- package/src/components/Environment/AddPackageDialog.tsx +202 -0
- package/src/components/{Project → Environment}/ConnectionExplorer.tsx +17 -14
- package/src/components/Environment/Connections.tsx +391 -0
- package/src/components/{Project → Environment}/DeletePackageDialog.tsx +8 -4
- package/src/components/{Project → Environment}/EditPackageDialog.tsx +21 -13
- package/src/components/Environment/Environment.tsx +89 -0
- package/src/components/Environment/Packages.tsx +206 -0
- package/src/components/Environment/index.ts +5 -0
- package/src/components/Home/{AddProjectDialog.tsx → AddEnvironmentDialog.tsx} +25 -19
- package/src/components/Home/{DeleteProjectDialog.tsx → DeleteEnvironmentDialog.tsx} +20 -15
- package/src/components/Home/{EditProjectDialog.tsx → EditEnvironmentDialog.tsx} +35 -28
- package/src/components/Home/Home.tsx +386 -408
- package/src/components/Home/index.ts +3 -0
- package/src/components/Loading.tsx +3 -0
- package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +179 -0
- package/src/components/Materializations/CreateMaterializationDialog.tsx +112 -0
- package/src/components/Materializations/DeleteMaterializationDialog.tsx +109 -0
- package/src/components/Materializations/EnvironmentMaterializations.tsx +267 -0
- package/src/components/Materializations/ManifestView.tsx +87 -0
- package/src/components/Materializations/MaterializationDetailDialog.tsx +259 -0
- package/src/components/Materializations/MaterializationRunsList.tsx +256 -0
- package/src/components/Materializations/Materializations.tsx +355 -0
- package/src/components/Materializations/ScheduleCard.tsx +231 -0
- package/src/components/Materializations/SectionLabel.tsx +30 -0
- package/src/components/Materializations/SetScheduleDialog.tsx +162 -0
- package/src/components/Materializations/TriggerChip.tsx +44 -0
- package/src/components/Materializations/cron.ts +124 -0
- package/src/components/Materializations/index.ts +5 -0
- package/src/components/Materializations/utils.ts +145 -0
- package/src/components/Model/Model.tsx +44 -2
- package/src/components/Model/ModelCell.tsx +14 -5
- package/src/components/Model/ModelExplorer.tsx +3 -0
- package/src/components/Model/ModelExplorerDialog.tsx +4 -1
- package/src/components/Model/SourcesExplorer.tsx +9 -6
- package/src/components/Model/index.ts +3 -0
- package/src/components/Model/useModelData.ts +6 -3
- package/src/components/Notebook/Notebook.tsx +475 -339
- package/src/components/Notebook/NotebookCell.tsx +264 -25
- package/src/components/Notebook/index.ts +3 -0
- package/src/components/Notebook/runPlan.spec.ts +155 -0
- package/src/components/Notebook/runPlan.ts +67 -0
- package/src/components/Notebook/types.ts +14 -0
- package/src/components/Package/ContentTypeIcon.spec.ts +91 -0
- package/src/components/Package/ContentTypeIcon.tsx +177 -0
- package/src/components/Package/FileTreeView.tsx +3 -0
- package/src/components/Package/Models.tsx +7 -4
- package/src/components/Package/Package.tsx +666 -59
- package/src/components/Package/index.ts +3 -0
- package/src/components/QueryResult/QueryResult.tsx +17 -8
- package/src/components/QueryResult/index.ts +3 -0
- package/src/components/RenderedResult/RenderedResult.tsx +685 -67
- package/src/components/RenderedResult/ResultContainer.tsx +71 -2
- package/src/components/RenderedResult/index.ts +3 -0
- package/src/components/RenderedResult/renderLogs.spec.ts +58 -0
- package/src/components/RenderedResult/renderLogs.ts +43 -0
- package/src/components/ResultsDialog.tsx +13 -1
- package/src/components/ServerProvider.tsx +175 -51
- package/src/components/Workbook/BrowserWorkbookStorage.ts +3 -0
- package/src/components/Workbook/EditableMalloyCell.tsx +3 -0
- package/src/components/Workbook/ModelPicker.tsx +7 -4
- package/src/components/Workbook/MutableCell.tsx +10 -5
- package/src/components/Workbook/Workbook.tsx +8 -5
- package/src/components/Workbook/WorkbookList.tsx +3 -0
- package/src/components/Workbook/WorkbookManager.ts +3 -0
- package/src/components/Workbook/WorkbookStorage.ts +3 -0
- package/src/components/Workbook/WorkbookStorageProvider.tsx +3 -0
- package/src/components/Workbook/index.ts +3 -0
- package/src/components/click_helper.ts +17 -1
- package/src/components/drill/index.ts +28 -0
- package/src/components/drill/markDrillableCells.dom.spec.ts +313 -0
- package/src/components/drill/markDrillableCells.spec.ts +109 -0
- package/src/components/drill/markDrillableCells.ts +314 -0
- package/src/components/drill/resolveDrill.spec.ts +449 -0
- package/src/components/drill/resolveDrill.ts +375 -0
- package/src/components/drill/useDrill.tsx +203 -0
- package/src/components/filter/DimensionFilter.tsx +3 -0
- package/src/components/filter/index.ts +3 -0
- package/src/components/filter/utils.ts +16 -5
- package/src/components/given/GivenInput.spec.tsx +689 -0
- package/src/components/given/GivenInput.tsx +801 -0
- package/src/components/given/GivensPanel.spec.tsx +175 -0
- package/src/components/given/GivensPanel.tsx +195 -0
- package/src/components/given/filterValue.spec.ts +364 -0
- package/src/components/given/filterValue.ts +207 -0
- package/src/components/given/index.ts +9 -0
- package/src/components/given/paramCodec.spec.ts +857 -0
- package/src/components/given/paramCodec.ts +483 -0
- package/src/components/given/utils.spec.ts +60 -0
- package/src/components/given/utils.ts +79 -0
- package/src/components/highlighter.ts +22 -5
- package/src/components/index.ts +10 -2
- package/src/components/styles.ts +82 -33
- package/src/constants/docLinks.spec.ts +54 -0
- package/src/constants/docLinks.ts +46 -0
- package/src/hooks/givenValue.ts +13 -0
- package/src/hooks/index.ts +13 -0
- package/src/hooks/useDimensionFilters.ts +4 -7
- package/src/hooks/useDimensionFiltersFromSpec.ts +8 -5
- package/src/hooks/useDimensionFiltersQuery.ts +10 -13
- package/src/hooks/useDimensionalFilterRangeData.ts +11 -14
- package/src/hooks/useGivensState.spec.ts +449 -0
- package/src/hooks/useGivensState.ts +340 -0
- package/src/hooks/useModelGivens.ts +29 -0
- package/src/hooks/useQueryWithApiError.ts +3 -0
- package/src/hooks/useRawQueryData.ts +6 -3
- package/src/hooks/useSuggestOptions.spec.ts +112 -0
- package/src/hooks/useSuggestOptions.ts +263 -0
- package/src/index.ts +10 -1
- package/src/react-app-env.d.ts +3 -0
- package/src/theme/ThemeContext.tsx +86 -0
- package/src/theme/buildMalloyExplicitTheme.ts +61 -0
- package/src/theme/buildTableCssVars.spec.ts +67 -0
- package/src/theme/buildTableCssVars.ts +67 -0
- package/src/theme/buildVegaThemeOverride.spec.ts +56 -0
- package/src/theme/buildVegaThemeOverride.ts +47 -0
- package/src/theme/defaults.ts +78 -0
- package/src/theme/index.ts +11 -0
- package/src/theme/keys.ts +32 -0
- package/src/theme/readChartAnnotations.spec.ts +58 -0
- package/src/theme/readChartAnnotations.ts +69 -0
- package/src/theme/resolveTheme.spec.ts +160 -0
- package/src/theme/resolveTheme.ts +121 -0
- package/src/theme/types.ts +79 -0
- package/src/utils/dataAppEmbed.spec.ts +63 -0
- package/src/utils/dataAppEmbed.ts +84 -0
- package/src/utils/formatting.spec.ts +25 -21
- package/src/utils/formatting.ts +11 -7
- package/src/utils/malloyString.spec.ts +24 -0
- package/src/utils/malloyString.ts +12 -0
- package/src/utils/parsing.spec.ts +26 -19
- package/src/utils/parsing.ts +11 -6
- package/src/utils/queryClient.ts +17 -0
- package/test/README.md +141 -0
- package/test/setup.ts +29 -0
- package/tsconfig.json +12 -1
- package/tsconfig.spec.json +22 -0
- package/vite.config.ts +3 -0
- package/dist/ServerProvider-lOQXDlqB.cjs.js +0 -1
- package/dist/ServerProvider-on-8FH5Z.es.js +0 -3060
- package/dist/components/Home/AddProjectDialog.d.ts +0 -1
- package/dist/components/Home/DeleteProjectDialog.d.ts +0 -5
- package/dist/components/Home/EditProjectDialog.d.ts +0 -7
- package/dist/components/Package/Config.d.ts +0 -5
- package/dist/components/Package/Databases.d.ts +0 -5
- package/dist/components/Package/Notebooks.d.ts +0 -6
- package/dist/components/Project/Project.d.ts +0 -6
- package/dist/components/Project/index.d.ts +0 -2
- package/dist/index-BOLBP6_i.cjs.js +0 -233
- package/src/components/Package/Config.tsx +0 -97
- package/src/components/Package/Connections.tsx +0 -373
- package/src/components/Package/Databases.tsx +0 -228
- package/src/components/Package/Notebooks.tsx +0 -77
- package/src/components/Project/AddPackageDialog.tsx +0 -159
- package/src/components/Project/Packages.tsx +0 -191
- package/src/components/Project/Project.tsx +0 -52
- package/src/components/Project/index.ts +0 -2
- /package/dist/components/{Project → Environment}/About.d.ts +0 -0
- /package/dist/components/{Project → Environment}/AddPackageDialog.d.ts +0 -0
- /package/dist/components/{Project → Environment}/ConnectionExplorer.d.ts +0 -0
- /package/dist/components/{Package → Environment}/Connections.d.ts +0 -0
- /package/dist/components/{Project → Environment}/DeletePackageDialog.d.ts +0 -0
- /package/dist/components/{Project → Environment}/EditPackageDialog.d.ts +0 -0
- /package/dist/components/{Project → Environment}/Packages.d.ts +0 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Alert, Box, Stack, Typography } from "@mui/material";
|
|
5
|
+
import { useCallback, useMemo } from "react";
|
|
6
|
+
import type { DashboardManifest } from "../../client";
|
|
7
|
+
import { useGivensState } from "../../hooks/useGivensState";
|
|
8
|
+
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
9
|
+
import { useSuggestOptions } from "../../hooks/useSuggestOptions";
|
|
10
|
+
import { parseResourceUri } from "../../utils/formatting";
|
|
11
|
+
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
12
|
+
import { encodeDrillValue, useDrill, type DrillNavigation } from "../drill";
|
|
13
|
+
import { GivensPanel } from "../given";
|
|
14
|
+
import { Loading } from "../Loading";
|
|
15
|
+
import { useServer } from "../ServerProvider";
|
|
16
|
+
import { DashboardTile } from "./DashboardTile";
|
|
17
|
+
|
|
18
|
+
export interface DashboardProps {
|
|
19
|
+
/** `publisher://environments/{env}/packages/{pkg}`, env and package only. */
|
|
20
|
+
resourceUri: string;
|
|
21
|
+
/** The dashboard's slug, as listed by the dashboards endpoint. */
|
|
22
|
+
dashboard: string;
|
|
23
|
+
/**
|
|
24
|
+
* Control values from the host, typically its URL query parameters. These
|
|
25
|
+
* beat the dashboard's own starting values, so a shared link shows what the
|
|
26
|
+
* sender was looking at.
|
|
27
|
+
*/
|
|
28
|
+
givens?: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* Applied control values, for a host that wants them in its URL. Fires with
|
|
31
|
+
* what the results reflect, not with every keystroke.
|
|
32
|
+
*
|
|
33
|
+
* `managed` is every given this dashboard declares, whether or not it
|
|
34
|
+
* currently holds a value, and a host writing to a shared query string needs
|
|
35
|
+
* it. `givens` alone says which parameters to write but not which to REMOVE,
|
|
36
|
+
* so a host that guesses by deleting everything it did not just receive
|
|
37
|
+
* deletes the unrelated parameters it has no business touching. Same contract
|
|
38
|
+
* as `Notebook`, so a host can treat the two surfaces alike.
|
|
39
|
+
*/
|
|
40
|
+
onGivensChange?: (
|
|
41
|
+
givens: Record<string, string>,
|
|
42
|
+
managed: readonly string[],
|
|
43
|
+
) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Where to go when a `# drill` cell is clicked. Without it, drilling to
|
|
46
|
+
* another dashboard is inert: `to=self` still filters in place, since that
|
|
47
|
+
* never leaves the component.
|
|
48
|
+
*/
|
|
49
|
+
onNavigate?: (target: DrillNavigation, event?: MouseEvent) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Height cap for a result panel. Left unset, each form gets the cap that
|
|
52
|
+
* suits its shape, see {@link TILE_HEIGHT} and {@link WHOLE_PAGE_HEIGHT}.
|
|
53
|
+
* Set it to hold a dashboard to a fixed box, as an embedding host might.
|
|
54
|
+
*/
|
|
55
|
+
height?: number;
|
|
56
|
+
maxResultSize?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Per-tile cap for the composite form. A tile is one panel among several, so
|
|
61
|
+
* capping them keeps the grid even instead of letting one long table set the
|
|
62
|
+
* height of its whole row.
|
|
63
|
+
*/
|
|
64
|
+
const TILE_HEIGHT = 400;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Cap for the single-query form, where the one result *is* the dashboard and a
|
|
68
|
+
* cap would clip the page rather than tidy it. High enough to be no cap in
|
|
69
|
+
* practice, and still a guard against a pathological result.
|
|
70
|
+
*
|
|
71
|
+
* A result that REPORTS its own height, which a `# dashboard` grid does, renders
|
|
72
|
+
* at that height and the page scrolls, which is what a reader expects. A result
|
|
73
|
+
* that sizes to its CONTAINER instead, which a bare `# bar_chart` does, has no
|
|
74
|
+
* height to report and keeps whatever first-paint height it was handed, so it
|
|
75
|
+
* stretches: measured 1992px for a two-row bar chart against 227px for the same
|
|
76
|
+
* query under a grid tag. `INITIAL_RENDER_HEIGHT` bounds that near 2000 rather
|
|
77
|
+
* than removing it, and lowering the bound is NOT the fix, because the same seed
|
|
78
|
+
* sizes a notebook's chart cells (measured 700px there). Telling the two kinds of
|
|
79
|
+
* result apart needs something the renderer does not expose here.
|
|
80
|
+
*/
|
|
81
|
+
const WHOLE_PAGE_HEIGHT = 20000;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A Malloyyo-style dashboard: a control row over one or more query results,
|
|
85
|
+
* declared entirely by tags in a package's `dashboards/*.malloy`.
|
|
86
|
+
*
|
|
87
|
+
* Host-agnostic on purpose. It takes props rather than reading a router, and
|
|
88
|
+
* hands navigation and URL state back to whoever mounted it, so the Publisher
|
|
89
|
+
* Console and an external React app render the same component and differ only
|
|
90
|
+
* in what they do with `onNavigate` and `onGivensChange`.
|
|
91
|
+
*/
|
|
92
|
+
export function Dashboard({
|
|
93
|
+
resourceUri,
|
|
94
|
+
dashboard,
|
|
95
|
+
givens,
|
|
96
|
+
onGivensChange,
|
|
97
|
+
onNavigate,
|
|
98
|
+
height,
|
|
99
|
+
maxResultSize,
|
|
100
|
+
}: DashboardProps) {
|
|
101
|
+
const parsed = parseResourceUri(resourceUri);
|
|
102
|
+
const { apiClients } = useServer();
|
|
103
|
+
|
|
104
|
+
// Degraded, not thrown. `Notebook`, `Model` and `Package` all let a bad URI
|
|
105
|
+
// fail into an error display; a throw in the render body takes the host's
|
|
106
|
+
// whole tree down with it instead, which is a white screen rather than a
|
|
107
|
+
// message. The Console cannot reach this, because `DashboardPage` builds the
|
|
108
|
+
// URI from params `ModelPage` has already guarded, so the only caller a throw
|
|
109
|
+
// could punish is the embedding host the docs invite. Reported below rather
|
|
110
|
+
// than here, so every hook still runs in the same order.
|
|
111
|
+
const environmentName = parsed.environmentName ?? "";
|
|
112
|
+
const packageName = parsed.packageName ?? "";
|
|
113
|
+
const uriNamesBoth = !!parsed.environmentName && !!parsed.packageName;
|
|
114
|
+
|
|
115
|
+
const {
|
|
116
|
+
data: manifestResponse,
|
|
117
|
+
isSuccess,
|
|
118
|
+
isError,
|
|
119
|
+
error,
|
|
120
|
+
} = useQueryWithApiError({
|
|
121
|
+
queryKey: ["dashboard", environmentName, packageName, dashboard],
|
|
122
|
+
queryFn: () =>
|
|
123
|
+
apiClients.dashboards.getDashboard(
|
|
124
|
+
environmentName,
|
|
125
|
+
packageName,
|
|
126
|
+
dashboard,
|
|
127
|
+
),
|
|
128
|
+
// No point asking for a dashboard under a name the URI never carried.
|
|
129
|
+
enabled: uriNamesBoth,
|
|
130
|
+
});
|
|
131
|
+
const manifest = manifestResponse?.data;
|
|
132
|
+
|
|
133
|
+
const specs = useMemo(() => manifest?.givens ?? [], [manifest]);
|
|
134
|
+
const declaredTypes = useMemo(
|
|
135
|
+
() =>
|
|
136
|
+
new Map(
|
|
137
|
+
specs
|
|
138
|
+
.filter((spec) => spec.name !== undefined)
|
|
139
|
+
.map((spec) => [spec.name as string, spec.type]),
|
|
140
|
+
),
|
|
141
|
+
[specs],
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
// Hands the host the names this dashboard MANAGES alongside the values, so it
|
|
145
|
+
// can merge into a shared query string instead of replacing it. Guarded on
|
|
146
|
+
// `isSuccess` as well as at the call site, since an empty declared set before
|
|
147
|
+
// the manifest lands is the absence of an answer rather than the answer.
|
|
148
|
+
const reportGivens = useCallback(
|
|
149
|
+
(next: Record<string, string>) => {
|
|
150
|
+
if (!isSuccess) return;
|
|
151
|
+
onGivensChange?.(next, Array.from(declaredTypes.keys()));
|
|
152
|
+
},
|
|
153
|
+
[isSuccess, onGivensChange, declaredTypes],
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const { draft, applied, setGiven, reset, apply, pending } = useGivensState({
|
|
157
|
+
declaredTypes,
|
|
158
|
+
startingValues: manifest?.startingGivens,
|
|
159
|
+
params: givens,
|
|
160
|
+
// Withheld until the manifest has loaded, for the same reason the notebook
|
|
161
|
+
// withholds it. Changing `dashboard` changes the query key, so `data` is
|
|
162
|
+
// undefined for one commit and `declaredTypes` is empty; `applied` prunes
|
|
163
|
+
// to nothing and the hook reports "no values, and I manage nothing". This
|
|
164
|
+
// component is reconciled rather than remounted on a dashboard-to-dashboard
|
|
165
|
+
// drill, so the hook's record of what it last reported still holds the
|
|
166
|
+
// PREVIOUS dashboard's values and does not suppress that report as a
|
|
167
|
+
// repeat. The host reasonably clears its query string, which is exactly the
|
|
168
|
+
// givens the drill just seeded for the dashboard now arriving.
|
|
169
|
+
onParamsChange: isSuccess ? reportGivens : undefined,
|
|
170
|
+
// Which document these edits belong to. Without it the edits are keyed by
|
|
171
|
+
// their starting VALUES alone, so two dashboards whose starting values
|
|
172
|
+
// coincide (the common case: both empty) look like one document, and the
|
|
173
|
+
// one you came from keeps filtering the one you drilled into.
|
|
174
|
+
documentKey: `${environmentName}/${packageName}/${dashboard}`,
|
|
175
|
+
// Absent means autorun; only an explicit `autorun=false` batches.
|
|
176
|
+
autorun: manifest?.autorun !== false,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const {
|
|
180
|
+
options,
|
|
181
|
+
isLoading: optionsLoading,
|
|
182
|
+
failed: optionsFailed,
|
|
183
|
+
} = useSuggestOptions(environmentName, packageName, manifest?.path, specs);
|
|
184
|
+
|
|
185
|
+
// A drill tag names its given as the model spells it, and `# drill` with no
|
|
186
|
+
// `given=` falls back to the DIMENSION's spelling, which need not match. The
|
|
187
|
+
// notebook folds case rather than picking a side, and this folds it the same
|
|
188
|
+
// way so one tag behaves identically on both surfaces.
|
|
189
|
+
const givenNamesByFold = useMemo(() => {
|
|
190
|
+
const byFold = new Map<string, string>();
|
|
191
|
+
for (const name of declaredTypes.keys()) {
|
|
192
|
+
// First declaration wins, so a model with `REGION` and `region` keeps
|
|
193
|
+
// the one it declared first rather than silently flipping.
|
|
194
|
+
if (!byFold.has(name.toLowerCase()))
|
|
195
|
+
byFold.set(name.toLowerCase(), name);
|
|
196
|
+
}
|
|
197
|
+
return byFold;
|
|
198
|
+
}, [declaredTypes]);
|
|
199
|
+
|
|
200
|
+
/** The declared given a drill tag's name refers to, or undefined. */
|
|
201
|
+
const resolveGiven = useCallback(
|
|
202
|
+
(given: string) =>
|
|
203
|
+
declaredTypes.has(given)
|
|
204
|
+
? given
|
|
205
|
+
: givenNamesByFold.get(given.toLowerCase()),
|
|
206
|
+
[declaredTypes, givenNamesByFold],
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
// `to=self` filters in place, which only works for a given this dashboard
|
|
210
|
+
// actually surfaces: sending one it cannot bind would fail every tile's
|
|
211
|
+
// query. Asked here rather than checked after the click, so a cell that
|
|
212
|
+
// cannot be honoured is never painted as clickable in the first place.
|
|
213
|
+
const canSelf = useCallback(
|
|
214
|
+
(given: string) => resolveGiven(given) !== undefined,
|
|
215
|
+
[resolveGiven],
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const onSelf = useCallback(
|
|
219
|
+
(given: string, rawValue: unknown) => {
|
|
220
|
+
const declared = resolveGiven(given);
|
|
221
|
+
if (declared === undefined) return;
|
|
222
|
+
// Encoded against the DECLARED type, which is knowable here and is not
|
|
223
|
+
// knowable at the click: `useDrill` hands over the raw cell value for
|
|
224
|
+
// exactly this reason. Passing it straight to `setGiven` skipped the
|
|
225
|
+
// encoder, so a clicked date reached a `number` given as epoch
|
|
226
|
+
// milliseconds and a filter value went unescaped. Set under the name
|
|
227
|
+
// the MODEL declares, so the value reaches the URL and the request
|
|
228
|
+
// under the one name the server knows.
|
|
229
|
+
const declaredType = declaredTypes.get(declared);
|
|
230
|
+
const value = encodeDrillValue(rawValue, declaredType);
|
|
231
|
+
if (value === undefined) {
|
|
232
|
+
// Say so, the way the notebook does. `canSelf` only checks that the
|
|
233
|
+
// NAME resolves, so a `given=` naming a type the clicked value
|
|
234
|
+
// cannot become still paints the whole column as clickable and then
|
|
235
|
+
// drops every click. That is an authoring mistake with no other
|
|
236
|
+
// symptom, and this is the likelier surface for it, because the
|
|
237
|
+
// givens are the dashboard's own.
|
|
238
|
+
console.warn(
|
|
239
|
+
`Drill declined: ${JSON.stringify(rawValue)} cannot be a value for given "${declared}"` +
|
|
240
|
+
(declaredType ? ` of type ${declaredType}` : ""),
|
|
241
|
+
);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
setGiven(declared, value);
|
|
245
|
+
},
|
|
246
|
+
[declaredTypes, resolveGiven, setGiven],
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
const { drill, drillMenu } = useDrill({
|
|
250
|
+
onNavigate,
|
|
251
|
+
onSelf,
|
|
252
|
+
canSelf,
|
|
253
|
+
selfLabel: "Filter this dashboard",
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// After every hook, so the hook order does not depend on the URI.
|
|
257
|
+
if (!uriNamesBoth) {
|
|
258
|
+
return (
|
|
259
|
+
<Alert severity="error">
|
|
260
|
+
A dashboard resource URI must name an environment and a package.
|
|
261
|
+
Received: {resourceUri}
|
|
262
|
+
</Alert>
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (isError) {
|
|
267
|
+
return (
|
|
268
|
+
<ApiErrorDisplay
|
|
269
|
+
context={`${environmentName} > ${packageName} > ${dashboard}`}
|
|
270
|
+
error={error}
|
|
271
|
+
/>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
if (!isSuccess || !manifest) {
|
|
275
|
+
return <Loading text="Loading dashboard…" />;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Reachable on the in-process load path only. Production loads a package
|
|
279
|
+
// through the worker pool, which aborts the package on the first compile
|
|
280
|
+
// error, so an uncompilable file answers 424 everywhere rather than serving a
|
|
281
|
+
// per-file error. Measured on this base with one bad file: the package
|
|
282
|
+
// endpoint, the dashboards listing, and the manifest of a dashboard that was
|
|
283
|
+
// FINE all answered 424. The earlier note here said such a dashboard "still
|
|
284
|
+
// lists and still resolves", which contradicted this repo's own docs and was
|
|
285
|
+
// the wrong half of the pair. Kept because the per-file error manifest still
|
|
286
|
+
// exists and an empty frame would be worse than saying why.
|
|
287
|
+
if (manifest.error) {
|
|
288
|
+
return (
|
|
289
|
+
<Stack spacing={2}>
|
|
290
|
+
<DashboardHeader manifest={manifest} />
|
|
291
|
+
<Alert severity="error">{manifest.error}</Alert>
|
|
292
|
+
</Stack>
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const modelPath = manifest.path;
|
|
297
|
+
const tiles = manifest.tiles ?? [];
|
|
298
|
+
|
|
299
|
+
return (
|
|
300
|
+
<Stack spacing={2}>
|
|
301
|
+
<DashboardHeader manifest={manifest} />
|
|
302
|
+
|
|
303
|
+
<GivensPanel
|
|
304
|
+
givens={specs}
|
|
305
|
+
values={draft}
|
|
306
|
+
onChange={setGiven}
|
|
307
|
+
onReset={reset}
|
|
308
|
+
layout="bar"
|
|
309
|
+
options={options}
|
|
310
|
+
optionsLoading={optionsLoading}
|
|
311
|
+
optionsFailed={optionsFailed}
|
|
312
|
+
apply={
|
|
313
|
+
manifest.autorun === false
|
|
314
|
+
? { onApply: apply, pending }
|
|
315
|
+
: undefined
|
|
316
|
+
}
|
|
317
|
+
/>
|
|
318
|
+
|
|
319
|
+
{modelPath === undefined ? (
|
|
320
|
+
<Alert severity="error">
|
|
321
|
+
This dashboard has no model path, so there is nothing to run.
|
|
322
|
+
</Alert>
|
|
323
|
+
) : manifest.query !== undefined ? (
|
|
324
|
+
// Single-query form: one query whose result IS the dashboard. Its
|
|
325
|
+
// `# dashboard {columns=N}` tag is the renderer's business, so no
|
|
326
|
+
// grid is imposed here: doing so would nest a grid in a grid.
|
|
327
|
+
<DashboardTile
|
|
328
|
+
environmentName={environmentName}
|
|
329
|
+
packageName={packageName}
|
|
330
|
+
modelPath={modelPath}
|
|
331
|
+
queryName={manifest.query}
|
|
332
|
+
givens={applied}
|
|
333
|
+
declaredTypes={declaredTypes}
|
|
334
|
+
height={height ?? WHOLE_PAGE_HEIGHT}
|
|
335
|
+
maxResultSize={maxResultSize}
|
|
336
|
+
drill={drill}
|
|
337
|
+
/>
|
|
338
|
+
) : tiles.length > 0 ? (
|
|
339
|
+
// Composite form: each tile runs on its own and the results are
|
|
340
|
+
// combined into one grid here, since no single Malloy result spans
|
|
341
|
+
// them.
|
|
342
|
+
<Box
|
|
343
|
+
sx={{
|
|
344
|
+
display: "grid",
|
|
345
|
+
gridTemplateColumns: {
|
|
346
|
+
xs: "1fr",
|
|
347
|
+
md: `repeat(${manifest.dashboardColumns ?? 2}, minmax(0, 1fr))`,
|
|
348
|
+
},
|
|
349
|
+
gap: 2,
|
|
350
|
+
}}
|
|
351
|
+
>
|
|
352
|
+
{tiles.map((tile, index) => (
|
|
353
|
+
<DashboardTile
|
|
354
|
+
// Position too, not the expression alone: `tiles=[…]` can
|
|
355
|
+
// repeat one, which is a typo rather than a request for two
|
|
356
|
+
// identical panels, and keying on the expression made the
|
|
357
|
+
// duplicate warn and reconcile onto its twin.
|
|
358
|
+
key={`${index}:${tile.query}`}
|
|
359
|
+
environmentName={environmentName}
|
|
360
|
+
packageName={packageName}
|
|
361
|
+
modelPath={modelPath}
|
|
362
|
+
tile={tile.query}
|
|
363
|
+
givens={applied}
|
|
364
|
+
declaredTypes={declaredTypes}
|
|
365
|
+
givenNames={tile.givenNames}
|
|
366
|
+
height={height ?? TILE_HEIGHT}
|
|
367
|
+
maxResultSize={maxResultSize}
|
|
368
|
+
drill={drill}
|
|
369
|
+
/>
|
|
370
|
+
))}
|
|
371
|
+
</Box>
|
|
372
|
+
) : (
|
|
373
|
+
<Alert severity="warning">
|
|
374
|
+
This dashboard names neither a query nor any tiles.
|
|
375
|
+
</Alert>
|
|
376
|
+
)}
|
|
377
|
+
|
|
378
|
+
{drillMenu}
|
|
379
|
+
</Stack>
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function DashboardHeader({ manifest }: { manifest: DashboardManifest }) {
|
|
384
|
+
return (
|
|
385
|
+
<Box>
|
|
386
|
+
<Typography variant="h5" sx={{ fontWeight: 600 }}>
|
|
387
|
+
{manifest.title ?? manifest.name}
|
|
388
|
+
</Typography>
|
|
389
|
+
{manifest.description && (
|
|
390
|
+
<Typography variant="body2" color="text.secondary">
|
|
391
|
+
{manifest.description}
|
|
392
|
+
</Typography>
|
|
393
|
+
)}
|
|
394
|
+
</Box>
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export default Dashboard;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box, Paper, Typography } from "@mui/material";
|
|
5
|
+
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
6
|
+
import type { GivenValue } from "../../hooks/givenValue";
|
|
7
|
+
import { CHART_RESULT_QUERY_OPTIONS } from "../../utils/queryClient";
|
|
8
|
+
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
9
|
+
import { humanizeSlug, type DrillBinding } from "../drill";
|
|
10
|
+
import { givensToRequest } from "../given/paramCodec";
|
|
11
|
+
import { Loading } from "../Loading";
|
|
12
|
+
import ResultContainer from "../RenderedResult/ResultContainer";
|
|
13
|
+
import { useServer } from "../ServerProvider";
|
|
14
|
+
|
|
15
|
+
export interface DashboardTileProps {
|
|
16
|
+
environmentName: string;
|
|
17
|
+
packageName: string;
|
|
18
|
+
modelPath: string;
|
|
19
|
+
/** A named query (the single-query form). */
|
|
20
|
+
queryName?: string;
|
|
21
|
+
/** A run expression (a composite tile). */
|
|
22
|
+
tile?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The whole applied control row, NOT this tile's share of it. The narrowing
|
|
25
|
+
* happens here, in `givensToRequest` below, using {@link givenNames}: the
|
|
26
|
+
* caller does not know which givens a tile references and this component
|
|
27
|
+
* does.
|
|
28
|
+
*/
|
|
29
|
+
givens: Map<string, GivenValue>;
|
|
30
|
+
/** Declared type per given name, which decides how a value is encoded. */
|
|
31
|
+
declaredTypes: ReadonlyMap<string, string | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Given names this tile references, or undefined when discovery could not
|
|
34
|
+
* resolve the tile. Undefined means "send the whole control row", which the
|
|
35
|
+
* server accepts: a surfaced given a query does not reference is ignored.
|
|
36
|
+
*/
|
|
37
|
+
givenNames?: string[];
|
|
38
|
+
height: number;
|
|
39
|
+
maxResultSize?: number;
|
|
40
|
+
/** Cell clicks and their affordance, for the dashboard's `# drill`. */
|
|
41
|
+
drill?: DrillBinding;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A composite tile's heading, read off its run expression: the last step's name
|
|
46
|
+
* as a sentence, so `scoped_sales -> sales_by_month` is titled "Sales by month".
|
|
47
|
+
*
|
|
48
|
+
* A tile in the single-query form gets its heading from a `# label` on the nest,
|
|
49
|
+
* and a composite tile has no nest to label: the entry is a string in
|
|
50
|
+
* `tiles=[…]`. Deriving it keeps the two forms reading alike instead of one
|
|
51
|
+
* showing titles and the other showing code.
|
|
52
|
+
*/
|
|
53
|
+
export function tileTitle(tile: string): string {
|
|
54
|
+
const lastStep = tile.split("->").at(-1)?.trim() ?? tile;
|
|
55
|
+
// Anything that is not a bare name (an inline `{ … }` stage, say) has no
|
|
56
|
+
// sensible title to derive, so it keeps the expression as written.
|
|
57
|
+
return /^[A-Za-z_][\w-]*$/.test(lastStep) ? humanizeSlug(lastStep) : tile;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* One result panel: run it, render it, and keep its failure to itself.
|
|
62
|
+
*
|
|
63
|
+
* A tile owning its own query is what lets a composite dashboard survive a bad
|
|
64
|
+
* tile: the broken one shows its error in place and the rest of the grid still
|
|
65
|
+
* renders, rather than one failure blanking the page.
|
|
66
|
+
*/
|
|
67
|
+
export function DashboardTile({
|
|
68
|
+
environmentName,
|
|
69
|
+
packageName,
|
|
70
|
+
modelPath,
|
|
71
|
+
queryName,
|
|
72
|
+
tile,
|
|
73
|
+
givens,
|
|
74
|
+
declaredTypes,
|
|
75
|
+
givenNames,
|
|
76
|
+
height,
|
|
77
|
+
maxResultSize,
|
|
78
|
+
drill,
|
|
79
|
+
}: DashboardTileProps) {
|
|
80
|
+
const { apiClients } = useServer();
|
|
81
|
+
const requestGivens = givensToRequest(givens, declaredTypes, givenNames);
|
|
82
|
+
|
|
83
|
+
const { data, isSuccess, isError, error } = useQueryWithApiError({
|
|
84
|
+
queryKey: [
|
|
85
|
+
"dashboardTile",
|
|
86
|
+
environmentName,
|
|
87
|
+
packageName,
|
|
88
|
+
modelPath,
|
|
89
|
+
queryName,
|
|
90
|
+
tile,
|
|
91
|
+
// Re-runs when the applied values change, which is the whole point of
|
|
92
|
+
// the control row.
|
|
93
|
+
JSON.stringify(requestGivens),
|
|
94
|
+
],
|
|
95
|
+
queryFn: () =>
|
|
96
|
+
apiClients.models.executeQueryModel(
|
|
97
|
+
environmentName,
|
|
98
|
+
packageName,
|
|
99
|
+
modelPath,
|
|
100
|
+
{
|
|
101
|
+
queryName,
|
|
102
|
+
query: tile !== undefined ? `run: ${tile}` : undefined,
|
|
103
|
+
givens: requestGivens,
|
|
104
|
+
},
|
|
105
|
+
),
|
|
106
|
+
...CHART_RESULT_QUERY_OPTIONS,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<Paper
|
|
111
|
+
elevation={0}
|
|
112
|
+
sx={{
|
|
113
|
+
border: 1,
|
|
114
|
+
borderColor: "divider",
|
|
115
|
+
borderRadius: 1,
|
|
116
|
+
overflow: "hidden",
|
|
117
|
+
minHeight: 120,
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
{tile !== undefined && (
|
|
121
|
+
<Box sx={{ px: 2.5, pt: 2 }}>
|
|
122
|
+
<Typography
|
|
123
|
+
variant="subtitle2"
|
|
124
|
+
sx={{ fontWeight: 500, color: "text.secondary" }}
|
|
125
|
+
// The expression is what actually ran, so it stays reachable
|
|
126
|
+
// as a tooltip rather than as the heading.
|
|
127
|
+
title={tile}
|
|
128
|
+
>
|
|
129
|
+
{tileTitle(tile)}
|
|
130
|
+
</Typography>
|
|
131
|
+
</Box>
|
|
132
|
+
)}
|
|
133
|
+
{!isSuccess && !isError && <Loading text="Running…" />}
|
|
134
|
+
{isSuccess && (
|
|
135
|
+
<ResultContainer
|
|
136
|
+
result={data.data.result}
|
|
137
|
+
maxHeight={height}
|
|
138
|
+
maxResultSize={maxResultSize}
|
|
139
|
+
renderLogs={data.data.renderLogs}
|
|
140
|
+
drill={drill}
|
|
141
|
+
/>
|
|
142
|
+
)}
|
|
143
|
+
{isError && (
|
|
144
|
+
<Box sx={{ p: 2 }}>
|
|
145
|
+
<ApiErrorDisplay
|
|
146
|
+
context={tile ?? queryName ?? modelPath}
|
|
147
|
+
error={error}
|
|
148
|
+
/>
|
|
149
|
+
</Box>
|
|
150
|
+
)}
|
|
151
|
+
</Paper>
|
|
152
|
+
);
|
|
153
|
+
}
|