@malloy-publisher/sdk 0.9.13 → 0.9.15
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/RenderedResult-BClN_PG6.cjs.js +154 -0
- package/dist/{RenderedResult-DnBtf-cI.es.js → RenderedResult-YBzVMVH2.es.js} +295 -234
- package/dist/{ServerProvider-BV7IoDMR.es.js → ServerProvider-D7neZcTk.es.js} +283 -265
- package/dist/ServerProvider-e2369oom.cjs.js +1 -0
- package/dist/builder/index.cjs.js +80 -79
- package/dist/builder/index.es.js +7430 -6548
- package/dist/client/api.d.ts +30 -6
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/DashboardGrid.d.ts +49 -1
- package/dist/components/Dashboard/DashboardTile.d.ts +5 -2
- package/dist/components/Dashboard/DashboardView.d.ts +9 -2
- package/dist/components/Dashboard/index.d.ts +1 -1
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
- package/dist/components/Dashboard/useStuck.d.ts +18 -12
- package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
- package/dist/components/RenderedResult/ResultContainer.d.ts +11 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +5 -1
- package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
- package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
- package/dist/components/RenderedResult/resultSizing.d.ts +42 -6
- package/dist/components/Report/Report.d.ts +7 -1
- package/dist/components/Report/ReportPage.d.ts +7 -0
- package/dist/components/Report/layoutRules.d.ts +45 -0
- package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
- package/dist/components/ReportBuilder/BuilderGrid.d.ts +14 -1
- package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
- package/dist/components/ReportBuilder/EditorSurface.d.ts +17 -1
- package/dist/components/ReportBuilder/ReportEditor.d.ts +18 -0
- package/dist/components/ReportBuilder/TileFrame.d.ts +33 -1
- package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
- package/dist/components/ReportBuilder/catalog.d.ts +23 -0
- package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
- package/dist/components/ReportBuilder/controls.d.ts +2 -2
- package/dist/components/ReportBuilder/document.d.ts +53 -5
- package/dist/components/ReportBuilder/imports.d.ts +7 -0
- package/dist/components/ReportBuilder/placement.d.ts +75 -0
- package/dist/components/ReportBuilder/preview.d.ts +59 -10
- package/dist/components/ReportBuilder/sortable.d.ts +3 -1
- package/dist/components/ReportBuilder/useTileHeight.d.ts +39 -0
- package/dist/components/ReportBuilder/useTileReorder.d.ts +27 -3
- package/dist/components/ReportBuilder/useTileResize.d.ts +8 -0
- package/dist/index.cjs.js +7 -7
- package/dist/index.es.js +3328 -3287
- package/dist/text/index.es.js +1 -1
- package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
- package/dist/theme/resolveTheme.d.ts +15 -0
- package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-BGk38oaW.es.js} +5097 -4805
- package/dist/useCompiledDocument-D9t5ry_t.cjs.js +142 -0
- package/dist/utils/blankQuoted.d.ts +15 -0
- package/package.json +1 -1
- package/src/components/Dashboard/DashboardGrid.tsx +127 -10
- package/src/components/Dashboard/DashboardTile.tsx +11 -1
- package/src/components/Dashboard/DashboardView.tsx +63 -10
- package/src/components/Dashboard/TileCard.tsx +6 -0
- package/src/components/Dashboard/index.ts +1 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
- package/src/components/Dashboard/tileHeight.spec.ts +72 -0
- package/src/components/Dashboard/useStuck.ts +76 -28
- package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
- package/src/components/Package/NewDocumentDialog.tsx +10 -11
- package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
- package/src/components/RenderedResult/RenderedResult.tsx +21 -6
- package/src/components/RenderedResult/ResultContainer.tsx +60 -7
- package/src/components/RenderedResult/ResultPanel.tsx +21 -1
- package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
- package/src/components/RenderedResult/chartPresentation.ts +166 -0
- package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
- package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
- package/src/components/RenderedResult/resultSizing.ts +65 -11
- package/src/components/Report/Report.spec.tsx +19 -0
- package/src/components/Report/Report.tsx +8 -1
- package/src/components/Report/ReportPage.tsx +13 -1
- package/src/components/Report/layoutRules.spec.ts +43 -3
- package/src/components/Report/layoutRules.ts +70 -0
- package/src/components/Report/tileOverflow.spec.tsx +162 -0
- package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
- package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
- package/src/components/ReportBuilder/BuilderBar.tsx +1 -1
- package/src/components/ReportBuilder/BuilderDialogs.tsx +20 -0
- package/src/components/ReportBuilder/BuilderGrid.tsx +126 -20
- package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
- package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
- package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
- package/src/components/ReportBuilder/EditorSurface.tsx +110 -28
- package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
- package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
- package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
- package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
- package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
- package/src/components/ReportBuilder/ReportBuilder.spec.tsx +143 -2
- package/src/components/ReportBuilder/ReportBuilder.tsx +73 -19
- package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
- package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
- package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +292 -0
- package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
- package/src/components/ReportBuilder/ReportEditor.tsx +35 -0
- package/src/components/ReportBuilder/TileFrame.tsx +251 -6
- package/src/components/ReportBuilder/TileMenu.tsx +259 -20
- package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
- package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
- package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
- package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
- package/src/components/ReportBuilder/catalog.ts +90 -37
- package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
- package/src/components/ReportBuilder/chartLine.ts +80 -2
- package/src/components/ReportBuilder/controls.ts +4 -3
- package/src/components/ReportBuilder/document.ts +65 -7
- package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
- package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
- package/src/components/ReportBuilder/imports.ts +1 -1
- package/src/components/ReportBuilder/invariants.spec.ts +18 -10
- package/src/components/ReportBuilder/layout.ts +3 -0
- package/src/components/ReportBuilder/placement.spec.ts +193 -0
- package/src/components/ReportBuilder/placement.ts +250 -0
- package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
- package/src/components/ReportBuilder/preview.spec.ts +151 -11
- package/src/components/ReportBuilder/preview.ts +203 -40
- package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
- package/src/components/ReportBuilder/readDocument.spec.ts +46 -2
- package/src/components/ReportBuilder/readDocument.ts +194 -23
- package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
- package/src/components/ReportBuilder/sortable.tsx +4 -0
- package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
- package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
- package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
- package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -18
- package/src/components/ReportBuilder/spliceDocument.ts +139 -52
- package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
- package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
- package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
- package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
- package/src/components/ReportBuilder/useTileEditing.ts +16 -3
- package/src/components/ReportBuilder/useTileHeight.ts +149 -0
- package/src/components/ReportBuilder/useTileReorder.ts +143 -6
- package/src/components/ReportBuilder/useTileResize.ts +16 -1
- package/src/components/given/FilterButton.spec.tsx +27 -11
- package/src/components/given/FilterButton.tsx +19 -6
- package/src/theme/resolveTheme.spec.ts +72 -1
- package/src/theme/resolveTheme.ts +43 -0
- package/src/utils/blankQuoted.spec.ts +50 -0
- package/src/utils/blankQuoted.ts +32 -0
- package/src/utils/malloyText.ts +2 -1
- package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
- package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
- package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
|
@@ -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 { previewTileQuery } from "./preview";
|
|
6
|
+
import { seriesColorOf } from "./chartLine";
|
|
7
|
+
import { openDocument, queryTile, spliced } from "./testing/fixtures";
|
|
8
|
+
|
|
9
|
+
const FILE = (tags: string) => `##! experimental.givens
|
|
10
|
+
## artifact { title="T" tiles=["a -> x", "a -> y"] } dashboard { columns=12 }
|
|
11
|
+
import { one } from "../m.malloy"
|
|
12
|
+
|
|
13
|
+
source: a is one extend {
|
|
14
|
+
${tags} # bar_chart
|
|
15
|
+
view: x is vx
|
|
16
|
+
|
|
17
|
+
view: y is vy
|
|
18
|
+
}`;
|
|
19
|
+
|
|
20
|
+
const colorOf = async (text: string, at: number) =>
|
|
21
|
+
queryTile(await openDocument(text), at).color;
|
|
22
|
+
|
|
23
|
+
describe("a tile's chart colour", () => {
|
|
24
|
+
it("writes a picked colour above the declaration, and reads it back", async () => {
|
|
25
|
+
const out = await spliced(FILE(""), (d) => {
|
|
26
|
+
queryTile(d, 0).color = "#1f6aa8";
|
|
27
|
+
});
|
|
28
|
+
expect(out).toContain(' # theme.palette.series=["#1f6aa8"]\n');
|
|
29
|
+
expect(await colorOf(out, 0)).toBe("#1f6aa8");
|
|
30
|
+
// The chart line it sits beside is left alone.
|
|
31
|
+
expect(out).toContain(" # bar_chart\n");
|
|
32
|
+
expect(await colorOf(out, 1)).toBeUndefined();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("replaces the colour in place, and takes the line away for the theme's own", async () => {
|
|
36
|
+
const coloured = FILE(' # theme.palette.series=["#1f6aa8"]\n');
|
|
37
|
+
const changed = await spliced(coloured, (d) => {
|
|
38
|
+
queryTile(d, 0).color = "#c2410c";
|
|
39
|
+
});
|
|
40
|
+
expect(changed).toContain('# theme.palette.series=["#c2410c"]');
|
|
41
|
+
expect(changed).not.toContain("#1f6aa8");
|
|
42
|
+
const removed = await spliced(coloured, (d) => {
|
|
43
|
+
delete queryTile(d, 0).color;
|
|
44
|
+
});
|
|
45
|
+
expect(removed).not.toContain("theme.palette.series");
|
|
46
|
+
expect(removed).toContain(" # bar_chart\n view: x is vx");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("leaves an author's whole palette alone through an edit", async () => {
|
|
50
|
+
const palette = ' # theme.palette.series=["#ff0080", "#ff6b00"]\n';
|
|
51
|
+
expect(await colorOf(FILE(palette), 0)).toBeUndefined();
|
|
52
|
+
const out = await spliced(FILE(palette), (d) => {
|
|
53
|
+
queryTile(d, 0).label = "Revenue";
|
|
54
|
+
});
|
|
55
|
+
expect(out).toContain(palette);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("previews a new colour before it is saved", async () => {
|
|
59
|
+
const document = await openDocument(FILE(""));
|
|
60
|
+
const tile = queryTile(document, 0);
|
|
61
|
+
tile.color = "#1f6aa8";
|
|
62
|
+
const query = previewTileQuery(document, tile, new Set());
|
|
63
|
+
expect(query.annotation?.split("\n")).toContain(
|
|
64
|
+
'# theme.palette.series=["#1f6aa8"]',
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("seriesColorOf", () => {
|
|
70
|
+
it("reads only the one-colour line the builder writes", () => {
|
|
71
|
+
expect(seriesColorOf('# theme.palette.series=["#1F6AA8"]')).toBe(
|
|
72
|
+
"#1f6aa8",
|
|
73
|
+
);
|
|
74
|
+
expect(
|
|
75
|
+
seriesColorOf('# theme.palette.series=["#1f6aa8","#000000"]'),
|
|
76
|
+
).toBe(undefined);
|
|
77
|
+
expect(seriesColorOf('# theme.palette.series=["red"]')).toBeUndefined();
|
|
78
|
+
expect(seriesColorOf("# bar_chart")).toBeUndefined();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { withSpan, writtenSpan } from "../Report/layoutRules";
|
|
6
|
+
import { addTileToDocument } from "./addTileToDocument";
|
|
7
|
+
import { openDocument, queryTile, spliced } from "./testing/fixtures";
|
|
8
|
+
|
|
9
|
+
/** A grid of `columns` (undeclared: the default two), its first tile carrying `tags`. */
|
|
10
|
+
const FILE = (
|
|
11
|
+
columns: number | undefined,
|
|
12
|
+
tags: string,
|
|
13
|
+
) => `##! experimental.givens
|
|
14
|
+
## artifact { title="T" tiles=["a -> x", "a -> y"] }${
|
|
15
|
+
columns === undefined ? "" : ` dashboard { columns=${columns} }`
|
|
16
|
+
}
|
|
17
|
+
import { one } from "../m.malloy"
|
|
18
|
+
|
|
19
|
+
source: a is one extend {
|
|
20
|
+
${tags} view: x is vx
|
|
21
|
+
|
|
22
|
+
view: y is vy
|
|
23
|
+
}`;
|
|
24
|
+
|
|
25
|
+
/** Every width the file writes: a view's `# colspan` line, or `colspan=N` on a tile's entry. */
|
|
26
|
+
const colspanLines = (text: string) => [
|
|
27
|
+
...text.split("\n").filter((line) => /#\s*colspan/.test(line)),
|
|
28
|
+
...(text
|
|
29
|
+
.split("\n")
|
|
30
|
+
.find((line) => line.startsWith("## artifact"))
|
|
31
|
+
?.match(/\bcolspan=\d+/g) ?? []),
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
describe("a tile's width, as the builder writes it", () => {
|
|
35
|
+
it("takes the colspan line away when a width is set back to one column of two", async () => {
|
|
36
|
+
const out = await spliced(FILE(undefined, " # colspan=2\n"), (d) => {
|
|
37
|
+
d.tiles[0] = withSpan(queryTile(d, 0), 1, 2);
|
|
38
|
+
});
|
|
39
|
+
expect(colspanLines(out)).toEqual([]);
|
|
40
|
+
expect(queryTile(await openDocument(out), 0).colspan).toBeUndefined();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("keeps an explicit one column where a tile with no width draws wider", async () => {
|
|
44
|
+
const out = await spliced(FILE(4, " # colspan=2\n"), (d) => {
|
|
45
|
+
d.tiles[0] = withSpan(queryTile(d, 0), 1, 4);
|
|
46
|
+
});
|
|
47
|
+
// Written on the tile's entry, and taken off the view.
|
|
48
|
+
expect(colspanLines(out)).toEqual(["colspan=1"]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("adds a tile to a two-column grid with no colspan line, and to a wider grid with half of it", async () => {
|
|
52
|
+
for (const [columns, want] of [
|
|
53
|
+
[undefined, []],
|
|
54
|
+
[2, []],
|
|
55
|
+
[4, ["colspan=2"]],
|
|
56
|
+
] as const) {
|
|
57
|
+
const grid = columns ?? 2;
|
|
58
|
+
const colspan = writtenSpan(Math.ceil(grid / 2), grid);
|
|
59
|
+
const out = await spliced(FILE(columns, ""), (d) =>
|
|
60
|
+
addTileToDocument(
|
|
61
|
+
d,
|
|
62
|
+
{
|
|
63
|
+
base: "one",
|
|
64
|
+
modelPath: "m.malloy",
|
|
65
|
+
view: "vz",
|
|
66
|
+
...(colspan !== undefined ? { colspan } : {}),
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
modelPath: "dashboards/x.malloy",
|
|
70
|
+
textHeld: false,
|
|
71
|
+
widths: true,
|
|
72
|
+
},
|
|
73
|
+
),
|
|
74
|
+
);
|
|
75
|
+
expect(colspanLines(out)).toEqual([...want]);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -46,9 +46,11 @@ describe("spliceDashboardDocument: what it preserves", () => {
|
|
|
46
46
|
expect(out).toContain(
|
|
47
47
|
" // Why this tile leads: revenue is the number people ask about first.",
|
|
48
48
|
);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
// The width moves to the entry, and the break with it, so the tile's
|
|
50
|
+
// layout has one home; the comment stays where it was.
|
|
51
|
+
expect(out).toContain('"a -> by_cat" { colspan=4 break }');
|
|
52
|
+
expect(out).toContain(
|
|
53
|
+
' // Why this tile leads: revenue is the number people ask about first.\n # label="By category"\n view: by_cat',
|
|
52
54
|
);
|
|
53
55
|
});
|
|
54
56
|
|
|
@@ -109,11 +111,11 @@ source: a is scoped_orders extend {
|
|
|
109
111
|
|
|
110
112
|
it("writes both when the tile had no tags at all", async () => {
|
|
111
113
|
const out = await spliced(UNTAGGED, (d) => {
|
|
112
|
-
d
|
|
114
|
+
queryTile(d, 0).label = "Cat";
|
|
113
115
|
queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
|
|
114
116
|
});
|
|
115
117
|
expect(out).toContain(
|
|
116
|
-
|
|
118
|
+
' # label="Cat"\n view: by_cat is by_category + { where: category ~ $CATEGORY }',
|
|
117
119
|
);
|
|
118
120
|
});
|
|
119
121
|
|
|
@@ -1437,12 +1439,11 @@ source: a is one extend {
|
|
|
1437
1439
|
});
|
|
1438
1440
|
});
|
|
1439
1441
|
expect(out).toContain(
|
|
1440
|
-
'tiles=["a -> by_cat", "a -> by_brand", "a -> by_state_tile"]',
|
|
1442
|
+
'tiles=["a -> by_cat", "a -> by_brand", "a -> by_state_tile" { colspan=6 }]',
|
|
1441
1443
|
);
|
|
1442
1444
|
expect(out).toContain(` # colspan=6
|
|
1443
1445
|
view: by_brand is by_brand_view
|
|
1444
1446
|
|
|
1445
|
-
# colspan=6
|
|
1446
1447
|
# label="By state"
|
|
1447
1448
|
view: by_state_tile is sales_by_state + { where: category ~ $CATEGORY }
|
|
1448
1449
|
}`);
|
|
@@ -1467,7 +1468,7 @@ source: a is one extend {
|
|
|
1467
1468
|
});
|
|
1468
1469
|
});
|
|
1469
1470
|
expect(out)
|
|
1470
|
-
.toBe(`## artifact { title="T" tiles=["a -> x", "products_tiles -> by_brand_tile"] }
|
|
1471
|
+
.toBe(`## artifact { title="T" tiles=["a -> x", "products_tiles -> by_brand_tile" { colspan=4 }] }
|
|
1471
1472
|
import { one, products } from "../m.malloy"
|
|
1472
1473
|
|
|
1473
1474
|
source: a is one extend {
|
|
@@ -1475,7 +1476,6 @@ source: a is one extend {
|
|
|
1475
1476
|
}
|
|
1476
1477
|
|
|
1477
1478
|
source: products_tiles is products extend {
|
|
1478
|
-
# colspan=4
|
|
1479
1479
|
view: by_brand_tile is by_brand
|
|
1480
1480
|
}
|
|
1481
1481
|
`);
|
|
@@ -1526,12 +1526,97 @@ describe("spliceDashboardDocument: what it refuses", () => {
|
|
|
1526
1526
|
it("refuses to restyle a tile declared on its source", async () => {
|
|
1527
1527
|
const source = `## artifact { title="T" tiles=["orders -> by_brand"] }\nimport { orders } from '../orders.malloy'`;
|
|
1528
1528
|
const r = await splice(source, (d) => {
|
|
1529
|
-
d
|
|
1529
|
+
queryTile(d, 0).label = "Brands";
|
|
1530
1530
|
});
|
|
1531
1531
|
expect(r.ok).toBe(false);
|
|
1532
1532
|
if (spliceFailed(r)) expect(r.reason).toContain("declared on its source");
|
|
1533
1533
|
});
|
|
1534
1534
|
|
|
1535
|
+
// Its layout is not the model's, though: the entry is this report's own.
|
|
1536
|
+
it("lays out a tile declared on its source by its entry", async () => {
|
|
1537
|
+
const source = `## artifact { title="T" tiles=["orders -> by_brand"] }\nimport { orders } from '../orders.malloy'`;
|
|
1538
|
+
const out = await spliced(source, (d) => {
|
|
1539
|
+
d.tiles[0].colspan = 6;
|
|
1540
|
+
d.tiles[0].rowspan = 4;
|
|
1541
|
+
});
|
|
1542
|
+
expect(out).toBe(
|
|
1543
|
+
`## artifact { title="T" tiles=["orders -> by_brand" { colspan=6 rowspan=4 }] }\nimport { orders } from '../orders.malloy'`,
|
|
1544
|
+
);
|
|
1545
|
+
const back = await openDocument(out);
|
|
1546
|
+
expect(back.tiles[0]).toMatchObject({ colspan: 6, rowspan: 4 });
|
|
1547
|
+
});
|
|
1548
|
+
|
|
1549
|
+
// A named query stays a named query: the entry is moved or dropped as
|
|
1550
|
+
// written, never rewritten to the `source -> …` it happens to read, and its
|
|
1551
|
+
// `query:` stays in the file, where other things may still read it.
|
|
1552
|
+
describe("a tile that names a query", () => {
|
|
1553
|
+
const NAMED = `## artifact { title="T" tiles=["by_carrier", "flights -> by_month"] }
|
|
1554
|
+
import { flights } from '../flights.malloy'
|
|
1555
|
+
|
|
1556
|
+
# bar_chart
|
|
1557
|
+
query: by_carrier is flights -> { group_by: carrier; aggregate: flight_count }`;
|
|
1558
|
+
|
|
1559
|
+
it("moves with its entry spelled as written", async () => {
|
|
1560
|
+
const out = await spliced(NAMED, (d) => {
|
|
1561
|
+
d.tiles.reverse();
|
|
1562
|
+
});
|
|
1563
|
+
expect(out).toContain('tiles=["flights -> by_month", "by_carrier"]');
|
|
1564
|
+
expect(out).toContain(
|
|
1565
|
+
"# bar_chart\nquery: by_carrier is flights -> { group_by: carrier; aggregate: flight_count }",
|
|
1566
|
+
);
|
|
1567
|
+
});
|
|
1568
|
+
|
|
1569
|
+
it("moves an unquoted entry, and keeps it unquoted", async () => {
|
|
1570
|
+
const out = await spliced(
|
|
1571
|
+
NAMED.replace('"by_carrier"', "by_carrier"),
|
|
1572
|
+
(d) => {
|
|
1573
|
+
d.tiles.reverse();
|
|
1574
|
+
},
|
|
1575
|
+
);
|
|
1576
|
+
expect(out).toContain('tiles=["flights -> by_month", by_carrier]');
|
|
1577
|
+
});
|
|
1578
|
+
|
|
1579
|
+
it("leaves its query in the file when the tile is removed", async () => {
|
|
1580
|
+
const out = await spliced(NAMED, (d) => {
|
|
1581
|
+
d.tiles.shift();
|
|
1582
|
+
});
|
|
1583
|
+
expect(out).toContain('tiles=["flights -> by_month"]');
|
|
1584
|
+
expect(out).toContain("query: by_carrier is flights");
|
|
1585
|
+
});
|
|
1586
|
+
|
|
1587
|
+
it("refuses to restyle it", async () => {
|
|
1588
|
+
expect(
|
|
1589
|
+
await refused(NAMED, (d) => {
|
|
1590
|
+
queryTile(d, 0).label = "Carriers";
|
|
1591
|
+
}),
|
|
1592
|
+
).toContain("names a query");
|
|
1593
|
+
});
|
|
1594
|
+
|
|
1595
|
+
// Its layout is the report's, on its entry, like any other tile's.
|
|
1596
|
+
it("lays it out on its entry, quoted or bare", async () => {
|
|
1597
|
+
const out = await spliced(NAMED, (d) => {
|
|
1598
|
+
d.tiles[0].colspan = 6;
|
|
1599
|
+
d.tiles[0].rowspan = 4;
|
|
1600
|
+
});
|
|
1601
|
+
expect(out).toContain('tiles=["by_carrier" { colspan=6 rowspan=4 }, ');
|
|
1602
|
+
const bare = await spliced(
|
|
1603
|
+
NAMED.replace('"by_carrier"', "by_carrier"),
|
|
1604
|
+
(d) => {
|
|
1605
|
+
d.tiles[0].row = 1;
|
|
1606
|
+
d.tiles[0].col = 7;
|
|
1607
|
+
},
|
|
1608
|
+
);
|
|
1609
|
+
expect(bare).toContain("tiles=[by_carrier { row=1 col=7 }, ");
|
|
1610
|
+
const back = await openDocument(bare);
|
|
1611
|
+
expect(back.tiles[0]).toMatchObject({
|
|
1612
|
+
name: "by_carrier",
|
|
1613
|
+
declaration: { kind: "query" },
|
|
1614
|
+
row: 1,
|
|
1615
|
+
col: 7,
|
|
1616
|
+
});
|
|
1617
|
+
});
|
|
1618
|
+
});
|
|
1619
|
+
|
|
1535
1620
|
it("refuses a new tile that is not a reference to a view", async () => {
|
|
1536
1621
|
expect(
|
|
1537
1622
|
await refused(SOURCE, (d) => {
|
|
@@ -2057,14 +2142,15 @@ ${comment}
|
|
|
2057
2142
|
" /* it was\n # colspan=12\n until the map stopped fitting */",
|
|
2058
2143
|
],
|
|
2059
2144
|
] as const) {
|
|
2060
|
-
it(`
|
|
2145
|
+
it(`moves the width off the tag above ${kind} rather than leaving it there`, async () => {
|
|
2061
2146
|
const out = await spliced(dashed(comment), (d) => {
|
|
2062
2147
|
d.tiles[0].colspan = 3;
|
|
2063
2148
|
});
|
|
2064
|
-
// The comment survives to the byte, the one real tag is
|
|
2065
|
-
//
|
|
2149
|
+
// The comment survives to the byte, the one real tag is taken off,
|
|
2150
|
+
// and the width lands on the entry.
|
|
2151
|
+
expect(out).toContain('"a -> revenue" { colspan=3 }');
|
|
2066
2152
|
expect(out).toContain(
|
|
2067
|
-
`
|
|
2153
|
+
`source: a is one extend {\n${comment}\n view: revenue is sales`,
|
|
2068
2154
|
);
|
|
2069
2155
|
expect(out).not.toContain("# colspan=6");
|
|
2070
2156
|
});
|
|
@@ -2310,9 +2396,11 @@ source: regional is duckdb.sql("""
|
|
|
2310
2396
|
// WITHIN the source's own extent, which used to be just the `source:` line.
|
|
2311
2397
|
it("finds and retags a view declared inside the source, not just its own line", async () => {
|
|
2312
2398
|
const out = await spliced(MULTILINE, (d) => {
|
|
2313
|
-
d
|
|
2399
|
+
queryTile(d, 0).label = "Regions";
|
|
2314
2400
|
});
|
|
2315
|
-
expect(out).toContain(
|
|
2401
|
+
expect(out).toContain(
|
|
2402
|
+
' # label="Regions"\n view: by_region is region_view',
|
|
2403
|
+
);
|
|
2316
2404
|
});
|
|
2317
2405
|
|
|
2318
2406
|
// planRemovedTiles: the LAST view before the extend's own closing brace.
|
|
@@ -2482,8 +2570,9 @@ source: a is one extend {
|
|
|
2482
2570
|
expect(out).toContain(
|
|
2483
2571
|
"##|(markdown) intro\n## How to read this page\n|##\n",
|
|
2484
2572
|
);
|
|
2573
|
+
expect(out).toContain('"a -> x" { colspan=4 }');
|
|
2485
2574
|
expect(out).toContain(
|
|
2486
|
-
" #|(markdown)\n # Lead tile\n |#\n
|
|
2575
|
+
" #|(markdown)\n # Lead tile\n |#\n view: x is vx",
|
|
2487
2576
|
);
|
|
2488
2577
|
});
|
|
2489
2578
|
|
|
@@ -2534,7 +2623,10 @@ source: a is one extend {
|
|
|
2534
2623
|
const out = await spliced(WITH_COMMENTED_CLOSER, (d) => {
|
|
2535
2624
|
d.tiles.find((t) => t.name === "x")!.colspan = 4;
|
|
2536
2625
|
});
|
|
2537
|
-
expect(out).toContain("
|
|
2626
|
+
expect(out).toContain('"a -> x" { colspan=4 }');
|
|
2627
|
+
expect(out).toContain(
|
|
2628
|
+
" view: u is vu\n\n /*\n |# looks like a closer\n",
|
|
2629
|
+
);
|
|
2538
2630
|
expect(out).not.toContain("colspan=6");
|
|
2539
2631
|
expect(out).toContain(
|
|
2540
2632
|
" #|(markdown)\n # Prev\n |#\n view: u is vu\n",
|