@malloy-publisher/sdk 0.9.10 → 0.9.11

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 (257) hide show
  1. package/dist/RenderedResult-BlNoIiSi.cjs.js +153 -0
  2. package/dist/{RenderedResult-Dp1Qdajz.es.js → RenderedResult-Cmx8sX8d.es.js} +102 -102
  3. package/dist/ServerProvider-BOgiW8MX.cjs.js +1 -0
  4. package/dist/{ServerProvider-CQy4jVYK.es.js → ServerProvider-azXLkk1q.es.js} +619 -586
  5. package/dist/builder/index.cjs.js +78 -130
  6. package/dist/builder/index.es.js +7493 -6769
  7. package/dist/builder-entry.d.ts +3 -0
  8. package/dist/client/api.d.ts +26 -22
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +1 -1
  11. package/dist/components/AppDialog.d.ts +9 -1
  12. package/dist/components/Dashboard/DashboardGrid.d.ts +14 -15
  13. package/dist/components/Dashboard/DashboardTile.d.ts +8 -1
  14. package/dist/components/Dashboard/DashboardView.d.ts +22 -34
  15. package/dist/components/Dashboard/TileCard.d.ts +10 -3
  16. package/dist/components/Dashboard/useStuck.d.ts +15 -7
  17. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +6 -0
  18. package/dist/components/Package/PackageProblems.d.ts +14 -0
  19. package/dist/components/RemoveBadge.d.ts +40 -0
  20. package/dist/components/Report/Report.d.ts +13 -4
  21. package/dist/components/Report/ReportPage.d.ts +60 -0
  22. package/dist/components/Report/layoutRules.d.ts +32 -0
  23. package/dist/components/Report/reportQuery.d.ts +30 -0
  24. package/dist/components/Report/telemetry.d.ts +0 -2
  25. package/dist/components/ReportBuilder/AddTileDialog.d.ts +22 -3
  26. package/dist/components/ReportBuilder/BuilderBar.d.ts +17 -0
  27. package/dist/components/ReportBuilder/BuilderDialogs.d.ts +7 -6
  28. package/dist/components/ReportBuilder/BuilderGrid.d.ts +10 -4
  29. package/dist/components/ReportBuilder/BuilderHeader.d.ts +4 -7
  30. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +88 -0
  31. package/dist/components/ReportBuilder/DrillDialog.d.ts +3 -1
  32. package/dist/components/ReportBuilder/EditorSurface.d.ts +7 -9
  33. package/dist/components/ReportBuilder/FilterDialog.d.ts +3 -1
  34. package/dist/components/ReportBuilder/FilterStrip.d.ts +30 -8
  35. package/dist/components/ReportBuilder/InlineMarkdown.d.ts +4 -4
  36. package/dist/components/ReportBuilder/ReportBuilder.d.ts +49 -12
  37. package/dist/components/ReportBuilder/ReportEditor.d.ts +53 -3
  38. package/dist/components/ReportBuilder/TextTileBody.d.ts +2 -5
  39. package/dist/components/ReportBuilder/TileFrame.d.ts +10 -4
  40. package/dist/components/ReportBuilder/TileMenu.d.ts +12 -9
  41. package/dist/components/ReportBuilder/ViewPicker.d.ts +53 -0
  42. package/dist/components/ReportBuilder/addTileToDocument.d.ts +24 -3
  43. package/dist/components/ReportBuilder/builderControls.d.ts +60 -0
  44. package/dist/components/ReportBuilder/catalog.d.ts +2 -4
  45. package/dist/components/ReportBuilder/inlineEdit.d.ts +9 -10
  46. package/dist/components/ReportBuilder/localGiven.d.ts +12 -0
  47. package/dist/components/ReportBuilder/preview.d.ts +17 -2
  48. package/dist/components/ReportBuilder/readDocument.d.ts +0 -2
  49. package/dist/components/ReportBuilder/readForEditor.d.ts +2 -7
  50. package/dist/components/ReportBuilder/reportTag.d.ts +11 -1
  51. package/dist/components/ReportBuilder/sortable.d.ts +4 -3
  52. package/dist/components/ReportBuilder/testing/inline.d.ts +5 -1
  53. package/dist/components/ReportBuilder/useBuilderSelection.d.ts +0 -1
  54. package/dist/components/ReportBuilder/useBuilderSession.d.ts +21 -12
  55. package/dist/components/ReportBuilder/useDocumentEditor.d.ts +2 -6
  56. package/dist/components/ReportBuilder/useExitGuard.d.ts +3 -0
  57. package/dist/components/ReportBuilder/useFilterForm.d.ts +3 -1
  58. package/dist/components/ReportBuilder/useOpenedDocument.d.ts +0 -4
  59. package/dist/components/ReportBuilder/useReportDraft.d.ts +66 -0
  60. package/dist/components/ReportBuilder/useReportEditor.d.ts +0 -9
  61. package/dist/components/ReportBuilder/useTileEditing.d.ts +6 -3
  62. package/dist/components/ReportBuilder/viewAnnotations.d.ts +9 -0
  63. package/dist/components/ReportBuilder/widthLabel.d.ts +6 -0
  64. package/dist/components/ServerProvider.d.ts +9 -0
  65. package/dist/components/controlTokens.d.ts +45 -0
  66. package/dist/components/drill/markDrillableCells.d.ts +1 -1
  67. package/dist/components/given/FilterButton.d.ts +35 -0
  68. package/dist/components/given/GivensPanel.d.ts +2 -1
  69. package/dist/components/given/filterEditing.d.ts +54 -0
  70. package/dist/components/given/filterSummary.d.ts +9 -0
  71. package/dist/components/given/paramCodec.d.ts +11 -0
  72. package/dist/components/given/required.d.ts +25 -0
  73. package/dist/components/index.d.ts +3 -0
  74. package/dist/components/legacy/index.d.ts +1 -1
  75. package/dist/components/{Report/CellReport.d.ts → legacy/malloynb/CellRunnerView.d.ts} +9 -17
  76. package/dist/components/legacy/{MalloynbCells.d.ts → malloynb/MalloynbCells.d.ts} +3 -3
  77. package/dist/components/legacy/{Notebook.d.ts → malloynb/Notebook.d.ts} +1 -1
  78. package/dist/components/{Notebook → legacy/malloynb}/NotebookCell.d.ts +3 -3
  79. package/dist/components/legacy/malloynb/cellKind.d.ts +5 -0
  80. package/dist/components/{Notebook → legacy/malloynb}/types.d.ts +1 -1
  81. package/dist/components/styles.d.ts +0 -2
  82. package/dist/hooks/useQueryResult.d.ts +7 -0
  83. package/dist/index.cjs.js +16 -19
  84. package/dist/index.es.js +8324 -7769
  85. package/dist/theme/ThemeContext.d.ts +8 -1
  86. package/dist/theme/classes.d.ts +49 -0
  87. package/dist/theme/index.d.ts +2 -0
  88. package/dist/theme/types.d.ts +7 -0
  89. package/dist/theme/ui.d.ts +75 -0
  90. package/dist/{useCompiledDocument-BMPDvdFx.es.js → useCompiledDocument-7j5cBjQd.es.js} +8669 -7851
  91. package/dist/useCompiledDocument-B21sVbb4.cjs.js +141 -0
  92. package/package.json +2 -2
  93. package/src/builder-entry.ts +9 -0
  94. package/src/components/AppDialog.tsx +23 -0
  95. package/src/components/Dashboard/DashboardGrid.tsx +39 -17
  96. package/src/components/Dashboard/DashboardTile.tsx +19 -2
  97. package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
  98. package/src/components/Dashboard/DashboardView.tsx +137 -155
  99. package/src/components/Dashboard/RowsDialog.tsx +1 -2
  100. package/src/components/Dashboard/TileCard.tsx +28 -10
  101. package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
  102. package/src/components/Dashboard/useStuck.ts +28 -17
  103. package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
  104. package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
  105. package/src/components/Package/NewDocumentDialog.tsx +383 -119
  106. package/src/components/Package/Package.artifacts.spec.tsx +1 -1
  107. package/src/components/Package/Package.create.spec.tsx +7 -6
  108. package/src/components/Package/Package.tsx +10 -7
  109. package/src/components/Package/PackageProblems.spec.tsx +41 -0
  110. package/src/components/Package/PackageProblems.tsx +95 -0
  111. package/src/components/Prose.tsx +12 -7
  112. package/src/components/RemoveBadge.tsx +94 -0
  113. package/src/components/RenderedResult/RenderedResult.tsx +5 -9
  114. package/src/components/RenderedResult/ResultPanel.tsx +59 -3
  115. package/src/components/Report/Report.spec.tsx +50 -32
  116. package/src/components/Report/Report.telemetry.spec.tsx +0 -45
  117. package/src/components/Report/Report.tsx +45 -77
  118. package/src/components/Report/ReportPage.tsx +168 -0
  119. package/src/components/Report/layoutRules.spec.ts +35 -0
  120. package/src/components/Report/layoutRules.ts +55 -0
  121. package/src/components/Report/reportQuery.ts +53 -0
  122. package/src/components/Report/telemetry.ts +0 -2
  123. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
  124. package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
  125. package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
  126. package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -39
  127. package/src/components/ReportBuilder/BuilderGrid.tsx +31 -29
  128. package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
  129. package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
  130. package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
  131. package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
  132. package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
  133. package/src/components/ReportBuilder/FilterStrip.tsx +130 -151
  134. package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
  135. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
  136. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
  137. package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
  138. package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -15
  139. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
  140. package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
  141. package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
  142. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +37 -31
  143. package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
  144. package/src/components/ReportBuilder/ReportBuilder.tsx +292 -117
  145. package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
  146. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
  147. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
  148. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
  149. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
  150. package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
  151. package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
  152. package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
  153. package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
  154. package/src/components/ReportBuilder/TileFrame.tsx +212 -75
  155. package/src/components/ReportBuilder/TileMenu.tsx +241 -140
  156. package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
  157. package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
  158. package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
  159. package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
  160. package/src/components/ReportBuilder/builderControls.ts +164 -0
  161. package/src/components/ReportBuilder/builderReport.ts +1 -2
  162. package/src/components/ReportBuilder/catalog.ts +10 -26
  163. package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
  164. package/src/components/ReportBuilder/localGiven.ts +56 -0
  165. package/src/components/ReportBuilder/preview.spec.ts +125 -5
  166. package/src/components/ReportBuilder/preview.ts +60 -44
  167. package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
  168. package/src/components/ReportBuilder/readDocument.ts +14 -11
  169. package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
  170. package/src/components/ReportBuilder/readForEditor.ts +4 -26
  171. package/src/components/ReportBuilder/reportTag.ts +28 -7
  172. package/src/components/ReportBuilder/sortable.tsx +15 -7
  173. package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
  174. package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
  175. package/src/components/ReportBuilder/testing/inline.ts +25 -5
  176. package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
  177. package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
  178. package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
  179. package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
  180. package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
  181. package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
  182. package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
  183. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
  184. package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
  185. package/src/components/ReportBuilder/useExitGuard.ts +16 -0
  186. package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
  187. package/src/components/ReportBuilder/useFilterForm.ts +5 -1
  188. package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
  189. package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
  190. package/src/components/ReportBuilder/useReportDraft.ts +292 -0
  191. package/src/components/ReportBuilder/useReportEditor.ts +3 -12
  192. package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
  193. package/src/components/ReportBuilder/useTileEditing.ts +43 -12
  194. package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
  195. package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
  196. package/src/components/ReportBuilder/widthLabel.ts +26 -0
  197. package/src/components/ServerProvider.tsx +11 -0
  198. package/src/components/controlTokens.ts +47 -0
  199. package/src/components/drill/markDrillableCells.ts +2 -1
  200. package/src/components/given/FilterButton.spec.tsx +143 -0
  201. package/src/components/given/FilterButton.tsx +478 -0
  202. package/src/components/given/GivenInput.spec.tsx +47 -0
  203. package/src/components/given/GivenInput.tsx +20 -2
  204. package/src/components/given/GivensPanel.spec.tsx +11 -3
  205. package/src/components/given/GivensPanel.tsx +45 -44
  206. package/src/components/given/filterEditing.ts +60 -0
  207. package/src/components/given/filterSummary.spec.ts +108 -0
  208. package/src/components/given/filterSummary.ts +109 -0
  209. package/src/components/given/paramCodec.ts +1 -1
  210. package/src/components/given/required.spec.ts +60 -0
  211. package/src/components/given/required.ts +78 -0
  212. package/src/components/index.ts +9 -0
  213. package/src/components/legacy/Dashboard.spec.tsx +3 -1
  214. package/src/components/legacy/index.ts +1 -1
  215. package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
  216. package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
  217. package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
  218. package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
  219. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
  220. package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
  221. package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
  222. package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
  223. package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
  224. package/src/components/legacy/malloynb/cellKind.ts +24 -0
  225. package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
  226. package/src/components/styles.ts +0 -18
  227. package/src/hooks/useGivensState.ts +7 -3
  228. package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
  229. package/src/hooks/useQueryResult.ts +26 -1
  230. package/src/theme/ThemeContext.tsx +21 -1
  231. package/src/theme/classes.ts +52 -0
  232. package/src/theme/index.ts +8 -0
  233. package/src/theme/resolveTheme.ts +3 -0
  234. package/src/theme/types.ts +7 -0
  235. package/src/theme/ui.spec.tsx +91 -0
  236. package/src/theme/ui.ts +115 -0
  237. package/dist/RenderedResult-BcgYjkZ0.cjs.js +0 -153
  238. package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
  239. package/dist/components/Notebook/cellKind.d.ts +0 -20
  240. package/dist/components/Report/LinearReport.d.ts +0 -18
  241. package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
  242. package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
  243. package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
  244. package/dist/useCompiledDocument-UY28ITET.cjs.js +0 -141
  245. package/src/components/Notebook/cellKind.spec.ts +0 -199
  246. package/src/components/Notebook/cellKind.ts +0 -74
  247. package/src/components/Report/LinearReport.tsx +0 -71
  248. package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
  249. package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
  250. package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
  251. package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
  252. package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
  253. package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
  254. package/src/components/legacy/Notebook.served.spec.tsx +0 -183
  255. /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
  256. /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
  257. /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.9.10",
4
+ "version": "0.9.11",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -75,7 +75,7 @@
75
75
  "build": "bun generate-api-types && bunx vite build",
76
76
  "postbuild": "cp ../../node_modules/@malloydata/malloy-explorer/dist/malloy-explorer.css ./dist/malloy-explorer.css && echo '/* SDK Styles */\n@import \"./malloy-explorer.css\";' > ./dist/styles.css",
77
77
  "test": "bun test",
78
- "test:tz": "bun test ./src/components/given/GivenInput.spec.tsx ./src/components/given/paramCodec.spec.ts ./src/utils/malloyLiteral.spec.ts ./src/components/drill/resolveDrill.spec.ts ./src/components/ReportBuilder/preview.spec.ts ./src/components/Materializations/cron.spec.ts ./src/components/Materializations/utils.spec.ts",
78
+ "test:tz": "bun test ./src/components/given/GivenInput.spec.tsx ./src/components/given/filterSummary.spec.ts ./src/components/given/paramCodec.spec.ts ./src/utils/malloyLiteral.spec.ts ./src/components/drill/resolveDrill.spec.ts ./src/components/ReportBuilder/preview.spec.ts ./src/components/Materializations/cron.spec.ts ./src/components/Materializations/utils.spec.ts",
79
79
  "lint": "bunx eslint ./src ./test --fix",
80
80
  "format": "bunx prettier --write --parser typescript '**/*.{ts,tsx}'",
81
81
  "analyze": "bunx vite-bundle-visualizer",
@@ -22,6 +22,15 @@ if (typeof globalThis.process === "undefined") {
22
22
  }
23
23
 
24
24
  export { ReportBuilder } from "./components/ReportBuilder/ReportBuilder";
25
+ export type { FixedFilter } from "./components/ReportBuilder/FilterStrip";
26
+ export {
27
+ BuilderBar,
28
+ type BuilderBarProps,
29
+ } from "./components/ReportBuilder/BuilderBar";
30
+ export type {
31
+ BuilderControls,
32
+ BuilderControlsHandler,
33
+ } from "./components/ReportBuilder/builderControls";
25
34
  export type {
26
35
  BuilderGiven,
27
36
  ReportBuilderProps,
@@ -1,6 +1,7 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
+ import { usePublisherTheme } from "../theme/ThemeContext";
4
5
  import CloseIcon from "@mui/icons-material/Close";
5
6
  import {
6
7
  Dialog,
@@ -37,6 +38,8 @@ export function AppDialog({
37
38
  maxWidth = "sm",
38
39
  showClose = false,
39
40
  actions,
41
+ initialFocus,
42
+ className,
40
43
  children,
41
44
  }: {
42
45
  open: boolean;
@@ -50,9 +53,18 @@ export function AppDialog({
50
53
  showClose?: boolean;
51
54
  /** The buttons, in order. Cancel first, the thing it does last. */
52
55
  actions?: React.ReactNode;
56
+ /**
57
+ * The control to start in. Focused once the window has opened: a child's
58
+ * own `autoFocus` loses to the focus trap, which takes focus to the
59
+ * window's container as it opens, after the child has mounted.
60
+ */
61
+ initialFocus?: React.RefObject<HTMLElement | null>;
62
+ /** Classes on the window's root, for a host to style it by. */
63
+ className?: string;
53
64
  children: React.ReactNode;
54
65
  }) {
55
66
  const titleId = useId();
67
+ const ui = usePublisherTheme().theme.ui;
56
68
  return (
57
69
  <Dialog
58
70
  open={open}
@@ -60,6 +72,17 @@ export function AppDialog({
60
72
  maxWidth={maxWidth}
61
73
  fullWidth
62
74
  aria-labelledby={titleId}
75
+ {...(className ? { className } : {})}
76
+ // The host's dialog radius (`ui.radius.dialog`), as every other
77
+ // corner on a report surface takes its token.
78
+ PaperProps={{ sx: { borderRadius: ui.radius.dialog } }}
79
+ {...(initialFocus
80
+ ? {
81
+ TransitionProps: {
82
+ onEntered: () => initialFocus.current?.focus(),
83
+ },
84
+ }
85
+ : {})}
63
86
  >
64
87
  <DialogTitle
65
88
  id={titleId}
@@ -2,7 +2,13 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { Box } from "@mui/material";
5
- import { useEffect, useRef, useState, type ReactNode } from "react";
5
+ import {
6
+ useEffect,
7
+ useRef,
8
+ useState,
9
+ type ReactNode,
10
+ type RefObject,
11
+ } from "react";
6
12
 
7
13
  /** Grid width when the dashboard declares no `# dashboard { columns=N }`. */
8
14
  export const DEFAULT_COLUMNS = 2;
@@ -24,22 +30,10 @@ export const nudgedSpan = (current: number, delta: 1 | -1, columns: number) =>
24
30
  export const GRID_GAP_PX = 16;
25
31
 
26
32
  /**
27
- * The space between a notebook's tiles, which stack in one column with no card
28
- * around them: wider than a dashboard's gap so the reading flow breathes, and
29
- * so the builder's selection ring, drawn {@link BARE_RING_OFFSET_PX} clear of
30
- * a bare tile, never meets the next tile's.
33
+ * How far a bare (uncarded) tile's selection ring sits from its prose: half the
34
+ * {@link GRID_GAP_PX} between tiles, so a ring never reaches into the next tile.
31
35
  */
32
- export const NOTEBOOK_GAP_PX = 40;
33
-
34
- /** How far a bare (uncarded) tile's selection ring sits from its content. */
35
- export const BARE_RING_OFFSET_PX = 12;
36
-
37
- /**
38
- * The space above and below a notebook's description, in both modes: a bare
39
- * description's ring in the builder is {@link BARE_RING_OFFSET_PX} clear of
40
- * its text, and needs the room to stay clear of the title and the filters.
41
- */
42
- export const BARE_DESCRIPTION_MARGIN_PX = BARE_RING_OFFSET_PX + 8;
36
+ export const BARE_RING_OFFSET_PX = GRID_GAP_PX / 2;
43
37
 
44
38
  /**
45
39
  * The `grid-column` one tile occupies: its `# colspan`, and a `# break` forcing
@@ -58,6 +52,34 @@ export function tileGridColumn(
58
52
  return tile.break ? `1 / span ${span}` : `span ${span}`;
59
53
  }
60
54
 
55
+ /** Narrowest a tile that sets no `colspan` is drawn, by the reader and the builder alike. */
56
+ export const MIN_TILE_PX = 240;
57
+
58
+ /**
59
+ * The span a tile with no `# colspan` is drawn at in the grid inside `box`:
60
+ * {@link defaultTileSpan} on its measured width. For a surface that lays the
61
+ * grid out itself (the builder, whose width handle and row arithmetic need
62
+ * the span a tile is drawn at, not the one it writes).
63
+ */
64
+ export function useDefaultTileSpan(
65
+ box: RefObject<HTMLElement | null>,
66
+ columns: number,
67
+ minTilePx: number = MIN_TILE_PX,
68
+ ): number {
69
+ const [width, setWidth] = useState(0);
70
+ useEffect(() => {
71
+ const node = box.current;
72
+ if (!node || typeof ResizeObserver === "undefined") return;
73
+ setWidth(node.getBoundingClientRect().width);
74
+ const observer = new ResizeObserver(([entry]) =>
75
+ setWidth(entry?.contentRect.width ?? 0),
76
+ );
77
+ observer.observe(node);
78
+ return () => observer.disconnect();
79
+ }, [box]);
80
+ return defaultTileSpan(columns, width, minTilePx);
81
+ }
82
+
61
83
  /**
62
84
  * Columns a tile with no `# colspan` spans so it is at least `minTilePx` wide.
63
85
  *
@@ -131,7 +153,7 @@ export function DashboardGrid<T extends GridTile>({
131
153
  * builder assumes an unset colspan is one column.
132
154
  */
133
155
  minTilePx?: number;
134
- /** The space between rows; a notebook's is {@link NOTEBOOK_GAP_PX}. */
156
+ /** The space between rows. */
135
157
  rowGapPx?: number;
136
158
  }) {
137
159
  const ref = useRef<HTMLDivElement>(null);
@@ -89,6 +89,13 @@ export interface DashboardTileProps {
89
89
  preamble?: string;
90
90
  /** The server marked this tile unreadable for the viewer: nothing is run. */
91
91
  restricted?: boolean;
92
+ /**
93
+ * Set while a required filter this tile reads has no value: what to say in
94
+ * place of the result ("Waiting for Recall Year."). Nothing is run, since
95
+ * the query would only fail with the compiler's "has no value and no
96
+ * default".
97
+ */
98
+ waitingFor?: string;
92
99
  /** Its position in the report, for the `report.query_failed` it reports. */
93
100
  index?: number;
94
101
  }
@@ -141,6 +148,7 @@ export function DashboardTile({
141
148
  ignoredFilters,
142
149
  preamble,
143
150
  restricted,
151
+ waitingFor,
144
152
  index,
145
153
  }: DashboardTileProps) {
146
154
  const { theme } = usePublisherTheme();
@@ -171,7 +179,10 @@ export function DashboardTile({
171
179
  ),
172
180
  },
173
181
  // Restricted tiles never run; the rest wait to come near the viewport.
174
- { enabled: nearViewport && restricted !== true },
182
+ {
183
+ enabled:
184
+ nearViewport && restricted !== true && waitingFor === undefined,
185
+ },
175
186
  );
176
187
  // Each failed run once: the error is drawn in place, and the report's host
177
188
  // hears of it when one is listening.
@@ -237,7 +248,13 @@ export function DashboardTile({
237
248
  />
238
249
  )}
239
250
  {ignoredFilters && <TileFilterTag ignored={ignoredFilters} />}
240
- {noAccess ? (
251
+ {waitingFor !== undefined ? (
252
+ <Box sx={{ p: 2 }}>
253
+ <Typography variant="body2" role="status" color="text.secondary">
254
+ {waitingFor}
255
+ </Typography>
256
+ </Box>
257
+ ) : noAccess ? (
241
258
  <Box sx={{ p: 2 }}>
242
259
  <Typography variant="body2" role="status" color="text.secondary">
243
260
  {RESTRICTED_NOTICE}
@@ -125,27 +125,154 @@ describe("DashboardView tiles", () => {
125
125
  });
126
126
  });
127
127
 
128
- describe("DashboardView chrome", () => {
129
- it("draws cards by default", async () => {
130
- const { container } = render(view(), { wrapper: serverWrapper });
131
- await screen.findByText("reader");
128
+ describe("filters a host writes into the query (literalReads)", () => {
129
+ it("count as read for the tile, and are never sent as givens", async () => {
130
+ const manifest = {
131
+ ...base,
132
+ givens: [
133
+ { name: "REGION", type: "string", label: "Region" },
134
+ // The document's own filter: resolved to a literal by the host.
135
+ { name: "BRAND", type: "string", label: "Brand" },
136
+ ],
137
+ tiles: [
138
+ {
139
+ kind: "query",
140
+ query: "orders -> by_brand",
141
+ givenNames: ["REGION"],
142
+ },
143
+ {
144
+ kind: "query",
145
+ query: "orders -> by_region",
146
+ givenNames: ["REGION"],
147
+ },
148
+ ],
149
+ } as DashboardManifest;
150
+ render(
151
+ <DashboardView
152
+ manifest={manifest}
153
+ environmentName="env"
154
+ packageName="pkg"
155
+ documentName="ops"
156
+ givens={{ REGION: "West", BRAND: "Acme" }}
157
+ literalReads={{ "orders -> by_brand": ["BRAND"] }}
158
+ />,
159
+ { wrapper: serverWrapper },
160
+ );
161
+
162
+ await waitFor(() =>
163
+ expect(executeQueryModel.mock.calls.length).toBeGreaterThanOrEqual(2),
164
+ );
165
+ // Only the tile that does not read Brand says so.
166
+ const tags = await screen.findAllByTestId("tile-filter-tag");
167
+ expect(tags.map((tag) => tag.textContent)).toEqual([
168
+ "Doesn't respond to Brand",
169
+ ]);
170
+ expect(tags[0].closest("[data-chrome]")?.textContent).toContain(
171
+ "By region",
172
+ );
173
+ // Brand's value reaches no request: the server does not know it.
174
+ for (const call of executeQueryModel.mock.calls)
175
+ expect(JSON.stringify(call[3])).not.toContain("BRAND");
176
+ });
177
+ });
178
+
179
+ describe("a required filter with no value", () => {
180
+ const manifest = {
181
+ ...base,
182
+ givens: [
183
+ {
184
+ name: "RECALL_YEAR",
185
+ type: "number",
186
+ label: "Recall Year",
187
+ required: true,
188
+ },
189
+ ],
190
+ tiles: [
191
+ {
192
+ kind: "query",
193
+ query: "recalls -> by_year",
194
+ givenNames: ["RECALL_YEAR"],
195
+ label: "By year",
196
+ },
197
+ {
198
+ kind: "query",
199
+ query: "recalls -> everything",
200
+ givenNames: [],
201
+ label: "Everything",
202
+ },
203
+ ],
204
+ } as DashboardManifest;
205
+ const sent = () =>
206
+ executeQueryModel.mock.calls.map(
207
+ (call) => (call[3] as { query?: string }).query,
208
+ );
209
+
210
+ it("runs no tile that reads it, and asks for it once for the page", async () => {
211
+ render(
212
+ <DashboardView
213
+ manifest={manifest}
214
+ environmentName="env"
215
+ packageName="pkg"
216
+ documentName="recalls"
217
+ />,
218
+ { wrapper: serverWrapper },
219
+ );
220
+ expect(
221
+ await screen.findByText(
222
+ "Pick a value for Recall Year to see this report.",
223
+ ),
224
+ ).toBeDefined();
225
+ expect(screen.getByText("Waiting for Recall Year.")).toBeDefined();
226
+ await waitFor(() =>
227
+ expect(sent()).toContain("run: recalls -> everything"),
228
+ );
229
+ expect(sent()).not.toContain("run: recalls -> by_year");
230
+ // The control says it, rather than "Any".
132
231
  expect(
133
- container.querySelectorAll('[data-chrome="card"]').length,
134
- ).toBeGreaterThan(0);
135
- expect(container.querySelector('[data-chrome="none"]')).toBeNull();
232
+ screen.getByRole("button", { name: "Recall Year: Required" }),
233
+ ).toBeDefined();
136
234
  });
137
235
 
138
- it("draws no cards and no title block with chrome none", async () => {
139
- const { container } = render(view("none"), { wrapper: serverWrapper });
140
- await screen.findByText("reader");
141
- expect(container.querySelector('[data-chrome="card"]')).toBeNull();
142
- expect(container.querySelectorAll('[data-chrome="none"]').length).toBe(3);
143
- expect(screen.queryByText("ops")).toBeNull();
236
+ it("runs every tile once it has a value, with no prompt", async () => {
237
+ render(
238
+ <DashboardView
239
+ manifest={manifest}
240
+ environmentName="env"
241
+ packageName="pkg"
242
+ documentName="recalls-set"
243
+ givens={{ RECALL_YEAR: "2020" }}
244
+ />,
245
+ { wrapper: serverWrapper },
246
+ );
247
+ await waitFor(() => expect(sent()).toContain("run: recalls -> by_year"));
248
+ expect(
249
+ screen.queryByText("Pick a value for Recall Year to see this report."),
250
+ ).toBeNull();
144
251
  });
145
252
  });
146
253
 
254
+ describe("DashboardView chrome", () => {
255
+ // A linear report and a grid draw the same page: query tiles in cards, text
256
+ // tiles as bare prose, and the title block. `chrome` is accepted and ignored.
257
+ for (const chrome of [undefined, "card", "none"] as const) {
258
+ it(`draws query tiles as cards and text as prose, with chrome ${chrome ?? "unset"}`, async () => {
259
+ const { container } = render(view(chrome), {
260
+ wrapper: serverWrapper,
261
+ });
262
+ const strong = await screen.findByText("reader");
263
+ expect(
264
+ strong.closest("[data-chrome]")?.getAttribute("data-chrome"),
265
+ ).toBe("none");
266
+ expect(
267
+ container.querySelectorAll('[data-chrome="card"]'),
268
+ ).toHaveLength(2);
269
+ expect(screen.getByRole("heading", { name: "ops" })).toBeDefined();
270
+ });
271
+ }
272
+ });
273
+
147
274
  describe("DashboardView header", () => {
148
- it("boxes a dashboard's description as it boxes a text tile", async () => {
275
+ it("draws a dashboard's description as bare page prose, not a card", async () => {
149
276
  render(
150
277
  <DashboardView
151
278
  manifest={{ ...base, description: "About **this**" }}
@@ -157,8 +284,82 @@ describe("DashboardView header", () => {
157
284
  );
158
285
  const strong = await screen.findByText("this");
159
286
  expect(strong.closest("[data-chrome]")?.getAttribute("data-chrome")).toBe(
160
- "card",
287
+ "none",
288
+ );
289
+ });
290
+ });
291
+
292
+ describe("DashboardView layout marker", () => {
293
+ it("marks the page with its layout, and a report that failed to load too", () => {
294
+ const { container, unmount } = render(
295
+ <DashboardView
296
+ manifest={{ ...base, layout: "linear" }}
297
+ environmentName="env"
298
+ packageName="pkg"
299
+ documentName="ops"
300
+ />,
301
+ { wrapper: serverWrapper },
302
+ );
303
+ expect(container.querySelector('[data-layout="linear"]')).not.toBeNull();
304
+ unmount();
305
+
306
+ const failed = render(
307
+ <DashboardView
308
+ manifest={{ ...base, layout: "grid", error: "did not compile" }}
309
+ environmentName="env"
310
+ packageName="pkg"
311
+ documentName="ops"
312
+ />,
313
+ { wrapper: serverWrapper },
161
314
  );
315
+ expect(
316
+ failed.container.querySelector('[data-layout="grid"]'),
317
+ ).not.toBeNull();
318
+ });
319
+ });
320
+
321
+ describe("DashboardView prose links", () => {
322
+ const linked = {
323
+ ...base,
324
+ tiles: [
325
+ { kind: "text", name: "intro", markdown: "See [the tour](tour)" },
326
+ ],
327
+ } as DashboardManifest;
328
+
329
+ it("leaves a relative link as written when the host has no router", async () => {
330
+ render(
331
+ <DashboardView
332
+ manifest={linked}
333
+ environmentName="env"
334
+ packageName="pkg"
335
+ documentName="ops"
336
+ />,
337
+ { wrapper: serverWrapper },
338
+ );
339
+
340
+ const link = await screen.findByRole("link", { name: "the tour" });
341
+ // Its host's routes are unknown here (a version segment, another prefix), so nothing is rewritten.
342
+ expect(link.getAttribute("href")).toBe("tour");
343
+ });
344
+
345
+ it("resolves a relative link against the report and hands it to the host's router", async () => {
346
+ const onLinkNavigate = mock((_to: string) => undefined);
347
+ render(
348
+ <DashboardView
349
+ manifest={linked}
350
+ environmentName="env"
351
+ packageName="pkg"
352
+ documentName="ops"
353
+ onLinkNavigate={onLinkNavigate}
354
+ />,
355
+ { wrapper: serverWrapper },
356
+ );
357
+
358
+ const link = await screen.findByRole("link", { name: "the tour" });
359
+ expect(link.getAttribute("href")).toBe("/env/pkg/dashboards/tour");
360
+ link.click();
361
+ expect(onLinkNavigate).toHaveBeenCalledTimes(1);
362
+ expect(onLinkNavigate.mock.calls[0][0]).toBe("/env/pkg/dashboards/tour");
162
363
  });
163
364
  });
164
365