@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.
Files changed (164) hide show
  1. package/dist/RenderedResult-5hOs5XnV.cjs.js +171 -0
  2. package/dist/RenderedResult-DxmHGZNQ.es.js +671 -0
  3. package/dist/{ServerProvider-BV7IoDMR.es.js → ServerProvider-D7neZcTk.es.js} +283 -265
  4. package/dist/ServerProvider-e2369oom.cjs.js +1 -0
  5. package/dist/builder/index.cjs.js +80 -79
  6. package/dist/builder/index.es.js +7732 -6717
  7. package/dist/builder-entry.d.ts +1 -1
  8. package/dist/client/api.d.ts +31 -7
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +1 -1
  11. package/dist/components/Dashboard/DashboardGrid.d.ts +51 -1
  12. package/dist/components/Dashboard/DashboardTile.d.ts +7 -2
  13. package/dist/components/Dashboard/DashboardView.d.ts +9 -2
  14. package/dist/components/Dashboard/index.d.ts +1 -1
  15. package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
  16. package/dist/components/Dashboard/useStuck.d.ts +18 -12
  17. package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
  18. package/dist/components/RenderedResult/ResultContainer.d.ts +18 -1
  19. package/dist/components/RenderedResult/ResultPanel.d.ts +7 -1
  20. package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
  21. package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
  22. package/dist/components/RenderedResult/resultSizing.d.ts +47 -6
  23. package/dist/components/Report/Report.d.ts +7 -1
  24. package/dist/components/Report/ReportPage.d.ts +7 -0
  25. package/dist/components/Report/layoutRules.d.ts +45 -0
  26. package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
  27. package/dist/components/ReportBuilder/ArrangeMenu.d.ts +9 -0
  28. package/dist/components/ReportBuilder/BuilderGrid.d.ts +15 -4
  29. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
  30. package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
  31. package/dist/components/ReportBuilder/EditorSurface.d.ts +10 -1
  32. package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
  33. package/dist/components/ReportBuilder/TileFrame.d.ts +54 -10
  34. package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
  35. package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
  36. package/dist/components/ReportBuilder/catalog.d.ts +23 -0
  37. package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
  38. package/dist/components/ReportBuilder/controls.d.ts +2 -2
  39. package/dist/components/ReportBuilder/document.d.ts +53 -5
  40. package/dist/components/ReportBuilder/imports.d.ts +7 -0
  41. package/dist/components/ReportBuilder/placement.d.ts +121 -0
  42. package/dist/components/ReportBuilder/preview.d.ts +59 -10
  43. package/dist/components/ReportBuilder/sortable.d.ts +12 -1
  44. package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
  45. package/dist/components/ReportBuilder/useBuilderShortcuts.d.ts +9 -1
  46. package/dist/components/ReportBuilder/useEdgeResize.d.ts +84 -0
  47. package/dist/components/ReportBuilder/useTileReorder.d.ts +30 -3
  48. package/dist/index.cjs.js +7 -7
  49. package/dist/index.es.js +3349 -3307
  50. package/dist/text/index.es.js +1 -1
  51. package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
  52. package/dist/theme/classes.d.ts +1 -1
  53. package/dist/theme/resolveTheme.d.ts +15 -0
  54. package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-CaYP_OYG.es.js} +6353 -6047
  55. package/dist/useCompiledDocument-zYEfLogf.cjs.js +142 -0
  56. package/dist/utils/blankQuoted.d.ts +15 -0
  57. package/package.json +1 -1
  58. package/src/builder-entry.ts +1 -0
  59. package/src/components/Dashboard/DashboardGrid.tsx +129 -10
  60. package/src/components/Dashboard/DashboardTile.tsx +15 -1
  61. package/src/components/Dashboard/DashboardView.tsx +64 -10
  62. package/src/components/Dashboard/TileCard.tsx +6 -0
  63. package/src/components/Dashboard/index.ts +1 -0
  64. package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
  65. package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
  66. package/src/components/Dashboard/tileHeight.spec.ts +72 -0
  67. package/src/components/Dashboard/useStuck.ts +76 -28
  68. package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
  69. package/src/components/Package/NewDocumentDialog.tsx +10 -11
  70. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
  71. package/src/components/RenderedResult/RenderedResult.tsx +39 -6
  72. package/src/components/RenderedResult/ResultContainer.tsx +99 -10
  73. package/src/components/RenderedResult/ResultPanel.tsx +25 -1
  74. package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
  75. package/src/components/RenderedResult/chartPresentation.ts +166 -0
  76. package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
  77. package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
  78. package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
  79. package/src/components/RenderedResult/resultSizing.ts +71 -11
  80. package/src/components/Report/Report.spec.tsx +19 -0
  81. package/src/components/Report/Report.tsx +8 -1
  82. package/src/components/Report/ReportPage.tsx +13 -1
  83. package/src/components/Report/layoutRules.spec.ts +43 -3
  84. package/src/components/Report/layoutRules.ts +70 -0
  85. package/src/components/Report/tileOverflow.spec.tsx +162 -0
  86. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
  87. package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
  88. package/src/components/ReportBuilder/ArrangeMenu.tsx +80 -0
  89. package/src/components/ReportBuilder/BuilderBar.tsx +5 -1
  90. package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -1
  91. package/src/components/ReportBuilder/BuilderGrid.tsx +142 -35
  92. package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
  93. package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
  94. package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
  95. package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
  96. package/src/components/ReportBuilder/EditorSurface.tsx +101 -20
  97. package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
  98. package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
  99. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
  100. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
  101. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
  102. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +242 -2
  103. package/src/components/ReportBuilder/ReportBuilder.tsx +161 -27
  104. package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
  105. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
  106. package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
  107. package/src/components/ReportBuilder/ReportEditor.tsx +13 -0
  108. package/src/components/ReportBuilder/TileFrame.tsx +366 -170
  109. package/src/components/ReportBuilder/TileMenu.tsx +259 -20
  110. package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
  111. package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
  112. package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
  113. package/src/components/ReportBuilder/builderControls.ts +34 -0
  114. package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
  115. package/src/components/ReportBuilder/catalog.ts +90 -37
  116. package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
  117. package/src/components/ReportBuilder/chartLine.ts +80 -2
  118. package/src/components/ReportBuilder/controls.ts +4 -3
  119. package/src/components/ReportBuilder/document.ts +65 -7
  120. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  121. package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
  122. package/src/components/ReportBuilder/imports.ts +1 -1
  123. package/src/components/ReportBuilder/invariants.spec.ts +18 -10
  124. package/src/components/ReportBuilder/layout.ts +3 -0
  125. package/src/components/ReportBuilder/placement.spec.ts +401 -0
  126. package/src/components/ReportBuilder/placement.ts +416 -0
  127. package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
  128. package/src/components/ReportBuilder/preview.spec.ts +151 -11
  129. package/src/components/ReportBuilder/preview.ts +203 -40
  130. package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
  131. package/src/components/ReportBuilder/readDocument.spec.ts +53 -19
  132. package/src/components/ReportBuilder/readDocument.ts +197 -29
  133. package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
  134. package/src/components/ReportBuilder/sortable.tsx +30 -2
  135. package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
  136. package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
  137. package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
  138. package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -58
  139. package/src/components/ReportBuilder/spliceDocument.ts +139 -91
  140. package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
  141. package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
  142. package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
  143. package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
  144. package/src/components/ReportBuilder/useBuilderSession.ts +7 -2
  145. package/src/components/ReportBuilder/useBuilderShortcuts.ts +25 -1
  146. package/src/components/ReportBuilder/useEdgeResize.spec.tsx +324 -0
  147. package/src/components/ReportBuilder/useEdgeResize.ts +397 -0
  148. package/src/components/ReportBuilder/useTileEditing.ts +16 -3
  149. package/src/components/ReportBuilder/useTileReorder.ts +143 -6
  150. package/src/components/given/FilterButton.spec.tsx +27 -11
  151. package/src/components/given/FilterButton.tsx +19 -6
  152. package/src/theme/classes.ts +1 -1
  153. package/src/theme/resolveTheme.spec.ts +72 -1
  154. package/src/theme/resolveTheme.ts +43 -0
  155. package/src/utils/blankQuoted.spec.ts +50 -0
  156. package/src/utils/blankQuoted.ts +32 -0
  157. package/src/utils/malloyText.ts +2 -1
  158. package/dist/RenderedResult-DnBtf-cI.es.js +0 -593
  159. package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
  160. package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
  161. package/dist/components/ReportBuilder/useTileResize.d.ts +0 -32
  162. package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
  163. package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
  164. package/src/components/ReportBuilder/useTileResize.ts +0 -133
@@ -0,0 +1,80 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import DashboardOutlinedIcon from "@mui/icons-material/DashboardOutlined";
5
+ import {
6
+ IconButton,
7
+ ListItemText,
8
+ Menu,
9
+ MenuItem,
10
+ Tooltip,
11
+ } from "@mui/material";
12
+ import { useState } from "react";
13
+ import { usePublisherTheme } from "../../theme/ThemeContext";
14
+ import { edgeColor } from "../controlTokens";
15
+ import { iconControlSx } from "./BuilderToolbar";
16
+
17
+ import type { ArrangeActions } from "./builderControls";
18
+
19
+ /**
20
+ * The layout of a placed grid report as a whole: closing its gaps, or letting
21
+ * its tiles flow again. One menu shared by the builder's own toolbar and the
22
+ * bar a host draws, so the two cannot offer different things.
23
+ */
24
+ export function ArrangeMenu({ arrange }: { arrange: ArrangeActions }) {
25
+ const { theme } = usePublisherTheme();
26
+ const [anchor, setAnchor] = useState<HTMLElement | null>(null);
27
+ const pick = (action: (() => void) | undefined) => () => {
28
+ setAnchor(null);
29
+ action?.();
30
+ };
31
+ return (
32
+ <>
33
+ <Tooltip title="Arrange tiles">
34
+ <IconButton
35
+ aria-label="Arrange tiles"
36
+ aria-haspopup="menu"
37
+ aria-expanded={anchor !== null}
38
+ onClick={(event) => setAnchor(event.currentTarget)}
39
+ sx={iconControlSx(theme.ui)}
40
+ >
41
+ <DashboardOutlinedIcon fontSize="small" />
42
+ </IconButton>
43
+ </Tooltip>
44
+ <Menu
45
+ anchorEl={anchor}
46
+ open={anchor !== null}
47
+ onClose={() => setAnchor(null)}
48
+ anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
49
+ transformOrigin={{ vertical: -6, horizontal: "right" }}
50
+ slotProps={{
51
+ paper: {
52
+ sx: {
53
+ minWidth: 260,
54
+ borderRadius: theme.ui.radius.menu,
55
+ border: `1px solid ${edgeColor(theme.cardBorder)}`,
56
+ boxShadow: theme.ui.shadow.menu,
57
+ },
58
+ },
59
+ }}
60
+ >
61
+ <MenuItem disabled={!arrange.pack} onClick={pick(arrange.pack)}>
62
+ <ListItemText
63
+ primary="Pack tiles upward"
64
+ secondary={
65
+ arrange.pack
66
+ ? "Close every gap above a tile"
67
+ : "There are no gaps to close"
68
+ }
69
+ />
70
+ </MenuItem>
71
+ <MenuItem onClick={pick(arrange.flow)}>
72
+ <ListItemText
73
+ primary="Let tiles flow"
74
+ secondary="Clear each tile's place; keep its size"
75
+ />
76
+ </MenuItem>
77
+ </Menu>
78
+ </>
79
+ );
80
+ }
@@ -27,6 +27,7 @@ import { usePublisherTheme } from "../../theme/ThemeContext";
27
27
  import { edgeColor, hoverEdgeColor } from "../controlTokens";
28
28
  import type { BuilderControls } from "./builderControls";
29
29
  import { controlSx, dividerSx, iconControlSx } from "./BuilderToolbar";
30
+ import { ArrangeMenu } from "./ArrangeMenu";
30
31
  import { SaveStatus } from "./SaveStatus";
31
32
  import { MOD } from "./useBuilderShortcuts";
32
33
 
@@ -118,6 +119,9 @@ export function BuilderBar({ controls, onDone: onDoneProp }: BuilderBarProps) {
118
119
  </IconButton>
119
120
  </span>
120
121
  </Tooltip>
122
+ {controls.arrange && (
123
+ <ArrangeMenu arrange={controls.arrange} />
124
+ )}
121
125
  {canAdd && (
122
126
  <Divider orientation="vertical" sx={dividerSx} />
123
127
  )}
@@ -167,7 +171,7 @@ export function BuilderBar({ controls, onDone: onDoneProp }: BuilderBarProps) {
167
171
  <AddItem
168
172
  icon={<InsertChartOutlinedIcon />}
169
173
  title="Tile"
170
- detail="A view from the model"
174
+ detail="A chart or table from the model"
171
175
  onClick={pick(add.tile)}
172
176
  />
173
177
  )}
@@ -1,6 +1,8 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
+ import { isPlaced } from "../Dashboard/DashboardGrid";
5
+ import { holdChartRows, settle } from "./placement";
4
6
  import { useState, type ComponentProps, type ReactNode } from "react";
5
7
  import { UnsavedChangesDialog } from "../UnsavedChangesDialog";
6
8
  import { AddTileDialog, type ViewPreview } from "./AddTileDialog";
@@ -57,6 +59,23 @@ export function BuilderDialogs({
57
59
  const menuTile = menuAt && isQueryTile(menuAt) ? menuAt : undefined;
58
60
  const menuView = (() => {
59
61
  if (!menuTile || !catalog) return undefined;
62
+ // A view this file declares is read off the file's own compiled model:
63
+ // an inline body is in no other model the catalog has.
64
+ const declared = catalog.documentViews
65
+ ?.get(menuTile.source ?? "")
66
+ ?.get(menuTile.name);
67
+ if (
68
+ declared &&
69
+ editor.document.sources.some((s) => s.name === menuTile.source)
70
+ )
71
+ return declared;
72
+ // An inline or opaque body is not a view of the base source, so a base
73
+ // view that happens to share its name says nothing about its shape.
74
+ if (
75
+ menuTile.declaration.kind === "inline" ||
76
+ menuTile.declaration.kind === "opaque"
77
+ )
78
+ return undefined;
60
79
  const base =
61
80
  editor.document.sources.find((s) => s.name === menuTile.source)
62
81
  ?.base ?? menuTile.source;
@@ -94,11 +113,19 @@ export function BuilderDialogs({
94
113
  onCommit={(next) => {
95
114
  const at = menu?.index;
96
115
  if (at === undefined) return;
116
+ // A chart picked on a tile too short to plot it raises the
117
+ // tile to a chart's rows, pushing down what it now covers.
118
+ const held = holdChartRows(next);
97
119
  editor.update((draft) => {
98
- draft.tiles[at] = next;
120
+ draft.tiles[at] = held;
121
+ if (held !== next && isPlaced(draft.tiles))
122
+ draft.tiles = settle(draft.tiles, columns, at);
99
123
  });
100
124
  }}
101
125
  view={menuView}
126
+ {...(menuView === undefined && menuTile
127
+ ? { viewStatus: catalog ? "unlisted" : "loading" }
128
+ : {})}
102
129
  onDuplicate={() => {
103
130
  if (menu) tiles.duplicate(menu.index);
104
131
  }}
@@ -5,11 +5,17 @@ import { DragDropProvider } from "@dnd-kit/react";
5
5
  import AddIcon from "@mui/icons-material/Add";
6
6
  import { Box, Button } from "@mui/material";
7
7
  import type { ReactNode, RefObject } from "react";
8
- import { DashboardGrid, GRID_GAP_PX } from "../Dashboard/DashboardGrid";
8
+ import {
9
+ DashboardGrid,
10
+ GRID_GAP_PX,
11
+ isPlaced,
12
+ PLACED_DEFAULT_ROWSPAN,
13
+ } from "../Dashboard/DashboardGrid";
9
14
  import type { TileChrome, TileHeadingSlots } from "../Dashboard/TileCard";
10
- import type { LayoutRules } from "../Report/layoutRules";
15
+ import { withSpan, type LayoutRules } from "../Report/layoutRules";
11
16
  import {
12
17
  isQueryTile,
18
+ isReadOnlyTile,
13
19
  isTextTile,
14
20
  tileKey,
15
21
  type DashboardTile,
@@ -17,23 +23,32 @@ import {
17
23
  } from "./document";
18
24
  import { InlineText } from "./InlineText";
19
25
  import { gapId, tileEntry, withGaps } from "./layout";
20
- import { builderSensors } from "./sortable";
26
+ import { minRowsOf, rowsOf, settle, widestFrom } from "./placement";
27
+ import { builderSensors, EscapeCancelsDrag } from "./sortable";
21
28
  import { TextTileBody } from "./TextTileBody";
22
- import { GapTarget, GridGuides, TileFrame, TilePlaceholder } from "./TileFrame";
29
+ import {
30
+ GapTarget,
31
+ GridGuides,
32
+ RowGuides,
33
+ TileFrame,
34
+ TilePlaceholder,
35
+ } from "./TileFrame";
23
36
  import { tileDisplayTitle } from "./tileDisplayTitle";
24
37
  import type { ReportEditorHandle } from "./useReportEditor";
25
38
  import type { useTileReorder } from "./useTileReorder";
26
- import type { useTileResize } from "./useTileResize";
39
+ import { shapeLabel, withShape, type useEdgeResize } from "./useEdgeResize";
27
40
 
28
41
  /**
29
42
  * The builder's tiles, on the SAME grid the dashboard renders on, each drawn
30
43
  * by the caller's `renderTile` inside a `TileFrame` that carries the
31
- * affordances: selection, the grip and menu, the width handle.
44
+ * affordances: selection, the menu, and its edges and corners.
32
45
  */
33
46
  export function BuilderGrid({
34
47
  editor,
35
48
  reorder,
36
- resizing,
49
+ edging,
50
+ place = (tiles) => tiles,
51
+ arrange = true,
37
52
  gridBox,
38
53
  defaultSpan = 1,
39
54
  rules,
@@ -51,7 +66,18 @@ export function BuilderGrid({
51
66
  }: {
52
67
  editor: ReportEditorHandle;
53
68
  reorder: ReturnType<typeof useTileReorder>;
54
- resizing: ReturnType<typeof useTileResize>;
69
+ /** Every edge and corner of a tile, dragged to resize it. */
70
+ edging: ReturnType<typeof useEdgeResize>;
71
+ /**
72
+ * The tiles after the one at `index` changed size: on a placed report,
73
+ * whatever it now covers pushed down. Identity elsewhere.
74
+ */
75
+ place?: (tiles: DashboardTile[], index: number) => DashboardTile[];
76
+ /**
77
+ * Whether tiles can be moved and widened here. Off while a grid is drawn
78
+ * as one column (a window narrower than the grid), where neither shows.
79
+ */
80
+ arrange?: boolean;
55
81
  gridBox: RefObject<HTMLDivElement | null>;
56
82
  /** The span a tile with no `# colspan` is drawn at: as wide as the reader draws it. */
57
83
  defaultSpan?: number;
@@ -77,9 +103,10 @@ export function BuilderGrid({
77
103
  chrome?: TileChrome,
78
104
  ) => ReactNode;
79
105
  }) {
80
- const { dragging, preview, onDragStart, onDragOver, onDragEnd } = reorder;
106
+ const { dragging, preview, onDragStart, onDragMove, onDragOver, onDragEnd } =
107
+ reorder;
81
108
  const { columns } = rules;
82
- const { resize, startResize, onResize, endResize } = resizing;
109
+ const edge = edging.drag;
83
110
  // What the grid lays out: the document, except mid-gesture, where it is
84
111
  // the preview — the tile being resized at its previewed width, or the tiles
85
112
  // in their previewed order. So the row reflows under the pointer exactly as
@@ -87,21 +114,38 @@ export function BuilderGrid({
87
114
  const drawn = (tile: DashboardTile): DashboardTile =>
88
115
  tile.colspan === undefined ? { ...tile, colspan: defaultSpan } : tile;
89
116
  const shown = (
90
- resize !== undefined
91
- ? editor.document.tiles.map((each, index) =>
92
- index === resize.index ? { ...each, colspan: resize.span } : each,
93
- )
117
+ edge !== undefined
118
+ ? (() => {
119
+ // The tiles as the resize would leave them: the one tile with
120
+ // the edges it moved, and on a placed report everything it now
121
+ // covers pushed down.
122
+ const base = edge.placedHere ? edge.base : editor.document.tiles;
123
+ const tile = base[edge.index];
124
+ if (!tile) return base;
125
+ const resized = base.map((each, index) =>
126
+ index === edge.index
127
+ ? withShape(each, edge.shape, edge.edges, edge.placed)
128
+ : each,
129
+ );
130
+ return edge.placed
131
+ ? settle(resized, columns, edge.index)
132
+ : resized;
133
+ })()
94
134
  : (preview ?? editor.document.tiles)
95
135
  ).map(drawn);
136
+ // Placed, every cell is somewhere to drop, so there are no row ends to offer.
137
+ const placed = isPlaced(shown);
138
+ const gesture = dragging || edge !== undefined;
139
+ // Faintly, while a tile of a placed report is selected and nothing is
140
+ // dragged: the empty cells read as places a tile can go before any drag.
141
+ const resting = !gesture && placed && arrange && selected !== undefined;
96
142
  // And, while a drag is live, the empty end of every row as a drop target.
97
143
  // While an edge is dragged too: narrowing a tile frees columns its row-mate
98
144
  // does not take, and an undrawn hole there read as a broken layout rather
99
145
  // than room to fill. Not otherwise: a gap is only shown mid-gesture.
100
146
  const empty = editor.document.tiles.length === 0;
101
147
  const entries =
102
- dragging || resize !== undefined
103
- ? withGaps(shown, columns)
104
- : shown.map(tileEntry);
148
+ gesture && !placed ? withGaps(shown, columns) : shown.map(tileEntry);
105
149
  const heading = (tile: QueryTile) =>
106
150
  headingOf(tile, tileDisplayTitle(tile), editTile);
107
151
  return (
@@ -109,18 +153,34 @@ export function BuilderGrid({
109
153
  <DragDropProvider
110
154
  sensors={builderSensors}
111
155
  onDragStart={onDragStart}
156
+ onDragMove={onDragMove}
112
157
  onDragOver={onDragOver}
113
158
  onDragEnd={onDragEnd}
114
159
  >
160
+ <EscapeCancelsDrag active={dragging} />
115
161
  <Box ref={gridBox} sx={{ position: "relative" }}>
116
- {rules.widths && (dragging || resize !== undefined) && (
117
- <GridGuides columns={columns} />
162
+ {rules.widths && (gesture || resting) && (
163
+ <GridGuides columns={columns} faint={!gesture} />
118
164
  )}
165
+ {edge !== undefined && !edge.placed
166
+ ? (edge.edges.s || edge.edges.n) && (
167
+ <RowGuides top={edge.guideTop} />
168
+ )
169
+ : // Placed, a move snaps to rows as well as columns.
170
+ placed &&
171
+ (gesture || resting) && (
172
+ <RowGuides top={0} faint={!gesture} />
173
+ )}
119
174
 
120
175
  <DashboardGrid
121
176
  tiles={entries}
122
177
  columns={columns}
123
178
  rowGapPx={GRID_GAP_PX}
179
+ defaultRowspan={(entry) =>
180
+ entry.kind === "tile"
181
+ ? rowsOf(entry.tile)
182
+ : PLACED_DEFAULT_ROWSPAN.query
183
+ }
124
184
  keyOf={(entry) =>
125
185
  entry.kind === "gap"
126
186
  ? gapId(entry.after)
@@ -149,24 +209,79 @@ export function BuilderGrid({
149
209
  onInsertAfter: () => openAdd(index + 1),
150
210
  }
151
211
  : {})}
152
- {...(rules.widths && resizable(each)
212
+ fixed={!arrange}
213
+ {...(rules.widths
214
+ ? {
215
+ edges: {
216
+ // Left and top move a place, so they
217
+ // need the grid drawn as a grid.
218
+ all: arrange,
219
+ right: arrange,
220
+ start: (event, edges) =>
221
+ edging.start(event, index, edges),
222
+ move: edging.move,
223
+ end: edging.end,
224
+ ...(edge?.index === index
225
+ ? { label: shapeLabel(edge, columns) }
226
+ : {}),
227
+ },
228
+ }
229
+ : {})}
230
+ {...(rules.widths && arrange
153
231
  ? {
154
- resizing: resize?.index === index,
155
232
  width: {
156
233
  span: each.colspan ?? 1,
157
234
  columns,
235
+ max: widestFrom(each, columns),
158
236
  onStep: (to: number) => {
159
237
  if (to === (each.colspan ?? 1)) return;
160
238
  editor.update((draft) => {
239
+ if (
240
+ !Number.isInteger(index) ||
241
+ index < 0
242
+ )
243
+ return;
161
244
  const tile = draft.tiles[index];
162
- if (tile) tile.colspan = to;
245
+ if (tile)
246
+ draft.tiles[index] = withSpan(
247
+ tile,
248
+ to,
249
+ columns,
250
+ defaultSpan,
251
+ );
252
+ draft.tiles = place(
253
+ draft.tiles,
254
+ index,
255
+ );
163
256
  });
164
257
  },
165
258
  },
166
- onResizeStart: (event) =>
167
- startResize(event, index),
168
- onResizeMove: onResize,
169
- onResizeEnd: endResize,
259
+ }
260
+ : {})}
261
+ {...(rules.widths
262
+ ? {
263
+ heightEdge: {
264
+ rows: each.rowspan,
265
+ min: minRowsOf(each),
266
+ minFor: (frame) => minRowsOf(each, frame),
267
+ onStep: (to) =>
268
+ editor.update((draft) => {
269
+ if (
270
+ !Number.isInteger(index) ||
271
+ index < 0
272
+ )
273
+ return;
274
+ const tile = draft.tiles[index];
275
+ if (!tile) return;
276
+ if (to === undefined)
277
+ delete tile.rowspan;
278
+ else tile.rowspan = to;
279
+ draft.tiles = place(
280
+ draft.tiles,
281
+ index,
282
+ );
283
+ }),
284
+ },
170
285
  }
171
286
  : {})}
172
287
  onSelect={() => onSelect(index)}
@@ -219,7 +334,7 @@ const headingOf = (
219
334
  fallback: string,
220
335
  editTile: (key: string, change: (tile: DashboardTile) => void) => void,
221
336
  ): TileHeadingSlots | undefined => {
222
- if (tile.declaration.kind === "inherited") return undefined;
337
+ if (isReadOnlyTile(tile)) return undefined;
223
338
  const key = tileKey(tile);
224
339
  const set = (field: "label" | "subtitle") => (next: string) =>
225
340
  editTile(key, (each) => {
@@ -247,11 +362,3 @@ const headingOf = (
247
362
  ),
248
363
  };
249
364
  };
250
-
251
- /**
252
- * Whether dragging this tile's edge can be saved: its width is a tag this file
253
- * owns. An inherited tile's tags live on the model's view, which the builder
254
- * does not write.
255
- */
256
- const resizable = (tile: DashboardTile): boolean =>
257
- isTextTile(tile) || tile.declaration.kind !== "inherited";
@@ -135,6 +135,8 @@ export interface BuilderToolbarProps {
135
135
  actions?: ReactNode;
136
136
  /** Open the add-tile picker. Absent when the host passed no catalog to pick from. */
137
137
  onAddTile?: () => void;
138
+ /** The arrange menu, on a report whose tiles are placed; drawn before Tile. */
139
+ arrange?: ReactNode;
138
140
  /**
139
141
  * Leave the builder: draws Close after Save, for a host that opts in. The
140
142
  * Console leaves from its own header and passes nothing.
@@ -161,6 +163,7 @@ export function BuilderToolbar({
161
163
  saveButton,
162
164
  actions,
163
165
  onAddTile,
166
+ arrange,
164
167
  onExit,
165
168
  saveStatus,
166
169
  }: BuilderToolbarProps) {
@@ -180,6 +183,7 @@ export function BuilderToolbar({
180
183
  "& .MuiButton-root": { whiteSpace: "nowrap" },
181
184
  }}
182
185
  >
186
+ {arrange}
183
187
  {/* What the page is made of. */}
184
188
  {onAddTile && (
185
189
  <Button
@@ -27,6 +27,7 @@ describe("chartChoices", () => {
27
27
  "scatter_chart",
28
28
  "shape_map",
29
29
  "segment_map",
30
+ "combo_chart",
30
31
  ]);
31
32
  expect(enabled(undefined, "default")).toEqual([
32
33
  "default",
@@ -37,13 +38,21 @@ describe("chartChoices", () => {
37
38
  ]);
38
39
  });
39
40
 
41
+ it("names the model's own chart Default, with a quiet line saying where it is set", () => {
42
+ expect(chartChoices(undefined, "default")[0]).toEqual({
43
+ value: "default",
44
+ label: "Default",
45
+ hint: "As set in the model",
46
+ });
47
+ });
48
+
40
49
  it("enables big_value only for an aggregate-only view, and says what it needs otherwise", () => {
41
50
  expect(enabled({ aggregateOnly: true }, "default")).toContain(
42
51
  "big_value",
43
52
  );
44
53
  expect(choice("big_value", {}, "default")).toMatchObject({
45
54
  disabled: true,
46
- reason: "Needs a view with only totals (no group by)",
55
+ reason: "Needs results that are only totals (no group by)",
47
56
  });
48
57
  });
49
58
 
@@ -56,16 +65,31 @@ describe("chartChoices", () => {
56
65
  choice("shape_map", { chart: "bar_chart" }, "default"),
57
66
  ).toMatchObject({
58
67
  disabled: true,
59
- reason: "Needs a view that already carries a map chart",
68
+ reason: "Needs a map chart set in the model",
69
+ });
70
+ });
71
+
72
+ it("enables a combo chart for a view with a group by and exactly two totals, and says what it needs otherwise", () => {
73
+ expect(
74
+ enabled({ shape: { groupBys: 1, totals: 2 } }, "default"),
75
+ ).toContain("combo_chart");
76
+ expect(enabled({ chart: "combo_chart" }, "default")).toContain(
77
+ "combo_chart",
78
+ );
79
+ expect(choice("combo_chart", {}, "default")).toMatchObject({
80
+ label: "Bar and line",
81
+ disabled: true,
82
+ reason:
83
+ "Needs a view with a group by and exactly two totals: the first is drawn as bars, the second as a line",
60
84
  });
61
85
  });
62
86
 
63
87
  it("words the reason by why the view's shape is unknown", () => {
64
88
  expect(choice("big_value", undefined, "default", "loading").reason).toBe(
65
- "Still loading this view's details",
89
+ "Still loading this tile's details",
66
90
  );
67
91
  expect(choice("shape_map", undefined, "default", "unlisted").reason).toBe(
68
- "Not a view the catalog lists, so its shape is unknown",
92
+ "Not in the model's list, so its shape is unknown",
69
93
  );
70
94
  });
71
95
 
@@ -75,3 +99,66 @@ describe("chartChoices", () => {
75
99
  expect(values({}, "custom")).toContain("custom");
76
100
  });
77
101
  });
102
+
103
+ describe("chartChoices on a view whose shape the model reported", () => {
104
+ const totalsOnly = {
105
+ aggregateOnly: true,
106
+ shape: { groupBys: 0, totals: 3 },
107
+ } as const;
108
+
109
+ it("greys out every chart that plots rows on a view of totals only, saying what is missing", () => {
110
+ // A scatter chart plots the first two columns, so two totals draw.
111
+ expect(enabled(totalsOnly, "default")).toEqual([
112
+ "default",
113
+ "none",
114
+ "big_value",
115
+ "scatter_chart",
116
+ ]);
117
+ for (const pick of ["line_chart", "bar_chart"])
118
+ expect(choice(pick, totalsOnly, "default").reason).toMatch(
119
+ /^This view has no field for the x-axis: a .* chart needs a group by, such as a date or a category$/,
120
+ );
121
+ const oneTotal = {
122
+ aggregateOnly: true,
123
+ shape: { groupBys: 0, totals: 1 },
124
+ };
125
+ expect(choice("scatter_chart", oneTotal, "default").reason).toBe(
126
+ "This view has no field for the x-axis: a scatter chart needs a group by, such as a date or a category",
127
+ );
128
+ expect(choice("combo_chart", totalsOnly, "default").reason).toBe(
129
+ "This view has no field for the x-axis: a bar and line chart needs a group by, such as a date or a category",
130
+ );
131
+ });
132
+
133
+ it("says a grouped view is more than one row when big numbers are asked for", () => {
134
+ const grouped = { shape: { groupBys: 1, totals: 1 } };
135
+ expect(choice("big_value", grouped, "default").reason).toBe(
136
+ "This view has a group by, so it is more than one row; big numbers need a view of totals only",
137
+ );
138
+ expect(enabled(grouped, "default")).toContain("line_chart");
139
+ });
140
+
141
+ it("says a view with no total has nothing for the y-axis", () => {
142
+ const noTotals = { shape: { groupBys: 2, totals: 0 } };
143
+ expect(choice("bar_chart", noTotals, "default").reason).toBe(
144
+ "This view has no total for the y-axis: a bar chart needs at least one aggregate",
145
+ );
146
+ // A scatter chart may plot two group-bys against each other, as the
147
+ // result panel also allows.
148
+ expect(enabled(noTotals, "default")).toContain("scatter_chart");
149
+ });
150
+
151
+ it("does not say a view of totals and a nest has a group by", () => {
152
+ const nested = { shape: { groupBys: 0, totals: 1 } };
153
+ expect(choice("big_value", nested, "default").reason).toBe(
154
+ "Needs results that are only totals (no group by)",
155
+ );
156
+ });
157
+
158
+ it("names the count when a bar and line chart gets the wrong number of totals", () => {
159
+ const three = { shape: { groupBys: 1, totals: 3 } };
160
+ expect(choice("combo_chart", three, "default").reason).toBe(
161
+ "A bar and line chart needs exactly two totals, the first drawn as bars and the second as a line; this view has 3",
162
+ );
163
+ });
164
+ });