@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
@@ -9,6 +9,8 @@ import {
9
9
  within,
10
10
  } from "@testing-library/react";
11
11
  import { describe, expect, it } from "bun:test";
12
+ import { promoteMeasureRowToKpis } from "../Dashboard/promoteMeasureRow";
13
+ import { requestedChart } from "../RenderedResult/chartShapeProblem";
12
14
  import { chartLineText } from "./chartLine";
13
15
  import { ReportBuilder } from "./ReportBuilder";
14
16
  import { openDocument } from "./testing/fixtures";
@@ -87,7 +89,7 @@ describe("ReportBuilder: charts", () => {
87
89
  const names = enabledCharts();
88
90
  // The wrapper's view `by_category` carries a shape map, so it is enabled; the rest are listed disabled.
89
91
  expect(names).toEqual([
90
- "From the view",
92
+ "Default",
91
93
  "Table",
92
94
  "Line",
93
95
  "Bar",
@@ -112,7 +114,7 @@ describe("ReportBuilder: charts", () => {
112
114
  });
113
115
  fireEvent.click(screen.getByLabelText("Settings for by_cat"));
114
116
  pickChart("Bar");
115
- pickChart("From the view");
117
+ pickChart("Default");
116
118
  closeMenu();
117
119
  const save = screen.queryByRole("button", {
118
120
  name: "Save",
@@ -198,3 +200,192 @@ describe("ReportBuilder: charts", () => {
198
200
  ).toBe(true);
199
201
  });
200
202
  });
203
+
204
+ describe("ReportBuilder: charts on a view the report declares itself", () => {
205
+ // A tile of big numbers whose body is written in the report: in no model
206
+ // the catalog reads, so its shape comes from the report's own compile.
207
+ const INLINE = `## artifact { title="Overview" tiles=["a -> kpis"] }
208
+ import { scoped_orders } from "../data_app.malloy"
209
+
210
+ source: a is scoped_orders extend {
211
+ # label="Key figures"
212
+ view: kpis is { aggregate: revenue, order_count }
213
+ }`;
214
+ const withOwnViews = {
215
+ ...catalog,
216
+ documentViews: new Map([
217
+ [
218
+ "a",
219
+ new Map([
220
+ [
221
+ "kpis",
222
+ {
223
+ name: "kpis",
224
+ aggregateOnly: true,
225
+ shape: { groupBys: 0, totals: 2 },
226
+ },
227
+ ],
228
+ ]),
229
+ ],
230
+ ]),
231
+ };
232
+
233
+ it("offers big numbers and greys out every chart that needs an x-axis, before and after a switch", async () => {
234
+ const document = await openDocument(INLINE);
235
+ render(
236
+ <ReportBuilder
237
+ source={INLINE}
238
+ document={document}
239
+ catalog={withOwnViews}
240
+ />,
241
+ );
242
+ fireEvent.click(screen.getByLabelText("Settings for Key figures"));
243
+ expect(enabledCharts()).toEqual([
244
+ "Default",
245
+ "Table",
246
+ "Big value",
247
+ "Scatter",
248
+ ]);
249
+ const line = chartItems().find((o) => primary(o) === "Line");
250
+ expect(line?.textContent).toContain(
251
+ "This view has no field for the x-axis",
252
+ );
253
+ pickChart("Table");
254
+ pickChart("Default");
255
+ expect(enabledCharts()).toEqual([
256
+ "Default",
257
+ "Table",
258
+ "Big value",
259
+ "Scatter",
260
+ ]);
261
+ });
262
+
263
+ // The view carries no chart tag, but its one row of totals draws as big
264
+ // numbers anyway (the KPI promotion), so Table has to take that off.
265
+ it("draws a table when Table is picked on a tile of totals", async () => {
266
+ let written: string | undefined;
267
+ const document = await openDocument(INLINE);
268
+ render(
269
+ <ReportBuilder
270
+ source={INLINE}
271
+ document={document}
272
+ catalog={withOwnViews}
273
+ onSave={(source) => {
274
+ written = source;
275
+ }}
276
+ />,
277
+ );
278
+ fireEvent.click(screen.getByLabelText("Settings for Key figures"));
279
+ pickChart("Table");
280
+ closeMenu();
281
+ fireEvent.click(
282
+ screen.getByRole("button", { name: "Save", hidden: true }),
283
+ );
284
+ await waitFor(() => expect(written).toBeDefined());
285
+ expect(written).toContain(" # -big_value -viz\n");
286
+ const promoted = JSON.parse(
287
+ promoteMeasureRowToKpis(
288
+ JSON.stringify({
289
+ schema: {
290
+ fields: [
291
+ { kind: "measure", name: "revenue" },
292
+ { kind: "measure", name: "order_count" },
293
+ ],
294
+ },
295
+ data: { kind: "array_cell", array_value: [{}] },
296
+ annotations: [{ value: "# -big_value -viz\n" }],
297
+ }),
298
+ ),
299
+ ) as { annotations: Array<{ value: string }> };
300
+ expect(
301
+ requestedChart(promoted.annotations.map((a) => a.value)),
302
+ ).toBeUndefined();
303
+ });
304
+
305
+ it("says the shape is unknown, rather than what the view lacks, when no model reported it", async () => {
306
+ const document = await openDocument(INLINE);
307
+ render(
308
+ <ReportBuilder
309
+ source={INLINE}
310
+ document={document}
311
+ catalog={catalog}
312
+ />,
313
+ );
314
+ fireEvent.click(screen.getByLabelText("Settings for Key figures"));
315
+ const big = chartItems().find((o) => primary(o) === "Big value");
316
+ expect(big?.textContent).toContain(
317
+ "Not in the model's list, so its shape is unknown",
318
+ );
319
+ });
320
+ });
321
+
322
+ describe("ReportBuilder: a chart's color", () => {
323
+ const colorItem = () =>
324
+ screen.getByRole("menuitem", { name: /^Color/, hidden: true });
325
+ const swatches = () => {
326
+ fireEvent.click(colorItem());
327
+ const menu = screen.getByRole("menu", { name: "Color", hidden: true });
328
+ return within(menu).getAllByRole("menuitemradio", { hidden: true });
329
+ };
330
+
331
+ it("sets a bar chart's color from the theme's series and writes the one line", async () => {
332
+ let written: string | undefined;
333
+ await mount((source) => {
334
+ written = source;
335
+ });
336
+ fireEvent.click(screen.getByLabelText("Settings for by_cat"));
337
+ pickChart("Bar");
338
+ const choices = swatches();
339
+ // The theme's own colors first, then any other.
340
+ expect(primary(choices[0])).toBe("Theme");
341
+ const second = choices[2];
342
+ const color = primary(second) as string;
343
+ expect(color).toMatch(/^#[0-9a-f]{6}$/);
344
+ fireEvent.click(second);
345
+ closeMenu();
346
+ fireEvent.click(
347
+ screen.getByRole("button", { name: "Save", hidden: true }),
348
+ );
349
+ await waitFor(() => expect(written).toBeDefined());
350
+ expect(written).toContain(` # theme.palette.series=["${color}"]\n`);
351
+ // And reopening the file reads it back.
352
+ const reopened = await openDocument(written as string);
353
+ const tile = reopened.tiles.find((t) => t.name === "by_cat");
354
+ expect(tile && "color" in tile ? tile.color : undefined).toBe(color);
355
+ });
356
+
357
+ it("opens the platform's picker from the keyboard, where focus is on the item and not its input", async () => {
358
+ await mount();
359
+ fireEvent.click(screen.getByLabelText("Settings for by_cat"));
360
+ pickChart("Bar");
361
+ const other = swatches().at(-1) as HTMLElement;
362
+ expect(primary(other)).toBe("Other color…");
363
+ const input = within(other).getByLabelText("Other color");
364
+ let opened = 0;
365
+ input.addEventListener("click", () => opened++);
366
+ fireEvent.keyDown(other, { key: "Enter" });
367
+ fireEvent.keyDown(other, { key: " " });
368
+ expect(opened).toBe(2);
369
+ });
370
+
371
+ // The row's swatch follows its value ("Theme", "#7f9862"); spaced like the
372
+ // swatches in the Color menu it read as "Theme▢", touching the text.
373
+ it("spaces the Color row's swatch from its value", async () => {
374
+ await mount();
375
+ fireEvent.click(screen.getByLabelText("Settings for by_cat"));
376
+ pickChart("Bar");
377
+ const swatch = colorItem().querySelector("[data-swatch]") as HTMLElement;
378
+ expect(swatch.dataset.swatch).toBe("trailing");
379
+ const style = getComputedStyle(swatch);
380
+ expect(parseFloat(style.marginLeft)).toBeGreaterThan(0);
381
+ expect(parseFloat(style.marginRight) || 0).toBe(0);
382
+ });
383
+
384
+ it("offers no color on a table, which draws no series", async () => {
385
+ await mount();
386
+ fireEvent.click(screen.getByLabelText("Settings for by_cat"));
387
+ pickChart("Table");
388
+ expect(colorItem().getAttribute("aria-disabled")).toBe("true");
389
+ expect(screen.getByText(/has a color to set/)).toBeDefined();
390
+ });
391
+ });
@@ -205,9 +205,11 @@ describe("Duplicate, from a tile's menu", () => {
205
205
  screen.getByRole("button", { name: "Save", hidden: true }).click();
206
206
  await waitFor(() => expect(saved).toHaveBeenCalledTimes(1));
207
207
  const text = saved.mock.calls[0]?.[0] ?? "";
208
- expect(text).toContain('tiles=["a -> by_cat", "a -> by_category_tile"]');
208
+ expect(text).toContain(
209
+ 'tiles=["a -> by_cat", "a -> by_category_tile" { colspan=6 }]',
210
+ );
209
211
  expect(text).toMatch(
210
- /# colspan=6\n\s*# label="By category"\n\s*view: by_category_tile is by_category/,
212
+ /\n\n\s*# label="By category"\n\s*view: by_category_tile is by_category/,
211
213
  );
212
214
  });
213
215
 
@@ -138,7 +138,7 @@ describe("ReportBuilder: a notebook is one column", () => {
138
138
  fireEvent.click(button("Add tile"));
139
139
  expect(
140
140
  screen.getByText(
141
- "Pick a view from this package. You can change its title and chart now or later.",
141
+ "Pick what the tile shows from the model. You can change its title and chart now or later.",
142
142
  ),
143
143
  ).toBeDefined();
144
144
  cleanup();
@@ -147,7 +147,7 @@ describe("ReportBuilder: a notebook is one column", () => {
147
147
  fireEvent.click(button("Add tile"));
148
148
  expect(
149
149
  screen.getByText(
150
- "Pick a view from this package. You can change its title and chart now or later.",
150
+ "Pick what the tile shows from the model. You can change its title and chart now or later.",
151
151
  ),
152
152
  ).toBeDefined();
153
153
  });
@@ -536,10 +536,10 @@ describe("ReportBuilder: tiles added and removed", () => {
536
536
  );
537
537
  await waitFor(() => expect(written).toBeDefined());
538
538
  expect(written).toContain(
539
- 'tiles=["a -> by_cat", "a -> by_brand", "a -> sales_by_state_tile"]',
539
+ 'tiles=["a -> by_cat", "a -> by_brand", "a -> sales_by_state_tile" { colspan=6 }]',
540
540
  );
541
541
  expect(written).toContain(
542
- ' # colspan=6\n # label="Revenue by state"\n view: sales_by_state_tile is sales_by_state\n}',
542
+ '\n\n # label="Revenue by state"\n view: sales_by_state_tile is sales_by_state\n}',
543
543
  );
544
544
  });
545
545
 
@@ -619,6 +619,65 @@ describe("ReportBuilder: a tile's own settings", () => {
619
619
  });
620
620
  });
621
621
 
622
+ describe("ReportBuilder: a tile that names a query", () => {
623
+ const named = `## artifact { title="T" tiles=["by_carrier", "flights -> by_month"] }
624
+ import { flights } from '../flights.malloy'
625
+
626
+ query: by_carrier is flights -> { group_by: carrier; aggregate: flight_count }`;
627
+
628
+ it("opens the report and shows the tile, with nothing on it to edit", async () => {
629
+ const document = await openDocument(named);
630
+ render(<ReportBuilder source={named} document={document} />);
631
+ // Titled as the reader titles it, from the query's name.
632
+ expect(
633
+ within(screen.getByLabelText("Tile by_carrier")).getByText(
634
+ "By carrier",
635
+ ),
636
+ ).toBeDefined();
637
+ // No title field on the tile, and a menu that says why. Its width and
638
+ // height are the report's, on its entry, so both edges are there.
639
+ fireEvent.click(screen.getByText("By carrier"));
640
+ expect(screen.queryByLabelText("Tile title")).toBeNull();
641
+ expect(
642
+ screen.queryByRole("separator", { name: "Width of by_carrier" }),
643
+ ).not.toBeNull();
644
+ fireEvent.click(screen.getByLabelText("Settings for by_carrier"));
645
+ expect(
646
+ screen.getByText(
647
+ "It names a query, so its chart is set where that query is declared.",
648
+ ),
649
+ ).toBeDefined();
650
+ // The menu names what the tile runs: the query, with no empty source.
651
+ const menu = screen.getByRole("menu", {
652
+ name: "by_carrier",
653
+ hidden: true,
654
+ });
655
+ expect(within(menu).getByText("by_carrier")).toBeDefined();
656
+ expect(within(menu).queryByText(/→/)).toBeNull();
657
+ });
658
+
659
+ it("removes it from the list and saves the query untouched", async () => {
660
+ let written: string | undefined;
661
+ const document = await openDocument(named);
662
+ render(
663
+ <ReportBuilder
664
+ source={named}
665
+ document={document}
666
+ onSave={(next) => {
667
+ written = next;
668
+ }}
669
+ />,
670
+ );
671
+ fireEvent.click(screen.getByLabelText("Remove by_carrier"));
672
+ fireEvent.click(
673
+ screen.getByRole("button", { name: "Save", hidden: true }),
674
+ );
675
+ await waitFor(() => expect(written).toBeDefined());
676
+ expect(written).toContain('tiles=["flights -> by_month"]');
677
+ expect(written).toContain("query: by_carrier is flights");
678
+ });
679
+ });
680
+
622
681
  describe("ReportBuilder: widths and the page's own settings", () => {
623
682
  it("steps a tile's width from the keyboard on its edge, one undo step each", async () => {
624
683
  await mount();
@@ -638,6 +697,37 @@ describe("ReportBuilder: widths and the page's own settings", () => {
638
697
  expect(itemStyleOf("by_cat")).toContain("grid-column: span 5");
639
698
  });
640
699
 
700
+ it("steps a tile's height from the keyboard on its bottom edge, and fits it again on Delete", async () => {
701
+ await mount();
702
+ const edge = () =>
703
+ screen.getByRole("separator", { name: "Height of By category" });
704
+ expect(edge().getAttribute("aria-valuetext")).toBe("Auto height");
705
+ expect(itemStyleOf("by_cat")).not.toContain("height:");
706
+ fireEvent.keyDown(edge(), { key: "ArrowDown" });
707
+ // One row past the fewest a chart is offered (3).
708
+ expect(edge().getAttribute("aria-valuetext")).toBe("4 rows tall");
709
+ // Four 80px rows and the three gaps between them.
710
+ expect(itemStyleOf("by_cat")).toContain("height: 368px");
711
+ fireEvent.keyDown(edge(), { key: "End" });
712
+ expect(edge().getAttribute("aria-valuenow")).toBe("16");
713
+ fireEvent.keyDown(edge(), { key: "Delete" });
714
+ expect(edge().getAttribute("aria-valuetext")).toBe("Auto height");
715
+ fireEvent.click(button("Undo"));
716
+ expect(edge().getAttribute("aria-valuenow")).toBe("16");
717
+ });
718
+
719
+ it("lays out a tile the model owns: it has both edges", async () => {
720
+ const source = `## artifact { title="T" tiles=["orders -> by_brand"] } dashboard { columns=12 }\nimport { orders } from '../orders.malloy'`;
721
+ const document = await openDocument(source);
722
+ render(<ReportBuilder source={source} document={document} />);
723
+ expect(
724
+ screen.getByRole("separator", { name: "Width of by_brand" }),
725
+ ).toBeDefined();
726
+ expect(
727
+ screen.getByRole("separator", { name: "Height of by_brand" }),
728
+ ).toBeDefined();
729
+ });
730
+
641
731
  it("sets a tile's width by dragging its right edge, not from its menu", async () => {
642
732
  await mount();
643
733
  fireEvent.click(screen.getByLabelText("Settings for By category"));
@@ -741,6 +831,57 @@ source: a is scoped_orders extend {
741
831
  );
742
832
  });
743
833
 
834
+ const clickableItem = () =>
835
+ screen.getByRole("menuitem", {
836
+ name: /^Clickable cells/,
837
+ hidden: true,
838
+ });
839
+
840
+ it("says which clicks it sets up, and that none act while editing", async () => {
841
+ // The renderer reports clicks on table cells only, never on a bar, and
842
+ // the builder renders tiles without click handling, because a press there
843
+ // selects the tile. The window says both, so the setting does not look
844
+ // broken when a click in the builder does nothing.
845
+ const doc = await openDocument(WITH_DIMENSION);
846
+ render(<ReportBuilder source={WITH_DIMENSION} document={doc} />);
847
+ fireEvent.click(screen.getByLabelText("Settings for x"));
848
+ fireEvent.click(clickableItem());
849
+ const dialog = screen.getByRole("dialog", { hidden: true });
850
+ expect(dialog.textContent).toContain(
851
+ "A click on a table cell sets a filter to its value, on this report or on the one it opens.",
852
+ );
853
+ expect(dialog.textContent).toContain(
854
+ "Bars, lines and points on a chart do not respond to a click.",
855
+ );
856
+ expect(dialog.textContent).toContain(
857
+ "Clicks work in the report, not while you edit it.",
858
+ );
859
+ });
860
+
861
+ it("warns on a chart tile that its bars will not click", async () => {
862
+ const BAR = WITH_DIMENSION.replace(
863
+ " # colspan=6\n view: x",
864
+ " # colspan=6\n # bar_chart\n view: x",
865
+ );
866
+ expect(BAR).toContain("# bar_chart");
867
+ const doc = await openDocument(BAR);
868
+ render(<ReportBuilder source={BAR} document={doc} />);
869
+ fireEvent.click(screen.getByLabelText("Settings for x"));
870
+ expect(clickableItem().textContent).toContain(
871
+ "Its chart's bars, lines and points do not respond to a click; show it as a table to click its cells.",
872
+ );
873
+ // Still offered: the tag is on the dimension, which a table tile on the
874
+ // same source can use.
875
+ expect(clickableItem().getAttribute("aria-disabled")).not.toBe("true");
876
+ });
877
+
878
+ it("adds no chart warning to a table tile", async () => {
879
+ const doc = await openDocument(WITH_DIMENSION);
880
+ render(<ReportBuilder source={WITH_DIMENSION} document={doc} />);
881
+ fireEvent.click(screen.getByLabelText("Settings for x"));
882
+ expect(clickableItem().textContent).toBe("Clickable cells…");
883
+ });
884
+
744
885
  it("offers no Drill when the source declares no dimension here", async () => {
745
886
  // A window whose only content is why its Apply is off is a dead end;
746
887
  // the menu leaves the entry out instead.
@@ -893,3 +1034,102 @@ describe("ReportBuilder: saving", () => {
893
1034
  expect(button("Save")).toBeDefined();
894
1035
  });
895
1036
  });
1037
+
1038
+ describe("ReportBuilder: arranging a placed report", () => {
1039
+ const PLACED = `## artifact { title="T" tiles=["a -> x" { row=1 col=1 colspan=6 rowspan=3 }, "a -> y" { row=9 col=1 colspan=6 rowspan=3 }] } dashboard { columns=12 }
1040
+ import "../m.malloy"
1041
+
1042
+ source: a is one extend {
1043
+ view: x is vx
1044
+
1045
+ view: y is vy
1046
+ }`;
1047
+ const mountPlaced = async (source = PLACED) => {
1048
+ const document = await openDocument(source);
1049
+ render(<ReportBuilder source={source} document={document} />);
1050
+ };
1051
+
1052
+ it("packs the tiles upward from the Arrange menu, as one undo step", async () => {
1053
+ await mountPlaced();
1054
+ expect(itemStyleOf("y")).toContain("grid-row: 9/span 3");
1055
+ fireEvent.click(button("Arrange tiles"));
1056
+ fireEvent.click(
1057
+ screen.getByRole("menuitem", { name: /Pack tiles upward/ }),
1058
+ );
1059
+ expect(itemStyleOf("y")).toContain("grid-row: 4/span 3");
1060
+ fireEvent.click(button("Undo"));
1061
+ expect(itemStyleOf("y")).toContain("grid-row: 9/span 3");
1062
+ });
1063
+
1064
+ it("lets the tiles flow again, keeping their sizes", async () => {
1065
+ await mountPlaced();
1066
+ fireEvent.click(button("Arrange tiles"));
1067
+ fireEvent.click(screen.getByRole("menuitem", { name: /Let tiles flow/ }));
1068
+ expect(itemStyleOf("y")).not.toMatch(/grid-row: \d+\//);
1069
+ expect(itemStyleOf("y")).toContain("height: 272px");
1070
+ // A report that flows has nothing to arrange.
1071
+ expect(
1072
+ screen.queryByRole("button", { name: "Arrange tiles", hidden: true }),
1073
+ ).toBeNull();
1074
+ });
1075
+
1076
+ it("offers no packing when there is no gap to close", async () => {
1077
+ await mountPlaced(PLACED.replace("row=9", "row=4"));
1078
+ fireEvent.click(button("Arrange tiles"));
1079
+ expect(
1080
+ screen
1081
+ .getByRole("menuitem", { name: /Pack tiles upward/ })
1082
+ .getAttribute("aria-disabled"),
1083
+ ).toBe("true");
1084
+ });
1085
+
1086
+ it("moves the selected tile a cell at a time with Option and the arrows", async () => {
1087
+ await mountPlaced();
1088
+ fireEvent.click(tile("x"));
1089
+ fireEvent.keyDown(window, { key: "ArrowRight", altKey: true });
1090
+ expect(itemStyleOf("x")).toContain("grid-column: 2/span 6");
1091
+ fireEvent.keyDown(window, { key: "ArrowDown", altKey: true });
1092
+ expect(itemStyleOf("x")).toContain("grid-row: 2/span 3");
1093
+ // Held on the grid: six columns wide, it goes no further right than 7.
1094
+ for (let i = 0; i < 10; i++)
1095
+ fireEvent.keyDown(window, { key: "ArrowRight", altKey: true });
1096
+ expect(itemStyleOf("x")).toContain("grid-column: 7/span 6");
1097
+ });
1098
+
1099
+ it("keeps the selection on the same tile when packing re-sorts the tiles", async () => {
1100
+ // y sits at row 9 beside nothing; packing moves it to row 4, and on a
1101
+ // report where it reads first after the move the order changes.
1102
+ await mountPlaced(
1103
+ PLACED.replace(
1104
+ '"a -> x" { row=1 col=1 colspan=6 rowspan=3 }',
1105
+ '"a -> x" { row=5 col=7 colspan=6 rowspan=3 }',
1106
+ ),
1107
+ );
1108
+ fireEvent.click(tile("y"));
1109
+ expect(tile("y").getAttribute("aria-current")).toBe("true");
1110
+ fireEvent.click(button("Arrange tiles"));
1111
+ fireEvent.click(
1112
+ screen.getByRole("menuitem", { name: /Pack tiles upward/ }),
1113
+ );
1114
+ expect(tile("y").getAttribute("aria-current")).toBe("true");
1115
+ expect(tile("x").getAttribute("aria-current")).toBe("false");
1116
+ });
1117
+
1118
+ it("leaves Option and an arrow to the browser when no placed tile is selected", async () => {
1119
+ await mountPlaced();
1120
+ const event = new KeyboardEvent("keydown", {
1121
+ key: "ArrowLeft",
1122
+ altKey: true,
1123
+ cancelable: true,
1124
+ });
1125
+ window.dispatchEvent(event);
1126
+ expect(event.defaultPrevented).toBe(false);
1127
+ });
1128
+
1129
+ it("offers no Arrange menu on a report that flows", async () => {
1130
+ await mount();
1131
+ expect(
1132
+ screen.queryByRole("button", { name: "Arrange tiles", hidden: true }),
1133
+ ).toBeNull();
1134
+ });
1135
+ });