@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,268 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { useQueries } from "@tanstack/react-query";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import type { Given } from "../client";
|
|
7
|
+
import { useServer } from "../components/ServerProvider";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* How many options a generated `suggest { source=… dimension=… }` asks for.
|
|
11
|
+
*
|
|
12
|
+
* Stated here rather than left to the server's `DEFAULT_QUERY_ROW_LIMIT`, which
|
|
13
|
+
* is also 1000 but caps silently and in whatever order the warehouse returns.
|
|
14
|
+
* An explicit limit with an explicit order makes a truncated list the same list
|
|
15
|
+
* every time, and makes the cap something a reader of this file can see.
|
|
16
|
+
* A dimension with more distinct values than this needs a hand-written
|
|
17
|
+
* `suggest { query=… }`: a picker over thousands of options is the wrong
|
|
18
|
+
* control anyway.
|
|
19
|
+
*/
|
|
20
|
+
export const SUGGEST_OPTION_LIMIT = 1000;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The name a `group_by` gives its output column, which is the last segment of a
|
|
24
|
+
* field path.
|
|
25
|
+
*
|
|
26
|
+
* `order_by` takes an output field name, not a path: `order_by:
|
|
27
|
+
* products.category` is refused outright ("order_by takes the name of a field in
|
|
28
|
+
* the query output, not a path"), while `group_by: products.category` names its
|
|
29
|
+
* column `category`. A joined dimension is the ordinary case for a `suggest`, so
|
|
30
|
+
* getting this wrong would have failed the option query for most of them.
|
|
31
|
+
*/
|
|
32
|
+
function outputFieldName(dimension: string): string {
|
|
33
|
+
const segments = dimension.split(".");
|
|
34
|
+
return segments[segments.length - 1];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The query a `suggest { source=… dimension=… }` runs.
|
|
39
|
+
*
|
|
40
|
+
* Exported so the spec can assert the text this hook actually sends. A test that
|
|
41
|
+
* rebuilds the same string alongside it proves only that the test agrees with
|
|
42
|
+
* itself, and this text has already been wrong once: `order_by` takes an output
|
|
43
|
+
* field name, not a path, so a joined dimension failed the query outright.
|
|
44
|
+
*/
|
|
45
|
+
export function buildSuggestQuery(source: string, dimension: string): string {
|
|
46
|
+
return (
|
|
47
|
+
`run: ${source} -> {\n` +
|
|
48
|
+
` group_by: ${dimension}\n` +
|
|
49
|
+
` order_by: ${outputFieldName(dimension)} asc\n` +
|
|
50
|
+
` limit: ${SUGGEST_OPTION_LIMIT}\n` +
|
|
51
|
+
`}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Resolve the option lists behind `select` / `multiselect` controls.
|
|
57
|
+
*
|
|
58
|
+
* A `suggest` is an ordinary query: either a named one (`suggest { query=… }`)
|
|
59
|
+
* or a grouping over a dimension (`suggest { source=… dimension=… }`), so this
|
|
60
|
+
* runs it on the same governed query endpoint everything else uses. No new
|
|
61
|
+
* endpoint, and the row caps and authorize gates that apply to a surface's own
|
|
62
|
+
* queries apply to its dropdowns too.
|
|
63
|
+
*
|
|
64
|
+
* Takes plain `Given`s: `suggest` is declared on the given, so a notebook's
|
|
65
|
+
* Parameters panel and a dashboard's control row fill the same dropdown from
|
|
66
|
+
* the same declaration.
|
|
67
|
+
*
|
|
68
|
+
* Requested with `compactJson` because these results are never rendered: the
|
|
69
|
+
* flat row form is what the widget needs, and asking for the full Malloy result
|
|
70
|
+
* would mean parsing rendering metadata to get at a list of strings.
|
|
71
|
+
*
|
|
72
|
+
* KNOWN GAP, latent until something populates `suggest`. The request carries no
|
|
73
|
+
* `givens`, and `QueryRequest` has a field for them. That is fine for row caps
|
|
74
|
+
* but not for `#(authorize)`: a gate is evaluated against the request's givens,
|
|
75
|
+
* so a `suggest` over a gated source is denied and every dropdown on it resolves
|
|
76
|
+
* to "Options unavailable": the failure surfaces honestly, but the control is
|
|
77
|
+
* unusable. Deliberately not guessed at here, because *which* givens a suggest
|
|
78
|
+
* should carry is a real decision: the applied ones make the option list depend
|
|
79
|
+
* on the current filters, which this hook's caching deliberately avoids, while
|
|
80
|
+
* only the gate-relevant ones means knowing which those are. Whoever populates
|
|
81
|
+
* `suggest` server-side should settle it, and this hook's signature will need
|
|
82
|
+
* the values passed in.
|
|
83
|
+
*/
|
|
84
|
+
export function useSuggestOptions(
|
|
85
|
+
environmentName: string,
|
|
86
|
+
packageName: string,
|
|
87
|
+
modelPath: string | undefined,
|
|
88
|
+
specs: Given[],
|
|
89
|
+
// Trailing and optional because this hook is exported from the package, so
|
|
90
|
+
// a slot beside `packageName` where it belongs would break every caller.
|
|
91
|
+
versionId?: string,
|
|
92
|
+
): {
|
|
93
|
+
options: Map<string, string[]>;
|
|
94
|
+
isLoading: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Givens whose suggest query failed.
|
|
97
|
+
*
|
|
98
|
+
* Reported separately from an empty option list because the two look
|
|
99
|
+
* identical in a dropdown and mean opposite things: "this dimension has no
|
|
100
|
+
* values" is data, "the query did not run" is a fault, and a reader offered
|
|
101
|
+
* an empty picker has no way to tell which they are looking at.
|
|
102
|
+
*/
|
|
103
|
+
failed: Set<string>;
|
|
104
|
+
} {
|
|
105
|
+
const { apiClients } = useServer();
|
|
106
|
+
|
|
107
|
+
// Only a picker needs options; a text box or a slider would just be issuing
|
|
108
|
+
// a query whose answer it never shows.
|
|
109
|
+
const suggestable = useMemo(
|
|
110
|
+
() =>
|
|
111
|
+
specs.filter(
|
|
112
|
+
(spec) =>
|
|
113
|
+
spec.name !== undefined &&
|
|
114
|
+
(spec.control === "select" || spec.control === "multiselect") &&
|
|
115
|
+
(spec.suggest?.query !== undefined ||
|
|
116
|
+
(spec.suggest?.source !== undefined &&
|
|
117
|
+
spec.suggest?.dimension !== undefined)),
|
|
118
|
+
),
|
|
119
|
+
[specs],
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const results = useQueries({
|
|
123
|
+
queries: suggestable.map((spec) => ({
|
|
124
|
+
queryKey: [
|
|
125
|
+
"givenSuggest",
|
|
126
|
+
environmentName,
|
|
127
|
+
packageName,
|
|
128
|
+
versionId,
|
|
129
|
+
modelPath,
|
|
130
|
+
spec.name,
|
|
131
|
+
spec.suggest?.query,
|
|
132
|
+
spec.suggest?.source,
|
|
133
|
+
spec.suggest?.dimension,
|
|
134
|
+
],
|
|
135
|
+
enabled: modelPath !== undefined,
|
|
136
|
+
// Option lists change with the data, not with the filters, so they are
|
|
137
|
+
// cached well past a single control interaction.
|
|
138
|
+
staleTime: 5 * 60 * 1000,
|
|
139
|
+
refetchOnWindowFocus: false,
|
|
140
|
+
queryFn: async () => {
|
|
141
|
+
const suggest = spec.suggest ?? {};
|
|
142
|
+
const response = await apiClients.models.executeQueryModel(
|
|
143
|
+
environmentName,
|
|
144
|
+
packageName,
|
|
145
|
+
modelPath as string,
|
|
146
|
+
suggest.query !== undefined
|
|
147
|
+
? { queryName: suggest.query, compactJson: true, versionId }
|
|
148
|
+
: {
|
|
149
|
+
query: buildSuggestQuery(
|
|
150
|
+
suggest.source as string,
|
|
151
|
+
suggest.dimension as string,
|
|
152
|
+
),
|
|
153
|
+
compactJson: true,
|
|
154
|
+
versionId,
|
|
155
|
+
},
|
|
156
|
+
);
|
|
157
|
+
return readOptionValues(
|
|
158
|
+
response.data.result,
|
|
159
|
+
suggest.dimension === undefined
|
|
160
|
+
? undefined
|
|
161
|
+
: outputFieldName(suggest.dimension),
|
|
162
|
+
);
|
|
163
|
+
},
|
|
164
|
+
})),
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const options = useMemo(() => {
|
|
168
|
+
const byName = new Map<string, string[]>();
|
|
169
|
+
suggestable.forEach((spec, index) => {
|
|
170
|
+
const value = results[index]?.data;
|
|
171
|
+
if (spec.name && value) byName.set(spec.name, value);
|
|
172
|
+
});
|
|
173
|
+
return byName;
|
|
174
|
+
// `results` is a fresh array each render; its data identity is what
|
|
175
|
+
// matters, so depend on that rather than the wrapper objects.
|
|
176
|
+
//
|
|
177
|
+
// `JSON.stringify`, not `join("|")`. `join` flattens a nested array with
|
|
178
|
+
// commas and renders undefined as empty, so genuinely different option
|
|
179
|
+
// lists produced the SAME key: `[["a","b"]]` and `[["a,b"]]` both give
|
|
180
|
+
// `a,b`, and `[undefined]`, `[[]]` and `[[""]]` all give `""`. A refetch
|
|
181
|
+
// between two colliding lists left the previous dropdown in place.
|
|
182
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
183
|
+
}, [suggestable, JSON.stringify(results.map((result) => result.data))]);
|
|
184
|
+
|
|
185
|
+
const failed = useMemo(() => {
|
|
186
|
+
const names = new Set<string>();
|
|
187
|
+
suggestable.forEach((spec, index) => {
|
|
188
|
+
if (spec.name && results[index]?.isError) names.add(spec.name);
|
|
189
|
+
});
|
|
190
|
+
return names;
|
|
191
|
+
// Same reasoning as `options`: `results` is a fresh array each render.
|
|
192
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
193
|
+
}, [suggestable, results.map((result) => result.isError).join("|")]);
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
options,
|
|
197
|
+
isLoading: results.some((result) => result.isLoading),
|
|
198
|
+
failed,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Pull the option strings out of a compact-JSON result.
|
|
204
|
+
*
|
|
205
|
+
* Prefers the named column and otherwise takes the first, which covers a
|
|
206
|
+
* `suggest { query=… }` whose column is named something else. Nulls are
|
|
207
|
+
* dropped: "no value" is expressed by clearing the control, not by picking an
|
|
208
|
+
* empty option.
|
|
209
|
+
*
|
|
210
|
+
* The name to pass is the OUTPUT column, so a joined `products.category` is
|
|
211
|
+
* looked up as `category`. Passing the path found nothing and fell through to
|
|
212
|
+
* the first column, which happened to be right only because the generated query
|
|
213
|
+
* selects exactly one.
|
|
214
|
+
*/
|
|
215
|
+
export function readOptionValues(
|
|
216
|
+
result: string | undefined,
|
|
217
|
+
dimension: string | undefined,
|
|
218
|
+
): string[] {
|
|
219
|
+
// Absent is tolerated: `result` is optional in the API contract, so a
|
|
220
|
+
// missing one is a shape the server is allowed to send and "no values" is
|
|
221
|
+
// the honest reading of it.
|
|
222
|
+
if (!result) return [];
|
|
223
|
+
|
|
224
|
+
// Corrupt is NOT tolerated, and the difference matters. This hook exists to
|
|
225
|
+
// separate "this dimension has no values" from "the option query failed",
|
|
226
|
+
// and returning `[]` for a response that could not be read collapsed the
|
|
227
|
+
// second into the first: the control rendered "No matching values" and told
|
|
228
|
+
// the reader a populated dimension was empty. Thrown, so react-query marks
|
|
229
|
+
// the query errored and `failed` reports it, which is what puts "Options
|
|
230
|
+
// unavailable" on the control.
|
|
231
|
+
let rows: unknown;
|
|
232
|
+
try {
|
|
233
|
+
rows = JSON.parse(result);
|
|
234
|
+
} catch {
|
|
235
|
+
throw new Error("Suggest query returned a result that is not JSON.");
|
|
236
|
+
}
|
|
237
|
+
if (!Array.isArray(rows)) {
|
|
238
|
+
throw new Error(
|
|
239
|
+
"Suggest query returned JSON that is not a list of rows.",
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const values: string[] = [];
|
|
244
|
+
const seen = new Set<string>();
|
|
245
|
+
for (const row of rows) {
|
|
246
|
+
if (row === null || typeof row !== "object") continue;
|
|
247
|
+
const record = row as Record<string, unknown>;
|
|
248
|
+
const keys = Object.keys(record);
|
|
249
|
+
// `hasOwnProperty`, not `in`: `record` comes from `JSON.parse`, so `in`
|
|
250
|
+
// walks its prototype and reports `constructor`, `toString` and friends
|
|
251
|
+
// as present. A dimension with one of those names would select a
|
|
252
|
+
// function off the prototype instead of falling back to the first
|
|
253
|
+
// column. The same hazard was fixed in the app's URL merge; this is the
|
|
254
|
+
// other place the rule lives.
|
|
255
|
+
const key =
|
|
256
|
+
dimension !== undefined &&
|
|
257
|
+
Object.prototype.hasOwnProperty.call(record, dimension)
|
|
258
|
+
? dimension
|
|
259
|
+
: keys[0];
|
|
260
|
+
const value = key === undefined ? undefined : record[key];
|
|
261
|
+
if (value === null || value === undefined) continue;
|
|
262
|
+
const text = String(value);
|
|
263
|
+
if (seen.has(text)) continue;
|
|
264
|
+
seen.add(text);
|
|
265
|
+
values.push(text);
|
|
266
|
+
}
|
|
267
|
+
return values;
|
|
268
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
1
4
|
export * from "./components";
|
|
2
|
-
export { default as ConnectionExplorer } from "./components/
|
|
5
|
+
export { default as ConnectionExplorer } from "./components/Environment/ConnectionExplorer";
|
|
3
6
|
export { useServer } from "./components/ServerProvider";
|
|
4
7
|
export * from "./hooks";
|
|
5
8
|
export { useRawQueryData } from "./hooks/useRawQueryData";
|
|
9
|
+
export * from "./theme";
|
|
6
10
|
export * from "./utils/formatting";
|
|
11
|
+
// How a package's own files are addressed. Exported because a host that renders
|
|
12
|
+
// its own "this path is not a model" state has to point at the URL that does
|
|
13
|
+
// serve the file, and this is the one place that string is built.
|
|
14
|
+
export { packageFileUrl } from "./utils/dataAppEmbed";
|
|
15
|
+
export * from "./constants/docLinks";
|
package/src/react-app-env.d.ts
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import React, {
|
|
5
|
+
createContext,
|
|
6
|
+
useContext,
|
|
7
|
+
useMemo,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { resolveTheme } from "./resolveTheme";
|
|
11
|
+
import type { ResolvedTheme, Theme, ThemeMode } from "./types";
|
|
12
|
+
|
|
13
|
+
interface ThemeContextValue {
|
|
14
|
+
/** Theme resolved from {@link layers} + {@link mode}. Used by the app shell. */
|
|
15
|
+
theme: ResolvedTheme;
|
|
16
|
+
/**
|
|
17
|
+
* Raw base layers in cascade order. Today this holds only the
|
|
18
|
+
* instance-level theme from `/status`; the built-in defaults live inside
|
|
19
|
+
* {@link resolveTheme}, not in this array. Exposed so per-chart renderers
|
|
20
|
+
* can append a per-chart override and re-run {@link resolveTheme} without
|
|
21
|
+
* losing that instance baseline. The merge accepts any number of
|
|
22
|
+
* lower-precedence layers, so a per-environment layer can be fed in here
|
|
23
|
+
* later (once the server wires it through) without changing the merge.
|
|
24
|
+
*/
|
|
25
|
+
layers: Array<Theme | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* The effective mode applied to charts and chrome (always "light" or "dark").
|
|
28
|
+
* "auto" is resolved before reaching here.
|
|
29
|
+
*/
|
|
30
|
+
mode: ThemeMode;
|
|
31
|
+
/**
|
|
32
|
+
* The viewer's stored preference: "light" | "dark" | "auto", or undefined
|
|
33
|
+
* when no choice has been persisted. Use this (not {@link mode}) when
|
|
34
|
+
* rendering a multi-state toggle that needs to expose "auto" as a position.
|
|
35
|
+
*/
|
|
36
|
+
userChoice: ThemeMode | "auto" | undefined;
|
|
37
|
+
setMode: (mode: ThemeMode | "auto") => void;
|
|
38
|
+
allowUserToggle: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const ThemeContext = createContext<ThemeContextValue | undefined>(undefined);
|
|
42
|
+
|
|
43
|
+
interface ThemeProviderProps {
|
|
44
|
+
layers: Array<Theme | undefined>;
|
|
45
|
+
mode: ThemeMode;
|
|
46
|
+
userChoice: ThemeMode | "auto" | undefined;
|
|
47
|
+
setMode: (mode: ThemeMode | "auto") => void;
|
|
48
|
+
allowUserToggle?: boolean;
|
|
49
|
+
children: ReactNode;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function ThemeProvider({
|
|
53
|
+
layers,
|
|
54
|
+
mode,
|
|
55
|
+
userChoice,
|
|
56
|
+
setMode,
|
|
57
|
+
allowUserToggle = true,
|
|
58
|
+
children,
|
|
59
|
+
}: ThemeProviderProps) {
|
|
60
|
+
const theme = useMemo(() => resolveTheme(layers, mode), [layers, mode]);
|
|
61
|
+
const value = useMemo<ThemeContextValue>(
|
|
62
|
+
() => ({ theme, layers, mode, userChoice, setMode, allowUserToggle }),
|
|
63
|
+
[theme, layers, mode, userChoice, setMode, allowUserToggle],
|
|
64
|
+
);
|
|
65
|
+
return (
|
|
66
|
+
<ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Resolved publisher theme. Returns a sensible default outside a provider
|
|
72
|
+
* so SDK consumers (third-party embedders, isolated stories) still get
|
|
73
|
+
* styled output without having to mount the provider.
|
|
74
|
+
*/
|
|
75
|
+
export function usePublisherTheme(): ThemeContextValue {
|
|
76
|
+
const ctx = useContext(ThemeContext);
|
|
77
|
+
if (ctx) return ctx;
|
|
78
|
+
return {
|
|
79
|
+
theme: resolveTheme([], "light"),
|
|
80
|
+
layers: [],
|
|
81
|
+
mode: "light",
|
|
82
|
+
userChoice: undefined,
|
|
83
|
+
setMode: () => {},
|
|
84
|
+
allowUserToggle: false,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { MalloyExplicitTheme } from "@malloydata/render";
|
|
5
|
+
import type { ResolvedTheme } from "./types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Map our {@link ResolvedTheme} onto the explicit `theme` option that
|
|
9
|
+
* `@malloydata/render` accepts. Values flow into the renderer's inline
|
|
10
|
+
* `--malloy-render--*` style ahead of any `# theme.*` annotations the
|
|
11
|
+
* Malloy result carries, so operator choices made in the Theme Editor
|
|
12
|
+
* reach table chrome and dashboard tiles directly instead of going
|
|
13
|
+
* through the outer-wrapper var cascade.
|
|
14
|
+
*
|
|
15
|
+
* Two non-operator-customizable fields:
|
|
16
|
+
*
|
|
17
|
+
* - `background` paints the renderer's HTML chrome (the area between
|
|
18
|
+
* dashboard tiles). Sourced from `theme.dashboardRoot` — mode-keyed,
|
|
19
|
+
* stays decoupled from `palette.background` so a bold accent on the
|
|
20
|
+
* chart canvas doesn't bleed across the panel.
|
|
21
|
+
* - `tableBackground` paints the table interior. Sourced from
|
|
22
|
+
* `theme.tableBackground` — currently tracks `palette.background`
|
|
23
|
+
* so charts and tables share a single viz surface colour.
|
|
24
|
+
*
|
|
25
|
+
* Operator-customizable mappings:
|
|
26
|
+
*
|
|
27
|
+
* - `tablePinnedBackground` = `theme.tableHeaderBackground` (a NEW
|
|
28
|
+
* schema field). Despite the renderer's name, this paints the
|
|
29
|
+
* table header row (`.malloy-table .pinned-header.th` in
|
|
30
|
+
* scroll-pinned tables; for non-pinned tables our CSS override
|
|
31
|
+
* forces the same value onto `.th.column-cell`). Distinct from
|
|
32
|
+
* `tile` (below).
|
|
33
|
+
* - `tile` does NOT flow to `tablePinnedBackground` anymore — the
|
|
34
|
+
* dashboard tile container picks it up via our outer-wrapper
|
|
35
|
+
* `--malloy-render--tile-background` var and the CSS override on
|
|
36
|
+
* `.dashboard-item`. See `buildTableCssVars`.
|
|
37
|
+
*/
|
|
38
|
+
export function buildMalloyExplicitTheme(
|
|
39
|
+
theme: ResolvedTheme,
|
|
40
|
+
): MalloyExplicitTheme {
|
|
41
|
+
return {
|
|
42
|
+
background: theme.dashboardRoot,
|
|
43
|
+
tableBackground: theme.tableBackground,
|
|
44
|
+
tableHeaderColor: theme.tableHeader,
|
|
45
|
+
tableBodyColor: theme.tableBody,
|
|
46
|
+
tableBorder: theme.border,
|
|
47
|
+
// Header row background (operator-customizable, NEW). The
|
|
48
|
+
// renderer reuses tablePinnedBackground for any pinned header
|
|
49
|
+
// cell; we additionally paint the regular header row from the
|
|
50
|
+
// same var via injectRendererOverrides so non-pinned tables
|
|
51
|
+
// also show the header band.
|
|
52
|
+
tablePinnedBackground: theme.tableHeaderBackground,
|
|
53
|
+
tablePinnedBorder: theme.pinnedBorder,
|
|
54
|
+
tableFontSize: `${theme.font.size}px`,
|
|
55
|
+
fontFamily: theme.font.family,
|
|
56
|
+
// Saturated end of the choropleth gradient. The renderer
|
|
57
|
+
// generates a low-to-high ramp from a neutral grey to this
|
|
58
|
+
// colour for shape-map / segment-map plugins via getColorScale.
|
|
59
|
+
mapColor: theme.mapColor,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { buildTableCssVars } from "./buildTableCssVars";
|
|
6
|
+
import { resolveTheme } from "./resolveTheme";
|
|
7
|
+
|
|
8
|
+
describe("buildTableCssVars", () => {
|
|
9
|
+
it("emits only --malloy-render--* and --publisher-* namespaces (no shadow --malloy-theme--*)", () => {
|
|
10
|
+
const vars = buildTableCssVars(resolveTheme([], "light"));
|
|
11
|
+
for (const key of Object.keys(vars)) {
|
|
12
|
+
const allowed =
|
|
13
|
+
key.startsWith("--malloy-render--") ||
|
|
14
|
+
key.startsWith("--publisher-");
|
|
15
|
+
expect(allowed).toBe(true);
|
|
16
|
+
expect(key.startsWith("--malloy-theme--")).toBe(false);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("includes header, body, border, tile, label, value", () => {
|
|
21
|
+
const t = resolveTheme([], "light");
|
|
22
|
+
const vars = buildTableCssVars(t);
|
|
23
|
+
expect(vars["--malloy-render--table-header-color"]).toBe(t.tableHeader);
|
|
24
|
+
expect(vars["--malloy-render--table-body-color"]).toBe(t.tableBody);
|
|
25
|
+
expect(vars["--malloy-render--table-border"]).toBe(t.border);
|
|
26
|
+
// `tile-background` is our custom var for the dashboard tile
|
|
27
|
+
// container. It's NOT the renderer's `table-pinned-background`
|
|
28
|
+
// (which now carries `tableHeaderBackground` via the theme prop).
|
|
29
|
+
expect(vars["--malloy-render--tile-background"]).toBe(t.tile);
|
|
30
|
+
expect(vars["--malloy-render--label-color"]).toBe(t.tileTitle);
|
|
31
|
+
expect(vars["--malloy-render--value-color"]).toBe(t.valueColor);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("omits the dashboard-root background keys", () => {
|
|
35
|
+
// background and table-background are deliberately not surfaced
|
|
36
|
+
// here; the renderer paints the dashboard chrome with its own
|
|
37
|
+
// neutral default and the operator's accent lands on viz
|
|
38
|
+
// surfaces (charts via Vega, tables via the renderer prop).
|
|
39
|
+
const vars = buildTableCssVars(resolveTheme([], "light"));
|
|
40
|
+
expect(vars["--malloy-render--background"]).toBeUndefined();
|
|
41
|
+
expect(vars["--malloy-render--table-background"]).toBeUndefined();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("flips body color and tile background in dark mode", () => {
|
|
45
|
+
const dark = resolveTheme([], "dark");
|
|
46
|
+
const vars = buildTableCssVars(dark);
|
|
47
|
+
expect(vars["--malloy-render--table-body-color"]).toBe("#e2e8f0");
|
|
48
|
+
expect(vars["--malloy-render--tile-background"]).toBe("#0f172a");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("honors a custom font size from the theme", () => {
|
|
52
|
+
const t = resolveTheme([{ font: { size: 14 } }], "light");
|
|
53
|
+
expect(buildTableCssVars(t)["--malloy-render--table-font-size"]).toBe(
|
|
54
|
+
"14px",
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// The card geometry does NOT come from the instance theme: the radius is the
|
|
59
|
+
// host app's MUI `shape.borderRadius`, passed in, so a dashboard card reads as
|
|
60
|
+
// a card of the app it is embedded in. The default is the renderer's own, so a
|
|
61
|
+
// caller that passes nothing gets today's look.
|
|
62
|
+
it("carries the caller's card geometry into the publisher namespace", () => {
|
|
63
|
+
const vars = buildTableCssVars(resolveTheme([], "light"), {
|
|
64
|
+
radius: "4px",
|
|
65
|
+
padding: "20px",
|
|
66
|
+
});
|
|
67
|
+
expect(vars["--publisher-dashboard-card-radius"]).toBe("4px");
|
|
68
|
+
expect(vars["--publisher-dashboard-card-padding"]).toBe("20px");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("defaults the card geometry to the renderer's own", () => {
|
|
72
|
+
const vars = buildTableCssVars(resolveTheme([], "light"));
|
|
73
|
+
expect(vars["--publisher-dashboard-card-radius"]).toBe("8px");
|
|
74
|
+
expect(vars["--publisher-dashboard-card-padding"]).toBe("20px");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("emits the font-family token consumed by the renderer", () => {
|
|
78
|
+
const t = resolveTheme(
|
|
79
|
+
[{ font: { family: "Roboto, sans-serif" } }],
|
|
80
|
+
"light",
|
|
81
|
+
);
|
|
82
|
+
expect(buildTableCssVars(t)["--malloy-render--font-family"]).toBe(
|
|
83
|
+
"Roboto, sans-serif",
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { ResolvedTheme } from "./types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Padding inside a dashboard card, around the result. The renderer's own
|
|
8
|
+
* default, shared with the composite tile so the two cards cannot drift.
|
|
9
|
+
*/
|
|
10
|
+
export const DASHBOARD_CARD_PADDING_PX = 20;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Geometry the two dashboard cards agree on. Not part of {@link ResolvedTheme}
|
|
14
|
+
* because the radius comes from the HOST's MUI `shape.borderRadius` rather than
|
|
15
|
+
* from the instance theme: a dashboard card should read as a card of the app it
|
|
16
|
+
* is embedded in, and pinning it to a constant is what made the renderer's 8px
|
|
17
|
+
* the only 8px card on a 4px page.
|
|
18
|
+
*/
|
|
19
|
+
export interface DashboardCardGeometry {
|
|
20
|
+
radius: string;
|
|
21
|
+
padding: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const DEFAULT_CARD_GEOMETRY: DashboardCardGeometry = {
|
|
25
|
+
radius: "8px",
|
|
26
|
+
padding: `${DASHBOARD_CARD_PADDING_PX}px`,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Build the CSS variable map applied to the wrapper element around
|
|
31
|
+
* `<malloy-render>`. The values here power two things only:
|
|
32
|
+
*
|
|
33
|
+
* 1. The dashboard tile chrome rules in
|
|
34
|
+
* {@link PUBLISHER_RENDERER_OVERRIDES_CSS} (`.dashboard-item`,
|
|
35
|
+
* `.dashboard-item-title`, `.dashboard-item-value`, ...). The
|
|
36
|
+
* renderer doesn't expose those surfaces through its `theme` prop,
|
|
37
|
+
* so we paint them ourselves via the var cascade.
|
|
38
|
+
*
|
|
39
|
+
* 2. Renderer-internal rules that read the same `--malloy-render--*`
|
|
40
|
+
* names. The renderer's own `theme` prop write (see
|
|
41
|
+
* `buildMalloyExplicitTheme`) usually sets these inline on a deeper
|
|
42
|
+
* element first, but we set them on the outer wrapper so the var
|
|
43
|
+
* has a value even when the prop is partial.
|
|
44
|
+
*
|
|
45
|
+
* Single namespace by design: the `--malloy-theme--*` shadow set we
|
|
46
|
+
* used to emit was a workaround for the renderer's
|
|
47
|
+
* `var(--malloy-theme--<key>)` fallback lookup, which only fires when
|
|
48
|
+
* no explicit `theme` prop is given. With the prop wired we no longer
|
|
49
|
+
* compete with that lookup, so the shadow namespace just bloated
|
|
50
|
+
* every wrapper element's inline style.
|
|
51
|
+
*/
|
|
52
|
+
export function buildTableCssVars(
|
|
53
|
+
theme: ResolvedTheme,
|
|
54
|
+
card: DashboardCardGeometry = DEFAULT_CARD_GEOMETRY,
|
|
55
|
+
): Record<string, string> {
|
|
56
|
+
return {
|
|
57
|
+
"--malloy-render--font-family": theme.font.family,
|
|
58
|
+
"--malloy-render--table-font-size": `${theme.font.size}px`,
|
|
59
|
+
"--malloy-render--table-header-color": theme.tableHeader,
|
|
60
|
+
"--malloy-render--table-body-color": theme.tableBody,
|
|
61
|
+
"--malloy-render--table-border": theme.border,
|
|
62
|
+
"--malloy-render--table-pinned-border": theme.pinnedBorder,
|
|
63
|
+
// Custom var (not used by the renderer's own CSS). Drives the
|
|
64
|
+
// dashboard tile container background via our
|
|
65
|
+
// injectRendererOverrides rule on `.dashboard-item`. Kept
|
|
66
|
+
// separate from `--malloy-render--table-pinned-background`
|
|
67
|
+
// (which is the renderer's own var for the table header band)
|
|
68
|
+
// so the operator can theme the tile padding and the table
|
|
69
|
+
// header row independently.
|
|
70
|
+
"--malloy-render--tile-background": theme.tile,
|
|
71
|
+
// Custom var for the dashboard PANEL (area between tiles).
|
|
72
|
+
// Set on the outer Publisher wrapper rather than relying on the
|
|
73
|
+
// renderer's own `--malloy-render--background` because that var
|
|
74
|
+
// gets shadowed by an inline write deeper in the renderer's DOM
|
|
75
|
+
// when annotations are present — and our intent here is to keep
|
|
76
|
+
// the panel neutral regardless of any annotation. The
|
|
77
|
+
// injectRendererOverrides CSS reads this var on .malloy-dashboard
|
|
78
|
+
// and its row-header / row-body children.
|
|
79
|
+
"--publisher-dashboard-root": theme.dashboardRoot,
|
|
80
|
+
// Drives the dashboard tile title (e.g. "by_month" above a chart)
|
|
81
|
+
// and the dimension-name text via injectRendererOverrides.
|
|
82
|
+
"--malloy-render--label-color": theme.tileTitle,
|
|
83
|
+
// The numeric value rendered under each tile title. Not editable
|
|
84
|
+
// in v1; computed from the active mode for readable contrast.
|
|
85
|
+
"--malloy-render--value-color": theme.valueColor,
|
|
86
|
+
// Custom var. Drives the hover colour of a `# drill` cell via the
|
|
87
|
+
// .publisher-drill rule in injectRendererOverrides: the renderer
|
|
88
|
+
// has no notion of drill, so the affordance is entirely ours.
|
|
89
|
+
"--publisher-drill-link": theme.drillLink,
|
|
90
|
+
// Card geometry, in the publisher namespace because the renderer's own
|
|
91
|
+
// `--malloy-theme--dashboard-*` are declared ON `.malloy-render` and so
|
|
92
|
+
// beat anything inherited from this wrapper. injectRendererOverrides
|
|
93
|
+
// redeclares them there at raised specificity reading these, which is why
|
|
94
|
+
// that route needs no !important.
|
|
95
|
+
"--publisher-dashboard-card-radius": card.radius,
|
|
96
|
+
"--publisher-dashboard-card-padding": card.padding,
|
|
97
|
+
};
|
|
98
|
+
}
|