@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
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { describe, expect, it } from "bun:test";
|
|
5
5
|
import * as fs from "fs";
|
|
6
6
|
import * as path from "path";
|
|
7
|
-
import type
|
|
7
|
+
import { isQueryTile, tileKey, type DashboardDocument } from "./document";
|
|
8
8
|
import { readDashboardDocument, readFailed } from "./readDocument";
|
|
9
9
|
import {
|
|
10
10
|
spliceDashboardDocument,
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import { openDocument, refused, splice, spliced } from "./testing/fixtures";
|
|
15
15
|
import { whatMoved } from "./__test__/inventory";
|
|
16
16
|
import { lintNotebookText } from "../../../../server/src/service/notebook_lint";
|
|
17
|
+
import { queryTile } from "./testing/fixtures";
|
|
17
18
|
|
|
18
19
|
const REPO = path.resolve(import.meta.dir, "../../../../..");
|
|
19
20
|
|
|
@@ -61,8 +62,8 @@ describe("spliceDashboardDocument: what it preserves", () => {
|
|
|
61
62
|
' # label="By category"\n # big_value\n # currency\n',
|
|
62
63
|
);
|
|
63
64
|
const out = await spliced(source, (d) => {
|
|
64
|
-
d
|
|
65
|
-
d
|
|
65
|
+
queryTile(d, 0).label = "Categories";
|
|
66
|
+
queryTile(d, 0).filters = [{ field: "cat", given: "CATEGORY" }];
|
|
66
67
|
});
|
|
67
68
|
expect(out).toContain(
|
|
68
69
|
' # label="Categories"\n # big_value\n # currency\n',
|
|
@@ -75,7 +76,7 @@ describe("spliceDashboardDocument: what it preserves", () => {
|
|
|
75
76
|
// Byte-minimal: one property changed, one line different.
|
|
76
77
|
it("changes only the line it had to", async () => {
|
|
77
78
|
const out = await spliced(SOURCE, (d) => {
|
|
78
|
-
d
|
|
79
|
+
queryTile(d, 0).label = "Categories";
|
|
79
80
|
});
|
|
80
81
|
const before = SOURCE.split("\n");
|
|
81
82
|
const after = out.split("\n");
|
|
@@ -109,12 +110,25 @@ source: a is scoped_orders extend {
|
|
|
109
110
|
it("writes both when the tile had no tags at all", async () => {
|
|
110
111
|
const out = await spliced(UNTAGGED, (d) => {
|
|
111
112
|
d.tiles[0].colspan = 4;
|
|
112
|
-
d
|
|
113
|
+
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
113
114
|
});
|
|
114
115
|
expect(out).toContain(
|
|
115
116
|
" # colspan=4\n view: by_cat is by_category + { where: category ~ $CATEGORY }",
|
|
116
117
|
);
|
|
117
118
|
});
|
|
119
|
+
|
|
120
|
+
it("back-quotes a reserved filter field, and refuses a reserved new given name", async () => {
|
|
121
|
+
const out = await spliced(UNTAGGED, (d) => {
|
|
122
|
+
queryTile(d, 0).filters = [{ field: "date", given: "WHEN_" }];
|
|
123
|
+
});
|
|
124
|
+
expect(out).toContain("+ { where: `date` ~ $WHEN_ }");
|
|
125
|
+
const reason = await refused(UNTAGGED, (d) => {
|
|
126
|
+
d.localGivens = [
|
|
127
|
+
{ name: "DATE", type: "filter<string>", default: "f''" },
|
|
128
|
+
];
|
|
129
|
+
});
|
|
130
|
+
expect(reason).toContain("cannot be written as a Malloy name");
|
|
131
|
+
});
|
|
118
132
|
});
|
|
119
133
|
|
|
120
134
|
/**
|
|
@@ -138,7 +152,7 @@ ${declaration}
|
|
|
138
152
|
}`;
|
|
139
153
|
|
|
140
154
|
const bind = (d: DashboardDocument) => {
|
|
141
|
-
d
|
|
155
|
+
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
142
156
|
};
|
|
143
157
|
|
|
144
158
|
it("puts the binding before the comment, not inside it", async () => {
|
|
@@ -166,7 +180,7 @@ ${declaration}
|
|
|
166
180
|
" view: by_cat is by_category + { where: category ~ $CATEGORY } // the lead tile",
|
|
167
181
|
);
|
|
168
182
|
const out = await spliced(source, (d) => {
|
|
169
|
-
delete d
|
|
183
|
+
delete queryTile(d, 0).filters;
|
|
170
184
|
d.tiles[0].colspan = 4;
|
|
171
185
|
});
|
|
172
186
|
expect(out).toContain(" view: by_cat is by_category // the lead tile");
|
|
@@ -187,7 +201,7 @@ ${declaration}
|
|
|
187
201
|
describe("spliceDashboardDocument: what it writes", () => {
|
|
188
202
|
it("adds a tag that was not there", async () => {
|
|
189
203
|
const out = await spliced(SOURCE, (d) => {
|
|
190
|
-
d
|
|
204
|
+
queryTile(d, 1).label = "By brand";
|
|
191
205
|
});
|
|
192
206
|
expect(out).toContain(' # label="By brand"\n view: by_brand');
|
|
193
207
|
expect(await openDocument(out)).toMatchObject({
|
|
@@ -206,14 +220,16 @@ describe("spliceDashboardDocument: what it writes", () => {
|
|
|
206
220
|
// The filter binding lives in the declaration, as a refinement.
|
|
207
221
|
it("writes and clears a filter binding", async () => {
|
|
208
222
|
const bound = await spliced(SOURCE, (d) => {
|
|
209
|
-
d
|
|
223
|
+
queryTile(d, 0).filters = [
|
|
224
|
+
{ field: "products.brand", given: "BRAND" },
|
|
225
|
+
];
|
|
210
226
|
});
|
|
211
227
|
expect(bound).toContain(
|
|
212
228
|
"view: by_cat is by_category + { where: products.brand ~ $BRAND }",
|
|
213
229
|
);
|
|
214
230
|
|
|
215
231
|
const cleared = await spliced(bound, (d) => {
|
|
216
|
-
delete d
|
|
232
|
+
delete queryTile(d, 0).filters;
|
|
217
233
|
});
|
|
218
234
|
expect(cleared).toContain("view: by_cat is by_category\n");
|
|
219
235
|
expect(cleared).not.toContain("where:");
|
|
@@ -275,14 +291,14 @@ describe("spliceDashboardDocument: reordering", () => {
|
|
|
275
291
|
const r = await splice(SOURCE, (d) => {
|
|
276
292
|
d.tiles.reverse();
|
|
277
293
|
// Matched by identity, not position: this is the tile now FIRST.
|
|
278
|
-
d
|
|
294
|
+
queryTile(d, 0).label = "Brands";
|
|
279
295
|
});
|
|
280
296
|
expect(r.ok).toBe(true);
|
|
281
297
|
if (!spliceFailed(r)) {
|
|
282
298
|
const back = await openDocument(r.source);
|
|
283
299
|
expect(back.tiles.map((t) => t.name)).toEqual(["by_brand", "by_cat"]);
|
|
284
|
-
expect(back
|
|
285
|
-
expect(back
|
|
300
|
+
expect(queryTile(back, 0).label).toBe("Brands");
|
|
301
|
+
expect(queryTile(back, 1).label).toBe("By category");
|
|
286
302
|
}
|
|
287
303
|
});
|
|
288
304
|
});
|
|
@@ -290,7 +306,7 @@ describe("spliceDashboardDocument: reordering", () => {
|
|
|
290
306
|
describe("spliceDashboardDocument: bindings", () => {
|
|
291
307
|
it("writes a binding with the comparison it was given", async () => {
|
|
292
308
|
const out = await spliced(SOURCE, (d) => {
|
|
293
|
-
d
|
|
309
|
+
queryTile(d, 0).filters = [
|
|
294
310
|
{ field: "created_at", given: "SINCE", op: ">=" },
|
|
295
311
|
];
|
|
296
312
|
});
|
|
@@ -307,7 +323,7 @@ describe("spliceDashboardDocument: bindings", () => {
|
|
|
307
323
|
"view: by_cat is by_category + { limit: 5 where: category ~ $CATEGORY }",
|
|
308
324
|
);
|
|
309
325
|
const out = await spliced(source, (d) => {
|
|
310
|
-
d
|
|
326
|
+
queryTile(d, 0).filters = [
|
|
311
327
|
{ field: "category", given: "CATEGORY" },
|
|
312
328
|
{ field: "brand", given: "BRAND" },
|
|
313
329
|
];
|
|
@@ -317,7 +333,7 @@ describe("spliceDashboardDocument: bindings", () => {
|
|
|
317
333
|
);
|
|
318
334
|
// And clearing the bindings leaves the clause that was never ours.
|
|
319
335
|
const cleared = await spliced(source, (d) => {
|
|
320
|
-
delete d
|
|
336
|
+
delete queryTile(d, 0).filters;
|
|
321
337
|
});
|
|
322
338
|
expect(cleared).toContain("view: by_cat is by_category + { limit: 5 }");
|
|
323
339
|
});
|
|
@@ -344,7 +360,7 @@ source: a is one extend {
|
|
|
344
360
|
|
|
345
361
|
it("adds a binding as a new depth-1 where: line before the closing brace", async () => {
|
|
346
362
|
const out = await spliced(MULTILINE, (d) => {
|
|
347
|
-
d
|
|
363
|
+
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
348
364
|
});
|
|
349
365
|
expect(out).toContain(
|
|
350
366
|
" view: kpis is {\n group_by: category\n aggregate: n is count()\n where: category ~ $CATEGORY\n }",
|
|
@@ -357,7 +373,7 @@ source: a is one extend {
|
|
|
357
373
|
"view: kpis is {\n where: category ~ $CATEGORY\n group_by: category",
|
|
358
374
|
);
|
|
359
375
|
const out = await spliced(source, (d) => {
|
|
360
|
-
d
|
|
376
|
+
queryTile(d, 0).filters = [{ field: "brand_name", given: "CATEGORY" }];
|
|
361
377
|
});
|
|
362
378
|
expect(out).toContain(
|
|
363
379
|
" view: kpis is {\n where: brand_name ~ $CATEGORY\n group_by: category",
|
|
@@ -372,7 +388,7 @@ source: a is one extend {
|
|
|
372
388
|
"view: kpis is {\n where: category ~ $CATEGORY\n group_by: category",
|
|
373
389
|
);
|
|
374
390
|
const out = await spliced(source, (d) => {
|
|
375
|
-
delete d
|
|
391
|
+
delete queryTile(d, 0).filters;
|
|
376
392
|
});
|
|
377
393
|
expect(out).toContain(MULTILINE);
|
|
378
394
|
expect(out).not.toContain("where:");
|
|
@@ -396,7 +412,7 @@ source: a is one extend {
|
|
|
396
412
|
}
|
|
397
413
|
}`;
|
|
398
414
|
const out = await spliced(source, (d) => {
|
|
399
|
-
d
|
|
415
|
+
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
400
416
|
});
|
|
401
417
|
expect(out).toContain("where: mth ~ $MONTH");
|
|
402
418
|
expect(out).toContain(
|
|
@@ -418,7 +434,7 @@ source: a is one extend {
|
|
|
418
434
|
}
|
|
419
435
|
}`;
|
|
420
436
|
const out = await spliced(source, (d) => {
|
|
421
|
-
d
|
|
437
|
+
queryTile(d, 0).filters = [{ field: "region", given: "REGION" }];
|
|
422
438
|
});
|
|
423
439
|
expect(out).toContain("where: category ~ $CATEGORY and status = 'open'");
|
|
424
440
|
expect(out).toContain(
|
|
@@ -454,7 +470,7 @@ source: a is one extend {
|
|
|
454
470
|
// in any of those spans. What used to need a refusal is now just an edit.
|
|
455
471
|
it("drops one binding and leaves the measure between them", async () => {
|
|
456
472
|
const out = await spliced(TWO_BINDINGS_ONE_STATEMENT, (d) => {
|
|
457
|
-
d
|
|
473
|
+
queryTile(d, 0).filters = [{ field: "a", given: "A" }];
|
|
458
474
|
});
|
|
459
475
|
expect(out).toContain(" where: a ~ $A, aggregate: n is count()");
|
|
460
476
|
expect(out).not.toContain("$B");
|
|
@@ -462,7 +478,7 @@ source: a is one extend {
|
|
|
462
478
|
|
|
463
479
|
it("rewrites each binding in place, measure untouched", async () => {
|
|
464
480
|
const out = await spliced(TWO_BINDINGS_ONE_STATEMENT, (d) => {
|
|
465
|
-
d
|
|
481
|
+
queryTile(d, 0).filters = [
|
|
466
482
|
{ field: "a2", given: "A" },
|
|
467
483
|
{ field: "b", given: "B" },
|
|
468
484
|
];
|
|
@@ -494,9 +510,11 @@ source: a is one extend {
|
|
|
494
510
|
view: kpis is { where: c ~ $C, aggregate: n is count() }
|
|
495
511
|
}`;
|
|
496
512
|
const before = await openDocument(oneLiner);
|
|
497
|
-
expect(before
|
|
513
|
+
expect(queryTile(before, 0).filters).toEqual([
|
|
514
|
+
{ field: "c", given: "C" },
|
|
515
|
+
]);
|
|
498
516
|
const out = await spliced(oneLiner, (d) => {
|
|
499
|
-
d
|
|
517
|
+
queryTile(d, 0).filters = [{ field: "c", given: "C2" }];
|
|
500
518
|
});
|
|
501
519
|
expect(out).toContain(
|
|
502
520
|
"view: kpis is { aggregate: n is count() where: c ~ $C2 }",
|
|
@@ -511,14 +529,14 @@ source: a is one extend {
|
|
|
511
529
|
view: kpis is { aggregate: n is count() }
|
|
512
530
|
}`;
|
|
513
531
|
const out = await spliced(oneLiner, (d) => {
|
|
514
|
-
d
|
|
532
|
+
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
515
533
|
});
|
|
516
534
|
expect(out).toContain(
|
|
517
535
|
"view: kpis is { aggregate: n is count() where: category ~ $CATEGORY }",
|
|
518
536
|
);
|
|
519
537
|
// And unbinding restores the file exactly as it was.
|
|
520
538
|
const restored = await spliced(out, (d) => {
|
|
521
|
-
delete d
|
|
539
|
+
delete queryTile(d, 0).filters;
|
|
522
540
|
});
|
|
523
541
|
expect(restored).toBe(oneLiner);
|
|
524
542
|
});
|
|
@@ -540,7 +558,7 @@ source: a is one extend {
|
|
|
540
558
|
}
|
|
541
559
|
}`;
|
|
542
560
|
const out = await spliced(source, (d) => {
|
|
543
|
-
d
|
|
561
|
+
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
544
562
|
});
|
|
545
563
|
expect(out).toContain(
|
|
546
564
|
" aggregate: n is count()\n where: category ~ $CATEGORY\n } -> {",
|
|
@@ -557,7 +575,9 @@ source: a is one extend {
|
|
|
557
575
|
}`;
|
|
558
576
|
expect(
|
|
559
577
|
await refused(source, (d) => {
|
|
560
|
-
d
|
|
578
|
+
queryTile(d, 0).filters = [
|
|
579
|
+
{ field: "category", given: "CATEGORY" },
|
|
580
|
+
];
|
|
561
581
|
}),
|
|
562
582
|
).toContain("compound refinement");
|
|
563
583
|
});
|
|
@@ -575,7 +595,7 @@ source: a is one extend {
|
|
|
575
595
|
view: other is { aggregate: m is count() }
|
|
576
596
|
}`;
|
|
577
597
|
const out = await spliced(source, (d) => {
|
|
578
|
-
d
|
|
598
|
+
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
579
599
|
});
|
|
580
600
|
expect(out).toContain(" where: brand_name ~ $BRAND\n");
|
|
581
601
|
expect(out).toContain(
|
|
@@ -585,18 +605,18 @@ source: a is one extend {
|
|
|
585
605
|
|
|
586
606
|
it("round-trips: bind, read back, unbind, read back to the original bytes", async () => {
|
|
587
607
|
const bound = await spliced(MULTILINE, (d) => {
|
|
588
|
-
d
|
|
608
|
+
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
589
609
|
});
|
|
590
610
|
const reopened = await openDocument(bound);
|
|
591
|
-
expect(reopened
|
|
611
|
+
expect(queryTile(reopened, 0).filters).toEqual([
|
|
592
612
|
{ field: "category", given: "CATEGORY" },
|
|
593
613
|
]);
|
|
594
614
|
const unbound = await spliced(bound, (d) => {
|
|
595
|
-
delete d
|
|
615
|
+
delete queryTile(d, 0).filters;
|
|
596
616
|
});
|
|
597
617
|
expect(unbound).toBe(MULTILINE);
|
|
598
618
|
const reread = await openDocument(unbound);
|
|
599
|
-
expect(reread
|
|
619
|
+
expect(queryTile(reread, 0).filters).toBeUndefined();
|
|
600
620
|
});
|
|
601
621
|
|
|
602
622
|
// The end-to-end shape of the corruption a quoted literal's brace used to
|
|
@@ -620,7 +640,7 @@ source: a is scoped_orders extend {
|
|
|
620
640
|
view: other is { aggregate: m is count() }
|
|
621
641
|
}`;
|
|
622
642
|
const out = await spliced(source, (d) => {
|
|
623
|
-
d
|
|
643
|
+
queryTile(d, 0).filters = [{ field: "cat", given: "CATEGORY" }];
|
|
624
644
|
});
|
|
625
645
|
expect(out).toContain(
|
|
626
646
|
" view: kpis is {\n where: path ~ 'a{b'\n aggregate: n is count()\n where: cat ~ $CATEGORY\n }",
|
|
@@ -628,7 +648,7 @@ source: a is scoped_orders extend {
|
|
|
628
648
|
expect(out).toContain(" view: other is { aggregate: m is count() }\n}");
|
|
629
649
|
expect(out.match(/where: cat ~ \$CATEGORY/g)).toHaveLength(1);
|
|
630
650
|
const reopened = await openDocument(out);
|
|
631
|
-
expect(reopened
|
|
651
|
+
expect(queryTile(reopened, 0).filters).toEqual([
|
|
632
652
|
{ field: "cat", given: "CATEGORY" },
|
|
633
653
|
]);
|
|
634
654
|
});
|
|
@@ -649,7 +669,7 @@ source: a is scoped_orders extend {
|
|
|
649
669
|
view: other is { aggregate: m is count() }
|
|
650
670
|
}`;
|
|
651
671
|
const out = await spliced(source, (d) => {
|
|
652
|
-
d
|
|
672
|
+
queryTile(d, 0).filters = [{ field: "cat", given: "CATEGORY" }];
|
|
653
673
|
});
|
|
654
674
|
expect(out).toContain(
|
|
655
675
|
" view: kpis is {\n where: path ~ 'a}b'\n aggregate: n is count()\n where: cat ~ $CATEGORY\n }",
|
|
@@ -668,16 +688,16 @@ source: a is one extend {
|
|
|
668
688
|
view: kpis is { where: category ~ $CATEGORY, aggregate: n is count() }
|
|
669
689
|
}`;
|
|
670
690
|
const before = await openDocument(boundOneLiner);
|
|
671
|
-
expect(before
|
|
691
|
+
expect(queryTile(before, 0).filters).toEqual([
|
|
672
692
|
{ field: "category", given: "CATEGORY" },
|
|
673
693
|
]);
|
|
674
694
|
const rebound = await spliced(boundOneLiner, (d) => {
|
|
675
|
-
d
|
|
695
|
+
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
676
696
|
});
|
|
677
697
|
expect(rebound).toBe(boundOneLiner);
|
|
678
698
|
expect(rebound.match(/where:/g)).toHaveLength(1);
|
|
679
699
|
const after = await openDocument(rebound);
|
|
680
|
-
expect(after
|
|
700
|
+
expect(queryTile(after, 0).filters).toEqual([
|
|
681
701
|
{ field: "category", given: "CATEGORY" },
|
|
682
702
|
]);
|
|
683
703
|
});
|
|
@@ -695,16 +715,16 @@ source: a is one extend {
|
|
|
695
715
|
}
|
|
696
716
|
}`;
|
|
697
717
|
const before = await openDocument(sharedOpen);
|
|
698
|
-
expect(before
|
|
718
|
+
expect(queryTile(before, 0).filters).toEqual([
|
|
699
719
|
{ field: "category", given: "CATEGORY" },
|
|
700
720
|
]);
|
|
701
721
|
const rebound = await spliced(sharedOpen, (d) => {
|
|
702
|
-
d
|
|
722
|
+
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
703
723
|
});
|
|
704
724
|
expect(rebound).toBe(sharedOpen);
|
|
705
725
|
expect(rebound.match(/where:/g)).toHaveLength(1);
|
|
706
726
|
const after = await openDocument(rebound);
|
|
707
|
-
expect(after
|
|
727
|
+
expect(queryTile(after, 0).filters).toEqual([
|
|
708
728
|
{ field: "category", given: "CATEGORY" },
|
|
709
729
|
]);
|
|
710
730
|
});
|
|
@@ -719,16 +739,16 @@ source: a is one extend {
|
|
|
719
739
|
where: category ~ $CATEGORY }
|
|
720
740
|
}`;
|
|
721
741
|
const before = await openDocument(sharedClose);
|
|
722
|
-
expect(before
|
|
742
|
+
expect(queryTile(before, 0).filters).toEqual([
|
|
723
743
|
{ field: "category", given: "CATEGORY" },
|
|
724
744
|
]);
|
|
725
745
|
const rebound = await spliced(sharedClose, (d) => {
|
|
726
|
-
d
|
|
746
|
+
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
727
747
|
});
|
|
728
748
|
expect(rebound).toBe(sharedClose);
|
|
729
749
|
expect(rebound.match(/where:/g)).toHaveLength(1);
|
|
730
750
|
const after = await openDocument(rebound);
|
|
731
|
-
expect(after
|
|
751
|
+
expect(queryTile(after, 0).filters).toEqual([
|
|
732
752
|
{ field: "category", given: "CATEGORY" },
|
|
733
753
|
]);
|
|
734
754
|
});
|
|
@@ -745,14 +765,14 @@ source: a is one extend {
|
|
|
745
765
|
where: category ~ $CATEGORY }
|
|
746
766
|
}`;
|
|
747
767
|
const out = await spliced(sharedClose, (d) => {
|
|
748
|
-
delete d
|
|
768
|
+
delete queryTile(d, 0).filters;
|
|
749
769
|
});
|
|
750
770
|
// The closing brace itself, not just the text before it: dropped whole
|
|
751
771
|
// line and all, the view's own `}` would go with the where: clause.
|
|
752
772
|
expect(out).toContain(" aggregate: n is count()\n }\n}");
|
|
753
773
|
expect(out).not.toContain("where:");
|
|
754
774
|
const reopened = await openDocument(out);
|
|
755
|
-
expect(reopened
|
|
775
|
+
expect(queryTile(reopened, 0).declaration).toEqual({ kind: "inline" });
|
|
756
776
|
});
|
|
757
777
|
|
|
758
778
|
// Adding a second binding when the first already shares the closing
|
|
@@ -768,7 +788,7 @@ source: a is one extend {
|
|
|
768
788
|
where: category ~ $CATEGORY }
|
|
769
789
|
}`;
|
|
770
790
|
const out = await spliced(sharedClose, (d) => {
|
|
771
|
-
d
|
|
791
|
+
queryTile(d, 0).filters = [
|
|
772
792
|
{ field: "category", given: "CATEGORY" },
|
|
773
793
|
{ field: "brand", given: "BRAND" },
|
|
774
794
|
];
|
|
@@ -777,7 +797,7 @@ source: a is one extend {
|
|
|
777
797
|
" where: category ~ $CATEGORY\n where: brand ~ $BRAND }",
|
|
778
798
|
);
|
|
779
799
|
const reopened = await openDocument(out);
|
|
780
|
-
expect(reopened
|
|
800
|
+
expect(queryTile(reopened, 0).filters).toEqual([
|
|
781
801
|
{ field: "category", given: "CATEGORY" },
|
|
782
802
|
{ field: "brand", given: "BRAND" },
|
|
783
803
|
]);
|
|
@@ -806,13 +826,13 @@ source: a is one extend {
|
|
|
806
826
|
suggest: { source: "products", dimension: "category" },
|
|
807
827
|
},
|
|
808
828
|
];
|
|
809
|
-
d
|
|
829
|
+
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
810
830
|
});
|
|
811
831
|
expect(out.startsWith("##! experimental.givens\n")).toBe(true);
|
|
812
832
|
expect(out).toContain(
|
|
813
833
|
`import { one, products } from "../m.malloy"
|
|
814
834
|
|
|
815
|
-
# label="Category" control=select suggest { source=products dimension=category }
|
|
835
|
+
# label="Category" control=select suggest { source=products dimension="category" }
|
|
816
836
|
given: CATEGORY :: filter<string> is f''
|
|
817
837
|
`,
|
|
818
838
|
);
|
|
@@ -919,6 +939,41 @@ given: CATEGORY :: filter<string> is f''`);
|
|
|
919
939
|
});
|
|
920
940
|
});
|
|
921
941
|
|
|
942
|
+
describe("spliceDashboardDocument: a given's suggest", () => {
|
|
943
|
+
const SUGGESTED = `##! experimental.givens
|
|
944
|
+
## artifact { title="T" tiles=["a -> x"] }
|
|
945
|
+
import "../m.malloy"
|
|
946
|
+
|
|
947
|
+
# label="Brand" suggest { query=brand_suggest dimension="brand" }
|
|
948
|
+
given: BRAND :: filter<string> is f''
|
|
949
|
+
|
|
950
|
+
source: a is one extend {
|
|
951
|
+
view: x is vx
|
|
952
|
+
}`;
|
|
953
|
+
|
|
954
|
+
it("relabels a given whose suggest is a query, writing the query quoted", async () => {
|
|
955
|
+
const out = await spliced(SUGGESTED, (d) => {
|
|
956
|
+
d.localGivens![0].label = "Brand name";
|
|
957
|
+
});
|
|
958
|
+
expect(out).toContain(
|
|
959
|
+
`# label="Brand name" suggest { query="brand_suggest" dimension="brand" }`,
|
|
960
|
+
);
|
|
961
|
+
expect((await openDocument(out)).localGivens![0].suggest).toEqual({
|
|
962
|
+
query: "brand_suggest",
|
|
963
|
+
dimension: "brand",
|
|
964
|
+
});
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
it("refuses a changed suggest dimension or query that reads as an access-control tag", async () => {
|
|
968
|
+
for (const field of ["dimension", "query"] as const) {
|
|
969
|
+
const reason = await refused(SUGGESTED, (d) => {
|
|
970
|
+
d.localGivens![0].suggest![field] = "# authorize";
|
|
971
|
+
});
|
|
972
|
+
expect(reason).toContain("access-control");
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
});
|
|
976
|
+
|
|
922
977
|
describe("spliceDashboardDocument: drills", () => {
|
|
923
978
|
const WITH_DIMENSION = `## artifact { title="T" tiles=["a -> x"] }
|
|
924
979
|
import "../m.malloy"
|
|
@@ -1070,6 +1125,48 @@ describe("spliceDashboardDocument: the page's own settings", () => {
|
|
|
1070
1125
|
).toBe(true);
|
|
1071
1126
|
});
|
|
1072
1127
|
|
|
1128
|
+
describe('how many `##"` lines a description writes', () => {
|
|
1129
|
+
const NB = `##" Old\n## artifact { kind=notebook title="T" tiles=["a -> x"] }\nimport "../m.malloy"\n\nsource: a is one extend {\n view: x is vx\n}`;
|
|
1130
|
+
|
|
1131
|
+
it("writes one line for a one-line description, however it ends", async () => {
|
|
1132
|
+
for (const description of [
|
|
1133
|
+
"Walk description",
|
|
1134
|
+
"Walk description\n\n",
|
|
1135
|
+
]) {
|
|
1136
|
+
const out = await spliced(NB, (d) => {
|
|
1137
|
+
d.description = description;
|
|
1138
|
+
});
|
|
1139
|
+
expect(out.startsWith('##" Walk description\n## artifact {')).toBe(
|
|
1140
|
+
true,
|
|
1141
|
+
);
|
|
1142
|
+
}
|
|
1143
|
+
});
|
|
1144
|
+
|
|
1145
|
+
it("writes N lines for N lines, keeping a blank paragraph between them", async () => {
|
|
1146
|
+
const out = await spliced(NB, (d) => {
|
|
1147
|
+
d.description = "\nOne\n\nTwo\n";
|
|
1148
|
+
});
|
|
1149
|
+
expect(out.startsWith('##" One\n##"\n##" Two\n## artifact {')).toBe(
|
|
1150
|
+
true,
|
|
1151
|
+
);
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1154
|
+
it("round-trips an unchanged description byte for byte", async () => {
|
|
1155
|
+
const source = NB.replace('##" Old', '##" One\n##"\n##" Two');
|
|
1156
|
+
expect(
|
|
1157
|
+
await spliced(source, (d) => {
|
|
1158
|
+
d.title = "Retitled";
|
|
1159
|
+
}),
|
|
1160
|
+
).toBe(source.replace('title="T"', 'title="Retitled"'));
|
|
1161
|
+
// The same text written back is the same file.
|
|
1162
|
+
expect(
|
|
1163
|
+
await spliced(source, (d) => {
|
|
1164
|
+
d.description = "One\n\nTwo";
|
|
1165
|
+
}),
|
|
1166
|
+
).toBe(source);
|
|
1167
|
+
});
|
|
1168
|
+
});
|
|
1169
|
+
|
|
1073
1170
|
// The saved file is what the server lints, so it is linted here rather than re-read.
|
|
1074
1171
|
const lintCodes = (source: string) =>
|
|
1075
1172
|
lintNotebookText("dashboards/d.malloy", source).map((f) => f.code);
|
|
@@ -1097,25 +1194,31 @@ describe("spliceDashboardDocument: the page's own settings", () => {
|
|
|
1097
1194
|
});
|
|
1098
1195
|
});
|
|
1099
1196
|
|
|
1100
|
-
it("
|
|
1101
|
-
const source = fs
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
d.tiles.pop();
|
|
1111
|
-
});
|
|
1112
|
-
expect(reason).toContain("text tile");
|
|
1113
|
-
// A settings edit that does not touch the tile list still works.
|
|
1197
|
+
it("reorders a list holding a text tile, keeping its entry as written", async () => {
|
|
1198
|
+
const source = fs
|
|
1199
|
+
.readFileSync(
|
|
1200
|
+
path.join(
|
|
1201
|
+
REPO,
|
|
1202
|
+
"packages/server/tests/fixtures/notebooks-malloyyo/dashboards/text_tiles.malloy",
|
|
1203
|
+
),
|
|
1204
|
+
"utf8",
|
|
1205
|
+
)
|
|
1206
|
+
.replace(/\r\n/g, "\n");
|
|
1114
1207
|
const out = await spliced(source, (d) => {
|
|
1208
|
+
d.tiles.reverse();
|
|
1209
|
+
});
|
|
1210
|
+
expect(out).toContain(
|
|
1211
|
+
'tiles=["orders -> kpis", intro { kind=text colspan=12 }]',
|
|
1212
|
+
);
|
|
1213
|
+
expect(out).toContain(
|
|
1214
|
+
"##|(markdown) intro\n## How to read this page\n|##",
|
|
1215
|
+
);
|
|
1216
|
+
// A settings edit that does not touch the tile list leaves the entry alone too.
|
|
1217
|
+
const renamed = await spliced(source, (d) => {
|
|
1115
1218
|
d.title = "Renamed";
|
|
1116
1219
|
});
|
|
1117
|
-
expect(
|
|
1118
|
-
expect(
|
|
1220
|
+
expect(renamed).toContain("intro { kind=text colspan=12 }");
|
|
1221
|
+
expect(renamed).toContain('title="Renamed"');
|
|
1119
1222
|
});
|
|
1120
1223
|
|
|
1121
1224
|
it("changes the width of a file whose title holds dashboard { }", async () => {
|
|
@@ -1375,7 +1478,7 @@ describe("spliceDashboardDocument: what it refuses", () => {
|
|
|
1375
1478
|
d.imports.push({ kind: "all", from: "../more.malloy" });
|
|
1376
1479
|
});
|
|
1377
1480
|
expect(r.ok).toBe(false);
|
|
1378
|
-
if (spliceFailed(r)) expect(r.reason).toContain("
|
|
1481
|
+
if (spliceFailed(r)) expect(r.reason).toContain("whole-file");
|
|
1379
1482
|
});
|
|
1380
1483
|
|
|
1381
1484
|
// An inherited tile's tags live on the model's view, and the builder never
|
|
@@ -1551,7 +1654,7 @@ describe("every composite dashboard survives an edit", () => {
|
|
|
1551
1654
|
const doc = await readDashboardDocument(source);
|
|
1552
1655
|
if (readFailed(doc)) throw new Error(doc.reason);
|
|
1553
1656
|
const target = doc.document.tiles.findIndex(
|
|
1554
|
-
(t) => t.declaration.kind !== "inherited",
|
|
1657
|
+
(t) => isQueryTile(t) && t.declaration.kind !== "inherited",
|
|
1555
1658
|
);
|
|
1556
1659
|
// A file whose tiles are all declared on their sources has nothing
|
|
1557
1660
|
// here to patch, which is a real shape rather than a gap.
|
|
@@ -1585,7 +1688,7 @@ describe("every composite dashboard survives an edit", () => {
|
|
|
1585
1688
|
const doc = await readDashboardDocument(source);
|
|
1586
1689
|
if (readFailed(doc)) throw new Error(doc.reason);
|
|
1587
1690
|
const target = doc.document.tiles.findIndex(
|
|
1588
|
-
(t) => t.declaration.kind !== "inherited",
|
|
1691
|
+
(t) => isQueryTile(t) && t.declaration.kind !== "inherited",
|
|
1589
1692
|
);
|
|
1590
1693
|
// No tile declared here: a real shape, not a gap in the sweep.
|
|
1591
1694
|
if (target < 0) return;
|
|
@@ -1596,8 +1699,8 @@ describe("every composite dashboard survives an edit", () => {
|
|
|
1596
1699
|
|
|
1597
1700
|
const next = structuredClone(doc.document);
|
|
1598
1701
|
const binding = { field: "_probe", given };
|
|
1599
|
-
next
|
|
1600
|
-
...(next
|
|
1702
|
+
queryTile(next, target).filters = [
|
|
1703
|
+
...(queryTile(next, target).filters ?? []),
|
|
1601
1704
|
binding,
|
|
1602
1705
|
];
|
|
1603
1706
|
const result = await spliceDashboardDocument(source, next);
|
|
@@ -1611,7 +1714,9 @@ describe("every composite dashboard survives an edit", () => {
|
|
|
1611
1714
|
expect(await syntaxErrors(result.source)).toEqual([]);
|
|
1612
1715
|
const reread = await readDashboardDocument(result.source);
|
|
1613
1716
|
if (readFailed(reread)) throw new Error(reread.reason);
|
|
1614
|
-
expect(reread.document
|
|
1717
|
+
expect(queryTile(reread.document, target).filters).toContainEqual(
|
|
1718
|
+
binding,
|
|
1719
|
+
);
|
|
1615
1720
|
const moved = await whatMoved(source, result.source);
|
|
1616
1721
|
expect(moved.comments).toEqual([]);
|
|
1617
1722
|
expect(moved.attached).toEqual([]);
|
|
@@ -1653,7 +1758,7 @@ describe("every composite dashboard survives an edit", () => {
|
|
|
1653
1758
|
const doc = await readDashboardDocument(source);
|
|
1654
1759
|
if (readFailed(doc)) throw new Error(doc.reason);
|
|
1655
1760
|
const target = doc.document.tiles.findIndex(
|
|
1656
|
-
(t) => t.declaration.kind !== "inherited",
|
|
1761
|
+
(t) => isQueryTile(t) && t.declaration.kind !== "inherited",
|
|
1657
1762
|
);
|
|
1658
1763
|
// One tile left, or every tile declared on its source: nothing here
|
|
1659
1764
|
// reaches the declaration-deletion path.
|
|
@@ -1671,30 +1776,31 @@ describe("every composite dashboard survives an edit", () => {
|
|
|
1671
1776
|
expect(reread.document.tiles.map((t) => t.name)).not.toContain(
|
|
1672
1777
|
gone.name,
|
|
1673
1778
|
);
|
|
1674
|
-
await survives(source, result.source, [
|
|
1675
|
-
`-view:${gone.source}.${gone.name}`,
|
|
1676
|
-
]);
|
|
1779
|
+
await survives(source, result.source, [`-view:${tileKey(gone)}`]);
|
|
1677
1780
|
});
|
|
1678
1781
|
|
|
1679
1782
|
it(`unbinds a filter in ${name} and disturbs nothing beside it`, async () => {
|
|
1680
1783
|
const source = fs.readFileSync(file, "utf8");
|
|
1681
1784
|
const doc = await readDashboardDocument(source);
|
|
1682
1785
|
if (readFailed(doc)) throw new Error(doc.reason);
|
|
1683
|
-
const target = doc.document.tiles.findIndex(
|
|
1786
|
+
const target = doc.document.tiles.findIndex(
|
|
1787
|
+
(t) => isQueryTile(t) && t.filters?.length,
|
|
1788
|
+
);
|
|
1684
1789
|
// No tile binds a control here: a real shape, not a gap.
|
|
1685
1790
|
if (target < 0) return;
|
|
1686
1791
|
|
|
1687
1792
|
const next = structuredClone(doc.document);
|
|
1688
|
-
next
|
|
1793
|
+
queryTile(next, target).filters = queryTile(
|
|
1794
|
+
next,
|
|
1795
|
+
target,
|
|
1796
|
+
).filters!.slice(0, -1);
|
|
1689
1797
|
const result = await spliceDashboardDocument(source, next);
|
|
1690
1798
|
if (spliceFailed(result)) {
|
|
1691
1799
|
expect(result.reason.length).toBeGreaterThan(0);
|
|
1692
1800
|
return;
|
|
1693
1801
|
}
|
|
1694
1802
|
const tile = next.tiles[target];
|
|
1695
|
-
await survives(source, result.source, [
|
|
1696
|
-
`~view:${tile.source}.${tile.name}`,
|
|
1697
|
-
]);
|
|
1803
|
+
await survives(source, result.source, [`~view:${tileKey(tile)}`]);
|
|
1698
1804
|
});
|
|
1699
1805
|
|
|
1700
1806
|
it(`removes a control from ${name} and disturbs nothing beside it`, async () => {
|
|
@@ -1985,10 +2091,10 @@ source: a is one extend {
|
|
|
1985
2091
|
it("keeps a quote in a tile label, and reads it back", async () => {
|
|
1986
2092
|
const label = 'Revenue (the "good" kind)';
|
|
1987
2093
|
const result = await spliced(FILE, (d) => {
|
|
1988
|
-
d
|
|
2094
|
+
queryTile(d, 0).label = label;
|
|
1989
2095
|
});
|
|
1990
2096
|
const reread = await openDocument(result);
|
|
1991
|
-
expect(reread
|
|
2097
|
+
expect(queryTile(reread, 0).label).toBe(label);
|
|
1992
2098
|
});
|
|
1993
2099
|
|
|
1994
2100
|
it("keeps a trailing backslash in a given's label", async () => {
|
|
@@ -2012,10 +2118,10 @@ source: a is one extend {
|
|
|
2012
2118
|
it("keeps a quote in a tile subtitle", async () => {
|
|
2013
2119
|
const subtitle = 'by "region"';
|
|
2014
2120
|
const result = await spliced(FILE, (d) => {
|
|
2015
|
-
d
|
|
2121
|
+
queryTile(d, 0).subtitle = subtitle;
|
|
2016
2122
|
});
|
|
2017
2123
|
const reread = await openDocument(result);
|
|
2018
|
-
expect(reread
|
|
2124
|
+
expect(queryTile(reread, 0).subtitle).toBe(subtitle);
|
|
2019
2125
|
});
|
|
2020
2126
|
});
|
|
2021
2127
|
|
|
@@ -2046,7 +2152,7 @@ source: a is one extend {
|
|
|
2046
2152
|
},
|
|
2047
2153
|
(d: DashboardDocument) => {
|
|
2048
2154
|
d.localGivens = d.localGivens ?? [];
|
|
2049
|
-
d
|
|
2155
|
+
queryTile(d, 0).filters = [];
|
|
2050
2156
|
},
|
|
2051
2157
|
]) {
|
|
2052
2158
|
expect(await spliced(FILE, materialise)).toBe(FILE);
|
|
@@ -2108,7 +2214,7 @@ source: b is scoped_orders extend {
|
|
|
2108
2214
|
|
|
2109
2215
|
it("retags the second source's view without touching the first's", async () => {
|
|
2110
2216
|
const out = await spliced(SHARED, (d) => {
|
|
2111
|
-
const tile = d.tiles.find((t) => t.source === "b");
|
|
2217
|
+
const tile = d.tiles.filter(isQueryTile).find((t) => t.source === "b");
|
|
2112
2218
|
if (!tile) throw new Error("no tile on b");
|
|
2113
2219
|
tile.label = "B by month";
|
|
2114
2220
|
});
|
|
@@ -2127,7 +2233,7 @@ source: b is scoped_orders extend {
|
|
|
2127
2233
|
|
|
2128
2234
|
it("edits the first source's view when that is the tile", async () => {
|
|
2129
2235
|
const out = await spliced(SHARED, (d) => {
|
|
2130
|
-
const tile = d.tiles.find((t) => t.source === "a");
|
|
2236
|
+
const tile = d.tiles.filter(isQueryTile).find((t) => t.source === "a");
|
|
2131
2237
|
if (!tile) throw new Error("no tile on a");
|
|
2132
2238
|
tile.label = "A by month";
|
|
2133
2239
|
});
|
|
@@ -2271,7 +2377,7 @@ source: a is scoped_orders extend {
|
|
|
2271
2377
|
|
|
2272
2378
|
it("binds inside kpis's own body and never touches the unrelated view", async () => {
|
|
2273
2379
|
const out = await spliced(SOURCE, (d) => {
|
|
2274
|
-
d
|
|
2380
|
+
queryTile(d, 0).filters = [{ field: "cat", given: "CATEGORY" }];
|
|
2275
2381
|
});
|
|
2276
2382
|
expect(out).toContain(
|
|
2277
2383
|
" view: kpis is {\n group_by: cat // the { brace here is unbalanced\n aggregate: n is count()\n where: cat ~ $CATEGORY\n }",
|
|
@@ -2311,11 +2417,15 @@ source: a is one extend {
|
|
|
2311
2417
|
expect(result.source).toBe(TEXT_TILE);
|
|
2312
2418
|
});
|
|
2313
2419
|
|
|
2314
|
-
it("
|
|
2315
|
-
const
|
|
2420
|
+
it("removes a query tile beside a text tile without touching the text tile", async () => {
|
|
2421
|
+
const out = await spliced(TEXT_TILE, (d) => {
|
|
2316
2422
|
d.tiles.pop();
|
|
2317
2423
|
});
|
|
2318
|
-
expect(
|
|
2424
|
+
expect(out).toContain("tiles=[intro { kind=text colspan=12 }]");
|
|
2425
|
+
expect(out).toContain(
|
|
2426
|
+
"##|(markdown) intro\n## How to read this page\n|##\n",
|
|
2427
|
+
);
|
|
2428
|
+
expect(out).not.toContain("view: x");
|
|
2319
2429
|
});
|
|
2320
2430
|
|
|
2321
2431
|
it("rewrites a description and a tile's colspan without touching the markdown around them", async () => {
|
|
@@ -2487,3 +2597,28 @@ source: a is one extend {
|
|
|
2487
2597
|
expect(given?.label).toBeUndefined();
|
|
2488
2598
|
});
|
|
2489
2599
|
});
|
|
2600
|
+
|
|
2601
|
+
describe("spliceDashboardDocument: a CRLF file", () => {
|
|
2602
|
+
const CRLF = SOURCE.replace(/\n/g, "\r\n");
|
|
2603
|
+
const bareNewlines = (text: string) => text.match(/(?<!\r)\n/g)?.length ?? 0;
|
|
2604
|
+
|
|
2605
|
+
it("writes its own line ending into every line it inserts", async () => {
|
|
2606
|
+
const out = await spliced(CRLF, (d) => {
|
|
2607
|
+
queryTile(d, 0).label = "Categories";
|
|
2608
|
+
queryTile(d, 1).filters = [{ field: "brand", given: "BRAND" }];
|
|
2609
|
+
queryTile(d, 1).subtitle = "Top brands";
|
|
2610
|
+
d.tiles.push({
|
|
2611
|
+
name: "by_state",
|
|
2612
|
+
source: "a",
|
|
2613
|
+
declaration: { kind: "reference", from: "by_state_view" },
|
|
2614
|
+
});
|
|
2615
|
+
});
|
|
2616
|
+
expect(out).toContain('# label="Categories"\r\n');
|
|
2617
|
+
expect(out).toContain("by_state");
|
|
2618
|
+
expect(bareNewlines(out)).toBe(0);
|
|
2619
|
+
});
|
|
2620
|
+
|
|
2621
|
+
it("leaves it byte-identical when nothing changed", async () => {
|
|
2622
|
+
expect(await spliced(CRLF, () => {})).toBe(CRLF);
|
|
2623
|
+
});
|
|
2624
|
+
});
|