@malloy-publisher/sdk 0.9.14 → 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 (146) 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 +78 -77
  6. package/dist/builder/index.es.js +7449 -6570
  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 +10 -1
  29. package/dist/components/ReportBuilder/TileFrame.d.ts +33 -1
  30. package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
  31. package/dist/components/ReportBuilder/catalog.d.ts +23 -0
  32. package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
  33. package/dist/components/ReportBuilder/controls.d.ts +2 -2
  34. package/dist/components/ReportBuilder/document.d.ts +53 -5
  35. package/dist/components/ReportBuilder/imports.d.ts +7 -0
  36. package/dist/components/ReportBuilder/placement.d.ts +75 -0
  37. package/dist/components/ReportBuilder/preview.d.ts +59 -10
  38. package/dist/components/ReportBuilder/sortable.d.ts +3 -1
  39. package/dist/components/ReportBuilder/useTileHeight.d.ts +39 -0
  40. package/dist/components/ReportBuilder/useTileReorder.d.ts +27 -3
  41. package/dist/components/ReportBuilder/useTileResize.d.ts +8 -0
  42. package/dist/index.cjs.js +7 -7
  43. package/dist/index.es.js +3328 -3287
  44. package/dist/text/index.es.js +1 -1
  45. package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
  46. package/dist/theme/resolveTheme.d.ts +15 -0
  47. package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-BGk38oaW.es.js} +5097 -4805
  48. package/dist/useCompiledDocument-D9t5ry_t.cjs.js +142 -0
  49. package/dist/utils/blankQuoted.d.ts +15 -0
  50. package/package.json +1 -1
  51. package/src/components/Dashboard/DashboardGrid.tsx +127 -10
  52. package/src/components/Dashboard/DashboardTile.tsx +11 -1
  53. package/src/components/Dashboard/DashboardView.tsx +63 -10
  54. package/src/components/Dashboard/TileCard.tsx +6 -0
  55. package/src/components/Dashboard/index.ts +1 -0
  56. package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
  57. package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
  58. package/src/components/Dashboard/tileHeight.spec.ts +72 -0
  59. package/src/components/Dashboard/useStuck.ts +76 -28
  60. package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
  61. package/src/components/Package/NewDocumentDialog.tsx +10 -11
  62. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
  63. package/src/components/RenderedResult/RenderedResult.tsx +21 -6
  64. package/src/components/RenderedResult/ResultContainer.tsx +60 -7
  65. package/src/components/RenderedResult/ResultPanel.tsx +21 -1
  66. package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
  67. package/src/components/RenderedResult/chartPresentation.ts +166 -0
  68. package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
  69. package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
  70. package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
  71. package/src/components/RenderedResult/resultSizing.ts +65 -11
  72. package/src/components/Report/Report.spec.tsx +19 -0
  73. package/src/components/Report/Report.tsx +8 -1
  74. package/src/components/Report/ReportPage.tsx +13 -1
  75. package/src/components/Report/layoutRules.spec.ts +43 -3
  76. package/src/components/Report/layoutRules.ts +70 -0
  77. package/src/components/Report/tileOverflow.spec.tsx +162 -0
  78. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
  79. package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
  80. package/src/components/ReportBuilder/BuilderBar.tsx +1 -1
  81. package/src/components/ReportBuilder/BuilderDialogs.tsx +20 -0
  82. package/src/components/ReportBuilder/BuilderGrid.tsx +126 -20
  83. package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
  84. package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
  85. package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
  86. package/src/components/ReportBuilder/EditorSurface.tsx +94 -20
  87. package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
  88. package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
  89. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
  90. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
  91. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
  92. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +143 -2
  93. package/src/components/ReportBuilder/ReportBuilder.tsx +73 -19
  94. package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
  95. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
  96. package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
  97. package/src/components/ReportBuilder/ReportEditor.tsx +13 -0
  98. package/src/components/ReportBuilder/TileFrame.tsx +251 -6
  99. package/src/components/ReportBuilder/TileMenu.tsx +259 -20
  100. package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
  101. package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
  102. package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
  103. package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
  104. package/src/components/ReportBuilder/catalog.ts +90 -37
  105. package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
  106. package/src/components/ReportBuilder/chartLine.ts +80 -2
  107. package/src/components/ReportBuilder/controls.ts +4 -3
  108. package/src/components/ReportBuilder/document.ts +65 -7
  109. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  110. package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
  111. package/src/components/ReportBuilder/imports.ts +1 -1
  112. package/src/components/ReportBuilder/invariants.spec.ts +18 -10
  113. package/src/components/ReportBuilder/layout.ts +3 -0
  114. package/src/components/ReportBuilder/placement.spec.ts +193 -0
  115. package/src/components/ReportBuilder/placement.ts +250 -0
  116. package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
  117. package/src/components/ReportBuilder/preview.spec.ts +151 -11
  118. package/src/components/ReportBuilder/preview.ts +203 -40
  119. package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
  120. package/src/components/ReportBuilder/readDocument.spec.ts +46 -2
  121. package/src/components/ReportBuilder/readDocument.ts +194 -23
  122. package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
  123. package/src/components/ReportBuilder/sortable.tsx +4 -0
  124. package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
  125. package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
  126. package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
  127. package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -18
  128. package/src/components/ReportBuilder/spliceDocument.ts +139 -52
  129. package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
  130. package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
  131. package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
  132. package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
  133. package/src/components/ReportBuilder/useTileEditing.ts +16 -3
  134. package/src/components/ReportBuilder/useTileHeight.ts +149 -0
  135. package/src/components/ReportBuilder/useTileReorder.ts +143 -6
  136. package/src/components/ReportBuilder/useTileResize.ts +16 -1
  137. package/src/components/given/FilterButton.spec.tsx +27 -11
  138. package/src/components/given/FilterButton.tsx +19 -6
  139. package/src/theme/resolveTheme.spec.ts +72 -1
  140. package/src/theme/resolveTheme.ts +43 -0
  141. package/src/utils/blankQuoted.spec.ts +50 -0
  142. package/src/utils/blankQuoted.ts +32 -0
  143. package/src/utils/malloyText.ts +2 -1
  144. package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
  145. package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
  146. package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
@@ -18,7 +18,13 @@ import { tileIgnoredFilterLabels } from "../Dashboard/TileFilterTag";
18
18
  import { documentPreamble } from "../Dashboard/textSource";
19
19
  import { GivensPanel } from "../given";
20
20
  import { Loading } from "../Loading";
21
- import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
21
+ import {
22
+ PLACED_DEFAULT_ROWSPAN,
23
+ tileHeightPx,
24
+ } from "../Dashboard/DashboardGrid";
25
+ import { layoutRules } from "../Report/layoutRules";
26
+ import type { CompiledModel } from "../../client";
27
+ import { documentViewsOf } from "./catalog";
22
28
  import { useReportListing } from "../Package/useDocumentLocation";
23
29
  import {
24
30
  BUILDER_HANDOFF_STALE_MS,
@@ -36,6 +42,8 @@ import type { FixedFilter } from "./FilterStrip";
36
42
  import type { ReportLayout } from "../Package/documentLocation";
37
43
  import {
38
44
  isQueryTile,
45
+ isReadOnlyTile,
46
+ tileExpression,
39
47
  tileKey,
40
48
  type DashboardDocument,
41
49
  type DashboardTile as DocumentTile,
@@ -47,6 +55,7 @@ import {
47
55
  previewGivens,
48
56
  previewTileQuery,
49
57
  tileExpressionKey,
58
+ unsavedSources,
50
59
  type PreviewTileQuery,
51
60
  } from "./preview";
52
61
  import type { TextSourceOptions } from "./ReportEditor";
@@ -91,7 +100,16 @@ export function EditorSurface({
91
100
  savesTo,
92
101
  saveLabel,
93
102
  note,
103
+ fileModel,
94
104
  }: {
105
+ /**
106
+ * The file's own compiled model as the package serves it, for the shapes
107
+ * of the views it declares (which charts each tile can take). Absent for a
108
+ * document held as text, whose compile answer carries no per-view shapes,
109
+ * and whenever the opened text is not the one this model compiled (a kept
110
+ * draft, the host's record, a held-back version): the catalog answers then.
111
+ */
112
+ fileModel?: CompiledModel;
95
113
  textSource?: TextSourceOptions;
96
114
  environmentName: string;
97
115
  packageName: string;
@@ -244,17 +262,21 @@ export function EditorSurface({
244
262
  : undefined,
245
263
  [catalog, textSource, runModelPath],
246
264
  );
247
- const offered = useMemo(
248
- () =>
265
+ const documentViews = useMemo(
266
+ () => (fileModel ? documentViewsOf(fileModel) : undefined),
267
+ [fileModel],
268
+ );
269
+ const offered = useMemo(() => {
270
+ const scoped =
249
271
  catalog && runSources
250
272
  ? {
251
273
  sources: catalog.sources.filter((s) =>
252
274
  runSources.includes(s.name),
253
275
  ),
254
276
  }
255
- : catalog,
256
- [catalog, runSources],
257
- );
277
+ : catalog;
278
+ return scoped && documentViews ? { ...scoped, documentViews } : scoped;
279
+ }, [catalog, runSources, documentViews]);
258
280
 
259
281
  const [doc, setDoc] = useState(opened.document);
260
282
  useEffect(() => setDoc(opened.document), [opened.document]);
@@ -304,6 +326,21 @@ export function EditorSurface({
304
326
  ),
305
327
  [manifest],
306
328
  );
329
+ // The served tiles' labels, keyed the same way. A tile the builder shows
330
+ // read-only (its view in the model, or a named query) carries no label in
331
+ // the document, since its `# label` sits on a declaration the builder does
332
+ // not read; the reader titles it from the server's label, and so does this.
333
+ const servedLabels = useMemo(
334
+ () =>
335
+ new Map(
336
+ (manifest?.tiles ?? []).flatMap((tile) =>
337
+ tile.kind !== "text" && tile.query && tile.label
338
+ ? [[tileExpressionKey(tile.query), tile.label] as const]
339
+ : [],
340
+ ),
341
+ ),
342
+ [manifest],
343
+ );
307
344
  // Givens a tile reads through the model (a source's own `where:`), not a
308
345
  // binding in this file: shown, so the row matches the reader's, but the
309
346
  // model's to change.
@@ -312,8 +349,8 @@ export function EditorSurface({
312
349
  [doc, opened.document, servedReads],
313
350
  );
314
351
  const specs = useMemo(
315
- () => previewGivens(doc, modelSpecs, modelReads),
316
- [doc, modelSpecs, modelReads],
352
+ () => previewGivens(doc, modelSpecs, modelReads, servedReads),
353
+ [doc, modelSpecs, modelReads, servedReads],
317
354
  );
318
355
  // A filter in the row the builder can show and set but not change: say
319
356
  // where it is set instead. Not always the model: a report's own `source:`
@@ -414,6 +451,12 @@ export function EditorSurface({
414
451
  ),
415
452
  [opened.document],
416
453
  );
454
+ // Extensions this session added, which the model the tiles run on does not
455
+ // have until the file is saved and served: a tile on one runs on its base.
456
+ const unsaved = useMemo(
457
+ () => unsavedSources(doc, opened.document, modelPath, !!textSource),
458
+ [doc, opened.document, modelPath, textSource],
459
+ );
417
460
  const renderTile = useMemo(
418
461
  () =>
419
462
  function LiveTile(
@@ -421,13 +464,17 @@ export function EditorSurface({
421
464
  heading?: TileHeadingSlots,
422
465
  chrome: TileChrome = "card",
423
466
  ) {
467
+ const title =
468
+ (isReadOnlyTile(tile)
469
+ ? servedLabels.get(tileExpressionKey(tileExpression(tile)))
470
+ : undefined) ?? tileDisplayTitle(tile);
424
471
  // The bindings a tile runs with come from the manifest; running before it lands queries every tile once unbound and again bound.
425
472
  // Until then the tile's own card and heading stand, so nothing pops in when it runs.
426
473
  if (notCompiled)
427
474
  return (
428
475
  <TileCard chrome={chrome}>
429
476
  <TileHeading
430
- title={heading?.title ?? tileDisplayTitle(tile)}
477
+ title={heading?.title ?? title}
431
478
  subtitle={heading ? heading.subtitle : tile.subtitle}
432
479
  />
433
480
  <Typography
@@ -442,14 +489,14 @@ export function EditorSurface({
442
489
  return (
443
490
  <TileCard chrome={chrome}>
444
491
  <TileHeading
445
- title={heading?.title ?? tileDisplayTitle(tile)}
492
+ title={heading?.title ?? title}
446
493
  subtitle={heading ? heading.subtitle : tile.subtitle}
447
494
  />
448
495
  <Loading text="Running…" />
449
496
  </TileCard>
450
497
  );
451
498
  const servedReadsOf = servedReads.get(
452
- tileExpressionKey(`${tile.source} -> ${tile.name}`),
499
+ tileExpressionKey(tileExpression(tile)),
453
500
  );
454
501
  // A tile not yet edited runs the served view with the served
455
502
  // tile's givens: the request the reader sends, so it shares the
@@ -462,20 +509,30 @@ export function EditorSurface({
462
509
  sameTile(openedTiles.get(tileKey(tile)), tile);
463
510
  const query: PreviewTileQuery = untouched
464
511
  ? {
465
- expression: `${tile.source} -> ${tile.name}`,
512
+ expression: tileExpression(tile),
466
513
  givenNames: [...servedReadsOf],
467
514
  reads: [...servedReadsOf],
468
515
  }
469
- : previewTileQuery(doc, tile, runnable, applied, servedReadsOf);
516
+ : previewTileQuery(
517
+ doc,
518
+ tile,
519
+ runnable,
520
+ applied,
521
+ servedReadsOf,
522
+ unsaved,
523
+ );
524
+ const rules = layoutRules(doc.layout, doc.columns);
470
525
  return (
471
526
  <DashboardTile
472
527
  environmentName={environmentName}
473
528
  packageName={packageName}
474
529
  versionId={queryVersionId}
475
- modelPath={runModelPath}
476
- {...(preamble !== undefined ? { preamble } : {})}
530
+ modelPath={query.modelPath ?? runModelPath}
531
+ {...(preamble !== undefined && query.modelPath === undefined
532
+ ? { preamble }
533
+ : {})}
477
534
  {...(restrictedTiles.has(
478
- tileExpressionKey(`${tile.source} -> ${tile.name}`),
535
+ tileExpressionKey(tileExpression(tile)),
479
536
  )
480
537
  ? { restricted: true }
481
538
  : {})}
@@ -483,7 +540,7 @@ export function EditorSurface({
483
540
  {...(query.annotation
484
541
  ? { annotation: query.annotation }
485
542
  : {})}
486
- label={tileDisplayTitle(tile)}
543
+ label={title}
487
544
  chrome={chrome}
488
545
  subtitle={tile.subtitle}
489
546
  {...(heading ? { heading } : {})}
@@ -502,7 +559,16 @@ export function EditorSurface({
502
559
  : {};
503
560
  })()}
504
561
  ignoredFilters={tileIgnoredFilterLabels(query.reads, specs)}
505
- height={TILE_MAX_HEIGHT}
562
+ // Its own rows when it has them (a rowspan, or a placed
563
+ // report's fixed rows); otherwise the layout's cap.
564
+ height={
565
+ tile.rowspan !== undefined || tile.row !== undefined
566
+ ? tileHeightPx(
567
+ tile.rowspan ?? PLACED_DEFAULT_ROWSPAN.query,
568
+ )
569
+ : rules.tileMaxHeight
570
+ }
571
+ tableMaxHeight={rules.tableMaxHeight}
506
572
  />
507
573
  );
508
574
  },
@@ -514,11 +580,13 @@ export function EditorSurface({
514
580
  missing,
515
581
  runnable,
516
582
  servedReads,
583
+ servedLabels,
517
584
  environmentName,
518
585
  packageName,
519
586
  queryVersionId,
520
587
  runModelPath,
521
588
  preamble,
589
+ unsaved,
522
590
  restrictedTiles,
523
591
  applied,
524
592
  tileHostGivens,
@@ -659,8 +727,8 @@ function sameTile(
659
727
  }
660
728
 
661
729
  /**
662
- * A tile less what only frames its result: its title, subtitle, width, row
663
- * and card are drawn by the tile around the result, not sent with the query.
730
+ * A tile less what only frames its result: its title, subtitle, width, row,
731
+ * rowspan and card are drawn by the tile around the result, not sent with the query.
664
732
  * Retitling a tile re-ran it before, and its chart blinked as the same rows
665
733
  * were drawn again.
666
734
  */
@@ -670,6 +738,9 @@ function whatRuns(tile: DocumentTile): DocumentTile {
670
738
  subtitle: _subtitle,
671
739
  colspan: _colspan,
672
740
  break: _break,
741
+ rowspan: _rowspan,
742
+ row: _row,
743
+ col: _col,
673
744
  borderless: _borderless,
674
745
  ...runs
675
746
  } = tile as DocumentTile & {
@@ -677,6 +748,9 @@ function whatRuns(tile: DocumentTile): DocumentTile {
677
748
  subtitle?: unknown;
678
749
  colspan?: unknown;
679
750
  break?: unknown;
751
+ rowspan?: unknown;
752
+ row?: unknown;
753
+ col?: unknown;
680
754
  borderless?: unknown;
681
755
  };
682
756
  return runs as DocumentTile;
@@ -53,6 +53,7 @@ import {
53
53
  } from "./controls";
54
54
  import {
55
55
  isQueryTile,
56
+ tileKey,
56
57
  type DashboardDocument,
57
58
  type DashboardTile,
58
59
  type LocalGiven,
@@ -205,9 +206,10 @@ function FieldPicker({
205
206
  }
206
207
 
207
208
  /**
208
- * Why a tile cannot take a binding. A tile declared on its source and one
209
- * declared HERE in a body with no single block for a `where:` are different
210
- * situations, and saying "from the model" about the second one is untrue.
209
+ * Why a tile cannot take a binding. A tile declared on its source, one
210
+ * declared HERE in a body with no single block for a `where:`, and one naming a
211
+ * query are different situations, and saying "from the model" about the others
212
+ * is untrue.
211
213
  */
212
214
  const unbindable = (tile: DashboardTile | undefined) =>
213
215
  tile && isQueryTile(tile) && tile.declaration.kind === "opaque"
@@ -215,10 +217,17 @@ const unbindable = (tile: DashboardTile | undefined) =>
215
217
  label: "Not bindable",
216
218
  reason: `Its body is ${tile.declaration.why}, so a filter has no single place to go.`,
217
219
  }
218
- : {
219
- label: "From the model",
220
- reason: "Declared on its source, which this report does not write.",
221
- };
220
+ : tile && isQueryTile(tile) && tile.declaration.kind === "query"
221
+ ? {
222
+ label: "Not bindable",
223
+ reason:
224
+ "It names a query, whose filters live in that query's own definition.",
225
+ }
226
+ : {
227
+ label: "From the model",
228
+ reason:
229
+ "Declared on its source, which this report does not write.",
230
+ };
222
231
 
223
232
  export function FilterDialog({
224
233
  open,
@@ -709,7 +718,7 @@ export function FilterDialog({
709
718
  : undefined;
710
719
  return (
711
720
  <Stack
712
- key={`${tile.source}.${tile.name}`}
721
+ key={tileKey(tile)}
713
722
  direction="row"
714
723
  sx={{
715
724
  gap: 1,
@@ -78,7 +78,8 @@ export function FilterStrip({
78
78
  if (fixed !== undefined) {
79
79
  const { modelPath } = fixed;
80
80
  return {
81
- origin: "model",
81
+ // Declared here or in the model: a report's own source can fix one of its own.
82
+ origin: byName.get(name)?.origin ?? "model",
82
83
  fixed: fixed.reason,
83
84
  ...(modelPath !== undefined && onOpenModel
84
85
  ? { openModel: () => onOpenModel(modelPath) }
@@ -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
  });