@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
|
@@ -6,7 +6,11 @@ import { openDocument } from "./testing/fixtures";
|
|
|
6
6
|
import * as fs from "fs";
|
|
7
7
|
import * as path from "path";
|
|
8
8
|
import { blockAbove, readDashboardDocument, readFailed } from "./readDocument";
|
|
9
|
+
import { readForEditor } from "./readForEditor";
|
|
9
10
|
import { parseMalloy, parseRefused } from "./malloyTree";
|
|
11
|
+
import { queryTile } from "./testing/fixtures";
|
|
12
|
+
import { tileKey } from "./document";
|
|
13
|
+
import { newNotebookSource } from "../DocumentCreate/newNotebook";
|
|
10
14
|
|
|
11
15
|
const REPO = path.resolve(import.meta.dir, "../../../../..");
|
|
12
16
|
|
|
@@ -361,10 +365,7 @@ source: b is two extend {
|
|
|
361
365
|
view: y is vy
|
|
362
366
|
}`);
|
|
363
367
|
expect(doc.sources.map((s) => s.name)).toEqual(["a", "b"]);
|
|
364
|
-
expect(doc.tiles.map(
|
|
365
|
-
"a.x",
|
|
366
|
-
"b.y",
|
|
367
|
-
]);
|
|
368
|
+
expect(doc.tiles.map(tileKey)).toEqual(["a.x", "b.y"]);
|
|
368
369
|
});
|
|
369
370
|
|
|
370
371
|
it("reads a filter binding written as a refinement", async () => {
|
|
@@ -374,11 +375,11 @@ import "../m.malloy"
|
|
|
374
375
|
source: a is one extend {
|
|
375
376
|
view: x is vx + { where: products.brand ~ $BRAND }
|
|
376
377
|
}`);
|
|
377
|
-
expect(doc
|
|
378
|
+
expect(queryTile(doc, 0).declaration).toEqual({
|
|
378
379
|
kind: "reference",
|
|
379
380
|
from: "vx",
|
|
380
381
|
});
|
|
381
|
-
expect(doc
|
|
382
|
+
expect(queryTile(doc, 0).filters).toEqual([
|
|
382
383
|
{ field: "products.brand", given: "BRAND" },
|
|
383
384
|
]);
|
|
384
385
|
});
|
|
@@ -409,6 +410,25 @@ source: a is one extend {
|
|
|
409
410
|
]);
|
|
410
411
|
});
|
|
411
412
|
|
|
413
|
+
it("reads the givens an extension's own where: reads, compound or not", async () => {
|
|
414
|
+
const doc =
|
|
415
|
+
await read(`## artifact { title="T" tiles=["a -> x", "b -> y"] }
|
|
416
|
+
import "../m.malloy"
|
|
417
|
+
|
|
418
|
+
source: a is one extend {
|
|
419
|
+
where: region ~ $REGION, (brand ~ $BRAND or brand = null)
|
|
420
|
+
view: x is vx + { where: cat ~ $CATEGORY }
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
source: b is two extend {
|
|
424
|
+
view: y is vy
|
|
425
|
+
}`);
|
|
426
|
+
expect(doc.sources.map((source) => source.scopedBy)).toEqual([
|
|
427
|
+
["REGION", "BRAND"],
|
|
428
|
+
undefined,
|
|
429
|
+
]);
|
|
430
|
+
});
|
|
431
|
+
|
|
412
432
|
// Givens are the one declaration the parser's symbol tree does not cover.
|
|
413
433
|
it("reads a dashboard-local given", async () => {
|
|
414
434
|
const doc = await read(`##! experimental.givens
|
|
@@ -445,7 +465,7 @@ import "../m.malloy"
|
|
|
445
465
|
source: a is one extend {
|
|
446
466
|
view: x is vx + { where: category ~ $CATEGORY, where: created_at >= $SINCE, limit: 5 }
|
|
447
467
|
}`);
|
|
448
|
-
expect(doc
|
|
468
|
+
expect(queryTile(doc, 0).filters).toEqual([
|
|
449
469
|
{ field: "category", given: "CATEGORY" },
|
|
450
470
|
{ field: "created_at", given: "SINCE", op: ">=" },
|
|
451
471
|
]);
|
|
@@ -467,8 +487,8 @@ source: a is one extend {
|
|
|
467
487
|
aggregate: n is count()
|
|
468
488
|
}
|
|
469
489
|
}`);
|
|
470
|
-
expect(doc
|
|
471
|
-
expect(doc
|
|
490
|
+
expect(queryTile(doc, 0).declaration).toEqual({ kind: "inline" });
|
|
491
|
+
expect(queryTile(doc, 0).filters).toEqual([
|
|
472
492
|
{ field: "category", given: "CATEGORY" },
|
|
473
493
|
]);
|
|
474
494
|
});
|
|
@@ -484,7 +504,7 @@ source: a is one extend {
|
|
|
484
504
|
where: category ~ $CATEGORY
|
|
485
505
|
}
|
|
486
506
|
}`);
|
|
487
|
-
expect(last
|
|
507
|
+
expect(queryTile(last, 0).filters).toEqual([
|
|
488
508
|
{ field: "category", given: "CATEGORY" },
|
|
489
509
|
]);
|
|
490
510
|
|
|
@@ -498,7 +518,7 @@ source: a is one extend {
|
|
|
498
518
|
aggregate: n is count()
|
|
499
519
|
}
|
|
500
520
|
}`);
|
|
501
|
-
expect(middle
|
|
521
|
+
expect(queryTile(middle, 0).filters).toEqual([
|
|
502
522
|
{ field: "category", given: "CATEGORY" },
|
|
503
523
|
]);
|
|
504
524
|
});
|
|
@@ -519,7 +539,7 @@ source: a is one extend {
|
|
|
519
539
|
}
|
|
520
540
|
}
|
|
521
541
|
}`);
|
|
522
|
-
expect(doc
|
|
542
|
+
expect(queryTile(doc, 0).filters).toBeUndefined();
|
|
523
543
|
});
|
|
524
544
|
|
|
525
545
|
// "Whose ENTIRE text is one or more binding clauses" — `a ~ $A and c = 1`
|
|
@@ -535,7 +555,7 @@ source: a is one extend {
|
|
|
535
555
|
aggregate: n is count()
|
|
536
556
|
}
|
|
537
557
|
}`);
|
|
538
|
-
expect(doc
|
|
558
|
+
expect(queryTile(doc, 0).filters).toBeUndefined();
|
|
539
559
|
});
|
|
540
560
|
|
|
541
561
|
// `cleanBindingClauses` accepts a following statement keyword as a clean
|
|
@@ -557,7 +577,7 @@ source: a is one extend {
|
|
|
557
577
|
where: a ~ $A, aggregate: n is count(), where: b ~ $B
|
|
558
578
|
}
|
|
559
579
|
}`);
|
|
560
|
-
expect(doc
|
|
580
|
+
expect(queryTile(doc, 0).filters).toEqual([
|
|
561
581
|
{ field: "a", given: "A" },
|
|
562
582
|
{ field: "b", given: "B" },
|
|
563
583
|
]);
|
|
@@ -575,7 +595,7 @@ source: a is one extend {
|
|
|
575
595
|
where: a ~ $A, where: b ~ $B
|
|
576
596
|
}
|
|
577
597
|
}`);
|
|
578
|
-
expect(doc
|
|
598
|
+
expect(queryTile(doc, 0).filters).toEqual([
|
|
579
599
|
{ field: "a", given: "A" },
|
|
580
600
|
{ field: "b", given: "B" },
|
|
581
601
|
]);
|
|
@@ -597,7 +617,7 @@ source: a is one extend {
|
|
|
597
617
|
select: category, n
|
|
598
618
|
}
|
|
599
619
|
}`);
|
|
600
|
-
expect(doc
|
|
620
|
+
expect(queryTile(doc, 0).filters).toEqual([
|
|
601
621
|
{ field: "category", given: "CATEGORY" },
|
|
602
622
|
]);
|
|
603
623
|
});
|
|
@@ -609,7 +629,7 @@ import "../m.malloy"
|
|
|
609
629
|
source: a is one extend {
|
|
610
630
|
view: x is { aggregate: n is count() where: category ~ $CATEGORY }
|
|
611
631
|
}`);
|
|
612
|
-
expect(doc
|
|
632
|
+
expect(queryTile(doc, 0).filters).toEqual([
|
|
613
633
|
{ field: "category", given: "CATEGORY" },
|
|
614
634
|
]);
|
|
615
635
|
});
|
|
@@ -624,7 +644,7 @@ import "../m.malloy"
|
|
|
624
644
|
source: a is one extend {
|
|
625
645
|
view: x is { where: category ~ $CATEGORY, aggregate: n is count() }
|
|
626
646
|
}`);
|
|
627
|
-
expect(doc
|
|
647
|
+
expect(queryTile(doc, 0).filters).toEqual([
|
|
628
648
|
{ field: "category", given: "CATEGORY" },
|
|
629
649
|
]);
|
|
630
650
|
});
|
|
@@ -640,7 +660,7 @@ source: a is one extend {
|
|
|
640
660
|
aggregate: n is count()
|
|
641
661
|
}
|
|
642
662
|
}`);
|
|
643
|
-
expect(opening
|
|
663
|
+
expect(queryTile(opening, 0).filters).toEqual([
|
|
644
664
|
{ field: "category", given: "CATEGORY" },
|
|
645
665
|
]);
|
|
646
666
|
|
|
@@ -652,7 +672,7 @@ source: a is one extend {
|
|
|
652
672
|
aggregate: n is count()
|
|
653
673
|
where: category ~ $CATEGORY }
|
|
654
674
|
}`);
|
|
655
|
-
expect(closing
|
|
675
|
+
expect(queryTile(closing, 0).filters).toEqual([
|
|
656
676
|
{ field: "category", given: "CATEGORY" },
|
|
657
677
|
]);
|
|
658
678
|
});
|
|
@@ -668,7 +688,7 @@ source: a is one extend {
|
|
|
668
688
|
|
|
669
689
|
view: x is { aggregate: n is count() }
|
|
670
690
|
}`);
|
|
671
|
-
expect(doc
|
|
691
|
+
expect(queryTile(doc, 0).filters).toBeUndefined();
|
|
672
692
|
});
|
|
673
693
|
});
|
|
674
694
|
|
|
@@ -732,6 +752,46 @@ source: a is one extend {
|
|
|
732
752
|
});
|
|
733
753
|
});
|
|
734
754
|
|
|
755
|
+
describe("readDashboardDocument: line endings", () => {
|
|
756
|
+
// A checkout with CRLF endings is the same document, so every field reads the same.
|
|
757
|
+
const SOURCES: Record<string, string> = {
|
|
758
|
+
"one-line tag, notes and tile tags": SIMPLE,
|
|
759
|
+
"a block tag and a text tile": newNotebookSource({
|
|
760
|
+
title: "Sales",
|
|
761
|
+
modelPath: "m.malloy",
|
|
762
|
+
source: "orders",
|
|
763
|
+
view: "by_brand",
|
|
764
|
+
}),
|
|
765
|
+
"a block description and a given contract": `##! experimental.givens
|
|
766
|
+
##|"
|
|
767
|
+
Block prose
|
|
768
|
+
|##
|
|
769
|
+
##| artifact { title="T"
|
|
770
|
+
tiles=["a -> x"]
|
|
771
|
+
}
|
|
772
|
+
|##
|
|
773
|
+
import { one } from "../m.malloy"
|
|
774
|
+
|
|
775
|
+
# label="Category" control=select
|
|
776
|
+
given: CATEGORY :: filter<string> is f''
|
|
777
|
+
|
|
778
|
+
source: a is one extend {
|
|
779
|
+
# colspan=6
|
|
780
|
+
view: x is vx + { where: category ~ $CATEGORY }
|
|
781
|
+
}`,
|
|
782
|
+
};
|
|
783
|
+
for (const [name, source] of Object.entries(SOURCES))
|
|
784
|
+
it(`reads ${name} the same with CRLF`, async () => {
|
|
785
|
+
const lf = await readDashboardDocument(source);
|
|
786
|
+
if (readFailed(lf)) throw new Error(lf.reason);
|
|
787
|
+
const crlf = await readDashboardDocument(
|
|
788
|
+
source.replace(/\n/g, "\r\n"),
|
|
789
|
+
);
|
|
790
|
+
if (readFailed(crlf)) throw new Error(crlf.reason);
|
|
791
|
+
expect(crlf.document).toEqual(lf.document);
|
|
792
|
+
});
|
|
793
|
+
});
|
|
794
|
+
|
|
735
795
|
describe("readDashboardDocument: what it refuses", () => {
|
|
736
796
|
// All-or-nothing, and every refusal names what it could not understand.
|
|
737
797
|
// "Cannot open this dashboard" with no reason reads as a bug.
|
|
@@ -772,11 +832,54 @@ describe("readDashboardDocument: what it refuses", () => {
|
|
|
772
832
|
const doc = await read(
|
|
773
833
|
`## artifact { title="T" tiles=["a -> x"] }\nimport "../m.malloy"\nsource: a is one extend {\n # colspan=6\n view: x is { aggregate: n }\n}`,
|
|
774
834
|
);
|
|
775
|
-
expect(doc
|
|
835
|
+
expect(queryTile(doc, 0).declaration).toEqual({ kind: "inline" });
|
|
776
836
|
expect(doc.tiles[0].colspan).toBe(6);
|
|
777
837
|
});
|
|
778
838
|
});
|
|
779
839
|
|
|
840
|
+
// The server serves such a file; the builder's tag rewrites only know `artifact { … }` leading.
|
|
841
|
+
describe("a tag whose artifact property is not the first", () => {
|
|
842
|
+
const rest = SIMPLE.split("\n").slice(5).join("\n");
|
|
843
|
+
const refused = async (text: string, modelPath?: string) => {
|
|
844
|
+
const result = await readDashboardDocument(text, modelPath);
|
|
845
|
+
if (!readFailed(result)) throw new Error("expected a refusal");
|
|
846
|
+
return result;
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
it("is refused with the reason, not read as untagged", async () => {
|
|
850
|
+
const result = await refused(
|
|
851
|
+
`## dashboard { columns=2 } artifact { title="Probe" tiles=["a -> by_cat"] }\n${rest}`,
|
|
852
|
+
);
|
|
853
|
+
expect(result.reason).toContain("`artifact { … }` first");
|
|
854
|
+
expect(result.reason).not.toContain("No `## artifact");
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
it("is refused in a ##| block too", async () => {
|
|
858
|
+
const result = await refused(
|
|
859
|
+
`##| dashboard { columns=2 }\n artifact { title="Probe" tiles=["a -> by_cat"] }\n|##\n${rest}`,
|
|
860
|
+
);
|
|
861
|
+
expect(result.reason).toContain("`artifact { … }` first");
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
it("is refused, not converted, for a cell-format notebook", async () => {
|
|
865
|
+
const open = await readForEditor(
|
|
866
|
+
`##! experimental.givens\n## dashboard { columns=2 } artifact { kind=notebook title="T" }\nrun: a -> by_cat`,
|
|
867
|
+
"notebooks/n.malloy",
|
|
868
|
+
);
|
|
869
|
+
expect(open.ok === false && open.reason).toContain(
|
|
870
|
+
"`artifact { … }` first",
|
|
871
|
+
);
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
it("still opens when artifact leads and another property follows", async () => {
|
|
875
|
+
const doc = await read(
|
|
876
|
+
`## artifact { title="Probe" tiles=["a -> by_cat"] } dashboard { columns=2 }\n${rest}`,
|
|
877
|
+
);
|
|
878
|
+
expect(doc.title).toBe("Probe");
|
|
879
|
+
expect(doc.columns).toBe(2);
|
|
880
|
+
});
|
|
881
|
+
});
|
|
882
|
+
|
|
780
883
|
/**
|
|
781
884
|
* The tripwire. All-or-nothing refusal is only reasonable while real dashboards
|
|
782
885
|
* open, so this asserts that every composite dashboard in the repository does.
|
|
@@ -835,11 +938,20 @@ describe("every composite dashboard in the repository opens", () => {
|
|
|
835
938
|
*/
|
|
836
939
|
describe("the compiler stays lazy", () => {
|
|
837
940
|
it("is never imported statically", () => {
|
|
838
|
-
const
|
|
839
|
-
path.join(import.meta.dir, "
|
|
840
|
-
|
|
941
|
+
const read = (file: string) =>
|
|
942
|
+
fs.readFileSync(path.join(import.meta.dir, file), "utf8");
|
|
943
|
+
const staticImport = /^\s*import\s[^(]*@malloydata\/malloy"/m;
|
|
944
|
+
expect(read("malloyTree.ts")).not.toMatch(staticImport);
|
|
945
|
+
expect(read("legacyNotebook.ts")).not.toMatch(staticImport);
|
|
946
|
+
expect(read("malloyTree.ts")).toContain("await loadMalloy()");
|
|
947
|
+
expect(read("loadMalloy.ts")).toContain(
|
|
948
|
+
'await import("@malloydata/malloy")',
|
|
841
949
|
);
|
|
842
|
-
|
|
843
|
-
|
|
950
|
+
for (const pkg of ["malloy-tag", "malloy-query-builder"])
|
|
951
|
+
expect(read("loadMalloy.ts")).toContain(
|
|
952
|
+
`await import("@malloydata/${pkg}")`,
|
|
953
|
+
);
|
|
954
|
+
for (const file of ["readDocument.ts", "legacyNotebook.ts"])
|
|
955
|
+
expect(read(file)).not.toContain('import("@malloydata/malloy-tag")');
|
|
844
956
|
});
|
|
845
957
|
});
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
+
import {
|
|
5
|
+
chartLinesOf,
|
|
6
|
+
chartStateOfTagLines,
|
|
7
|
+
type ChartState,
|
|
8
|
+
} from "./chartLine";
|
|
4
9
|
import type {
|
|
5
10
|
DashboardDocument,
|
|
6
11
|
DashboardDrill,
|
|
@@ -9,18 +14,25 @@ import type {
|
|
|
9
14
|
DashboardTile,
|
|
10
15
|
LocalGiven,
|
|
11
16
|
} from "./document";
|
|
17
|
+
import { isTextTile } from "./document";
|
|
18
|
+
import { loadMalloyTag } from "./loadMalloy";
|
|
19
|
+
import { parseTagLines } from "./tagParse";
|
|
12
20
|
import {
|
|
13
21
|
parseMalloy,
|
|
14
22
|
parseRefused,
|
|
23
|
+
readTileList,
|
|
15
24
|
type ParsedMalloy,
|
|
16
25
|
type TreeStage,
|
|
17
26
|
type TreeView,
|
|
18
27
|
} from "./malloyTree";
|
|
19
28
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
ARTIFACT_NOT_FIRST,
|
|
30
|
+
artifactLeads,
|
|
31
|
+
artifactTag as locateArtifactTag,
|
|
22
32
|
descriptionNotes,
|
|
23
|
-
|
|
33
|
+
readPath,
|
|
34
|
+
splitSourceLines,
|
|
35
|
+
tagAnnotation,
|
|
24
36
|
tileSteps,
|
|
25
37
|
} from "./malloyText";
|
|
26
38
|
|
|
@@ -54,6 +66,8 @@ export interface ReadFailure {
|
|
|
54
66
|
reason: string;
|
|
55
67
|
/** 1-based, for a message that can point at the line. */
|
|
56
68
|
line?: number;
|
|
69
|
+
/** The file is a `kind=notebook` in the run-cell format, which `convertLegacyNotebook` turns into a layout notebook. */
|
|
70
|
+
legacyNotebook?: true;
|
|
57
71
|
}
|
|
58
72
|
|
|
59
73
|
export type ReadResult =
|
|
@@ -129,26 +143,17 @@ export function blockAbove(
|
|
|
129
143
|
/** Just the text of a block's tags, which is what `parseAnnotation` takes. */
|
|
130
144
|
const tagText = (tags: Array<{ text: string }>) => tags.map((t) => t.text);
|
|
131
145
|
|
|
132
|
-
/** The
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
|
|
146
|
+
/** The tile's `chart` property, absent when its wrapper carries no chart line; a custom one also carries the lines. */
|
|
147
|
+
function chartField(tags: Array<{ text: string }>): {
|
|
148
|
+
chart?: ChartState;
|
|
149
|
+
chartLines?: string[];
|
|
136
150
|
} {
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (
|
|
144
|
-
text.startsWith("##") &&
|
|
145
|
-
!text.startsWith('##"') &&
|
|
146
|
-
!text.startsWith("##!") &&
|
|
147
|
-
!(note?.level === 2 && !note.block)
|
|
148
|
-
)
|
|
149
|
-
artifact.push(text);
|
|
150
|
-
}
|
|
151
|
-
return { description: descriptionNotes(lines).text, artifact };
|
|
151
|
+
const lines = tagText(tags);
|
|
152
|
+
const chart = chartStateOfTagLines(lines);
|
|
153
|
+
if (chart === undefined) return {};
|
|
154
|
+
return chart === "custom"
|
|
155
|
+
? { chart, chartLines: chartLinesOf(lines) }
|
|
156
|
+
: { chart };
|
|
152
157
|
}
|
|
153
158
|
|
|
154
159
|
/**
|
|
@@ -169,7 +174,11 @@ function filtersOf(
|
|
|
169
174
|
for (const clause of where.clauses) {
|
|
170
175
|
if (!clause.binding) continue;
|
|
171
176
|
const { field, op, given } = clause.binding;
|
|
172
|
-
out.push({
|
|
177
|
+
out.push({
|
|
178
|
+
field: readPath(field),
|
|
179
|
+
given,
|
|
180
|
+
...(op === "~" ? {} : { op }),
|
|
181
|
+
});
|
|
173
182
|
}
|
|
174
183
|
return out.length > 0 ? out : undefined;
|
|
175
184
|
}
|
|
@@ -266,22 +275,30 @@ function gridWidth(
|
|
|
266
275
|
return Number.isInteger(value) && value >= 1 ? value : undefined;
|
|
267
276
|
}
|
|
268
277
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const key = artifactLine.search(/tiles\s*=\s*\[/);
|
|
272
|
-
if (key < 0) return [];
|
|
273
|
-
const open = artifactLine.indexOf("[", key);
|
|
274
|
-
const close = artifactLine.indexOf("]", open);
|
|
275
|
-
if (close < 0) return [];
|
|
276
|
-
const list = artifactLine.slice(open + 1, close);
|
|
277
|
-
return [...list.matchAll(/"([^"]+)"/g)].map((m) => m[1]);
|
|
278
|
-
}
|
|
278
|
+
const QUOTED_ENTRY = /^"((?:[^"\\]|\\.)+)"$/;
|
|
279
|
+
const TEXT_ENTRY = /^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;
|
|
279
280
|
|
|
281
|
+
/** Refuses rather than throws: `Tag.text()` throws on a malformed date literal such as `@2024-13-01`, and dropping the value would lose it on the next save. */
|
|
280
282
|
export async function readDashboardDocument(
|
|
281
283
|
sourceText: string,
|
|
284
|
+
modelPath?: string,
|
|
285
|
+
): Promise<ReadResult> {
|
|
286
|
+
try {
|
|
287
|
+
return await readDocumentText(sourceText, modelPath);
|
|
288
|
+
} catch (error) {
|
|
289
|
+
return {
|
|
290
|
+
ok: false,
|
|
291
|
+
reason: `A value in this file's tags cannot be read (${error instanceof Error ? error.message : String(error)}), so it cannot be opened in the builder.`,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async function readDocumentText(
|
|
297
|
+
sourceText: string,
|
|
298
|
+
modelPath: string | undefined,
|
|
282
299
|
): Promise<ReadResult> {
|
|
283
|
-
const { parseAnnotation } = await
|
|
284
|
-
const lines = sourceText
|
|
300
|
+
const { parseAnnotation } = await loadMalloyTag();
|
|
301
|
+
const lines = splitSourceLines(sourceText);
|
|
285
302
|
|
|
286
303
|
const parse = await parseMalloy(sourceText);
|
|
287
304
|
if (parseRefused(parse))
|
|
@@ -292,24 +309,52 @@ export async function readDashboardDocument(
|
|
|
292
309
|
};
|
|
293
310
|
const parsed = parse.parsed;
|
|
294
311
|
|
|
295
|
-
const
|
|
296
|
-
const
|
|
297
|
-
if (
|
|
312
|
+
const description = descriptionNotes(lines).text;
|
|
313
|
+
const artifactAt = locateArtifactTag(lines);
|
|
314
|
+
if (artifactAt === undefined) {
|
|
298
315
|
return {
|
|
299
316
|
ok: false,
|
|
300
317
|
reason:
|
|
301
318
|
"No `## artifact { … }` tag, so this file is not a composite dashboard.",
|
|
302
319
|
};
|
|
303
320
|
}
|
|
321
|
+
if (!artifactLeads(artifactAt.text))
|
|
322
|
+
return {
|
|
323
|
+
ok: false,
|
|
324
|
+
reason: ARTIFACT_NOT_FIRST,
|
|
325
|
+
line: artifactAt.from + 1,
|
|
326
|
+
};
|
|
304
327
|
|
|
305
|
-
const tag = parseAnnotation
|
|
328
|
+
const { tag, errors: tagErrors } = parseTagLines(parseAnnotation, [
|
|
329
|
+
tagAnnotation(artifactAt.text),
|
|
330
|
+
]);
|
|
306
331
|
const artifactTag = tag?.tag("artifact");
|
|
307
|
-
const
|
|
308
|
-
|
|
332
|
+
const tagKind = artifactTag?.text("kind");
|
|
333
|
+
// The server's rule: a tag that names no kind takes the folder's.
|
|
334
|
+
const kind =
|
|
335
|
+
tagKind === "notebook" ||
|
|
336
|
+
(tagKind !== "dashboard" && modelPath?.startsWith("notebooks/"))
|
|
337
|
+
? ("notebook" as const)
|
|
338
|
+
: undefined;
|
|
339
|
+
const list = readTileList(artifactAt.text);
|
|
340
|
+
if (list === undefined) {
|
|
341
|
+
if (tagErrors.length > 0)
|
|
342
|
+
return {
|
|
343
|
+
ok: false,
|
|
344
|
+
reason: `The \`## artifact\` tag does not parse: ${tagErrors[0]}`,
|
|
345
|
+
};
|
|
346
|
+
// A notebook is told from a layout one by whether it lists tiles at all.
|
|
347
|
+
if (kind === "notebook")
|
|
348
|
+
return {
|
|
349
|
+
ok: false,
|
|
350
|
+
legacyNotebook: true,
|
|
351
|
+
reason:
|
|
352
|
+
"This notebook is in the cell format, with no `tiles=[…]` list.",
|
|
353
|
+
};
|
|
309
354
|
return {
|
|
310
355
|
ok: false,
|
|
311
356
|
reason:
|
|
312
|
-
"The `## artifact` tag
|
|
357
|
+
"The `## artifact` tag has no `tiles=[…]` list the builder can read.",
|
|
313
358
|
};
|
|
314
359
|
}
|
|
315
360
|
|
|
@@ -329,6 +374,12 @@ export async function readDashboardDocument(
|
|
|
329
374
|
name: d.name,
|
|
330
375
|
expression: d.expression,
|
|
331
376
|
}));
|
|
377
|
+
const scopedBy = new Set(
|
|
378
|
+
source.wheres.flatMap((where) =>
|
|
379
|
+
where.clauses.flatMap((clause) => clause.givens),
|
|
380
|
+
),
|
|
381
|
+
);
|
|
382
|
+
if (scopedBy.size > 0) entry.scopedBy = Array.from(scopedBy);
|
|
332
383
|
sources.push(entry);
|
|
333
384
|
|
|
334
385
|
// A `# drill` is a tag on a dimension's declaration, so the dimensions
|
|
@@ -357,8 +408,40 @@ export async function readDashboardDocument(
|
|
|
357
408
|
}
|
|
358
409
|
|
|
359
410
|
const tiles: DashboardTile[] = [];
|
|
360
|
-
for (const
|
|
361
|
-
const
|
|
411
|
+
for (const { text: entryText } of list.entries) {
|
|
412
|
+
const quoted = QUOTED_ENTRY.exec(entryText);
|
|
413
|
+
const textName = quoted ? undefined : TEXT_ENTRY.exec(entryText)?.[1];
|
|
414
|
+
if (textName !== undefined) {
|
|
415
|
+
const textTag = parseAnnotation([`# ${entryText}`]).tag?.tag(textName);
|
|
416
|
+
if (textTag?.text("kind") !== "text") {
|
|
417
|
+
return {
|
|
418
|
+
ok: false,
|
|
419
|
+
reason:
|
|
420
|
+
`The tile \`${entryText}\` is neither a quoted \`source -> view\` ` +
|
|
421
|
+
`expression nor a \`${textName} { kind=text }\` entry, which are ` +
|
|
422
|
+
`the only forms the builder can lay out.`,
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
if (tiles.some((tile) => isTextTile(tile) && tile.name === textName)) {
|
|
426
|
+
return {
|
|
427
|
+
ok: false,
|
|
428
|
+
reason: `Two text tiles are named \`${textName}\`, so the builder cannot tell them apart.`,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
const colspan = gridWidth(textTag, "colspan");
|
|
432
|
+
tiles.push({
|
|
433
|
+
kind: "text",
|
|
434
|
+
name: textName,
|
|
435
|
+
markdown:
|
|
436
|
+
parsed.textBlocks.find((block) => block.name === textName)
|
|
437
|
+
?.body ?? "",
|
|
438
|
+
...(colspan === undefined ? {} : { colspan }),
|
|
439
|
+
...(textTag.has("break") ? { break: true } : {}),
|
|
440
|
+
});
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
const entry = quoted?.[1] ?? entryText;
|
|
444
|
+
const steps = quoted ? tileSteps(entry) : undefined;
|
|
362
445
|
if (!steps) {
|
|
363
446
|
return {
|
|
364
447
|
ok: false,
|
|
@@ -415,6 +498,7 @@ export async function readDashboardDocument(
|
|
|
415
498
|
...(t?.numeric("colspan") !== undefined
|
|
416
499
|
? { colspan: t.numeric("colspan") as number }
|
|
417
500
|
: {}),
|
|
501
|
+
...chartField(view.tags),
|
|
418
502
|
...(t?.has("break") ? { break: true } : {}),
|
|
419
503
|
...(t?.has("borderless") ? { borderless: true } : {}),
|
|
420
504
|
});
|
|
@@ -441,6 +525,7 @@ export async function readDashboardDocument(
|
|
|
441
525
|
...(t?.numeric("colspan") !== undefined
|
|
442
526
|
? { colspan: t.numeric("colspan") as number }
|
|
443
527
|
: {}),
|
|
528
|
+
...chartField(view.tags),
|
|
444
529
|
...(t?.has("break") ? { break: true } : {}),
|
|
445
530
|
...(t?.has("borderless") ? { borderless: true } : {}),
|
|
446
531
|
});
|
|
@@ -467,6 +552,7 @@ export async function readDashboardDocument(
|
|
|
467
552
|
return {
|
|
468
553
|
ok: true,
|
|
469
554
|
document: {
|
|
555
|
+
...(kind ? { kind } : {}),
|
|
470
556
|
title: artifactTag?.text("title") ?? "",
|
|
471
557
|
...(description ? { description } : {}),
|
|
472
558
|
...(columnsTag === undefined ? {} : { columns: columnsTag }),
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import * as fs from "fs";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
import { readForEditor } from "./readForEditor";
|
|
8
|
+
|
|
9
|
+
const REPO = path.resolve(import.meta.dir, "../../../../..");
|
|
10
|
+
const LEGACY = fs
|
|
11
|
+
.readFileSync(
|
|
12
|
+
path.join(REPO, "examples/storefront/notebooks/category-review.malloy"),
|
|
13
|
+
"utf8",
|
|
14
|
+
)
|
|
15
|
+
.replace(/\r\n/g, "\n");
|
|
16
|
+
|
|
17
|
+
describe("readForEditor", () => {
|
|
18
|
+
it("opens a layout file as it is, with no conversion", async () => {
|
|
19
|
+
const result = await readForEditor(
|
|
20
|
+
`## artifact { title="D" tiles=["a -> x"] }\nsource: a is b extend {\n view: x is v\n}\n`,
|
|
21
|
+
);
|
|
22
|
+
expect(result.ok).toBe(true);
|
|
23
|
+
expect(result.ok && result.conversion).toBeUndefined();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("converts a cell-format notebook, keeping the disk text to hand back", async () => {
|
|
27
|
+
const result = await readForEditor(LEGACY);
|
|
28
|
+
if (result.ok === false) throw new Error(result.reason);
|
|
29
|
+
expect(result.conversion?.from).toBe(LEGACY);
|
|
30
|
+
expect(result.conversion?.to).toContain(
|
|
31
|
+
"tiles=[\n text_1 { kind=text }",
|
|
32
|
+
);
|
|
33
|
+
expect(result.document.kind).toBe("notebook");
|
|
34
|
+
expect(result.document.tiles).toHaveLength(7);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("refuses a conversion it cannot make, naming the line", async () => {
|
|
38
|
+
const result = await readForEditor(
|
|
39
|
+
`## artifact { kind=notebook }\nimport { o } from "../m.malloy"\n\nrun: o extend { dimension: z is 1 } -> { select: z }\n`,
|
|
40
|
+
);
|
|
41
|
+
expect(result.ok).toBe(false);
|
|
42
|
+
expect(result.ok === false && result.reason).toMatch(/line 4/i);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("says why a file that is not a notebook will not open, with its line", async () => {
|
|
46
|
+
const result = await readForEditor(`source: a is b\n`);
|
|
47
|
+
expect(result.ok).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("a tag that names no kind takes the folder's, as the server does", () => {
|
|
51
|
+
const LAYOUT = `## artifact { title="D" tiles=["a -> x"] }\nsource: a is b extend {\n view: x is v\n}\n`;
|
|
52
|
+
|
|
53
|
+
it("opens a kind-less layout file in notebooks/ as a notebook", async () => {
|
|
54
|
+
const result = await readForEditor(LAYOUT, "notebooks/d.malloy");
|
|
55
|
+
expect(result.ok && result.document.kind).toBe("notebook");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("opens it as a dashboard in dashboards/, and when the tag says so in notebooks/", async () => {
|
|
59
|
+
const inDashboards = await readForEditor(
|
|
60
|
+
LAYOUT,
|
|
61
|
+
"dashboards/d.malloy",
|
|
62
|
+
);
|
|
63
|
+
expect(inDashboards.ok && inDashboards.document.kind).toBeUndefined();
|
|
64
|
+
const tagged = await readForEditor(
|
|
65
|
+
LAYOUT.replace("{ title", "{ kind=dashboard title"),
|
|
66
|
+
"notebooks/d.malloy",
|
|
67
|
+
);
|
|
68
|
+
expect(tagged.ok && tagged.document.kind).toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("converts a kind-less cell-format file in notebooks/ rather than refusing it", async () => {
|
|
72
|
+
const kindless = LEGACY.replace("kind=notebook ", "");
|
|
73
|
+
expect(kindless).not.toBe(LEGACY);
|
|
74
|
+
const result = await readForEditor(kindless, "notebooks/c.malloy");
|
|
75
|
+
if (result.ok === false) throw new Error(result.reason);
|
|
76
|
+
expect(result.conversion?.from).toBe(kindless);
|
|
77
|
+
expect(result.document.kind).toBe("notebook");
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|