@malloy-publisher/sdk 0.0.382-dev → 0.2.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 +115 -95
- package/TREE_SHAKING.md +16 -11
- package/bunfig.toml +7 -0
- package/dist/ServerProvider-Cn_LhKda.cjs.js +1 -0
- package/dist/ServerProvider-sfabtriY.es.js +4076 -0
- package/dist/client/api.d.ts +3773 -1515
- 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 +86 -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 +62 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +57 -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-CqRKhtoy.cjs.js} +1 -1
- package/dist/{core-CjeTkq8O.es.js → core-DyU47reh.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-DRDu9kIV.es.js → index-CAkFE4Ol.es.js} +41278 -28504
- package/dist/index-DD4b_bt0.cjs.js +356 -0
- 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 +41 -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 +132 -25
- package/src/components/Connections/DeleteConnectionDialog.tsx +14 -3
- package/src/components/Connections/EditConnectionDialog.tsx +167 -37
- package/src/components/Connections/common.ts +94 -3
- package/src/components/DOMElement/DOMElement.tsx +3 -0
- package/src/components/DOMElement/index.ts +3 -0
- package/src/components/Dashboard/Dashboard.spec.tsx +216 -0
- package/src/components/Dashboard/Dashboard.tsx +458 -0
- package/src/components/Dashboard/DashboardTile.spec.tsx +81 -0
- package/src/components/Dashboard/DashboardTile.tsx +199 -0
- package/src/components/Dashboard/index.ts +5 -0
- package/src/components/Dashboard/tileGridColumn.spec.ts +35 -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.spec.tsx +88 -0
- package/src/components/Notebook/Notebook.tsx +476 -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.spec.tsx +113 -0
- package/src/components/Package/Package.tsx +692 -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 +725 -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.dom.spec.ts +91 -0
- package/src/hooks/useSuggestOptions.spec.ts +112 -0
- package/src/hooks/useSuggestOptions.ts +268 -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 +86 -0
- package/src/theme/buildTableCssVars.ts +98 -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 +185 -0
- package/test/serverProvider.tsx +72 -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,216 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What a dashboard's queries are CACHED under, not what they render.
|
|
6
|
+
*
|
|
7
|
+
* A version that reaches the request but not the request's key is worse than
|
|
8
|
+
* no version at all: two versions of one dashboard share a cache entry and one
|
|
9
|
+
* silently serves the other's data, which looks correct on screen. Nothing a
|
|
10
|
+
* manual smoke test can see, so it is pinned here.
|
|
11
|
+
*/
|
|
12
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
13
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
14
|
+
import {
|
|
15
|
+
cacheKeys,
|
|
16
|
+
clearCache,
|
|
17
|
+
mockServerProvider,
|
|
18
|
+
pending,
|
|
19
|
+
serverWrapper,
|
|
20
|
+
} from "../../../test/serverProvider";
|
|
21
|
+
import type { DashboardManifest } from "../../client";
|
|
22
|
+
|
|
23
|
+
const getDashboard = mock(
|
|
24
|
+
(
|
|
25
|
+
_environmentName: string,
|
|
26
|
+
_packageName: string,
|
|
27
|
+
_dashboardName: string,
|
|
28
|
+
_versionId?: string,
|
|
29
|
+
) => pending<{ data: DashboardManifest }>(),
|
|
30
|
+
);
|
|
31
|
+
const executeQueryModel = mock(
|
|
32
|
+
(
|
|
33
|
+
_environmentName: string,
|
|
34
|
+
_packageName: string,
|
|
35
|
+
_modelPath: string,
|
|
36
|
+
_request: { versionId?: string; givens?: Record<string, string> },
|
|
37
|
+
) => pending(),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
mockServerProvider({
|
|
41
|
+
dashboards: { getDashboard },
|
|
42
|
+
models: { executeQueryModel },
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Imported after the stub is registered: a static import would hoist above it.
|
|
46
|
+
const { default: Dashboard } = await import("./Dashboard");
|
|
47
|
+
|
|
48
|
+
const URI = "publisher://environments/env/packages/pkg";
|
|
49
|
+
|
|
50
|
+
const dashboardAt = (versionId?: string) => (
|
|
51
|
+
<Dashboard
|
|
52
|
+
resourceUri={
|
|
53
|
+
versionId === undefined ? URI : `${URI}?versionId=${versionId}`
|
|
54
|
+
}
|
|
55
|
+
dashboard="ops"
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
/** The latest tile request, told apart from a suggest by its `givens`. */
|
|
60
|
+
const tileRequest = () =>
|
|
61
|
+
executeQueryModel.mock.calls
|
|
62
|
+
.filter((call) => call[3] !== undefined && "givens" in call[3])
|
|
63
|
+
.at(-1)?.[3];
|
|
64
|
+
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
clearCache();
|
|
67
|
+
// `mockClear` leaves a queued `mockImplementationOnce` in place, so a test
|
|
68
|
+
// that queued one it never consumed would hand it to the next test.
|
|
69
|
+
getDashboard.mockReset();
|
|
70
|
+
getDashboard.mockImplementation(() => pending());
|
|
71
|
+
executeQueryModel.mockReset();
|
|
72
|
+
executeQueryModel.mockImplementation(() => pending());
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("the manifest fetch", () => {
|
|
76
|
+
it("sends the version the URI carried, and keys on it", async () => {
|
|
77
|
+
render(dashboardAt("v2"), { wrapper: serverWrapper });
|
|
78
|
+
|
|
79
|
+
await waitFor(() => expect(getDashboard).toHaveBeenCalled());
|
|
80
|
+
expect(getDashboard.mock.calls[0]).toEqual(["env", "pkg", "ops", "v2"]);
|
|
81
|
+
expect(cacheKeys("dashboard")[0]).toContain('"v2"');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("sends and keys nothing when the URI named no version", async () => {
|
|
85
|
+
render(dashboardAt(), { wrapper: serverWrapper });
|
|
86
|
+
|
|
87
|
+
await waitFor(() => expect(getDashboard).toHaveBeenCalled());
|
|
88
|
+
expect(getDashboard.mock.calls[0]).toEqual([
|
|
89
|
+
"env",
|
|
90
|
+
"pkg",
|
|
91
|
+
"ops",
|
|
92
|
+
undefined,
|
|
93
|
+
]);
|
|
94
|
+
// The whole key, not just the absence of a version: the slot is empty
|
|
95
|
+
// and nothing else about the key moved. A `toContain` here would pass
|
|
96
|
+
// for a key that had also grown something it should not carry.
|
|
97
|
+
expect(cacheKeys("dashboard")[0]).toBe(
|
|
98
|
+
'["dashboard","env","pkg",null,"ops","http://localhost/api/v0"]',
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("gives two versions of one dashboard two cache entries", async () => {
|
|
103
|
+
const { rerender } = render(dashboardAt("v1"), {
|
|
104
|
+
wrapper: serverWrapper,
|
|
105
|
+
});
|
|
106
|
+
await waitFor(() => expect(getDashboard).toHaveBeenCalledTimes(1));
|
|
107
|
+
|
|
108
|
+
rerender(dashboardAt("v2"));
|
|
109
|
+
|
|
110
|
+
await waitFor(() => expect(getDashboard).toHaveBeenCalledTimes(2));
|
|
111
|
+
expect(new Set(cacheKeys("dashboard")).size).toBe(2);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("keys two spellings of one unversioned dashboard together", async () => {
|
|
115
|
+
// Built from what `parseResourceUri` returned rather than from the URI
|
|
116
|
+
// as the host spelled it, so an empty `?versionId=` and no query string
|
|
117
|
+
// at all stay one cache entry instead of fetching the same thing twice.
|
|
118
|
+
const { rerender } = render(dashboardAt(), { wrapper: serverWrapper });
|
|
119
|
+
await waitFor(() => expect(getDashboard).toHaveBeenCalledTimes(1));
|
|
120
|
+
|
|
121
|
+
rerender(<Dashboard resourceUri={`${URI}?versionId=`} dashboard="ops" />);
|
|
122
|
+
|
|
123
|
+
await waitFor(() => expect(cacheKeys("dashboard").length).toBe(1));
|
|
124
|
+
expect(getDashboard).toHaveBeenCalledTimes(1);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("the version reaches what the manifest drives", () => {
|
|
129
|
+
// End to end through the manifest: the version has to survive the fetch and
|
|
130
|
+
// be handed on, which is the step a key-only test cannot see.
|
|
131
|
+
const manifest: DashboardManifest = {
|
|
132
|
+
name: "ops",
|
|
133
|
+
path: "dashboards/ops.malloy",
|
|
134
|
+
query: "overview",
|
|
135
|
+
givens: [
|
|
136
|
+
{ name: "REGION", type: "string" },
|
|
137
|
+
{
|
|
138
|
+
name: "TIER",
|
|
139
|
+
control: "select",
|
|
140
|
+
suggest: { source: "orders", dimension: "tier" },
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
beforeEach(() => {
|
|
146
|
+
getDashboard.mockImplementation(() =>
|
|
147
|
+
Promise.resolve({ data: manifest }),
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("runs the tile's query against the same version", async () => {
|
|
152
|
+
render(dashboardAt("v2"), { wrapper: serverWrapper });
|
|
153
|
+
|
|
154
|
+
await waitFor(() => expect(cacheKeys("dashboardTile").length).toBe(1));
|
|
155
|
+
expect(tileRequest()?.versionId).toBe("v2");
|
|
156
|
+
expect(cacheKeys("dashboardTile")[0]).toContain('"v2"');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("runs every composite tile against the same version", async () => {
|
|
160
|
+
// The composite branch wraps each tile in its own grid cell, so the prop
|
|
161
|
+
// is threaded at a different call site than the single-query form above.
|
|
162
|
+
getDashboard.mockImplementation(() =>
|
|
163
|
+
Promise.resolve({
|
|
164
|
+
data: {
|
|
165
|
+
...manifest,
|
|
166
|
+
query: undefined,
|
|
167
|
+
tiles: [{ query: "by_month" }, { query: "by_region" }],
|
|
168
|
+
},
|
|
169
|
+
}),
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
render(dashboardAt("v2"), { wrapper: serverWrapper });
|
|
173
|
+
|
|
174
|
+
await waitFor(() => expect(cacheKeys("dashboardTile").length).toBe(2));
|
|
175
|
+
for (const key of cacheKeys("dashboardTile"))
|
|
176
|
+
expect(key).toContain('"v2"');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("runs the control's suggest query against the same version", async () => {
|
|
180
|
+
render(dashboardAt("v2"), { wrapper: serverWrapper });
|
|
181
|
+
|
|
182
|
+
await waitFor(() => expect(cacheKeys("givenSuggest").length).toBe(1));
|
|
183
|
+
expect(cacheKeys("givenSuggest")[0]).toContain('"v2"');
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("does not carry one version's applied values into another", async () => {
|
|
187
|
+
// `documentKey` is what tells `useGivensState` the document changed. With
|
|
188
|
+
// the version missing from it, a host swapping versions kept the values
|
|
189
|
+
// the reader applied to the old one and filtered the new one by them —
|
|
190
|
+
// the same confusion the keys above exist to prevent, one layer up.
|
|
191
|
+
//
|
|
192
|
+
// Mounted with no `givens` prop, which is the case the key governs. A
|
|
193
|
+
// host feeding its URL back in through `givens` re-supplies the values
|
|
194
|
+
// itself, and no `documentKey` can override that.
|
|
195
|
+
const { rerender } = render(dashboardAt("v1"), {
|
|
196
|
+
wrapper: serverWrapper,
|
|
197
|
+
});
|
|
198
|
+
await waitFor(() => expect(cacheKeys("dashboardTile").length).toBe(1));
|
|
199
|
+
|
|
200
|
+
fireEvent.change(await screen.findByLabelText("REGION"), {
|
|
201
|
+
target: { value: "CA" },
|
|
202
|
+
});
|
|
203
|
+
await waitFor(() =>
|
|
204
|
+
expect(tileRequest()?.givens).toEqual({ REGION: "CA" }),
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
rerender(dashboardAt("v2"));
|
|
208
|
+
|
|
209
|
+
await waitFor(() => expect(cacheKeys("dashboardTile").length).toBe(3));
|
|
210
|
+
const v2 = cacheKeys("dashboardTile").filter((key) =>
|
|
211
|
+
key.includes('"v2"'),
|
|
212
|
+
);
|
|
213
|
+
expect(v2).toHaveLength(1);
|
|
214
|
+
expect(v2[0]).not.toContain("CA");
|
|
215
|
+
});
|
|
216
|
+
});
|
|
@@ -0,0 +1,458 @@
|
|
|
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}`, optionally `?versionId=`. */
|
|
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
|
+
/** Grid width when the dashboard declares no `# dashboard { columns=N }`. */
|
|
84
|
+
const DEFAULT_COLUMNS = 2;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The `grid-column` one tile occupies: its `# colspan`, and a `# break` forcing
|
|
88
|
+
* it to start a fresh row.
|
|
89
|
+
*
|
|
90
|
+
* Clamped to the grid width the same way @malloydata/render clamps it, so one
|
|
91
|
+
* view laid out as a composite tile and as a `nest:` under `# dashboard` lands
|
|
92
|
+
* in the same place. A break is `1 / span N` — an explicit start line, which is
|
|
93
|
+
* what pushes the tile down to the next row; the renderer's grid does the same.
|
|
94
|
+
*/
|
|
95
|
+
export function tileGridColumn(
|
|
96
|
+
tile: { colspan?: number; break?: boolean },
|
|
97
|
+
columns: number,
|
|
98
|
+
): string {
|
|
99
|
+
const span = Math.min(tile.colspan ?? 1, columns);
|
|
100
|
+
return tile.break ? `1 / span ${span}` : `span ${span}`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A Malloyyo-style dashboard: a control row over one or more query results,
|
|
105
|
+
* declared entirely by tags in a package's `dashboards/*.malloy`.
|
|
106
|
+
*
|
|
107
|
+
* Host-agnostic on purpose. It takes props rather than reading a router, and
|
|
108
|
+
* hands navigation and URL state back to whoever mounted it, so the Publisher
|
|
109
|
+
* Console and an external React app render the same component and differ only
|
|
110
|
+
* in what they do with `onNavigate` and `onGivensChange`.
|
|
111
|
+
*/
|
|
112
|
+
export function Dashboard({
|
|
113
|
+
resourceUri,
|
|
114
|
+
dashboard,
|
|
115
|
+
givens,
|
|
116
|
+
onGivensChange,
|
|
117
|
+
onNavigate,
|
|
118
|
+
height,
|
|
119
|
+
maxResultSize,
|
|
120
|
+
}: DashboardProps) {
|
|
121
|
+
const parsed = parseResourceUri(resourceUri);
|
|
122
|
+
const { apiClients } = useServer();
|
|
123
|
+
|
|
124
|
+
// Degraded, not thrown. `Notebook`, `Model` and `Package` all let a bad URI
|
|
125
|
+
// fail into an error display; a throw in the render body takes the host's
|
|
126
|
+
// whole tree down with it instead, which is a white screen rather than a
|
|
127
|
+
// message. The Console cannot reach this, because `DashboardPage` builds the
|
|
128
|
+
// URI from params `ModelPage` has already guarded, so the only caller a throw
|
|
129
|
+
// could punish is the embedding host the docs invite. Reported below rather
|
|
130
|
+
// than here, so every hook still runs in the same order.
|
|
131
|
+
const environmentName = parsed.environmentName ?? "";
|
|
132
|
+
const packageName = parsed.packageName ?? "";
|
|
133
|
+
const versionId = parsed.versionId;
|
|
134
|
+
const uriNamesBoth = !!parsed.environmentName && !!parsed.packageName;
|
|
135
|
+
|
|
136
|
+
const {
|
|
137
|
+
data: manifestResponse,
|
|
138
|
+
isSuccess,
|
|
139
|
+
isError,
|
|
140
|
+
error,
|
|
141
|
+
} = useQueryWithApiError({
|
|
142
|
+
// Every value the request is built from, so the key cannot drift out of
|
|
143
|
+
// step with it. A version that reached the request alone would leave two
|
|
144
|
+
// versions of one dashboard on a single cache entry, each able to serve
|
|
145
|
+
// the other's manifest.
|
|
146
|
+
queryKey: [
|
|
147
|
+
"dashboard",
|
|
148
|
+
environmentName,
|
|
149
|
+
packageName,
|
|
150
|
+
versionId,
|
|
151
|
+
dashboard,
|
|
152
|
+
],
|
|
153
|
+
queryFn: () =>
|
|
154
|
+
apiClients.dashboards.getDashboard(
|
|
155
|
+
environmentName,
|
|
156
|
+
packageName,
|
|
157
|
+
dashboard,
|
|
158
|
+
versionId,
|
|
159
|
+
),
|
|
160
|
+
// No point asking for a dashboard under a name the URI never carried.
|
|
161
|
+
enabled: uriNamesBoth,
|
|
162
|
+
});
|
|
163
|
+
const manifest = manifestResponse?.data;
|
|
164
|
+
|
|
165
|
+
const specs = useMemo(() => manifest?.givens ?? [], [manifest]);
|
|
166
|
+
const declaredTypes = useMemo(
|
|
167
|
+
() =>
|
|
168
|
+
new Map(
|
|
169
|
+
specs
|
|
170
|
+
.filter((spec) => spec.name !== undefined)
|
|
171
|
+
.map((spec) => [spec.name as string, spec.type]),
|
|
172
|
+
),
|
|
173
|
+
[specs],
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
// Hands the host the names this dashboard MANAGES alongside the values, so it
|
|
177
|
+
// can merge into a shared query string instead of replacing it. Guarded on
|
|
178
|
+
// `isSuccess` as well as at the call site, since an empty declared set before
|
|
179
|
+
// the manifest lands is the absence of an answer rather than the answer.
|
|
180
|
+
const reportGivens = useCallback(
|
|
181
|
+
(next: Record<string, string>) => {
|
|
182
|
+
if (!isSuccess) return;
|
|
183
|
+
onGivensChange?.(next, Array.from(declaredTypes.keys()));
|
|
184
|
+
},
|
|
185
|
+
[isSuccess, onGivensChange, declaredTypes],
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
const { draft, applied, setGiven, reset, apply, pending } = useGivensState({
|
|
189
|
+
declaredTypes,
|
|
190
|
+
startingValues: manifest?.startingGivens,
|
|
191
|
+
params: givens,
|
|
192
|
+
// Withheld until the manifest has loaded, for the same reason the notebook
|
|
193
|
+
// withholds it. Changing `dashboard` changes the query key, so `data` is
|
|
194
|
+
// undefined for one commit and `declaredTypes` is empty; `applied` prunes
|
|
195
|
+
// to nothing and the hook reports "no values, and I manage nothing". This
|
|
196
|
+
// component is reconciled rather than remounted on a dashboard-to-dashboard
|
|
197
|
+
// drill, so the hook's record of what it last reported still holds the
|
|
198
|
+
// PREVIOUS dashboard's values and does not suppress that report as a
|
|
199
|
+
// repeat. The host reasonably clears its query string, which is exactly the
|
|
200
|
+
// givens the drill just seeded for the dashboard now arriving.
|
|
201
|
+
onParamsChange: isSuccess ? reportGivens : undefined,
|
|
202
|
+
// Which document these edits belong to. Without it the edits are keyed by
|
|
203
|
+
// their starting VALUES alone, so two dashboards whose starting values
|
|
204
|
+
// coincide (the common case: both empty) look like one document, and the
|
|
205
|
+
// one you came from keeps filtering the one you drilled into.
|
|
206
|
+
// The version belongs in that identity too, so a swap between versions
|
|
207
|
+
// drops the edits a reader made to the one they came from. Only the
|
|
208
|
+
// EDITS: `initial` is `startingValues` merged with `params`, so a host
|
|
209
|
+
// that round-trips givens through its own URL hands them straight back
|
|
210
|
+
// and they still apply across the swap. That one is the host's call, and
|
|
211
|
+
// this key neither can nor should overrule it.
|
|
212
|
+
documentKey: `${environmentName}/${packageName}/${versionId ?? ""}/${dashboard}`,
|
|
213
|
+
// Absent means autorun; only an explicit `autorun=false` batches.
|
|
214
|
+
autorun: manifest?.autorun !== false,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const {
|
|
218
|
+
options,
|
|
219
|
+
isLoading: optionsLoading,
|
|
220
|
+
failed: optionsFailed,
|
|
221
|
+
} = useSuggestOptions(
|
|
222
|
+
environmentName,
|
|
223
|
+
packageName,
|
|
224
|
+
manifest?.path,
|
|
225
|
+
specs,
|
|
226
|
+
versionId,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
// A drill tag names its given as the model spells it, and `# drill` with no
|
|
230
|
+
// `given=` falls back to the DIMENSION's spelling, which need not match. The
|
|
231
|
+
// notebook folds case rather than picking a side, and this folds it the same
|
|
232
|
+
// way so one tag behaves identically on both surfaces.
|
|
233
|
+
const givenNamesByFold = useMemo(() => {
|
|
234
|
+
const byFold = new Map<string, string>();
|
|
235
|
+
for (const name of declaredTypes.keys()) {
|
|
236
|
+
// First declaration wins, so a model with `REGION` and `region` keeps
|
|
237
|
+
// the one it declared first rather than silently flipping.
|
|
238
|
+
if (!byFold.has(name.toLowerCase()))
|
|
239
|
+
byFold.set(name.toLowerCase(), name);
|
|
240
|
+
}
|
|
241
|
+
return byFold;
|
|
242
|
+
}, [declaredTypes]);
|
|
243
|
+
|
|
244
|
+
/** The declared given a drill tag's name refers to, or undefined. */
|
|
245
|
+
const resolveGiven = useCallback(
|
|
246
|
+
(given: string) =>
|
|
247
|
+
declaredTypes.has(given)
|
|
248
|
+
? given
|
|
249
|
+
: givenNamesByFold.get(given.toLowerCase()),
|
|
250
|
+
[declaredTypes, givenNamesByFold],
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
// `to=self` filters in place, which only works for a given this dashboard
|
|
254
|
+
// actually surfaces: sending one it cannot bind would fail every tile's
|
|
255
|
+
// query. Asked here rather than checked after the click, so a cell that
|
|
256
|
+
// cannot be honoured is never painted as clickable in the first place.
|
|
257
|
+
const canSelf = useCallback(
|
|
258
|
+
(given: string) => resolveGiven(given) !== undefined,
|
|
259
|
+
[resolveGiven],
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
const onSelf = useCallback(
|
|
263
|
+
(given: string, rawValue: unknown) => {
|
|
264
|
+
const declared = resolveGiven(given);
|
|
265
|
+
if (declared === undefined) return;
|
|
266
|
+
// Encoded against the DECLARED type, which is knowable here and is not
|
|
267
|
+
// knowable at the click: `useDrill` hands over the raw cell value for
|
|
268
|
+
// exactly this reason. Passing it straight to `setGiven` skipped the
|
|
269
|
+
// encoder, so a clicked date reached a `number` given as epoch
|
|
270
|
+
// milliseconds and a filter value went unescaped. Set under the name
|
|
271
|
+
// the MODEL declares, so the value reaches the URL and the request
|
|
272
|
+
// under the one name the server knows.
|
|
273
|
+
const declaredType = declaredTypes.get(declared);
|
|
274
|
+
const value = encodeDrillValue(rawValue, declaredType);
|
|
275
|
+
if (value === undefined) {
|
|
276
|
+
// Say so, the way the notebook does. `canSelf` only checks that the
|
|
277
|
+
// NAME resolves, so a `given=` naming a type the clicked value
|
|
278
|
+
// cannot become still paints the whole column as clickable and then
|
|
279
|
+
// drops every click. That is an authoring mistake with no other
|
|
280
|
+
// symptom, and this is the likelier surface for it, because the
|
|
281
|
+
// givens are the dashboard's own.
|
|
282
|
+
console.warn(
|
|
283
|
+
`Drill declined: ${JSON.stringify(rawValue)} cannot be a value for given "${declared}"` +
|
|
284
|
+
(declaredType ? ` of type ${declaredType}` : ""),
|
|
285
|
+
);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
setGiven(declared, value);
|
|
289
|
+
},
|
|
290
|
+
[declaredTypes, resolveGiven, setGiven],
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
const { drill, drillMenu } = useDrill({
|
|
294
|
+
onNavigate,
|
|
295
|
+
onSelf,
|
|
296
|
+
canSelf,
|
|
297
|
+
selfLabel: "Filter this dashboard",
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// After every hook, so the hook order does not depend on the URI.
|
|
301
|
+
if (!uriNamesBoth) {
|
|
302
|
+
return (
|
|
303
|
+
<Alert severity="error">
|
|
304
|
+
A dashboard resource URI must name an environment and a package.
|
|
305
|
+
Received: {resourceUri}
|
|
306
|
+
</Alert>
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (isError) {
|
|
311
|
+
return (
|
|
312
|
+
<ApiErrorDisplay
|
|
313
|
+
context={`${environmentName} > ${packageName} > ${dashboard}`}
|
|
314
|
+
error={error}
|
|
315
|
+
/>
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
if (!isSuccess || !manifest) {
|
|
319
|
+
return <Loading text="Loading dashboard…" />;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// Reachable on the in-process load path only. Production loads a package
|
|
323
|
+
// through the worker pool, which aborts the package on the first compile
|
|
324
|
+
// error, so an uncompilable file answers 424 everywhere rather than serving a
|
|
325
|
+
// per-file error. Measured on this base with one bad file: the package
|
|
326
|
+
// endpoint, the dashboards listing, and the manifest of a dashboard that was
|
|
327
|
+
// FINE all answered 424. The earlier note here said such a dashboard "still
|
|
328
|
+
// lists and still resolves", which contradicted this repo's own docs and was
|
|
329
|
+
// the wrong half of the pair. Kept because the per-file error manifest still
|
|
330
|
+
// exists and an empty frame would be worse than saying why.
|
|
331
|
+
if (manifest.error) {
|
|
332
|
+
return (
|
|
333
|
+
<Stack spacing={2}>
|
|
334
|
+
<DashboardHeader manifest={manifest} />
|
|
335
|
+
<Alert severity="error">{manifest.error}</Alert>
|
|
336
|
+
</Stack>
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const modelPath = manifest.path;
|
|
341
|
+
const tiles = manifest.tiles ?? [];
|
|
342
|
+
const columns = manifest.dashboardColumns ?? DEFAULT_COLUMNS;
|
|
343
|
+
|
|
344
|
+
return (
|
|
345
|
+
<Stack spacing={2}>
|
|
346
|
+
<DashboardHeader manifest={manifest} />
|
|
347
|
+
|
|
348
|
+
<GivensPanel
|
|
349
|
+
givens={specs}
|
|
350
|
+
values={draft}
|
|
351
|
+
onChange={setGiven}
|
|
352
|
+
onReset={reset}
|
|
353
|
+
layout="bar"
|
|
354
|
+
options={options}
|
|
355
|
+
optionsLoading={optionsLoading}
|
|
356
|
+
optionsFailed={optionsFailed}
|
|
357
|
+
apply={
|
|
358
|
+
manifest.autorun === false
|
|
359
|
+
? { onApply: apply, pending }
|
|
360
|
+
: undefined
|
|
361
|
+
}
|
|
362
|
+
/>
|
|
363
|
+
|
|
364
|
+
{modelPath === undefined ? (
|
|
365
|
+
<Alert severity="error">
|
|
366
|
+
This dashboard has no model path, so there is nothing to run.
|
|
367
|
+
</Alert>
|
|
368
|
+
) : manifest.query !== undefined ? (
|
|
369
|
+
// Single-query form: one query whose result IS the dashboard. Its
|
|
370
|
+
// `# dashboard {columns=N}` tag is the renderer's business, so no
|
|
371
|
+
// grid is imposed here: doing so would nest a grid in a grid.
|
|
372
|
+
<DashboardTile
|
|
373
|
+
environmentName={environmentName}
|
|
374
|
+
packageName={packageName}
|
|
375
|
+
versionId={versionId}
|
|
376
|
+
modelPath={modelPath}
|
|
377
|
+
queryName={manifest.query}
|
|
378
|
+
givens={applied}
|
|
379
|
+
declaredTypes={declaredTypes}
|
|
380
|
+
height={height ?? WHOLE_PAGE_HEIGHT}
|
|
381
|
+
maxResultSize={maxResultSize}
|
|
382
|
+
drill={drill}
|
|
383
|
+
/>
|
|
384
|
+
) : tiles.length > 0 ? (
|
|
385
|
+
// Composite form: each tile runs on its own and the results are
|
|
386
|
+
// combined into one grid here, since no single Malloy result spans
|
|
387
|
+
// them.
|
|
388
|
+
<Box
|
|
389
|
+
sx={{
|
|
390
|
+
display: "grid",
|
|
391
|
+
gridTemplateColumns: {
|
|
392
|
+
xs: "1fr",
|
|
393
|
+
md: `repeat(${columns}, minmax(0, 1fr))`,
|
|
394
|
+
},
|
|
395
|
+
gap: 2,
|
|
396
|
+
}}
|
|
397
|
+
>
|
|
398
|
+
{tiles.map((tile, index) => (
|
|
399
|
+
<Box
|
|
400
|
+
// Position too, not the expression alone: `tiles=[…]` can
|
|
401
|
+
// repeat one, which is a typo rather than a request for two
|
|
402
|
+
// identical panels, and keying on the expression made the
|
|
403
|
+
// duplicate warn and reconcile onto its twin.
|
|
404
|
+
key={`${index}:${tile.query}`}
|
|
405
|
+
sx={{
|
|
406
|
+
display: "grid",
|
|
407
|
+
// Only above `md`: the narrow breakpoint is one column,
|
|
408
|
+
// where a span would overflow the grid rather than widen
|
|
409
|
+
// anything.
|
|
410
|
+
gridColumn: { md: tileGridColumn(tile, columns) },
|
|
411
|
+
}}
|
|
412
|
+
>
|
|
413
|
+
<DashboardTile
|
|
414
|
+
environmentName={environmentName}
|
|
415
|
+
packageName={packageName}
|
|
416
|
+
versionId={versionId}
|
|
417
|
+
modelPath={modelPath}
|
|
418
|
+
tile={tile.query}
|
|
419
|
+
label={tile.label}
|
|
420
|
+
subtitle={tile.subtitle}
|
|
421
|
+
borderless={tile.borderless}
|
|
422
|
+
givens={applied}
|
|
423
|
+
declaredTypes={declaredTypes}
|
|
424
|
+
givenNames={tile.givenNames}
|
|
425
|
+
height={height ?? TILE_HEIGHT}
|
|
426
|
+
maxResultSize={maxResultSize}
|
|
427
|
+
drill={drill}
|
|
428
|
+
/>
|
|
429
|
+
</Box>
|
|
430
|
+
))}
|
|
431
|
+
</Box>
|
|
432
|
+
) : (
|
|
433
|
+
<Alert severity="warning">
|
|
434
|
+
This dashboard names neither a query nor any tiles.
|
|
435
|
+
</Alert>
|
|
436
|
+
)}
|
|
437
|
+
|
|
438
|
+
{drillMenu}
|
|
439
|
+
</Stack>
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function DashboardHeader({ manifest }: { manifest: DashboardManifest }) {
|
|
444
|
+
return (
|
|
445
|
+
<Box>
|
|
446
|
+
<Typography variant="h5" sx={{ fontWeight: 600 }}>
|
|
447
|
+
{manifest.title ?? manifest.name}
|
|
448
|
+
</Typography>
|
|
449
|
+
{manifest.description && (
|
|
450
|
+
<Typography variant="body2" color="text.secondary">
|
|
451
|
+
{manifest.description}
|
|
452
|
+
</Typography>
|
|
453
|
+
)}
|
|
454
|
+
</Box>
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export default Dashboard;
|