@malloy-publisher/sdk 0.9.13 → 0.9.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/dist/RenderedResult-BClN_PG6.cjs.js +154 -0
  2. package/dist/{RenderedResult-DnBtf-cI.es.js → RenderedResult-YBzVMVH2.es.js} +295 -234
  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 +7430 -6548
  7. package/dist/client/api.d.ts +30 -6
  8. package/dist/client/index.cjs.js +1 -1
  9. package/dist/client/index.es.js +1 -1
  10. package/dist/components/Dashboard/DashboardGrid.d.ts +49 -1
  11. package/dist/components/Dashboard/DashboardTile.d.ts +5 -2
  12. package/dist/components/Dashboard/DashboardView.d.ts +9 -2
  13. package/dist/components/Dashboard/index.d.ts +1 -1
  14. package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
  15. package/dist/components/Dashboard/useStuck.d.ts +18 -12
  16. package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
  17. package/dist/components/RenderedResult/ResultContainer.d.ts +11 -1
  18. package/dist/components/RenderedResult/ResultPanel.d.ts +5 -1
  19. package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
  20. package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
  21. package/dist/components/RenderedResult/resultSizing.d.ts +42 -6
  22. package/dist/components/Report/Report.d.ts +7 -1
  23. package/dist/components/Report/ReportPage.d.ts +7 -0
  24. package/dist/components/Report/layoutRules.d.ts +45 -0
  25. package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
  26. package/dist/components/ReportBuilder/BuilderGrid.d.ts +14 -1
  27. package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
  28. package/dist/components/ReportBuilder/EditorSurface.d.ts +17 -1
  29. package/dist/components/ReportBuilder/ReportEditor.d.ts +18 -0
  30. package/dist/components/ReportBuilder/TileFrame.d.ts +33 -1
  31. package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
  32. package/dist/components/ReportBuilder/catalog.d.ts +23 -0
  33. package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
  34. package/dist/components/ReportBuilder/controls.d.ts +2 -2
  35. package/dist/components/ReportBuilder/document.d.ts +53 -5
  36. package/dist/components/ReportBuilder/imports.d.ts +7 -0
  37. package/dist/components/ReportBuilder/placement.d.ts +75 -0
  38. package/dist/components/ReportBuilder/preview.d.ts +59 -10
  39. package/dist/components/ReportBuilder/sortable.d.ts +3 -1
  40. package/dist/components/ReportBuilder/useTileHeight.d.ts +39 -0
  41. package/dist/components/ReportBuilder/useTileReorder.d.ts +27 -3
  42. package/dist/components/ReportBuilder/useTileResize.d.ts +8 -0
  43. package/dist/index.cjs.js +7 -7
  44. package/dist/index.es.js +3328 -3287
  45. package/dist/text/index.es.js +1 -1
  46. package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
  47. package/dist/theme/resolveTheme.d.ts +15 -0
  48. package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-BGk38oaW.es.js} +5097 -4805
  49. package/dist/useCompiledDocument-D9t5ry_t.cjs.js +142 -0
  50. package/dist/utils/blankQuoted.d.ts +15 -0
  51. package/package.json +1 -1
  52. package/src/components/Dashboard/DashboardGrid.tsx +127 -10
  53. package/src/components/Dashboard/DashboardTile.tsx +11 -1
  54. package/src/components/Dashboard/DashboardView.tsx +63 -10
  55. package/src/components/Dashboard/TileCard.tsx +6 -0
  56. package/src/components/Dashboard/index.ts +1 -0
  57. package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
  58. package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
  59. package/src/components/Dashboard/tileHeight.spec.ts +72 -0
  60. package/src/components/Dashboard/useStuck.ts +76 -28
  61. package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
  62. package/src/components/Package/NewDocumentDialog.tsx +10 -11
  63. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
  64. package/src/components/RenderedResult/RenderedResult.tsx +21 -6
  65. package/src/components/RenderedResult/ResultContainer.tsx +60 -7
  66. package/src/components/RenderedResult/ResultPanel.tsx +21 -1
  67. package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
  68. package/src/components/RenderedResult/chartPresentation.ts +166 -0
  69. package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
  70. package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
  71. package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
  72. package/src/components/RenderedResult/resultSizing.ts +65 -11
  73. package/src/components/Report/Report.spec.tsx +19 -0
  74. package/src/components/Report/Report.tsx +8 -1
  75. package/src/components/Report/ReportPage.tsx +13 -1
  76. package/src/components/Report/layoutRules.spec.ts +43 -3
  77. package/src/components/Report/layoutRules.ts +70 -0
  78. package/src/components/Report/tileOverflow.spec.tsx +162 -0
  79. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
  80. package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
  81. package/src/components/ReportBuilder/BuilderBar.tsx +1 -1
  82. package/src/components/ReportBuilder/BuilderDialogs.tsx +20 -0
  83. package/src/components/ReportBuilder/BuilderGrid.tsx +126 -20
  84. package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
  85. package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
  86. package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
  87. package/src/components/ReportBuilder/EditorSurface.tsx +110 -28
  88. package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
  89. package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
  90. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
  91. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
  92. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
  93. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +143 -2
  94. package/src/components/ReportBuilder/ReportBuilder.tsx +73 -19
  95. package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
  96. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
  97. package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +292 -0
  98. package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
  99. package/src/components/ReportBuilder/ReportEditor.tsx +35 -0
  100. package/src/components/ReportBuilder/TileFrame.tsx +251 -6
  101. package/src/components/ReportBuilder/TileMenu.tsx +259 -20
  102. package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
  103. package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
  104. package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
  105. package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
  106. package/src/components/ReportBuilder/catalog.ts +90 -37
  107. package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
  108. package/src/components/ReportBuilder/chartLine.ts +80 -2
  109. package/src/components/ReportBuilder/controls.ts +4 -3
  110. package/src/components/ReportBuilder/document.ts +65 -7
  111. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  112. package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
  113. package/src/components/ReportBuilder/imports.ts +1 -1
  114. package/src/components/ReportBuilder/invariants.spec.ts +18 -10
  115. package/src/components/ReportBuilder/layout.ts +3 -0
  116. package/src/components/ReportBuilder/placement.spec.ts +193 -0
  117. package/src/components/ReportBuilder/placement.ts +250 -0
  118. package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
  119. package/src/components/ReportBuilder/preview.spec.ts +151 -11
  120. package/src/components/ReportBuilder/preview.ts +203 -40
  121. package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
  122. package/src/components/ReportBuilder/readDocument.spec.ts +46 -2
  123. package/src/components/ReportBuilder/readDocument.ts +194 -23
  124. package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
  125. package/src/components/ReportBuilder/sortable.tsx +4 -0
  126. package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
  127. package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
  128. package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
  129. package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -18
  130. package/src/components/ReportBuilder/spliceDocument.ts +139 -52
  131. package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
  132. package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
  133. package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
  134. package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
  135. package/src/components/ReportBuilder/useTileEditing.ts +16 -3
  136. package/src/components/ReportBuilder/useTileHeight.ts +149 -0
  137. package/src/components/ReportBuilder/useTileReorder.ts +143 -6
  138. package/src/components/ReportBuilder/useTileResize.ts +16 -1
  139. package/src/components/given/FilterButton.spec.tsx +27 -11
  140. package/src/components/given/FilterButton.tsx +19 -6
  141. package/src/theme/resolveTheme.spec.ts +72 -1
  142. package/src/theme/resolveTheme.ts +43 -0
  143. package/src/utils/blankQuoted.spec.ts +50 -0
  144. package/src/utils/blankQuoted.ts +32 -0
  145. package/src/utils/malloyText.ts +2 -1
  146. package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
  147. package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
  148. package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `text` with every double-quoted string, escapes included, replaced by `""`,
3
+ * so a tag line can be split into words without a quoted value reading as a
4
+ * tag name: `# label="bar_chart" line_chart` -> `# label="" line_chart`.
5
+ *
6
+ * A quote that never closes is left as it is, along with the rest of the text.
7
+ *
8
+ * A scanner rather than `/"(?:[^"\\]|\\.)*"/g`: annotation text comes from the
9
+ * model, and that regex retries from every quote of an unclosed string, so a
10
+ * line like `"\"\"\"…` took time quadratic in its length. This one reads each
11
+ * character once. It can stop at the first unclosed quote because every quote
12
+ * after it was read as an escaped character, so a scan from any of them sees
13
+ * the same characters and cannot close either.
14
+ */
15
+ export declare function blankQuoted(text: string): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.9.13",
4
+ "version": "0.9.15",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -52,6 +52,36 @@ export function tileGridColumn(
52
52
  return tile.break ? `1 / span ${span}` : `span ${span}`;
53
53
  }
54
54
 
55
+ /** One grid row, in px: the unit `rowspan=N` on a tile's entry counts in. */
56
+ export const TILE_ROW_PX = 80;
57
+
58
+ /**
59
+ * Fewest and most rows the builder offers for a tile's height; a hand-written
60
+ * file may go outside them. A query tile's floor is the shortest a chart still
61
+ * draws its plot in: at 2 rows a line chart had no plot area left under its
62
+ * heading and axes, and the renderer failed on it. Prose fits in one.
63
+ */
64
+ export const MIN_TILE_ROWS = 3;
65
+ export const MIN_TEXT_TILE_ROWS = 1;
66
+ export const MAX_TILE_ROWS = 16;
67
+
68
+ /**
69
+ * A tile `rows` grid rows tall, in px: the rows and the gaps between them, so
70
+ * a tile placed on explicit rows later lands on exactly this height.
71
+ */
72
+ export const tileHeightPx = (rows: number) =>
73
+ rows * TILE_ROW_PX + (rows - 1) * GRID_GAP_PX;
74
+
75
+ /** The rows a tile `px` tall is closest to, held to what the builder offers. */
76
+ export const rowsForHeight = (px: number, min: number = MIN_TILE_ROWS) =>
77
+ Math.min(
78
+ Math.max(
79
+ Math.round((px + GRID_GAP_PX) / (TILE_ROW_PX + GRID_GAP_PX)),
80
+ min,
81
+ ),
82
+ MAX_TILE_ROWS,
83
+ );
84
+
55
85
  /** Narrowest a tile that sets no `colspan` is drawn, by the reader and the builder alike. */
56
86
  export const MIN_TILE_PX = 240;
57
87
 
@@ -104,8 +134,51 @@ export function defaultTileSpan(
104
134
  export interface GridTile {
105
135
  colspan?: number;
106
136
  break?: boolean;
137
+ /** `rowspan=N` on its entry: the grid rows it is tall. Absent, the tile is as tall as its row. */
138
+ rowspan?: number;
139
+ /** `row=N` and `col=N` on its entry: where it sits, which makes the report placed. */
140
+ row?: number;
141
+ col?: number;
142
+ }
143
+
144
+ /**
145
+ * Rows a tile with no `rowspan` takes on a placed report, whose rows are
146
+ * fixed tracks: about the height it is drawn at unplaced. Kept equal to the
147
+ * server's `PLACED_DEFAULT_ROWSPAN`, whose overlap lint counts these rows.
148
+ */
149
+ export const PLACED_DEFAULT_ROWSPAN = { query: 5, text: 2 } as const;
150
+
151
+ /** Whether a report is placed: any tile says which row it sits in. */
152
+ export const isPlaced = (tiles: readonly GridTile[]) =>
153
+ tiles.some((tile) => tile.row !== undefined);
154
+
155
+ /**
156
+ * Where one tile sits on a placed report. A tile with no `row` or `col` is
157
+ * left to the grid's own auto-placement, which puts it in the first free cell
158
+ * after the placed ones; a `col` too far right for its span is pulled in so
159
+ * the tile stays on the grid, as a colspan wider than the grid is clamped.
160
+ */
161
+ export function placedArea(
162
+ tile: GridTile,
163
+ columns: number,
164
+ rows: number,
165
+ ): { gridRow: string; gridColumn: string } {
166
+ const span = Math.min(tile.colspan ?? 1, columns);
167
+ const col =
168
+ tile.col === undefined
169
+ ? undefined
170
+ : Math.min(tile.col, columns - span + 1);
171
+ return {
172
+ gridRow:
173
+ tile.row === undefined ? `span ${rows}` : `${tile.row} / span ${rows}`,
174
+ gridColumn: col === undefined ? `span ${span}` : `${col} / span ${span}`,
175
+ };
107
176
  }
108
177
 
178
+ /** A placed tile's place in reading order, top to bottom and then left to right: its order when the grid is one column. */
179
+ export const readingOrder = (tile: GridTile) =>
180
+ tile.row === undefined ? 1_000_000 : tile.row * 1000 + (tile.col ?? 0);
181
+
109
182
  /**
110
183
  * The composite dashboard's grid: the column track, and each tile's place on
111
184
  * it.
@@ -136,6 +209,10 @@ export function DashboardGrid<T extends GridTile>({
136
209
  renderTile,
137
210
  minTilePx,
138
211
  rowGapPx = GRID_GAP_PX,
212
+ defaultRowspan = (tile) =>
213
+ PLACED_DEFAULT_ROWSPAN[
214
+ (tile as { kind?: string }).kind === "text" ? "text" : "query"
215
+ ],
139
216
  }: {
140
217
  tiles: readonly T[];
141
218
  /** Track count — `# dashboard { columns=N }`, or {@link DEFAULT_COLUMNS}. */
@@ -155,7 +232,10 @@ export function DashboardGrid<T extends GridTile>({
155
232
  minTilePx?: number;
156
233
  /** The space between rows. */
157
234
  rowGapPx?: number;
235
+ /** Rows a tile with no `rowspan` takes on a placed report; by default its kind's {@link PLACED_DEFAULT_ROWSPAN}. */
236
+ defaultRowspan?: (tile: T) => number;
158
237
  }) {
238
+ const placed = isPlaced(tiles);
159
239
  const ref = useRef<HTMLDivElement>(null);
160
240
  const [width, setWidth] = useState(0);
161
241
  useEffect(() => {
@@ -185,6 +265,9 @@ export function DashboardGrid<T extends GridTile>({
185
265
  },
186
266
  columnGap: `${GRID_GAP_PX}px`,
187
267
  rowGap: `${rowGapPx}px`,
268
+ // Placed, the rows are fixed tracks a tile spans, so a rowspan is
269
+ // a span and empty cells stay empty rather than closing up.
270
+ ...(placed && { gridAutoRows: `${TILE_ROW_PX}px` }),
188
271
  }}
189
272
  >
190
273
  {tiles.map((tile, index) => (
@@ -205,16 +288,50 @@ export function DashboardGrid<T extends GridTile>({
205
288
  // width, the chart's box shrinks with it, and the renderer
206
289
  // redraws to fit — the same way it already did on growth.
207
290
  minWidth: 0,
208
- // Only above `md`: the narrow breakpoint is one column, where
209
- // a span would overflow the grid rather than widen anything.
210
- gridColumn: {
211
- md: tileGridColumn(
212
- tile.colspan === undefined && floor > 1
213
- ? { ...tile, colspan: floor }
214
- : tile,
215
- columns,
216
- ),
217
- },
291
+ // A set height is the tile's own, not its row's: it holds
292
+ // that height beside a taller neighbour rather than
293
+ // stretching to it, and the card inside fills it.
294
+ // A grid item's row is as tall as its content's minimum, so
295
+ // the row is held to the box: the result shrinks to fit it.
296
+ ...(!placed &&
297
+ tile.rowspan !== undefined && {
298
+ height: tileHeightPx(tile.rowspan),
299
+ alignSelf: "start",
300
+ }),
301
+ ...((placed || tile.rowspan !== undefined) && {
302
+ gridTemplateRows: "minmax(0, 1fr)",
303
+ }),
304
+ ...(placed
305
+ ? (() => {
306
+ const rows = tile.rowspan ?? defaultRowspan(tile);
307
+ const area = placedArea(
308
+ tile.colspan === undefined && floor > 1
309
+ ? { ...tile, colspan: floor }
310
+ : tile,
311
+ columns,
312
+ rows,
313
+ );
314
+ // One column below `md`: the tiles stack in reading
315
+ // order, each keeping its rows.
316
+ return {
317
+ gridRow: { xs: `span ${rows}`, md: area.gridRow },
318
+ gridColumn: { md: area.gridColumn },
319
+ order: { xs: readingOrder(tile), md: 0 },
320
+ };
321
+ })()
322
+ : {
323
+ // Only above `md`: the narrow breakpoint is one
324
+ // column, where a span would overflow the grid rather
325
+ // than widen anything.
326
+ gridColumn: {
327
+ md: tileGridColumn(
328
+ tile.colspan === undefined && floor > 1
329
+ ? { ...tile, colspan: floor }
330
+ : tile,
331
+ columns,
332
+ ),
333
+ },
334
+ }),
218
335
  }}
219
336
  >
220
337
  {renderTile(tile, index)}
@@ -16,6 +16,7 @@ import type { GivenValue, HostGivenValue } from "../../hooks/givenValue";
16
16
  import { humanizeSlug, type DrillBinding } from "../drill";
17
17
  import { givensToRequest, withHostGivens } from "../given/paramCodec";
18
18
  import { ResultPanel } from "../RenderedResult/ResultPanel";
19
+ import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
19
20
  import { failureCategory, useReportEvents } from "../Report/telemetry";
20
21
  import { dropValueUrlTags } from "./dropValueUrlTags";
21
22
  import { promoteMeasureRowToKpis } from "./promoteMeasureRow";
@@ -68,7 +69,10 @@ export interface DashboardTileProps {
68
69
  * server accepts: a surfaced given a query does not reference is ignored.
69
70
  */
70
71
  givenNames?: string[];
71
- height: number;
72
+ /** Cap on the result's height, past which it scrolls. Undefined is no cap: the tile grows to fit. */
73
+ height: number | undefined;
74
+ /** A further cap when the result is a table, past which it scrolls under its pinned header. */
75
+ tableMaxHeight?: number;
72
76
  maxResultSize?: number;
73
77
  /** Cell clicks and their affordance, for the dashboard's `# drill`. */
74
78
  drill?: DrillBinding;
@@ -141,6 +145,7 @@ export function DashboardTile({
141
145
  declaredTypes,
142
146
  givenNames,
143
147
  height,
148
+ tableMaxHeight,
144
149
  maxResultSize,
145
150
  drill,
146
151
  onExplore,
@@ -266,6 +271,11 @@ export function DashboardTile({
266
271
  state={state}
267
272
  context={tile ?? queryName ?? modelPath}
268
273
  maxHeight={height}
274
+ tableMaxHeight={tableMaxHeight}
275
+ // Uncapped in a linear report, a tile would first paint at the
276
+ // 2000px default and collapse once measured. A grid tile's cap
277
+ // is a sound first guess for every tile.
278
+ firstPaintHeight={TILE_MAX_HEIGHT}
269
279
  maxResultSize={maxResultSize}
270
280
  drill={drill}
271
281
  // A composite tile that is one row of measures draws as KPI cards,
@@ -1,8 +1,8 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import { Alert } from "@mui/material";
5
- import { useCallback, useMemo, useState } from "react";
4
+ import { Alert, Box } from "@mui/material";
5
+ import { useCallback, useMemo, useState, type ReactNode } from "react";
6
6
  import type { DashboardManifest } from "../../client";
7
7
  import type { HostGivenValue } from "../../hooks/givenValue";
8
8
  import { useDocumentControls } from "../../hooks/useDocumentControls";
@@ -23,8 +23,14 @@ import {
23
23
  } from "../given/required";
24
24
  import { Prose, type ProseLinkContext } from "../Prose";
25
25
  import type { NavigationClick } from "../click_helper";
26
- import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
27
- import { DashboardGrid, GRID_GAP_PX, MIN_TILE_PX } from "./DashboardGrid";
26
+ import {
27
+ DashboardGrid,
28
+ GRID_GAP_PX,
29
+ isPlaced,
30
+ MIN_TILE_PX,
31
+ PLACED_DEFAULT_ROWSPAN,
32
+ tileHeightPx,
33
+ } from "./DashboardGrid";
28
34
  import { DashboardTile } from "./DashboardTile";
29
35
  import { RowsDialog, stepsOf, type RowsRequest } from "./RowsDialog";
30
36
  import { useReportEvents } from "../Report/telemetry";
@@ -39,7 +45,7 @@ import {
39
45
  } from "../Report/ReportPage";
40
46
 
41
47
  /** Re-exported for hosts that import it from here; defined with the page parts. */
42
- export { STICKY_CONTROLS_Z } from "../Report/ReportPage";
48
+ export { STICKY_CONTROLS_Z, STICKY_TOP_VAR } from "../Report/ReportPage";
43
49
 
44
50
  export interface DashboardViewProps {
45
51
  /** The dashboard, or the tile layout a layout notebook carries. */
@@ -60,6 +66,7 @@ export interface DashboardViewProps {
60
66
  managed: readonly string[],
61
67
  ) => void;
62
68
  onNavigate?: (target: DrillNavigation, event?: MouseEvent) => void;
69
+ /** Height cap for a grid tile's result panel; a linear report's tiles take the layout's own. */
63
70
  height?: number;
64
71
  maxResultSize?: number;
65
72
  /**
@@ -96,6 +103,11 @@ export interface DashboardViewProps {
96
103
  * for a host with its own router. Omitted, links are plain anchors.
97
104
  */
98
105
  onLinkNavigate?: (to: string, event?: NavigationClick) => void;
106
+ /**
107
+ * The host's actions for this report (a download, a menu), drawn at the
108
+ * end of the title's line, where the builder's toolbar sits.
109
+ */
110
+ actions?: ReactNode;
99
111
  }
100
112
 
101
113
  /**
@@ -121,6 +133,7 @@ export function DashboardView({
121
133
  hiddenGivens,
122
134
  literalReads,
123
135
  onLinkNavigate,
136
+ actions,
124
137
  }: DashboardViewProps) {
125
138
  // Where a relative link in the report's prose resolves from, and how the
126
139
  // host navigates to it. Only a host with a router gets its links resolved:
@@ -251,7 +264,7 @@ export function DashboardView({
251
264
  );
252
265
 
253
266
  // The layout decides the arrangement only, as it does in the builder.
254
- const { columns, layout } = layoutRules(
267
+ const { columns, layout, tileMaxHeight, tableMaxHeight } = layoutRules(
255
268
  manifest.layout,
256
269
  manifest.dashboardColumns,
257
270
  );
@@ -270,7 +283,13 @@ export function DashboardView({
270
283
  return (
271
284
  <ReportPage
272
285
  layout={layout}
273
- header={<DashboardHeader manifest={manifest} links={links} />}
286
+ header={
287
+ <DashboardHeader
288
+ manifest={manifest}
289
+ links={links}
290
+ actions={actions}
291
+ />
292
+ }
274
293
  >
275
294
  <Alert severity="error">{manifest.error}</Alert>
276
295
  </ReportPage>
@@ -279,11 +298,18 @@ export function DashboardView({
279
298
 
280
299
  const modelPath = runModelPath ?? manifest.path;
281
300
  const tiles = manifest.tiles ?? [];
301
+ const placed = isPlaced(tiles);
282
302
 
283
303
  return (
284
304
  <ReportPage
285
305
  layout={layout}
286
- header={<DashboardHeader manifest={manifest} links={links} />}
306
+ header={
307
+ <DashboardHeader
308
+ manifest={manifest}
309
+ links={links}
310
+ actions={actions}
311
+ />
312
+ }
287
313
  // Only when there are controls: GivensPanel draws nothing without
288
314
  // them, and an empty bar would still cost the page a gap.
289
315
  controls={
@@ -322,7 +348,20 @@ export function DashboardView({
322
348
  tile.kind === "text" || tile.query === undefined ? (
323
349
  // Prose, never a card, in either layout: a text tile is
324
350
  // part of the page, not a result.
325
- <TextTile markdown={tile.markdown ?? ""} links={links} />
351
+ // A set height scrolls the prose rather than overflowing
352
+ // the tile below it.
353
+ <Box
354
+ sx={
355
+ tile.rowspan !== undefined || placed
356
+ ? { minHeight: 0, overflow: "auto" }
357
+ : undefined
358
+ }
359
+ >
360
+ <TextTile
361
+ markdown={tile.markdown ?? ""}
362
+ links={links}
363
+ />
364
+ </Box>
326
365
  ) : (
327
366
  <DashboardTile
328
367
  index={index}
@@ -338,7 +377,18 @@ export function DashboardView({
338
377
  hostGivens={tileHostGivens}
339
378
  declaredTypes={declaredTypes}
340
379
  givenNames={tile.givenNames}
341
- height={height ?? TILE_MAX_HEIGHT}
380
+ height={
381
+ // A set rowspan, or a placed report's fixed rows, is
382
+ // the tile's own height; otherwise the layout's cap.
383
+ tile.rowspan !== undefined || placed
384
+ ? tileHeightPx(
385
+ tile.rowspan ?? PLACED_DEFAULT_ROWSPAN.query,
386
+ )
387
+ : layout === "grid"
388
+ ? (height ?? tileMaxHeight)
389
+ : tileMaxHeight
390
+ }
391
+ tableMaxHeight={tableMaxHeight}
342
392
  maxResultSize={maxResultSize}
343
393
  drill={drillFor(tile.query)}
344
394
  ignoredFilters={tileIgnoredFilterLabels(
@@ -422,13 +472,16 @@ function TextTile({
422
472
  function DashboardHeader({
423
473
  manifest,
424
474
  links,
475
+ actions,
425
476
  }: {
426
477
  manifest: DashboardManifest;
427
478
  links: ProseLinkContext | undefined;
479
+ actions?: ReactNode;
428
480
  }) {
429
481
  return (
430
482
  <ReportHeader
431
483
  title={manifest.title ?? manifest.name}
484
+ actions={actions}
432
485
  description={
433
486
  manifest.description ? (
434
487
  <TextTileFrame>
@@ -89,6 +89,12 @@ export function TileCard({
89
89
  borderRadius: bare ? 0 : ui.radius.tile,
90
90
  background: bare ? "none" : theme.tile,
91
91
  overflow: "hidden",
92
+ // Its own stacking context, so nothing inside a tile is drawn
93
+ // over the page around it. A table's pinned header row is
94
+ // `z-index: 100` in the renderer's CSS; without this it painted
95
+ // over the sticky control row (z 4) as the tile scrolled under
96
+ // it. Popups (tooltips, menus) are portalled out and unaffected.
97
+ isolation: "isolate",
92
98
  // A column so a tile's result can take the room under its heading.
93
99
  display: "flex",
94
100
  flexDirection: "column",
@@ -4,6 +4,7 @@
4
4
  export {
5
5
  DashboardView,
6
6
  STICKY_CONTROLS_Z,
7
+ STICKY_TOP_VAR,
7
8
  type DashboardViewProps,
8
9
  } from "./DashboardView";
9
10
  export { TileFilterTag, tileIgnoredFilterLabels } from "./TileFilterTag";
@@ -165,6 +165,24 @@ describe("isMeasureRow", () => {
165
165
  expect(isMeasureRow(row)).toBe(false);
166
166
  });
167
167
 
168
+ // `calculation` in the drill expression is the group-by's own name, not
169
+ // the aggregate marker. Read as one, the row was promoted to KPI cards
170
+ // while the result panel treated the same column as a group-by.
171
+ it("refuses a row with a group-by named calculation", () => {
172
+ const row = serverMeasureRow();
173
+ row.schema.fields.unshift({
174
+ kind: "dimension",
175
+ name: "calculation",
176
+ type: { kind: "string_type", subtype: "text" },
177
+ annotations: [
178
+ {
179
+ value: '#(malloy) reference_id = "5e1f" drill_expression { kind = field_reference name = calculation }\n',
180
+ },
181
+ ],
182
+ });
183
+ expect(isMeasureRow(row)).toBe(false);
184
+ });
185
+
168
186
  it("accepts a single record cell as well as a one-element array", () => {
169
187
  const row = measureRow();
170
188
  expect(isMeasureRow(row)).toBe(true);
@@ -186,6 +204,7 @@ describe("carriesRenderTag", () => {
186
204
  carriesRenderTag(['# label="Sales" bar_chart { x=month }\n']),
187
205
  ).toBe(true);
188
206
  expect(carriesRenderTag(["# bar_chart.stack\n"])).toBe(true);
207
+ expect(carriesRenderTag(["# combo_chart { y2=revenue }\n"])).toBe(true);
189
208
  });
190
209
 
191
210
  it("ignores documentation lines and formatting-only tags", () => {
@@ -20,10 +20,16 @@
20
20
  *
21
21
  * Textual rather than through `@malloydata/malloy-tag`, which the SDK loads
22
22
  * lazily so a host may bundle without it; a synchronous check in the render
23
- * path cannot wait on that import. The cost is that a tag NAME inside a quoted
24
- * string reads as a tag, which only ever withholds the promotion.
23
+ * path cannot wait on that import. Quoted values are blanked before the line is
24
+ * split, so a tag name inside one (`# label="table"`) is not read as a tag.
25
25
  */
26
26
 
27
+ import { blankQuoted } from "../../utils/blankQuoted";
28
+ import {
29
+ isTotalColumn,
30
+ type ResultField,
31
+ } from "../RenderedResult/chartShapeProblem";
32
+
27
33
  /**
28
34
  * The renderer's top-level render tags: any one of these on the result means
29
35
  * the author chose a rendering, and this module has nothing to add.
@@ -32,6 +38,7 @@ const RENDER_TAGS = new Set([
32
38
  "bar_chart",
33
39
  "line_chart",
34
40
  "scatter_chart",
41
+ "combo_chart",
35
42
  "shape_map",
36
43
  "segment_map",
37
44
  "point_map",
@@ -50,51 +57,23 @@ const RENDER_TAGS = new Set([
50
57
 
51
58
  const BIG_VALUE_ANNOTATION = { value: "# big_value\n" };
52
59
 
53
- interface ResultField {
54
- kind?: string;
55
- annotations?: Array<{ value?: string }>;
56
- }
57
-
58
60
  interface ResultShape {
59
61
  schema?: { fields?: ResultField[] };
60
62
  data?: { kind?: string; array_value?: unknown[] };
61
63
  annotations?: Array<{ value?: string }>;
62
64
  }
63
65
 
64
- /**
65
- * Whether an output field is an aggregate.
66
- *
67
- * Measured against the server: every output field of a query comes back
68
- * `kind: "dimension"` — a result's columns are its dimensions, whatever they
69
- * were in the source — and what marks an aggregate is the `calculation` token
70
- * in the field's internal annotation:
71
- *
72
- * #(malloy) reference_id = "…" calculation drill_expression { … }
73
- *
74
- * `kind === "measure"` is kept for a renderer that says so directly, but no
75
- * real result has yet. Until this read the annotation the promotion never
76
- * fired on real output, and only its own fixture — written with `"measure"` —
77
- * ever passed it.
78
- */
79
- const MALLOY_CALCULATION = /^#\(malloy\)[\s\S]*\bcalculation\b/;
80
- function isMeasureField(field: ResultField | undefined): boolean {
81
- if (!field) return false;
82
- if (field.kind === "measure") return true;
83
- return (field.annotations ?? []).some(
84
- (annotation) =>
85
- typeof annotation?.value === "string" &&
86
- MALLOY_CALCULATION.test(annotation.value.trim()),
87
- );
88
- }
89
-
90
66
  /**
91
67
  * True when the result is one row consisting solely of measures: the shape a
92
- * `view: kpis is { aggregate: … }` tile produces.
68
+ * `view: kpis is { aggregate: … }` tile produces. A column is a measure by
69
+ * the result panel's own rule ({@link isTotalColumn}): every output column
70
+ * comes back `kind: "dimension"`, and an aggregate is the one whose
71
+ * `#(malloy)` note carries `calculation` as a property of its own.
93
72
  */
94
73
  export function isMeasureRow(result: ResultShape): boolean {
95
74
  const fields = result.schema?.fields;
96
75
  if (!Array.isArray(fields) || fields.length === 0) return false;
97
- if (!fields.every(isMeasureField)) return false;
76
+ if (!fields.every((field) => isTotalColumn(field))) return false;
98
77
  const data = result.data;
99
78
  if (!data) return false;
100
79
  if (data.kind === "record_cell") return true;
@@ -123,7 +102,7 @@ export function carriesRenderTag(annotations: readonly string[]): boolean {
123
102
  text.startsWith('#"')
124
103
  )
125
104
  continue;
126
- const body = text.slice(1).replace(/"(?:[^"\\]|\\.)*"/g, '""');
105
+ const body = blankQuoted(text.slice(1));
127
106
  for (const token of body.split(/[\s{}=.,[\]]+/)) {
128
107
  if (RENDER_TAGS.has(token)) return true;
129
108
  }
@@ -0,0 +1,72 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import {
6
+ GRID_GAP_PX,
7
+ MAX_TILE_ROWS,
8
+ MIN_TILE_ROWS,
9
+ TILE_ROW_PX,
10
+ placedArea,
11
+ readingOrder,
12
+ rowsForHeight,
13
+ tileHeightPx,
14
+ } from "./DashboardGrid";
15
+
16
+ describe("tile heights in grid rows", () => {
17
+ // A tile N rows tall spans the N-1 gaps between them too, so a tile placed
18
+ // on explicit grid rows later lands on exactly the height it has now.
19
+ it("counts the gaps between the rows a tile spans", () => {
20
+ expect(tileHeightPx(1)).toBe(TILE_ROW_PX);
21
+ expect(tileHeightPx(4)).toBe(4 * TILE_ROW_PX + 3 * GRID_GAP_PX);
22
+ });
23
+
24
+ it("reads a drawn height back as the rows it is closest to", () => {
25
+ for (let rows = MIN_TILE_ROWS; rows <= MAX_TILE_ROWS; rows++) {
26
+ expect(rowsForHeight(tileHeightPx(rows))).toBe(rows);
27
+ expect(rowsForHeight(tileHeightPx(rows) + 20)).toBe(rows);
28
+ }
29
+ });
30
+
31
+ it("holds a dragged height to the rows the builder offers", () => {
32
+ expect(rowsForHeight(0)).toBe(MIN_TILE_ROWS);
33
+ expect(rowsForHeight(100_000)).toBe(MAX_TILE_ROWS);
34
+ });
35
+ });
36
+
37
+ describe("placed tiles", () => {
38
+ it("sits a placed tile on its row and column, spanning its rows", () => {
39
+ expect(placedArea({ row: 3, col: 7, colspan: 6 }, 12, 4)).toEqual({
40
+ gridRow: "3 / span 4",
41
+ gridColumn: "7 / span 6",
42
+ });
43
+ });
44
+
45
+ it("pulls a tile hanging off the right edge back onto the grid", () => {
46
+ expect(
47
+ placedArea({ row: 1, col: 10, colspan: 6 }, 12, 5).gridColumn,
48
+ ).toBe("7 / span 6");
49
+ });
50
+
51
+ it("leaves a tile with no place for the grid to fill in", () => {
52
+ expect(placedArea({ colspan: 4 }, 12, 5)).toEqual({
53
+ gridRow: "span 5",
54
+ gridColumn: "span 4",
55
+ });
56
+ });
57
+
58
+ it("orders tiles for one column top to bottom, then left to right", () => {
59
+ const order = [
60
+ { row: 2, col: 7 },
61
+ { row: 2, col: 1 },
62
+ { row: 1, col: 9 },
63
+ {},
64
+ ].map(readingOrder);
65
+ expect([...order].sort((a, b) => a - b)).toEqual([
66
+ order[2],
67
+ order[1],
68
+ order[0],
69
+ order[3],
70
+ ]);
71
+ });
72
+ });