@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,9 +18,15 @@ import { useDraft } from "./useDraft";
18
18
  import { edgeColor } from "../controlTokens";
19
19
  import { usePublisherTheme } from "../../theme/ThemeContext";
20
20
  import type { CatalogView } from "./catalog";
21
- import { isQueryTile, type DashboardTile, type QueryTile } from "./document";
22
- import { chartChoices } from "./ChartPicker";
23
- import type { ChartState } from "./chartLine";
21
+ import {
22
+ isQueryTile,
23
+ isReadOnlyTile,
24
+ tileExpression,
25
+ type DashboardTile,
26
+ type QueryTile,
27
+ } from "./document";
28
+ import { chartChoices, type ViewStatus } from "./ChartPicker";
29
+ import { isSeriesColor, seriesColorFrom, type ChartState } from "./chartLine";
24
30
 
25
31
  /**
26
32
  * A tile's own settings, on the tile: a menu off its ⋯ button, so editing it
@@ -55,15 +61,28 @@ export interface TileMenuProps {
55
61
  /** Why the tile cannot be copied, when it cannot: Duplicate is then listed, greyed, with this under it. */
56
62
  duplicateBlocked?: string;
57
63
  /** The catalog's view the tile shows, when the catalog knows it: what decides which charts are offered. */
58
- view?: Pick<CatalogView, "chart" | "aggregateOnly">;
64
+ view?: Pick<CatalogView, "chart" | "aggregateOnly" | "shape">;
65
+ /** Why `view` is absent: still loading, or a view the catalog does not list. */
66
+ viewStatus?: ViewStatus;
59
67
  }
60
68
 
61
69
  const customChart = (lines: string[] | undefined) =>
62
70
  lines && lines.length === 1
63
71
  ? `This tile's chart line (${lines[0]}) is not one the builder models, so its chart cannot be changed here.`
64
72
  : `This tile has ${lines?.length ?? "several"} chart lines${lines ? ` (${lines.join(" and ")})` : ""}, so its chart cannot be changed here.`;
73
+ /** Charts whose marks the renderer gives no click to: its click payload is a table cell or a dashboard item, never a mark. */
74
+ const CLICKLESS_CHARTS = new Set<string>([
75
+ "bar_chart",
76
+ "line_chart",
77
+ "scatter_chart",
78
+ "combo_chart",
79
+ ]);
80
+ const CHART_DOES_NOT_CLICK =
81
+ "Its chart's bars, lines and points do not respond to a click; show it as a table to click its cells.";
65
82
  const INHERITED_CHART =
66
83
  "Declared on its source, so its chart is set in the model.";
84
+ const QUERY_CHART =
85
+ "It names a query, so its chart is set where that query is declared.";
67
86
 
68
87
  export function TileMenu({
69
88
  anchor,
@@ -74,10 +93,11 @@ export function TileMenu({
74
93
  onDuplicate,
75
94
  duplicateBlocked,
76
95
  view,
96
+ viewStatus,
77
97
  }: TileMenuProps) {
78
98
  const { theme } = usePublisherTheme();
79
99
  const ui = theme.ui;
80
- const { draft, apply, close } = useDraft(
100
+ const { draft, apply, patch, close } = useDraft(
81
101
  tile,
82
102
  anchor !== null,
83
103
  onCommit,
@@ -85,12 +105,11 @@ export function TileMenu({
85
105
  );
86
106
  // Which submenu is open, anchored to its item.
87
107
  const [sub, setSub] = useState<
88
- { kind: "chart"; anchor: HTMLElement } | undefined
108
+ { kind: "chart" | "color"; anchor: HTMLElement } | undefined
89
109
  >(undefined);
90
110
 
91
111
  const query = draft !== undefined && isQueryTile(draft) ? draft : undefined;
92
- const editable =
93
- query !== undefined && query.declaration.kind !== "inherited";
112
+ const editable = query !== undefined && !isReadOnlyTile(query);
94
113
  // The draft is a query tile whenever the controls that call this are shown.
95
114
  // Committed at once, so the tile redraws in the new chart while the menu is
96
115
  // still open rather than when it closes.
@@ -102,6 +121,7 @@ export function TileMenu({
102
121
  // moves with them, and "back to where it started" means where the menu
103
122
  // started.
104
123
  const openedChart = useRef<QueryTile["chart"]>(undefined);
124
+ const otherColor = useRef<HTMLInputElement>(null);
105
125
  const opened = anchor !== null;
106
126
  useEffect(() => {
107
127
  if (opened)
@@ -113,14 +133,16 @@ export function TileMenu({
113
133
  }, [opened]);
114
134
 
115
135
  const chartState: ChartState = query?.chart ?? "default";
116
- const choices = chartChoices(view, chartState);
136
+ const choices = chartChoices(view, chartState, viewStatus);
117
137
  const chartBlocked = !query
118
138
  ? undefined
119
- : !editable
120
- ? INHERITED_CHART
121
- : query.chart === "custom"
122
- ? customChart(query.chartLines)
123
- : undefined;
139
+ : query.declaration.kind === "query"
140
+ ? QUERY_CHART
141
+ : !editable
142
+ ? INHERITED_CHART
143
+ : query.chart === "custom"
144
+ ? customChart(query.chartLines)
145
+ : undefined;
124
146
  const pickChart = (next: ChartState) =>
125
147
  applyQuery((t) => {
126
148
  const was = openedChart.current;
@@ -142,8 +164,43 @@ export function TileMenu({
142
164
  ? undefined
143
165
  : "Its source declares no dimension a click could filter by.";
144
166
 
145
- const subOpen = (kind: "chart") => (event: { currentTarget: HTMLElement }) =>
146
- setSub({ kind, anchor: event.currentTarget });
167
+ // The renderer reports a click on a table cell only, so on a tile drawn as
168
+ // a chart the setting does nothing there. Said, not blocked: the tag is on
169
+ // the dimension, and a table tile over the same source does use it.
170
+ const drawn = chartState === "default" ? view?.chart : chartState;
171
+ const drillNote =
172
+ drawn !== undefined && CLICKLESS_CHARTS.has(drawn)
173
+ ? CHART_DOES_NOT_CLICK
174
+ : undefined;
175
+
176
+ const subOpen =
177
+ (kind: "chart" | "color") => (event: { currentTarget: HTMLElement }) =>
178
+ setSub({ kind, anchor: event.currentTarget });
179
+
180
+ // A tile's colour is the chart's first series colour. Offered from the
181
+ // theme's own series, so a pick stays on the palette the page uses, with
182
+ // any other colour a picker away. Not on a table or KPI tile, which draw
183
+ // no series; and not offered at all where the chart is locked, since the
184
+ // Chart item already says why.
185
+ const colorBlocked =
186
+ chartBlocked ??
187
+ (drawn === undefined || !COLORED_CHARTS.has(drawn)
188
+ ? "Only a bar, line, scatter or bar and line chart has a color to set."
189
+ : undefined);
190
+ // As the builder writes them, so a pick reads back; one it cannot write is
191
+ // left to the "any other colour" picker.
192
+ const swatches = Array.from(
193
+ new Set(
194
+ theme.series
195
+ .map(seriesColorFrom)
196
+ .filter((c): c is string => c !== undefined),
197
+ ),
198
+ ).slice(0, 8);
199
+ const pickColor = (next: string | undefined) =>
200
+ applyQuery((t) => {
201
+ if (next === undefined) delete t.color;
202
+ else t.color = next.toLowerCase();
203
+ });
147
204
  const label = (text: string, value?: string, reason?: string) => (
148
205
  <>
149
206
  <ListItemText
@@ -174,7 +231,7 @@ export function TileMenu({
174
231
  MenuListProps={{
175
232
  dense: true,
176
233
  disabledItemsFocusable: true,
177
- "aria-label": query ? `${query.source} ${query.name}` : "Tile",
234
+ "aria-label": query ? tileExpression(query) : "Tile",
178
235
  }}
179
236
  // Set like the builder's other menus: a rounded, bordered card.
180
237
  slotProps={{
@@ -222,6 +279,35 @@ export function TileMenu({
222
279
  />
223
280
  </MenuItem>
224
281
  )}
282
+ {/* Not where the chart itself is locked: the Chart item says why. */}
283
+ {query && chartBlocked === undefined && (
284
+ <MenuItem
285
+ aria-haspopup="menu"
286
+ aria-expanded={sub?.kind === "color"}
287
+ disabled={colorBlocked !== undefined}
288
+ onClick={subOpen("color")}
289
+ onKeyDown={(event) => {
290
+ if (
291
+ event.key === "ArrowRight" &&
292
+ colorBlocked === undefined
293
+ )
294
+ setSub({ kind: "color", anchor: event.currentTarget });
295
+ }}
296
+ >
297
+ {label(
298
+ "Color",
299
+ colorBlocked ? undefined : (query.color ?? "Theme"),
300
+ colorBlocked,
301
+ )}
302
+ {!colorBlocked && (
303
+ <Swatch color={query.color ?? theme.series[0]} trailing />
304
+ )}
305
+ <ChevronRightIcon
306
+ fontSize="small"
307
+ sx={{ ml: 1, color: "text.secondary" }}
308
+ />
309
+ </MenuItem>
310
+ )}
225
311
  {editable && (
226
312
  <MenuItem
227
313
  aria-haspopup="dialog"
@@ -231,7 +317,11 @@ export function TileMenu({
231
317
  onDrills?.();
232
318
  }}
233
319
  >
234
- {label("Clickable cells…", undefined, drillBlocked)}
320
+ {label(
321
+ "Clickable cells…",
322
+ undefined,
323
+ drillBlocked ?? drillNote,
324
+ )}
235
325
  </MenuItem>
236
326
  )}
237
327
  {query && onDuplicate && (
@@ -270,7 +360,8 @@ export function TileMenu({
270
360
  color: "text.secondary",
271
361
  }}
272
362
  >
273
- {query.source} → {query.name}
363
+ {/* As the tile's placeholder names it (`TileFrame`): a named query is its name alone. */}
364
+ {tileExpression(query).replace("->", "→")}
274
365
  </Box>
275
366
  )}
276
367
  </Menu>
@@ -310,7 +401,9 @@ export function TileMenu({
310
401
  >
311
402
  <ListItemText
312
403
  primary={choice.label}
313
- {...(choice.reason ? { secondary: choice.reason } : {})}
404
+ {...((choice.reason ?? choice.hint)
405
+ ? { secondary: choice.reason ?? choice.hint }
406
+ : {})}
314
407
  />
315
408
  {choice.value === chartState && (
316
409
  <ListItemIcon sx={{ minWidth: 0, ml: 2 }}>
@@ -323,6 +416,152 @@ export function TileMenu({
323
416
  </MenuItem>
324
417
  ))}
325
418
  </Menu>
419
+
420
+ <Menu
421
+ className={reportClasses.menu}
422
+ open={sub?.kind === "color"}
423
+ anchorEl={sub?.anchor ?? null}
424
+ onClose={() => setSub(undefined)}
425
+ anchorOrigin={{ vertical: "top", horizontal: "left" }}
426
+ transformOrigin={{ vertical: "top", horizontal: "right" }}
427
+ MenuListProps={{
428
+ dense: true,
429
+ "aria-label": "Color",
430
+ onKeyDown: (event) => {
431
+ if (event.key === "ArrowLeft") {
432
+ event.preventDefault();
433
+ setSub(undefined);
434
+ }
435
+ },
436
+ }}
437
+ >
438
+ <MenuItem
439
+ role="menuitemradio"
440
+ aria-checked={query?.color === undefined}
441
+ onClick={() => {
442
+ pickColor(undefined);
443
+ setSub(undefined);
444
+ }}
445
+ >
446
+ <Swatch color={theme.series[0]} />
447
+ <ListItemText
448
+ primary="Theme"
449
+ secondary="The page's own colors"
450
+ />
451
+ {query?.color === undefined && <Check color={theme.accent} />}
452
+ </MenuItem>
453
+ {swatches.map((color) => (
454
+ <MenuItem
455
+ key={color}
456
+ role="menuitemradio"
457
+ aria-checked={query?.color === color.toLowerCase()}
458
+ onClick={() => {
459
+ pickColor(color);
460
+ setSub(undefined);
461
+ }}
462
+ >
463
+ <Swatch color={color} />
464
+ <ListItemText primary={color.toLowerCase()} />
465
+ {query?.color === color.toLowerCase() && (
466
+ <Check color={theme.accent} />
467
+ )}
468
+ </MenuItem>
469
+ ))}
470
+ <Divider />
471
+ {/* Any other colour: the platform's own picker, committed as the
472
+ reader lets go of it. */}
473
+ <MenuItem
474
+ component="label"
475
+ aria-checked={
476
+ query?.color !== undefined &&
477
+ !swatches.some((c) => c.toLowerCase() === query.color)
478
+ }
479
+ role="menuitemradio"
480
+ // A label opens its input on a click only. Menu focus sits on
481
+ // this item, not the input, so Enter and Space open the picker
482
+ // here, as they choose any other item.
483
+ onKeyDown={(event) => {
484
+ if (event.key === "Enter" || event.key === " ") {
485
+ event.preventDefault();
486
+ otherColor.current?.click();
487
+ }
488
+ }}
489
+ >
490
+ <input
491
+ ref={otherColor}
492
+ type="color"
493
+ aria-label="Other color"
494
+ value={query?.color ?? toHex(theme.series[0])}
495
+ // Held in the draft while the picker is dragged, and
496
+ // committed once as the menu closes: one undo step, not
497
+ // one per shade passed on the way.
498
+ onChange={(event) => {
499
+ const next = event.target.value;
500
+ if (isSeriesColor(next))
501
+ patch((t) => {
502
+ if (isQueryTile(t)) t.color = next.toLowerCase();
503
+ });
504
+ }}
505
+ style={{
506
+ width: 18,
507
+ height: 18,
508
+ padding: 0,
509
+ border: "none",
510
+ background: "none",
511
+ marginRight: 12,
512
+ }}
513
+ />
514
+ <ListItemText primary="Other color…" />
515
+ </MenuItem>
516
+ </Menu>
326
517
  </>
327
518
  );
328
519
  }
520
+
521
+ /** Charts that draw a series, and so have a colour to set. */
522
+ const COLORED_CHARTS = new Set<string>([
523
+ "bar_chart",
524
+ "line_chart",
525
+ "scatter_chart",
526
+ "combo_chart",
527
+ ]);
528
+
529
+ /** A colour input takes `#rrggbb` only. */
530
+ const toHex = (color: string | undefined) =>
531
+ (color && seriesColorFrom(color)) ?? "#000000";
532
+
533
+ /**
534
+ * A colour square. Leading, it sits before a choice's name; trailing, it
535
+ * follows a row's value, spaced from it as the row's chevron is.
536
+ */
537
+ function Swatch({
538
+ color,
539
+ trailing = false,
540
+ }: {
541
+ color: string | undefined;
542
+ trailing?: boolean;
543
+ }) {
544
+ return (
545
+ <Box
546
+ aria-hidden
547
+ data-swatch={trailing ? "trailing" : "leading"}
548
+ sx={{
549
+ width: 14,
550
+ height: 14,
551
+ borderRadius: "3px",
552
+ bgcolor: color,
553
+ border: "1px solid rgba(0,0,0,0.15)",
554
+ ...(trailing ? { ml: 1 } : { mr: 1.5 }),
555
+ flex: "none",
556
+ }}
557
+ />
558
+ );
559
+ }
560
+
561
+ function Check({ color }: { color: string }) {
562
+ return (
563
+ <ListItemIcon sx={{ minWidth: 0, ml: 2 }}>
564
+ <CheckIcon fontSize="small" sx={{ color }} />
565
+ </ListItemIcon>
566
+ );
567
+ }
@@ -54,6 +54,7 @@ export function ChartGlyph({ chart }: { chart: string | undefined }) {
54
54
  const sx = { fontSize: 16 };
55
55
  switch (chart) {
56
56
  case "bar_chart":
57
+ case "combo_chart":
57
58
  return <BarChartIcon sx={sx} />;
58
59
  case "line_chart":
59
60
  case "sparkline":
@@ -171,7 +172,7 @@ export function ViewPicker({
171
172
  size="small"
172
173
  fullWidth
173
174
  inputRef={searchRef}
174
- placeholder="Search views"
175
+ placeholder="Search the model"
175
176
  value={query}
176
177
  disabled={disabled}
177
178
  onChange={(event) => onQuery(event.target.value)}
@@ -192,7 +193,7 @@ export function ViewPicker({
192
193
  }
193
194
  }}
194
195
  inputProps={{
195
- "aria-label": "Search views",
196
+ "aria-label": "Search the model",
196
197
  role: "combobox",
197
198
  "aria-controls": listId,
198
199
  "aria-expanded": true,
@@ -214,7 +215,7 @@ export function ViewPicker({
214
215
  <Box
215
216
  id={listId}
216
217
  role="listbox"
217
- aria-label="Views"
218
+ aria-label="From the model"
218
219
  sx={{ overflowY: "auto", flex: 1, minHeight: 0, pb: 1 }}
219
220
  >
220
221
  {groups.length === 0 && empty}
@@ -97,6 +97,40 @@ describe("duplicateTile", () => {
97
97
  });
98
98
  });
99
99
 
100
+ it("puts a placed tile's copy straight under it, pushing what was there down", () => {
101
+ const draft = {
102
+ ...withTiles([
103
+ {
104
+ name: "by_day_tile",
105
+ source: "orders_tiles",
106
+ declaration: { kind: "reference", from: "by_day" },
107
+ row: 1,
108
+ col: 1,
109
+ colspan: 6,
110
+ rowspan: 4,
111
+ },
112
+ {
113
+ name: "below",
114
+ source: "orders_tiles",
115
+ declaration: { kind: "reference", from: "by_week" },
116
+ row: 5,
117
+ col: 1,
118
+ colspan: 6,
119
+ rowspan: 3,
120
+ },
121
+ ]),
122
+ columns: 12,
123
+ };
124
+ expect(duplicateTile(draft, 0)).toBe(1);
125
+ expect(draft.tiles.map((t) => [t.name, t.row, t.col, t.rowspan])).toEqual(
126
+ [
127
+ ["by_day_tile", 1, 1, 4],
128
+ ["by_day_tile_2", 5, 1, 4],
129
+ ["below", 9, 1, 3],
130
+ ],
131
+ );
132
+ });
133
+
100
134
  it("copies a view the model declares onto the file's extension of its source", () => {
101
135
  const draft: DashboardDocument = {
102
136
  ...document(),
@@ -8,7 +8,9 @@ import {
8
8
  type DashboardSource,
9
9
  type QueryTile,
10
10
  } from "./document";
11
+ import { DEFAULT_COLUMNS } from "../Dashboard/DashboardGrid";
11
12
  import { withSource } from "./imports";
13
+ import { rowsOf, settle } from "./placement";
12
14
 
13
15
  /** Where a tile is added and what the document is: the parts of an add that are not the tile. */
14
16
  export interface AddTileContext {
@@ -43,7 +45,9 @@ export function addTileToDocument(
43
45
  name,
44
46
  source: extension.name,
45
47
  declaration: { kind: "reference", from: tile.view },
46
- ...(widths ? { colspan: tile.colspan } : {}),
48
+ ...(widths && tile.colspan !== undefined
49
+ ? { colspan: tile.colspan }
50
+ : {}),
47
51
  ...(tile.label ? { label: tile.label } : {}),
48
52
  ...(tile.chart ? { chart: tile.chart } : {}),
49
53
  ...(tile.chartCarried ? { chartCarried: tile.chartCarried } : {}),
@@ -102,6 +106,8 @@ export function duplicateBlocked(tile: QueryTile): string | undefined {
102
106
  return "Its query is written in this file, and the builder does not copy a query's body.";
103
107
  case "opaque":
104
108
  return `Its query is ${tile.declaration.why}, which the builder does not copy.`;
109
+ case "query":
110
+ return "It names a query, and a copy could not be told apart from it: the builder writes nothing about such a tile but its place.";
105
111
  default:
106
112
  return tile.chart === "custom"
107
113
  ? "Its chart line is one the builder does not write, so a copy would lose it."
@@ -156,6 +162,25 @@ export function duplicateTile(
156
162
  : {}),
157
163
  };
158
164
  }
165
+ // On a placed report the copy goes straight under the original, at its
166
+ // size, and whatever was there moves down; it never lands on top of it.
167
+ const placed = original.row !== undefined && original.col !== undefined;
168
+ if (placed) {
169
+ copy = {
170
+ ...copy,
171
+ row: (original.row ?? 1) + rowsOf(original),
172
+ col: original.col,
173
+ ...(original.rowspan !== undefined
174
+ ? { rowspan: original.rowspan }
175
+ : {}),
176
+ };
177
+ }
159
178
  draft.tiles.splice(index + 1, 0, copy);
179
+ if (placed)
180
+ draft.tiles = settle(
181
+ draft.tiles,
182
+ draft.columns ?? DEFAULT_COLUMNS,
183
+ index + 1,
184
+ );
160
185
  return index + 1;
161
186
  }
@@ -3,7 +3,8 @@
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
5
  import type { CompiledModel } from "../../client";
6
- import { buildCatalog } from "./catalog";
6
+ import { chartShapeGap } from "../RenderedResult/chartShapeProblem";
7
+ import { buildCatalog, documentViewsOf } from "./catalog";
7
8
 
8
9
  /**
9
10
  * `sourceInfos` as the compiler wrote it (modelDefToModelInfo on a DuckDB source with a measure `n`
@@ -48,3 +49,138 @@ describe("buildCatalog, aggregate-only views, from real compiler output", () =>
48
49
  );
49
50
  });
50
51
  });
52
+
53
+ describe("documentViewsOf, the views a report file declares itself", () => {
54
+ it("gives each view its shape, from the file's own compiled model", () => {
55
+ const views = documentViewsOf(MODEL).get("s");
56
+ expect(views?.get("kpi")).toEqual({
57
+ name: "kpi",
58
+ aggregateOnly: true,
59
+ shape: { groupBys: 0, totals: 1 },
60
+ });
61
+ expect(views?.get("by_calc_n")?.shape).toEqual({
62
+ groupBys: 1,
63
+ totals: 1,
64
+ });
65
+ // A nest is neither an x-axis field nor a total.
66
+ expect(views?.get("nst")?.shape).toEqual({ groupBys: 1, totals: 0 });
67
+ });
68
+
69
+ // A pick negates the chart its view declares. Without it, a bar picked on
70
+ // a `# line_chart` view wrote `# -viz bar_chart` and the renderer was asked
71
+ // for both charts at once, and drew an error.
72
+ it("carries the chart and doc line each view declares, as the catalog does", () => {
73
+ const withNotes = {
74
+ ...MODEL,
75
+ sources: [
76
+ {
77
+ name: "s",
78
+ views: [
79
+ {
80
+ name: "by_calc_n",
81
+ annotations: [
82
+ "#(doc) Orders by month\n",
83
+ "# line_chart\n",
84
+ ],
85
+ },
86
+ { name: "kpi" },
87
+ ],
88
+ },
89
+ ],
90
+ } as unknown as CompiledModel;
91
+ const views = documentViewsOf(withNotes).get("s");
92
+ expect(views?.get("by_calc_n")).toEqual({
93
+ name: "by_calc_n",
94
+ description: "Orders by month",
95
+ chart: "line_chart",
96
+ shape: { groupBys: 1, totals: 1 },
97
+ });
98
+ expect(views?.get("kpi")?.chart).toBeUndefined();
99
+ expect(views?.get("by_calc_n")).toEqual(
100
+ buildCatalog([withNotes]).sources[0].views.find(
101
+ (v) => v.name === "by_calc_n",
102
+ ),
103
+ );
104
+ });
105
+ });
106
+
107
+ describe("buildCatalog, combo-chart views", () => {
108
+ // Columns as the compiler annotates them: an aggregate carries
109
+ // `calculation` in its `#(malloy)` note, a group-by does not.
110
+ const column = (name: string, aggregate: boolean, array = false) => ({
111
+ kind: "dimension",
112
+ name,
113
+ type: array
114
+ ? {
115
+ kind: "array_type",
116
+ element_type: { kind: "record_type", fields: [] },
117
+ }
118
+ : { kind: "number_type" },
119
+ annotations: [
120
+ {
121
+ value: `#(malloy) ${aggregate ? "calculation " : ""}drill_expression { kind = field_reference name = ${name} }\n`,
122
+ },
123
+ ],
124
+ });
125
+ const view = (name: string, columns: unknown[]) => ({
126
+ kind: "view",
127
+ name,
128
+ schema: { fields: columns },
129
+ });
130
+ const VIEWS = [
131
+ view("by_month", [
132
+ column("month", false),
133
+ column("orders", true),
134
+ column("revenue", true),
135
+ ]),
136
+ view("one_total", [column("month", false), column("orders", true)]),
137
+ view("three_totals", [
138
+ column("month", false),
139
+ column("a", true),
140
+ column("b", true),
141
+ column("c", true),
142
+ ]),
143
+ view("totals_only", [column("a", true), column("b", true)]),
144
+ view("nested_only", [
145
+ column("rows", false, true),
146
+ column("a", true),
147
+ column("b", true),
148
+ ]),
149
+ ];
150
+ const COMBO = {
151
+ ...MODEL,
152
+ sources: [{ name: "s", views: VIEWS.map((v) => ({ name: v.name })) }],
153
+ sourceInfos: [JSON.stringify({ name: "s", schema: { fields: VIEWS } })],
154
+ } as unknown as CompiledModel;
155
+
156
+ it("counts each view's group-bys and totals, a nest being neither", () => {
157
+ const [source] = buildCatalog([COMBO]).sources;
158
+ expect(
159
+ Object.fromEntries(source.views.map((v) => [v.name, v.shape])),
160
+ ).toEqual({
161
+ by_month: { groupBys: 1, totals: 2 },
162
+ one_total: { groupBys: 1, totals: 1 },
163
+ three_totals: { groupBys: 1, totals: 3 },
164
+ totals_only: { groupBys: 0, totals: 2 },
165
+ nested_only: { groupBys: 0, totals: 2 },
166
+ });
167
+ });
168
+
169
+ it("gives only a view with a group by and exactly two totals the shape a bare # combo_chart draws", () => {
170
+ const [source] = buildCatalog([COMBO]).sources;
171
+ expect(
172
+ Object.fromEntries(
173
+ source.views.map((v) => [
174
+ v.name,
175
+ v.shape && chartShapeGap("combo_chart", v.shape),
176
+ ]),
177
+ ),
178
+ ).toEqual({
179
+ by_month: undefined,
180
+ one_total: "combo_totals",
181
+ three_totals: "combo_totals",
182
+ totals_only: "no_x_axis",
183
+ nested_only: "no_x_axis",
184
+ });
185
+ });
186
+ });