@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,449 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
NumberFilterExpression,
|
|
6
|
+
StringFilterExpression,
|
|
7
|
+
} from "@malloydata/malloy-filter";
|
|
8
|
+
import { parseAnnotation } from "@malloydata/malloy-tag";
|
|
9
|
+
import { describe, expect, it } from "bun:test";
|
|
10
|
+
import {
|
|
11
|
+
drillDestinations,
|
|
12
|
+
drillGivenName,
|
|
13
|
+
encodeDrillValue,
|
|
14
|
+
drillValueToFilter,
|
|
15
|
+
humanizeSlug,
|
|
16
|
+
resolveDrill,
|
|
17
|
+
type DrillClickPayload,
|
|
18
|
+
} from "./resolveDrill";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A click payload whose field carries the given annotation lines, parsed the
|
|
22
|
+
* way the renderer parses them. Going through the real tag parser rather than a
|
|
23
|
+
* hand-built stub is the point: the grammar is the contract with Malloyyo, and a
|
|
24
|
+
* stub would agree with itself no matter what MOTLY actually accepts.
|
|
25
|
+
*/
|
|
26
|
+
function click(
|
|
27
|
+
annotations: string[],
|
|
28
|
+
value: unknown,
|
|
29
|
+
options: {
|
|
30
|
+
name?: string;
|
|
31
|
+
isHeader?: boolean;
|
|
32
|
+
wasDimension?: boolean;
|
|
33
|
+
} = {},
|
|
34
|
+
): DrillClickPayload {
|
|
35
|
+
return {
|
|
36
|
+
field: {
|
|
37
|
+
name: options.name ?? "brand_name",
|
|
38
|
+
tag: parseAnnotation(annotations).tag,
|
|
39
|
+
wasDimension:
|
|
40
|
+
options.wasDimension === undefined
|
|
41
|
+
? undefined
|
|
42
|
+
: () => options.wasDimension as boolean,
|
|
43
|
+
},
|
|
44
|
+
value,
|
|
45
|
+
isHeader: options.isHeader,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const DRILL_TO_TWO = '# drill { to=["overview", "regions"] given=BRAND }\n';
|
|
50
|
+
|
|
51
|
+
describe("resolveDrill", () => {
|
|
52
|
+
it("reads destinations, the given override, and the clicked value", () => {
|
|
53
|
+
expect(resolveDrill(click([DRILL_TO_TWO], "Nike"))).toEqual({
|
|
54
|
+
to: ["overview", "regions"],
|
|
55
|
+
given: "BRAND",
|
|
56
|
+
value: "Nike",
|
|
57
|
+
rawValue: "Nike",
|
|
58
|
+
label: "Nike",
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("uses the dimension name verbatim when the tag names no given", () => {
|
|
63
|
+
const intent = resolveDrill(
|
|
64
|
+
click(["# drill { to=overview }\n"], "US", { name: "region_name" }),
|
|
65
|
+
);
|
|
66
|
+
// NOT upper-cased. Given names are matched exactly, so upper-casing here
|
|
67
|
+
// made `to=self` on a lowercase-named given resolve to nothing at all.
|
|
68
|
+
expect(intent?.given).toBe("region_name");
|
|
69
|
+
// A lone destination may be written unbracketed, as Malloyyo allows.
|
|
70
|
+
expect(intent?.to).toEqual(["overview"]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("passes `self` through as a destination for the host to interpret", () => {
|
|
74
|
+
expect(resolveDrill(click(["# drill { to=self }\n"], "EU"))?.to).toEqual([
|
|
75
|
+
"self",
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("ignores a click on a field with no drill tag", () => {
|
|
80
|
+
expect(resolveDrill(click([], "Nike"))).toBeUndefined();
|
|
81
|
+
expect(
|
|
82
|
+
resolveDrill(click(["# currency\n"], 10, { name: "amount" })),
|
|
83
|
+
).toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("ignores a header click, which names a field rather than a value", () => {
|
|
87
|
+
expect(
|
|
88
|
+
resolveDrill(click([DRILL_TO_TWO], "Nike", { isHeader: true })),
|
|
89
|
+
).toBeUndefined();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("ignores a drill tag that names no destination", () => {
|
|
93
|
+
// The server lints this as an authoring error; clicking it must not
|
|
94
|
+
// navigate to nowhere in the meantime.
|
|
95
|
+
expect(resolveDrill(click(["# drill\n"], "Nike"))).toBeUndefined();
|
|
96
|
+
expect(
|
|
97
|
+
resolveDrill(click(["# drill { to=[] }\n"], "Nike")),
|
|
98
|
+
).toBeUndefined();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("ignores clicks with nothing to resolve", () => {
|
|
102
|
+
expect(resolveDrill(undefined)).toBeUndefined();
|
|
103
|
+
expect(resolveDrill({})).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("ignores an aggregate that inherited the tag", () => {
|
|
107
|
+
// `# drill` is declared on a dimension, but a measure defined over it can
|
|
108
|
+
// carry the annotation through. Its cell holds a total, not the value the
|
|
109
|
+
// filter would name, so clicking it must not navigate.
|
|
110
|
+
expect(
|
|
111
|
+
resolveDrill(click([DRILL_TO_TWO], "Nike", { wasDimension: false })),
|
|
112
|
+
).toBeUndefined();
|
|
113
|
+
expect(
|
|
114
|
+
resolveDrill(click([DRILL_TO_TWO], "Nike", { wasDimension: true })),
|
|
115
|
+
).toBeDefined();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("escapes a clicked value that would otherwise re-parse as two", () => {
|
|
119
|
+
// The whole reason the value goes through the filter encoder: a comma in
|
|
120
|
+
// the data would silently become "either of these" in the filter.
|
|
121
|
+
const intent = resolveDrill(click([DRILL_TO_TWO], "Ben & Jerry, Inc"));
|
|
122
|
+
expect(intent).toEqual({
|
|
123
|
+
to: ["overview", "regions"],
|
|
124
|
+
given: "BRAND",
|
|
125
|
+
value: "Ben\\ &\\ Jerry\\,\\ Inc",
|
|
126
|
+
rawValue: "Ben & Jerry, Inc",
|
|
127
|
+
// The label stays human: it is only ever shown, never parsed.
|
|
128
|
+
label: "Ben & Jerry, Inc",
|
|
129
|
+
});
|
|
130
|
+
// And the encoding is checked against the parser that will read it,
|
|
131
|
+
// rather than against our own idea of what it should look like.
|
|
132
|
+
expect(StringFilterExpression.parse(intent!.value).parsed).toEqual({
|
|
133
|
+
operator: "=",
|
|
134
|
+
values: ["Ben & Jerry, Inc"],
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("declines a value it cannot express, rather than filtering by the wrong thing", () => {
|
|
139
|
+
expect(resolveDrill(click([DRILL_TO_TWO], null))).toBeUndefined();
|
|
140
|
+
expect(resolveDrill(click([DRILL_TO_TWO], undefined))).toBeUndefined();
|
|
141
|
+
expect(
|
|
142
|
+
resolveDrill(click([DRILL_TO_TWO], { nested: 1 })),
|
|
143
|
+
).toBeUndefined();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe("drillDestinations", () => {
|
|
148
|
+
// The affordance reads destinations off field metadata, before any click, so
|
|
149
|
+
// it has to answer the same as the click path: otherwise a cell reads as
|
|
150
|
+
// clickable and then does nothing, or the reverse.
|
|
151
|
+
const field = (annotations: string[], wasDimension?: boolean) => ({
|
|
152
|
+
name: "brand_name",
|
|
153
|
+
tag: parseAnnotation(annotations).tag,
|
|
154
|
+
wasDimension: wasDimension === undefined ? undefined : () => wasDimension,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("agrees with resolveDrill about what drills", () => {
|
|
158
|
+
expect(drillDestinations(field([DRILL_TO_TWO]))).toEqual([
|
|
159
|
+
"overview",
|
|
160
|
+
"regions",
|
|
161
|
+
]);
|
|
162
|
+
expect(drillDestinations(field(["# drill { to=self }\n"]))).toEqual([
|
|
163
|
+
"self",
|
|
164
|
+
]);
|
|
165
|
+
expect(drillDestinations(field(["# drill { to=overview }\n"]))).toEqual([
|
|
166
|
+
"overview",
|
|
167
|
+
]);
|
|
168
|
+
expect(drillDestinations(field([]))).toEqual([]);
|
|
169
|
+
expect(drillDestinations(field(["# drill\n"]))).toEqual([]);
|
|
170
|
+
expect(drillDestinations(field([DRILL_TO_TWO], false))).toEqual([]);
|
|
171
|
+
expect(drillDestinations(undefined)).toEqual([]);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("humanizeSlug", () => {
|
|
176
|
+
it("reads a slug as a sentence, the way Malloyyo labels the same menu", () => {
|
|
177
|
+
expect(humanizeSlug("category_detail")).toBe("Category detail");
|
|
178
|
+
expect(humanizeSlug("brand-explorer")).toBe("Brand explorer");
|
|
179
|
+
expect(humanizeSlug("overview")).toBe("Overview");
|
|
180
|
+
expect(humanizeSlug("")).toBe("");
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("drillValueToFilter", () => {
|
|
185
|
+
it("encodes a string as a filter list entry", () => {
|
|
186
|
+
expect(drillValueToFilter("Nike")).toBe("Nike");
|
|
187
|
+
expect(drillValueToFilter("a, b")).toBe("a\\,\\ b");
|
|
188
|
+
// An apostrophe is ordinary inside a filter word, so it stays bare.
|
|
189
|
+
expect(drillValueToFilter("Levi's")).toBe("Levi's");
|
|
190
|
+
// The values a hazardous cell will actually match, per the real parser.
|
|
191
|
+
for (const value of ["a, b", "-Nike", "100%", "null"]) {
|
|
192
|
+
expect(
|
|
193
|
+
StringFilterExpression.parse(drillValueToFilter(value)!).parsed,
|
|
194
|
+
).toEqual({ operator: "=", values: [value] });
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("refuses a cell that would encode to the EMPTY filter", () => {
|
|
199
|
+
// The empty filter matches every row, so a drill producing one hands back
|
|
200
|
+
// the whole dataset dressed up as a drilled view. `encodeFilterList`
|
|
201
|
+
// drops any value with no non-whitespace character, and this guard used
|
|
202
|
+
// to test the input against `""` instead of asking the encoder, so it
|
|
203
|
+
// fell out of step the moment that rule grew past the empty string.
|
|
204
|
+
for (const blank of ["", " ", " ", "\t", "\u00a0", "\u3000"]) {
|
|
205
|
+
expect(drillValueToFilter(blank)).toBeUndefined();
|
|
206
|
+
}
|
|
207
|
+
// A value that merely LOOKS blank but does encode is still a drill: the
|
|
208
|
+
// refusal is "encodes to nothing", not "looks empty".
|
|
209
|
+
expect(drillValueToFilter("\u200b")).toBe("\u200b");
|
|
210
|
+
expect(drillValueToFilter(" Nike ")).toBe("\\ Nike\\ ");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("leaves a number bare, which the number grammar reads as the value", () => {
|
|
214
|
+
// Not a negation: checked against the real parser, because `-2.5` looks
|
|
215
|
+
// exactly like the `-` that negates in the *string* grammar.
|
|
216
|
+
for (const value of [100, -2.5, 0]) {
|
|
217
|
+
expect(
|
|
218
|
+
NumberFilterExpression.parse(drillValueToFilter(value)!).parsed,
|
|
219
|
+
).toEqual({ operator: "=", values: [String(value)] });
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("encodes a number as equality and a boolean as itself", () => {
|
|
224
|
+
expect(drillValueToFilter(100)).toBe("100");
|
|
225
|
+
expect(drillValueToFilter(-2.5)).toBe("-2.5");
|
|
226
|
+
expect(drillValueToFilter(0)).toBe("0");
|
|
227
|
+
expect(drillValueToFilter(true)).toBe("true");
|
|
228
|
+
expect(drillValueToFilter(false)).toBe("false");
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("truncates a date to the day the cell showed", () => {
|
|
232
|
+
expect(drillValueToFilter(new Date("2024-03-05T13:45:00Z"))).toBe(
|
|
233
|
+
"2024-03-05",
|
|
234
|
+
);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("declines what has no filter spelling", () => {
|
|
238
|
+
expect(drillValueToFilter(null)).toBeUndefined();
|
|
239
|
+
expect(drillValueToFilter(undefined)).toBeUndefined();
|
|
240
|
+
expect(drillValueToFilter(NaN)).toBeUndefined();
|
|
241
|
+
expect(drillValueToFilter(Infinity)).toBeUndefined();
|
|
242
|
+
expect(drillValueToFilter([1, 2])).toBeUndefined();
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe("encodeDrillValue", () => {
|
|
247
|
+
it("escapes for a filter given, which is what a filter parses", () => {
|
|
248
|
+
expect(encodeDrillValue("Ben & Jerry, Inc", "filter<string>")).toBe(
|
|
249
|
+
"Ben\\ &\\ Jerry\\,\\ Inc",
|
|
250
|
+
);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("leaves the value alone for a plain string given", () => {
|
|
254
|
+
// The escaping is meaningful only to the filter parser. A plain `string`
|
|
255
|
+
// given is bound as a value, so a seeded `Ben\ &\ Jerry\,\ Inc` would
|
|
256
|
+
// be compared literally, backslashes and all, and match nothing.
|
|
257
|
+
expect(encodeDrillValue("Ben & Jerry, Inc", "string")).toBe(
|
|
258
|
+
"Ben & Jerry, Inc",
|
|
259
|
+
);
|
|
260
|
+
expect(encodeDrillValue("-Outerwear", "string")).toBe("-Outerwear");
|
|
261
|
+
expect(encodeDrillValue("100%", "string")).toBe("100%");
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("passes numbers and booleans through in their own type", () => {
|
|
265
|
+
// The STRING forms ("100", "true") would be wrong here, not merely a
|
|
266
|
+
// different spelling: `givensToRequest` converts only `Date`, so a string
|
|
267
|
+
// sent for a `number` given travels as a string and Malloy refuses it.
|
|
268
|
+
expect(encodeDrillValue(100, "number")).toBe(100);
|
|
269
|
+
expect(encodeDrillValue(-2.5, "number")).toBe(-2.5);
|
|
270
|
+
expect(encodeDrillValue(true, "boolean")).toBe(true);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("falls back to the filter encoding when the type is unknown", () => {
|
|
274
|
+
// A cross-dashboard drill: the destination declares its own givens and
|
|
275
|
+
// this side cannot see them, so the filter spelling is the useful guess.
|
|
276
|
+
expect(encodeDrillValue("a, b", undefined)).toBe("a\\,\\ b");
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("declines a non-numeric value for a `filter<number>` given", () => {
|
|
280
|
+
// The number branch for PLAIN givens already refused these; the filter
|
|
281
|
+
// arm fell through to string-filter syntax, so a click on a text cell
|
|
282
|
+
// seeded `filter<number>` with `West`, which its own parser refuses, and
|
|
283
|
+
// the server failed every cell in the notebook.
|
|
284
|
+
for (const value of [
|
|
285
|
+
"West",
|
|
286
|
+
true,
|
|
287
|
+
new Date("2024-03-05T00:00:00Z"),
|
|
288
|
+
"",
|
|
289
|
+
]) {
|
|
290
|
+
expect(encodeDrillValue(value, "filter<number>")).toBeUndefined();
|
|
291
|
+
}
|
|
292
|
+
// A number, or a string spelling one, still passes through bare, which is
|
|
293
|
+
// correct for the NUMBER grammar.
|
|
294
|
+
expect(encodeDrillValue(42, "filter<number>")).toBe("42");
|
|
295
|
+
expect(encodeDrillValue("42", "filter<number>")).toBe("42");
|
|
296
|
+
expect(encodeDrillValue(-5, "filter<number>")).toBe("-5");
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("escapes a number drilled into a `filter<string>` given", () => {
|
|
300
|
+
// The two filter grammars disagree about a leading `-`: the NUMBER
|
|
301
|
+
// grammar reads `-5` as the value, the STRING grammar reads it as a
|
|
302
|
+
// negation. Routing a number bare into a `filter<string>` therefore
|
|
303
|
+
// filtered to every row EXCEPT the one clicked, silently.
|
|
304
|
+
const encoded = encodeDrillValue(-5, "filter<string>") as string;
|
|
305
|
+
expect(StringFilterExpression.parse(encoded).parsed).toEqual({
|
|
306
|
+
operator: "=",
|
|
307
|
+
values: ["-5"],
|
|
308
|
+
});
|
|
309
|
+
expect(
|
|
310
|
+
StringFilterExpression.parse(
|
|
311
|
+
encodeDrillValue(-2.5, "filter<string>") as string,
|
|
312
|
+
).parsed,
|
|
313
|
+
).toEqual({ operator: "=", values: ["-2.5"] });
|
|
314
|
+
// A `filter<number>` target keeps the bare spelling, which is correct for
|
|
315
|
+
// ITS grammar. That difference is the whole point.
|
|
316
|
+
expect(encodeDrillValue(-5, "filter<number>")).toBe("-5");
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it("declines a blank cell for a plain `string` given too", () => {
|
|
320
|
+
// The same reason `drillValueToFilter` refuses one: a blank cell is far
|
|
321
|
+
// likelier a misclick than a request for the rows that are blank. This
|
|
322
|
+
// used to test only `""`, so a space or a tab drilled to a value matching
|
|
323
|
+
// essentially nothing and the reader got an empty notebook instead of a
|
|
324
|
+
// declined click.
|
|
325
|
+
for (const blank of ["", " ", "\t", "\u00a0"]) {
|
|
326
|
+
expect(encodeDrillValue(blank, "string")).toBeUndefined();
|
|
327
|
+
}
|
|
328
|
+
// Padding around a real value is not blank, and is kept as clicked.
|
|
329
|
+
expect(encodeDrillValue(" Nike ", "string")).toBe(" Nike ");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("declines a value that is not a number for a `number` given", () => {
|
|
333
|
+
// `Number()` accepts far more than numbers, and every extra it accepted
|
|
334
|
+
// became a WRONG filter rather than a refused one: a clicked Date
|
|
335
|
+
// encoded to its epoch milliseconds and a null cell to 0, so the notebook
|
|
336
|
+
// re-ran filtered to a value nobody clicked and returned nothing.
|
|
337
|
+
expect(
|
|
338
|
+
encodeDrillValue(new Date("2024-03-05T13:45:00Z"), "number"),
|
|
339
|
+
).toBeUndefined();
|
|
340
|
+
expect(encodeDrillValue(null, "number")).toBeUndefined();
|
|
341
|
+
expect(encodeDrillValue(true, "number")).toBeUndefined();
|
|
342
|
+
expect(encodeDrillValue("", "number")).toBeUndefined();
|
|
343
|
+
expect(encodeDrillValue(" ", "number")).toBeUndefined();
|
|
344
|
+
// A number, and a string that spells one, still pass.
|
|
345
|
+
expect(encodeDrillValue(12, "number")).toBe(12);
|
|
346
|
+
expect(encodeDrillValue("12", "number")).toBe(12);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it("hands a temporal given the Date, so it keeps its time of day", () => {
|
|
350
|
+
// Falling through to `drillValueToFilter` truncated to `YYYY-MM-DD`
|
|
351
|
+
// first, which is right for a `date` given and drops the time of day for
|
|
352
|
+
// a `timestamp` one, so the drill filtered to midnight rather than to the
|
|
353
|
+
// instant in the cell. `givensToRequest` spells it per type instead.
|
|
354
|
+
const clicked = new Date("2024-03-05T13:45:00Z");
|
|
355
|
+
for (const type of ["date", "timestamp", "timestamptz"]) {
|
|
356
|
+
expect(encodeDrillValue(clicked, type)).toEqual(clicked);
|
|
357
|
+
}
|
|
358
|
+
// A filter-typed target still takes the day, which is its own rule.
|
|
359
|
+
expect(encodeDrillValue(clicked, "filter<date>")).toBe("2024-03-05");
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it("declines a value with no spelling", () => {
|
|
363
|
+
expect(encodeDrillValue(null, "string")).toBeUndefined();
|
|
364
|
+
expect(encodeDrillValue(undefined, "filter<string>")).toBeUndefined();
|
|
365
|
+
expect(encodeDrillValue(NaN, "number")).toBeUndefined();
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
describe("a drill on an empty cell", () => {
|
|
370
|
+
it("is refused rather than encoding the match-everything filter", () => {
|
|
371
|
+
// `encodeFilterList` drops an empty value, so encoding one yields the
|
|
372
|
+
// EMPTY filter, which matches every row. A drill that widened instead of
|
|
373
|
+
// narrowing is worse than one that does nothing, and `null` is already
|
|
374
|
+
// refused on exactly that reasoning.
|
|
375
|
+
expect(drillValueToFilter("")).toBeUndefined();
|
|
376
|
+
expect(encodeDrillValue("", "filter<string>")).toBeUndefined();
|
|
377
|
+
expect(encodeDrillValue("", "string")).toBeUndefined();
|
|
378
|
+
expect(encodeDrillValue("", undefined)).toBeUndefined();
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it("does not over-refuse a falsy value that is a real one", () => {
|
|
382
|
+
// The refusal is about values with no filter spelling, not about values
|
|
383
|
+
// that look empty. A zero and a false are ordinary cells.
|
|
384
|
+
expect(drillValueToFilter(0)).toBe("0");
|
|
385
|
+
expect(drillValueToFilter(false)).toBe("false");
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it("refuses whitespace too, which it did not always", () => {
|
|
389
|
+
// This case used to assert the opposite, that `" "` still produced a
|
|
390
|
+
// drill, and it passed for the worst possible reason: the value it got
|
|
391
|
+
// back was `""`, the match-everything filter, and `toBeDefined()` is
|
|
392
|
+
// satisfied by it. The assertion was too weak to tell a working drill
|
|
393
|
+
// from the exact catastrophe the block above exists to prevent.
|
|
394
|
+
//
|
|
395
|
+
// The encoder cannot carry a whitespace-only value in this grammar (see
|
|
396
|
+
// filterValue.ts), so refusing is the only faithful option: a drill that
|
|
397
|
+
// widens to every row is worse than one that does nothing.
|
|
398
|
+
expect(drillValueToFilter(" ")).toBeUndefined();
|
|
399
|
+
expect(encodeDrillValue(" ", "filter<string>")).toBeUndefined();
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
describe("encodeDrillValue returns the given's own type", () => {
|
|
404
|
+
it("gives a number given a number, not a string", () => {
|
|
405
|
+
// `givensToRequest` converts only `Date`, so a string sent for a `number`
|
|
406
|
+
// given goes over the wire as a string and Malloy refuses the query.
|
|
407
|
+
expect(encodeDrillValue(100, "number")).toBe(100);
|
|
408
|
+
expect(encodeDrillValue("100", "number")).toBe(100);
|
|
409
|
+
expect(encodeDrillValue(-2.5, "number")).toBe(-2.5);
|
|
410
|
+
expect(encodeDrillValue("not a number", "number")).toBeUndefined();
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it("gives a boolean given a boolean", () => {
|
|
414
|
+
expect(encodeDrillValue(true, "boolean")).toBe(true);
|
|
415
|
+
expect(encodeDrillValue(false, "boolean")).toBe(false);
|
|
416
|
+
expect(encodeDrillValue("true", "boolean")).toBe(true);
|
|
417
|
+
expect(encodeDrillValue("false", "boolean")).toBe(false);
|
|
418
|
+
expect(encodeDrillValue("yes", "boolean")).toBeUndefined();
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it("still gives a string given a string and a filter given filter syntax", () => {
|
|
422
|
+
expect(encodeDrillValue("Outerwear", "string")).toBe("Outerwear");
|
|
423
|
+
expect(encodeDrillValue("a, b", "filter<string>")).toBe("a\\,\\ b");
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
describe("drillGivenName", () => {
|
|
428
|
+
it("prefers the tag's given= and otherwise uses the field name as spelled", () => {
|
|
429
|
+
const tagged = parseAnnotation(["# drill { to=self given=BRAND }\n"]);
|
|
430
|
+
expect(drillGivenName({ name: "brand_name", tag: tagged.tag })).toBe(
|
|
431
|
+
"BRAND",
|
|
432
|
+
);
|
|
433
|
+
const untagged = parseAnnotation(["# drill { to=self }\n"]);
|
|
434
|
+
expect(drillGivenName({ name: "brand_name", tag: untagged.tag })).toBe(
|
|
435
|
+
"brand_name",
|
|
436
|
+
);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it("matches a lowercase given declaration, which upper-casing did not", () => {
|
|
440
|
+
// The whole point of the change. `declaredTypes` is keyed by the name the
|
|
441
|
+
// model spells and probed with `.has()`, so an upper-cased lookup missed
|
|
442
|
+
// and the click was dropped with no affordance and no error.
|
|
443
|
+
const declared = new Map([["region", "string"]]);
|
|
444
|
+
const untagged = parseAnnotation(["# drill { to=self }\n"]);
|
|
445
|
+
expect(
|
|
446
|
+
declared.has(drillGivenName({ name: "region", tag: untagged.tag })),
|
|
447
|
+
).toBe(true);
|
|
448
|
+
});
|
|
449
|
+
});
|