@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,180 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { parseAnnotation } from "@malloydata/malloy-tag";
|
|
5
|
+
import { describe, expect, it } from "bun:test";
|
|
6
|
+
import {
|
|
7
|
+
CHART_TAGS,
|
|
8
|
+
chartLineText,
|
|
9
|
+
chartStateOf,
|
|
10
|
+
isChartPick,
|
|
11
|
+
mentionsChartTag,
|
|
12
|
+
parseChartLine,
|
|
13
|
+
} from "./chartLine";
|
|
14
|
+
|
|
15
|
+
describe("parseChartLine", () => {
|
|
16
|
+
it("recognizes a bare pick, negations, and the writer's own lines", () => {
|
|
17
|
+
expect(parseChartLine("# line_chart")).toEqual({
|
|
18
|
+
negated: [],
|
|
19
|
+
pick: "line_chart",
|
|
20
|
+
});
|
|
21
|
+
expect(parseChartLine("# -bar_chart line_chart")).toEqual({
|
|
22
|
+
negated: ["bar_chart"],
|
|
23
|
+
pick: "line_chart",
|
|
24
|
+
});
|
|
25
|
+
expect(parseChartLine("# -bar_chart -viz")).toEqual({
|
|
26
|
+
negated: ["bar_chart", "viz"],
|
|
27
|
+
});
|
|
28
|
+
expect(parseChartLine(" # -viz \r")).toEqual({ negated: ["viz"] });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("does not recognize a line with properties, other tags, or two picks", () => {
|
|
32
|
+
for (const line of [
|
|
33
|
+
"# bar_chart { size=spark }",
|
|
34
|
+
'# line_chart label="Revenue"',
|
|
35
|
+
"# viz=line",
|
|
36
|
+
"# bar_chart line_chart",
|
|
37
|
+
"# line_chart -bar_chart",
|
|
38
|
+
"# bar_chart colspan=2",
|
|
39
|
+
"# bar_chart label",
|
|
40
|
+
"# -nonsense",
|
|
41
|
+
"# drill",
|
|
42
|
+
"#",
|
|
43
|
+
"#-bar_chart",
|
|
44
|
+
'#" a caption',
|
|
45
|
+
"#(doc) bar_chart",
|
|
46
|
+
"## bar_chart",
|
|
47
|
+
"// # bar_chart",
|
|
48
|
+
])
|
|
49
|
+
expect(parseChartLine(line)).toBeUndefined();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("mentionsChartTag", () => {
|
|
54
|
+
it("flags the unmodelled lines a chart edit must not touch", () => {
|
|
55
|
+
expect(mentionsChartTag("# bar_chart { size=spark }")).toBe(true);
|
|
56
|
+
expect(mentionsChartTag('# line_chart label="Revenue"')).toBe(true);
|
|
57
|
+
expect(mentionsChartTag("# viz=line")).toBe(true);
|
|
58
|
+
expect(mentionsChartTag("# line_chart")).toBe(false);
|
|
59
|
+
expect(mentionsChartTag('# label="Sales"')).toBe(false);
|
|
60
|
+
expect(mentionsChartTag('#" about the bar_chart')).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("chartLineText", () => {
|
|
65
|
+
it("negates every other chart tag and viz, in a fixed order", () => {
|
|
66
|
+
expect(chartLineText("line_chart")).toBe(
|
|
67
|
+
"# -bar_chart -big_value -scatter_chart -shape_map -segment_map -viz line_chart",
|
|
68
|
+
);
|
|
69
|
+
expect(chartLineText("bar_chart")).toBe(
|
|
70
|
+
"# -line_chart -big_value -scatter_chart -shape_map -segment_map -viz bar_chart",
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("writes -viz on the no-chart line, which keeps a viz= view from rendering a chart", () => {
|
|
75
|
+
expect(chartLineText("none")).toBe(
|
|
76
|
+
"# -line_chart -bar_chart -big_value -scatter_chart -shape_map -segment_map -viz",
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("negates only the chart tags the view carries when the catalog knows them", () => {
|
|
81
|
+
expect(chartLineText("line_chart", ["bar_chart"])).toBe(
|
|
82
|
+
"# -bar_chart -viz line_chart",
|
|
83
|
+
);
|
|
84
|
+
expect(chartLineText("none", ["bar_chart"])).toBe("# -bar_chart -viz");
|
|
85
|
+
expect(chartLineText("bar_chart", ["bar_chart"])).toBe(
|
|
86
|
+
"# -viz bar_chart",
|
|
87
|
+
);
|
|
88
|
+
expect(chartLineText("line_chart", [])).toBe("# -viz line_chart");
|
|
89
|
+
expect(chartLineText("none", [])).toBe("# -viz");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("reads a narrowed line back as the same state", () => {
|
|
93
|
+
expect(chartStateOf([chartLineText("line_chart", ["bar_chart"])])).toBe(
|
|
94
|
+
"line_chart",
|
|
95
|
+
);
|
|
96
|
+
expect(chartStateOf([chartLineText("none", ["bar_chart"])])).toBe("none");
|
|
97
|
+
expect(chartStateOf([chartLineText("none", [])])).toBe("none");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("emits lines the recognizer reads back as the same state", () => {
|
|
101
|
+
for (const pick of CHART_TAGS.filter(isChartPick))
|
|
102
|
+
expect(chartStateOf([chartLineText(pick)])).toBe(pick);
|
|
103
|
+
expect(chartStateOf([chartLineText("none")])).toBe("none");
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("chartLineText through the tag parser", () => {
|
|
108
|
+
const PLUGINS = [
|
|
109
|
+
"line_chart",
|
|
110
|
+
"bar_chart",
|
|
111
|
+
"big_value",
|
|
112
|
+
"scatter_chart",
|
|
113
|
+
"shape_map",
|
|
114
|
+
"segment_map",
|
|
115
|
+
] as const;
|
|
116
|
+
const BASES = [
|
|
117
|
+
"# bar_chart",
|
|
118
|
+
"# line_chart",
|
|
119
|
+
"# viz=line",
|
|
120
|
+
"# big_value",
|
|
121
|
+
"# scatter_chart",
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
it("leaves exactly the picked tag over any base, stacked as the renderer inherits", () => {
|
|
125
|
+
for (const base of BASES)
|
|
126
|
+
for (const pick of PLUGINS) {
|
|
127
|
+
const { tag, log } = parseAnnotation([
|
|
128
|
+
base,
|
|
129
|
+
`${chartLineText(pick)}\n`,
|
|
130
|
+
]);
|
|
131
|
+
expect(log).toEqual([]);
|
|
132
|
+
for (const name of [...PLUGINS, "viz"])
|
|
133
|
+
expect(tag.has(name)).toBe(name === pick);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("a narrowed line over a view carrying its tag leaves the same tags as the full line", () => {
|
|
138
|
+
for (const carried of PLUGINS)
|
|
139
|
+
for (const pick of [...PLUGINS, "none" as const]) {
|
|
140
|
+
const { tag, log } = parseAnnotation([
|
|
141
|
+
`# ${carried}`,
|
|
142
|
+
`${chartLineText(pick, [carried])}\n`,
|
|
143
|
+
]);
|
|
144
|
+
expect(log).toEqual([]);
|
|
145
|
+
for (const name of [...PLUGINS, "viz"])
|
|
146
|
+
expect(tag.has(name)).toBe(name === pick);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("turns every chart and viz off for none", () => {
|
|
151
|
+
for (const base of BASES) {
|
|
152
|
+
const { tag, log } = parseAnnotation([
|
|
153
|
+
base,
|
|
154
|
+
`${chartLineText("none")}\n`,
|
|
155
|
+
]);
|
|
156
|
+
expect(log).toEqual([]);
|
|
157
|
+
for (const name of [...PLUGINS, "viz"])
|
|
158
|
+
expect(tag.has(name)).toBe(false);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("chartStateOf", () => {
|
|
164
|
+
it("reads no line as default, a partial negation or two lines as custom", () => {
|
|
165
|
+
expect(chartStateOf([])).toBe("default");
|
|
166
|
+
expect(chartStateOf(["# -bar_chart"])).toBe("custom");
|
|
167
|
+
expect(chartStateOf(["# line_chart", "# -viz"])).toBe("custom");
|
|
168
|
+
expect(chartStateOf(["# sparkline"])).toBe("custom");
|
|
169
|
+
expect(chartStateOf(["# bar_chart"])).toBe("bar_chart");
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("mentionsChartTag: quoted values", () => {
|
|
174
|
+
it("ignores words inside a string and still sees real ones", () => {
|
|
175
|
+
expect(mentionsChartTag('# label="Sales viz"')).toBe(false);
|
|
176
|
+
expect(mentionsChartTag('# label="a \\" viz"')).toBe(false);
|
|
177
|
+
expect(mentionsChartTag('# line_chart label="Revenue"')).toBe(true);
|
|
178
|
+
expect(mentionsChartTag("# viz=line")).toBe(true);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The one `# <chart>` tag line a builder writes above a tile or a query cell.
|
|
6
|
+
* Pure text, with no Malloy import, so both writers and the main entry can reach it.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** The renderer's chart tags, as they are spelled in a model. */
|
|
10
|
+
export const CHART_TAGS = [
|
|
11
|
+
"bar_chart",
|
|
12
|
+
"line_chart",
|
|
13
|
+
"scatter_chart",
|
|
14
|
+
"shape_map",
|
|
15
|
+
"segment_map",
|
|
16
|
+
"big_value",
|
|
17
|
+
"sparkline",
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/** The tags the renderer has a plugin for, in the order a line negates them. */
|
|
21
|
+
const PLUGIN_TAGS = [
|
|
22
|
+
"line_chart",
|
|
23
|
+
"bar_chart",
|
|
24
|
+
"big_value",
|
|
25
|
+
"scatter_chart",
|
|
26
|
+
"shape_map",
|
|
27
|
+
"segment_map",
|
|
28
|
+
] as const;
|
|
29
|
+
|
|
30
|
+
export type ChartPick = (typeof PLUGIN_TAGS)[number];
|
|
31
|
+
|
|
32
|
+
/** What a picker holds: a chart, no chart (a table), the view's own (no line), or a line the builder does not model. */
|
|
33
|
+
export type ChartState = ChartPick | "none" | "default" | "custom";
|
|
34
|
+
|
|
35
|
+
export const isChartPick = (value: unknown): value is ChartPick =>
|
|
36
|
+
PLUGIN_TAGS.includes(value as ChartPick);
|
|
37
|
+
|
|
38
|
+
const LINE_NAMES = new Set([...CHART_TAGS, "viz"]);
|
|
39
|
+
|
|
40
|
+
export interface ChartLineParts {
|
|
41
|
+
negated: string[];
|
|
42
|
+
pick?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** `#`, any `-name`s, at most one `name`, every name a chart tag or `viz`, no `{` and no `=`; anything else is not ours to rewrite. */
|
|
46
|
+
export function parseChartLine(line: string): ChartLineParts | undefined {
|
|
47
|
+
const trimmed = line.trim();
|
|
48
|
+
if (!/^#[ \t]/.test(trimmed) || /[{=]/.test(trimmed)) return undefined;
|
|
49
|
+
const words = trimmed
|
|
50
|
+
.slice(1)
|
|
51
|
+
.trim()
|
|
52
|
+
.split(/[ \t]+/);
|
|
53
|
+
const negated: string[] = [];
|
|
54
|
+
let pick: string | undefined;
|
|
55
|
+
for (const word of words) {
|
|
56
|
+
if (word.startsWith("-")) {
|
|
57
|
+
if (pick !== undefined) return undefined;
|
|
58
|
+
const name = word.slice(1);
|
|
59
|
+
if (!LINE_NAMES.has(name)) return undefined;
|
|
60
|
+
negated.push(name);
|
|
61
|
+
} else {
|
|
62
|
+
if (pick !== undefined || !LINE_NAMES.has(word)) return undefined;
|
|
63
|
+
pick = word;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return { negated, ...(pick !== undefined && { pick }) };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Some other `#` tag line that names a chart tag (`# bar_chart { size=spark }`), which a chart edit must leave alone. */
|
|
70
|
+
export function mentionsChartTag(line: string): boolean {
|
|
71
|
+
const trimmed = line.trim();
|
|
72
|
+
if (!/^#[ \t]/.test(trimmed) || parseChartLine(trimmed)) return false;
|
|
73
|
+
const unquoted = trimmed.replace(/"(?:[^"\\]|\\.)*"/g, '""');
|
|
74
|
+
return (unquoted.match(/[A-Za-z_]+/g) ?? []).some((word) =>
|
|
75
|
+
LINE_NAMES.has(word),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The line for a pick. Given the chart tags the view carries it negates only those; without them
|
|
81
|
+
* (the catalog does not know the view) it negates every other chart tag. `-viz` stays either way,
|
|
82
|
+
* since the catalog does not report a `viz=` tag.
|
|
83
|
+
*/
|
|
84
|
+
export function chartLineText(
|
|
85
|
+
chart: ChartPick | "none",
|
|
86
|
+
carried?: readonly string[],
|
|
87
|
+
): string {
|
|
88
|
+
const negated = PLUGIN_TAGS.filter(
|
|
89
|
+
(tag) =>
|
|
90
|
+
tag !== chart && (carried === undefined || carried.includes(tag)),
|
|
91
|
+
).map((tag) => `-${tag}`);
|
|
92
|
+
return ["#", ...negated, "-viz", ...(chart === "none" ? [] : [chart])].join(
|
|
93
|
+
" ",
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** What a recognized line says: its pick, a table when it negates `viz` and picks nothing, otherwise a line the picker cannot show. */
|
|
98
|
+
function chartStateOfParts(parts: ChartLineParts): ChartState {
|
|
99
|
+
if (parts.pick !== undefined)
|
|
100
|
+
return isChartPick(parts.pick) ? parts.pick : "custom";
|
|
101
|
+
return parts.negated.includes("viz") ? "none" : "custom";
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The picker state of a tile's or cell's recognized chart lines. */
|
|
105
|
+
export function chartStateOf(lines: string[]): ChartState {
|
|
106
|
+
if (lines.length === 0) return "default";
|
|
107
|
+
if (lines.length > 1) return "custom";
|
|
108
|
+
const parts = parseChartLine(lines[0]);
|
|
109
|
+
return parts ? chartStateOfParts(parts) : "custom";
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** What a tile's `#` lines say about its chart: nothing (undefined), a state, or "custom" when any line names a chart tag the builder does not model. */
|
|
113
|
+
export function chartStateOfTagLines(lines: string[]): ChartState | undefined {
|
|
114
|
+
const ours = lines.filter((line) => parseChartLine(line));
|
|
115
|
+
if (lines.some(mentionsChartTag)) return "custom";
|
|
116
|
+
return ours.length === 0 ? undefined : chartStateOf(ours);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The lines of `lines` that are about the chart, recognized or not: what a "custom" state is made of. */
|
|
120
|
+
export const chartLinesOf = (lines: string[]): string[] =>
|
|
121
|
+
lines.filter((line) => parseChartLine(line) || mentionsChartTag(line));
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { isStrictName } from "./malloyText";
|
|
5
6
|
import {
|
|
6
7
|
acceptsField,
|
|
7
8
|
kindForFieldType,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
removeControl,
|
|
18
19
|
} from "./controls";
|
|
19
20
|
import type { DashboardDocument } from "./document";
|
|
21
|
+
import { queryTile } from "./testing/fixtures";
|
|
20
22
|
|
|
21
23
|
const doc = (): DashboardDocument => ({
|
|
22
24
|
title: "T",
|
|
@@ -92,10 +94,19 @@ describe("givenNameFor", () => {
|
|
|
92
94
|
expect(givenNameFor("category", ["CATEGORY"])).toBe("CATEGORY_2");
|
|
93
95
|
expect(givenNameFor("2nd-tier", [])).toBe("F_2ND_TIER");
|
|
94
96
|
});
|
|
97
|
+
|
|
98
|
+
it("never generates a reserved word, which Malloy refuses in any case", () => {
|
|
99
|
+
for (const field of ["date", "type", "source", "year", "orders.filter"]) {
|
|
100
|
+
const name = givenNameFor(field, []);
|
|
101
|
+
expect(isStrictName(name)).toBe(true);
|
|
102
|
+
expect(name).toBe(`${field.split(".").at(-1)!.toUpperCase()}_FILTER`);
|
|
103
|
+
}
|
|
104
|
+
expect(givenNameFor("date", ["DATE_FILTER"])).toBe("DATE_FILTER_2");
|
|
105
|
+
});
|
|
95
106
|
});
|
|
96
107
|
|
|
97
108
|
describe("newLocalGiven", () => {
|
|
98
|
-
it("declares a picker that suggests over the field's own source", () => {
|
|
109
|
+
it("declares a picker that suggests over the field's own source, keeping a joined path whole", () => {
|
|
99
110
|
expect(
|
|
100
111
|
newLocalGiven({
|
|
101
112
|
name: "REGION",
|
|
@@ -110,7 +121,7 @@ describe("newLocalGiven", () => {
|
|
|
110
121
|
default: "f''",
|
|
111
122
|
label: "Region",
|
|
112
123
|
control: "select",
|
|
113
|
-
suggest: { source: "order_items", dimension: "region" },
|
|
124
|
+
suggest: { source: "order_items", dimension: "regions.region" },
|
|
114
125
|
});
|
|
115
126
|
});
|
|
116
127
|
|
|
@@ -157,14 +168,14 @@ describe("mappings", () => {
|
|
|
157
168
|
// reference tile's refinement as far as applyMapping is concerned.
|
|
158
169
|
{ include: true, field: "created_at", op: ">=" },
|
|
159
170
|
]);
|
|
160
|
-
expect(d
|
|
171
|
+
expect(queryTile(d, 0).filters).toEqual([
|
|
161
172
|
{ field: "category", given: "CATEGORY" },
|
|
162
173
|
{ field: "created_at", given: "SINCE", op: ">=" },
|
|
163
174
|
]);
|
|
164
|
-
expect(d
|
|
175
|
+
expect(queryTile(d, 1).filters).toEqual([
|
|
165
176
|
{ field: "created_at", given: "SINCE", op: ">=" },
|
|
166
177
|
]);
|
|
167
|
-
expect(d
|
|
178
|
+
expect(queryTile(d, 2).filters).toEqual([
|
|
168
179
|
{ field: "created_at", given: "SINCE", op: ">=" },
|
|
169
180
|
]);
|
|
170
181
|
|
|
@@ -174,13 +185,13 @@ describe("mappings", () => {
|
|
|
174
185
|
{ include: true, field: "created_at", op: "~" },
|
|
175
186
|
{ include: false, field: "created_at" },
|
|
176
187
|
]);
|
|
177
|
-
expect(d
|
|
188
|
+
expect(queryTile(d, 0).filters).toEqual([
|
|
178
189
|
{ field: "category", given: "CATEGORY" },
|
|
179
190
|
]);
|
|
180
|
-
expect(d
|
|
191
|
+
expect(queryTile(d, 1).filters).toEqual([
|
|
181
192
|
{ field: "created_at", given: "SINCE" },
|
|
182
193
|
]);
|
|
183
|
-
expect(d
|
|
194
|
+
expect(queryTile(d, 2).filters).toBeUndefined();
|
|
184
195
|
});
|
|
185
196
|
|
|
186
197
|
it("still skips a tile the writer cannot locate at all: inherited", () => {
|
|
@@ -196,7 +207,7 @@ describe("mappings", () => {
|
|
|
196
207
|
{ include: false, field: "created_at" },
|
|
197
208
|
{ include: true, field: "created_at", op: ">=" },
|
|
198
209
|
]);
|
|
199
|
-
expect(d
|
|
210
|
+
expect(queryTile(d, 3).filters).toBeUndefined();
|
|
200
211
|
});
|
|
201
212
|
});
|
|
202
213
|
|
|
@@ -247,7 +258,7 @@ describe("declareControl and removeControl", () => {
|
|
|
247
258
|
expect(d.localGivens?.map((g) => g.name)).toEqual(["CATEGORY", "SINCE"]);
|
|
248
259
|
|
|
249
260
|
removeControl(d, "CATEGORY");
|
|
250
|
-
expect(d
|
|
261
|
+
expect(queryTile(d, 0).filters).toBeUndefined();
|
|
251
262
|
expect(d.localGivens?.map((g) => g.name)).toEqual(["SINCE"]);
|
|
252
263
|
removeControl(d, "SINCE");
|
|
253
264
|
expect(d.localGivens).toBeUndefined();
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import {
|
|
5
|
+
isQueryTile,
|
|
6
|
+
type DashboardDocument,
|
|
7
|
+
type DashboardTile,
|
|
8
|
+
type LocalGiven,
|
|
9
|
+
type QueryTile,
|
|
10
|
+
} from "./document";
|
|
11
|
+
import { isStrictName } from "./malloyText";
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
14
|
* The builder's view of the dashboard's filter controls, and the pure edits it
|
|
@@ -61,7 +68,7 @@ export function controlsOf(
|
|
|
61
68
|
): BuilderControl[] {
|
|
62
69
|
const bound = new Map<string, number>();
|
|
63
70
|
for (const tile of document.tiles)
|
|
64
|
-
for (const filter of tile.filters ?? [])
|
|
71
|
+
for (const filter of isQueryTile(tile) ? (tile.filters ?? []) : [])
|
|
65
72
|
bound.set(filter.given, (bound.get(filter.given) ?? 0) + 1);
|
|
66
73
|
|
|
67
74
|
const out: BuilderControl[] = [];
|
|
@@ -198,7 +205,9 @@ export function givenNameFor(field: string, taken: Iterable<string>): string {
|
|
|
198
205
|
.split(/[^A-Za-z0-9]+/)
|
|
199
206
|
.filter(Boolean);
|
|
200
207
|
const base = words.join("_").toUpperCase() || "FILTER";
|
|
201
|
-
const
|
|
208
|
+
const shaped = /^[A-Z_]/.test(base) ? base : `F_${base}`;
|
|
209
|
+
// Reserved words are case-insensitive, so `DATE` would not compile as a given name.
|
|
210
|
+
const stem = isStrictName(shaped) ? shaped : `${shaped}_FILTER`;
|
|
202
211
|
const used = new Set(taken);
|
|
203
212
|
if (!used.has(stem)) return stem;
|
|
204
213
|
for (let n = 2; ; n++) if (!used.has(`${stem}_${n}`)) return `${stem}_${n}`;
|
|
@@ -230,7 +239,7 @@ export const CONTROL_KINDS: ReadonlyArray<{
|
|
|
230
239
|
},
|
|
231
240
|
{
|
|
232
241
|
kind: "date",
|
|
233
|
-
label: "
|
|
242
|
+
label: "On or after a date",
|
|
234
243
|
hint: "A date picker; tiles keep rows on or after it",
|
|
235
244
|
},
|
|
236
245
|
];
|
|
@@ -254,7 +263,7 @@ export function newLocalGiven(spec: {
|
|
|
254
263
|
range?: { min: number; max: number };
|
|
255
264
|
}): LocalGiven {
|
|
256
265
|
const label = spec.label.trim() || spec.name;
|
|
257
|
-
const dimension = spec.field
|
|
266
|
+
const dimension = spec.field;
|
|
258
267
|
switch (spec.kind) {
|
|
259
268
|
case "select":
|
|
260
269
|
case "multiselect":
|
|
@@ -315,8 +324,10 @@ export interface MappingRow {
|
|
|
315
324
|
* excludes, and so is an `opaque` one: its body has no single block a binding
|
|
316
325
|
* belongs in, which the reader can see before a save is ever attempted.
|
|
317
326
|
*/
|
|
318
|
-
export const canBind = (tile: DashboardTile) =>
|
|
319
|
-
tile
|
|
327
|
+
export const canBind = (tile: DashboardTile): tile is QueryTile =>
|
|
328
|
+
isQueryTile(tile) &&
|
|
329
|
+
tile.declaration.kind !== "inherited" &&
|
|
330
|
+
tile.declaration.kind !== "opaque";
|
|
320
331
|
|
|
321
332
|
/** The mapping a control has NOW, one row per tile, for the dialog to open on. */
|
|
322
333
|
export function mappingOf(
|
|
@@ -324,7 +335,9 @@ export function mappingOf(
|
|
|
324
335
|
control: { name: string; field?: string; type?: string },
|
|
325
336
|
): MappingRow[] {
|
|
326
337
|
return document.tiles.map((tile) => {
|
|
327
|
-
const bound = (tile.filters ?? []).find(
|
|
338
|
+
const bound = (isQueryTile(tile) ? (tile.filters ?? []) : []).find(
|
|
339
|
+
(f) => f.given === control.name,
|
|
340
|
+
);
|
|
328
341
|
return {
|
|
329
342
|
// Ticked where the tile ALREADY carries this control, so the window
|
|
330
343
|
// opens on what is true rather than on what would be added. That is
|
|
@@ -390,6 +403,7 @@ export function declareControl(
|
|
|
390
403
|
*/
|
|
391
404
|
export function removeControl(draft: DashboardDocument, name: string): void {
|
|
392
405
|
for (const tile of draft.tiles) {
|
|
406
|
+
if (!isQueryTile(tile)) continue;
|
|
393
407
|
const kept = (tile.filters ?? []).filter((f) => f.given !== name);
|
|
394
408
|
if (kept.length > 0) tile.filters = kept;
|
|
395
409
|
else delete tile.filters;
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
* opening it half-understood. See {@link readDashboardDocument}.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
import type { ChartState } from "./chartLine";
|
|
25
|
+
|
|
24
26
|
/** One `import` line. The file needs both forms, and for different reasons. */
|
|
25
27
|
export type DashboardImport =
|
|
26
28
|
/** `import "../givens.malloy"` — the whole file's declarations. */
|
|
@@ -122,8 +124,10 @@ export type TileDeclaration =
|
|
|
122
124
|
| { kind: "opaque"; why: string }
|
|
123
125
|
| { kind: "inherited" };
|
|
124
126
|
|
|
125
|
-
/**
|
|
126
|
-
export interface
|
|
127
|
+
/** A tile that runs a view: a view shown on the page, plus how it is presented. */
|
|
128
|
+
export interface QueryTile {
|
|
129
|
+
/** Absent means a query tile, the API's default. */
|
|
130
|
+
kind?: "query";
|
|
127
131
|
/**
|
|
128
132
|
* The view name. For a tile declared in this file, assigned ONCE when the
|
|
129
133
|
* tile is added and never recomputed — deriving it from position would
|
|
@@ -151,11 +155,48 @@ export interface DashboardTile {
|
|
|
151
155
|
filters?: Array<{ field: string; given: string; op?: string }>;
|
|
152
156
|
label?: string;
|
|
153
157
|
subtitle?: string;
|
|
158
|
+
/**
|
|
159
|
+
* The chart line on the tile's wrapper. `"default"` removes the writer's line
|
|
160
|
+
* and, on a tile read from a file with none, is what absent means; an absent
|
|
161
|
+
* `chart` handed to the writer means unchanged. `"custom"` is a line the
|
|
162
|
+
* builder does not model, which it keeps and never writes.
|
|
163
|
+
*/
|
|
164
|
+
chart?: ChartState;
|
|
165
|
+
/** The chart lines behind a `"custom"` chart, as written; read-only, so a picker can say what it will not change. */
|
|
166
|
+
chartLines?: string[];
|
|
167
|
+
/** The chart tags the tile's view carries, when the catalog knows them: the writer negates only these. Never read from a file. */
|
|
168
|
+
chartCarried?: string[];
|
|
154
169
|
colspan?: number;
|
|
155
170
|
break?: boolean;
|
|
156
171
|
borderless?: boolean;
|
|
157
172
|
}
|
|
158
173
|
|
|
174
|
+
/**
|
|
175
|
+
* A markdown tile: prose between the query tiles, written as a `##|(markdown) <name>` block
|
|
176
|
+
* and listed in `tiles=[…]` as `<name> { kind=text }`. Its width and row break live on that
|
|
177
|
+
* list entry, since a block has no tags.
|
|
178
|
+
*/
|
|
179
|
+
export interface TextTile {
|
|
180
|
+
kind: "text";
|
|
181
|
+
/** The block's name and the list entry's: a bare identifier, unique among the text tiles. */
|
|
182
|
+
name: string;
|
|
183
|
+
markdown: string;
|
|
184
|
+
colspan?: number;
|
|
185
|
+
break?: boolean;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export type DashboardTile = QueryTile | TextTile;
|
|
189
|
+
|
|
190
|
+
export const isTextTile = (tile: DashboardTile): tile is TextTile =>
|
|
191
|
+
tile.kind === "text";
|
|
192
|
+
|
|
193
|
+
export const isQueryTile = (tile: DashboardTile): tile is QueryTile =>
|
|
194
|
+
tile.kind !== "text";
|
|
195
|
+
|
|
196
|
+
/** What a tile is called in the builder's own labels: a query tile's title, else its name. */
|
|
197
|
+
export const tileLabel = (tile: DashboardTile) =>
|
|
198
|
+
isQueryTile(tile) ? (tile.label ?? tile.name) : tile.name;
|
|
199
|
+
|
|
159
200
|
/**
|
|
160
201
|
* A source extension the dashboard DECLARES, holding tiles that read it.
|
|
161
202
|
*
|
|
@@ -182,11 +223,13 @@ export interface DashboardSource {
|
|
|
182
223
|
* the model.
|
|
183
224
|
*/
|
|
184
225
|
dimensions?: DashboardDimension[];
|
|
226
|
+
/** Givens the extension's own `where:`s read, which filter every tile on it. Read-only: never written. */
|
|
227
|
+
scopedBy?: string[];
|
|
185
228
|
}
|
|
186
229
|
|
|
187
230
|
/** A tile's identity across a reorder: what the grid keys on, a drag names and the writer matches. */
|
|
188
|
-
export const tileKey = (tile:
|
|
189
|
-
`${tile.source}.${tile.name}`;
|
|
231
|
+
export const tileKey = (tile: DashboardTile) =>
|
|
232
|
+
isTextTile(tile) ? `text.${tile.name}` : `${tile.source}.${tile.name}`;
|
|
190
233
|
|
|
191
234
|
/** `dimension: <name> is <expression>` in the dashboard's own extension. */
|
|
192
235
|
export interface DashboardDimension {
|
|
@@ -194,11 +237,16 @@ export interface DashboardDimension {
|
|
|
194
237
|
expression: string;
|
|
195
238
|
}
|
|
196
239
|
|
|
240
|
+
/** Which surface the file is: a notebook is the same file with one column. */
|
|
241
|
+
export type DocumentKind = "dashboard" | "notebook";
|
|
242
|
+
|
|
197
243
|
export interface DashboardDocument {
|
|
244
|
+
/** `## artifact { kind=… }`; the reader leaves it out for a dashboard. */
|
|
245
|
+
kind?: DocumentKind;
|
|
198
246
|
title: string;
|
|
199
247
|
/** The narrative header, as markdown. Emitted as `##"` lines. */
|
|
200
248
|
description?: string;
|
|
201
|
-
/** `# dashboard { columns=N }
|
|
249
|
+
/** `# dashboard { columns=N }` as the file has it; a notebook's grid is one column whatever it says. */
|
|
202
250
|
columns?: number;
|
|
203
251
|
/** `## artifact { autorun=false }`. Absent means autorun. */
|
|
204
252
|
autorun?: boolean;
|