@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,375 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolving a renderer click into a `# drill` intent.
|
|
6
|
+
*
|
|
7
|
+
* `# drill { to=[…] given=… }` is written on a source *dimension*, and Malloy
|
|
8
|
+
* carries a dimension's annotations through to the query result's output field.
|
|
9
|
+
* So everything a click needs is already on the clicked field, and drill needs
|
|
10
|
+
* no endpoint of its own: the same resolution works for a dashboard tile and a
|
|
11
|
+
* notebook cell, which is the "one drill implementation" the design asks for.
|
|
12
|
+
*
|
|
13
|
+
* That propagation is the premise the whole design rests on, and NOTHING IN THIS
|
|
14
|
+
* PR pins it: the specs here drive a hand-built tag stub, deliberately, because
|
|
15
|
+
* what they test is the grammar. It is pinned against the real compiler by
|
|
16
|
+
* `packages/server/src/service/drill_probe.spec.ts`, which arrives with the
|
|
17
|
+
* dashboard slice of this split rather than here. If a Malloy upgrade stopped
|
|
18
|
+
* propagating dimension annotations, drill would go quiet everywhere at once and
|
|
19
|
+
* this slice's tests would all still pass.
|
|
20
|
+
*
|
|
21
|
+
* This module answers only *what* was asked for, which dashboards, seeding
|
|
22
|
+
* which given to which value. Navigating is the host's job.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
encodeFilterList,
|
|
27
|
+
filterInnerType,
|
|
28
|
+
isFilterType,
|
|
29
|
+
} from "../given/filterValue";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The parsed-tag surface this module reads, structurally typed.
|
|
33
|
+
*
|
|
34
|
+
* The renderer hands over an already-parsed `Tag` from `@malloydata/malloy-tag`,
|
|
35
|
+
* so naming the shape rather than importing the class keeps that package a
|
|
36
|
+
* render-time detail: SDK consumers can bundle without it, the same allowance
|
|
37
|
+
* `RenderedResult` makes for its theme annotations.
|
|
38
|
+
*/
|
|
39
|
+
export interface DrillTagReader {
|
|
40
|
+
tag(...at: string[]): DrillTagReader | undefined;
|
|
41
|
+
text(...at: string[]): string | undefined;
|
|
42
|
+
textArray(...at: string[]): string[] | undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The clicked field, as much of it as drill reads. */
|
|
46
|
+
export interface DrillField {
|
|
47
|
+
name: string;
|
|
48
|
+
tag?: DrillTagReader;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the field was grouped rather than aggregated. Only dimensions
|
|
51
|
+
* drill: a measure's cell has no dimension value to seed a filter with even
|
|
52
|
+
* when the tag reaches it, so filtering by one would filter by something
|
|
53
|
+
* other than what was clicked. Optional because the renderer's click payload
|
|
54
|
+
* and its field metadata are the two callers and only one is guaranteed to
|
|
55
|
+
* carry the method; absent, the field is taken at its word.
|
|
56
|
+
*/
|
|
57
|
+
wasDimension?: () => boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A click from `@malloydata/render`'s `onClick`, narrowed to what drill needs.
|
|
62
|
+
* Mirrors its `MalloyClickEventPayload` without importing it, since the renderer
|
|
63
|
+
* is a lazily-imported dependency here.
|
|
64
|
+
*/
|
|
65
|
+
export interface DrillClickPayload {
|
|
66
|
+
field?: DrillField;
|
|
67
|
+
value?: unknown;
|
|
68
|
+
isHeader?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* The originating click, which the host needs for two things a resolved
|
|
71
|
+
* intent cannot express, where to anchor a menu of destinations, and whether
|
|
72
|
+
* a modifier was held (cmd/ctrl to open in a new tab).
|
|
73
|
+
*/
|
|
74
|
+
event?: MouseEvent;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The literal `to=self`: filter the current view instead of leaving it. */
|
|
78
|
+
export const DRILL_SELF = "self";
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The `to=` destinations a field's `# drill` declares, empty when it declares
|
|
82
|
+
* none or the field cannot drill.
|
|
83
|
+
*
|
|
84
|
+
* Read separately from {@link resolveDrill} because two callers need it: the
|
|
85
|
+
* click, which also needs the clicked value, and the *affordance*, which runs
|
|
86
|
+
* over the result's field metadata before any click to decide which columns read
|
|
87
|
+
* as clickable. Sharing this is what keeps the two honest: a cell that looks
|
|
88
|
+
* clickable is one whose click resolves, because both answers come from here.
|
|
89
|
+
*/
|
|
90
|
+
export function drillDestinations(field: DrillField | undefined): string[] {
|
|
91
|
+
if (!field) return [];
|
|
92
|
+
// `wasDimension` is only consulted when the field answers; see DrillField.
|
|
93
|
+
if (field.wasDimension && !field.wasDimension()) return [];
|
|
94
|
+
const drill = field.tag?.tag("drill");
|
|
95
|
+
if (!drill) return [];
|
|
96
|
+
// Malloyyo accepts a lone destination unbracketed (`to=overview`) as well as
|
|
97
|
+
// the list form. The server grows the same leniency in `readDrillTag`
|
|
98
|
+
// (`service/dashboard.ts`) with the dashboard slice of this split; it is not
|
|
99
|
+
// in the tree yet, so keep the two in step when it lands.
|
|
100
|
+
return (
|
|
101
|
+
drill.textArray("to") ?? [drill.text("to")].filter(isNonEmpty)
|
|
102
|
+
).filter(isNonEmpty);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A destination slug as a menu label: `category_detail` → `Category detail`.
|
|
107
|
+
*
|
|
108
|
+
* Ported from Malloyyo so the same drill reads the same way in both, rather than
|
|
109
|
+
* naming the file on one and a sentence on the other.
|
|
110
|
+
*/
|
|
111
|
+
export function humanizeSlug(slug: string): string {
|
|
112
|
+
const words = slug.replace(/[-_]+/g, " ").trim();
|
|
113
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The given a `# drill` on this field would set: `given=` when the tag names
|
|
118
|
+
* one, otherwise the dimension name exactly as the model spells it.
|
|
119
|
+
*
|
|
120
|
+
* Shared with the affordance for the same reason `drillDestinations` is: a cell
|
|
121
|
+
* reads as clickable exactly when clicking it would do something, and deciding
|
|
122
|
+
* "would it" needs the given's name before any click happens.
|
|
123
|
+
*/
|
|
124
|
+
export function drillGivenName(field: DrillField): string {
|
|
125
|
+
// The field name verbatim, NOT upper-cased. Given names are stored as the
|
|
126
|
+
// model spells them, so upper-casing meant a `to=self` on a lowercase-named
|
|
127
|
+
// dimension resolved to a given that does not exist and the click was
|
|
128
|
+
// dropped in silence. An upper-case convention is common enough that it hid
|
|
129
|
+
// this: `given: REGION` worked, `given: region` did not.
|
|
130
|
+
//
|
|
131
|
+
// How the name is then MATCHED is the caller's business, and Notebook folds
|
|
132
|
+
// case before looking it up, so a tag naming `region` still finds a declared
|
|
133
|
+
// `REGION`. That is a courtesy at the lookup, not a licence to re-spell the
|
|
134
|
+
// name here: the value has to be set under the name the model declares.
|
|
135
|
+
return field.tag?.tag("drill")?.text("given") ?? field.name;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Where a `# drill` click wants to go, for the host to route however it routes. */
|
|
139
|
+
export interface DrillNavigation {
|
|
140
|
+
/** The destination dashboard's slug. */
|
|
141
|
+
dashboard: string;
|
|
142
|
+
/**
|
|
143
|
+
* Control values to open it with: the clicked value seeded into the drill's
|
|
144
|
+
* given. Only the seeded given: the source view's other filters are not
|
|
145
|
+
* carried over, since the destination need not bind them.
|
|
146
|
+
*/
|
|
147
|
+
givens: Record<string, string>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** What a click asked for, once the tag on the clicked field is read. */
|
|
151
|
+
export interface DrillIntent {
|
|
152
|
+
/** Destinations in declared order: dashboard slugs and/or {@link DRILL_SELF}. */
|
|
153
|
+
to: string[];
|
|
154
|
+
/** The given to seed: the dimension name as spelled, unless `given=` says otherwise. */
|
|
155
|
+
given: string;
|
|
156
|
+
/**
|
|
157
|
+
* The clicked value as Malloy filter syntax, ready to send to a `filter<…>`
|
|
158
|
+
* given. This is the right encoding for a cross-dashboard drill, whose
|
|
159
|
+
* destination declares its own givens and is conventionally `filter<…>`.
|
|
160
|
+
*/
|
|
161
|
+
value: string;
|
|
162
|
+
/**
|
|
163
|
+
* The same value before any encoding.
|
|
164
|
+
*
|
|
165
|
+
* Carried because the filter encoding above is only correct for a
|
|
166
|
+
* `filter<…>` target, and a click cannot know what it is aiming at: the
|
|
167
|
+
* destination may be another dashboard entirely. A host that *does* know,
|
|
168
|
+
* `to=self`, where the target given is one of its own: re-encodes from this
|
|
169
|
+
* with {@link encodeDrillValue}. Without it, drilling into a plain `string`
|
|
170
|
+
* given seeded it with backslash-escaped filter syntax and matched nothing.
|
|
171
|
+
*/
|
|
172
|
+
rawValue: unknown;
|
|
173
|
+
/** The clicked value as it read on screen, for labelling the destination menu. */
|
|
174
|
+
label: string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The clicked cell's value as filter syntax, or undefined when it cannot be
|
|
179
|
+
* expressed as one.
|
|
180
|
+
*
|
|
181
|
+
* Encoded from the value's own type rather than the given's, which a click does
|
|
182
|
+
* not know (a notebook cell has no control row to consult). Refusing the cases
|
|
183
|
+
* it cannot encode is deliberate: a drill that filtered by something other than
|
|
184
|
+
* the cell the user clicked would be worse than one that does nothing.
|
|
185
|
+
*/
|
|
186
|
+
export function drillValueToFilter(value: unknown): string | undefined {
|
|
187
|
+
if (typeof value === "string") {
|
|
188
|
+
// Refused when it ENCODES to nothing, not when it IS the empty string.
|
|
189
|
+
// `encodeFilterList` drops any value with no non-whitespace character,
|
|
190
|
+
// and the empty filter matches every row, so a drill producing one would
|
|
191
|
+
// silently widen instead of narrowing. Testing the input against `""`
|
|
192
|
+
// duplicated the encoder's rule and then fell out of step with it the
|
|
193
|
+
// moment that rule grew to cover whitespace: clicking a blank-looking
|
|
194
|
+
// cell (a space, a tab, an NBSP, all ordinary in pasted data) handed back
|
|
195
|
+
// the whole dataset dressed up as a drilled view. Asking the encoder is
|
|
196
|
+
// the one form of this that cannot drift again.
|
|
197
|
+
const encoded = encodeFilterList([value]);
|
|
198
|
+
return encoded === "" ? undefined : encoded;
|
|
199
|
+
}
|
|
200
|
+
if (typeof value === "boolean") return String(value);
|
|
201
|
+
if (typeof value === "number") {
|
|
202
|
+
// A bare number reads as equality. NaN/Infinity have no filter spelling.
|
|
203
|
+
return Number.isFinite(value) ? String(value) : undefined;
|
|
204
|
+
}
|
|
205
|
+
if (value instanceof Date) {
|
|
206
|
+
// Malloy's date filter literal. Deliberately day-granularity: seeding a
|
|
207
|
+
// timestamp to the millisecond would filter to a single row nobody asked
|
|
208
|
+
// for, and for a `date` column the clicked cell was a truncated date in
|
|
209
|
+
// the first place.
|
|
210
|
+
//
|
|
211
|
+
// KNOWN LIMITATION for a TIMESTAMP column feeding a `filter<…>` given.
|
|
212
|
+
// This truncates on the UTC day, and the renderer prints a timestamp in
|
|
213
|
+
// the query timezone, so the two disagree whenever that zone crosses
|
|
214
|
+
// midnight away from UTC: an instant of `2024-03-06T04:00:00Z` shows as
|
|
215
|
+
// `2024-03-05 20:00` under US-Pacific and seeds `2024-03-06`, the day
|
|
216
|
+
// AFTER the one on screen. Plain `date`/`timestamp` givens route around
|
|
217
|
+
// this entirely (`encodeDrillValue` hands them the Date and lets
|
|
218
|
+
// `givensToRequest` spell it per type); only the filter-typed targets
|
|
219
|
+
// land here, because a filter's value must be text.
|
|
220
|
+
//
|
|
221
|
+
// Not fixed rather than fixed wrongly: the correct day is the one the
|
|
222
|
+
// CELL displayed, which needs the query timezone, and that is not on the
|
|
223
|
+
// click payload or anywhere else this function can see. Guessing the
|
|
224
|
+
// browser's zone would be a second wrong answer that happens to be right
|
|
225
|
+
// more often, which is harder to diagnose than a consistent one.
|
|
226
|
+
const iso = value.toISOString();
|
|
227
|
+
return iso.slice(0, iso.indexOf("T"));
|
|
228
|
+
}
|
|
229
|
+
// null included: "the rows with no value" is expressible in Malloy, but
|
|
230
|
+
// clicking an empty cell is far more likely a misclick than that request.
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** How the clicked value read on screen, for a menu label. */
|
|
235
|
+
function drillValueLabel(value: unknown): string {
|
|
236
|
+
if (value instanceof Date) return drillValueToFilter(value) ?? "";
|
|
237
|
+
return String(value);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Read the `# drill` intent off a renderer click, or undefined when the click
|
|
242
|
+
* was not on a drillable value.
|
|
243
|
+
*
|
|
244
|
+
* Silent on anything untagged, which is most clicks: this runs on every click
|
|
245
|
+
* the renderer reports, so "not a drill" is the ordinary answer, not a fault.
|
|
246
|
+
*/
|
|
247
|
+
export function resolveDrill(
|
|
248
|
+
payload: DrillClickPayload | undefined,
|
|
249
|
+
): DrillIntent | undefined {
|
|
250
|
+
// A column header names the field rather than carrying a value, so there is
|
|
251
|
+
// nothing to seed even though the tag is on the field the header belongs to.
|
|
252
|
+
if (!payload || payload.isHeader) return undefined;
|
|
253
|
+
|
|
254
|
+
const field = payload.field;
|
|
255
|
+
if (!field) return undefined;
|
|
256
|
+
|
|
257
|
+
const to = drillDestinations(field);
|
|
258
|
+
if (to.length === 0) return undefined;
|
|
259
|
+
|
|
260
|
+
const value = drillValueToFilter(payload.value);
|
|
261
|
+
if (value === undefined) return undefined;
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
to,
|
|
265
|
+
given: drillGivenName(field),
|
|
266
|
+
value,
|
|
267
|
+
rawValue: payload.value,
|
|
268
|
+
label: drillValueLabel(payload.value),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function isNonEmpty(value: string | undefined): value is string {
|
|
273
|
+
return typeof value === "string" && value !== "";
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* A clicked value encoded for a given whose declared type is known.
|
|
278
|
+
*
|
|
279
|
+
* `filter<…>` takes filter syntax, so the value is escaped into a one-value
|
|
280
|
+
* filter list. Every other type takes the value itself: a plain `string` given
|
|
281
|
+
* seeded with `Ben\ &\ Jerry` would match nothing, because the escaping is
|
|
282
|
+
* meaningful only to the filter parser.
|
|
283
|
+
*
|
|
284
|
+
* Undefined when the value has no spelling for that type, which the caller
|
|
285
|
+
* should treat the way it treats an unresolvable drill: do nothing.
|
|
286
|
+
*/
|
|
287
|
+
export function encodeDrillValue(
|
|
288
|
+
rawValue: unknown,
|
|
289
|
+
targetType: string | undefined,
|
|
290
|
+
): string | number | boolean | Date | undefined {
|
|
291
|
+
if (targetType !== undefined && !isFilterType(targetType)) {
|
|
292
|
+
// Returned in the given's OWN type, not stringified. `givensToRequest`
|
|
293
|
+
// converts only `Date`, so a string sent for a `number` or `boolean` given
|
|
294
|
+
// travels as a string and Malloy refuses the query.
|
|
295
|
+
if (targetType === "number") {
|
|
296
|
+
// Only a number, or a string that spells one. `Number()` accepts far
|
|
297
|
+
// more than that and every extra it accepts is a wrong filter rather
|
|
298
|
+
// than a refused one: a clicked Date became its epoch milliseconds
|
|
299
|
+
// (1709646300000 for 2024-03-05) and a null cell became 0, so the
|
|
300
|
+
// notebook re-ran filtered to a value nobody clicked and returned
|
|
301
|
+
// nothing, with no error to explain it.
|
|
302
|
+
if (typeof rawValue === "number") {
|
|
303
|
+
return Number.isFinite(rawValue) ? rawValue : undefined;
|
|
304
|
+
}
|
|
305
|
+
if (typeof rawValue !== "string" || rawValue.trim() === "") {
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|
|
308
|
+
const parsed = Number(rawValue);
|
|
309
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
310
|
+
}
|
|
311
|
+
if (
|
|
312
|
+
targetType === "date" ||
|
|
313
|
+
targetType === "timestamp" ||
|
|
314
|
+
targetType === "timestamptz"
|
|
315
|
+
) {
|
|
316
|
+
// The Date itself, so `givensToRequest` can spell it per type. Falling
|
|
317
|
+
// through to `drillValueToFilter` truncated it to `YYYY-MM-DD` first,
|
|
318
|
+
// which is the right spelling for a `date` given and drops the time of
|
|
319
|
+
// day for a `timestamp` one: the drill then filtered to midnight
|
|
320
|
+
// rather than to the instant in the cell.
|
|
321
|
+
return rawValue instanceof Date ? rawValue : undefined;
|
|
322
|
+
}
|
|
323
|
+
if (targetType === "boolean") {
|
|
324
|
+
if (typeof rawValue === "boolean") return rawValue;
|
|
325
|
+
if (rawValue === "true") return true;
|
|
326
|
+
if (rawValue === "false") return false;
|
|
327
|
+
return undefined;
|
|
328
|
+
}
|
|
329
|
+
// A blank cell is refused here too, for the same reason as in
|
|
330
|
+
// `drillValueToFilter`: on a plain given it is a real but almost certainly
|
|
331
|
+
// unintended value, and clicking a blank cell is far more likely a
|
|
332
|
+
// misclick. Whitespace counts as blank, which is what makes that reason
|
|
333
|
+
// and this test agree: refusing only `""` left a space, a tab or an NBSP
|
|
334
|
+
// drilling to a value that matches essentially nothing, so the reader got
|
|
335
|
+
// an empty notebook rather than the click being declined.
|
|
336
|
+
if (typeof rawValue === "string")
|
|
337
|
+
return rawValue.trim() === "" ? undefined : rawValue;
|
|
338
|
+
if (typeof rawValue === "number") {
|
|
339
|
+
return Number.isFinite(rawValue) ? String(rawValue) : undefined;
|
|
340
|
+
}
|
|
341
|
+
if (typeof rawValue === "boolean") return String(rawValue);
|
|
342
|
+
}
|
|
343
|
+
// A `filter<string>` target takes the STRING grammar, so a bare number is
|
|
344
|
+
// not safe there: `-5` parses as `{operator:"=", values:["5"], not:true}`,
|
|
345
|
+
// a NEGATION, so drilling a negative cell filtered to every row EXCEPT the
|
|
346
|
+
// one clicked, silently. `drillValueToFilter`'s number branch is right for a
|
|
347
|
+
// `filter<number>`, whose grammar reads `-5` as the value. The spec already
|
|
348
|
+
// knew the two grammars disagree here and pinned only the number one.
|
|
349
|
+
if (
|
|
350
|
+
filterInnerType(targetType) === "string" &&
|
|
351
|
+
typeof rawValue === "number"
|
|
352
|
+
) {
|
|
353
|
+
return Number.isFinite(rawValue)
|
|
354
|
+
? encodeFilterList([String(rawValue)])
|
|
355
|
+
: undefined;
|
|
356
|
+
}
|
|
357
|
+
// A `filter<number>` takes the NUMBER grammar, so a string belongs to it only
|
|
358
|
+
// if it spells a number. Falling through emitted STRING filter syntax for it:
|
|
359
|
+
// a click on a text cell seeded `filter<number>` with `West`, a boolean with
|
|
360
|
+
// `true`, and a Date with a `YYYY-MM-DD` day, each of which that grammar
|
|
361
|
+
// refuses, so the server failed EVERY cell and the reader got an error
|
|
362
|
+
// notebook rather than a declined click. The non-filter `number` branch above
|
|
363
|
+
// already refuses exactly these; this is the same rule for the filter arm,
|
|
364
|
+
// which is where the two copies had drifted.
|
|
365
|
+
if (filterInnerType(targetType) === "number") {
|
|
366
|
+
if (typeof rawValue === "number") {
|
|
367
|
+
return Number.isFinite(rawValue) ? String(rawValue) : undefined;
|
|
368
|
+
}
|
|
369
|
+
if (typeof rawValue !== "string" || rawValue.trim() === "") {
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
return Number.isFinite(Number(rawValue)) ? rawValue.trim() : undefined;
|
|
373
|
+
}
|
|
374
|
+
return drillValueToFilter(rawValue);
|
|
375
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { ListSubheader, Menu, MenuItem } from "@mui/material";
|
|
5
|
+
import { useCallback, useMemo, useState, type ReactNode } from "react";
|
|
6
|
+
import type { DrillField } from "./resolveDrill";
|
|
7
|
+
import {
|
|
8
|
+
DRILL_SELF,
|
|
9
|
+
drillDestinations,
|
|
10
|
+
drillGivenName,
|
|
11
|
+
humanizeSlug,
|
|
12
|
+
resolveDrill,
|
|
13
|
+
type DrillClickPayload,
|
|
14
|
+
type DrillIntent,
|
|
15
|
+
type DrillNavigation,
|
|
16
|
+
} from "./resolveDrill";
|
|
17
|
+
|
|
18
|
+
export interface UseDrillOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Open another dashboard, seeded with the clicked value. Omitted on a surface
|
|
21
|
+
* that cannot navigate, which makes those destinations inert rather than
|
|
22
|
+
* dead-ended.
|
|
23
|
+
*/
|
|
24
|
+
onNavigate?: (target: DrillNavigation, event?: MouseEvent) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Apply the clicked value to this surface's own control row (`to=self`).
|
|
27
|
+
* Omitted on a surface that has none, such as a notebook cell.
|
|
28
|
+
*/
|
|
29
|
+
onSelf?: (given: string, rawValue: unknown) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Whether a `to=self` drill onto this given can actually be honoured: for a
|
|
32
|
+
* notebook, whether it declares that given at all.
|
|
33
|
+
*
|
|
34
|
+
* Without it the affordance says yes to every self-drill and the click is
|
|
35
|
+
* refused afterwards with a console warning, which is the dead link this
|
|
36
|
+
* module exists to avoid. Absent means "any self-drill is fine", the right
|
|
37
|
+
* default for a surface that binds whatever it is handed.
|
|
38
|
+
*/
|
|
39
|
+
canSelf?: (given: string) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* What `to=self` is called in the menu. A notebook filtering itself is not
|
|
42
|
+
* "this dashboard", and the drill tag: written on a shared model dimension,
|
|
43
|
+
* cannot know which document the reader is in, so the surface names itself.
|
|
44
|
+
*/
|
|
45
|
+
selfLabel?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* What a surface hands to its result renderer to become drillable: the click
|
|
50
|
+
* handler, and the predicate that decides which cells say so.
|
|
51
|
+
*
|
|
52
|
+
* One object because the two must agree. Passing only the handler is what
|
|
53
|
+
* produced the original asymmetry: clicks worked, but nothing looked clickable.
|
|
54
|
+
*/
|
|
55
|
+
export interface DrillBinding {
|
|
56
|
+
/**
|
|
57
|
+
* Every cell click. Most carry no `# drill` and mean nothing, so this
|
|
58
|
+
* tolerates being called constantly.
|
|
59
|
+
*/
|
|
60
|
+
onClick: (payload: DrillClickPayload) => void;
|
|
61
|
+
/** Whether this field's cells should read as clickable. */
|
|
62
|
+
canDrill: (field: DrillField) => boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface UseDrillResult {
|
|
66
|
+
/** Hand to `ResultContainer`'s (or `RenderedResult`'s) `drill` prop. */
|
|
67
|
+
drill: DrillBinding;
|
|
68
|
+
/** Render anywhere in the subtree: the menu a multi-destination drill opens. */
|
|
69
|
+
drillMenu: ReactNode;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface DrillMenuState {
|
|
73
|
+
intent: DrillIntent;
|
|
74
|
+
destinations: string[];
|
|
75
|
+
event?: MouseEvent;
|
|
76
|
+
top: number;
|
|
77
|
+
left: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Click-to-drill for any surface that renders a Malloy result.
|
|
82
|
+
*
|
|
83
|
+
* Shared between the dashboard viewer and notebook cells on purpose: `# drill`
|
|
84
|
+
* is declared on a model *dimension*, so it fires wherever that dimension is
|
|
85
|
+
* grouped, and a notebook can therefore drill into a dashboard with no notebook-
|
|
86
|
+
* specific code. What differs between surfaces is only what they can do about it,
|
|
87
|
+
* which is what the two callbacks express.
|
|
88
|
+
*/
|
|
89
|
+
export function useDrill({
|
|
90
|
+
onNavigate,
|
|
91
|
+
onSelf,
|
|
92
|
+
selfLabel = "Filter this view",
|
|
93
|
+
canSelf,
|
|
94
|
+
}: UseDrillOptions): UseDrillResult {
|
|
95
|
+
// A cell inside the renderer's own DOM is the anchor, and this component
|
|
96
|
+
// holds no ref to it, so the menu is positioned from the click coordinates.
|
|
97
|
+
const [menu, setMenu] = useState<DrillMenuState | null>(null);
|
|
98
|
+
|
|
99
|
+
// What this surface can actually do about a destination. Applied to the click
|
|
100
|
+
// and to the affordance from one place, so a cell reads as clickable exactly
|
|
101
|
+
// when clicking it would do something.
|
|
102
|
+
const honorable = useCallback(
|
|
103
|
+
(destinations: string[], given: string) =>
|
|
104
|
+
destinations.filter((destination) =>
|
|
105
|
+
destination === DRILL_SELF
|
|
106
|
+
? onSelf !== undefined && (canSelf?.(given) ?? true)
|
|
107
|
+
: onNavigate !== undefined,
|
|
108
|
+
),
|
|
109
|
+
[onNavigate, onSelf, canSelf],
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const go = useCallback(
|
|
113
|
+
(intent: DrillIntent, destination: string, event?: MouseEvent) => {
|
|
114
|
+
if (destination === DRILL_SELF) {
|
|
115
|
+
// The raw value, not `intent.value`: only this surface knows the
|
|
116
|
+
// declared type of its own given, so only it can encode correctly.
|
|
117
|
+
onSelf?.(intent.given, intent.rawValue);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
onNavigate?.(
|
|
121
|
+
{
|
|
122
|
+
dashboard: destination,
|
|
123
|
+
givens: { [intent.given]: intent.value },
|
|
124
|
+
},
|
|
125
|
+
event,
|
|
126
|
+
);
|
|
127
|
+
},
|
|
128
|
+
[onNavigate, onSelf],
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const onClick = useCallback(
|
|
132
|
+
(payload: DrillClickPayload) => {
|
|
133
|
+
// Runs on every cell click, so "not a drill" is the ordinary answer.
|
|
134
|
+
const intent = resolveDrill(payload);
|
|
135
|
+
if (!intent) return;
|
|
136
|
+
|
|
137
|
+
// Offer only what this surface can actually do, so a menu never lists a
|
|
138
|
+
// destination that would be a no-op when picked.
|
|
139
|
+
const destinations = honorable(intent.to, intent.given);
|
|
140
|
+
if (destinations.length === 0) return;
|
|
141
|
+
if (destinations.length === 1) {
|
|
142
|
+
go(intent, destinations[0], payload.event);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
setMenu({
|
|
146
|
+
intent,
|
|
147
|
+
destinations,
|
|
148
|
+
event: payload.event,
|
|
149
|
+
top: payload.event?.clientY ?? 0,
|
|
150
|
+
left: payload.event?.clientX ?? 0,
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
[go, honorable],
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const canDrill = useCallback(
|
|
157
|
+
(field: DrillField) =>
|
|
158
|
+
honorable(drillDestinations(field), drillGivenName(field)).length > 0,
|
|
159
|
+
[honorable],
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const drill = useMemo<DrillBinding>(
|
|
163
|
+
() => ({ onClick, canDrill }),
|
|
164
|
+
[onClick, canDrill],
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const close = useCallback(() => setMenu(null), []);
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
drill,
|
|
171
|
+
drillMenu: (
|
|
172
|
+
<Menu
|
|
173
|
+
open={menu !== null}
|
|
174
|
+
onClose={close}
|
|
175
|
+
anchorReference="anchorPosition"
|
|
176
|
+
anchorPosition={{ top: menu?.top ?? 0, left: menu?.left ?? 0 }}
|
|
177
|
+
>
|
|
178
|
+
<ListSubheader sx={{ lineHeight: "32px" }}>
|
|
179
|
+
{menu ? `${menu.intent.label} →` : ""}
|
|
180
|
+
</ListSubheader>
|
|
181
|
+
{/* Deduplicated: `# drill { to=[overview, overview] }` is a typo
|
|
182
|
+
rather than a request for two identical rows, and React keys
|
|
183
|
+
these by destination, so the duplicate warned as well as
|
|
184
|
+
rendered twice. */}
|
|
185
|
+
{Array.from(new Set(menu?.destinations ?? [])).map(
|
|
186
|
+
(destination) => (
|
|
187
|
+
<MenuItem
|
|
188
|
+
key={destination}
|
|
189
|
+
onClick={() => {
|
|
190
|
+
close();
|
|
191
|
+
if (menu) go(menu.intent, destination, menu.event);
|
|
192
|
+
}}
|
|
193
|
+
>
|
|
194
|
+
{destination === DRILL_SELF
|
|
195
|
+
? selfLabel
|
|
196
|
+
: humanizeSlug(destination)}
|
|
197
|
+
</MenuItem>
|
|
198
|
+
),
|
|
199
|
+
)}
|
|
200
|
+
</Menu>
|
|
201
|
+
),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
1
4
|
import * as Malloy from "@malloydata/malloy-interfaces";
|
|
2
5
|
import {
|
|
3
6
|
DimensionSpec,
|
|
4
7
|
FilterType,
|
|
5
8
|
} from "../../hooks/useDimensionalFilterRangeData";
|
|
6
9
|
import { FilterSelection } from "../../hooks/useDimensionFilters";
|
|
10
|
+
import { escapeMalloyString } from "../../utils/malloyString";
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* A single filter specification with source and dimension
|
|
@@ -136,9 +140,16 @@ export function parseAllSourceInfos(
|
|
|
136
140
|
if (cell.type === "code") {
|
|
137
141
|
// Extract model path from the first import statement found
|
|
138
142
|
if (!modelPath && cell.text) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
// The first quoted string on the first `import` line is the
|
|
144
|
+
// module path, for both `import 'x'` and `import {a} from 'x'`.
|
|
145
|
+
// A line scan rather than one regex over the whole cell: the
|
|
146
|
+
// optional `{...} from` group made that regex backtrack
|
|
147
|
+
// polynomially on adversarial input.
|
|
148
|
+
const importLine = cell.text
|
|
149
|
+
.split("\n")
|
|
150
|
+
.map((line) => line.trim())
|
|
151
|
+
.find((line) => line.startsWith("import "));
|
|
152
|
+
const importMatch = importLine?.match(/['"]([^'"\n]+)['"]/);
|
|
142
153
|
if (importMatch) {
|
|
143
154
|
modelPath = importMatch[1];
|
|
144
155
|
}
|
|
@@ -295,7 +306,7 @@ export function generateFilterClause(
|
|
|
295
306
|
return `@${v.getFullYear()}-${String(v.getMonth() + 1).padStart(2, "0")}-${String(v.getDate()).padStart(2, "0")}`;
|
|
296
307
|
}
|
|
297
308
|
if (typeof v === "string") {
|
|
298
|
-
return `'${v
|
|
309
|
+
return `'${escapeMalloyString(v)}'`;
|
|
299
310
|
}
|
|
300
311
|
if (typeof v === "boolean") return v ? "true" : "false";
|
|
301
312
|
return String(v);
|
|
@@ -314,7 +325,7 @@ export function generateFilterClause(
|
|
|
314
325
|
|
|
315
326
|
case "Contains":
|
|
316
327
|
if (typeof value === "string") {
|
|
317
|
-
return `${fieldName} ~ f'%${value
|
|
328
|
+
return `${fieldName} ~ f'%${escapeMalloyString(value)}%'`;
|
|
318
329
|
}
|
|
319
330
|
return `${fieldName} = ${formatValue(value)}`;
|
|
320
331
|
|