@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
@@ -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";
@@ -78,6 +87,7 @@ export function EditorSurface({
78
87
  packageName,
79
88
  modelPath,
80
89
  versionId,
90
+ queryVersionId,
81
91
  opened,
82
92
  replaces,
83
93
  onSave,
@@ -90,14 +100,30 @@ export function EditorSurface({
90
100
  savesTo,
91
101
  saveLabel,
92
102
  note,
103
+ fileModel,
93
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;
94
113
  textSource?: TextSourceOptions;
95
114
  environmentName: string;
96
115
  packageName: string;
97
116
  modelPath: string;
98
117
  /** A display label; the editor keys on `modelPath`. */
99
118
  slug: string;
119
+ /** The document's version, from its `resourceUri`: what its control state is keyed by. */
100
120
  versionId?: string;
121
+ /**
122
+ * The package version every query runs at: tiles, the manifest, filter
123
+ * options, the listing and the catalog. `ReportEditor` passes its
124
+ * `queryVersionId`, or the document's own version when there is none.
125
+ */
126
+ queryVersionId?: string;
101
127
  opened: {
102
128
  source: string;
103
129
  document: DashboardDocument;
@@ -140,7 +166,7 @@ export function EditorSurface({
140
166
  environmentName,
141
167
  packageName,
142
168
  path: modelPath,
143
- versionId,
169
+ versionId: queryVersionId,
144
170
  },
145
171
  BUILDER_HANDOFF_STALE_MS,
146
172
  ),
@@ -198,7 +224,7 @@ export function EditorSurface({
198
224
  const { reports: reportList, settled: reportsSettled } = useReportListing(
199
225
  environmentName,
200
226
  packageName,
201
- versionId,
227
+ queryVersionId,
202
228
  );
203
229
  const otherDashboards = useMemo(
204
230
  () =>
@@ -216,7 +242,7 @@ export function EditorSurface({
216
242
  const catalog = useEditorCatalog({
217
243
  environmentName,
218
244
  packageName,
219
- ...(versionId !== undefined ? { versionId } : {}),
245
+ ...(queryVersionId !== undefined ? { versionId: queryVersionId } : {}),
220
246
  modelPath,
221
247
  reports: reportList,
222
248
  reportsSettled,
@@ -236,17 +262,21 @@ export function EditorSurface({
236
262
  : undefined,
237
263
  [catalog, textSource, runModelPath],
238
264
  );
239
- const offered = useMemo(
240
- () =>
265
+ const documentViews = useMemo(
266
+ () => (fileModel ? documentViewsOf(fileModel) : undefined),
267
+ [fileModel],
268
+ );
269
+ const offered = useMemo(() => {
270
+ const scoped =
241
271
  catalog && runSources
242
272
  ? {
243
273
  sources: catalog.sources.filter((s) =>
244
274
  runSources.includes(s.name),
245
275
  ),
246
276
  }
247
- : catalog,
248
- [catalog, runSources],
249
- );
277
+ : catalog;
278
+ return scoped && documentViews ? { ...scoped, documentViews } : scoped;
279
+ }, [catalog, runSources, documentViews]);
250
280
 
251
281
  const [doc, setDoc] = useState(opened.document);
252
282
  useEffect(() => setDoc(opened.document), [opened.document]);
@@ -296,6 +326,21 @@ export function EditorSurface({
296
326
  ),
297
327
  [manifest],
298
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
+ );
299
344
  // Givens a tile reads through the model (a source's own `where:`), not a
300
345
  // binding in this file: shown, so the row matches the reader's, but the
301
346
  // model's to change.
@@ -304,8 +349,8 @@ export function EditorSurface({
304
349
  [doc, opened.document, servedReads],
305
350
  );
306
351
  const specs = useMemo(
307
- () => previewGivens(doc, modelSpecs, modelReads),
308
- [doc, modelSpecs, modelReads],
352
+ () => previewGivens(doc, modelSpecs, modelReads, servedReads),
353
+ [doc, modelSpecs, modelReads, servedReads],
309
354
  );
310
355
  // A filter in the row the builder can show and set but not change: say
311
356
  // where it is set instead. Not always the model: a report's own `source:`
@@ -365,7 +410,7 @@ export function EditorSurface({
365
410
  environmentName,
366
411
  packageName,
367
412
  modelPath: textSource ? runModelPath : manifest?.path,
368
- versionId,
413
+ versionId: queryVersionId,
369
414
  documentName: modelPath,
370
415
  ...(preamble !== undefined ? { preamble } : {}),
371
416
  ...(hostGivens ? { hostGivens } : {}),
@@ -406,6 +451,12 @@ export function EditorSurface({
406
451
  ),
407
452
  [opened.document],
408
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
+ );
409
460
  const renderTile = useMemo(
410
461
  () =>
411
462
  function LiveTile(
@@ -413,13 +464,17 @@ export function EditorSurface({
413
464
  heading?: TileHeadingSlots,
414
465
  chrome: TileChrome = "card",
415
466
  ) {
467
+ const title =
468
+ (isReadOnlyTile(tile)
469
+ ? servedLabels.get(tileExpressionKey(tileExpression(tile)))
470
+ : undefined) ?? tileDisplayTitle(tile);
416
471
  // The bindings a tile runs with come from the manifest; running before it lands queries every tile once unbound and again bound.
417
472
  // Until then the tile's own card and heading stand, so nothing pops in when it runs.
418
473
  if (notCompiled)
419
474
  return (
420
475
  <TileCard chrome={chrome}>
421
476
  <TileHeading
422
- title={heading?.title ?? tileDisplayTitle(tile)}
477
+ title={heading?.title ?? title}
423
478
  subtitle={heading ? heading.subtitle : tile.subtitle}
424
479
  />
425
480
  <Typography
@@ -434,14 +489,14 @@ export function EditorSurface({
434
489
  return (
435
490
  <TileCard chrome={chrome}>
436
491
  <TileHeading
437
- title={heading?.title ?? tileDisplayTitle(tile)}
492
+ title={heading?.title ?? title}
438
493
  subtitle={heading ? heading.subtitle : tile.subtitle}
439
494
  />
440
495
  <Loading text="Running…" />
441
496
  </TileCard>
442
497
  );
443
498
  const servedReadsOf = servedReads.get(
444
- tileExpressionKey(`${tile.source} -> ${tile.name}`),
499
+ tileExpressionKey(tileExpression(tile)),
445
500
  );
446
501
  // A tile not yet edited runs the served view with the served
447
502
  // tile's givens: the request the reader sends, so it shares the
@@ -454,20 +509,30 @@ export function EditorSurface({
454
509
  sameTile(openedTiles.get(tileKey(tile)), tile);
455
510
  const query: PreviewTileQuery = untouched
456
511
  ? {
457
- expression: `${tile.source} -> ${tile.name}`,
512
+ expression: tileExpression(tile),
458
513
  givenNames: [...servedReadsOf],
459
514
  reads: [...servedReadsOf],
460
515
  }
461
- : 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);
462
525
  return (
463
526
  <DashboardTile
464
527
  environmentName={environmentName}
465
528
  packageName={packageName}
466
- versionId={versionId}
467
- modelPath={runModelPath}
468
- {...(preamble !== undefined ? { preamble } : {})}
529
+ versionId={queryVersionId}
530
+ modelPath={query.modelPath ?? runModelPath}
531
+ {...(preamble !== undefined && query.modelPath === undefined
532
+ ? { preamble }
533
+ : {})}
469
534
  {...(restrictedTiles.has(
470
- tileExpressionKey(`${tile.source} -> ${tile.name}`),
535
+ tileExpressionKey(tileExpression(tile)),
471
536
  )
472
537
  ? { restricted: true }
473
538
  : {})}
@@ -475,7 +540,7 @@ export function EditorSurface({
475
540
  {...(query.annotation
476
541
  ? { annotation: query.annotation }
477
542
  : {})}
478
- label={tileDisplayTitle(tile)}
543
+ label={title}
479
544
  chrome={chrome}
480
545
  subtitle={tile.subtitle}
481
546
  {...(heading ? { heading } : {})}
@@ -494,7 +559,16 @@ export function EditorSurface({
494
559
  : {};
495
560
  })()}
496
561
  ignoredFilters={tileIgnoredFilterLabels(query.reads, specs)}
497
- 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}
498
572
  />
499
573
  );
500
574
  },
@@ -506,11 +580,13 @@ export function EditorSurface({
506
580
  missing,
507
581
  runnable,
508
582
  servedReads,
583
+ servedLabels,
509
584
  environmentName,
510
585
  packageName,
511
- versionId,
586
+ queryVersionId,
512
587
  runModelPath,
513
588
  preamble,
589
+ unsaved,
514
590
  restrictedTiles,
515
591
  applied,
516
592
  tileHostGivens,
@@ -529,7 +605,7 @@ export function EditorSurface({
529
605
  <DashboardTile
530
606
  environmentName={environmentName}
531
607
  packageName={packageName}
532
- versionId={versionId}
608
+ versionId={queryVersionId}
533
609
  modelPath={view.modelPath}
534
610
  tile={`${view.base} -> ${view.view}`}
535
611
  {...(view.chart
@@ -553,7 +629,7 @@ export function EditorSurface({
553
629
  [
554
630
  environmentName,
555
631
  packageName,
556
- versionId,
632
+ queryVersionId,
557
633
  applied,
558
634
  tileHostGivens,
559
635
  declaredTypes,
@@ -651,8 +727,8 @@ function sameTile(
651
727
  }
652
728
 
653
729
  /**
654
- * A tile less what only frames its result: its title, subtitle, width, row
655
- * 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.
656
732
  * Retitling a tile re-ran it before, and its chart blinked as the same rows
657
733
  * were drawn again.
658
734
  */
@@ -662,6 +738,9 @@ function whatRuns(tile: DocumentTile): DocumentTile {
662
738
  subtitle: _subtitle,
663
739
  colspan: _colspan,
664
740
  break: _break,
741
+ rowspan: _rowspan,
742
+ row: _row,
743
+ col: _col,
665
744
  borderless: _borderless,
666
745
  ...runs
667
746
  } = tile as DocumentTile & {
@@ -669,6 +748,9 @@ function whatRuns(tile: DocumentTile): DocumentTile {
669
748
  subtitle?: unknown;
670
749
  colspan?: unknown;
671
750
  break?: unknown;
751
+ rowspan?: unknown;
752
+ row?: unknown;
753
+ col?: unknown;
672
754
  borderless?: unknown;
673
755
  };
674
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
  });