@malloy-publisher/sdk 0.9.9 → 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 (261) hide show
  1. package/dist/RenderedResult-BlNoIiSi.cjs.js +153 -0
  2. package/dist/{RenderedResult-BHuJpdSn.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 +7440 -6727
  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 -23
  15. package/dist/components/Dashboard/TileCard.d.ts +10 -3
  16. package/dist/components/Dashboard/useStuck.d.ts +22 -0
  17. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -5
  18. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +6 -0
  19. package/dist/components/Package/PackageProblems.d.ts +14 -0
  20. package/dist/components/RemoveBadge.d.ts +40 -0
  21. package/dist/components/Report/Report.d.ts +13 -4
  22. package/dist/components/Report/ReportPage.d.ts +60 -0
  23. package/dist/components/Report/layoutRules.d.ts +32 -0
  24. package/dist/components/Report/reportQuery.d.ts +30 -0
  25. package/dist/components/Report/telemetry.d.ts +0 -2
  26. package/dist/components/ReportBuilder/AddTileDialog.d.ts +22 -3
  27. package/dist/components/ReportBuilder/BuilderBar.d.ts +17 -0
  28. package/dist/components/ReportBuilder/BuilderDialogs.d.ts +7 -6
  29. package/dist/components/ReportBuilder/BuilderGrid.d.ts +10 -4
  30. package/dist/components/ReportBuilder/BuilderHeader.d.ts +4 -7
  31. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +88 -0
  32. package/dist/components/ReportBuilder/DrillDialog.d.ts +3 -1
  33. package/dist/components/ReportBuilder/EditorSurface.d.ts +7 -9
  34. package/dist/components/ReportBuilder/FilterDialog.d.ts +3 -1
  35. package/dist/components/ReportBuilder/FilterStrip.d.ts +30 -6
  36. package/dist/components/ReportBuilder/InlineMarkdown.d.ts +4 -4
  37. package/dist/components/ReportBuilder/ReportBuilder.d.ts +49 -12
  38. package/dist/components/ReportBuilder/ReportEditor.d.ts +53 -3
  39. package/dist/components/ReportBuilder/TextTileBody.d.ts +2 -5
  40. package/dist/components/ReportBuilder/TileFrame.d.ts +10 -4
  41. package/dist/components/ReportBuilder/TileMenu.d.ts +19 -11
  42. package/dist/components/ReportBuilder/ViewPicker.d.ts +53 -0
  43. package/dist/components/ReportBuilder/addTileToDocument.d.ts +24 -3
  44. package/dist/components/ReportBuilder/builderControls.d.ts +60 -0
  45. package/dist/components/ReportBuilder/catalog.d.ts +2 -4
  46. package/dist/components/ReportBuilder/inlineEdit.d.ts +9 -10
  47. package/dist/components/ReportBuilder/localGiven.d.ts +12 -0
  48. package/dist/components/ReportBuilder/preview.d.ts +17 -2
  49. package/dist/components/ReportBuilder/readDocument.d.ts +0 -2
  50. package/dist/components/ReportBuilder/readForEditor.d.ts +2 -7
  51. package/dist/components/ReportBuilder/reportTag.d.ts +11 -1
  52. package/dist/components/ReportBuilder/sortable.d.ts +4 -3
  53. package/dist/components/ReportBuilder/testing/inline.d.ts +5 -1
  54. package/dist/components/ReportBuilder/useBuilderSelection.d.ts +0 -1
  55. package/dist/components/ReportBuilder/useBuilderSession.d.ts +21 -12
  56. package/dist/components/ReportBuilder/useDocumentEditor.d.ts +2 -6
  57. package/dist/components/ReportBuilder/useExitGuard.d.ts +3 -0
  58. package/dist/components/ReportBuilder/useFilterForm.d.ts +3 -1
  59. package/dist/components/ReportBuilder/useOpenedDocument.d.ts +0 -4
  60. package/dist/components/ReportBuilder/useReportDraft.d.ts +66 -0
  61. package/dist/components/ReportBuilder/useReportEditor.d.ts +0 -9
  62. package/dist/components/ReportBuilder/useTileEditing.d.ts +6 -3
  63. package/dist/components/ReportBuilder/viewAnnotations.d.ts +9 -0
  64. package/dist/components/ReportBuilder/widthLabel.d.ts +6 -0
  65. package/dist/components/ServerProvider.d.ts +9 -0
  66. package/dist/components/controlTokens.d.ts +45 -0
  67. package/dist/components/drill/markDrillableCells.d.ts +1 -1
  68. package/dist/components/given/FilterButton.d.ts +35 -0
  69. package/dist/components/given/GivensPanel.d.ts +2 -1
  70. package/dist/components/given/filterEditing.d.ts +54 -0
  71. package/dist/components/given/filterSummary.d.ts +9 -0
  72. package/dist/components/given/paramCodec.d.ts +11 -0
  73. package/dist/components/given/required.d.ts +25 -0
  74. package/dist/components/index.d.ts +3 -0
  75. package/dist/components/legacy/index.d.ts +1 -1
  76. package/dist/components/{Report/CellReport.d.ts → legacy/malloynb/CellRunnerView.d.ts} +9 -17
  77. package/dist/components/legacy/{MalloynbCells.d.ts → malloynb/MalloynbCells.d.ts} +3 -3
  78. package/dist/components/legacy/{Notebook.d.ts → malloynb/Notebook.d.ts} +1 -1
  79. package/dist/components/{Notebook → legacy/malloynb}/NotebookCell.d.ts +3 -3
  80. package/dist/components/legacy/malloynb/cellKind.d.ts +5 -0
  81. package/dist/components/{Notebook → legacy/malloynb}/types.d.ts +1 -1
  82. package/dist/components/styles.d.ts +0 -2
  83. package/dist/hooks/useQueryResult.d.ts +7 -0
  84. package/dist/index.cjs.js +16 -19
  85. package/dist/index.es.js +8324 -7769
  86. package/dist/theme/ThemeContext.d.ts +8 -1
  87. package/dist/theme/classes.d.ts +49 -0
  88. package/dist/theme/index.d.ts +2 -0
  89. package/dist/theme/types.d.ts +7 -0
  90. package/dist/theme/ui.d.ts +75 -0
  91. package/dist/{useCompiledDocument-1dgF5CC9.es.js → useCompiledDocument-7j5cBjQd.es.js} +8768 -7912
  92. package/dist/useCompiledDocument-B21sVbb4.cjs.js +141 -0
  93. package/package.json +2 -2
  94. package/src/builder-entry.ts +9 -0
  95. package/src/components/AppDialog.tsx +23 -0
  96. package/src/components/Dashboard/DashboardGrid.tsx +39 -17
  97. package/src/components/Dashboard/DashboardTile.tsx +19 -2
  98. package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
  99. package/src/components/Dashboard/DashboardView.tsx +136 -105
  100. package/src/components/Dashboard/RowsDialog.tsx +1 -2
  101. package/src/components/Dashboard/TileCard.tsx +28 -10
  102. package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
  103. package/src/components/Dashboard/useStuck.ts +49 -0
  104. package/src/components/DocumentCreate/newNotebook.spec.ts +8 -6
  105. package/src/components/DocumentCreate/newNotebook.ts +26 -12
  106. package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
  107. package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
  108. package/src/components/Package/NewDocumentDialog.tsx +383 -119
  109. package/src/components/Package/Package.artifacts.spec.tsx +1 -1
  110. package/src/components/Package/Package.create.spec.tsx +7 -6
  111. package/src/components/Package/Package.tsx +10 -7
  112. package/src/components/Package/PackageProblems.spec.tsx +41 -0
  113. package/src/components/Package/PackageProblems.tsx +95 -0
  114. package/src/components/Prose.tsx +12 -7
  115. package/src/components/RemoveBadge.tsx +94 -0
  116. package/src/components/RenderedResult/RenderedResult.tsx +5 -9
  117. package/src/components/RenderedResult/ResultPanel.tsx +59 -3
  118. package/src/components/Report/Report.spec.tsx +50 -32
  119. package/src/components/Report/Report.telemetry.spec.tsx +0 -45
  120. package/src/components/Report/Report.tsx +45 -77
  121. package/src/components/Report/ReportPage.tsx +168 -0
  122. package/src/components/Report/layoutRules.spec.ts +35 -0
  123. package/src/components/Report/layoutRules.ts +55 -0
  124. package/src/components/Report/reportQuery.ts +53 -0
  125. package/src/components/Report/telemetry.ts +0 -2
  126. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
  127. package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
  128. package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
  129. package/src/components/ReportBuilder/BuilderDialogs.tsx +30 -39
  130. package/src/components/ReportBuilder/BuilderGrid.tsx +43 -31
  131. package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
  132. package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
  133. package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
  134. package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
  135. package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
  136. package/src/components/ReportBuilder/FilterStrip.tsx +129 -150
  137. package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
  138. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
  139. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
  140. package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
  141. package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -16
  142. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
  143. package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
  144. package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
  145. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +41 -36
  146. package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
  147. package/src/components/ReportBuilder/ReportBuilder.tsx +292 -116
  148. package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
  149. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
  150. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
  151. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
  152. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
  153. package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
  154. package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
  155. package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
  156. package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
  157. package/src/components/ReportBuilder/TileFrame.tsx +212 -75
  158. package/src/components/ReportBuilder/TileMenu.tsx +248 -142
  159. package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
  160. package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
  161. package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
  162. package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
  163. package/src/components/ReportBuilder/builderControls.ts +164 -0
  164. package/src/components/ReportBuilder/builderReport.ts +1 -2
  165. package/src/components/ReportBuilder/catalog.ts +10 -26
  166. package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
  167. package/src/components/ReportBuilder/localGiven.ts +56 -0
  168. package/src/components/ReportBuilder/newDashboard.spec.ts +2 -3
  169. package/src/components/ReportBuilder/preview.spec.ts +125 -5
  170. package/src/components/ReportBuilder/preview.ts +60 -44
  171. package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
  172. package/src/components/ReportBuilder/readDocument.ts +14 -11
  173. package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
  174. package/src/components/ReportBuilder/readForEditor.ts +4 -26
  175. package/src/components/ReportBuilder/reportTag.ts +28 -7
  176. package/src/components/ReportBuilder/sortable.tsx +15 -7
  177. package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
  178. package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
  179. package/src/components/ReportBuilder/testing/inline.ts +25 -5
  180. package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
  181. package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
  182. package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
  183. package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
  184. package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
  185. package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
  186. package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
  187. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
  188. package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
  189. package/src/components/ReportBuilder/useExitGuard.ts +16 -0
  190. package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
  191. package/src/components/ReportBuilder/useFilterForm.ts +5 -1
  192. package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
  193. package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
  194. package/src/components/ReportBuilder/useReportDraft.ts +292 -0
  195. package/src/components/ReportBuilder/useReportEditor.ts +3 -12
  196. package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
  197. package/src/components/ReportBuilder/useTileEditing.ts +43 -12
  198. package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
  199. package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
  200. package/src/components/ReportBuilder/widthLabel.ts +26 -0
  201. package/src/components/ServerProvider.tsx +11 -0
  202. package/src/components/controlTokens.ts +47 -0
  203. package/src/components/drill/markDrillableCells.ts +2 -1
  204. package/src/components/given/FilterButton.spec.tsx +143 -0
  205. package/src/components/given/FilterButton.tsx +478 -0
  206. package/src/components/given/GivenInput.spec.tsx +47 -0
  207. package/src/components/given/GivenInput.tsx +20 -2
  208. package/src/components/given/GivensPanel.spec.tsx +11 -3
  209. package/src/components/given/GivensPanel.tsx +45 -44
  210. package/src/components/given/filterEditing.ts +60 -0
  211. package/src/components/given/filterSummary.spec.ts +108 -0
  212. package/src/components/given/filterSummary.ts +109 -0
  213. package/src/components/given/paramCodec.ts +1 -1
  214. package/src/components/given/required.spec.ts +60 -0
  215. package/src/components/given/required.ts +78 -0
  216. package/src/components/index.ts +9 -0
  217. package/src/components/legacy/Dashboard.spec.tsx +3 -1
  218. package/src/components/legacy/index.ts +1 -1
  219. package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
  220. package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
  221. package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
  222. package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
  223. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
  224. package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
  225. package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
  226. package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
  227. package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
  228. package/src/components/legacy/malloynb/cellKind.ts +24 -0
  229. package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
  230. package/src/components/styles.ts +0 -18
  231. package/src/hooks/useGivensState.ts +7 -3
  232. package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
  233. package/src/hooks/useQueryResult.ts +26 -1
  234. package/src/theme/ThemeContext.tsx +21 -1
  235. package/src/theme/classes.ts +52 -0
  236. package/src/theme/index.ts +8 -0
  237. package/src/theme/resolveTheme.ts +3 -0
  238. package/src/theme/types.ts +7 -0
  239. package/src/theme/ui.spec.tsx +91 -0
  240. package/src/theme/ui.ts +115 -0
  241. package/dist/RenderedResult-Bw7EQc42.cjs.js +0 -153
  242. package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
  243. package/dist/components/Notebook/cellKind.d.ts +0 -20
  244. package/dist/components/Report/LinearReport.d.ts +0 -18
  245. package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
  246. package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
  247. package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
  248. package/dist/useCompiledDocument-BKyRnXmA.cjs.js +0 -141
  249. package/src/components/Notebook/cellKind.spec.ts +0 -199
  250. package/src/components/Notebook/cellKind.ts +0 -74
  251. package/src/components/Report/LinearReport.tsx +0 -71
  252. package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
  253. package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
  254. package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
  255. package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
  256. package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
  257. package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
  258. package/src/components/legacy/Notebook.served.spec.tsx +0 -183
  259. /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
  260. /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
  261. /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
@@ -5,7 +5,7 @@ import { Alert } from "@mui/material";
5
5
  import { useCallback, useEffect, useRef } from "react";
6
6
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
7
7
  import { now } from "../../utils/clock";
8
- import { encodeResourceUri, parseResourceUri } from "../../utils/formatting";
8
+ import { parseResourceUri } from "../../utils/formatting";
9
9
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
10
10
  import type { NavigationClick } from "../click_helper";
11
11
  import { DashboardView } from "../Dashboard/DashboardView";
@@ -13,8 +13,7 @@ import type { TileChrome } from "../Dashboard/TileCard";
13
13
  import type { DrillNavigation } from "../drill";
14
14
  import { Loading, LOADING_COPY } from "../Loading";
15
15
  import { useServer } from "../ServerProvider";
16
- import { CellReport } from "./CellReport";
17
- import { LinearReport } from "./LinearReport";
16
+ import { reportQueryOptions } from "./reportQuery";
18
17
  import {
19
18
  failureCategory,
20
19
  ReportEventsContext,
@@ -74,14 +73,23 @@ export interface ReportProps {
74
73
  * shown, a drill — for the host to log or count; see `ReportEvent`.
75
74
  */
76
75
  onEvent?: ReportEventHandler;
77
- /** A grid report's tile chrome: `card` (default) or `none`. */
76
+ /** Ignored: kept so existing callers compile. Both layouts draw the same cards. */
78
77
  chrome?: TileChrome;
78
+ /**
79
+ * How long a read of the report is reused without asking the server again,
80
+ * in ms. Default: the query client's staleness for the `report` key, which
81
+ * is 0 (every mount asks, so a change made elsewhere shows) unless the host
82
+ * sets one with `setQueryDefaults(["report"], …)`. A host that draws the
83
+ * same report twice in a row can set a few seconds, as the Console does
84
+ * while the builder loads over it.
85
+ */
86
+ manifestStaleTime?: number;
79
87
  }
80
88
 
81
89
  /**
82
90
  * A report of either layout, from `GET …/reports/{path}`: a grid drawn as a
83
- * dashboard, a linear report top to bottom, and a linear report written as
84
- * `run:` cells cell by cell, each through the governed query endpoint.
91
+ * dashboard, or a linear report top to bottom (a legacy `.malloynb` among
92
+ * them, read-only), each tile run through the governed query endpoint.
85
93
  *
86
94
  * Host-agnostic, like `Dashboard`: it takes props rather than reading a
87
95
  * router, and hands navigation and URL state back to whoever mounted it.
@@ -97,6 +105,7 @@ export function Report({
97
105
  maxResultSize,
98
106
  onEvent,
99
107
  chrome,
108
+ manifestStaleTime,
100
109
  }: ReportProps) {
101
110
  const parsed = parseResourceUri(resourceUri);
102
111
  const { apiClients } = useServer();
@@ -111,28 +120,21 @@ export function Report({
111
120
  isError,
112
121
  error,
113
122
  } = useQueryWithApiError({
114
- // Every value the request is built from, so two versions of one report
115
- // never share a cache entry.
116
- queryKey: ["report", environmentName, packageName, versionId, path],
117
- queryFn: async ({ signal }) =>
118
- (
119
- await apiClients.reports.getReport(
120
- environmentName,
121
- packageName,
122
- path,
123
- versionId,
124
- { signal },
125
- )
126
- ).data,
123
+ ...reportQueryOptions(
124
+ apiClients,
125
+ {
126
+ environmentName,
127
+ packageName,
128
+ path,
129
+ versionId,
130
+ },
131
+ manifestStaleTime,
132
+ ),
127
133
  enabled: uriNamesBoth && path !== "",
128
134
  });
129
135
 
130
- // The layout once the report has said; a `run:`-cell report reads top to bottom.
131
- const layout = manifest
132
- ? manifest.notebook
133
- ? "linear"
134
- : manifest.layout
135
- : undefined;
136
+ // The layout once the report has said.
137
+ const layout = manifest?.layout;
136
138
  const events = useReportEmitter({ path, layout }, onEvent);
137
139
  // One open or one failure per report shown: a refetch is not another open,
138
140
  // and the guard survives a development double-run of the effect.
@@ -172,9 +174,7 @@ export function Report({
172
174
  type: "report.opened",
173
175
  surface: "view",
174
176
  from: "package",
175
- tiles: manifest.notebook
176
- ? (manifest.notebook.notebookCells?.length ?? 0)
177
- : (manifest.tiles?.length ?? 0),
177
+ tiles: manifest.tiles?.length ?? 0,
178
178
  durationMs: now() - started.current.at,
179
179
  });
180
180
  }
@@ -218,55 +218,23 @@ export function Report({
218
218
  </Alert>
219
219
  );
220
220
  }
221
- let body;
222
- if (manifest.notebook) {
223
- body = (
224
- <CellReport
225
- resourceUri={encodeResourceUri({
226
- environmentName,
227
- packageName,
228
- versionId,
229
- modelPath: path,
230
- })}
231
- notebook={manifest.notebook}
232
- maxResultSize={maxResultSize}
233
- givens={givens}
234
- onGivensChange={onGivensChange}
235
- onNavigate={onLinkNavigate}
236
- onDrillNavigate={drillNavigate}
237
- />
238
- );
239
- } else if (manifest.layout === "linear") {
240
- body = (
241
- <LinearReport
242
- manifest={manifest}
243
- environmentName={environmentName}
244
- packageName={packageName}
245
- versionId={versionId}
246
- documentName={path}
247
- givens={givens}
248
- onGivensChange={onGivensChange}
249
- onDrillNavigate={drillNavigate}
250
- maxResultSize={maxResultSize}
251
- />
252
- );
253
- } else {
254
- body = (
255
- <DashboardView
256
- manifest={manifest}
257
- environmentName={environmentName}
258
- packageName={packageName}
259
- versionId={versionId}
260
- documentName={path}
261
- givens={givens}
262
- onGivensChange={onGivensChange}
263
- onNavigate={drillNavigate}
264
- height={height}
265
- maxResultSize={maxResultSize}
266
- chrome={chrome}
267
- />
268
- );
269
- }
221
+ // Either layout: the same view, arranged as the manifest's layout says.
222
+ const body = (
223
+ <DashboardView
224
+ manifest={manifest}
225
+ environmentName={environmentName}
226
+ packageName={packageName}
227
+ versionId={versionId}
228
+ documentName={path}
229
+ givens={givens}
230
+ onGivensChange={onGivensChange}
231
+ onNavigate={drillNavigate}
232
+ {...(onLinkNavigate ? { onLinkNavigate } : {})}
233
+ height={height}
234
+ maxResultSize={maxResultSize}
235
+ chrome={chrome}
236
+ />
237
+ );
270
238
  return (
271
239
  <ReportEventsContext.Provider value={events}>
272
240
  {body}
@@ -0,0 +1,168 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { reportClasses } from "../../theme/classes";
5
+ import {
6
+ Box,
7
+ Stack,
8
+ Typography,
9
+ type SxProps,
10
+ type Theme,
11
+ } from "@mui/material";
12
+ import type { ReactNode } from "react";
13
+ import { MOTION_FAST, reducedMotionSx } from "../../theme/motion";
14
+ import { usePublisherTheme } from "../../theme/ThemeContext";
15
+ import { edgeColor } from "../controlTokens";
16
+ import { TileCard } from "../Dashboard/TileCard";
17
+ import { STUCK_TOP_PX, useStuck } from "../Dashboard/useStuck";
18
+
19
+ /**
20
+ * The parts of a report page that the reader and the builder both draw, in
21
+ * either layout: the page's arrangement, its header, its pinned control row,
22
+ * and a text tile's frame.
23
+ *
24
+ * Each surface fills the same slots with its own content (the reader with
25
+ * text, the builder with the same text made editable in place) rather than
26
+ * drawing a page of its own, so a change to how a report looks is made here
27
+ * once and editing a page can never draw it differently from reading it.
28
+ */
29
+
30
+ /**
31
+ * The control row's stacking level: above anything a tile raises inside
32
+ * itself as it scrolls under (a result's floating buttons sit at 1–2), and
33
+ * below MUI's app bar, popovers and dialogs.
34
+ */
35
+ export const STICKY_CONTROLS_Z = 4;
36
+
37
+ /** The space between the page's parts and between its tiles' rows, in theme units. */
38
+ const PAGE_GAP = 2;
39
+
40
+ /**
41
+ * A report page, top to bottom: anything that must be said before it
42
+ * (`notice`), the header, the control row, then the body (the tiles, and
43
+ * whatever the surface adds under them).
44
+ */
45
+ export function ReportPage({
46
+ layout,
47
+ notice,
48
+ header,
49
+ controls,
50
+ children,
51
+ sx,
52
+ }: {
53
+ /** Written as `data-layout` on the page, so a test or a host can tell the two apart. */
54
+ layout?: "grid" | "linear";
55
+ notice?: ReactNode;
56
+ header: ReactNode;
57
+ controls?: ReactNode;
58
+ children: ReactNode;
59
+ sx?: SxProps<Theme>;
60
+ }) {
61
+ return (
62
+ <Stack
63
+ className={reportClasses.report}
64
+ data-layout={layout}
65
+ sx={[{ gap: PAGE_GAP }, ...(Array.isArray(sx) ? sx : [sx])]}
66
+ >
67
+ {notice}
68
+ {header}
69
+ {controls}
70
+ {children}
71
+ </Stack>
72
+ );
73
+ }
74
+
75
+ /**
76
+ * A report's title, with the surface's actions on its line (the builder's
77
+ * toolbar), and its description beneath. The title and description are slots:
78
+ * text in the reader, the same text editable in place in the builder.
79
+ */
80
+ export function ReportHeader({
81
+ title,
82
+ description,
83
+ actions,
84
+ }: {
85
+ title: ReactNode;
86
+ description?: ReactNode;
87
+ actions?: ReactNode;
88
+ }) {
89
+ const ui = usePublisherTheme().theme.ui;
90
+ return (
91
+ <Stack className={reportClasses.header} sx={{ gap: 1.5 }}>
92
+ <Stack direction="row" sx={{ alignItems: "center", gap: 2 }}>
93
+ <Typography
94
+ component="h1"
95
+ className={reportClasses.title}
96
+ sx={{ ...ui.type.pageTitle, m: 0, flex: 1, minWidth: 0 }}
97
+ >
98
+ {title}
99
+ </Typography>
100
+ {/* Overhangs the title's line rather than heightening it, so the
101
+ title sits at the same height with or without actions. */}
102
+ {actions && <Box sx={{ my: "-4px" }}>{actions}</Box>}
103
+ </Stack>
104
+ {description}
105
+ </Stack>
106
+ );
107
+ }
108
+
109
+ /**
110
+ * The frame a text tile (and the page description) is drawn in: none. Prose
111
+ * is part of the page, not a result, so it never takes a card, in either
112
+ * layout. One definition, so every text block on every surface agrees.
113
+ */
114
+ export function TextTileFrame({
115
+ sx,
116
+ children,
117
+ }: {
118
+ sx?: SxProps<Theme>;
119
+ children: ReactNode;
120
+ }) {
121
+ return (
122
+ <TileCard chrome="none" kind="text" {...(sx ? { sx } : {})}>
123
+ {children}
124
+ </TileCard>
125
+ );
126
+ }
127
+
128
+ /**
129
+ * The control row, pinned to the top of the scroller so the controls stay in
130
+ * reach while the tiles scroll under, with a hairline under it only while
131
+ * pinned: tiles passing beneath read as going under a bar rather than being
132
+ * cut off by nothing.
133
+ */
134
+ export function StickyControls({ children }: { children: ReactNode }) {
135
+ const { theme } = usePublisherTheme();
136
+ const { stickyRef, stuck } = useStuck();
137
+ return (
138
+ <Box
139
+ ref={stickyRef}
140
+ className={reportClasses.filterRow}
141
+ data-stuck={stuck || undefined}
142
+ sx={{
143
+ position: "sticky",
144
+ top: `${STUCK_TOP_PX}px`,
145
+ zIndex: STICKY_CONTROLS_Z,
146
+ bgcolor: "background.default",
147
+ // Room under the bar for the edge, so the line never sits on the
148
+ // controls themselves.
149
+ pb: 1,
150
+ // And room over them, for what stands above a control (a filter's
151
+ // × in the builder): pinned, the bar's top is the scroller's edge,
152
+ // and the badge was cut off there. Taken back by the margin, so the
153
+ // row sits where it did while unpinned.
154
+ pt: 1,
155
+ mt: -1,
156
+ // A shadow rather than a border: drawing the edge must not change
157
+ // the bar's height, or the page jumps as it pins.
158
+ boxShadow: stuck
159
+ ? `0 1px 0 ${edgeColor(theme.cardBorder)}`
160
+ : "none",
161
+ transition: `box-shadow ${MOTION_FAST}`,
162
+ ...reducedMotionSx,
163
+ }}
164
+ >
165
+ {children}
166
+ </Box>
167
+ );
168
+ }
@@ -0,0 +1,35 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { DEFAULT_COLUMNS } from "../Dashboard/DashboardGrid";
6
+ import { layoutRules } from "./layoutRules";
7
+
8
+ describe("layoutRules", () => {
9
+ it("lays a linear report in one column of full-width tiles, added between others", () => {
10
+ expect(layoutRules("linear", 12)).toEqual({
11
+ layout: "linear",
12
+ columns: 1,
13
+ widths: false,
14
+ insertBetween: true,
15
+ });
16
+ });
17
+
18
+ it("lays a grid across its declared columns, with widths, added at the end", () => {
19
+ expect(layoutRules("grid", 12)).toEqual({
20
+ layout: "grid",
21
+ columns: 12,
22
+ widths: true,
23
+ insertBetween: false,
24
+ });
25
+ });
26
+
27
+ it("reads no layout as a grid, at the default width", () => {
28
+ expect(layoutRules(undefined).columns).toBe(DEFAULT_COLUMNS);
29
+ expect(layoutRules(undefined).layout).toBe("grid");
30
+ });
31
+
32
+ it("gives a one-column grid no widths to set", () => {
33
+ expect(layoutRules("grid", 1).widths).toBe(false);
34
+ });
35
+ });
@@ -0,0 +1,55 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type { ReportLayout } from "../Package/documentLocation";
5
+ import { DEFAULT_COLUMNS } from "../Dashboard/DashboardGrid";
6
+
7
+ /**
8
+ * What a report's layout decides, and nothing else.
9
+ *
10
+ * A linear report and a grid draw the same page (header, filter row, cards,
11
+ * prose) through the same components; the layout only constrains how tiles
12
+ * are arranged on it. Every surface that arranges tiles (the reader's grid,
13
+ * the builder's grid, adding a tile) asks this one function rather than
14
+ * branching on the layout itself, so a new constraint is added here once and
15
+ * the two layouts cannot drift apart in how they look.
16
+ */
17
+ export interface LayoutRules {
18
+ layout: ReportLayout;
19
+ /** Columns the grid lays tiles across: one for linear, whatever it says, as the server reads it. */
20
+ columns: number;
21
+ /**
22
+ * Whether a tile has a width of its own: dragged at its edge, stepped with
23
+ * the arrow keys, written as `# colspan`. Off in one column, where every
24
+ * tile is the column's width and a width in the file is not the builder's
25
+ * to rewrite.
26
+ */
27
+ widths: boolean;
28
+ /**
29
+ * Whether tiles are added between others: a "+" under each tile and an
30
+ * "Add tile" after the last. A top-to-bottom report is written by
31
+ * inserting; a grid is arranged by dragging, so it adds at the end.
32
+ */
33
+ insertBetween: boolean;
34
+ }
35
+
36
+ export function layoutRules(
37
+ layout: ReportLayout | undefined,
38
+ /** `# dashboard { columns=N }` as the file has it. */
39
+ declaredColumns?: number,
40
+ ): LayoutRules {
41
+ if (layout === "linear")
42
+ return {
43
+ layout: "linear",
44
+ columns: 1,
45
+ widths: false,
46
+ insertBetween: true,
47
+ };
48
+ const columns = declaredColumns ?? DEFAULT_COLUMNS;
49
+ return {
50
+ layout: "grid",
51
+ columns,
52
+ widths: columns > 1,
53
+ insertBetween: false,
54
+ };
55
+ }
@@ -0,0 +1,53 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type { useServer } from "../ServerProvider";
5
+
6
+ /**
7
+ * The one read of a report's manifest, `GET …/reports/{path}`, shared by the
8
+ * reader and the builder so switching between them draws from one cache entry
9
+ * rather than reading the report again.
10
+ *
11
+ * `staleTime` is how long a read is reused without asking the server: 0 (every
12
+ * mount asks) unless a caller draws the same report twice in a row, as the
13
+ * builder does over the reader it keeps on screen while it loads. A write this
14
+ * app makes invalidates every `report` entry, but a change it did not make (a
15
+ * watch-mode save, another client's write, a package reload) is only seen by
16
+ * asking, so a standalone reader keeps 0.
17
+ */
18
+ export function reportQueryOptions(
19
+ apiClients: ReturnType<typeof useServer>["apiClients"],
20
+ {
21
+ environmentName,
22
+ packageName,
23
+ path,
24
+ versionId,
25
+ }: {
26
+ environmentName: string;
27
+ packageName: string;
28
+ path: string;
29
+ versionId: string | undefined;
30
+ },
31
+ /** Omitted, the query client's staleness for the `report` key decides. */
32
+ staleTime?: number,
33
+ ) {
34
+ return {
35
+ // Every value the request is built from, so two versions of one report
36
+ // never share a cache entry.
37
+ queryKey: ["report", environmentName, packageName, versionId, path],
38
+ queryFn: async ({ signal }: { signal?: AbortSignal }) =>
39
+ (
40
+ await apiClients.reports.getReport(
41
+ environmentName,
42
+ packageName,
43
+ path,
44
+ versionId,
45
+ { signal },
46
+ )
47
+ ).data,
48
+ ...(staleTime === undefined ? {} : { staleTime }),
49
+ };
50
+ }
51
+
52
+ /** How long the builder, and the reader drawn while it loads, reuse one read of the report. */
53
+ export const BUILDER_HANDOFF_STALE_MS = 10_000;
@@ -107,8 +107,6 @@ export type ReportEvent =
107
107
  tiles: number;
108
108
  /** Whether a tile was added or removed, which moves declarations. */
109
109
  structural: boolean;
110
- /** The save rewrote a report in the cell format as tiles. */
111
- converted?: boolean;
112
110
  where: SavesTo;
113
111
  /** The host workspace that took the write; never set for a package save. */
114
112
  workspace?: string;
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import { fireEvent, render, screen, within } from "@testing-library/react";
4
+ import { fireEvent, render, screen } from "@testing-library/react";
5
5
  import { describe, expect, it, mock } from "bun:test";
6
6
  import { AddTileDialog } from "./AddTileDialog";
7
7
  import { openDocument } from "./testing/fixtures";
@@ -32,57 +32,92 @@ const catalog = {
32
32
  ],
33
33
  };
34
34
 
35
+ const mount = async (
36
+ onAdd: (tile: unknown) => void = () => {},
37
+ onAddText: () => void = () => {},
38
+ ) =>
39
+ render(
40
+ <AddTileDialog
41
+ open
42
+ document={await openDocument(SOURCE)}
43
+ catalog={catalog}
44
+ columns={12}
45
+ onClose={() => {}}
46
+ onAdd={onAdd}
47
+ onAddText={onAddText}
48
+ />,
49
+ );
50
+
35
51
  describe("AddTileDialog", () => {
36
- it("opens on a source that has views and lists one without as disabled with its reason", async () => {
37
- const document = await openDocument(SOURCE);
38
- render(
39
- <AddTileDialog
40
- open
41
- document={document}
42
- catalog={catalog}
43
- columns={12}
44
- onClose={() => {}}
45
- onAdd={() => {}}
46
- onAddText={() => {}}
47
- />,
48
- );
49
- expect(screen.getByLabelText("View totals")).toBeDefined();
50
- fireEvent.mouseDown(
51
- screen.getByRole("combobox", { name: /Source/, hidden: true }),
52
- );
53
- const menu = screen.getAllByRole("listbox", { hidden: true }).at(-1)!;
54
- const options = within(menu).getAllByRole("option", { hidden: true });
55
- const empty = options.find((o) => o.textContent?.startsWith("empty"))!;
56
- expect(empty.getAttribute("aria-disabled")).toBe("true");
57
- expect(empty.textContent).toContain("declares no views");
58
- const stocked = options.find((o) =>
59
- o.textContent?.startsWith("stocked"),
60
- )!;
61
- expect(stocked.getAttribute("aria-disabled")).not.toBe("true");
52
+ it("opens on the first view, and names a source with no views rather than offering it", async () => {
53
+ await mount();
54
+ const option = screen.getByRole("option", { name: "Totals (totals)" });
55
+ expect(option.getAttribute("aria-selected")).toBe("true");
56
+ expect(screen.getByText(/with no views to show: empty/)).toBeDefined();
57
+ });
58
+
59
+ it("adds the picked view, with the title typed for it", async () => {
60
+ const onAdd = mock((_tile: unknown) => {});
61
+ await mount(onAdd);
62
+ fireEvent.change(screen.getByLabelText("Tile title"), {
63
+ target: { value: "All totals" },
64
+ });
65
+ fireEvent.click(screen.getByRole("button", { name: "Add tile" }));
66
+ expect(onAdd).toHaveBeenCalledTimes(1);
67
+ expect(onAdd.mock.calls[0]?.[0]).toMatchObject({
68
+ base: "stocked",
69
+ view: "totals",
70
+ label: "All totals",
71
+ });
72
+ });
73
+
74
+ it("searches, and Enter adds what the search left picked", async () => {
75
+ const onAdd = mock((_tile: unknown) => {});
76
+ await mount(onAdd);
77
+ const search = screen.getByRole("combobox", { name: "Search views" });
78
+ fireEvent.change(search, { target: { value: "nothing like it" } });
79
+ expect(screen.getByText(/No view matches/)).toBeDefined();
80
+ fireEvent.change(search, { target: { value: "tot" } });
81
+ fireEvent.keyDown(search, { key: "Enter" });
82
+ expect(onAdd).toHaveBeenCalledTimes(1);
62
83
  });
63
84
 
64
- it("adds a text tile without asking for a view", async () => {
65
- const document = await openDocument(SOURCE);
66
- const onAdd = mock(() => {});
85
+ it("adds a text tile instead, without a view", async () => {
86
+ const onAdd = mock((_tile: unknown) => {});
67
87
  const onAddText = mock(() => {});
88
+ await mount(onAdd, onAddText);
89
+ fireEvent.click(screen.getByRole("button", { name: "Add text instead" }));
90
+ expect(onAddText).toHaveBeenCalledTimes(1);
91
+ expect(onAdd).not.toHaveBeenCalled();
92
+ });
93
+
94
+ it("Enter takes the top match when a search hides the pick", async () => {
95
+ const onAdd = mock((_tile: unknown) => {});
68
96
  render(
69
97
  <AddTileDialog
70
98
  open
71
- document={document}
72
- catalog={catalog}
99
+ document={await openDocument(SOURCE)}
100
+ catalog={{
101
+ sources: [
102
+ {
103
+ name: "stocked",
104
+ modelPath: "m.malloy",
105
+ views: [{ name: "totals" }, { name: "by_brand" }],
106
+ givens: [],
107
+ fields: [],
108
+ },
109
+ ],
110
+ }}
73
111
  columns={12}
74
112
  onClose={() => {}}
75
113
  onAdd={onAdd}
76
- onAddText={onAddText}
114
+ onAddText={() => {}}
77
115
  />,
78
116
  );
79
- expect(screen.getByRole("button", { name: "Add tile" })).toHaveProperty(
80
- "disabled",
81
- true,
82
- );
83
- fireEvent.click(screen.getByRole("button", { name: "Text" }));
84
- fireEvent.click(screen.getByRole("button", { name: "Add text" }));
85
- expect(onAddText).toHaveBeenCalledTimes(1);
86
- expect(onAdd).not.toHaveBeenCalled();
117
+ // Opens on `totals`; the search hides it.
118
+ const search = screen.getByRole("combobox", { name: "Search views" });
119
+ fireEvent.change(search, { target: { value: "brand" } });
120
+ fireEvent.keyDown(search, { key: "Enter" });
121
+ expect(onAdd.mock.calls[0]?.[0]).toMatchObject({ view: "by_brand" });
87
122
  });
88
123
  });