@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
@@ -1,57 +1,39 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
+ // DEPRECATED FEATURE COVERAGE — delete together with
5
+ // `.malloynb` notebooks (see RELEASE_NOTES deprecations).
6
+
4
7
  /**
5
- * What a report written as `run:` cells shows when something fails: a cell
6
- * the server refuses says why in that cell and leaves the others running, and
7
- * cells that could not be read at all say so in place of the cells. Rendering
8
- * the happy path is `Report.spec`'s.
8
+ * What a `.malloynb` shows when something fails: a cell the server refuses
9
+ * says why in that cell and leaves the others running, and cells that could
10
+ * not be read at all say so in place of the cells.
9
11
  */
10
- import {
11
- afterEach,
12
- beforeEach,
13
- describe,
14
- expect,
15
- it,
16
- mock,
17
- spyOn,
18
- } from "bun:test";
12
+ import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test";
19
13
  import { render, screen, waitFor } from "@testing-library/react";
20
14
  import {
21
15
  clearCache,
22
16
  mockServerProvider,
23
17
  serverWrapper,
24
- } from "../../../test/serverProvider";
25
- import type { RawNotebook } from "../../client";
26
-
27
- let answer: (query: string) => Promise<unknown> = () =>
28
- Promise.resolve({ data: { result: undefined } });
29
- const executeQueryModel = mock(
30
- (
31
- _environmentName: string,
32
- _packageName: string,
33
- _modelPath: string,
34
- request: { query?: string },
35
- ) => answer(request.query ?? ""),
36
- );
37
-
38
- mockServerProvider({
39
- models: { executeQueryModel, getModel: () => new Promise(() => {}) },
40
- });
18
+ } from "../../../../test/serverProvider";
19
+ import type { RawNotebook } from "../../../client";
20
+ import type { CellRunner } from "./CellRunnerView";
21
+
22
+ // Cells run through the runner each test hands in, never the server.
23
+ mockServerProvider({ models: { getModel: () => new Promise(() => {}) } });
41
24
 
42
25
  // Imported after the stub is registered: a static import would hoist above it.
43
- const { CellReport, CellRunnerView } = await import("./CellReport");
26
+ const { CellRunnerView } = await import("./CellRunnerView");
44
27
 
45
- const URI = "publisher://environments/env/packages/pkg/models/review.malloy";
28
+ const URI = "publisher://environments/env/packages/pkg/models/review.malloynb";
46
29
 
47
- const cells = (...queries: string[]): RawNotebook =>
48
- ({
49
- format: "malloy",
50
- notebookCells: [
51
- { type: "markdown", kind: "markdown", text: "Intro prose" },
52
- ...queries.map((text) => ({ type: "code", kind: "query", text })),
53
- ],
54
- }) as RawNotebook;
30
+ const cells = (...queries: string[]): RawNotebook => ({
31
+ format: "malloynb",
32
+ notebookCells: [
33
+ { type: "markdown", text: "Intro prose" },
34
+ ...queries.map((text) => ({ type: "code" as const, text })),
35
+ ],
36
+ });
55
37
 
56
38
  /** A rejection shaped like axios's, carrying the server's `{message}`. */
57
39
  const refused = (message: string) =>
@@ -59,11 +41,20 @@ const refused = (message: string) =>
59
41
  response: { data: { message } },
60
42
  });
61
43
 
44
+ /** A runner that answers each cell's code with `answer`, and records the order it was asked in. */
45
+ function runner(answer: (code: string) => Promise<unknown>) {
46
+ const asked: number[] = [];
47
+ const runCell: CellRunner = ({ cell, index }) => {
48
+ asked.push(index);
49
+ return answer(cell.text ?? "") as ReturnType<CellRunner>;
50
+ };
51
+ return { asked, runCell };
52
+ }
53
+
62
54
  // A failed cell is logged as well as shown; the log is not under test.
63
55
  let quiet: { mockRestore(): void } | undefined;
64
56
  beforeEach(() => {
65
57
  clearCache();
66
- executeQueryModel.mockClear();
67
58
  quiet = spyOn(console, "error").mockImplementation(() => {});
68
59
  });
69
60
  afterEach(() => quiet?.mockRestore());
@@ -86,10 +77,15 @@ describe("a cell that fails", () => {
86
77
  "The server did not say why.",
87
78
  ],
88
79
  ])("says why with %s, in that cell", async (_name, error, shown) => {
89
- answer = () => Promise.reject(error);
90
- render(<CellReport resourceUri={URI} notebook={cells("run: a -> v")} />, {
91
- wrapper: serverWrapper,
92
- });
80
+ const { runCell } = runner(() => Promise.reject(error));
81
+ render(
82
+ <CellRunnerView
83
+ resourceUri={URI}
84
+ notebook={cells("run: a -> v")}
85
+ runCell={runCell}
86
+ />,
87
+ { wrapper: serverWrapper },
88
+ );
93
89
 
94
90
  expect(
95
91
  await screen.findByText("This cell could not be run."),
@@ -99,23 +95,23 @@ describe("a cell that fails", () => {
99
95
  });
100
96
 
101
97
  it("still runs and shows the other cells", async () => {
102
- answer = (query) =>
103
- query === "run: bad -> v"
98
+ const { asked, runCell } = runner((code) =>
99
+ code === "run: bad -> v"
104
100
  ? Promise.reject(refused("no such source"))
105
- : Promise.resolve({ data: { result: undefined } });
101
+ : Promise.resolve({}),
102
+ );
106
103
  render(
107
- <CellReport
104
+ <CellRunnerView
108
105
  resourceUri={URI}
109
106
  notebook={cells("run: bad -> v", "run: good -> v")}
107
+ runCell={runCell}
110
108
  />,
111
109
  { wrapper: serverWrapper },
112
110
  );
113
111
 
114
112
  expect(await screen.findByText("no such source")).toBeTruthy();
115
- expect(executeQueryModel.mock.calls.map((call) => call[3])).toEqual([
116
- expect.objectContaining({ query: "run: bad -> v" }),
117
- expect.objectContaining({ query: "run: good -> v" }),
118
- ]);
113
+ // The markdown cell is index 0 and never runs.
114
+ expect(asked).toEqual([1, 2]);
119
115
  expect(screen.getAllByText("This cell could not be run.")).toHaveLength(
120
116
  1,
121
117
  );
@@ -138,16 +134,16 @@ describe("cells that could not be read", () => {
138
134
  { wrapper: serverWrapper },
139
135
  );
140
136
 
141
- it("names the report that does not exist", () => {
137
+ it("names the notebook that does not exist", () => {
142
138
  view({ status: 404, message: "Not found" });
143
- expect(screen.getByText("env > pkg > review.malloy")).toBeTruthy();
139
+ expect(screen.getByText("env > pkg > review.malloynb")).toBeTruthy();
144
140
  expect(screen.getByText(/not found\./)).toBeTruthy();
145
141
  });
146
142
 
147
- it("shows any other failure with the report it was reading", async () => {
143
+ it("shows any other failure with the notebook it was reading", async () => {
148
144
  view({ status: 500, message: "The package did not load" });
149
145
  await waitFor(() =>
150
- expect(screen.getByText("env > pkg > review.malloy")).toBeTruthy(),
146
+ expect(screen.getByText("env > pkg > review.malloynb")).toBeTruthy(),
151
147
  );
152
148
  expect(screen.getByText("The package did not load")).toBeTruthy();
153
149
  expect(screen.queryByText(/not found\./)).toBeNull();
@@ -1,28 +1,42 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
+ /**
5
+ * @deprecated `.malloynb` only. The cell runner behind the deprecated
6
+ * `Notebook`: it runs a `.malloynb` notebook's code cells through the
7
+ * deprecated `…/notebooks/*` routes and draws them on the shared report page.
8
+ * Nothing outside `legacy/malloynb/` imports it (eslint enforces this), and it
9
+ * is deleted with the `.malloynb` format. A `.malloy` report is always tiles,
10
+ * drawn by `DashboardView`.
11
+ */
12
+
4
13
  import "@malloydata/malloy-explorer/styles.css";
5
- import { Stack, Typography } from "@mui/material";
14
+ import { Typography } from "@mui/material";
6
15
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
7
- import type { NotebookCell as RawCell, RawNotebook } from "../../client";
8
- import type { GivenValue } from "../../hooks/givenValue";
9
- import { useDocumentControls } from "../../hooks/useDocumentControls";
10
- import { useModelGivens } from "../../hooks/useModelGivens";
11
- import { GIVEN_SETTLE_MS } from "../../hooks/useSettled";
12
- import { parseResourceUri } from "../../utils/formatting";
13
- import { ApiErrorDisplay, type ApiError } from "../ApiErrorDisplay";
14
- import type { NavigationClick } from "../click_helper";
15
- import type { DrillNavigation } from "../drill";
16
- import { GivensPanel } from "../given";
17
- import { givensToParams, givensToRequest } from "../given/paramCodec";
18
- import { Loading, LOADING_COPY } from "../Loading";
19
- import { cellRuns } from "../Notebook/cellKind";
20
- import { NotebookCell } from "../Notebook/NotebookCell";
21
- import { planRun } from "../Notebook/runPlan";
22
- import type { EnhancedNotebookCell } from "../Notebook/types";
23
- import { useServer } from "../ServerProvider";
24
- import { failureCategory, useReportEvents } from "./telemetry";
25
- import { CleanNotebookContainer, CleanNotebookSection } from "../styles";
16
+ import type { NotebookCell as RawCell, RawNotebook } from "../../../client";
17
+ import type { GivenValue } from "../../../hooks/givenValue";
18
+ import { useDocumentControls } from "../../../hooks/useDocumentControls";
19
+ import { useModelGivens } from "../../../hooks/useModelGivens";
20
+ import { GIVEN_SETTLE_MS } from "../../../hooks/useSettled";
21
+ import { parseResourceUri } from "../../../utils/formatting";
22
+ import { ApiErrorDisplay, type ApiError } from "../../ApiErrorDisplay";
23
+ import type { NavigationClick } from "../../click_helper";
24
+ import type { DrillNavigation } from "../../drill";
25
+ import { GivensPanel } from "../../given";
26
+ import { givensToParams, givensToRequest } from "../../given/paramCodec";
27
+ import { Loading, LOADING_COPY } from "../../Loading";
28
+ import { cellRuns } from "./cellKind";
29
+ import { NotebookCell } from "./NotebookCell";
30
+ import { planRun } from "./runPlan";
31
+ import type { EnhancedNotebookCell } from "./types";
32
+ import { failureCategory, useReportEvents } from "../../Report/telemetry";
33
+ import { Prose } from "../../Prose";
34
+ import {
35
+ ReportHeader,
36
+ ReportPage,
37
+ StickyControls,
38
+ TextTileFrame,
39
+ } from "../../Report/ReportPage";
26
40
 
27
41
  // Maximum number of concurrent cell executions to avoid overwhelming the server
28
42
  const MAX_CONCURRENT = 4;
@@ -61,6 +75,9 @@ export type CellRunner = (
61
75
  export interface CellReportProps {
62
76
  /** `publisher://…/models/<path>`: the report, and the model its cells run against. */
63
77
  resourceUri: string;
78
+ /** The report's title and description, drawn in the header every report has. */
79
+ title?: string;
80
+ description?: string;
64
81
  maxResultSize?: number;
65
82
  /**
66
83
  * Parameter values from the host, typically its URL query parameters: the
@@ -117,6 +134,8 @@ export interface CellReportProps {
117
134
  */
118
135
  export function CellRunnerView({
119
136
  resourceUri,
137
+ title,
138
+ description,
120
139
  maxResultSize = 0,
121
140
  givens,
122
141
  onGivensChange,
@@ -465,123 +484,90 @@ export function CellRunnerView({
465
484
 
466
485
  const shownCells =
467
486
  enhancedCells.length > 0 ? enhancedCells : notebook?.notebookCells || [];
468
- // A served report can open with definition cells; a .malloynb keeps the icon on its first cell.
469
- const copyLinkIndex =
470
- notebook?.format === "malloy"
471
- ? shownCells.findIndex((cell) => cell.type === "markdown")
472
- : 0;
487
+ // A .malloynb keeps the copy-link icon on its first cell.
488
+ const copyLinkIndex = 0;
473
489
 
474
490
  return (
475
- <CleanNotebookContainer>
476
- <CleanNotebookSection>
477
- <Stack spacing={3} component="section">
478
- {/* Parameters panel: the controls for `given:` declarations */}
479
- <GivensPanel {...controls.panel} />
480
-
481
- {!isSuccess && !isError && (
482
- <Loading text={LOADING_COPY.opening("report")} />
483
- )}
484
-
485
- {isSuccess &&
486
- shownCells.map((cell, index) => (
487
- <NotebookCell
488
- cell={cell as EnhancedNotebookCell}
489
- key={index}
490
- showCopyLink={index === copyLinkIndex}
491
- resourceUri={resourceUri}
492
- maxResultSize={maxResultSize}
493
- isExecuting={isExecuting}
494
- givens={cellStartingGivens}
495
- givenSpecs={declaredGivens}
496
- // Distinct from `isExecuting`: the cell's spinner is
497
- // gated on `!cell.result`, so feeding this through it
498
- // showed nothing on a re-run, which is the only case
499
- // the settle window has to signal.
500
- pendingRerun={runScheduled}
501
- onNavigate={onNavigate}
502
- onDrillNavigate={onDrillNavigate}
503
- onDrillSelf={
504
- declaredGivens.length > 0 ? onDrillSelf : undefined
505
- }
506
- canDrillSelf={canDrillSelf}
507
- />
508
- ))}
509
-
510
- {isError && error?.status === 404 && (
511
- <Typography variant="body2" sx={{ color: "text.secondary" }}>
512
- <code>{`${environmentName} > ${packageName} > ${notebookPath}`}</code>{" "}
513
- not found.
514
- </Typography>
515
- )}
516
-
517
- {isError && error?.status !== 404 && (
518
- <ApiErrorDisplay
519
- error={error as ApiError}
520
- context={`${environmentName} > ${packageName} > ${notebookPath}`}
521
- />
522
- )}
523
-
524
- {executionError && (
525
- <ApiErrorDisplay
526
- error={{
527
- message: executionError.message,
528
- status: 500,
529
- name: "ExecutionError",
530
- }}
531
- context="Notebook Execution"
532
- />
533
- )}
534
- </Stack>
535
- </CleanNotebookSection>
536
- </CleanNotebookContainer>
537
- );
538
- }
539
-
540
- /**
541
- * A `.malloy` report written as `run:` cells, whose cells the caller already
542
- * holds (`Report` reads them off `GET …/reports/{path}`). Each runs through
543
- * the governed query endpoint the grid tiles use
544
- * (`POST …/models/{path}/query`, the report's path as the model and the cell's
545
- * text as the query), which holds a cell to the same surface, `#(authorize)`
546
- * and row-level gates a tile is held to.
547
- */
548
- export function CellReport({
549
- notebook: held,
550
- ...props
551
- }: CellReportProps & { notebook: RawNotebook }) {
552
- const { apiClients } = useServer();
553
- const { environmentName, packageName, versionId, modelPath } =
554
- parseResourceUri(props.resourceUri);
555
- // Handed over from the first render after mount, not on it, so the
556
- // controls see the document ARRIVE as they do when it is fetched: that
557
- // arrival is what reports the file's starting values to the host's URL
558
- // (`useGivensState` seeds its record from the first render).
559
- const [mounted, setMounted] = useState(false);
560
- useEffect(() => setMounted(true), []);
561
- const runCell = useCallback<CellRunner>(
562
- async ({ cell, givens, declaredTypes, signal }) => ({
563
- result: (
564
- await apiClients.models.executeQueryModel(
565
- environmentName,
566
- packageName,
567
- modelPath,
568
- {
569
- query: cell.text,
570
- givens: givensToRequest(givens, declaredTypes),
571
- versionId,
572
- },
573
- undefined,
574
- { signal },
575
- )
576
- ).data.result,
577
- }),
578
- [apiClients.models, environmentName, packageName, modelPath, versionId],
579
- );
580
- return (
581
- <CellRunnerView
582
- {...props}
583
- notebook={mounted ? held : undefined}
584
- runCell={runCell}
585
- />
491
+ // The page every report draws, whatever its format: the header, the
492
+ // pinned row of filter buttons, then the cells as prose and tiles.
493
+ <ReportPage
494
+ // Cells read top to bottom, so a report of cells is linear.
495
+ layout="linear"
496
+ header={
497
+ title || description ? (
498
+ <ReportHeader
499
+ title={title ?? ""}
500
+ description={
501
+ description ? (
502
+ <TextTileFrame>
503
+ <Prose variant="document">{description}</Prose>
504
+ </TextTileFrame>
505
+ ) : undefined
506
+ }
507
+ />
508
+ ) : null
509
+ }
510
+ controls={
511
+ controls.panel.givens.length > 0 ? (
512
+ <StickyControls>
513
+ <GivensPanel {...controls.panel} layout="bar" />
514
+ </StickyControls>
515
+ ) : undefined
516
+ }
517
+ >
518
+ {!isSuccess && !isError && (
519
+ <Loading text={LOADING_COPY.opening("report")} />
520
+ )}
521
+
522
+ {isSuccess &&
523
+ shownCells.map((cell, index) => (
524
+ <NotebookCell
525
+ cell={cell as EnhancedNotebookCell}
526
+ key={index}
527
+ showCopyLink={index === copyLinkIndex}
528
+ resourceUri={resourceUri}
529
+ maxResultSize={maxResultSize}
530
+ isExecuting={isExecuting}
531
+ givens={cellStartingGivens}
532
+ givenSpecs={declaredGivens}
533
+ // Distinct from `isExecuting`: the cell's spinner is
534
+ // gated on `!cell.result`, so feeding this through it
535
+ // showed nothing on a re-run, which is the only case
536
+ // the settle window has to signal.
537
+ pendingRerun={runScheduled}
538
+ onNavigate={onNavigate}
539
+ onDrillNavigate={onDrillNavigate}
540
+ onDrillSelf={
541
+ declaredGivens.length > 0 ? onDrillSelf : undefined
542
+ }
543
+ canDrillSelf={canDrillSelf}
544
+ />
545
+ ))}
546
+
547
+ {isError && error?.status === 404 && (
548
+ <Typography variant="body2" sx={{ color: "text.secondary" }}>
549
+ <code>{`${environmentName} > ${packageName} > ${notebookPath}`}</code>{" "}
550
+ not found.
551
+ </Typography>
552
+ )}
553
+
554
+ {isError && error?.status !== 404 && (
555
+ <ApiErrorDisplay
556
+ error={error as ApiError}
557
+ context={`${environmentName} > ${packageName} > ${notebookPath}`}
558
+ />
559
+ )}
560
+
561
+ {executionError && (
562
+ <ApiErrorDisplay
563
+ error={{
564
+ message: executionError.message,
565
+ status: 500,
566
+ name: "ExecutionError",
567
+ }}
568
+ context="Notebook Execution"
569
+ />
570
+ )}
571
+ </ReportPage>
586
572
  );
587
573
  }
@@ -2,16 +2,16 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { useCallback } from "react";
5
- import type { RawNotebook } from "../../client";
6
- import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
7
- import { parseResourceUri } from "../../utils/formatting";
8
- import { givensToRequest } from "../given/paramCodec";
5
+ import type { RawNotebook } from "../../../client";
6
+ import { useQueryWithApiError } from "../../../hooks/useQueryWithApiError";
7
+ import { parseResourceUri } from "../../../utils/formatting";
8
+ import { givensToRequest } from "../../given/paramCodec";
9
9
  import {
10
10
  CellRunnerView,
11
11
  type CellReportProps,
12
12
  type CellRunner,
13
- } from "../Report/CellReport";
14
- import { useServer } from "../ServerProvider";
13
+ } from "./CellRunnerView";
14
+ import { useServer } from "../../ServerProvider";
15
15
 
16
16
  /** The deprecated notebook read, one cache entry per URI however many components ask. */
17
17
  export function useNotebookQuery(resourceUri: string) {
@@ -8,8 +8,8 @@ import {
8
8
  mockServerProvider,
9
9
  pending,
10
10
  serverWrapper,
11
- } from "../../../test/serverProvider";
12
- import type { RawNotebook } from "../../client";
11
+ } from "../../../../test/serverProvider";
12
+ import type { RawNotebook } from "../../../client";
13
13
 
14
14
  const LAYOUT = {
15
15
  format: "malloy",
@@ -56,14 +56,22 @@ beforeEach(() => {
56
56
  executeQueryModel.mockClear();
57
57
  });
58
58
 
59
- it("renders a layout notebook as a bare dashboard grid", async () => {
59
+ it("renders a layout notebook as a grid report draws its tiles", async () => {
60
60
  const { container } = render(
61
61
  <Notebook resourceUri="publisher://environments/env/packages/pkg/models/notebooks/tour.malloy" />,
62
62
  { wrapper: serverWrapper },
63
63
  );
64
64
 
65
65
  expect((await screen.findByText("intro")).tagName).toBe("STRONG");
66
- expect(container.querySelector('[data-chrome="card"]')).toBeNull();
66
+ // Text as prose, a query tile in a card: the same look as a grid.
67
+ expect(
68
+ (await screen.findByText("intro"))
69
+ .closest("[data-chrome]")
70
+ ?.getAttribute("data-chrome"),
71
+ ).toBe("none");
72
+ await waitFor(() =>
73
+ expect(container.querySelector('[data-chrome="card"]')).not.toBeNull(),
74
+ );
67
75
  // Tiles run through the model query endpoint, not the cell endpoint.
68
76
  await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
69
77
  expect(executeQueryModel.mock.calls[0]?.[2]).toBe("notebooks/tour.malloy");
@@ -79,16 +87,17 @@ it("shows a layout notebook's title and description above its tiles", async () =
79
87
 
80
88
  expect(
81
89
  (await screen.findByRole("heading", { name: "Tour title" })).tagName,
82
- ).toBe("H5");
90
+ // The page's main heading: the report title is the page.
91
+ ).toBe("H1");
83
92
  expect((await screen.findByText("description")).tagName).toBe("STRONG");
84
93
  });
85
94
 
86
- it("draws no header for a layout notebook with no title or description", async () => {
95
+ it("titles an untitled layout notebook with its name, as a grid report does", async () => {
87
96
  render(
88
97
  <Notebook resourceUri="publisher://environments/env/packages/pkg/models/notebooks/tour.malloy" />,
89
98
  { wrapper: serverWrapper },
90
99
  );
91
100
 
92
101
  await screen.findByText("intro");
93
- expect(screen.queryByRole("heading", { name: "tour" })).toBeNull();
102
+ expect(screen.getByRole("heading", { name: "tour" })).toBeDefined();
94
103
  });
@@ -0,0 +1,84 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { beforeEach, describe, expect, it, mock } from "bun:test";
5
+ import { render, screen, waitFor } from "@testing-library/react";
6
+ import {
7
+ clearCache,
8
+ mockServerProvider,
9
+ pending,
10
+ serverWrapper,
11
+ } from "../../../../test/serverProvider";
12
+ import type { RawNotebook } from "../../../client";
13
+
14
+ const SERVED = {
15
+ format: "malloynb",
16
+ notebookCells: [
17
+ { type: "markdown", text: "Served prose" },
18
+ { type: "code", text: 'import { orders } from "../orders.malloy"' },
19
+ { type: "code", text: "run: orders -> by_month" },
20
+ ],
21
+ } as RawNotebook;
22
+
23
+ let current: RawNotebook = SERVED;
24
+ const getNotebook = mock(() => Promise.resolve({ data: current }));
25
+ const executeNotebookCell = mock(
26
+ (
27
+ _env: string,
28
+ _pkg: string,
29
+ _path: string,
30
+ _index: number,
31
+ ): Promise<never> => pending(),
32
+ );
33
+
34
+ mockServerProvider({
35
+ notebooks: { getNotebook, executeNotebookCell },
36
+ models: { executeQueryModel: () => pending() },
37
+ });
38
+
39
+ const { default: Notebook } = await import("./Notebook");
40
+
41
+ const URI =
42
+ "publisher://environments/env/packages/pkg/models/notebooks/ops.malloynb";
43
+
44
+ beforeEach(() => {
45
+ current = SERVED;
46
+ clearCache();
47
+ getNotebook.mockClear();
48
+ executeNotebookCell.mockClear();
49
+ });
50
+
51
+ it("runs every code cell of a .malloynb", async () => {
52
+ render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
53
+
54
+ await waitFor(() =>
55
+ expect(executeNotebookCell.mock.calls.map((call) => call[3])).toEqual([
56
+ 1, 2,
57
+ ]),
58
+ );
59
+ });
60
+
61
+ it("puts the copy-link icon on a leading markdown cell", async () => {
62
+ render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
63
+
64
+ await screen.findByText("Served prose");
65
+ expect(screen.getAllByTestId("LinkOutlinedIcon")).toHaveLength(1);
66
+ });
67
+
68
+ // DEPRECATED FEATURE COVERAGE — delete together with
69
+ // `.malloynb` notebooks (see RELEASE_NOTES deprecations).
70
+ describe("deprecated: .malloynb notebooks", () => {
71
+ it("keeps the copy-link icon off a .malloynb that opens with a code cell", async () => {
72
+ current = {
73
+ format: "malloynb",
74
+ notebookCells: [
75
+ { type: "code", text: "import { orders } from '../orders.malloy'" },
76
+ { type: "markdown", text: "Legacy prose" },
77
+ ],
78
+ } as RawNotebook;
79
+ render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
80
+
81
+ await screen.findByText("Legacy prose");
82
+ expect(screen.queryAllByTestId("LinkOutlinedIcon")).toHaveLength(0);
83
+ });
84
+ });
@@ -19,8 +19,8 @@ import {
19
19
  mockServerProvider,
20
20
  pending,
21
21
  serverWrapper,
22
- } from "../../../test/serverProvider";
23
- import type { RawNotebook } from "../../client";
22
+ } from "../../../../test/serverProvider";
23
+ import type { RawNotebook } from "../../../client";
24
24
 
25
25
  const NOTEBOOK: RawNotebook = {
26
26
  notebookCells: [
@@ -91,7 +91,7 @@ const dataSourcesDialogProps = mock(
91
91
  data?: { givens?: { name?: string }[] };
92
92
  }) => {},
93
93
  );
94
- mock.module("../Model/ModelExplorerDialog", () => ({
94
+ mock.module("../../Model/ModelExplorerDialog", () => ({
95
95
  ModelExplorerDialog: (props: {
96
96
  open: boolean;
97
97
  startingGivens?: Record<string, string>;
@@ -141,6 +141,8 @@ it("sends none when the notebook was opened without one", async () => {
141
141
  it("opens a cell's 'Data sources' dialog with the notebook's current values", async () => {
142
142
  render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
143
143
 
144
+ // The control sits in its filter button's popover.
145
+ fireEvent.click(await screen.findByRole("button", { name: /^TENANT: / }));
144
146
  const input = (await screen.findByLabelText("TENANT")) as HTMLInputElement;
145
147
  fireEvent.change(input, { target: { value: "acme" } });
146
148
  // Wait for the control's own re-render before opening the dialog: without