@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
@@ -61,7 +61,7 @@ export type ResultSizing = "content" | "container";
61
61
  * put a map that needs 365px into 700px of cell.
62
62
  *
63
63
  * Every name here is checked against the plugin's declared strategy at runtime
64
- * and agrees with it today (`bar:fill`, `line:fill`, `shape_map:fixed`); the
64
+ * and agrees with it today (`bar:fill`, `line:fill`, `combo:fill`, `shape_map:fixed`); the
65
65
  * strategy wins where both are available, so this list carries the roots no
66
66
  * plugin claims and anything a renderer stops declaring.
67
67
  */
@@ -70,6 +70,7 @@ const CONTAINER_SIZED_ROOTS: ReadonlySet<string> = new Set([
70
70
  "line",
71
71
  "chart",
72
72
  "scatter_chart",
73
+ "combo",
73
74
  ]);
74
75
 
75
76
  /**
@@ -241,6 +242,39 @@ export const TILE_MAX_HEIGHT = 400;
241
242
  */
242
243
  export const NOTEBOOK_CELL_MAX_HEIGHT = 700;
243
244
 
245
+ /**
246
+ * Cap for a table in a linear report, whose tiles otherwise grow to fit. A
247
+ * long table drawn at full length pushes everything after it a screen or more
248
+ * down, so it stops here and scrolls inside its tile under its own pinned
249
+ * header row. The same number as a notebook cell, the linear report's
250
+ * predecessor.
251
+ */
252
+ export const LINEAR_TABLE_MAX_HEIGHT = 700;
253
+
254
+ /**
255
+ * The cap a rendered root is held to: `maxHeight`, and for a table root also
256
+ * `tableMaxHeight`, whichever is lower. Undefined is no cap.
257
+ *
258
+ * Only a root that IS a table. A `# dashboard` root is not one: the renderer
259
+ * caps the tables inside it itself, at its own default or the author's
260
+ * `# dashboard { table.max_height=N | none }`. A KPI row, a list or a map keeps
261
+ * `maxHeight` alone, so a linear report still grows to show every card.
262
+ */
263
+ export function resultCap({
264
+ renderAs,
265
+ maxHeight,
266
+ tableMaxHeight,
267
+ }: {
268
+ renderAs: string | undefined;
269
+ maxHeight: number | undefined;
270
+ tableMaxHeight: number | undefined;
271
+ }): number | undefined {
272
+ if (renderAs !== "table" || tableMaxHeight === undefined) return maxHeight;
273
+ return maxHeight === undefined
274
+ ? tableMaxHeight
275
+ : Math.min(maxHeight, tableMaxHeight);
276
+ }
277
+
244
278
  /** Cap for a query result shown inside a model page's cell. */
245
279
  export const MODEL_CELL_MAX_HEIGHT = 600;
246
280
 
@@ -273,11 +307,20 @@ export const UNCAPPED_CONTAINER_HEIGHT = 400;
273
307
  */
274
308
  export const INITIAL_RENDER_HEIGHT = 2000;
275
309
 
276
- /** First-paint height, before anything is known about the result. */
277
- export function initialResultHeight(maxHeight: number | undefined): number {
278
- return maxHeight === undefined
279
- ? INITIAL_RENDER_HEIGHT
280
- : Math.min(maxHeight, INITIAL_RENDER_HEIGHT);
310
+ /**
311
+ * First-paint height, before anything is known about the result.
312
+ *
313
+ * `firstPaintHeight` replaces {@link INITIAL_RENDER_HEIGHT} for a caller that
314
+ * knows better. A report tile does: uncapped in a linear report, it would
315
+ * otherwise open at 2000px and collapse once measured, jumping the page under
316
+ * the reader. It is a first paint only; the measured height still wins.
317
+ */
318
+ export function initialResultHeight(
319
+ maxHeight: number | undefined,
320
+ firstPaintHeight?: number,
321
+ ): number {
322
+ const first = firstPaintHeight ?? INITIAL_RENDER_HEIGHT;
323
+ return maxHeight === undefined ? first : Math.min(maxHeight, first);
281
324
  }
282
325
 
283
326
  /**
@@ -290,26 +333,37 @@ export function initialResultHeight(maxHeight: number | undefined): number {
290
333
  * `fillHeight` is the room the surface has to give, for a cell that stretches
291
334
  * its result (a dashboard tile). It is a FLOOR on a measured content-sized
292
335
  * result and wins over the cap, so a short table reaches the bottom of its cell
293
- * and a long one still scrolls inside it. A container-sized result ignores it,
294
- * and so does one not measured yet, which would otherwise paint at a made-up
295
- * height.
336
+ * and a long one still scrolls inside it. A content-sized result not measured
337
+ * yet ignores it, since it would otherwise paint at a made-up height.
338
+ *
339
+ * A container-sized result (a chart) takes it only as a CEILING: drawn at its
340
+ * cap in a cell shorter than that, it ran past the cell's bottom and lost its
341
+ * x-axis labels to the card's clip, which is what a tile with a set `rowspan`
342
+ * is. It still never grows past its cap. No ratchet follows, because the chart
343
+ * sits out of flow in its cell, so the cell's height never depends on it.
296
344
  */
297
345
  export function resolveResultHeight({
298
346
  sizing,
299
347
  contentHeight,
300
348
  maxHeight,
301
349
  fillHeight,
350
+ firstPaintHeight,
302
351
  }: {
303
352
  sizing: ResultSizing | undefined;
304
353
  contentHeight: number | undefined;
305
354
  maxHeight: number | undefined;
306
355
  fillHeight?: number | undefined;
356
+ /** See {@link initialResultHeight}. */
357
+ firstPaintHeight?: number | undefined;
307
358
  }): number {
308
359
  if (sizing === "container") {
309
- return maxHeight ?? UNCAPPED_CONTAINER_HEIGHT;
360
+ const cap = maxHeight ?? UNCAPPED_CONTAINER_HEIGHT;
361
+ return fillHeight !== undefined && fillHeight > 0
362
+ ? Math.min(cap, fillHeight)
363
+ : cap;
310
364
  }
311
365
  if (contentHeight === undefined || contentHeight <= 0) {
312
- return initialResultHeight(maxHeight);
366
+ return initialResultHeight(maxHeight, firstPaintHeight);
313
367
  }
314
368
  const own =
315
369
  maxHeight === undefined
@@ -170,6 +170,25 @@ describe("the manifest fetch", () => {
170
170
  });
171
171
  });
172
172
 
173
+ describe("the host's actions", () => {
174
+ it("draws them on the title's line, not on a row of their own above it", async () => {
175
+ manifest = { ...TILES, layout: "linear" };
176
+ render(
177
+ <Report
178
+ resourceUri={URI}
179
+ path="sales/q3.malloy"
180
+ actions={<button type="button">Download</button>}
181
+ />,
182
+ { wrapper: serverWrapper },
183
+ );
184
+
185
+ const title = await screen.findByText("Third quarter");
186
+ const action = screen.getByRole("button", { name: "Download" });
187
+ // The title's own row holds both.
188
+ expect(title.parentElement?.contains(action)).toBe(true);
189
+ });
190
+ });
191
+
173
192
  describe("rendering by layout", () => {
174
193
  it("draws a grid report's tiles as cards, run against the report's path", async () => {
175
194
  manifest = { ...TILES, layout: "grid" };
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { Alert } from "@mui/material";
5
- import { useCallback, useEffect, useRef } from "react";
5
+ import { useCallback, useEffect, useRef, type ReactNode } from "react";
6
6
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
7
7
  import { now } from "../../utils/clock";
8
8
  import { parseResourceUri } from "../../utils/formatting";
@@ -84,6 +84,11 @@ export interface ReportProps {
84
84
  * while the builder loads over it.
85
85
  */
86
86
  manifestStaleTime?: number;
87
+ /**
88
+ * The host's actions for the report (a download, its own menu), drawn at
89
+ * the end of the title's line rather than on a row of their own above it.
90
+ */
91
+ actions?: ReactNode;
87
92
  }
88
93
 
89
94
  /**
@@ -106,6 +111,7 @@ export function Report({
106
111
  onEvent,
107
112
  chrome,
108
113
  manifestStaleTime,
114
+ actions,
109
115
  }: ReportProps) {
110
116
  const parsed = parseResourceUri(resourceUri);
111
117
  const { apiClients } = useServer();
@@ -233,6 +239,7 @@ export function Report({
233
239
  height={height}
234
240
  maxResultSize={maxResultSize}
235
241
  chrome={chrome}
242
+ {...(actions !== undefined ? { actions } : {})}
236
243
  />
237
244
  );
238
245
  return (
@@ -34,6 +34,14 @@ import { STUCK_TOP_PX, useStuck } from "../Dashboard/useStuck";
34
34
  */
35
35
  export const STICKY_CONTROLS_Z = 4;
36
36
 
37
+ /**
38
+ * The CSS custom property a host sets, on any ancestor of a report, to the
39
+ * height of what it pins above the report in the same scroller. The control
40
+ * row pins that far down instead of at the scroller's edge, so the two stack
41
+ * rather than overlap. Unset, it is 0.
42
+ */
43
+ export const STICKY_TOP_VAR = "--publisher-sticky-top";
44
+
37
45
  /** The space between the page's parts and between its tiles' rows, in theme units. */
38
46
  const PAGE_GAP = 2;
39
47
 
@@ -141,7 +149,11 @@ export function StickyControls({ children }: { children: ReactNode }) {
141
149
  data-stuck={stuck || undefined}
142
150
  sx={{
143
151
  position: "sticky",
144
- top: `${STUCK_TOP_PX}px`,
152
+ // Under whatever the host pins above the report (its own toolbar,
153
+ // say), which it says by setting `--publisher-sticky-top` on an
154
+ // ancestor. `useStuck` measures against this line, so the fill
155
+ // and edge still come on when the bar pins below the host's.
156
+ top: `calc(var(${STICKY_TOP_VAR}, 0px) + ${STUCK_TOP_PX}px)`,
145
157
  zIndex: STICKY_CONTROLS_Z,
146
158
  // Filled only while pinned, when the tiles pass under it. Unpinned
147
159
  // nothing does, and the fill, reaching up over the gap by the room
@@ -2,17 +2,29 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
- import { DEFAULT_COLUMNS } from "../Dashboard/DashboardGrid";
6
- import { layoutRules } from "./layoutRules";
5
+ import {
6
+ DEFAULT_COLUMNS,
7
+ GRID_GAP_PX,
8
+ MIN_TILE_PX,
9
+ defaultTileSpan,
10
+ } from "../Dashboard/DashboardGrid";
11
+ import {
12
+ LINEAR_TABLE_MAX_HEIGHT,
13
+ TILE_MAX_HEIGHT,
14
+ } from "../RenderedResult/resultSizing";
15
+ import { layoutRules, writtenSpan } from "./layoutRules";
7
16
 
8
17
  describe("layoutRules", () => {
9
- it("lays a linear report in one column of full-width tiles, added between others", () => {
18
+ it("lays a linear report in one column of full-width tiles that grow to fit, a table capped, added between others", () => {
10
19
  expect(layoutRules("linear", 12)).toEqual({
11
20
  layout: "linear",
12
21
  columns: 1,
13
22
  widths: false,
14
23
  insertBetween: true,
24
+ tileMaxHeight: undefined,
25
+ tableMaxHeight: LINEAR_TABLE_MAX_HEIGHT,
15
26
  });
27
+ expect(LINEAR_TABLE_MAX_HEIGHT).toBe(700);
16
28
  });
17
29
 
18
30
  it("lays a grid across its declared columns, with widths, added at the end", () => {
@@ -21,6 +33,8 @@ describe("layoutRules", () => {
21
33
  columns: 12,
22
34
  widths: true,
23
35
  insertBetween: false,
36
+ tileMaxHeight: TILE_MAX_HEIGHT,
37
+ tableMaxHeight: undefined,
24
38
  });
25
39
  });
26
40
 
@@ -33,3 +47,29 @@ describe("layoutRules", () => {
33
47
  expect(layoutRules("grid", 1).widths).toBe(false);
34
48
  });
35
49
  });
50
+
51
+ describe("writtenSpan", () => {
52
+ // The reader's own rule for a tile with no colspan is the oracle: absent is
53
+ // drawn at `defaultTileSpan`, so a written 1 repeats the default only where
54
+ // that is 1 at every width the grid is laid out in columns.
55
+ it("writes no width for one column of a one- or two-column grid", () => {
56
+ expect(writtenSpan(1, 2)).toBeUndefined();
57
+ expect(writtenSpan(1, 1)).toBeUndefined();
58
+ for (let px = 2 * MIN_TILE_PX + GRID_GAP_PX; px <= 2400; px += 50)
59
+ expect(defaultTileSpan(2, px, MIN_TILE_PX)).toBe(1);
60
+ });
61
+
62
+ it("keeps an explicit 1 where a tile with no width can draw wider", () => {
63
+ // Three columns in a 600px box: an unset tile is widened past one column.
64
+ expect(defaultTileSpan(3, 600, MIN_TILE_PX)).toBeGreaterThan(1);
65
+ expect(writtenSpan(1, 3)).toBe(1);
66
+ expect(writtenSpan(1, 12)).toBe(1);
67
+ // And in two columns while the builder draws an unset tile wider.
68
+ expect(writtenSpan(1, 2, 2)).toBe(1);
69
+ });
70
+
71
+ it("writes every other width as it is", () => {
72
+ expect(writtenSpan(2, 2)).toBe(2);
73
+ expect(writtenSpan(6, 12)).toBe(6);
74
+ });
75
+ });
@@ -3,6 +3,10 @@
3
3
 
4
4
  import type { ReportLayout } from "../Package/documentLocation";
5
5
  import { DEFAULT_COLUMNS } from "../Dashboard/DashboardGrid";
6
+ import {
7
+ LINEAR_TABLE_MAX_HEIGHT,
8
+ TILE_MAX_HEIGHT,
9
+ } from "../RenderedResult/resultSizing";
6
10
 
7
11
  /**
8
12
  * What a report's layout decides, and nothing else.
@@ -31,6 +35,68 @@ export interface LayoutRules {
31
35
  * inserting; a grid is arranged by dragging, so it adds at the end.
32
36
  */
33
37
  insertBetween: boolean;
38
+ /**
39
+ * The cap on a query tile's result, or undefined for none. A grid keeps its
40
+ * rows even, so a tile is one panel among several: it stops at
41
+ * {@link TILE_MAX_HEIGHT} and scrolls past it. A linear report is read top
42
+ * to bottom and nothing beside a tile sets its height, so a tile grows to
43
+ * fit what it holds, the way the single-query form already does: a row of
44
+ * KPI cards that wraps one per line in a narrow column shows every card. A
45
+ * table is the exception, held by {@link tableMaxHeight}. A
46
+ * chart, which has no height of its own, still draws at the uncapped
47
+ * default (see `resolveResultHeight`).
48
+ */
49
+ tileMaxHeight: number | undefined;
50
+ /**
51
+ * A further cap on a tile whose result is a table, or undefined for none
52
+ * beyond {@link tileMaxHeight}. A linear report's tiles grow to fit, but a
53
+ * long table at full length pushes the rest of the report a screen or more
54
+ * down, so a table stops at {@link LINEAR_TABLE_MAX_HEIGHT} and scrolls
55
+ * inside its tile under its pinned header row. A grid needs none: its tile
56
+ * cap is lower. See `resultCap`.
57
+ */
58
+ tableMaxHeight: number | undefined;
59
+ }
60
+
61
+ /**
62
+ * The `# colspan` to write for a tile `span` columns wide, or undefined to
63
+ * write none because the tile draws the same without one.
64
+ *
65
+ * A tile with no colspan is one column, except that the reader widens it until
66
+ * it is at least `MIN_TILE_PX` wide (`defaultTileSpan`). In a grid of one or two
67
+ * columns, one column is already that wide wherever the grid is laid out in
68
+ * columns (two columns of 240px need a box of 496px). So there a written
69
+ * `colspan=1` only repeats the default. In a wider grid an unset tile can be
70
+ * drawn wider than one column, and an explicit 1 is the author's choice to keep.
71
+ *
72
+ * `drawnWithout` is the span the caller draws an unset tile at now, when it
73
+ * measures one (the builder does): a width the author just set to 1 is still
74
+ * written while the tile would draw wider without it.
75
+ */
76
+ export function writtenSpan(
77
+ span: number,
78
+ columns: number,
79
+ drawnWithout = 1,
80
+ ): number | undefined {
81
+ return span === 1 && columns <= 2 && drawnWithout === 1 ? undefined : span;
82
+ }
83
+
84
+ /**
85
+ * The tile with its width as {@link writtenSpan} would write it: a `colspan`,
86
+ * or none. A copy, so a caller puts it back in its list rather than writing
87
+ * through an entry it looked up.
88
+ */
89
+ export function withSpan<T extends { colspan?: number }>(
90
+ tile: T,
91
+ span: number,
92
+ columns: number,
93
+ drawnWithout = 1,
94
+ ): T {
95
+ const next = { ...tile };
96
+ const colspan = writtenSpan(span, columns, drawnWithout);
97
+ if (colspan === undefined) delete next.colspan;
98
+ else next.colspan = colspan;
99
+ return next;
34
100
  }
35
101
 
36
102
  export function layoutRules(
@@ -44,6 +110,8 @@ export function layoutRules(
44
110
  columns: 1,
45
111
  widths: false,
46
112
  insertBetween: true,
113
+ tileMaxHeight: undefined,
114
+ tableMaxHeight: LINEAR_TABLE_MAX_HEIGHT,
47
115
  };
48
116
  const columns = declaredColumns ?? DEFAULT_COLUMNS;
49
117
  return {
@@ -51,5 +119,7 @@ export function layoutRules(
51
119
  columns,
52
120
  widths: columns > 1,
53
121
  insertBetween: false,
122
+ tileMaxHeight: TILE_MAX_HEIGHT,
123
+ tableMaxHeight: undefined,
54
124
  };
55
125
  }
@@ -0,0 +1,162 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * What a tile does with what it holds, against the page around it: a result
6
+ * taller than its cap scrolls instead of being cut off, and nothing inside a
7
+ * tile is drawn over the pinned control row.
8
+ */
9
+ import { act, render } from "@testing-library/react";
10
+ import { describe, expect, it } from "bun:test";
11
+ import type { CSSProperties } from "react";
12
+ import { TileCard } from "../Dashboard/TileCard";
13
+ import ResultContainer, {
14
+ RESULT_SCROLLER_CLASS,
15
+ } from "../RenderedResult/ResultContainer";
16
+ import { STICKY_TOP_VAR, StickyControls } from "./ReportPage";
17
+
18
+ describe("a tile's result taller than its cap", () => {
19
+ it("scrolls inside the tile rather than being clipped", () => {
20
+ const { container } = render(<ResultContainer result="{}" fill />);
21
+ const scroller = container.querySelector(`.${RESULT_SCROLLER_CLASS}`);
22
+ expect(scroller).not.toBeNull();
23
+ const style = getComputedStyle(scroller as Element);
24
+ expect(style.overflowY).toBe("auto");
25
+ // Sideways it still follows the tile's width, so a narrowed tile narrows.
26
+ expect(style.overflowX).toBe("hidden");
27
+ });
28
+
29
+ it("scrolls an unfilled panel too", () => {
30
+ const { container } = render(<ResultContainer result="{}" />);
31
+ const panel = container.firstElementChild as Element;
32
+ expect(getComputedStyle(panel).overflowY).toBe("auto");
33
+ });
34
+ });
35
+
36
+ describe("a tile against the pinned control row", () => {
37
+ it("is its own stacking context, so a table's pinned header cannot paint over the row", () => {
38
+ const { container } = render(
39
+ <TileCard>
40
+ <div />
41
+ </TileCard>,
42
+ );
43
+ const card = container.querySelector("[data-tile-kind]") as Element;
44
+ expect(getComputedStyle(card).isolation).toBe("isolate");
45
+ });
46
+
47
+ it("pins the row under what the host pins above the report", () => {
48
+ const { container } = render(
49
+ <div style={{ [STICKY_TOP_VAR]: "44px" } as CSSProperties}>
50
+ <StickyControls>
51
+ <span>controls</span>
52
+ </StickyControls>
53
+ </div>,
54
+ );
55
+ const row = container.querySelector(".publisher-filter-row") as Element;
56
+ expect(getComputedStyle(row).top).toBe("calc(44px + -1px)");
57
+ });
58
+
59
+ // Pinned under a host's bar, nothing clips the row, which is what pinning
60
+ // used to be detected by. It stayed transparent, and "+ Filter" was drawn
61
+ // over the title of the tile scrolling under it.
62
+ it("fills the row once it pins under what the host pins above the report", async () => {
63
+ const { container } = render(
64
+ <div
65
+ data-testid="scroller"
66
+ style={
67
+ {
68
+ overflowY: "auto",
69
+ height: "300px",
70
+ [STICKY_TOP_VAR]: "48px",
71
+ } as CSSProperties
72
+ }
73
+ >
74
+ <StickyControls>
75
+ <span>controls</span>
76
+ </StickyControls>
77
+ <div style={{ height: "2000px" }} />
78
+ </div>,
79
+ );
80
+ const scroller = container.firstElementChild as HTMLElement;
81
+ const row = container.querySelector(
82
+ ".publisher-filter-row",
83
+ ) as HTMLElement;
84
+ // happy-dom neither lays out nor resolves `calc()`: the browser's
85
+ // numbers for a row pinned at 47px in a scroller at the page's top.
86
+ const real = window.getComputedStyle.bind(window);
87
+ const restore = () => {
88
+ window.getComputedStyle = real;
89
+ };
90
+ window.getComputedStyle = ((el: Element) =>
91
+ el === row
92
+ ? ({ ...real(el), top: "47px" } as CSSStyleDeclaration)
93
+ : real(el)) as typeof window.getComputedStyle;
94
+ try {
95
+ const rect = (top: number) => ({ top, bottom: top + 48 }) as DOMRect;
96
+ scroller.getBoundingClientRect = () => rect(0);
97
+ row.getBoundingClientRect = () => rect(47);
98
+ scroller.scrollTop = 230;
99
+ await act(async () => {
100
+ scroller.dispatchEvent(new Event("scroll"));
101
+ await new Promise((r) => requestAnimationFrame(() => r(null)));
102
+ });
103
+ expect(row.getAttribute("data-stuck")).toBe("true");
104
+
105
+ // Back at the top the row sits in the flow, under the header.
106
+ row.getBoundingClientRect = () => rect(122);
107
+ scroller.scrollTop = 0;
108
+ await act(async () => {
109
+ scroller.dispatchEvent(new Event("scroll"));
110
+ await new Promise((r) => requestAnimationFrame(() => r(null)));
111
+ });
112
+ expect(row.getAttribute("data-stuck")).toBeNull();
113
+ } finally {
114
+ restore();
115
+ }
116
+ });
117
+
118
+ // A host page that scrolls the window but styles `html { overflow-y:
119
+ // scroll }` and `body { overflow-x: hidden }`: both compute as scrollers,
120
+ // and neither receives the page's scroll events.
121
+ it("fills the row once it pins on a page that scrolls the window", async () => {
122
+ const html = document.documentElement;
123
+ const body = document.body;
124
+ html.style.overflowY = "scroll";
125
+ body.style.overflowY = "auto";
126
+ const { container } = render(
127
+ <div style={{ [STICKY_TOP_VAR]: "48px" } as CSSProperties}>
128
+ <StickyControls>
129
+ <span>controls</span>
130
+ </StickyControls>
131
+ <div style={{ height: "2000px" }} />
132
+ </div>,
133
+ );
134
+ const row = container.querySelector(
135
+ ".publisher-filter-row",
136
+ ) as HTMLElement;
137
+ const real = window.getComputedStyle.bind(window);
138
+ const scrollY = Object.getOwnPropertyDescriptor(window, "scrollY");
139
+ window.getComputedStyle = ((el: Element) =>
140
+ el === row
141
+ ? ({ ...real(el), top: "47px" } as CSSStyleDeclaration)
142
+ : real(el)) as typeof window.getComputedStyle;
143
+ try {
144
+ row.getBoundingClientRect = () => ({ top: 47, bottom: 95 }) as DOMRect;
145
+ Object.defineProperty(window, "scrollY", {
146
+ value: 230,
147
+ configurable: true,
148
+ });
149
+ await act(async () => {
150
+ window.dispatchEvent(new Event("scroll"));
151
+ await new Promise((r) => requestAnimationFrame(() => r(null)));
152
+ });
153
+ expect(row.getAttribute("data-stuck")).toBe("true");
154
+ } finally {
155
+ window.getComputedStyle = real;
156
+ if (scrollY) Object.defineProperty(window, "scrollY", scrollY);
157
+ else delete (window as { scrollY?: number }).scrollY;
158
+ html.style.overflowY = "";
159
+ body.style.overflowY = "";
160
+ }
161
+ });
162
+ });
@@ -74,7 +74,7 @@ describe("AddTileDialog", () => {
74
74
  it("searches, and Enter adds what the search left picked", async () => {
75
75
  const onAdd = mock((_tile: unknown) => {});
76
76
  await mount(onAdd);
77
- const search = screen.getByRole("combobox", { name: "Search views" });
77
+ const search = screen.getByRole("combobox", { name: "Search the model" });
78
78
  fireEvent.change(search, { target: { value: "nothing like it" } });
79
79
  expect(screen.getByText(/No view matches/)).toBeDefined();
80
80
  fireEvent.change(search, { target: { value: "tot" } });
@@ -115,7 +115,7 @@ describe("AddTileDialog", () => {
115
115
  />,
116
116
  );
117
117
  // Opens on `totals`; the search hides it.
118
- const search = screen.getByRole("combobox", { name: "Search views" });
118
+ const search = screen.getByRole("combobox", { name: "Search the model" });
119
119
  fireEvent.change(search, { target: { value: "brand" } });
120
120
  fireEvent.keyDown(search, { key: "Enter" });
121
121
  expect(onAdd.mock.calls[0]?.[0]).toMatchObject({ view: "by_brand" });
@@ -25,6 +25,7 @@ import {
25
25
  type PickerGroup,
26
26
  } from "./ViewPicker";
27
27
  import type { ChartPick } from "./chartLine";
28
+ import { writtenSpan } from "../Report/layoutRules";
28
29
  import type { DashboardDocument } from "./document";
29
30
 
30
31
  /**
@@ -55,7 +56,8 @@ export interface NewTile {
55
56
  chart?: ChartPick | "none";
56
57
  /** The chart tags the view carries, so the chart line negates only those. */
57
58
  chartCarried?: string[];
58
- colspan: number;
59
+ /** Columns the tile spans; absent writes none, where that draws the same (`writtenSpan`). */
60
+ colspan?: number;
59
61
  }
60
62
 
61
63
  /** A view the picker shows a preview of, as the tile it would add. */
@@ -96,6 +98,7 @@ const DECLARED: Record<string, string> = {
96
98
  bar_chart: "a bar chart",
97
99
  line_chart: "a line chart",
98
100
  scatter_chart: "a scatter chart",
101
+ combo_chart: "a bar and line chart",
99
102
  shape_map: "a shape map",
100
103
  segment_map: "a segment map",
101
104
  big_value: "a big value",
@@ -213,6 +216,8 @@ export function AddTileDialog({
213
216
  if (!entry) return;
214
217
  if (![entry.source.name, entry.view.name].every(isBareName)) return;
215
218
  const same = entry.key === picked?.key;
219
+ // Half the grid; none written where that is what no width draws.
220
+ const colspan = writtenSpan(Math.ceil(columns / 2), columns);
216
221
  onAdd({
217
222
  base: entry.source.name,
218
223
  modelPath: entry.source.modelPath,
@@ -222,7 +227,7 @@ export function AddTileDialog({
222
227
  view: entry.view.name,
223
228
  ...(same && label.trim() ? { label: label.trim() } : {}),
224
229
  ...(same ? chartPart : {}),
225
- colspan: Math.ceil(columns / 2),
230
+ ...(colspan !== undefined ? { colspan } : {}),
226
231
  });
227
232
  };
228
233
  // Only the charts this view can take: a choice that cannot apply is not a
@@ -241,7 +246,7 @@ export function AddTileDialog({
241
246
  maxWidth="md"
242
247
  initialFocus={searchRef}
243
248
  title="Add a tile"
244
- description="Pick a view from this package. You can change its title and chart now or later."
249
+ description="Pick what the tile shows from the model. You can change its title and chart now or later."
245
250
  actions={
246
251
  <>
247
252
  <Button onClick={onAddText} sx={{ mr: "auto" }}>
@@ -296,7 +301,7 @@ export function AddTileDialog({
296
301
  sx={{ color: theme.tileTitle, p: 2 }}
297
302
  >
298
303
  {catalog
299
- ? "This package publishes no source with a view to put on a tile."
304
+ ? "This package's models have nothing to put on a tile yet."
300
305
  : "The package's sources are still loading."}
301
306
  </Typography>
302
307
  }
@@ -448,8 +453,8 @@ export function AddTileDialog({
448
453
  sx={{ color: "text.secondary", mt: 0.75 }}
449
454
  >
450
455
  {picked.view.chart
451
- ? `The view declares ${DECLARED[picked.view.chart] ?? "a chart"}.`
452
- : "The view declares no chart, so it shows as a table."}
456
+ ? `The model sets ${DECLARED[picked.view.chart] ?? "a chart"}.`
457
+ : "The model sets no chart, so it shows as a table."}
453
458
  </Typography>
454
459
  </Box>
455
460
  {unwritable && (
@@ -167,7 +167,7 @@ export function BuilderBar({ controls, onDone: onDoneProp }: BuilderBarProps) {
167
167
  <AddItem
168
168
  icon={<InsertChartOutlinedIcon />}
169
169
  title="Tile"
170
- detail="A view from the model"
170
+ detail="A chart or table from the model"
171
171
  onClick={pick(add.tile)}
172
172
  />
173
173
  )}