@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,13 @@
|
|
|
3
3
|
|
|
4
4
|
import { reportClasses } from "../../theme/classes";
|
|
5
5
|
import AddIcon from "@mui/icons-material/Add";
|
|
6
|
-
import { Alert, Button, Stack, Typography } from "@mui/material";
|
|
7
|
-
import { useMemo, useRef, useState, type ReactNode } from "react";
|
|
8
|
-
import {
|
|
6
|
+
import { Alert, Button, Stack, Typography, useMediaQuery } from "@mui/material";
|
|
7
|
+
import { useCallback, useMemo, useRef, useState, type ReactNode } from "react";
|
|
8
|
+
import {
|
|
9
|
+
isPlaced,
|
|
10
|
+
nudgedSpan,
|
|
11
|
+
useDefaultTileSpan,
|
|
12
|
+
} from "../Dashboard/DashboardGrid";
|
|
9
13
|
import type { TileChrome, TileHeadingSlots } from "../Dashboard/TileCard";
|
|
10
14
|
import type { SavesTo } from "./documentSession";
|
|
11
15
|
import type { ReportEventHandler } from "../Report/telemetry";
|
|
@@ -22,11 +26,7 @@ import {
|
|
|
22
26
|
} from "./builderControls";
|
|
23
27
|
import { OpenDraftContext } from "./openDraft";
|
|
24
28
|
import type { PackageCatalog } from "./catalog";
|
|
25
|
-
import {
|
|
26
|
-
isQueryTile,
|
|
27
|
-
type DashboardDocument,
|
|
28
|
-
type QueryTile,
|
|
29
|
-
} from "./document";
|
|
29
|
+
import { tileKey, type DashboardDocument, type QueryTile } from "./document";
|
|
30
30
|
import { FilterStrip, type FixedFilter } from "./FilterStrip";
|
|
31
31
|
import { clockTime, type SaveStatusProps } from "./SaveStatus";
|
|
32
32
|
import { SELECTION_RING_PX } from "./TileFrame";
|
|
@@ -39,8 +39,19 @@ import type { SaveHandler } from "./useDocumentEditor";
|
|
|
39
39
|
import { useOpenDraftCommit } from "./useOpenDraftCommit";
|
|
40
40
|
import { useTileEditing } from "./useTileEditing";
|
|
41
41
|
import { useTileReorder } from "./useTileReorder";
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
42
|
+
import { ArrangeMenu } from "./ArrangeMenu";
|
|
43
|
+
import type { ArrangeActions } from "./builderControls";
|
|
44
|
+
import {
|
|
45
|
+
flowTiles,
|
|
46
|
+
hasGaps,
|
|
47
|
+
inReadingOrder,
|
|
48
|
+
pack,
|
|
49
|
+
settle,
|
|
50
|
+
stepPlaced,
|
|
51
|
+
widestFrom,
|
|
52
|
+
} from "./placement";
|
|
53
|
+
import { useEdgeResize, withShape } from "./useEdgeResize";
|
|
54
|
+
import { layoutRules, withSpan } from "../Report/layoutRules";
|
|
44
55
|
import { ReportPage } from "../Report/ReportPage";
|
|
45
56
|
|
|
46
57
|
export type { BuilderGiven } from "./controls";
|
|
@@ -61,7 +72,7 @@ export type { BuilderGiven } from "./controls";
|
|
|
61
72
|
* draws its own card AND its own heading. Nesting one inside a card of ours
|
|
62
73
|
* would show a card in a card under two titles — which is precisely not what a
|
|
63
74
|
* reader sees. So every affordance is drawn AROUND whatever the caller renders:
|
|
64
|
-
* an outline for selection, a
|
|
75
|
+
* an outline for selection, a menu in the corner, and edges that resize.
|
|
65
76
|
*
|
|
66
77
|
* **Everything here is on the thing it changes.** Set a tile's width from its menu, and drag
|
|
67
78
|
* the tile itself to reorder — into the empty end of a row
|
|
@@ -296,6 +307,17 @@ export function ReportBuilder({
|
|
|
296
307
|
?.split("/")
|
|
297
308
|
.at(-1)
|
|
298
309
|
?.replace(/\.malloy$/, "");
|
|
310
|
+
// Below `md` the grid is drawn as one column, as a phone shows it, so a
|
|
311
|
+
// tile's width and place do not show: moving and widening are off there.
|
|
312
|
+
// Assumed wide where the width cannot be asked (tests, server render).
|
|
313
|
+
// 900px is `md` in the default breakpoints, which the grid's own `sx`
|
|
314
|
+
// resolves against; written out so a host with no MUI theme still works.
|
|
315
|
+
const wide = useMediaQuery("(min-width:900px)", {
|
|
316
|
+
defaultMatches: true,
|
|
317
|
+
noSsr: true,
|
|
318
|
+
});
|
|
319
|
+
const arrange = !rules.widths || wide;
|
|
320
|
+
// On a grid a move is free placement; on a linear report it reorders.
|
|
299
321
|
const reorder = useTileReorder({
|
|
300
322
|
tiles: editor.document.tiles,
|
|
301
323
|
commit: (next) =>
|
|
@@ -303,11 +325,31 @@ export function ReportBuilder({
|
|
|
303
325
|
draft.tiles = next;
|
|
304
326
|
}),
|
|
305
327
|
onLanded: selectTile,
|
|
328
|
+
...(rules.widths && wide ? { placement: { columns, gridBox } } : {}),
|
|
306
329
|
});
|
|
330
|
+
// After a tile on a placed report changes size, whatever it now covers
|
|
331
|
+
// is pushed down; a report that flows has nothing to settle.
|
|
332
|
+
// Write a new tile list as one edit, keeping the selection on the tile it
|
|
333
|
+
// was on: a placed report is written in reading order, so a resize, a
|
|
334
|
+
// pack or a flow can move the selected tile to another index.
|
|
335
|
+
const writeTiles = (next: DashboardDocument["tiles"], key?: string) => {
|
|
336
|
+
editor.update((draft) => {
|
|
337
|
+
draft.tiles = next;
|
|
338
|
+
});
|
|
339
|
+
if (key === undefined) return;
|
|
340
|
+
const landed = next.findIndex((each) => tileKey(each) === key);
|
|
341
|
+
if (landed >= 0) selectTile(landed);
|
|
342
|
+
};
|
|
343
|
+
const placesTiles = rules.widths;
|
|
344
|
+
const place = useCallback(
|
|
345
|
+
(tiles: DashboardDocument["tiles"], index: number) =>
|
|
346
|
+
placesTiles && isPlaced(tiles) ? settle(tiles, columns, index) : tiles,
|
|
347
|
+
[placesTiles, columns],
|
|
348
|
+
);
|
|
307
349
|
const { dragging } = reorder;
|
|
308
350
|
// Dragging a tile's right edge sets its width, written once on release.
|
|
309
351
|
// A tile with no `# colspan` is drawn as the reader draws it, at least
|
|
310
|
-
// MIN_TILE_PX wide, rather than one column: the
|
|
352
|
+
// MIN_TILE_PX wide, rather than one column: the right edge and the row
|
|
311
353
|
// arithmetic start from that span. Only drawn; nothing is written until
|
|
312
354
|
// the author sets a width.
|
|
313
355
|
const defaultSpan = useDefaultTileSpan(gridBox, columns);
|
|
@@ -320,16 +362,28 @@ export function ReportBuilder({
|
|
|
320
362
|
),
|
|
321
363
|
[editor.document.tiles, defaultSpan],
|
|
322
364
|
);
|
|
323
|
-
|
|
365
|
+
// Dragging any edge or corner of a tile resizes it: the right and bottom
|
|
366
|
+
// edges set width and height, the left and top move those edges (placing a
|
|
367
|
+
// report that flows, as a move does), a corner both at once. Written once,
|
|
368
|
+
// on release, and on a placed report whatever it now covers moves down.
|
|
369
|
+
const edging = useEdgeResize({
|
|
324
370
|
tiles: laidOut,
|
|
325
371
|
columns,
|
|
326
372
|
gridBox,
|
|
327
373
|
onStart: selectTile,
|
|
328
|
-
commit: (index,
|
|
329
|
-
editor.
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
374
|
+
commit: ({ index, edges, shape, placed, placedAll }) => {
|
|
375
|
+
const all = placedAll ?? editor.document.tiles;
|
|
376
|
+
const tile = all[index];
|
|
377
|
+
if (!tile) return;
|
|
378
|
+
let next = withShape(tile, shape, edges, placed);
|
|
379
|
+
if (edges.e || edges.w)
|
|
380
|
+
next = withSpan(next, shape.colspan, columns, defaultSpan);
|
|
381
|
+
const resized = all.map((each, i) => (i === index ? next : each));
|
|
382
|
+
writeTiles(
|
|
383
|
+
placed ? inReadingOrder(settle(resized, columns, index)) : resized,
|
|
384
|
+
tileKey(tile),
|
|
385
|
+
);
|
|
386
|
+
},
|
|
333
387
|
});
|
|
334
388
|
const tiles = useTileEditing({
|
|
335
389
|
editor,
|
|
@@ -355,8 +409,12 @@ export function ReportBuilder({
|
|
|
355
409
|
editorDirty: editor.dirty,
|
|
356
410
|
});
|
|
357
411
|
|
|
412
|
+
const edgeDragging = edging.drag !== undefined;
|
|
358
413
|
const shortcuts = useMemo(
|
|
359
414
|
() => ({
|
|
415
|
+
// While an edge is dragged: its release writes the layout the drag
|
|
416
|
+
// began from, so an undo or a move made mid-drag would be lost.
|
|
417
|
+
paused: edgeDragging,
|
|
360
418
|
// Escape drops the selection — unless the menu or the filter window is open, in which case the key is theirs and they close on it themselves.
|
|
361
419
|
escape: () => {
|
|
362
420
|
// Not while a menu or a window is open: the key is theirs, and
|
|
@@ -369,28 +427,69 @@ export function ReportBuilder({
|
|
|
369
427
|
)
|
|
370
428
|
clearSelection();
|
|
371
429
|
},
|
|
430
|
+
// Option/Alt and an arrow: a placed tile moves exactly one cell. A
|
|
431
|
+
// step into the tile beside it swaps the two; otherwise whatever it
|
|
432
|
+
// lands on is pushed down. Unlike a drop it never slides under a
|
|
433
|
+
// taller tile, so a key press moves it where the arrow points.
|
|
434
|
+
move: (rows: -1 | 0 | 1, cols: -1 | 0 | 1) => {
|
|
435
|
+
if (dragging || selected === undefined || !rules.widths || !arrange)
|
|
436
|
+
return false;
|
|
437
|
+
const tile = editor.document.tiles[selected];
|
|
438
|
+
if (!tile || tile.row === undefined || tile.col === undefined)
|
|
439
|
+
return false;
|
|
440
|
+
const next = stepPlaced(
|
|
441
|
+
editor.document.tiles,
|
|
442
|
+
selected,
|
|
443
|
+
rows,
|
|
444
|
+
cols,
|
|
445
|
+
columns,
|
|
446
|
+
);
|
|
447
|
+
// At the grid's edge: the key is still the builder's, so it does
|
|
448
|
+
// not fall through to the browser's Back or Forward.
|
|
449
|
+
if (next.every((each, i) => each === editor.document.tiles[i]))
|
|
450
|
+
return true;
|
|
451
|
+
const key = tileKey(tile);
|
|
452
|
+
editor.update((draft) => {
|
|
453
|
+
draft.tiles = inReadingOrder(
|
|
454
|
+
stepPlaced(draft.tiles, selected, rows, cols, columns),
|
|
455
|
+
);
|
|
456
|
+
});
|
|
457
|
+
const landed = inReadingOrder(next).findIndex(
|
|
458
|
+
(each) => tileKey(each) === key,
|
|
459
|
+
);
|
|
460
|
+
if (landed >= 0) selectTile(landed);
|
|
461
|
+
return true;
|
|
462
|
+
},
|
|
372
463
|
nudge: (delta: 1 | -1) => {
|
|
373
464
|
// The drag's keyboard sensor also reads the arrows, and a drop would write the drag-start width back.
|
|
374
|
-
if (dragging || selected === undefined || !rules.widths)
|
|
375
|
-
const tile = editor.document.tiles[selected];
|
|
376
|
-
if (
|
|
377
|
-
!tile ||
|
|
378
|
-
(isQueryTile(tile) && tile.declaration.kind === "inherited")
|
|
379
|
-
)
|
|
465
|
+
if (dragging || selected === undefined || !rules.widths || !arrange)
|
|
380
466
|
return;
|
|
467
|
+
// Any tile, an inherited one too: its width is on its entry.
|
|
468
|
+
const tile = editor.document.tiles[selected];
|
|
469
|
+
if (!tile) return;
|
|
381
470
|
const span = nudgedSpan(
|
|
382
471
|
tile.colspan ?? defaultSpan,
|
|
383
472
|
delta,
|
|
384
|
-
columns,
|
|
473
|
+
widestFrom(tile, columns),
|
|
385
474
|
);
|
|
386
475
|
if (span === (tile.colspan ?? defaultSpan)) return;
|
|
387
476
|
editor.update((draft) => {
|
|
388
|
-
draft.tiles[selected]
|
|
477
|
+
draft.tiles[selected] = withSpan(
|
|
478
|
+
draft.tiles[selected],
|
|
479
|
+
span,
|
|
480
|
+
columns,
|
|
481
|
+
defaultSpan,
|
|
482
|
+
);
|
|
483
|
+
draft.tiles = place(draft.tiles, selected);
|
|
389
484
|
});
|
|
390
485
|
},
|
|
391
486
|
}),
|
|
392
487
|
[
|
|
488
|
+
edgeDragging,
|
|
393
489
|
defaultSpan,
|
|
490
|
+
arrange,
|
|
491
|
+
place,
|
|
492
|
+
selectTile,
|
|
394
493
|
editor,
|
|
395
494
|
menu,
|
|
396
495
|
filterDialog,
|
|
@@ -448,6 +547,28 @@ export function ReportBuilder({
|
|
|
448
547
|
? { dismissRestored: draft.dismissRestored }
|
|
449
548
|
: {}),
|
|
450
549
|
};
|
|
550
|
+
// The layout as a whole, once a grid report's tiles are placed: close its
|
|
551
|
+
// gaps, or let it flow again. Each is one undoable edit.
|
|
552
|
+
const tilesNow = editor.document.tiles;
|
|
553
|
+
const selectedKey =
|
|
554
|
+
selected !== undefined && tilesNow[selected]
|
|
555
|
+
? tileKey(tilesNow[selected])
|
|
556
|
+
: undefined;
|
|
557
|
+
const arrangeActions: ArrangeActions | undefined =
|
|
558
|
+
rules.widths && arrange && isPlaced(tilesNow)
|
|
559
|
+
? {
|
|
560
|
+
...(hasGaps(tilesNow, columns)
|
|
561
|
+
? {
|
|
562
|
+
pack: () =>
|
|
563
|
+
writeTiles(
|
|
564
|
+
inReadingOrder(pack(tilesNow, columns)),
|
|
565
|
+
selectedKey,
|
|
566
|
+
),
|
|
567
|
+
}
|
|
568
|
+
: {}),
|
|
569
|
+
flow: () => writeTiles(flowTiles(tilesNow), selectedKey),
|
|
570
|
+
}
|
|
571
|
+
: undefined;
|
|
451
572
|
useReportControls(onControlsChange, {
|
|
452
573
|
...saveStatus,
|
|
453
574
|
...(toolbarProps.onSave ? { save: toolbarProps.onSave } : {}),
|
|
@@ -468,6 +589,7 @@ export function ReportBuilder({
|
|
|
468
589
|
...(toolbarProps.onExit ? { exit: toolbarProps.onExit } : {}),
|
|
469
590
|
...(session.done ? { done: session.done } : {}),
|
|
470
591
|
...(restored?.pending ? { restore: draft.restoreOffered } : {}),
|
|
592
|
+
...(arrangeActions ? { arrange: arrangeActions } : {}),
|
|
471
593
|
});
|
|
472
594
|
// The builder's actions: on the title's line, at the right, above the
|
|
473
595
|
// description.
|
|
@@ -476,6 +598,9 @@ export function ReportBuilder({
|
|
|
476
598
|
{...session.toolbarProps}
|
|
477
599
|
{...(toolbar ? { actions: toolbar } : {})}
|
|
478
600
|
{...(catalog ? { onAddTile: () => openAdd() } : {})}
|
|
601
|
+
{...(arrangeActions
|
|
602
|
+
? { arrange: <ArrangeMenu arrange={arrangeActions} /> }
|
|
603
|
+
: {})}
|
|
479
604
|
savesTo={savesTo}
|
|
480
605
|
{...(saveLabel ? { saveLabel } : {})}
|
|
481
606
|
{...(draftKey !== undefined && toolbarProps.onSave
|
|
@@ -618,10 +743,19 @@ export function ReportBuilder({
|
|
|
618
743
|
<Alert severity="warning">{editor.error}</Alert>
|
|
619
744
|
)}
|
|
620
745
|
|
|
746
|
+
{!arrange && (
|
|
747
|
+
<Alert severity="info">
|
|
748
|
+
This window is too narrow for the grid, so tiles stack in
|
|
749
|
+
one column, as on a phone. Widen it to move tiles or change
|
|
750
|
+
their width.
|
|
751
|
+
</Alert>
|
|
752
|
+
)}
|
|
621
753
|
<BuilderGrid
|
|
622
754
|
editor={editor}
|
|
755
|
+
arrange={arrange}
|
|
623
756
|
reorder={reorder}
|
|
624
|
-
|
|
757
|
+
edging={edging}
|
|
758
|
+
place={place}
|
|
625
759
|
gridBox={gridBox}
|
|
626
760
|
defaultSpan={defaultSpan}
|
|
627
761
|
rules={rules}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { fireEvent, render, screen, within } from "@testing-library/react";
|
|
5
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import {
|
|
7
|
+
clearCache,
|
|
8
|
+
mockServerProvider,
|
|
9
|
+
pending,
|
|
10
|
+
serverWrapper,
|
|
11
|
+
} from "../../../test/serverProvider";
|
|
12
|
+
import {
|
|
13
|
+
DocumentNotFoundError,
|
|
14
|
+
type DocumentLocator,
|
|
15
|
+
type DocumentStorage,
|
|
16
|
+
type Workspace,
|
|
17
|
+
} from "../DocumentStorage";
|
|
18
|
+
import { DocumentStorageProvider } from "../DocumentStorage/DocumentStorageProvider";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Which charts a tile can take come from the report file's own compiled
|
|
22
|
+
* model, for the views it declares. That model is the package's file, so it
|
|
23
|
+
* speaks for the builder only while the builder is on that text: a host's
|
|
24
|
+
* record can declare a view of the same name with another shape.
|
|
25
|
+
*/
|
|
26
|
+
const file = (
|
|
27
|
+
body: string,
|
|
28
|
+
) => `## artifact { title="Overview" tiles=["a -> kpis"] }
|
|
29
|
+
import { scoped_orders } from "../data_app.malloy"
|
|
30
|
+
|
|
31
|
+
source: a is scoped_orders extend {
|
|
32
|
+
# label="Key figures"
|
|
33
|
+
view: kpis is { ${body} }
|
|
34
|
+
}`;
|
|
35
|
+
const PACKAGE_FILE = file("aggregate: revenue, order_count");
|
|
36
|
+
const RECORD_FILE = file("group_by: carrier; aggregate: revenue");
|
|
37
|
+
|
|
38
|
+
const total = (name: string) => ({
|
|
39
|
+
kind: "dimension",
|
|
40
|
+
name,
|
|
41
|
+
type: { kind: "number_type" },
|
|
42
|
+
annotations: [{ value: '#(malloy) reference_id = "x" calculation\n' }],
|
|
43
|
+
});
|
|
44
|
+
// The package file's compile: `kpis` is two totals and nothing else.
|
|
45
|
+
const SERVED = {
|
|
46
|
+
modelPath: "dashboards/overview.malloy",
|
|
47
|
+
sourceText: PACKAGE_FILE,
|
|
48
|
+
sources: [{ name: "a", views: [{ name: "kpis" }] }],
|
|
49
|
+
sourceInfos: [
|
|
50
|
+
JSON.stringify({
|
|
51
|
+
name: "a",
|
|
52
|
+
schema: {
|
|
53
|
+
fields: [
|
|
54
|
+
{
|
|
55
|
+
kind: "view",
|
|
56
|
+
name: "kpis",
|
|
57
|
+
schema: { fields: [total("revenue"), total("order_count")] },
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
mockServerProvider(
|
|
66
|
+
{
|
|
67
|
+
models: {
|
|
68
|
+
getModel: mock((_env: string, _pkg: string, path: string) =>
|
|
69
|
+
Promise.resolve({
|
|
70
|
+
data:
|
|
71
|
+
path === "dashboards/overview.malloy"
|
|
72
|
+
? SERVED
|
|
73
|
+
: { modelPath: path, sources: [], sourceInfos: [] },
|
|
74
|
+
}),
|
|
75
|
+
),
|
|
76
|
+
executeQueryModel: mock(() => pending()),
|
|
77
|
+
listModels: mock(() => Promise.resolve({ data: [] })),
|
|
78
|
+
},
|
|
79
|
+
reports: {
|
|
80
|
+
getReport: mock(() =>
|
|
81
|
+
Promise.resolve({
|
|
82
|
+
data: {
|
|
83
|
+
path: "dashboards/overview.malloy",
|
|
84
|
+
givens: [],
|
|
85
|
+
tiles: [],
|
|
86
|
+
},
|
|
87
|
+
}),
|
|
88
|
+
),
|
|
89
|
+
listReports: mock(() => Promise.resolve({ data: [] })),
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{ mutable: true },
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const { ReportEditor } = await import("./ReportEditor");
|
|
96
|
+
|
|
97
|
+
beforeEach(() => clearCache());
|
|
98
|
+
|
|
99
|
+
/** A host store that is the record, holding one document. */
|
|
100
|
+
class RecordStorage implements DocumentStorage {
|
|
101
|
+
private readonly workspace: Workspace = {
|
|
102
|
+
name: "Branch",
|
|
103
|
+
writeable: true,
|
|
104
|
+
description: "Saved to the draft branch",
|
|
105
|
+
authoritative: true,
|
|
106
|
+
};
|
|
107
|
+
constructor(private readonly text: string) {}
|
|
108
|
+
async listWorkspaces(): Promise<Workspace[]> {
|
|
109
|
+
return [this.workspace];
|
|
110
|
+
}
|
|
111
|
+
async listDocuments(): Promise<DocumentLocator[]> {
|
|
112
|
+
return [
|
|
113
|
+
{
|
|
114
|
+
workspace: this.workspace.name,
|
|
115
|
+
type: "grid",
|
|
116
|
+
path: "env/pkg/dashboards/overview.malloy",
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
async getDocument(locator: DocumentLocator): Promise<string> {
|
|
121
|
+
if (locator.path !== "env/pkg/dashboards/overview.malloy")
|
|
122
|
+
throw new DocumentNotFoundError(`No dashboard at ${locator.path}`);
|
|
123
|
+
return this.text;
|
|
124
|
+
}
|
|
125
|
+
async saveDocument(): Promise<void> {}
|
|
126
|
+
async deleteDocument(): Promise<void> {}
|
|
127
|
+
async moveDocument(): Promise<void> {
|
|
128
|
+
throw new Error("not exercised");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const editor = (
|
|
133
|
+
<ReportEditor
|
|
134
|
+
environmentName="env"
|
|
135
|
+
packageName="pkg"
|
|
136
|
+
dashboardName="overview"
|
|
137
|
+
/>
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
/** The Line choice in the open tile's Chart submenu. */
|
|
141
|
+
const lineChoice = async () => {
|
|
142
|
+
fireEvent.click(await screen.findByLabelText("Settings for Key figures"));
|
|
143
|
+
fireEvent.click(
|
|
144
|
+
screen.getByRole("menuitem", { name: /^Chart/, hidden: true }),
|
|
145
|
+
);
|
|
146
|
+
const menu = screen.getByRole("menu", { name: "Chart", hidden: true });
|
|
147
|
+
return within(menu)
|
|
148
|
+
.getAllByRole("menuitemradio", { hidden: true })
|
|
149
|
+
.find(
|
|
150
|
+
(item) =>
|
|
151
|
+
item.querySelector(".MuiListItemText-primary")?.textContent ===
|
|
152
|
+
"Line",
|
|
153
|
+
) as HTMLElement;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
describe("the chart choices of a view the report declares", () => {
|
|
157
|
+
it("follow the package's compile while the builder is on the package's file", async () => {
|
|
158
|
+
render(editor, { wrapper: serverWrapper });
|
|
159
|
+
const line = await lineChoice();
|
|
160
|
+
expect(line.getAttribute("aria-disabled")).toBe("true");
|
|
161
|
+
expect(line.textContent).toContain(
|
|
162
|
+
"This view has no field for the x-axis",
|
|
163
|
+
);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("do not follow it on a record whose view of the same name has another shape", async () => {
|
|
167
|
+
render(
|
|
168
|
+
<DocumentStorageProvider
|
|
169
|
+
documentStorage={new RecordStorage(RECORD_FILE)}
|
|
170
|
+
>
|
|
171
|
+
{editor}
|
|
172
|
+
</DocumentStorageProvider>,
|
|
173
|
+
{ wrapper: serverWrapper },
|
|
174
|
+
);
|
|
175
|
+
const line = await lineChoice();
|
|
176
|
+
expect(line.getAttribute("aria-disabled")).not.toBe("true");
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -220,7 +220,7 @@ source: recalls_tiles is recalls extend {
|
|
|
220
220
|
],
|
|
221
221
|
};
|
|
222
222
|
|
|
223
|
-
it("can
|
|
223
|
+
it("can make the model filter's current value the report's default", async () => {
|
|
224
224
|
packageFile = RECALLS;
|
|
225
225
|
served = READS_MANUFACTURER;
|
|
226
226
|
open();
|
|
@@ -229,13 +229,11 @@ source: recalls_tiles is recalls extend {
|
|
|
229
229
|
);
|
|
230
230
|
fireEvent.click(
|
|
231
231
|
await screen.findByRole("button", {
|
|
232
|
-
name: "
|
|
232
|
+
name: "Make this the report's default",
|
|
233
233
|
}),
|
|
234
234
|
);
|
|
235
235
|
// The report now holds it: the popover says so, and Undo takes it back.
|
|
236
|
-
expect(
|
|
237
|
-
await screen.findByText("The report opens with this value."),
|
|
238
|
-
).toBeDefined();
|
|
236
|
+
expect(await screen.findByText("Report default")).toBeDefined();
|
|
239
237
|
expect(
|
|
240
238
|
(
|
|
241
239
|
screen.getByRole("button", {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { render, screen, within } from "@testing-library/react";
|
|
5
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import type { DashboardManifest } from "../../client";
|
|
7
|
+
import {
|
|
8
|
+
clearCache,
|
|
9
|
+
mockServerProvider,
|
|
10
|
+
pending,
|
|
11
|
+
serverWrapper,
|
|
12
|
+
} from "../../../test/serverProvider";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A tile the builder shows read-only keeps the title the reader gives it. Its
|
|
16
|
+
* `# label` sits on a declaration the builder does not read (a named query, or
|
|
17
|
+
* a view in the model), so the served manifest's label is the one to show.
|
|
18
|
+
*/
|
|
19
|
+
const packageFile = `## artifact { title="Flights" tiles=["by_carrier", "flights -> by_month"] }
|
|
20
|
+
import { flights } from "../flights.malloy"
|
|
21
|
+
|
|
22
|
+
# label="Flights by airline"
|
|
23
|
+
# bar_chart
|
|
24
|
+
query: by_carrier is flights -> { group_by: carrier; aggregate: flight_count }`;
|
|
25
|
+
|
|
26
|
+
const served: Partial<DashboardManifest> = {
|
|
27
|
+
tiles: [
|
|
28
|
+
{
|
|
29
|
+
kind: "query",
|
|
30
|
+
query: "by_carrier",
|
|
31
|
+
label: "Flights by airline",
|
|
32
|
+
givenNames: [],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
kind: "query",
|
|
36
|
+
query: "flights -> by_month",
|
|
37
|
+
label: "Flights each month",
|
|
38
|
+
givenNames: [],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
mockServerProvider(
|
|
44
|
+
{
|
|
45
|
+
models: {
|
|
46
|
+
getModel: mock((_env: string, _pkg: string, path: string) =>
|
|
47
|
+
Promise.resolve({
|
|
48
|
+
data:
|
|
49
|
+
path === "dashboards/flights.malloy"
|
|
50
|
+
? { modelPath: path, sourceText: packageFile }
|
|
51
|
+
: { modelPath: path, sources: [], sourceInfos: [] },
|
|
52
|
+
}),
|
|
53
|
+
),
|
|
54
|
+
executeQueryModel: mock(() => pending()),
|
|
55
|
+
listModels: mock(() => Promise.resolve({ data: [] })),
|
|
56
|
+
},
|
|
57
|
+
reports: {
|
|
58
|
+
getReport: mock(() =>
|
|
59
|
+
Promise.resolve({
|
|
60
|
+
data: { path: "dashboards/flights.malloy", ...served },
|
|
61
|
+
}),
|
|
62
|
+
),
|
|
63
|
+
listReports: mock(() => Promise.resolve({ data: [] })),
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{ mutable: true },
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const { ReportEditor } = await import("./ReportEditor");
|
|
70
|
+
|
|
71
|
+
beforeEach(() => clearCache());
|
|
72
|
+
|
|
73
|
+
describe("a read-only tile's title in the builder", () => {
|
|
74
|
+
it("is the served label, as the reader shows it, not one derived from the name", async () => {
|
|
75
|
+
render(
|
|
76
|
+
<ReportEditor
|
|
77
|
+
environmentName="env"
|
|
78
|
+
packageName="pkg"
|
|
79
|
+
dashboardName="flights"
|
|
80
|
+
/>,
|
|
81
|
+
{ wrapper: serverWrapper },
|
|
82
|
+
);
|
|
83
|
+
const named = await screen.findByLabelText("Tile by_carrier");
|
|
84
|
+
expect(
|
|
85
|
+
await within(named).findByText("Flights by airline"),
|
|
86
|
+
).toBeDefined();
|
|
87
|
+
expect(within(named).queryByText("By carrier")).toBeNull();
|
|
88
|
+
// A view in the model is read-only too, and titled the same way.
|
|
89
|
+
const inherited = screen.getByLabelText("Tile by_month");
|
|
90
|
+
expect(within(inherited).getByText("Flights each month")).toBeDefined();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -5,6 +5,7 @@ import { clearReportDraft, reportDraftKey } from "./useReportDraft";
|
|
|
5
5
|
import { Alert, Button, Stack } from "@mui/material";
|
|
6
6
|
import { useQueryClient } from "@tanstack/react-query";
|
|
7
7
|
import { useCallback, useEffect, useRef } from "react";
|
|
8
|
+
import type { CompiledModel } from "../../client";
|
|
8
9
|
import type { HostGivenValue } from "../../hooks/givenValue";
|
|
9
10
|
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
10
11
|
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
@@ -408,6 +409,17 @@ export function ReportEditor(props: ReportEditorProps) {
|
|
|
408
409
|
|
|
409
410
|
// One per report, version and server: a draft is never restored onto a
|
|
410
411
|
// file it was not made on.
|
|
412
|
+
// The file's compiled model, only while the builder is on the text it
|
|
413
|
+
// compiled. A kept draft, the host's record or a version held back is other
|
|
414
|
+
// text, whose views can differ under the same names.
|
|
415
|
+
const fileModel =
|
|
416
|
+
!textSource &&
|
|
417
|
+
modelQuery.data?.data &&
|
|
418
|
+
packageText !== undefined &&
|
|
419
|
+
opened?.source === packageText
|
|
420
|
+
? (modelQuery.data.data as CompiledModel)
|
|
421
|
+
: undefined;
|
|
422
|
+
|
|
411
423
|
const draftKey = keepDraft
|
|
412
424
|
? reportDraftKey({
|
|
413
425
|
server,
|
|
@@ -574,6 +586,7 @@ export function ReportEditor(props: ReportEditorProps) {
|
|
|
574
586
|
{...(saveLabel ? { saveLabel } : {})}
|
|
575
587
|
{...(onEvent ? { onEvent: reportEvent } : {})}
|
|
576
588
|
note={note}
|
|
589
|
+
{...(fileModel ? { fileModel } : {})}
|
|
577
590
|
/>
|
|
578
591
|
)}
|
|
579
592
|
</Stack>
|