@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,175 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
5
|
+
import { describe, expect, it } from "bun:test";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import type { Given } from "../../client";
|
|
8
|
+
import { useGivensState } from "../../hooks/useGivensState";
|
|
9
|
+
import { decodeFilterList } from "./filterValue";
|
|
10
|
+
import { GivensPanel } from "./GivensPanel";
|
|
11
|
+
|
|
12
|
+
const TYPES = new Map<string, string | undefined>([
|
|
13
|
+
["BRAND", "filter<string>"],
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const MULTISELECT: Given = {
|
|
17
|
+
name: "BRAND",
|
|
18
|
+
type: "filter<string>",
|
|
19
|
+
control: "multiselect",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
let lastDraft: string | undefined;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The panel wired to the state hook through a host that keeps applied values in
|
|
26
|
+
* its "URL" and feeds them straight back in, which is what `NotebookPage` does
|
|
27
|
+
* through react-router. The loop is the point: a control's next value is
|
|
28
|
+
* computed from the value it is currently rendering, so anything that delays
|
|
29
|
+
* that value getting back to it is where a lost click would come from.
|
|
30
|
+
*/
|
|
31
|
+
function Harness({ options }: { options?: Map<string, string[]> }) {
|
|
32
|
+
const [params, setParams] = useState<Record<string, string>>({});
|
|
33
|
+
const { draft, setGiven } = useGivensState({
|
|
34
|
+
declaredTypes: TYPES,
|
|
35
|
+
params,
|
|
36
|
+
onParamsChange: setParams,
|
|
37
|
+
autorun: true,
|
|
38
|
+
});
|
|
39
|
+
lastDraft = draft.get("BRAND") as string | undefined;
|
|
40
|
+
return (
|
|
41
|
+
<GivensPanel
|
|
42
|
+
givens={[MULTISELECT]}
|
|
43
|
+
values={draft}
|
|
44
|
+
onChange={setGiven}
|
|
45
|
+
onReset={() => {}}
|
|
46
|
+
options={options ?? new Map([["BRAND", ["Loft", "Aurora", "Nike"]]])}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// The combobox by role, not by label: once a value is picked the control also
|
|
52
|
+
// renders a chip carrying the same accessible name, and getByLabelText then
|
|
53
|
+
// matches two elements.
|
|
54
|
+
const combobox = () => screen.getByRole("combobox");
|
|
55
|
+
|
|
56
|
+
function pick(label: string) {
|
|
57
|
+
fireEvent.keyDown(combobox(), { key: "ArrowDown" });
|
|
58
|
+
fireEvent.click(screen.getByRole("option", { name: label }));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe("GivensPanel: multiselect", () => {
|
|
62
|
+
it("joins a second pick onto the first rather than replacing it", () => {
|
|
63
|
+
// A Playwright spec on the originating branch documented the opposite,
|
|
64
|
+
// "a second click sent immediately lands on the pre-first-pick selection
|
|
65
|
+
// and replaces Loft instead of joining it", and worked around it by
|
|
66
|
+
// awaiting a URL change between the clicks. It does not reproduce here,
|
|
67
|
+
// with the host's round trip in place and no await between the clicks, so
|
|
68
|
+
// this pins the behaviour that is actually observable at this level
|
|
69
|
+
// rather than encoding a race nobody can currently demonstrate.
|
|
70
|
+
render(<Harness />);
|
|
71
|
+
|
|
72
|
+
pick("Loft");
|
|
73
|
+
expect(decodeFilterList(lastDraft ?? "")).toEqual(["Loft"]);
|
|
74
|
+
|
|
75
|
+
pick("Aurora");
|
|
76
|
+
expect(decodeFilterList(lastDraft ?? "")).toEqual(["Loft", "Aurora"]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("encodes the selection as a filter Malloy reads as 'any of these'", () => {
|
|
80
|
+
render(<Harness options={new Map([["BRAND", ["Ben & Jerry, Inc"]]])} />);
|
|
81
|
+
|
|
82
|
+
pick("Ben & Jerry, Inc");
|
|
83
|
+
|
|
84
|
+
// Escaped, so the comma stays inside one value instead of splitting it
|
|
85
|
+
// into two brands.
|
|
86
|
+
expect(lastDraft).toBe("Ben\\ &\\ Jerry\\,\\ Inc");
|
|
87
|
+
expect(decodeFilterList(lastDraft ?? "")).toEqual(["Ben & Jerry, Inc"]);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe("GivensPanel: a suggest query that failed", () => {
|
|
92
|
+
it("says so, instead of showing an empty dropdown", () => {
|
|
93
|
+
// An empty option list and a failed query render identically, and mean
|
|
94
|
+
// opposite things. Without this the reader sees a picker with nothing in
|
|
95
|
+
// it and concludes the data has no values.
|
|
96
|
+
render(
|
|
97
|
+
<GivensPanel
|
|
98
|
+
givens={[MULTISELECT]}
|
|
99
|
+
values={new Map()}
|
|
100
|
+
onChange={() => {}}
|
|
101
|
+
onReset={() => {}}
|
|
102
|
+
options={new Map()}
|
|
103
|
+
optionsFailed={new Set(["BRAND"])}
|
|
104
|
+
/>,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
expect(
|
|
108
|
+
screen.getByText(/Could not load the options for this control/),
|
|
109
|
+
).toBeDefined();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("says nothing when the dimension simply has no values", () => {
|
|
113
|
+
render(
|
|
114
|
+
<GivensPanel
|
|
115
|
+
givens={[MULTISELECT]}
|
|
116
|
+
values={new Map()}
|
|
117
|
+
onChange={() => {}}
|
|
118
|
+
onReset={() => {}}
|
|
119
|
+
options={new Map([["BRAND", []]])}
|
|
120
|
+
/>,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
expect(screen.queryAllByText(/Could not load the options/)).toHaveLength(
|
|
124
|
+
0,
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe("layout and title", () => {
|
|
130
|
+
// Both props exist for the dashboard surface, which does not land in this
|
|
131
|
+
// slice, so nothing in the repo passes either one. Exercised here so the
|
|
132
|
+
// first render of the `bar` branch is not an external consumer's.
|
|
133
|
+
const props = {
|
|
134
|
+
givens: [MULTISELECT],
|
|
135
|
+
values: new Map(),
|
|
136
|
+
onChange: () => {},
|
|
137
|
+
onReset: () => {},
|
|
138
|
+
options: new Map([["BRAND", ["Nike"]]]),
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
it('titles the panel "Parameters" by default', () => {
|
|
142
|
+
render(<GivensPanel {...props} />);
|
|
143
|
+
expect(screen.getByText("Parameters")).toBeDefined();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("uses a given title in place of the default", () => {
|
|
147
|
+
render(<GivensPanel {...props} title="Filters" />);
|
|
148
|
+
expect(screen.getByText("Filters")).toBeDefined();
|
|
149
|
+
expect(screen.queryAllByText("Parameters")).toHaveLength(0);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("renders the bar layout with its controls and no heading", () => {
|
|
153
|
+
render(<GivensPanel {...props} layout="bar" />);
|
|
154
|
+
// The bar is meant to sit inline above a dashboard, so it carries the
|
|
155
|
+
// controls but drops the heading the panel layout shows.
|
|
156
|
+
expect(screen.getByRole("combobox")).toBeDefined();
|
|
157
|
+
expect(screen.queryAllByText("Parameters")).toHaveLength(0);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("still offers Reset from the bar layout", () => {
|
|
161
|
+
let reset = 0;
|
|
162
|
+
render(
|
|
163
|
+
<GivensPanel
|
|
164
|
+
{...props}
|
|
165
|
+
layout="bar"
|
|
166
|
+
values={new Map([["BRAND", "Nike"]])}
|
|
167
|
+
onReset={() => {
|
|
168
|
+
reset += 1;
|
|
169
|
+
}}
|
|
170
|
+
/>,
|
|
171
|
+
);
|
|
172
|
+
fireEvent.click(screen.getByRole("button", { name: "Reset" }));
|
|
173
|
+
expect(reset).toBe(1);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box, Button, Paper, Stack, Typography } from "@mui/material";
|
|
5
|
+
import { Given } from "../../client";
|
|
6
|
+
import { GivenValue } from "../../hooks/givenValue";
|
|
7
|
+
import { GivenInput } from "./GivenInput";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* How the control row is laid out.
|
|
11
|
+
*
|
|
12
|
+
* - `panel`: the vertical "Parameters" block a notebook shows above its cells.
|
|
13
|
+
* - `bar`: a horizontal filter bar above a dashboard grid.
|
|
14
|
+
*
|
|
15
|
+
* Two presentations of one control implementation, rather than two
|
|
16
|
+
* implementations: a control gains a behavior (a suggest dropdown, an Apply
|
|
17
|
+
* button) on both surfaces at once.
|
|
18
|
+
*/
|
|
19
|
+
export type GivensLayout = "panel" | "bar";
|
|
20
|
+
|
|
21
|
+
export interface GivensPanelProps {
|
|
22
|
+
givens: Given[];
|
|
23
|
+
values: Map<string, GivenValue>;
|
|
24
|
+
onChange: (name: string, value: GivenValue) => void;
|
|
25
|
+
onReset: () => void;
|
|
26
|
+
layout?: GivensLayout;
|
|
27
|
+
/** Resolved `suggest` options per given name. */
|
|
28
|
+
options?: Map<string, string[]>;
|
|
29
|
+
optionsLoading?: boolean;
|
|
30
|
+
/** Givens whose `suggest` query failed, from `useSuggestOptions.failed`. */
|
|
31
|
+
optionsFailed?: ReadonlySet<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Set to render an Apply button, for `autorun=false`. Absent means controls
|
|
34
|
+
* take effect as they change, which is the default everywhere.
|
|
35
|
+
*/
|
|
36
|
+
apply?: {
|
|
37
|
+
onApply: () => void;
|
|
38
|
+
/** Whether anything has changed since the last apply. */
|
|
39
|
+
pending: boolean;
|
|
40
|
+
};
|
|
41
|
+
/** Overrides the `panel` layout's "Parameters" heading. */
|
|
42
|
+
title?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Renders the control row: one input per declared `given:`.
|
|
47
|
+
* Returns null when the model declares no givens, so callers can drop
|
|
48
|
+
* `<GivensPanel ... />` unconditionally without a length guard.
|
|
49
|
+
*
|
|
50
|
+
* A "Reset" button appears in the header when at least one value is set; it
|
|
51
|
+
* fires `onReset`, which the parent should wire to `useGivensState.reset`. That
|
|
52
|
+
* puts the document's starting values back rather than emptying the row, so the
|
|
53
|
+
* button and the state agree on what "Reset" means.
|
|
54
|
+
*/
|
|
55
|
+
export function GivensPanel({
|
|
56
|
+
givens,
|
|
57
|
+
values,
|
|
58
|
+
onChange,
|
|
59
|
+
onReset,
|
|
60
|
+
layout = "panel",
|
|
61
|
+
options,
|
|
62
|
+
optionsLoading,
|
|
63
|
+
optionsFailed,
|
|
64
|
+
apply,
|
|
65
|
+
title,
|
|
66
|
+
}: GivensPanelProps) {
|
|
67
|
+
if (givens.length === 0) return null;
|
|
68
|
+
// Some value actually SET, not merely some entry present. `paramsToGivens`
|
|
69
|
+
// records `?X=` as a null entry, so counting entries offered Reset for a
|
|
70
|
+
// control that is unset, and pressing it changed nothing and left the empty
|
|
71
|
+
// parameter in the URL.
|
|
72
|
+
const hasValues = Array.from(values.values()).some((v) => v !== null);
|
|
73
|
+
|
|
74
|
+
const inputs = givens.map((given) => (
|
|
75
|
+
<Box
|
|
76
|
+
key={given.name}
|
|
77
|
+
sx={
|
|
78
|
+
layout === "bar"
|
|
79
|
+
? { minWidth: 200, flex: "1 1 200px", maxWidth: 320 }
|
|
80
|
+
: undefined
|
|
81
|
+
}
|
|
82
|
+
>
|
|
83
|
+
<GivenInput
|
|
84
|
+
given={given}
|
|
85
|
+
value={given.name ? values.get(given.name) : undefined}
|
|
86
|
+
onChange={(next) => given.name && onChange(given.name, next)}
|
|
87
|
+
options={given.name ? options?.get(given.name) : undefined}
|
|
88
|
+
optionsLoading={optionsLoading}
|
|
89
|
+
optionsFailed={
|
|
90
|
+
given.name ? optionsFailed?.has(given.name) : undefined
|
|
91
|
+
}
|
|
92
|
+
/>
|
|
93
|
+
</Box>
|
|
94
|
+
));
|
|
95
|
+
|
|
96
|
+
const actions = (
|
|
97
|
+
<Stack direction="row" alignItems="center" spacing={1}>
|
|
98
|
+
{apply && (
|
|
99
|
+
<Button
|
|
100
|
+
variant="contained"
|
|
101
|
+
size="small"
|
|
102
|
+
disableElevation
|
|
103
|
+
onClick={apply.onApply}
|
|
104
|
+
disabled={!apply.pending}
|
|
105
|
+
sx={{ textTransform: "none" }}
|
|
106
|
+
>
|
|
107
|
+
Apply
|
|
108
|
+
</Button>
|
|
109
|
+
)}
|
|
110
|
+
{hasValues && (
|
|
111
|
+
<Button
|
|
112
|
+
variant="text"
|
|
113
|
+
size="small"
|
|
114
|
+
onClick={onReset}
|
|
115
|
+
sx={{ textTransform: "none" }}
|
|
116
|
+
>
|
|
117
|
+
Reset
|
|
118
|
+
</Button>
|
|
119
|
+
)}
|
|
120
|
+
</Stack>
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
if (layout === "bar") {
|
|
124
|
+
return (
|
|
125
|
+
<Paper
|
|
126
|
+
elevation={0}
|
|
127
|
+
sx={{
|
|
128
|
+
p: 2,
|
|
129
|
+
border: 1,
|
|
130
|
+
borderColor: "divider",
|
|
131
|
+
borderRadius: 1,
|
|
132
|
+
backgroundColor: "background.paper",
|
|
133
|
+
}}
|
|
134
|
+
>
|
|
135
|
+
<Stack
|
|
136
|
+
direction="row"
|
|
137
|
+
alignItems="flex-start"
|
|
138
|
+
spacing={2}
|
|
139
|
+
useFlexGap
|
|
140
|
+
sx={{ flexWrap: "wrap" }}
|
|
141
|
+
>
|
|
142
|
+
{inputs}
|
|
143
|
+
<Box sx={{ flex: "0 0 auto", ml: "auto", pt: 0.5 }}>
|
|
144
|
+
{actions}
|
|
145
|
+
</Box>
|
|
146
|
+
</Stack>
|
|
147
|
+
</Paper>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<Paper
|
|
153
|
+
elevation={0}
|
|
154
|
+
sx={{
|
|
155
|
+
p: 3,
|
|
156
|
+
backgroundColor: "transparent",
|
|
157
|
+
border: "none",
|
|
158
|
+
boxShadow: "none",
|
|
159
|
+
}}
|
|
160
|
+
>
|
|
161
|
+
<Stack
|
|
162
|
+
direction="row"
|
|
163
|
+
alignItems="center"
|
|
164
|
+
justifyContent="space-between"
|
|
165
|
+
sx={{ mb: 2 }}
|
|
166
|
+
>
|
|
167
|
+
<Typography
|
|
168
|
+
variant="subtitle2"
|
|
169
|
+
sx={{ fontWeight: 600, color: "#333" }}
|
|
170
|
+
>
|
|
171
|
+
{title ?? "Parameters"}
|
|
172
|
+
</Typography>
|
|
173
|
+
{actions}
|
|
174
|
+
</Stack>
|
|
175
|
+
<Box
|
|
176
|
+
sx={{
|
|
177
|
+
display: "grid",
|
|
178
|
+
// Equal columns, so controls line up in a grid rather than
|
|
179
|
+
// packing by their own widths. 220px is a deliberate floor: at
|
|
180
|
+
// 250 a four-given notebook came out three-across with a lone
|
|
181
|
+
// control stranded on a second row at the common page width.
|
|
182
|
+
gridTemplateColumns: "repeat(auto-fill, minmax(220px, 1fr))",
|
|
183
|
+
// Each control is label + field + a helper line or two, so rows
|
|
184
|
+
// are top-aligned; a taller helper must not push its neighbours'
|
|
185
|
+
// fields down.
|
|
186
|
+
alignItems: "start",
|
|
187
|
+
columnGap: 3,
|
|
188
|
+
rowGap: 2.5,
|
|
189
|
+
}}
|
|
190
|
+
>
|
|
191
|
+
{inputs}
|
|
192
|
+
</Box>
|
|
193
|
+
</Paper>
|
|
194
|
+
);
|
|
195
|
+
}
|