@malloy-publisher/sdk 0.9.1 → 0.9.2

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 (292) hide show
  1. package/dist/{Dashboard-H1kJlDFo.es.js → DashboardTile-BFcxdv7R.es.js} +15918 -17760
  2. package/dist/DashboardTile-sg8LjUk8.cjs.js +137 -0
  3. package/dist/RenderedResult-B48wAjM8.cjs.js +141 -0
  4. package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-CBLHr32C.es.js} +193 -183
  5. package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-DCV8BUWD.es.js} +529 -521
  6. package/dist/ServerProvider-HRqT3w1C.cjs.js +1 -0
  7. package/dist/builder/index.cjs.js +146 -58
  8. package/dist/builder/index.es.js +9076 -6479
  9. package/dist/builder-entry.d.ts +4 -0
  10. package/dist/client/api.d.ts +77 -47
  11. package/dist/client/configuration.d.ts +1 -1
  12. package/dist/client/index.cjs.js +1 -1
  13. package/dist/client/index.d.ts +1 -1
  14. package/dist/client/index.es.js +84 -82
  15. package/dist/components/Dashboard/Dashboard.d.ts +8 -15
  16. package/dist/components/Dashboard/DashboardGrid.d.ts +23 -6
  17. package/dist/components/Dashboard/DashboardTile.d.ts +10 -1
  18. package/dist/components/Dashboard/DashboardView.d.ts +36 -0
  19. package/dist/components/Dashboard/TileCard.d.ts +15 -4
  20. package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
  21. package/dist/components/Dashboard/index.d.ts +3 -0
  22. package/dist/components/Dashboard/telemetry.d.ts +15 -3
  23. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -1
  24. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +16 -5
  25. package/dist/components/DashboardBuilder/ChartPicker.d.ts +29 -0
  26. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +48 -21
  27. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +17 -4
  28. package/dist/components/DashboardBuilder/DiffDialog.d.ts +2 -10
  29. package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
  30. package/dist/components/DashboardBuilder/FilterStrip.d.ts +3 -1
  31. package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
  32. package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
  33. package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
  34. package/dist/components/DashboardBuilder/SaveNotice.d.ts +27 -0
  35. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +19 -7
  36. package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
  37. package/dist/components/DashboardBuilder/TextTileBody.d.ts +7 -0
  38. package/dist/components/DashboardBuilder/TileFrame.d.ts +14 -12
  39. package/dist/components/DashboardBuilder/TileMenu.d.ts +11 -3
  40. package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
  41. package/dist/components/DashboardBuilder/catalog.d.ts +4 -0
  42. package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
  43. package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
  44. package/dist/components/DashboardBuilder/controls.d.ts +2 -2
  45. package/dist/components/DashboardBuilder/document.d.ts +42 -26
  46. package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
  47. package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
  48. package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
  49. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -5
  50. package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
  51. package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
  52. package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
  53. package/dist/components/DashboardBuilder/preview.d.ts +24 -4
  54. package/dist/components/DashboardBuilder/readDocument.d.ts +4 -1
  55. package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
  56. package/dist/components/DashboardBuilder/sortable.d.ts +14 -0
  57. package/dist/components/DashboardBuilder/spliceDocument.d.ts +13 -13
  58. package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
  59. package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
  60. package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
  61. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
  62. package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
  63. package/dist/components/DashboardBuilder/useBuilderSession.d.ts +89 -0
  64. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
  65. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +17 -55
  66. package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
  67. package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
  68. package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
  69. package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
  70. package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
  71. package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
  72. package/dist/components/DocumentCreate/events.d.ts +10 -0
  73. package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
  74. package/dist/components/DocumentCreate/guards.d.ts +12 -0
  75. package/dist/components/DocumentCreate/index.d.ts +6 -0
  76. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
  77. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
  78. package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
  79. package/dist/components/NarrowEditGate.d.ts +8 -0
  80. package/dist/components/Notebook/Notebook.d.ts +1 -1
  81. package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
  82. package/dist/components/Package/Package.d.ts +1 -0
  83. package/dist/components/Package/documentLocation.d.ts +28 -0
  84. package/dist/components/Package/index.d.ts +4 -0
  85. package/dist/components/Package/useDocumentLocation.d.ts +12 -0
  86. package/dist/components/PackageSection.d.ts +2 -2
  87. package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
  88. package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
  89. package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
  90. package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
  91. package/dist/components/ServerProvider.d.ts +2 -1
  92. package/dist/components/UnsavedChangesDialog.d.ts +9 -0
  93. package/dist/components/given/GivensPanel.d.ts +2 -2
  94. package/dist/components/index.d.ts +2 -0
  95. package/dist/hooks/index.d.ts +1 -0
  96. package/dist/hooks/useNarrowScreen.d.ts +4 -0
  97. package/dist/hooks/useQueryResult.d.ts +2 -0
  98. package/dist/hooks/useSettled.d.ts +14 -0
  99. package/dist/index.cjs.js +23 -24
  100. package/dist/index.es.js +9714 -7072
  101. package/dist/text/index.cjs.js +1 -0
  102. package/dist/text/index.d.ts +2 -0
  103. package/dist/text/index.es.js +6 -0
  104. package/dist/text-entry-BJwltZiy.cjs.js +7 -0
  105. package/dist/text-entry-CbbBcZl8.es.js +196 -0
  106. package/dist/text-entry.d.ts +2 -0
  107. package/dist/utils/clock.d.ts +2 -0
  108. package/package.json +10 -1
  109. package/src/builder-entry.ts +35 -0
  110. package/src/components/Dashboard/Dashboard.tsx +27 -278
  111. package/src/components/Dashboard/DashboardGrid.tsx +68 -7
  112. package/src/components/Dashboard/DashboardTile.spec.tsx +24 -0
  113. package/src/components/Dashboard/DashboardTile.tsx +31 -4
  114. package/src/components/Dashboard/DashboardView.spec.tsx +212 -0
  115. package/src/components/Dashboard/DashboardView.tsx +352 -0
  116. package/src/components/Dashboard/RowsDialog.tsx +1 -1
  117. package/src/components/Dashboard/TileCard.tsx +44 -10
  118. package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
  119. package/src/components/Dashboard/TileFilterTag.tsx +78 -0
  120. package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
  121. package/src/components/Dashboard/index.ts +3 -0
  122. package/src/components/Dashboard/telemetry.ts +16 -5
  123. package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
  124. package/src/components/DashboardBuilder/AddTileDialog.tsx +137 -111
  125. package/src/components/DashboardBuilder/BuilderToolbar.tsx +85 -27
  126. package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
  127. package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
  128. package/src/components/DashboardBuilder/ChartPicker.tsx +153 -0
  129. package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
  130. package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +192 -0
  131. package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +329 -0
  132. package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +363 -0
  133. package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +194 -0
  134. package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +157 -0
  135. package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +124 -0
  136. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +103 -78
  137. package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +177 -0
  138. package/src/components/DashboardBuilder/DashboardBuilder.tsx +610 -315
  139. package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +58 -8
  140. package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +191 -0
  141. package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
  142. package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +316 -0
  143. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +56 -10
  144. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +5 -22
  145. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +96 -14
  146. package/src/components/DashboardBuilder/DashboardEditor.tsx +482 -332
  147. package/src/components/DashboardBuilder/DiffDialog.spec.tsx +25 -0
  148. package/src/components/DashboardBuilder/DiffDialog.tsx +5 -24
  149. package/src/components/DashboardBuilder/DrillDialog.tsx +1 -1
  150. package/src/components/DashboardBuilder/FilterDialog.tsx +10 -3
  151. package/src/components/DashboardBuilder/FilterStrip.tsx +26 -4
  152. package/src/components/DashboardBuilder/InlineMarkdown.tsx +184 -0
  153. package/src/components/DashboardBuilder/InlineText.tsx +106 -0
  154. package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
  155. package/src/components/DashboardBuilder/SaveNotice.tsx +113 -0
  156. package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +87 -0
  157. package/src/components/DashboardBuilder/SettingsPopover.tsx +225 -67
  158. package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
  159. package/src/components/DashboardBuilder/TextTileBody.tsx +28 -0
  160. package/src/components/DashboardBuilder/TileFrame.tsx +89 -115
  161. package/src/components/DashboardBuilder/TileMenu.tsx +168 -90
  162. package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
  163. package/src/components/DashboardBuilder/annotationText.ts +17 -0
  164. package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
  165. package/src/components/DashboardBuilder/artifactTagParity.spec.ts +41 -0
  166. package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
  167. package/src/components/DashboardBuilder/catalog.spec.ts +2 -0
  168. package/src/components/DashboardBuilder/catalog.ts +61 -21
  169. package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
  170. package/src/components/DashboardBuilder/changedTile.ts +28 -0
  171. package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
  172. package/src/components/DashboardBuilder/chartLine.ts +121 -0
  173. package/src/components/DashboardBuilder/controls.spec.ts +21 -10
  174. package/src/components/DashboardBuilder/controls.ts +22 -8
  175. package/src/components/DashboardBuilder/document.ts +53 -5
  176. package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
  177. package/src/components/DashboardBuilder/documentSession.ts +257 -0
  178. package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
  179. package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
  180. package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
  181. package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
  182. package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
  183. package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
  184. package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
  185. package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
  186. package/src/components/DashboardBuilder/malloyText.spec.ts +48 -0
  187. package/src/components/DashboardBuilder/malloyText.ts +181 -27
  188. package/src/components/DashboardBuilder/malloyTree.ts +155 -7
  189. package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
  190. package/src/components/DashboardBuilder/newDashboard.ts +30 -3
  191. package/src/components/DashboardBuilder/openDraft.ts +52 -0
  192. package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
  193. package/src/components/DashboardBuilder/preview.spec.ts +159 -12
  194. package/src/components/DashboardBuilder/preview.ts +83 -9
  195. package/src/components/DashboardBuilder/readDocument.spec.ts +139 -27
  196. package/src/components/DashboardBuilder/readDocument.ts +130 -44
  197. package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
  198. package/src/components/DashboardBuilder/readForEditor.ts +47 -0
  199. package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
  200. package/src/components/DashboardBuilder/sortable.spec.ts +65 -0
  201. package/src/components/DashboardBuilder/sortable.tsx +2 -12
  202. package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
  203. package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
  204. package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
  205. package/src/components/DashboardBuilder/spliceDocument.ts +762 -130
  206. package/src/components/DashboardBuilder/spliceResult.ts +15 -0
  207. package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
  208. package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
  209. package/src/components/DashboardBuilder/tagParse.ts +103 -0
  210. package/src/components/DashboardBuilder/telemetry.ts +47 -0
  211. package/src/components/DashboardBuilder/testing/artifactTagParity.json +197 -0
  212. package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
  213. package/src/components/DashboardBuilder/testing/inline.ts +25 -0
  214. package/src/components/DashboardBuilder/textTiles.spec.ts +718 -0
  215. package/src/components/DashboardBuilder/useBuilderSession.spec.ts +335 -0
  216. package/src/components/DashboardBuilder/useBuilderSession.ts +292 -0
  217. package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +65 -0
  218. package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
  219. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +36 -10
  220. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
  221. package/src/components/DashboardBuilder/useDashboardEditor.ts +54 -181
  222. package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
  223. package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
  224. package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
  225. package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
  226. package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
  227. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
  228. package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
  229. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
  230. package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
  231. package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
  232. package/src/components/DocumentCreate/canRetry.ts +19 -0
  233. package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
  234. package/src/components/DocumentCreate/createDocument.ts +159 -0
  235. package/src/components/DocumentCreate/documentPath.ts +40 -0
  236. package/src/components/DocumentCreate/events.ts +15 -0
  237. package/src/components/DocumentCreate/exportedSources.ts +25 -0
  238. package/src/components/DocumentCreate/guards.ts +45 -0
  239. package/src/components/DocumentCreate/index.ts +27 -0
  240. package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
  241. package/src/components/DocumentCreate/newNotebook.ts +44 -0
  242. package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
  243. package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
  244. package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
  245. package/src/components/Model/ModelExplorer.spec.tsx +2 -2
  246. package/src/components/Model/SourcesExplorer.tsx +2 -4
  247. package/src/components/NarrowEditGate.spec.tsx +73 -0
  248. package/src/components/NarrowEditGate.tsx +29 -0
  249. package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
  250. package/src/components/Notebook/Notebook.tsx +66 -27
  251. package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
  252. package/src/components/Package/NewDocumentDialog.tsx +401 -0
  253. package/src/components/Package/Package.artifacts.spec.tsx +190 -0
  254. package/src/components/Package/Package.create.spec.tsx +380 -0
  255. package/src/components/Package/Package.notebooks.spec.tsx +18 -0
  256. package/src/components/Package/Package.tsx +366 -171
  257. package/src/components/Package/documentLocation.spec.ts +81 -0
  258. package/src/components/Package/documentLocation.ts +55 -0
  259. package/src/components/Package/index.ts +13 -0
  260. package/src/components/Package/useDocumentLocation.ts +59 -0
  261. package/src/components/PackageSection.tsx +2 -2
  262. package/src/components/RenderedResult/RenderedResult.tsx +18 -1
  263. package/src/components/RenderedResult/ResultContainer.tsx +44 -11
  264. package/src/components/RenderedResult/ResultPanel.tsx +4 -0
  265. package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
  266. package/src/components/RenderedResult/resultSizing.ts +14 -3
  267. package/src/components/ServerProvider.tsx +2 -1
  268. package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
  269. package/src/components/UnsavedChangesDialog.tsx +49 -0
  270. package/src/components/given/GivensPanel.spec.tsx +6 -6
  271. package/src/components/given/GivensPanel.tsx +3 -3
  272. package/src/components/index.ts +2 -0
  273. package/src/hooks/index.ts +3 -0
  274. package/src/hooks/useNarrowScreen.ts +21 -0
  275. package/src/hooks/useQueryResult.ts +16 -0
  276. package/src/hooks/useSettled.spec.ts +41 -0
  277. package/src/hooks/useSettled.ts +27 -0
  278. package/src/mainEntry.spec.ts +145 -0
  279. package/src/text-entry.ts +12 -0
  280. package/src/textEntry.spec.ts +118 -0
  281. package/src/utils/clock.spec.ts +12 -0
  282. package/src/utils/clock.ts +6 -0
  283. package/vite.config.ts +4 -0
  284. package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
  285. package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
  286. package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
  287. package/dist/components/DashboardBuilder/useTileResize.d.ts +0 -29
  288. package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
  289. package/src/components/DashboardBuilder/useTileResize.spec.tsx +0 -121
  290. package/src/components/DashboardBuilder/useTileResize.ts +0 -110
  291. package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
  292. package/src/components/Package/NewDashboardDialog.tsx +0 -265
@@ -0,0 +1,77 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { chartChoices } from "./ChartPicker";
6
+
7
+ const values = (...args: Parameters<typeof chartChoices>) =>
8
+ chartChoices(...args).map((choice) => choice.value);
9
+ const enabled = (...args: Parameters<typeof chartChoices>) =>
10
+ chartChoices(...args)
11
+ .filter((choice) => !choice.disabled)
12
+ .map((choice) => choice.value);
13
+ const choice = (
14
+ pick: string,
15
+ ...args: Parameters<typeof chartChoices>
16
+ ): ReturnType<typeof chartChoices>[number] =>
17
+ chartChoices(...args).find((c) => c.value === pick)!;
18
+
19
+ describe("chartChoices", () => {
20
+ it("lists every chart, never a sparkline, with the inapplicable ones disabled", () => {
21
+ expect(values(undefined, "default")).toEqual([
22
+ "default",
23
+ "none",
24
+ "line_chart",
25
+ "bar_chart",
26
+ "big_value",
27
+ "scatter_chart",
28
+ "shape_map",
29
+ "segment_map",
30
+ ]);
31
+ expect(enabled(undefined, "default")).toEqual([
32
+ "default",
33
+ "none",
34
+ "line_chart",
35
+ "bar_chart",
36
+ "scatter_chart",
37
+ ]);
38
+ });
39
+
40
+ it("enables big_value only for an aggregate-only view, and says what it needs otherwise", () => {
41
+ expect(enabled({ aggregateOnly: true }, "default")).toContain(
42
+ "big_value",
43
+ );
44
+ expect(choice("big_value", {}, "default")).toMatchObject({
45
+ disabled: true,
46
+ reason: "Needs a view with only totals (no group by)",
47
+ });
48
+ });
49
+
50
+ it("enables a map only when the view carries that map tag, and says what it needs otherwise", () => {
51
+ expect(enabled({ chart: "shape_map" }, "default")).toContain("shape_map");
52
+ expect(enabled({ chart: "shape_map" }, "default")).not.toContain(
53
+ "segment_map",
54
+ );
55
+ expect(
56
+ choice("shape_map", { chart: "bar_chart" }, "default"),
57
+ ).toMatchObject({
58
+ disabled: true,
59
+ reason: "Needs a view that already carries a map chart",
60
+ });
61
+ });
62
+
63
+ it("words the reason by why the view's shape is unknown", () => {
64
+ expect(choice("big_value", undefined, "default", "loading").reason).toBe(
65
+ "Still loading this view's details",
66
+ );
67
+ expect(choice("shape_map", undefined, "default", "unlisted").reason).toBe(
68
+ "Not a view the catalog lists, so its shape is unknown",
69
+ );
70
+ });
71
+
72
+ it("keeps what the cell has now selectable, even when it would not be offered", () => {
73
+ expect(enabled({}, "big_value")).toContain("big_value");
74
+ expect(enabled({}, "segment_map")).toContain("segment_map");
75
+ expect(values({}, "custom")).toContain("custom");
76
+ });
77
+ });
@@ -0,0 +1,153 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { ListItemText, MenuItem, TextField } from "@mui/material";
5
+ import { useId } from "react";
6
+ import type { CatalogView } from "./catalog";
7
+ import type { ChartPick, ChartState } from "./chartLine";
8
+
9
+ export interface ChartChoice {
10
+ value: ChartState;
11
+ label: string;
12
+ /** Listed but not pickable; `reason` says what the view would need. */
13
+ disabled?: boolean;
14
+ reason?: string;
15
+ }
16
+
17
+ /** Why a view is absent, so the reason on a disabled choice says whether to wait or to pick another. */
18
+ export type ViewStatus = "loading" | "unlisted";
19
+
20
+ const LABELS: Record<ChartPick, string> = {
21
+ line_chart: "Line",
22
+ bar_chart: "Bar",
23
+ big_value: "Big value",
24
+ scatter_chart: "Scatter",
25
+ shape_map: "Shape map",
26
+ segment_map: "Segment map",
27
+ };
28
+
29
+ /**
30
+ * Every chart a cell can be set to; one the view cannot render is listed disabled with its reason, so it is discoverable rather than missing.
31
+ * Whatever the cell has now stays selectable, so the select never shows a value it does not offer.
32
+ */
33
+ export function chartChoices(
34
+ view: Pick<CatalogView, "chart" | "aggregateOnly"> | undefined,
35
+ current: ChartState,
36
+ viewStatus?: ViewStatus,
37
+ ): ChartChoice[] {
38
+ const unknown =
39
+ view !== undefined
40
+ ? undefined
41
+ : viewStatus === "loading"
42
+ ? "Still loading this view's details"
43
+ : viewStatus === "unlisted"
44
+ ? "Not a view the catalog lists, so its shape is unknown"
45
+ : undefined;
46
+ const reasonFor = (pick: ChartPick): string | undefined => {
47
+ if (current === pick) return undefined;
48
+ if (pick === "big_value")
49
+ return view?.aggregateOnly === true
50
+ ? undefined
51
+ : (unknown ?? "Needs a view with only totals (no group by)");
52
+ if (pick === "shape_map" || pick === "segment_map")
53
+ return view?.chart === pick
54
+ ? undefined
55
+ : (unknown ?? "Needs a view that already carries a map chart");
56
+ return undefined;
57
+ };
58
+ const picks: ChartPick[] = [
59
+ "line_chart",
60
+ "bar_chart",
61
+ "big_value",
62
+ "scatter_chart",
63
+ "shape_map",
64
+ "segment_map",
65
+ ];
66
+ return [
67
+ { value: "default", label: "From the view" },
68
+ { value: "none", label: "Table" },
69
+ ...picks.map((pick): ChartChoice => {
70
+ const reason = reasonFor(pick);
71
+ return {
72
+ value: pick,
73
+ label: LABELS[pick],
74
+ ...(reason ? { disabled: true, reason } : {}),
75
+ };
76
+ }),
77
+ ...(current === "custom"
78
+ ? [{ value: "custom" as const, label: "As written" }]
79
+ : []),
80
+ ];
81
+ }
82
+
83
+ export function ChartPicker({
84
+ state,
85
+ view,
86
+ viewStatus,
87
+ cellLabel,
88
+ disabledReason,
89
+ onOpen,
90
+ onChange,
91
+ }: {
92
+ state: ChartState;
93
+ /** The catalog's view this cell runs, when it is one the catalog knows. */
94
+ view: Pick<CatalogView, "chart" | "aggregateOnly"> | undefined;
95
+ /** Why `view` is absent, worded into the reasons on the charts that need its shape. */
96
+ viewStatus?: ViewStatus;
97
+ /** Which cell this is, so the control is named apart from its neighbours. */
98
+ cellLabel: string;
99
+ disabledReason?: string;
100
+ /** The choices are being looked at, which is when a host may fetch what it needs to offer more. */
101
+ onOpen?: () => void;
102
+ onChange: (next: ChartState) => void;
103
+ }) {
104
+ const choices = chartChoices(view, state, viewStatus);
105
+ const reasonId = useId();
106
+ return (
107
+ <TextField
108
+ select
109
+ size="small"
110
+ variant="standard"
111
+ label="Viz type"
112
+ value={state}
113
+ disabled={disabledReason !== undefined}
114
+ onChange={(event) => {
115
+ const next = event.target.value as ChartState;
116
+ // A disabled item still receives a click from a focusable-disabled menu.
117
+ if (!choices.find((choice) => choice.value === next)?.disabled)
118
+ onChange(next);
119
+ }}
120
+ // On screen and described-by, not only in a tooltip that a keyboard or screen reader never reaches.
121
+ helperText={disabledReason}
122
+ FormHelperTextProps={{ id: reasonId }}
123
+ SelectProps={{
124
+ ...(onOpen ? { onOpen } : {}),
125
+ // The menu items carry a reason line; the closed field shows the label alone.
126
+ renderValue: (value) =>
127
+ choices.find((choice) => choice.value === value)?.label ??
128
+ String(value),
129
+ // A disabled choice stays focusable so a keyboard user reaches its reason.
130
+ MenuProps: { MenuListProps: { disabledItemsFocusable: true } },
131
+ SelectDisplayProps: {
132
+ "aria-label": `Viz type, ${cellLabel}`,
133
+ "aria-labelledby": undefined,
134
+ ...(disabledReason ? { "aria-describedby": reasonId } : {}),
135
+ },
136
+ }}
137
+ sx={{ minWidth: 140 }}
138
+ >
139
+ {choices.map((choice) => (
140
+ <MenuItem
141
+ key={choice.value}
142
+ value={choice.value}
143
+ disabled={choice.value === "custom" || choice.disabled === true}
144
+ >
145
+ <ListItemText
146
+ primary={choice.label}
147
+ {...(choice.reason ? { secondary: choice.reason } : {})}
148
+ />
149
+ </MenuItem>
150
+ ))}
151
+ </TextField>
152
+ );
153
+ }
@@ -0,0 +1,205 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import {
5
+ fireEvent,
6
+ render,
7
+ screen,
8
+ waitFor,
9
+ within,
10
+ } from "@testing-library/react";
11
+ import { describe, expect, it } from "bun:test";
12
+ import { chartLineText } from "./chartLine";
13
+ import { DashboardBuilder } from "./DashboardBuilder";
14
+ import { openDocument } from "./testing/fixtures";
15
+ import { closeMenu, editInline } from "./testing/inline";
16
+
17
+ const SOURCE = `## artifact { title="Storefront" tiles=["a -> by_cat", "a -> by_brand"] } dashboard { columns=12 }
18
+ import { scoped_orders } from "../data_app.malloy"
19
+
20
+ source: a is scoped_orders extend {
21
+ # colspan=6
22
+ view: by_cat is by_category
23
+
24
+ # colspan=6
25
+ # bar_chart { size=spark }
26
+ view: by_brand is by_brand_view
27
+ }`;
28
+
29
+ const catalog = {
30
+ sources: [
31
+ {
32
+ name: "scoped_orders",
33
+ modelPath: "data_app.malloy",
34
+ views: [
35
+ { name: "by_category", chart: "shape_map" },
36
+ { name: "by_brand_view" },
37
+ { name: "kpis", aggregateOnly: true },
38
+ { name: "table_view" },
39
+ { name: "odd view" },
40
+ ],
41
+ givens: [],
42
+ fields: [],
43
+ },
44
+ ],
45
+ };
46
+
47
+ const mount = async (onSave?: (source: string) => void) => {
48
+ const document = await openDocument(SOURCE);
49
+ return render(
50
+ <DashboardBuilder
51
+ source={SOURCE}
52
+ document={document}
53
+ catalog={catalog}
54
+ {...(onSave ? { onSave } : {})}
55
+ />,
56
+ );
57
+ };
58
+
59
+ const chartPicker = (name: string) =>
60
+ screen.getByRole("combobox", { name: `Viz type, ${name}`, hidden: true });
61
+ const optionsOf = (name: string) => {
62
+ fireEvent.mouseDown(chartPicker(name));
63
+ const menu = screen.getAllByRole("listbox", { hidden: true }).at(-1)!;
64
+ return within(menu).getAllByRole("option", { hidden: true });
65
+ };
66
+ const enabledNames = (name: string) =>
67
+ optionsOf(name)
68
+ .filter((o) => o.getAttribute("aria-disabled") !== "true")
69
+ .map((o) => o.textContent);
70
+ const choose = (name: string, option: string) =>
71
+ fireEvent.click(
72
+ optionsOf(name).find((o) => o.textContent === option) as HTMLElement,
73
+ );
74
+
75
+ describe("DashboardBuilder: charts", () => {
76
+ it("sets a tile's chart from its menu and writes the one line", async () => {
77
+ let written: string | undefined;
78
+ await mount((source) => {
79
+ written = source;
80
+ });
81
+ fireEvent.click(screen.getByLabelText("Settings for by_cat"));
82
+ const names = enabledNames("a by_cat");
83
+ // The wrapper's view `by_category` carries a shape map, so it is enabled; the rest are listed disabled.
84
+ expect(names).toEqual([
85
+ "From the view",
86
+ "Table",
87
+ "Line",
88
+ "Bar",
89
+ "Scatter",
90
+ "Shape map",
91
+ ]);
92
+ choose("a by_cat", "Line");
93
+ closeMenu();
94
+ fireEvent.click(
95
+ screen.getByRole("button", { name: "Save changes", hidden: true }),
96
+ );
97
+ await waitFor(() => expect(written).toBeDefined());
98
+ expect(written).toContain(
99
+ ` ${chartLineText("line_chart", ["shape_map"])}\n view: by_cat is by_category`,
100
+ );
101
+ });
102
+
103
+ it("treats picking a chart and then Default as no edit on a tile with no chart line", async () => {
104
+ let written: string | undefined;
105
+ await mount((source) => {
106
+ written = source;
107
+ });
108
+ fireEvent.click(screen.getByLabelText("Settings for by_cat"));
109
+ choose("a by_cat", "Bar");
110
+ choose("a by_cat", "From the view");
111
+ closeMenu();
112
+ const save = screen.queryByRole("button", {
113
+ name: "Save changes",
114
+ hidden: true,
115
+ });
116
+ expect(save === null || (save as HTMLButtonElement).disabled).toBe(true);
117
+ expect(written).toBeUndefined();
118
+ });
119
+
120
+ it("shows a line the builder does not model as locked, and keeps it", async () => {
121
+ let written: string | undefined;
122
+ await mount((source) => {
123
+ written = source;
124
+ });
125
+ fireEvent.click(screen.getByLabelText("Settings for by_brand"));
126
+ expect(
127
+ screen
128
+ .getByRole("combobox", {
129
+ name: "Viz type, a by_brand",
130
+ hidden: true,
131
+ })
132
+ .getAttribute("aria-disabled"),
133
+ ).toBe("true");
134
+ expect(screen.getByText(/is not one the builder models/)).toBeDefined();
135
+ closeMenu();
136
+ editInline("by_brand", "Tile title", "Brands");
137
+ fireEvent.click(
138
+ screen.getByRole("button", { name: "Save changes", hidden: true }),
139
+ );
140
+ await waitFor(() => expect(written).toBeDefined());
141
+ expect(written).toContain(" # bar_chart { size=spark }\n");
142
+ expect(written).toContain('# label="Brands"');
143
+ });
144
+
145
+ it("disables the picker on a tile the model owns, with the reason", async () => {
146
+ const source = `## artifact { title="T" tiles=["orders -> by_brand"] }\nimport { orders } from '../orders.malloy'`;
147
+ const document = await openDocument(source);
148
+ render(<DashboardBuilder source={source} document={document} />);
149
+ fireEvent.click(screen.getByLabelText("Settings for by_brand"));
150
+ expect(
151
+ screen
152
+ .getByRole("combobox", {
153
+ name: "Viz type, orders by_brand",
154
+ hidden: true,
155
+ })
156
+ .getAttribute("aria-disabled"),
157
+ ).toBe("true");
158
+ expect(
159
+ screen.getByText(/so its chart is set in the model/),
160
+ ).toBeDefined();
161
+ });
162
+
163
+ it("adds a tile with a chart, offering big value only for an aggregate-only view", async () => {
164
+ let written: string | undefined;
165
+ await mount((source) => {
166
+ written = source;
167
+ });
168
+ fireEvent.click(
169
+ screen.getByRole("button", { name: "Add tile", hidden: true }),
170
+ );
171
+ fireEvent.click(screen.getByLabelText("View table_view"));
172
+ expect(enabledNames("new tile")).not.toContain("Big value");
173
+ fireEvent.click(
174
+ within(
175
+ screen.getAllByRole("listbox", { hidden: true }).at(-1)!,
176
+ ).getByRole("option", { name: "From the view", hidden: true }),
177
+ );
178
+ fireEvent.click(screen.getByLabelText("View kpis"));
179
+ expect(enabledNames("new tile")).toContain("Big value");
180
+ choose("new tile", "Big value");
181
+ fireEvent.click(screen.getByRole("button", { name: "Add tile" }));
182
+ fireEvent.click(
183
+ screen.getByRole("button", { name: "Save changes", hidden: true }),
184
+ );
185
+ await waitFor(() => expect(written).toBeDefined());
186
+ expect(written).toContain(
187
+ ` ${chartLineText("big_value", [])}\n view: kpis_tile is kpis`,
188
+ );
189
+ });
190
+
191
+ it("says why a view the writer cannot name is not addable", async () => {
192
+ await mount();
193
+ fireEvent.click(
194
+ screen.getByRole("button", { name: "Add tile", hidden: true }),
195
+ );
196
+ fireEvent.click(screen.getByLabelText("View odd view"));
197
+ expect(
198
+ screen.getByText(/"odd view" is not a plain Malloy name/),
199
+ ).toBeDefined();
200
+ expect(
201
+ (screen.getByRole("button", { name: "Add tile" }) as HTMLButtonElement)
202
+ .disabled,
203
+ ).toBe(true);
204
+ });
205
+ });
@@ -0,0 +1,192 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import {
5
+ act,
6
+ cleanup,
7
+ fireEvent,
8
+ render,
9
+ screen,
10
+ waitFor,
11
+ } from "@testing-library/react";
12
+ import { afterEach, describe, expect, it, mock } from "bun:test";
13
+ import { DashboardBuilder } from "./DashboardBuilder";
14
+ import { openDocument } from "./testing/fixtures";
15
+ import { editInline } from "./testing/inline";
16
+
17
+ const SOURCE = `## artifact { title="Storefront" tiles=["a -> by_cat", "a -> by_brand"] } dashboard { columns=12 }
18
+ import "../data_app.malloy"
19
+
20
+ source: a is scoped_orders extend {
21
+ # colspan=6
22
+ # label="By category"
23
+ view: by_cat is by_category
24
+
25
+ # colspan=6
26
+ view: by_brand is by_brand_view
27
+ }`;
28
+
29
+ const mount = async (
30
+ options: {
31
+ onExit?: () => void;
32
+ onSave?: (source: string) => Promise<void> | void;
33
+ onDirtyChange?: (dirty: boolean) => void;
34
+ } = {},
35
+ ) => {
36
+ const document = await openDocument(SOURCE);
37
+ return render(
38
+ <DashboardBuilder
39
+ source={SOURCE}
40
+ document={document}
41
+ {...(options.onExit ? { onExit: options.onExit } : {})}
42
+ {...(options.onSave ? { onSave: options.onSave } : {})}
43
+ {...(options.onDirtyChange
44
+ ? { onDirtyChange: options.onDirtyChange }
45
+ : {})}
46
+ />,
47
+ );
48
+ };
49
+
50
+ const button = (name: string) =>
51
+ screen.getByRole("button", { name, hidden: true });
52
+
53
+ const retitle = () => {
54
+ editInline("By category", "Tile title", "Renamed");
55
+ };
56
+
57
+ const shortcut = (key: string) =>
58
+ fireEvent.keyDown(window, { key, ctrlKey: true, metaKey: true });
59
+
60
+ const dialogs = () => screen.getAllByRole("dialog", { hidden: true });
61
+
62
+ const settleTick = () => act(async () => {});
63
+
64
+ afterEach(cleanup);
65
+
66
+ describe("DashboardBuilder: leaving", () => {
67
+ it("renders no Close without an onExit", async () => {
68
+ await mount();
69
+ expect(screen.queryByRole("button", { name: "Close" })).toBeNull();
70
+ });
71
+
72
+ it("exits at once when nothing is unsaved", async () => {
73
+ const onExit = mock(() => {});
74
+ await mount({ onExit });
75
+ fireEvent.click(button("Close"));
76
+ expect(onExit).toHaveBeenCalledTimes(1);
77
+ });
78
+
79
+ it("asks first when there are edits, and Keep editing stays", async () => {
80
+ const onExit = mock(() => {});
81
+ await mount({ onExit, onSave: async () => {} });
82
+ retitle();
83
+ fireEvent.click(button("Close"));
84
+ expect(screen.getByRole("dialog")).toBeDefined();
85
+ fireEvent.click(button("Keep editing"));
86
+ expect(onExit).not.toHaveBeenCalled();
87
+ });
88
+
89
+ it("Discard changes exits without saving", async () => {
90
+ const onExit = mock(() => {});
91
+ const onSave = mock(async () => {});
92
+ await mount({ onExit, onSave });
93
+ retitle();
94
+ fireEvent.click(button("Close"));
95
+ fireEvent.click(button("Discard changes"));
96
+ expect(onExit).toHaveBeenCalledTimes(1);
97
+ expect(onSave).not.toHaveBeenCalled();
98
+ });
99
+
100
+ it("Save and exit saves, then exits", async () => {
101
+ const onExit = mock(() => {});
102
+ const onSave = mock(async () => {});
103
+ await mount({ onExit, onSave });
104
+ retitle();
105
+ fireEvent.click(button("Close"));
106
+ fireEvent.click(button("Save and exit"));
107
+ await waitFor(() => expect(onExit).toHaveBeenCalledTimes(1));
108
+ expect(onSave).toHaveBeenCalledTimes(1);
109
+ });
110
+
111
+ it("stays open when the save fails", async () => {
112
+ const onExit = mock(() => {});
113
+ const onSave = mock(async () => {
114
+ throw new Error("nope");
115
+ });
116
+ await mount({ onExit, onSave });
117
+ retitle();
118
+ fireEvent.click(button("Close"));
119
+ fireEvent.click(button("Save and exit"));
120
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
121
+ await screen.findByText(/nope/);
122
+ expect(onExit).not.toHaveBeenCalled();
123
+ });
124
+
125
+ it("offers no Save and exit when the builder cannot save", async () => {
126
+ await mount({ onExit: () => {} });
127
+ retitle();
128
+ fireEvent.click(button("Close"));
129
+ expect(
130
+ screen.queryByRole("button", { name: "Save and exit" }),
131
+ ).toBeNull();
132
+ expect(button("Discard changes")).toBeDefined();
133
+ });
134
+
135
+ it("reports clean when it unmounts dirty", async () => {
136
+ const onDirtyChange = mock((_dirty: boolean) => {});
137
+ const view = await mount({ onDirtyChange, onSave: async () => {} });
138
+ retitle();
139
+ expect(onDirtyChange.mock.calls.at(-1)?.[0]).toBe(true);
140
+ view.unmount();
141
+ expect(onDirtyChange.mock.calls.at(-1)?.[0]).toBe(false);
142
+ });
143
+ });
144
+
145
+ const removeTile = () => {
146
+ fireEvent.click(screen.getByLabelText("Settings for By category"));
147
+ fireEvent.click(screen.getByRole("button", { name: "Remove tile" }));
148
+ };
149
+
150
+ describe("DashboardBuilder: leaving with a structural edit", () => {
151
+ it("ignores save, undo and redo shortcuts while the exit dialog is open", async () => {
152
+ const onSave = mock(async () => {});
153
+ await mount({ onExit: () => {}, onSave });
154
+ removeTile();
155
+ fireEvent.click(button("Close"));
156
+ shortcut("s");
157
+ shortcut("z");
158
+ await settleTick();
159
+ expect(dialogs()).toHaveLength(1);
160
+ expect(onSave).not.toHaveBeenCalled();
161
+ });
162
+
163
+ it("Save and exit writes a structural edit at once, saving once and exiting once", async () => {
164
+ const onExit = mock(() => {});
165
+ const onSave = mock(async () => {});
166
+ await mount({ onExit, onSave });
167
+ removeTile();
168
+ fireEvent.click(button("Close"));
169
+ fireEvent.click(button("Save and exit"));
170
+ await waitFor(() => expect(onExit).toHaveBeenCalledTimes(1));
171
+ expect(onSave).toHaveBeenCalledTimes(1);
172
+ });
173
+
174
+ it("waits out a save already in flight, then exits without saving twice", async () => {
175
+ const onExit = mock(() => {});
176
+ let finish = () => {};
177
+ const onSave = mock(
178
+ () => new Promise<void>((resolve) => (finish = resolve)),
179
+ );
180
+ await mount({ onExit, onSave });
181
+ retitle();
182
+ fireEvent.click(button("Save changes"));
183
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
184
+ fireEvent.click(button("Close"));
185
+ fireEvent.click(button("Save and exit"));
186
+ await settleTick();
187
+ expect(onExit).not.toHaveBeenCalled();
188
+ await act(async () => finish());
189
+ await waitFor(() => expect(onExit).toHaveBeenCalledTimes(1));
190
+ expect(onSave).toHaveBeenCalledTimes(1);
191
+ });
192
+ });