@malloy-publisher/sdk 0.9.10 → 0.9.12

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 (263) hide show
  1. package/dist/{RenderedResult-Dp1Qdajz.es.js → RenderedResult-CDiXJAh9.es.js} +102 -102
  2. package/dist/RenderedResult-De51QvsZ.cjs.js +153 -0
  3. package/dist/ServerProvider-DKrBcXL7.cjs.js +1 -0
  4. package/dist/{ServerProvider-CQy4jVYK.es.js → ServerProvider-RvKSbvnL.es.js} +622 -587
  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 +72 -23
  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/Connections/common.d.ts +11 -3
  13. package/dist/components/Dashboard/DashboardGrid.d.ts +14 -15
  14. package/dist/components/Dashboard/DashboardTile.d.ts +8 -1
  15. package/dist/components/Dashboard/DashboardView.d.ts +22 -34
  16. package/dist/components/Dashboard/TileCard.d.ts +10 -3
  17. package/dist/components/Dashboard/useStuck.d.ts +15 -7
  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 -8
  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 +12 -9
  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 +8418 -7722
  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-BMPDvdFx.es.js → useCompiledDocument-Bf4RSfB6.es.js} +8669 -7851
  92. package/dist/useCompiledDocument-XsQz85Ri.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/Connections/AddConnectionDialog.tsx +34 -2
  97. package/src/components/Connections/EditConnectionDialog.tsx +45 -3
  98. package/src/components/Connections/common.spec.ts +69 -0
  99. package/src/components/Connections/common.ts +132 -0
  100. package/src/components/Dashboard/DashboardGrid.tsx +39 -17
  101. package/src/components/Dashboard/DashboardTile.tsx +19 -2
  102. package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
  103. package/src/components/Dashboard/DashboardView.tsx +137 -155
  104. package/src/components/Dashboard/RowsDialog.tsx +1 -2
  105. package/src/components/Dashboard/TileCard.tsx +28 -10
  106. package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
  107. package/src/components/Dashboard/useStuck.ts +28 -17
  108. package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
  109. package/src/components/Environment/Connections.tsx +1 -0
  110. package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
  111. package/src/components/Package/NewDocumentDialog.tsx +383 -119
  112. package/src/components/Package/Package.artifacts.spec.tsx +1 -1
  113. package/src/components/Package/Package.create.spec.tsx +7 -6
  114. package/src/components/Package/Package.tsx +10 -7
  115. package/src/components/Package/PackageProblems.spec.tsx +41 -0
  116. package/src/components/Package/PackageProblems.tsx +95 -0
  117. package/src/components/Prose.tsx +12 -7
  118. package/src/components/RemoveBadge.tsx +94 -0
  119. package/src/components/RenderedResult/RenderedResult.tsx +5 -9
  120. package/src/components/RenderedResult/ResultPanel.tsx +59 -3
  121. package/src/components/Report/Report.spec.tsx +50 -32
  122. package/src/components/Report/Report.telemetry.spec.tsx +0 -45
  123. package/src/components/Report/Report.tsx +45 -77
  124. package/src/components/Report/ReportPage.tsx +168 -0
  125. package/src/components/Report/layoutRules.spec.ts +35 -0
  126. package/src/components/Report/layoutRules.ts +55 -0
  127. package/src/components/Report/reportQuery.ts +53 -0
  128. package/src/components/Report/telemetry.ts +0 -2
  129. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
  130. package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
  131. package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
  132. package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -39
  133. package/src/components/ReportBuilder/BuilderGrid.tsx +31 -29
  134. package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
  135. package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
  136. package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
  137. package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
  138. package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
  139. package/src/components/ReportBuilder/FilterStrip.tsx +130 -151
  140. package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
  141. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
  142. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
  143. package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
  144. package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -15
  145. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
  146. package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
  147. package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
  148. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +37 -31
  149. package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
  150. package/src/components/ReportBuilder/ReportBuilder.tsx +292 -117
  151. package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
  152. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
  153. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
  154. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
  155. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
  156. package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
  157. package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
  158. package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
  159. package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
  160. package/src/components/ReportBuilder/TileFrame.tsx +212 -75
  161. package/src/components/ReportBuilder/TileMenu.tsx +241 -140
  162. package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
  163. package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
  164. package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
  165. package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
  166. package/src/components/ReportBuilder/builderControls.ts +164 -0
  167. package/src/components/ReportBuilder/builderReport.ts +1 -2
  168. package/src/components/ReportBuilder/catalog.ts +10 -26
  169. package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
  170. package/src/components/ReportBuilder/localGiven.ts +56 -0
  171. package/src/components/ReportBuilder/preview.spec.ts +125 -5
  172. package/src/components/ReportBuilder/preview.ts +60 -44
  173. package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
  174. package/src/components/ReportBuilder/readDocument.ts +14 -11
  175. package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
  176. package/src/components/ReportBuilder/readForEditor.ts +4 -26
  177. package/src/components/ReportBuilder/reportTag.ts +28 -7
  178. package/src/components/ReportBuilder/sortable.tsx +15 -7
  179. package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
  180. package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
  181. package/src/components/ReportBuilder/testing/inline.ts +25 -5
  182. package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
  183. package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
  184. package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
  185. package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
  186. package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
  187. package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
  188. package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
  189. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
  190. package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
  191. package/src/components/ReportBuilder/useExitGuard.ts +16 -0
  192. package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
  193. package/src/components/ReportBuilder/useFilterForm.ts +5 -1
  194. package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
  195. package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
  196. package/src/components/ReportBuilder/useReportDraft.ts +292 -0
  197. package/src/components/ReportBuilder/useReportEditor.ts +3 -12
  198. package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
  199. package/src/components/ReportBuilder/useTileEditing.ts +43 -12
  200. package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
  201. package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
  202. package/src/components/ReportBuilder/widthLabel.ts +26 -0
  203. package/src/components/ServerProvider.tsx +11 -0
  204. package/src/components/controlTokens.ts +47 -0
  205. package/src/components/drill/markDrillableCells.ts +2 -1
  206. package/src/components/given/FilterButton.spec.tsx +143 -0
  207. package/src/components/given/FilterButton.tsx +478 -0
  208. package/src/components/given/GivenInput.spec.tsx +47 -0
  209. package/src/components/given/GivenInput.tsx +20 -2
  210. package/src/components/given/GivensPanel.spec.tsx +11 -3
  211. package/src/components/given/GivensPanel.tsx +45 -44
  212. package/src/components/given/filterEditing.ts +60 -0
  213. package/src/components/given/filterSummary.spec.ts +108 -0
  214. package/src/components/given/filterSummary.ts +109 -0
  215. package/src/components/given/paramCodec.ts +1 -1
  216. package/src/components/given/required.spec.ts +60 -0
  217. package/src/components/given/required.ts +78 -0
  218. package/src/components/index.ts +9 -0
  219. package/src/components/legacy/Dashboard.spec.tsx +3 -1
  220. package/src/components/legacy/index.ts +1 -1
  221. package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
  222. package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
  223. package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
  224. package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
  225. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
  226. package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
  227. package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
  228. package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
  229. package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
  230. package/src/components/legacy/malloynb/cellKind.ts +24 -0
  231. package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
  232. package/src/components/styles.ts +0 -18
  233. package/src/hooks/useGivensState.ts +7 -3
  234. package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
  235. package/src/hooks/useQueryResult.ts +26 -1
  236. package/src/theme/ThemeContext.tsx +21 -1
  237. package/src/theme/classes.ts +52 -0
  238. package/src/theme/index.ts +8 -0
  239. package/src/theme/resolveTheme.ts +3 -0
  240. package/src/theme/types.ts +7 -0
  241. package/src/theme/ui.spec.tsx +91 -0
  242. package/src/theme/ui.ts +115 -0
  243. package/dist/RenderedResult-BcgYjkZ0.cjs.js +0 -153
  244. package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
  245. package/dist/components/Notebook/cellKind.d.ts +0 -20
  246. package/dist/components/Report/LinearReport.d.ts +0 -18
  247. package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
  248. package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
  249. package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
  250. package/dist/useCompiledDocument-UY28ITET.cjs.js +0 -141
  251. package/src/components/Notebook/cellKind.spec.ts +0 -199
  252. package/src/components/Notebook/cellKind.ts +0 -74
  253. package/src/components/Report/LinearReport.tsx +0 -71
  254. package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
  255. package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
  256. package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
  257. package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
  258. package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
  259. package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
  260. package/src/components/legacy/Notebook.served.spec.tsx +0 -183
  261. /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
  262. /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
  263. /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
@@ -0,0 +1,312 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * A filter a tile reads through the model (the source's own `where:`) shows in
6
+ * the builder's row as it does in the reader's, settable, but not removable or
7
+ * configured: the builder never edits the model.
8
+ */
9
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
10
+ import { beforeEach, describe, expect, it, mock } from "bun:test";
11
+ import type { DashboardManifest } from "../../client";
12
+ import {
13
+ clearCache,
14
+ mockServerProvider,
15
+ pending,
16
+ serverWrapper,
17
+ } from "../../../test/serverProvider";
18
+
19
+ let packageFile = "";
20
+ let served: Partial<DashboardManifest> = {};
21
+
22
+ const MANUFACTURER = {
23
+ name: "manufacturer_filter",
24
+ label: "Manufacturer",
25
+ type: "filter<string>",
26
+ };
27
+ const SUBJECT = {
28
+ name: "subject_filter",
29
+ label: "Subject",
30
+ type: "filter<string>",
31
+ };
32
+ const SINCE = { name: "SINCE", label: "Since", type: "date" };
33
+
34
+ const executeQueryModel = mock(
35
+ (_env: string, _pkg: string, _path: string, _body: { query?: string }) =>
36
+ pending(),
37
+ );
38
+ const getModel = mock((_env: string, _pkg: string, path: string) =>
39
+ Promise.resolve({
40
+ data:
41
+ path === "README.malloy"
42
+ ? { path, sourceText: packageFile }
43
+ : path === "reports/recalls.malloy"
44
+ ? { path, sourceText: packageFile }
45
+ : { path, sources: [], sourceInfos: [] },
46
+ }),
47
+ );
48
+ const getReport = mock(() =>
49
+ Promise.resolve({ data: { path: "README.malloy", tiles: [], ...served } }),
50
+ );
51
+ mockServerProvider(
52
+ {
53
+ models: {
54
+ getModel,
55
+ executeQueryModel,
56
+ listModels: mock(() => Promise.resolve({ data: [] })),
57
+ },
58
+ reports: {
59
+ getReport,
60
+ listReports: mock(() => Promise.resolve({ data: [] })),
61
+ },
62
+ },
63
+ { mutable: true },
64
+ );
65
+
66
+ const { ReportEditor } = await import("./ReportEditor");
67
+
68
+ beforeEach(() => {
69
+ clearCache();
70
+ executeQueryModel.mockClear();
71
+ });
72
+
73
+ const open = (
74
+ extra: { onOpenModel?: (modelPath: string) => void } = {},
75
+ path = "README.malloy",
76
+ ) =>
77
+ render(
78
+ <ReportEditor
79
+ resourceUri="publisher://environments/env/packages/pkg"
80
+ path={path}
81
+ {...extra}
82
+ />,
83
+ { wrapper: serverWrapper },
84
+ );
85
+
86
+ /** The filter buttons in the row, by their names as a reader hears them. */
87
+ const row = async () =>
88
+ (
89
+ await screen.findAllByRole("button", {
90
+ name: /^(Manufacturer|Subject|Since): /,
91
+ })
92
+ ).map((button) => button.getAttribute("aria-label")?.split(":")[0]);
93
+
94
+ describe("filters read through the model", () => {
95
+ it("are in the builder's row as in the reader's, with no remove and no settings", async () => {
96
+ packageFile = `## artifact { title="Recalls" tiles=["recalls_tiles -> by_year", "recalls_tiles -> by_maker"] } dashboard { columns=12 }
97
+ import "auto_recalls.malloy"
98
+
99
+ source: recalls_tiles is recalls extend {
100
+ view: by_year is by_year_view
101
+ view: by_maker is by_maker_view
102
+ }`;
103
+ served = {
104
+ givens: [MANUFACTURER, SUBJECT],
105
+ tiles: [
106
+ {
107
+ kind: "query",
108
+ query: "recalls_tiles -> by_year",
109
+ givenNames: ["manufacturer_filter"],
110
+ },
111
+ {
112
+ kind: "query",
113
+ query: "recalls_tiles -> by_maker",
114
+ givenNames: ["manufacturer_filter", "subject_filter"],
115
+ },
116
+ ],
117
+ };
118
+ open();
119
+ expect(await row()).toEqual(["Manufacturer", "Subject"]);
120
+ expect(
121
+ screen.queryByRole("button", {
122
+ name: "Remove filter manufacturer_filter",
123
+ }),
124
+ ).toBeNull();
125
+
126
+ fireEvent.click(screen.getByRole("button", { name: /^Manufacturer: / }));
127
+ const popover = await screen.findByRole("dialog", {
128
+ name: "Manufacturer filter",
129
+ });
130
+ expect(popover.textContent).toContain(
131
+ "Set in the model auto_recalls.malloy. Edit the model to change it.",
132
+ );
133
+ expect(
134
+ screen.queryByRole("button", {
135
+ name: "Edit filter manufacturer_filter",
136
+ }),
137
+ ).toBeNull();
138
+ });
139
+
140
+ it("come after this file's own bound filters, which stay removable", async () => {
141
+ packageFile = `## artifact { title="Recalls" tiles=["recalls_tiles -> by_year"] } dashboard { columns=12 }
142
+ import "auto_recalls.malloy"
143
+
144
+ #(control) label="Since"
145
+ given: SINCE :: date is @2020-01-01
146
+
147
+ source: recalls_tiles is recalls extend {
148
+ view: by_year is by_year_view + { where: recall_date >= $SINCE }
149
+ }`;
150
+ served = {
151
+ givens: [SINCE, MANUFACTURER],
152
+ tiles: [
153
+ {
154
+ kind: "query",
155
+ query: "recalls_tiles -> by_year",
156
+ givenNames: ["SINCE", "manufacturer_filter"],
157
+ },
158
+ ],
159
+ };
160
+ open();
161
+ expect(await row()).toEqual(["Since", "Manufacturer"]);
162
+ expect(
163
+ screen.getByRole("button", { name: "Remove filter SINCE" }),
164
+ ).toBeTruthy();
165
+ expect(
166
+ screen.queryByRole("button", {
167
+ name: "Remove filter manufacturer_filter",
168
+ }),
169
+ ).toBeNull();
170
+ });
171
+
172
+ it("says a filter this report's own source applies is the file's, not the model's", async () => {
173
+ packageFile = `## artifact { title="Recalls" tiles=["recalls_tiles -> by_year"] } dashboard { columns=12 }
174
+ import "auto_recalls.malloy"
175
+
176
+ #(control) label="Since"
177
+ given: SINCE :: date is @2020-01-01
178
+
179
+ source: recalls_tiles is recalls extend {
180
+ where: recall_date >= $SINCE
181
+ view: by_year is by_year_view
182
+ }`;
183
+ served = {
184
+ givens: [SINCE],
185
+ tiles: [
186
+ {
187
+ kind: "query",
188
+ query: "recalls_tiles -> by_year",
189
+ givenNames: ["SINCE"],
190
+ },
191
+ ],
192
+ };
193
+ open();
194
+ expect(await row()).toEqual(["Since"]);
195
+ fireEvent.click(screen.getByRole("button", { name: /^Since: / }));
196
+ const popover = await screen.findByRole("dialog", {
197
+ name: "Since filter",
198
+ });
199
+ expect(popover.textContent).not.toContain("Set in the model");
200
+ expect(popover.textContent).toContain("recalls_tiles");
201
+ });
202
+ });
203
+
204
+ describe("what a report says about a filter it cannot change", () => {
205
+ const RECALLS = `## artifact { title="Recalls" tiles=["recalls_tiles -> by_year"] } dashboard { columns=12 }
206
+ import "auto_recalls.malloy"
207
+
208
+ source: recalls_tiles is recalls extend {
209
+ view: by_year is by_year_view
210
+ }`;
211
+ const READS_MANUFACTURER = {
212
+ givens: [MANUFACTURER],
213
+ startingGivens: { manufacturer_filter: "Ford" },
214
+ tiles: [
215
+ {
216
+ kind: "query" as const,
217
+ query: "recalls_tiles -> by_year",
218
+ givenNames: ["manufacturer_filter"],
219
+ },
220
+ ],
221
+ };
222
+
223
+ it("can open the report with the model filter's current value", async () => {
224
+ packageFile = RECALLS;
225
+ served = READS_MANUFACTURER;
226
+ open();
227
+ fireEvent.click(
228
+ await screen.findByRole("button", { name: /^Manufacturer: / }),
229
+ );
230
+ fireEvent.click(
231
+ await screen.findByRole("button", {
232
+ name: "Open the report with this value",
233
+ }),
234
+ );
235
+ // The report now holds it: the popover says so, and Undo takes it back.
236
+ expect(
237
+ await screen.findByText("The report opens with this value."),
238
+ ).toBeDefined();
239
+ expect(
240
+ (
241
+ screen.getByRole("button", {
242
+ name: "Undo",
243
+ hidden: true,
244
+ }) as HTMLButtonElement
245
+ ).disabled,
246
+ ).toBe(false);
247
+ });
248
+
249
+ it("opens the model by its package path, from a report in a folder", async () => {
250
+ packageFile = RECALLS.replace(
251
+ 'import "auto_recalls.malloy"',
252
+ 'import "../auto_recalls.malloy"',
253
+ );
254
+ served = READS_MANUFACTURER;
255
+ const onOpenModel = mock((_path: string) => {});
256
+ open({ onOpenModel }, "reports/recalls.malloy");
257
+ fireEvent.click(
258
+ await screen.findByRole("button", { name: /^Manufacturer: / }),
259
+ );
260
+ fireEvent.click(
261
+ await screen.findByRole("button", { name: "Open the model" }),
262
+ );
263
+ expect(onOpenModel).toHaveBeenCalledWith("auto_recalls.malloy");
264
+ });
265
+ });
266
+
267
+ describe("a required filter the model reads, in the builder", () => {
268
+ it("runs no tile that reads it and asks for it, as the reader does", async () => {
269
+ packageFile = `## artifact { title="Recalls" tiles=["recalls_tiles -> by_year", "recalls_tiles -> everything"] } dashboard { columns=12 }
270
+ import "auto_recalls.malloy"
271
+
272
+ source: recalls_tiles is recalls extend {
273
+ view: by_year is by_year_view
274
+ view: everything is everything_view
275
+ }`;
276
+ served = {
277
+ givens: [
278
+ {
279
+ name: "RECALL_YEAR",
280
+ label: "Recall Year",
281
+ type: "number",
282
+ required: true,
283
+ },
284
+ ],
285
+ tiles: [
286
+ {
287
+ kind: "query",
288
+ query: "recalls_tiles -> by_year",
289
+ givenNames: ["RECALL_YEAR"],
290
+ },
291
+ {
292
+ kind: "query",
293
+ query: "recalls_tiles -> everything",
294
+ givenNames: [],
295
+ },
296
+ ],
297
+ };
298
+ open();
299
+ expect(
300
+ await screen.findByText(
301
+ "Pick a value for Recall Year to see this report.",
302
+ ),
303
+ ).toBeDefined();
304
+ expect(screen.getByText("Waiting for Recall Year.")).toBeDefined();
305
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
306
+ const queries = executeQueryModel.mock.calls.map((call) =>
307
+ JSON.stringify(call[3]),
308
+ );
309
+ expect(queries.some((q) => q.includes("everything"))).toBe(true);
310
+ expect(queries.some((q) => q.includes("by_year"))).toBe(false);
311
+ });
312
+ });
@@ -9,8 +9,6 @@ import {
9
9
  waitFor,
10
10
  } from "@testing-library/react";
11
11
  import { beforeEach, describe, expect, it, mock } from "bun:test";
12
- import * as fs from "fs";
13
- import * as path from "path";
14
12
  import {
15
13
  clearCache,
16
14
  mockServerProvider,
@@ -31,16 +29,8 @@ import { editInline } from "./testing/inline";
31
29
 
32
30
  /**
33
31
  * The one editor opened as a notebook: how it reads the file, where it takes
34
- * the manifest from, and what it does with a notebook in the cell format.
32
+ * the manifest from.
35
33
  */
36
- const REPO = path.resolve(import.meta.dir, "../../../../..");
37
- const LEGACY = fs
38
- .readFileSync(
39
- path.join(REPO, "examples/storefront/category-review.malloy"),
40
- "utf8",
41
- )
42
- .replace(/\r\n/g, "\n");
43
-
44
34
  const LAYOUT = `## artifact { layout=linear title="Tour" tiles=[intro { kind=text }] }
45
35
 
46
36
  ##|(markdown) intro
@@ -48,12 +38,6 @@ Hello.
48
38
  |##
49
39
  `;
50
40
 
51
- const REFUSED = `## artifact { layout=linear }
52
- import { orders } from "../m.malloy"
53
-
54
- run: orders extend { dimension: z is 1 } -> { select: z }
55
- `;
56
-
57
41
  let served = LAYOUT;
58
42
  let servedHash = await sha256Hex(LAYOUT);
59
43
  let writes: string[] = [];
@@ -73,22 +57,15 @@ const getModel = mock(
73
57
  },
74
58
  }),
75
59
  );
76
- // One read for either layout, by path: a report in tiles carries its manifest,
77
- // one in cells carries its cells instead.
60
+ // One read for either layout, by path: the report's manifest.
78
61
  const getReport = mock(
79
62
  async (_env: string, _pkg: string, modelPath: string) => ({
80
- data: served.includes("tiles=")
81
- ? {
82
- path: modelPath,
83
- layout: "linear",
84
- givens: [{ name: "FROM_MANIFEST", type: "string" }],
85
- tiles: [],
86
- }
87
- : {
88
- path: modelPath,
89
- layout: "linear",
90
- notebook: { notebookCells: [] },
91
- },
63
+ data: {
64
+ path: modelPath,
65
+ layout: "linear",
66
+ givens: [{ name: "FROM_MANIFEST", type: "string" }],
67
+ tiles: [],
68
+ },
92
69
  }),
93
70
  );
94
71
  const getDashboard = mock(() => pending());
@@ -207,6 +184,24 @@ describe("ReportEditor as a notebook", () => {
207
184
  expect(getModel.mock.calls[0][2]).toBe("dashboards/tour.malloy");
208
185
  });
209
186
 
187
+ it("refuses a file written as `run:` cells, saying why, and reports a category, never the reason", async () => {
188
+ served =
189
+ '## artifact { layout=linear }\nimport { orders } from "../m.malloy"\n\nrun: orders -> by_month\n';
190
+ const onEvent = mock((_event: ReportEvent) => {});
191
+ mount({}, onEvent);
192
+ expect(
193
+ await screen.findByText(/written as `run:` cells is no longer read/),
194
+ ).toBeDefined();
195
+ expect(onEvent.mock.calls[0][0]).toMatchObject({
196
+ type: "report.load_failed",
197
+ surface: "edit",
198
+ category: "invalid",
199
+ });
200
+ // A category, never the message: the reason can carry the file's text.
201
+ expect(onEvent.mock.calls[0][0]).not.toHaveProperty("reason");
202
+ expect(writes).toEqual([]);
203
+ });
204
+
210
205
  // DEPRECATED FEATURE COVERAGE — delete together with
211
206
  // `.malloynb` notebooks (see RELEASE_NOTES deprecations).
212
207
  describe("deprecated: .malloynb notebooks", () => {
@@ -226,50 +221,6 @@ describe("ReportEditor as a notebook", () => {
226
221
  });
227
222
  });
228
223
  });
229
-
230
- it("offers a notebook in the cell format as a conversion, and Save writes it exactly", async () => {
231
- served = LEGACY;
232
- servedHash = await sha256Hex(LEGACY);
233
- const onEvent = mock((_event: ReportEvent) => {});
234
- mount({}, onEvent);
235
- expect(
236
- await screen.findByText(/This report is in the cell format/),
237
- ).toBeDefined();
238
- expect(screen.getByLabelText("Tile revenue_by_month")).toBeDefined();
239
-
240
- fireEvent.click(button("Save"));
241
- fireEvent.click(
242
- await screen.findByRole("button", { name: "Convert and save" }),
243
- );
244
- await waitFor(() => expect(writes).toHaveLength(1));
245
- expect(writes[0]).toContain("tiles=[\n text_1 { kind=text }");
246
- expect(writes[0]).toContain("view: revenue_by_month is sales_by_month");
247
- await waitFor(() =>
248
- expect(onEvent.mock.calls.map(([event]) => event.type)).toEqual([
249
- "report.opened",
250
- "report.saved",
251
- ]),
252
- );
253
- expect(onEvent.mock.calls[1][0]).toMatchObject({ converted: true });
254
- });
255
-
256
- it("says why a notebook cannot be converted, naming the line", async () => {
257
- served = REFUSED;
258
- const onEvent = mock((_event: ReportEvent) => {});
259
- mount({}, onEvent);
260
- const alert = await screen.findByText(/cannot be opened in the builder/);
261
- expect(alert.textContent).toMatch(/line 4/i);
262
- expect(
263
- screen.queryByText(/This report is in the cell format/),
264
- ).toBeNull();
265
- expect(onEvent.mock.calls[0][0]).toMatchObject({
266
- type: "report.load_failed",
267
- surface: "edit",
268
- category: "invalid",
269
- });
270
- // A category, never the message: the reason can carry the file's text.
271
- expect(onEvent.mock.calls[0][0]).not.toHaveProperty("reason");
272
- });
273
224
  });
274
225
 
275
226
  describe("ReportEditor as a notebook: the host's record", () => {
@@ -118,8 +118,12 @@ describe("ReportEditor, when the server takes writes", () => {
118
118
  await new BrowserDocumentStorage().saveDocument(DRAFT, "stale draft");
119
119
  await screen.findByText("Storefront");
120
120
  expect(
121
- screen.getByText("Save writes the file into the package."),
122
- ).toBeDefined();
121
+ document.querySelector('[data-saves-to="package"]'),
122
+ ).not.toBeNull();
123
+ // The ordinary case is not a line on the page; the status says it.
124
+ expect(
125
+ screen.queryByText("Save writes the file into the package."),
126
+ ).toBeNull();
123
127
 
124
128
  editInline("By category", "Tile title", "Categories");
125
129
  fireEvent.click(button("Save"));
@@ -233,7 +233,8 @@ describe("versionId", () => {
233
233
  expect(
234
234
  getModel.mock.calls.find((call) => call[2] === "data_app.malloy"),
235
235
  ).toEqual(["env", "pkg", "data_app.malloy", "v7"]);
236
- expect(getReport.mock.calls[0]).toEqual([
236
+ // The reader's request, which also carries its abort signal.
237
+ expect(getReport.mock.calls[0].slice(0, 4)).toEqual([
237
238
  "env",
238
239
  "pkg",
239
240
  "dashboards/overview.malloy",
@@ -247,7 +248,7 @@ describe("versionId", () => {
247
248
  // one dashboard apart, and nothing about that failure is visible on
248
249
  // screen.
249
250
  expect(cacheKeys("dashboard-editor-model")[0]).toContain('"v7"');
250
- expect(cacheKeys("dashboard-editor-manifest")[0]).toContain('"v7"');
251
+ expect(cacheKeys("report")[0]).toContain('"v7"');
251
252
  expect(cacheKeys("reports")[0]).toContain('"v7"');
252
253
  await waitFor(() =>
253
254
  expect(cacheKeys("report-editor-models")[0]).toContain('"v7"'),
@@ -33,7 +33,7 @@ source: a is scoped_orders extend {
33
33
  # label="By category"
34
34
  view: by_cat is by_category
35
35
  }`;
36
- import { editInline } from "./testing/inline";
36
+ import { editInline, findViewOption } from "./testing/inline";
37
37
 
38
38
  let served = PACKAGE_FILE;
39
39
  /** Set, and the dashboard's own file fails to fetch: a refetch the server could not answer. */
@@ -246,9 +246,7 @@ describe("ReportEditor", () => {
246
246
  fireEvent.click(
247
247
  await screen.findByRole("button", { name: "Add tile", hidden: true }),
248
248
  );
249
- expect(
250
- await screen.findByRole("button", { name: "View by_category" }),
251
- ).toBeDefined();
249
+ expect(await findViewOption("by_category")).toBeDefined();
252
250
  });
253
251
 
254
252
  it("leaves the package's listed reports out of the catalog, wherever they live", async () => {
@@ -1,13 +1,13 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
+ import { findViewOption } from "./testing/inline";
4
5
  import {
5
6
  cleanup,
6
7
  fireEvent,
7
8
  render,
8
9
  screen,
9
10
  waitFor,
10
- within,
11
11
  } from "@testing-library/react";
12
12
  import { beforeEach, describe, expect, it, mock } from "bun:test";
13
13
  import {
@@ -128,6 +128,7 @@ const mount = (
128
128
  textSource: {
129
129
  modelPath: string;
130
130
  givens?: Record<string, string | string[]>;
131
+ compileSource?: (text: string) => string | Promise<string>;
131
132
  } = {
132
133
  modelPath: "models/orders.malloy",
133
134
  },
@@ -335,18 +336,15 @@ describe("ReportEditor in text-source mode", () => {
335
336
  fireEvent.click(
336
337
  await screen.findByRole("button", { name: "Add tile" }),
337
338
  );
338
- fireEvent.mouseDown(
339
- await screen.findByRole("combobox", { name: /Source/ }),
340
- );
341
- const options = within(screen.getByRole("listbox")).getAllByRole(
342
- "option",
343
- );
344
- expect(options.map((o) => o.textContent).sort()).toEqual([
345
- "orders",
346
- "other",
347
- ]);
348
- fireEvent.keyDown(screen.getByRole("listbox"), { key: "Escape" });
349
- fireEvent.click(await screen.findByLabelText("View by_x"));
339
+ await findViewOption("by_x");
340
+ expect(
341
+ screen
342
+ .getAllByRole("group", { hidden: true })
343
+ .map((group) => group.getAttribute("aria-label"))
344
+ .filter((name) => name === "orders" || name === "other")
345
+ .sort(),
346
+ ).toEqual(["orders", "other"]);
347
+ fireEvent.click(await findViewOption("by_x"));
350
348
  fireEvent.click(
351
349
  screen.getByRole("button", { name: "Add tile", hidden: false }),
352
350
  );
@@ -391,3 +389,85 @@ describe("ReportEditor in text-source mode", () => {
391
389
  expect(await screen.findByText(/authoritative/)).toBeDefined();
392
390
  });
393
391
  });
392
+
393
+ describe("a host that compiles its own text (compileSource)", () => {
394
+ /** A document that declares its own filter and binds it on its tile. */
395
+ const WITH_FILTER = `##! experimental.givens
396
+ ## artifact { title="Ops" tiles=["a -> by_cat"] } dashboard { columns=12 }
397
+
398
+ # label="Category"
399
+ given: CAT :: filter<string> is f'Outerwear'
400
+
401
+ source: a is orders extend {
402
+ view: by_cat is by_category + { where: category ~ $CAT }
403
+ }
404
+ `;
405
+ /** What a host does with it: no flag, no declaration, the value as a literal. */
406
+ const resolve = (text: string) =>
407
+ text
408
+ .replace(/^##!.*\n/m, "")
409
+ .replace(/^# label="Category"\ngiven: CAT .*\n/m, "")
410
+ .replace(/\$CAT\b/g, "f'Outerwear'");
411
+
412
+ const storeOf = (text: string) => {
413
+ const storage = new FakeStorage();
414
+ storage.documents.set("env/pkg/dashboards/ops.malloy", text);
415
+ return storage;
416
+ };
417
+
418
+ it("compiles what the host makes of the text, and turns Add filter on", async () => {
419
+ mount(storeOf(DOCUMENT), {
420
+ modelPath: "models/orders.malloy",
421
+ compileSource: (text) => `// resolved by the host\n${text}`,
422
+ });
423
+
424
+ await waitFor(() => expect(compileModelSource).toHaveBeenCalled());
425
+ expect(compileModelSource.mock.calls[0][3]).toEqual({
426
+ source: `// resolved by the host\n${DOCUMENT}`,
427
+ scope: "append",
428
+ });
429
+ const add = await screen.findByRole("button", { name: "Add filter" });
430
+ expect((add as HTMLButtonElement).disabled).toBe(false);
431
+ });
432
+
433
+ it("runs the document's own filter as a literal, never as a given the server is sent", async () => {
434
+ mount(storeOf(WITH_FILTER), {
435
+ modelPath: "models/orders.malloy",
436
+ compileSource: resolve,
437
+ });
438
+
439
+ await waitFor(() => expect(compileModelSource).toHaveBeenCalled());
440
+ const sent = compileModelSource.mock.calls[0][3].source ?? "";
441
+ expect(sent).not.toContain("given:");
442
+ expect(sent).not.toContain("$CAT");
443
+
444
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
445
+ const body = JSON.stringify(executeQueryModel.mock.calls[0][3]);
446
+ expect(body).toContain("category ~ f'Outerwear'");
447
+ expect(body).not.toContain('"CAT"');
448
+ // The control is drawn from the document's own declaration.
449
+ expect(
450
+ await screen.findByRole("button", { name: /^Category: / }),
451
+ ).toBeDefined();
452
+ });
453
+
454
+ it("says so when the host cannot prepare the text, and compiles nothing", async () => {
455
+ mount(storeOf(DOCUMENT), {
456
+ modelPath: "models/orders.malloy",
457
+ compileSource: () => Promise.reject(new Error("CAT is the model's")),
458
+ });
459
+
460
+ expect(
461
+ await screen.findByText(
462
+ /could not be prepared to compile: CAT is the model's/,
463
+ ),
464
+ ).toBeDefined();
465
+ expect(compileModelSource).not.toHaveBeenCalled();
466
+ // Its tiles are drawn, but nothing runs them: no source is declared.
467
+ expect(
468
+ (await screen.findAllByText("Not run: this document did not compile."))
469
+ .length,
470
+ ).toBeGreaterThan(0);
471
+ expect(executeQueryModel).not.toHaveBeenCalled();
472
+ });
473
+ });