@malloy-publisher/sdk 0.9.1 → 0.9.2
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/dist/{Dashboard-H1kJlDFo.es.js → DashboardTile-BFcxdv7R.es.js} +15918 -17760
- package/dist/DashboardTile-sg8LjUk8.cjs.js +137 -0
- package/dist/RenderedResult-B48wAjM8.cjs.js +141 -0
- package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-CBLHr32C.es.js} +193 -183
- package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-DCV8BUWD.es.js} +529 -521
- package/dist/ServerProvider-HRqT3w1C.cjs.js +1 -0
- package/dist/builder/index.cjs.js +146 -58
- package/dist/builder/index.es.js +9076 -6479
- package/dist/builder-entry.d.ts +4 -0
- package/dist/client/api.d.ts +77 -47
- 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 +84 -82
- package/dist/components/Dashboard/Dashboard.d.ts +8 -15
- package/dist/components/Dashboard/DashboardGrid.d.ts +23 -6
- package/dist/components/Dashboard/DashboardTile.d.ts +10 -1
- package/dist/components/Dashboard/DashboardView.d.ts +36 -0
- package/dist/components/Dashboard/TileCard.d.ts +15 -4
- package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
- package/dist/components/Dashboard/index.d.ts +3 -0
- package/dist/components/Dashboard/telemetry.d.ts +15 -3
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -1
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +16 -5
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +29 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +48 -21
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +17 -4
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +2 -10
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +3 -1
- package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
- package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
- package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
- package/dist/components/DashboardBuilder/SaveNotice.d.ts +27 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +19 -7
- package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +7 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +14 -12
- package/dist/components/DashboardBuilder/TileMenu.d.ts +11 -3
- package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +4 -0
- package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
- package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
- package/dist/components/DashboardBuilder/controls.d.ts +2 -2
- package/dist/components/DashboardBuilder/document.d.ts +42 -26
- package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
- package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
- package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -5
- package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
- package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
- package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
- package/dist/components/DashboardBuilder/preview.d.ts +24 -4
- package/dist/components/DashboardBuilder/readDocument.d.ts +4 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +14 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +13 -13
- package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
- package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
- package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
- package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
- package/dist/components/DashboardBuilder/useBuilderSession.d.ts +89 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +17 -55
- package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
- package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
- package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
- package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
- package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
- package/dist/components/DocumentCreate/events.d.ts +10 -0
- package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
- package/dist/components/DocumentCreate/guards.d.ts +12 -0
- package/dist/components/DocumentCreate/index.d.ts +6 -0
- package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
- package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
- package/dist/components/NarrowEditGate.d.ts +8 -0
- package/dist/components/Notebook/Notebook.d.ts +1 -1
- package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
- package/dist/components/Package/Package.d.ts +1 -0
- package/dist/components/Package/documentLocation.d.ts +28 -0
- package/dist/components/Package/index.d.ts +4 -0
- package/dist/components/Package/useDocumentLocation.d.ts +12 -0
- package/dist/components/PackageSection.d.ts +2 -2
- package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
- package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
- package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
- package/dist/components/ServerProvider.d.ts +2 -1
- package/dist/components/UnsavedChangesDialog.d.ts +9 -0
- package/dist/components/given/GivensPanel.d.ts +2 -2
- package/dist/components/index.d.ts +2 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useNarrowScreen.d.ts +4 -0
- package/dist/hooks/useQueryResult.d.ts +2 -0
- package/dist/hooks/useSettled.d.ts +14 -0
- package/dist/index.cjs.js +23 -24
- package/dist/index.es.js +9714 -7072
- package/dist/text/index.cjs.js +1 -0
- package/dist/text/index.d.ts +2 -0
- package/dist/text/index.es.js +6 -0
- package/dist/text-entry-BJwltZiy.cjs.js +7 -0
- package/dist/text-entry-CbbBcZl8.es.js +196 -0
- package/dist/text-entry.d.ts +2 -0
- package/dist/utils/clock.d.ts +2 -0
- package/package.json +10 -1
- package/src/builder-entry.ts +35 -0
- package/src/components/Dashboard/Dashboard.tsx +27 -278
- package/src/components/Dashboard/DashboardGrid.tsx +68 -7
- package/src/components/Dashboard/DashboardTile.spec.tsx +24 -0
- package/src/components/Dashboard/DashboardTile.tsx +31 -4
- package/src/components/Dashboard/DashboardView.spec.tsx +212 -0
- package/src/components/Dashboard/DashboardView.tsx +352 -0
- package/src/components/Dashboard/RowsDialog.tsx +1 -1
- package/src/components/Dashboard/TileCard.tsx +44 -10
- package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
- package/src/components/Dashboard/TileFilterTag.tsx +78 -0
- package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
- package/src/components/Dashboard/index.ts +3 -0
- package/src/components/Dashboard/telemetry.ts +16 -5
- package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +137 -111
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +85 -27
- package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
- package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
- package/src/components/DashboardBuilder/ChartPicker.tsx +153 -0
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +192 -0
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +329 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +363 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +194 -0
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +157 -0
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +124 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +103 -78
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +177 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +610 -315
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +58 -8
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +191 -0
- package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +316 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +56 -10
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +5 -22
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +96 -14
- package/src/components/DashboardBuilder/DashboardEditor.tsx +482 -332
- package/src/components/DashboardBuilder/DiffDialog.spec.tsx +25 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +5 -24
- package/src/components/DashboardBuilder/DrillDialog.tsx +1 -1
- package/src/components/DashboardBuilder/FilterDialog.tsx +10 -3
- package/src/components/DashboardBuilder/FilterStrip.tsx +26 -4
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +184 -0
- package/src/components/DashboardBuilder/InlineText.tsx +106 -0
- package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
- package/src/components/DashboardBuilder/SaveNotice.tsx +113 -0
- package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +87 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +225 -67
- package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
- package/src/components/DashboardBuilder/TextTileBody.tsx +28 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +89 -115
- package/src/components/DashboardBuilder/TileMenu.tsx +168 -90
- package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
- package/src/components/DashboardBuilder/annotationText.ts +17 -0
- package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
- package/src/components/DashboardBuilder/artifactTagParity.spec.ts +41 -0
- package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +2 -0
- package/src/components/DashboardBuilder/catalog.ts +61 -21
- package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
- package/src/components/DashboardBuilder/changedTile.ts +28 -0
- package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
- package/src/components/DashboardBuilder/chartLine.ts +121 -0
- package/src/components/DashboardBuilder/controls.spec.ts +21 -10
- package/src/components/DashboardBuilder/controls.ts +22 -8
- package/src/components/DashboardBuilder/document.ts +53 -5
- package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
- package/src/components/DashboardBuilder/documentSession.ts +257 -0
- package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
- package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
- package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
- package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
- package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
- package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
- package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
- package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +48 -0
- package/src/components/DashboardBuilder/malloyText.ts +181 -27
- package/src/components/DashboardBuilder/malloyTree.ts +155 -7
- package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
- package/src/components/DashboardBuilder/newDashboard.ts +30 -3
- package/src/components/DashboardBuilder/openDraft.ts +52 -0
- package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
- package/src/components/DashboardBuilder/preview.spec.ts +159 -12
- package/src/components/DashboardBuilder/preview.ts +83 -9
- package/src/components/DashboardBuilder/readDocument.spec.ts +139 -27
- package/src/components/DashboardBuilder/readDocument.ts +130 -44
- package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
- package/src/components/DashboardBuilder/readForEditor.ts +47 -0
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
- package/src/components/DashboardBuilder/sortable.spec.ts +65 -0
- package/src/components/DashboardBuilder/sortable.tsx +2 -12
- package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
- package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
- package/src/components/DashboardBuilder/spliceDocument.ts +762 -130
- package/src/components/DashboardBuilder/spliceResult.ts +15 -0
- package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
- package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
- package/src/components/DashboardBuilder/tagParse.ts +103 -0
- package/src/components/DashboardBuilder/telemetry.ts +47 -0
- package/src/components/DashboardBuilder/testing/artifactTagParity.json +197 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
- package/src/components/DashboardBuilder/testing/inline.ts +25 -0
- package/src/components/DashboardBuilder/textTiles.spec.ts +718 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +335 -0
- package/src/components/DashboardBuilder/useBuilderSession.ts +292 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +65 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +36 -10
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
- package/src/components/DashboardBuilder/useDashboardEditor.ts +54 -181
- package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
- package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
- package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
- package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
- package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
- package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
- package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
- package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
- package/src/components/DocumentCreate/canRetry.ts +19 -0
- package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
- package/src/components/DocumentCreate/createDocument.ts +159 -0
- package/src/components/DocumentCreate/documentPath.ts +40 -0
- package/src/components/DocumentCreate/events.ts +15 -0
- package/src/components/DocumentCreate/exportedSources.ts +25 -0
- package/src/components/DocumentCreate/guards.ts +45 -0
- package/src/components/DocumentCreate/index.ts +27 -0
- package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
- package/src/components/DocumentCreate/newNotebook.ts +44 -0
- package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
- package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
- package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
- package/src/components/Model/ModelExplorer.spec.tsx +2 -2
- package/src/components/Model/SourcesExplorer.tsx +2 -4
- package/src/components/NarrowEditGate.spec.tsx +73 -0
- package/src/components/NarrowEditGate.tsx +29 -0
- package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
- package/src/components/Notebook/Notebook.tsx +66 -27
- package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
- package/src/components/Package/NewDocumentDialog.tsx +401 -0
- package/src/components/Package/Package.artifacts.spec.tsx +190 -0
- package/src/components/Package/Package.create.spec.tsx +380 -0
- package/src/components/Package/Package.notebooks.spec.tsx +18 -0
- package/src/components/Package/Package.tsx +366 -171
- package/src/components/Package/documentLocation.spec.ts +81 -0
- package/src/components/Package/documentLocation.ts +55 -0
- package/src/components/Package/index.ts +13 -0
- package/src/components/Package/useDocumentLocation.ts +59 -0
- package/src/components/PackageSection.tsx +2 -2
- package/src/components/RenderedResult/RenderedResult.tsx +18 -1
- package/src/components/RenderedResult/ResultContainer.tsx +44 -11
- package/src/components/RenderedResult/ResultPanel.tsx +4 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
- package/src/components/RenderedResult/resultSizing.ts +14 -3
- package/src/components/ServerProvider.tsx +2 -1
- package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
- package/src/components/UnsavedChangesDialog.tsx +49 -0
- package/src/components/given/GivensPanel.spec.tsx +6 -6
- package/src/components/given/GivensPanel.tsx +3 -3
- package/src/components/index.ts +2 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useNarrowScreen.ts +21 -0
- package/src/hooks/useQueryResult.ts +16 -0
- package/src/hooks/useSettled.spec.ts +41 -0
- package/src/hooks/useSettled.ts +27 -0
- package/src/mainEntry.spec.ts +145 -0
- package/src/text-entry.ts +12 -0
- package/src/textEntry.spec.ts +118 -0
- package/src/utils/clock.spec.ts +12 -0
- package/src/utils/clock.ts +6 -0
- package/vite.config.ts +4 -0
- package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
- package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
- package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
- package/dist/components/DashboardBuilder/useTileResize.d.ts +0 -29
- package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +0 -121
- package/src/components/DashboardBuilder/useTileResize.ts +0 -110
- package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
- package/src/components/Package/NewDashboardDialog.tsx +0 -265
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { chartChoices } from "./ChartPicker";
|
|
6
|
+
|
|
7
|
+
const values = (...args: Parameters<typeof chartChoices>) =>
|
|
8
|
+
chartChoices(...args).map((choice) => choice.value);
|
|
9
|
+
const enabled = (...args: Parameters<typeof chartChoices>) =>
|
|
10
|
+
chartChoices(...args)
|
|
11
|
+
.filter((choice) => !choice.disabled)
|
|
12
|
+
.map((choice) => choice.value);
|
|
13
|
+
const choice = (
|
|
14
|
+
pick: string,
|
|
15
|
+
...args: Parameters<typeof chartChoices>
|
|
16
|
+
): ReturnType<typeof chartChoices>[number] =>
|
|
17
|
+
chartChoices(...args).find((c) => c.value === pick)!;
|
|
18
|
+
|
|
19
|
+
describe("chartChoices", () => {
|
|
20
|
+
it("lists every chart, never a sparkline, with the inapplicable ones disabled", () => {
|
|
21
|
+
expect(values(undefined, "default")).toEqual([
|
|
22
|
+
"default",
|
|
23
|
+
"none",
|
|
24
|
+
"line_chart",
|
|
25
|
+
"bar_chart",
|
|
26
|
+
"big_value",
|
|
27
|
+
"scatter_chart",
|
|
28
|
+
"shape_map",
|
|
29
|
+
"segment_map",
|
|
30
|
+
]);
|
|
31
|
+
expect(enabled(undefined, "default")).toEqual([
|
|
32
|
+
"default",
|
|
33
|
+
"none",
|
|
34
|
+
"line_chart",
|
|
35
|
+
"bar_chart",
|
|
36
|
+
"scatter_chart",
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("enables big_value only for an aggregate-only view, and says what it needs otherwise", () => {
|
|
41
|
+
expect(enabled({ aggregateOnly: true }, "default")).toContain(
|
|
42
|
+
"big_value",
|
|
43
|
+
);
|
|
44
|
+
expect(choice("big_value", {}, "default")).toMatchObject({
|
|
45
|
+
disabled: true,
|
|
46
|
+
reason: "Needs a view with only totals (no group by)",
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("enables a map only when the view carries that map tag, and says what it needs otherwise", () => {
|
|
51
|
+
expect(enabled({ chart: "shape_map" }, "default")).toContain("shape_map");
|
|
52
|
+
expect(enabled({ chart: "shape_map" }, "default")).not.toContain(
|
|
53
|
+
"segment_map",
|
|
54
|
+
);
|
|
55
|
+
expect(
|
|
56
|
+
choice("shape_map", { chart: "bar_chart" }, "default"),
|
|
57
|
+
).toMatchObject({
|
|
58
|
+
disabled: true,
|
|
59
|
+
reason: "Needs a view that already carries a map chart",
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("words the reason by why the view's shape is unknown", () => {
|
|
64
|
+
expect(choice("big_value", undefined, "default", "loading").reason).toBe(
|
|
65
|
+
"Still loading this view's details",
|
|
66
|
+
);
|
|
67
|
+
expect(choice("shape_map", undefined, "default", "unlisted").reason).toBe(
|
|
68
|
+
"Not a view the catalog lists, so its shape is unknown",
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("keeps what the cell has now selectable, even when it would not be offered", () => {
|
|
73
|
+
expect(enabled({}, "big_value")).toContain("big_value");
|
|
74
|
+
expect(enabled({}, "segment_map")).toContain("segment_map");
|
|
75
|
+
expect(values({}, "custom")).toContain("custom");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { ListItemText, MenuItem, TextField } from "@mui/material";
|
|
5
|
+
import { useId } from "react";
|
|
6
|
+
import type { CatalogView } from "./catalog";
|
|
7
|
+
import type { ChartPick, ChartState } from "./chartLine";
|
|
8
|
+
|
|
9
|
+
export interface ChartChoice {
|
|
10
|
+
value: ChartState;
|
|
11
|
+
label: string;
|
|
12
|
+
/** Listed but not pickable; `reason` says what the view would need. */
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
reason?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Why a view is absent, so the reason on a disabled choice says whether to wait or to pick another. */
|
|
18
|
+
export type ViewStatus = "loading" | "unlisted";
|
|
19
|
+
|
|
20
|
+
const LABELS: Record<ChartPick, string> = {
|
|
21
|
+
line_chart: "Line",
|
|
22
|
+
bar_chart: "Bar",
|
|
23
|
+
big_value: "Big value",
|
|
24
|
+
scatter_chart: "Scatter",
|
|
25
|
+
shape_map: "Shape map",
|
|
26
|
+
segment_map: "Segment map",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Every chart a cell can be set to; one the view cannot render is listed disabled with its reason, so it is discoverable rather than missing.
|
|
31
|
+
* Whatever the cell has now stays selectable, so the select never shows a value it does not offer.
|
|
32
|
+
*/
|
|
33
|
+
export function chartChoices(
|
|
34
|
+
view: Pick<CatalogView, "chart" | "aggregateOnly"> | undefined,
|
|
35
|
+
current: ChartState,
|
|
36
|
+
viewStatus?: ViewStatus,
|
|
37
|
+
): ChartChoice[] {
|
|
38
|
+
const unknown =
|
|
39
|
+
view !== undefined
|
|
40
|
+
? undefined
|
|
41
|
+
: viewStatus === "loading"
|
|
42
|
+
? "Still loading this view's details"
|
|
43
|
+
: viewStatus === "unlisted"
|
|
44
|
+
? "Not a view the catalog lists, so its shape is unknown"
|
|
45
|
+
: undefined;
|
|
46
|
+
const reasonFor = (pick: ChartPick): string | undefined => {
|
|
47
|
+
if (current === pick) return undefined;
|
|
48
|
+
if (pick === "big_value")
|
|
49
|
+
return view?.aggregateOnly === true
|
|
50
|
+
? undefined
|
|
51
|
+
: (unknown ?? "Needs a view with only totals (no group by)");
|
|
52
|
+
if (pick === "shape_map" || pick === "segment_map")
|
|
53
|
+
return view?.chart === pick
|
|
54
|
+
? undefined
|
|
55
|
+
: (unknown ?? "Needs a view that already carries a map chart");
|
|
56
|
+
return undefined;
|
|
57
|
+
};
|
|
58
|
+
const picks: ChartPick[] = [
|
|
59
|
+
"line_chart",
|
|
60
|
+
"bar_chart",
|
|
61
|
+
"big_value",
|
|
62
|
+
"scatter_chart",
|
|
63
|
+
"shape_map",
|
|
64
|
+
"segment_map",
|
|
65
|
+
];
|
|
66
|
+
return [
|
|
67
|
+
{ value: "default", label: "From the view" },
|
|
68
|
+
{ value: "none", label: "Table" },
|
|
69
|
+
...picks.map((pick): ChartChoice => {
|
|
70
|
+
const reason = reasonFor(pick);
|
|
71
|
+
return {
|
|
72
|
+
value: pick,
|
|
73
|
+
label: LABELS[pick],
|
|
74
|
+
...(reason ? { disabled: true, reason } : {}),
|
|
75
|
+
};
|
|
76
|
+
}),
|
|
77
|
+
...(current === "custom"
|
|
78
|
+
? [{ value: "custom" as const, label: "As written" }]
|
|
79
|
+
: []),
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function ChartPicker({
|
|
84
|
+
state,
|
|
85
|
+
view,
|
|
86
|
+
viewStatus,
|
|
87
|
+
cellLabel,
|
|
88
|
+
disabledReason,
|
|
89
|
+
onOpen,
|
|
90
|
+
onChange,
|
|
91
|
+
}: {
|
|
92
|
+
state: ChartState;
|
|
93
|
+
/** The catalog's view this cell runs, when it is one the catalog knows. */
|
|
94
|
+
view: Pick<CatalogView, "chart" | "aggregateOnly"> | undefined;
|
|
95
|
+
/** Why `view` is absent, worded into the reasons on the charts that need its shape. */
|
|
96
|
+
viewStatus?: ViewStatus;
|
|
97
|
+
/** Which cell this is, so the control is named apart from its neighbours. */
|
|
98
|
+
cellLabel: string;
|
|
99
|
+
disabledReason?: string;
|
|
100
|
+
/** The choices are being looked at, which is when a host may fetch what it needs to offer more. */
|
|
101
|
+
onOpen?: () => void;
|
|
102
|
+
onChange: (next: ChartState) => void;
|
|
103
|
+
}) {
|
|
104
|
+
const choices = chartChoices(view, state, viewStatus);
|
|
105
|
+
const reasonId = useId();
|
|
106
|
+
return (
|
|
107
|
+
<TextField
|
|
108
|
+
select
|
|
109
|
+
size="small"
|
|
110
|
+
variant="standard"
|
|
111
|
+
label="Viz type"
|
|
112
|
+
value={state}
|
|
113
|
+
disabled={disabledReason !== undefined}
|
|
114
|
+
onChange={(event) => {
|
|
115
|
+
const next = event.target.value as ChartState;
|
|
116
|
+
// A disabled item still receives a click from a focusable-disabled menu.
|
|
117
|
+
if (!choices.find((choice) => choice.value === next)?.disabled)
|
|
118
|
+
onChange(next);
|
|
119
|
+
}}
|
|
120
|
+
// On screen and described-by, not only in a tooltip that a keyboard or screen reader never reaches.
|
|
121
|
+
helperText={disabledReason}
|
|
122
|
+
FormHelperTextProps={{ id: reasonId }}
|
|
123
|
+
SelectProps={{
|
|
124
|
+
...(onOpen ? { onOpen } : {}),
|
|
125
|
+
// The menu items carry a reason line; the closed field shows the label alone.
|
|
126
|
+
renderValue: (value) =>
|
|
127
|
+
choices.find((choice) => choice.value === value)?.label ??
|
|
128
|
+
String(value),
|
|
129
|
+
// A disabled choice stays focusable so a keyboard user reaches its reason.
|
|
130
|
+
MenuProps: { MenuListProps: { disabledItemsFocusable: true } },
|
|
131
|
+
SelectDisplayProps: {
|
|
132
|
+
"aria-label": `Viz type, ${cellLabel}`,
|
|
133
|
+
"aria-labelledby": undefined,
|
|
134
|
+
...(disabledReason ? { "aria-describedby": reasonId } : {}),
|
|
135
|
+
},
|
|
136
|
+
}}
|
|
137
|
+
sx={{ minWidth: 140 }}
|
|
138
|
+
>
|
|
139
|
+
{choices.map((choice) => (
|
|
140
|
+
<MenuItem
|
|
141
|
+
key={choice.value}
|
|
142
|
+
value={choice.value}
|
|
143
|
+
disabled={choice.value === "custom" || choice.disabled === true}
|
|
144
|
+
>
|
|
145
|
+
<ListItemText
|
|
146
|
+
primary={choice.label}
|
|
147
|
+
{...(choice.reason ? { secondary: choice.reason } : {})}
|
|
148
|
+
/>
|
|
149
|
+
</MenuItem>
|
|
150
|
+
))}
|
|
151
|
+
</TextField>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
fireEvent,
|
|
6
|
+
render,
|
|
7
|
+
screen,
|
|
8
|
+
waitFor,
|
|
9
|
+
within,
|
|
10
|
+
} from "@testing-library/react";
|
|
11
|
+
import { describe, expect, it } from "bun:test";
|
|
12
|
+
import { chartLineText } from "./chartLine";
|
|
13
|
+
import { DashboardBuilder } from "./DashboardBuilder";
|
|
14
|
+
import { openDocument } from "./testing/fixtures";
|
|
15
|
+
import { closeMenu, editInline } from "./testing/inline";
|
|
16
|
+
|
|
17
|
+
const SOURCE = `## artifact { title="Storefront" tiles=["a -> by_cat", "a -> by_brand"] } dashboard { columns=12 }
|
|
18
|
+
import { scoped_orders } from "../data_app.malloy"
|
|
19
|
+
|
|
20
|
+
source: a is scoped_orders extend {
|
|
21
|
+
# colspan=6
|
|
22
|
+
view: by_cat is by_category
|
|
23
|
+
|
|
24
|
+
# colspan=6
|
|
25
|
+
# bar_chart { size=spark }
|
|
26
|
+
view: by_brand is by_brand_view
|
|
27
|
+
}`;
|
|
28
|
+
|
|
29
|
+
const catalog = {
|
|
30
|
+
sources: [
|
|
31
|
+
{
|
|
32
|
+
name: "scoped_orders",
|
|
33
|
+
modelPath: "data_app.malloy",
|
|
34
|
+
views: [
|
|
35
|
+
{ name: "by_category", chart: "shape_map" },
|
|
36
|
+
{ name: "by_brand_view" },
|
|
37
|
+
{ name: "kpis", aggregateOnly: true },
|
|
38
|
+
{ name: "table_view" },
|
|
39
|
+
{ name: "odd view" },
|
|
40
|
+
],
|
|
41
|
+
givens: [],
|
|
42
|
+
fields: [],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const mount = async (onSave?: (source: string) => void) => {
|
|
48
|
+
const document = await openDocument(SOURCE);
|
|
49
|
+
return render(
|
|
50
|
+
<DashboardBuilder
|
|
51
|
+
source={SOURCE}
|
|
52
|
+
document={document}
|
|
53
|
+
catalog={catalog}
|
|
54
|
+
{...(onSave ? { onSave } : {})}
|
|
55
|
+
/>,
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const chartPicker = (name: string) =>
|
|
60
|
+
screen.getByRole("combobox", { name: `Viz type, ${name}`, hidden: true });
|
|
61
|
+
const optionsOf = (name: string) => {
|
|
62
|
+
fireEvent.mouseDown(chartPicker(name));
|
|
63
|
+
const menu = screen.getAllByRole("listbox", { hidden: true }).at(-1)!;
|
|
64
|
+
return within(menu).getAllByRole("option", { hidden: true });
|
|
65
|
+
};
|
|
66
|
+
const enabledNames = (name: string) =>
|
|
67
|
+
optionsOf(name)
|
|
68
|
+
.filter((o) => o.getAttribute("aria-disabled") !== "true")
|
|
69
|
+
.map((o) => o.textContent);
|
|
70
|
+
const choose = (name: string, option: string) =>
|
|
71
|
+
fireEvent.click(
|
|
72
|
+
optionsOf(name).find((o) => o.textContent === option) as HTMLElement,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
describe("DashboardBuilder: charts", () => {
|
|
76
|
+
it("sets a tile's chart from its menu and writes the one line", async () => {
|
|
77
|
+
let written: string | undefined;
|
|
78
|
+
await mount((source) => {
|
|
79
|
+
written = source;
|
|
80
|
+
});
|
|
81
|
+
fireEvent.click(screen.getByLabelText("Settings for by_cat"));
|
|
82
|
+
const names = enabledNames("a by_cat");
|
|
83
|
+
// The wrapper's view `by_category` carries a shape map, so it is enabled; the rest are listed disabled.
|
|
84
|
+
expect(names).toEqual([
|
|
85
|
+
"From the view",
|
|
86
|
+
"Table",
|
|
87
|
+
"Line",
|
|
88
|
+
"Bar",
|
|
89
|
+
"Scatter",
|
|
90
|
+
"Shape map",
|
|
91
|
+
]);
|
|
92
|
+
choose("a by_cat", "Line");
|
|
93
|
+
closeMenu();
|
|
94
|
+
fireEvent.click(
|
|
95
|
+
screen.getByRole("button", { name: "Save changes", hidden: true }),
|
|
96
|
+
);
|
|
97
|
+
await waitFor(() => expect(written).toBeDefined());
|
|
98
|
+
expect(written).toContain(
|
|
99
|
+
` ${chartLineText("line_chart", ["shape_map"])}\n view: by_cat is by_category`,
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("treats picking a chart and then Default as no edit on a tile with no chart line", async () => {
|
|
104
|
+
let written: string | undefined;
|
|
105
|
+
await mount((source) => {
|
|
106
|
+
written = source;
|
|
107
|
+
});
|
|
108
|
+
fireEvent.click(screen.getByLabelText("Settings for by_cat"));
|
|
109
|
+
choose("a by_cat", "Bar");
|
|
110
|
+
choose("a by_cat", "From the view");
|
|
111
|
+
closeMenu();
|
|
112
|
+
const save = screen.queryByRole("button", {
|
|
113
|
+
name: "Save changes",
|
|
114
|
+
hidden: true,
|
|
115
|
+
});
|
|
116
|
+
expect(save === null || (save as HTMLButtonElement).disabled).toBe(true);
|
|
117
|
+
expect(written).toBeUndefined();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("shows a line the builder does not model as locked, and keeps it", async () => {
|
|
121
|
+
let written: string | undefined;
|
|
122
|
+
await mount((source) => {
|
|
123
|
+
written = source;
|
|
124
|
+
});
|
|
125
|
+
fireEvent.click(screen.getByLabelText("Settings for by_brand"));
|
|
126
|
+
expect(
|
|
127
|
+
screen
|
|
128
|
+
.getByRole("combobox", {
|
|
129
|
+
name: "Viz type, a by_brand",
|
|
130
|
+
hidden: true,
|
|
131
|
+
})
|
|
132
|
+
.getAttribute("aria-disabled"),
|
|
133
|
+
).toBe("true");
|
|
134
|
+
expect(screen.getByText(/is not one the builder models/)).toBeDefined();
|
|
135
|
+
closeMenu();
|
|
136
|
+
editInline("by_brand", "Tile title", "Brands");
|
|
137
|
+
fireEvent.click(
|
|
138
|
+
screen.getByRole("button", { name: "Save changes", hidden: true }),
|
|
139
|
+
);
|
|
140
|
+
await waitFor(() => expect(written).toBeDefined());
|
|
141
|
+
expect(written).toContain(" # bar_chart { size=spark }\n");
|
|
142
|
+
expect(written).toContain('# label="Brands"');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("disables the picker on a tile the model owns, with the reason", async () => {
|
|
146
|
+
const source = `## artifact { title="T" tiles=["orders -> by_brand"] }\nimport { orders } from '../orders.malloy'`;
|
|
147
|
+
const document = await openDocument(source);
|
|
148
|
+
render(<DashboardBuilder source={source} document={document} />);
|
|
149
|
+
fireEvent.click(screen.getByLabelText("Settings for by_brand"));
|
|
150
|
+
expect(
|
|
151
|
+
screen
|
|
152
|
+
.getByRole("combobox", {
|
|
153
|
+
name: "Viz type, orders by_brand",
|
|
154
|
+
hidden: true,
|
|
155
|
+
})
|
|
156
|
+
.getAttribute("aria-disabled"),
|
|
157
|
+
).toBe("true");
|
|
158
|
+
expect(
|
|
159
|
+
screen.getByText(/so its chart is set in the model/),
|
|
160
|
+
).toBeDefined();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("adds a tile with a chart, offering big value only for an aggregate-only view", async () => {
|
|
164
|
+
let written: string | undefined;
|
|
165
|
+
await mount((source) => {
|
|
166
|
+
written = source;
|
|
167
|
+
});
|
|
168
|
+
fireEvent.click(
|
|
169
|
+
screen.getByRole("button", { name: "Add tile", hidden: true }),
|
|
170
|
+
);
|
|
171
|
+
fireEvent.click(screen.getByLabelText("View table_view"));
|
|
172
|
+
expect(enabledNames("new tile")).not.toContain("Big value");
|
|
173
|
+
fireEvent.click(
|
|
174
|
+
within(
|
|
175
|
+
screen.getAllByRole("listbox", { hidden: true }).at(-1)!,
|
|
176
|
+
).getByRole("option", { name: "From the view", hidden: true }),
|
|
177
|
+
);
|
|
178
|
+
fireEvent.click(screen.getByLabelText("View kpis"));
|
|
179
|
+
expect(enabledNames("new tile")).toContain("Big value");
|
|
180
|
+
choose("new tile", "Big value");
|
|
181
|
+
fireEvent.click(screen.getByRole("button", { name: "Add tile" }));
|
|
182
|
+
fireEvent.click(
|
|
183
|
+
screen.getByRole("button", { name: "Save changes", hidden: true }),
|
|
184
|
+
);
|
|
185
|
+
await waitFor(() => expect(written).toBeDefined());
|
|
186
|
+
expect(written).toContain(
|
|
187
|
+
` ${chartLineText("big_value", [])}\n view: kpis_tile is kpis`,
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("says why a view the writer cannot name is not addable", async () => {
|
|
192
|
+
await mount();
|
|
193
|
+
fireEvent.click(
|
|
194
|
+
screen.getByRole("button", { name: "Add tile", hidden: true }),
|
|
195
|
+
);
|
|
196
|
+
fireEvent.click(screen.getByLabelText("View odd view"));
|
|
197
|
+
expect(
|
|
198
|
+
screen.getByText(/"odd view" is not a plain Malloy name/),
|
|
199
|
+
).toBeDefined();
|
|
200
|
+
expect(
|
|
201
|
+
(screen.getByRole("button", { name: "Add tile" }) as HTMLButtonElement)
|
|
202
|
+
.disabled,
|
|
203
|
+
).toBe(true);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
act,
|
|
6
|
+
cleanup,
|
|
7
|
+
fireEvent,
|
|
8
|
+
render,
|
|
9
|
+
screen,
|
|
10
|
+
waitFor,
|
|
11
|
+
} from "@testing-library/react";
|
|
12
|
+
import { afterEach, describe, expect, it, mock } from "bun:test";
|
|
13
|
+
import { DashboardBuilder } from "./DashboardBuilder";
|
|
14
|
+
import { openDocument } from "./testing/fixtures";
|
|
15
|
+
import { editInline } from "./testing/inline";
|
|
16
|
+
|
|
17
|
+
const SOURCE = `## artifact { title="Storefront" tiles=["a -> by_cat", "a -> by_brand"] } dashboard { columns=12 }
|
|
18
|
+
import "../data_app.malloy"
|
|
19
|
+
|
|
20
|
+
source: a is scoped_orders extend {
|
|
21
|
+
# colspan=6
|
|
22
|
+
# label="By category"
|
|
23
|
+
view: by_cat is by_category
|
|
24
|
+
|
|
25
|
+
# colspan=6
|
|
26
|
+
view: by_brand is by_brand_view
|
|
27
|
+
}`;
|
|
28
|
+
|
|
29
|
+
const mount = async (
|
|
30
|
+
options: {
|
|
31
|
+
onExit?: () => void;
|
|
32
|
+
onSave?: (source: string) => Promise<void> | void;
|
|
33
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
34
|
+
} = {},
|
|
35
|
+
) => {
|
|
36
|
+
const document = await openDocument(SOURCE);
|
|
37
|
+
return render(
|
|
38
|
+
<DashboardBuilder
|
|
39
|
+
source={SOURCE}
|
|
40
|
+
document={document}
|
|
41
|
+
{...(options.onExit ? { onExit: options.onExit } : {})}
|
|
42
|
+
{...(options.onSave ? { onSave: options.onSave } : {})}
|
|
43
|
+
{...(options.onDirtyChange
|
|
44
|
+
? { onDirtyChange: options.onDirtyChange }
|
|
45
|
+
: {})}
|
|
46
|
+
/>,
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const button = (name: string) =>
|
|
51
|
+
screen.getByRole("button", { name, hidden: true });
|
|
52
|
+
|
|
53
|
+
const retitle = () => {
|
|
54
|
+
editInline("By category", "Tile title", "Renamed");
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const shortcut = (key: string) =>
|
|
58
|
+
fireEvent.keyDown(window, { key, ctrlKey: true, metaKey: true });
|
|
59
|
+
|
|
60
|
+
const dialogs = () => screen.getAllByRole("dialog", { hidden: true });
|
|
61
|
+
|
|
62
|
+
const settleTick = () => act(async () => {});
|
|
63
|
+
|
|
64
|
+
afterEach(cleanup);
|
|
65
|
+
|
|
66
|
+
describe("DashboardBuilder: leaving", () => {
|
|
67
|
+
it("renders no Close without an onExit", async () => {
|
|
68
|
+
await mount();
|
|
69
|
+
expect(screen.queryByRole("button", { name: "Close" })).toBeNull();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("exits at once when nothing is unsaved", async () => {
|
|
73
|
+
const onExit = mock(() => {});
|
|
74
|
+
await mount({ onExit });
|
|
75
|
+
fireEvent.click(button("Close"));
|
|
76
|
+
expect(onExit).toHaveBeenCalledTimes(1);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("asks first when there are edits, and Keep editing stays", async () => {
|
|
80
|
+
const onExit = mock(() => {});
|
|
81
|
+
await mount({ onExit, onSave: async () => {} });
|
|
82
|
+
retitle();
|
|
83
|
+
fireEvent.click(button("Close"));
|
|
84
|
+
expect(screen.getByRole("dialog")).toBeDefined();
|
|
85
|
+
fireEvent.click(button("Keep editing"));
|
|
86
|
+
expect(onExit).not.toHaveBeenCalled();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("Discard changes exits without saving", async () => {
|
|
90
|
+
const onExit = mock(() => {});
|
|
91
|
+
const onSave = mock(async () => {});
|
|
92
|
+
await mount({ onExit, onSave });
|
|
93
|
+
retitle();
|
|
94
|
+
fireEvent.click(button("Close"));
|
|
95
|
+
fireEvent.click(button("Discard changes"));
|
|
96
|
+
expect(onExit).toHaveBeenCalledTimes(1);
|
|
97
|
+
expect(onSave).not.toHaveBeenCalled();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("Save and exit saves, then exits", async () => {
|
|
101
|
+
const onExit = mock(() => {});
|
|
102
|
+
const onSave = mock(async () => {});
|
|
103
|
+
await mount({ onExit, onSave });
|
|
104
|
+
retitle();
|
|
105
|
+
fireEvent.click(button("Close"));
|
|
106
|
+
fireEvent.click(button("Save and exit"));
|
|
107
|
+
await waitFor(() => expect(onExit).toHaveBeenCalledTimes(1));
|
|
108
|
+
expect(onSave).toHaveBeenCalledTimes(1);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("stays open when the save fails", async () => {
|
|
112
|
+
const onExit = mock(() => {});
|
|
113
|
+
const onSave = mock(async () => {
|
|
114
|
+
throw new Error("nope");
|
|
115
|
+
});
|
|
116
|
+
await mount({ onExit, onSave });
|
|
117
|
+
retitle();
|
|
118
|
+
fireEvent.click(button("Close"));
|
|
119
|
+
fireEvent.click(button("Save and exit"));
|
|
120
|
+
await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
|
|
121
|
+
await screen.findByText(/nope/);
|
|
122
|
+
expect(onExit).not.toHaveBeenCalled();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("offers no Save and exit when the builder cannot save", async () => {
|
|
126
|
+
await mount({ onExit: () => {} });
|
|
127
|
+
retitle();
|
|
128
|
+
fireEvent.click(button("Close"));
|
|
129
|
+
expect(
|
|
130
|
+
screen.queryByRole("button", { name: "Save and exit" }),
|
|
131
|
+
).toBeNull();
|
|
132
|
+
expect(button("Discard changes")).toBeDefined();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("reports clean when it unmounts dirty", async () => {
|
|
136
|
+
const onDirtyChange = mock((_dirty: boolean) => {});
|
|
137
|
+
const view = await mount({ onDirtyChange, onSave: async () => {} });
|
|
138
|
+
retitle();
|
|
139
|
+
expect(onDirtyChange.mock.calls.at(-1)?.[0]).toBe(true);
|
|
140
|
+
view.unmount();
|
|
141
|
+
expect(onDirtyChange.mock.calls.at(-1)?.[0]).toBe(false);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const removeTile = () => {
|
|
146
|
+
fireEvent.click(screen.getByLabelText("Settings for By category"));
|
|
147
|
+
fireEvent.click(screen.getByRole("button", { name: "Remove tile" }));
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
describe("DashboardBuilder: leaving with a structural edit", () => {
|
|
151
|
+
it("ignores save, undo and redo shortcuts while the exit dialog is open", async () => {
|
|
152
|
+
const onSave = mock(async () => {});
|
|
153
|
+
await mount({ onExit: () => {}, onSave });
|
|
154
|
+
removeTile();
|
|
155
|
+
fireEvent.click(button("Close"));
|
|
156
|
+
shortcut("s");
|
|
157
|
+
shortcut("z");
|
|
158
|
+
await settleTick();
|
|
159
|
+
expect(dialogs()).toHaveLength(1);
|
|
160
|
+
expect(onSave).not.toHaveBeenCalled();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("Save and exit writes a structural edit at once, saving once and exiting once", async () => {
|
|
164
|
+
const onExit = mock(() => {});
|
|
165
|
+
const onSave = mock(async () => {});
|
|
166
|
+
await mount({ onExit, onSave });
|
|
167
|
+
removeTile();
|
|
168
|
+
fireEvent.click(button("Close"));
|
|
169
|
+
fireEvent.click(button("Save and exit"));
|
|
170
|
+
await waitFor(() => expect(onExit).toHaveBeenCalledTimes(1));
|
|
171
|
+
expect(onSave).toHaveBeenCalledTimes(1);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("waits out a save already in flight, then exits without saving twice", async () => {
|
|
175
|
+
const onExit = mock(() => {});
|
|
176
|
+
let finish = () => {};
|
|
177
|
+
const onSave = mock(
|
|
178
|
+
() => new Promise<void>((resolve) => (finish = resolve)),
|
|
179
|
+
);
|
|
180
|
+
await mount({ onExit, onSave });
|
|
181
|
+
retitle();
|
|
182
|
+
fireEvent.click(button("Save changes"));
|
|
183
|
+
await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
|
|
184
|
+
fireEvent.click(button("Close"));
|
|
185
|
+
fireEvent.click(button("Save and exit"));
|
|
186
|
+
await settleTick();
|
|
187
|
+
expect(onExit).not.toHaveBeenCalled();
|
|
188
|
+
await act(async () => finish());
|
|
189
|
+
await waitFor(() => expect(onExit).toHaveBeenCalledTimes(1));
|
|
190
|
+
expect(onSave).toHaveBeenCalledTimes(1);
|
|
191
|
+
});
|
|
192
|
+
});
|