@malloy-publisher/sdk 0.9.14 → 0.9.16
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-5hOs5XnV.cjs.js +171 -0
- package/dist/RenderedResult-DxmHGZNQ.es.js +671 -0
- 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 +7732 -6717
- package/dist/builder-entry.d.ts +1 -1
- package/dist/client/api.d.ts +31 -7
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/DashboardGrid.d.ts +51 -1
- package/dist/components/Dashboard/DashboardTile.d.ts +7 -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 +18 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +7 -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 +47 -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/ArrangeMenu.d.ts +9 -0
- package/dist/components/ReportBuilder/BuilderGrid.d.ts +15 -4
- package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
- package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
- package/dist/components/ReportBuilder/EditorSurface.d.ts +10 -1
- package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
- package/dist/components/ReportBuilder/TileFrame.d.ts +54 -10
- package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
- package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
- 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 +121 -0
- package/dist/components/ReportBuilder/preview.d.ts +59 -10
- package/dist/components/ReportBuilder/sortable.d.ts +12 -1
- package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
- package/dist/components/ReportBuilder/useBuilderShortcuts.d.ts +9 -1
- package/dist/components/ReportBuilder/useEdgeResize.d.ts +84 -0
- package/dist/components/ReportBuilder/useTileReorder.d.ts +30 -3
- package/dist/index.cjs.js +7 -7
- package/dist/index.es.js +3349 -3307
- 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/classes.d.ts +1 -1
- package/dist/theme/resolveTheme.d.ts +15 -0
- package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-CaYP_OYG.es.js} +6353 -6047
- package/dist/useCompiledDocument-zYEfLogf.cjs.js +142 -0
- package/dist/utils/blankQuoted.d.ts +15 -0
- package/package.json +1 -1
- package/src/builder-entry.ts +1 -0
- package/src/components/Dashboard/DashboardGrid.tsx +129 -10
- package/src/components/Dashboard/DashboardTile.tsx +15 -1
- package/src/components/Dashboard/DashboardView.tsx +64 -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 +39 -6
- package/src/components/RenderedResult/ResultContainer.tsx +99 -10
- package/src/components/RenderedResult/ResultPanel.tsx +25 -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 +71 -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/ArrangeMenu.tsx +80 -0
- package/src/components/ReportBuilder/BuilderBar.tsx +5 -1
- package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -1
- package/src/components/ReportBuilder/BuilderGrid.tsx +142 -35
- package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
- 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 +101 -20
- 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 +242 -2
- package/src/components/ReportBuilder/ReportBuilder.tsx +161 -27
- 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.readOnlyTitle.spec.tsx +92 -0
- package/src/components/ReportBuilder/ReportEditor.tsx +13 -0
- package/src/components/ReportBuilder/TileFrame.tsx +366 -170
- 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/builderControls.ts +34 -0
- 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 +401 -0
- package/src/components/ReportBuilder/placement.ts +416 -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 +53 -19
- package/src/components/ReportBuilder/readDocument.ts +197 -29
- package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
- package/src/components/ReportBuilder/sortable.tsx +30 -2
- 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 -58
- package/src/components/ReportBuilder/spliceDocument.ts +139 -91
- 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/useBuilderSession.ts +7 -2
- package/src/components/ReportBuilder/useBuilderShortcuts.ts +25 -1
- package/src/components/ReportBuilder/useEdgeResize.spec.tsx +324 -0
- package/src/components/ReportBuilder/useEdgeResize.ts +397 -0
- package/src/components/ReportBuilder/useTileEditing.ts +16 -3
- package/src/components/ReportBuilder/useTileReorder.ts +143 -6
- package/src/components/given/FilterButton.spec.tsx +27 -11
- package/src/components/given/FilterButton.tsx +19 -6
- package/src/theme/classes.ts +1 -1
- 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-DnBtf-cI.es.js +0 -593
- package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
- package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
- package/dist/components/ReportBuilder/useTileResize.d.ts +0 -32
- package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
- package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
- package/src/components/ReportBuilder/useTileResize.ts +0 -133
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
import { pointerIntersection } from "@dnd-kit/collision";
|
|
5
5
|
import { Feedback, KeyboardSensor, PointerSensor } from "@dnd-kit/dom";
|
|
6
|
-
import { useDroppable } from "@dnd-kit/react";
|
|
6
|
+
import { useDragDropManager, useDroppable } from "@dnd-kit/react";
|
|
7
7
|
import { useSortable, type UseSortableInput } from "@dnd-kit/react/sortable";
|
|
8
|
-
import type
|
|
8
|
+
import { useEffect, type ReactNode } from "react";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* The builder's drag and drop, on `@dnd-kit/react`.
|
|
@@ -99,15 +99,19 @@ interface TileSortableHandles {
|
|
|
99
99
|
export function TileSortable({
|
|
100
100
|
id,
|
|
101
101
|
index,
|
|
102
|
+
disabled = false,
|
|
102
103
|
children,
|
|
103
104
|
}: {
|
|
104
105
|
id: string;
|
|
105
106
|
index: number;
|
|
107
|
+
/** Not movable now: the grid is drawn as one column, where a move means nothing. */
|
|
108
|
+
disabled?: boolean;
|
|
106
109
|
children: (handles: TileSortableHandles) => ReactNode;
|
|
107
110
|
}) {
|
|
108
111
|
const { ref, handleRef, isDragSource } = useSortable({
|
|
109
112
|
id,
|
|
110
113
|
index,
|
|
114
|
+
disabled,
|
|
111
115
|
type: TILE_TYPE,
|
|
112
116
|
accept: TILE_TYPE,
|
|
113
117
|
// The same rule the gaps use: the target is what the POINTER is over.
|
|
@@ -158,3 +162,27 @@ export function GapDroppable({
|
|
|
158
162
|
});
|
|
159
163
|
return <>{children({ ref, isDropTarget })}</>;
|
|
160
164
|
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Escape cancels a drag wherever focus is. The library's pointer drag listens
|
|
168
|
+
* for Escape only on the element under the pointer, and a press on a tile's
|
|
169
|
+
* padding focuses nothing, so the key reached the page instead and the drop
|
|
170
|
+
* landed on release. Mounted inside the drag provider while a drag is live.
|
|
171
|
+
*/
|
|
172
|
+
export function EscapeCancelsDrag({ active }: { active: boolean }) {
|
|
173
|
+
const manager = useDragDropManager();
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
if (!active || !manager) return;
|
|
176
|
+
const onKey = (event: KeyboardEvent) => {
|
|
177
|
+
if (event.key !== "Escape" || manager.dragOperation.status.idle)
|
|
178
|
+
return;
|
|
179
|
+
// The drag's, not the builder's: it must not also drop the selection.
|
|
180
|
+
event.preventDefault();
|
|
181
|
+
event.stopPropagation();
|
|
182
|
+
manager.actions.stop({ event, canceled: true });
|
|
183
|
+
};
|
|
184
|
+
window.addEventListener("keydown", onKey, true);
|
|
185
|
+
return () => window.removeEventListener("keydown", onKey, true);
|
|
186
|
+
}, [active, manager]);
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
@@ -86,7 +86,7 @@ describe("a tile's chart line", () => {
|
|
|
86
86
|
queryTile(d, 0).chart = "none";
|
|
87
87
|
queryTile(d, 0).chartCarried = [];
|
|
88
88
|
});
|
|
89
|
-
expect(table).toContain(" # -viz\n view: x is vx");
|
|
89
|
+
expect(table).toContain(" # -big_value -viz\n view: x is vx");
|
|
90
90
|
expect(await chartOf(table, 0)).toBe("none");
|
|
91
91
|
});
|
|
92
92
|
|
|
@@ -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
|
|
|
@@ -1091,24 +1093,6 @@ describe("spliceDashboardDocument: the page's own settings", () => {
|
|
|
1091
1093
|
expect(flowed).not.toContain("dashboard {");
|
|
1092
1094
|
});
|
|
1093
1095
|
|
|
1094
|
-
it("replaces the dashboard_columns alias when a width is set, and the result lints clean", async () => {
|
|
1095
|
-
const aliased = SOURCE.replace(
|
|
1096
|
-
'"a -> by_brand"] } dashboard { columns=12 }',
|
|
1097
|
-
'"a -> by_brand"] dashboard_columns=8 }',
|
|
1098
|
-
);
|
|
1099
|
-
expect(aliased).toContain("dashboard_columns=8");
|
|
1100
|
-
const out = await spliced(aliased, (d) => {
|
|
1101
|
-
d.columns = 12;
|
|
1102
|
-
});
|
|
1103
|
-
expect(out).not.toContain("dashboard_columns");
|
|
1104
|
-
expect(out).toContain("dashboard { columns=12 }");
|
|
1105
|
-
const removed = await spliced(aliased, (d) => {
|
|
1106
|
-
delete d.columns;
|
|
1107
|
-
});
|
|
1108
|
-
expect(removed).not.toContain("dashboard_columns");
|
|
1109
|
-
expect(removed).not.toContain("dashboard {");
|
|
1110
|
-
});
|
|
1111
|
-
|
|
1112
1096
|
it("adds and removes autorun and starting values inside the tag", async () => {
|
|
1113
1097
|
const out = await spliced(SOURCE, (d) => {
|
|
1114
1098
|
d.autorun = false;
|
|
@@ -1197,28 +1181,6 @@ describe("spliceDashboardDocument: the page's own settings", () => {
|
|
|
1197
1181
|
lintNotebookText("dashboards/d.malloy", source).map((f) => f.code);
|
|
1198
1182
|
const TAIL = `import "../m.malloy"\n\nsource: a is one extend {\n view: x is vx\n}`;
|
|
1199
1183
|
|
|
1200
|
-
describe("a width change against the deprecated alias", () => {
|
|
1201
|
-
it("removes the alias whatever spacing surrounds its =", async () => {
|
|
1202
|
-
const source = `## artifact { title="T" tiles=["a -> x"] dashboard_columns = 3 }\n${TAIL}`;
|
|
1203
|
-
const out = await spliced(source, (d) => {
|
|
1204
|
-
d.columns = 6;
|
|
1205
|
-
});
|
|
1206
|
-
expect(out).not.toContain("dashboard_columns");
|
|
1207
|
-
expect(out).toContain("dashboard { columns=6 }");
|
|
1208
|
-
expect(lintCodes(out)).toEqual([]);
|
|
1209
|
-
});
|
|
1210
|
-
|
|
1211
|
-
it("removes the alias, not the same words inside a quoted title", async () => {
|
|
1212
|
-
const source = `## artifact { title="a dashboard_columns=2 b" tiles=["a -> x"] dashboard_columns=3 }\n${TAIL}`;
|
|
1213
|
-
const out = await spliced(source, (d) => {
|
|
1214
|
-
d.columns = 6;
|
|
1215
|
-
});
|
|
1216
|
-
expect(out).toContain('title="a dashboard_columns=2 b"');
|
|
1217
|
-
expect(out.match(/dashboard_columns/g)).toHaveLength(1);
|
|
1218
|
-
expect(lintCodes(out)).toEqual([]);
|
|
1219
|
-
});
|
|
1220
|
-
});
|
|
1221
|
-
|
|
1222
1184
|
it("reorders a list holding a text tile, keeping its entry as written", async () => {
|
|
1223
1185
|
const source = fs
|
|
1224
1186
|
.readFileSync(
|
|
@@ -1437,12 +1399,11 @@ source: a is one extend {
|
|
|
1437
1399
|
});
|
|
1438
1400
|
});
|
|
1439
1401
|
expect(out).toContain(
|
|
1440
|
-
'tiles=["a -> by_cat", "a -> by_brand", "a -> by_state_tile"]',
|
|
1402
|
+
'tiles=["a -> by_cat", "a -> by_brand", "a -> by_state_tile" { colspan=6 }]',
|
|
1441
1403
|
);
|
|
1442
1404
|
expect(out).toContain(` # colspan=6
|
|
1443
1405
|
view: by_brand is by_brand_view
|
|
1444
1406
|
|
|
1445
|
-
# colspan=6
|
|
1446
1407
|
# label="By state"
|
|
1447
1408
|
view: by_state_tile is sales_by_state + { where: category ~ $CATEGORY }
|
|
1448
1409
|
}`);
|
|
@@ -1467,7 +1428,7 @@ source: a is one extend {
|
|
|
1467
1428
|
});
|
|
1468
1429
|
});
|
|
1469
1430
|
expect(out)
|
|
1470
|
-
.toBe(`## artifact { title="T" tiles=["a -> x", "products_tiles -> by_brand_tile"] }
|
|
1431
|
+
.toBe(`## artifact { title="T" tiles=["a -> x", "products_tiles -> by_brand_tile" { colspan=4 }] }
|
|
1471
1432
|
import { one, products } from "../m.malloy"
|
|
1472
1433
|
|
|
1473
1434
|
source: a is one extend {
|
|
@@ -1475,7 +1436,6 @@ source: a is one extend {
|
|
|
1475
1436
|
}
|
|
1476
1437
|
|
|
1477
1438
|
source: products_tiles is products extend {
|
|
1478
|
-
# colspan=4
|
|
1479
1439
|
view: by_brand_tile is by_brand
|
|
1480
1440
|
}
|
|
1481
1441
|
`);
|
|
@@ -1526,12 +1486,97 @@ describe("spliceDashboardDocument: what it refuses", () => {
|
|
|
1526
1486
|
it("refuses to restyle a tile declared on its source", async () => {
|
|
1527
1487
|
const source = `## artifact { title="T" tiles=["orders -> by_brand"] }\nimport { orders } from '../orders.malloy'`;
|
|
1528
1488
|
const r = await splice(source, (d) => {
|
|
1529
|
-
d
|
|
1489
|
+
queryTile(d, 0).label = "Brands";
|
|
1530
1490
|
});
|
|
1531
1491
|
expect(r.ok).toBe(false);
|
|
1532
1492
|
if (spliceFailed(r)) expect(r.reason).toContain("declared on its source");
|
|
1533
1493
|
});
|
|
1534
1494
|
|
|
1495
|
+
// Its layout is not the model's, though: the entry is this report's own.
|
|
1496
|
+
it("lays out a tile declared on its source by its entry", async () => {
|
|
1497
|
+
const source = `## artifact { title="T" tiles=["orders -> by_brand"] }\nimport { orders } from '../orders.malloy'`;
|
|
1498
|
+
const out = await spliced(source, (d) => {
|
|
1499
|
+
d.tiles[0].colspan = 6;
|
|
1500
|
+
d.tiles[0].rowspan = 4;
|
|
1501
|
+
});
|
|
1502
|
+
expect(out).toBe(
|
|
1503
|
+
`## artifact { title="T" tiles=["orders -> by_brand" { colspan=6 rowspan=4 }] }\nimport { orders } from '../orders.malloy'`,
|
|
1504
|
+
);
|
|
1505
|
+
const back = await openDocument(out);
|
|
1506
|
+
expect(back.tiles[0]).toMatchObject({ colspan: 6, rowspan: 4 });
|
|
1507
|
+
});
|
|
1508
|
+
|
|
1509
|
+
// A named query stays a named query: the entry is moved or dropped as
|
|
1510
|
+
// written, never rewritten to the `source -> …` it happens to read, and its
|
|
1511
|
+
// `query:` stays in the file, where other things may still read it.
|
|
1512
|
+
describe("a tile that names a query", () => {
|
|
1513
|
+
const NAMED = `## artifact { title="T" tiles=["by_carrier", "flights -> by_month"] }
|
|
1514
|
+
import { flights } from '../flights.malloy'
|
|
1515
|
+
|
|
1516
|
+
# bar_chart
|
|
1517
|
+
query: by_carrier is flights -> { group_by: carrier; aggregate: flight_count }`;
|
|
1518
|
+
|
|
1519
|
+
it("moves with its entry spelled as written", async () => {
|
|
1520
|
+
const out = await spliced(NAMED, (d) => {
|
|
1521
|
+
d.tiles.reverse();
|
|
1522
|
+
});
|
|
1523
|
+
expect(out).toContain('tiles=["flights -> by_month", "by_carrier"]');
|
|
1524
|
+
expect(out).toContain(
|
|
1525
|
+
"# bar_chart\nquery: by_carrier is flights -> { group_by: carrier; aggregate: flight_count }",
|
|
1526
|
+
);
|
|
1527
|
+
});
|
|
1528
|
+
|
|
1529
|
+
it("moves an unquoted entry, and keeps it unquoted", async () => {
|
|
1530
|
+
const out = await spliced(
|
|
1531
|
+
NAMED.replace('"by_carrier"', "by_carrier"),
|
|
1532
|
+
(d) => {
|
|
1533
|
+
d.tiles.reverse();
|
|
1534
|
+
},
|
|
1535
|
+
);
|
|
1536
|
+
expect(out).toContain('tiles=["flights -> by_month", by_carrier]');
|
|
1537
|
+
});
|
|
1538
|
+
|
|
1539
|
+
it("leaves its query in the file when the tile is removed", async () => {
|
|
1540
|
+
const out = await spliced(NAMED, (d) => {
|
|
1541
|
+
d.tiles.shift();
|
|
1542
|
+
});
|
|
1543
|
+
expect(out).toContain('tiles=["flights -> by_month"]');
|
|
1544
|
+
expect(out).toContain("query: by_carrier is flights");
|
|
1545
|
+
});
|
|
1546
|
+
|
|
1547
|
+
it("refuses to restyle it", async () => {
|
|
1548
|
+
expect(
|
|
1549
|
+
await refused(NAMED, (d) => {
|
|
1550
|
+
queryTile(d, 0).label = "Carriers";
|
|
1551
|
+
}),
|
|
1552
|
+
).toContain("names a query");
|
|
1553
|
+
});
|
|
1554
|
+
|
|
1555
|
+
// Its layout is the report's, on its entry, like any other tile's.
|
|
1556
|
+
it("lays it out on its entry, quoted or bare", async () => {
|
|
1557
|
+
const out = await spliced(NAMED, (d) => {
|
|
1558
|
+
d.tiles[0].colspan = 6;
|
|
1559
|
+
d.tiles[0].rowspan = 4;
|
|
1560
|
+
});
|
|
1561
|
+
expect(out).toContain('tiles=["by_carrier" { colspan=6 rowspan=4 }, ');
|
|
1562
|
+
const bare = await spliced(
|
|
1563
|
+
NAMED.replace('"by_carrier"', "by_carrier"),
|
|
1564
|
+
(d) => {
|
|
1565
|
+
d.tiles[0].row = 1;
|
|
1566
|
+
d.tiles[0].col = 7;
|
|
1567
|
+
},
|
|
1568
|
+
);
|
|
1569
|
+
expect(bare).toContain("tiles=[by_carrier { row=1 col=7 }, ");
|
|
1570
|
+
const back = await openDocument(bare);
|
|
1571
|
+
expect(back.tiles[0]).toMatchObject({
|
|
1572
|
+
name: "by_carrier",
|
|
1573
|
+
declaration: { kind: "query" },
|
|
1574
|
+
row: 1,
|
|
1575
|
+
col: 7,
|
|
1576
|
+
});
|
|
1577
|
+
});
|
|
1578
|
+
});
|
|
1579
|
+
|
|
1535
1580
|
it("refuses a new tile that is not a reference to a view", async () => {
|
|
1536
1581
|
expect(
|
|
1537
1582
|
await refused(SOURCE, (d) => {
|
|
@@ -2057,14 +2102,15 @@ ${comment}
|
|
|
2057
2102
|
" /* it was\n # colspan=12\n until the map stopped fitting */",
|
|
2058
2103
|
],
|
|
2059
2104
|
] as const) {
|
|
2060
|
-
it(`
|
|
2105
|
+
it(`moves the width off the tag above ${kind} rather than leaving it there`, async () => {
|
|
2061
2106
|
const out = await spliced(dashed(comment), (d) => {
|
|
2062
2107
|
d.tiles[0].colspan = 3;
|
|
2063
2108
|
});
|
|
2064
|
-
// The comment survives to the byte, the one real tag is
|
|
2065
|
-
//
|
|
2109
|
+
// The comment survives to the byte, the one real tag is taken off,
|
|
2110
|
+
// and the width lands on the entry.
|
|
2111
|
+
expect(out).toContain('"a -> revenue" { colspan=3 }');
|
|
2066
2112
|
expect(out).toContain(
|
|
2067
|
-
`
|
|
2113
|
+
`source: a is one extend {\n${comment}\n view: revenue is sales`,
|
|
2068
2114
|
);
|
|
2069
2115
|
expect(out).not.toContain("# colspan=6");
|
|
2070
2116
|
});
|
|
@@ -2310,9 +2356,11 @@ source: regional is duckdb.sql("""
|
|
|
2310
2356
|
// WITHIN the source's own extent, which used to be just the `source:` line.
|
|
2311
2357
|
it("finds and retags a view declared inside the source, not just its own line", async () => {
|
|
2312
2358
|
const out = await spliced(MULTILINE, (d) => {
|
|
2313
|
-
d
|
|
2359
|
+
queryTile(d, 0).label = "Regions";
|
|
2314
2360
|
});
|
|
2315
|
-
expect(out).toContain(
|
|
2361
|
+
expect(out).toContain(
|
|
2362
|
+
' # label="Regions"\n view: by_region is region_view',
|
|
2363
|
+
);
|
|
2316
2364
|
});
|
|
2317
2365
|
|
|
2318
2366
|
// planRemovedTiles: the LAST view before the extend's own closing brace.
|
|
@@ -2482,8 +2530,9 @@ source: a is one extend {
|
|
|
2482
2530
|
expect(out).toContain(
|
|
2483
2531
|
"##|(markdown) intro\n## How to read this page\n|##\n",
|
|
2484
2532
|
);
|
|
2533
|
+
expect(out).toContain('"a -> x" { colspan=4 }');
|
|
2485
2534
|
expect(out).toContain(
|
|
2486
|
-
" #|(markdown)\n # Lead tile\n |#\n
|
|
2535
|
+
" #|(markdown)\n # Lead tile\n |#\n view: x is vx",
|
|
2487
2536
|
);
|
|
2488
2537
|
});
|
|
2489
2538
|
|
|
@@ -2534,7 +2583,10 @@ source: a is one extend {
|
|
|
2534
2583
|
const out = await spliced(WITH_COMMENTED_CLOSER, (d) => {
|
|
2535
2584
|
d.tiles.find((t) => t.name === "x")!.colspan = 4;
|
|
2536
2585
|
});
|
|
2537
|
-
expect(out).toContain("
|
|
2586
|
+
expect(out).toContain('"a -> x" { colspan=4 }');
|
|
2587
|
+
expect(out).toContain(
|
|
2588
|
+
" view: u is vu\n\n /*\n |# looks like a closer\n",
|
|
2589
|
+
);
|
|
2538
2590
|
expect(out).not.toContain("colspan=6");
|
|
2539
2591
|
expect(out).toContain(
|
|
2540
2592
|
" #|(markdown)\n # Prev\n |#\n view: u is vu\n",
|