@malloy-publisher/sdk 0.9.1 → 0.9.3

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 (410) hide show
  1. package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-DwB0-9Yx.es.js} +219 -210
  2. package/dist/RenderedResult-hKjFEqaN.cjs.js +141 -0
  3. package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-CcSrGaRN.es.js} +1473 -1326
  4. package/dist/ServerProvider-Gbf1YPOP.cjs.js +1 -0
  5. package/dist/builder/index.cjs.js +143 -58
  6. package/dist/builder/index.es.js +12179 -9318
  7. package/dist/builder-entry.d.ts +5 -1
  8. package/dist/client/api.d.ts +247 -56
  9. package/dist/client/configuration.d.ts +1 -1
  10. package/dist/client/index.cjs.js +1 -1
  11. package/dist/client/index.d.ts +1 -1
  12. package/dist/client/index.es.js +94 -88
  13. package/dist/client-entry.d.ts +2 -0
  14. package/dist/components/ApiErrorDisplay.d.ts +11 -0
  15. package/dist/components/AppDialog.d.ts +6 -6
  16. package/dist/components/Dashboard/Dashboard.d.ts +8 -15
  17. package/dist/components/Dashboard/DashboardGrid.d.ts +38 -6
  18. package/dist/components/Dashboard/DashboardTile.d.ts +21 -2
  19. package/dist/components/Dashboard/DashboardView.d.ts +71 -0
  20. package/dist/components/Dashboard/TileCard.d.ts +30 -5
  21. package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
  22. package/dist/components/Dashboard/dropValueUrlTags.d.ts +6 -0
  23. package/dist/components/Dashboard/index.d.ts +5 -1
  24. package/dist/components/Dashboard/telemetry.d.ts +16 -3
  25. package/dist/components/Dashboard/textSource.d.ts +19 -0
  26. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +15 -9
  27. package/dist/components/DashboardBuilder/BuilderDialogs.d.ts +25 -0
  28. package/dist/components/DashboardBuilder/BuilderGrid.d.ts +31 -0
  29. package/dist/components/DashboardBuilder/BuilderHeader.d.ts +17 -0
  30. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +23 -15
  31. package/dist/components/DashboardBuilder/ChartPicker.d.ts +31 -0
  32. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +56 -21
  33. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +44 -5
  34. package/dist/components/DashboardBuilder/EditorSurface.d.ts +33 -0
  35. package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
  36. package/dist/components/DashboardBuilder/FilterStrip.d.ts +8 -4
  37. package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
  38. package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
  39. package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
  40. package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
  41. package/dist/components/DashboardBuilder/TextTileBody.d.ts +10 -0
  42. package/dist/components/DashboardBuilder/TileFrame.d.ts +51 -12
  43. package/dist/components/DashboardBuilder/TileMenu.d.ts +12 -6
  44. package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
  45. package/dist/components/DashboardBuilder/builderReport.d.ts +13 -0
  46. package/dist/components/DashboardBuilder/catalog.d.ts +4 -18
  47. package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
  48. package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
  49. package/dist/components/DashboardBuilder/controls.d.ts +2 -2
  50. package/dist/components/DashboardBuilder/document.d.ts +42 -26
  51. package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
  52. package/dist/components/DashboardBuilder/imports.d.ts +19 -0
  53. package/dist/components/DashboardBuilder/inlineEdit.d.ts +18 -0
  54. package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
  55. package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
  56. package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
  57. package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
  58. package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
  59. package/dist/components/DashboardBuilder/preview.d.ts +24 -4
  60. package/dist/components/DashboardBuilder/readDocument.d.ts +6 -1
  61. package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
  62. package/dist/components/DashboardBuilder/sortable.d.ts +16 -0
  63. package/dist/components/DashboardBuilder/spliceDocument.d.ts +15 -13
  64. package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
  65. package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
  66. package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
  67. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
  68. package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
  69. package/dist/components/DashboardBuilder/testing/resize.d.ts +7 -0
  70. package/dist/components/DashboardBuilder/tileDisplayTitle.d.ts +7 -0
  71. package/dist/components/DashboardBuilder/useBuilderSelection.d.ts +53 -0
  72. package/dist/components/DashboardBuilder/useBuilderSession.d.ts +86 -0
  73. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
  74. package/dist/components/DashboardBuilder/useControlBindings.d.ts +30 -0
  75. package/dist/components/DashboardBuilder/useConversionConfirm.d.ts +20 -0
  76. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +19 -55
  77. package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
  78. package/dist/components/DashboardBuilder/useDraft.d.ts +3 -1
  79. package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
  80. package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
  81. package/dist/components/DashboardBuilder/useHostCopy.d.ts +26 -0
  82. package/dist/components/DashboardBuilder/useOpenDraftCommit.d.ts +17 -0
  83. package/dist/components/DashboardBuilder/useOpenedDocument.d.ts +71 -0
  84. package/dist/components/DashboardBuilder/useSaveChannel.d.ts +50 -0
  85. package/dist/components/DashboardBuilder/useTileEditing.d.ts +33 -0
  86. package/dist/components/DashboardBuilder/useTileResize.d.ts +6 -3
  87. package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
  88. package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
  89. package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
  90. package/dist/components/DocumentCreate/events.d.ts +10 -0
  91. package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
  92. package/dist/components/DocumentCreate/guards.d.ts +12 -0
  93. package/dist/components/DocumentCreate/index.d.ts +6 -0
  94. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
  95. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
  96. package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
  97. package/dist/components/Loading.d.ts +13 -0
  98. package/dist/components/NarrowEditGate.d.ts +8 -0
  99. package/dist/components/Notebook/Notebook.d.ts +1 -1
  100. package/dist/components/Notebook/NotebookCell.d.ts +1 -5
  101. package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
  102. package/dist/components/Package/Package.d.ts +17 -1
  103. package/dist/components/Package/documentLocation.d.ts +28 -0
  104. package/dist/components/Package/index.d.ts +5 -1
  105. package/dist/components/Package/useDocumentLocation.d.ts +12 -0
  106. package/dist/components/PackageSection.d.ts +2 -2
  107. package/dist/components/Prose.d.ts +1 -1
  108. package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
  109. package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
  110. package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
  111. package/dist/components/RenderedResult/loadRenderer.d.ts +7 -0
  112. package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
  113. package/dist/components/ServerProvider.d.ts +2 -1
  114. package/dist/components/UnsavedChangesDialog.d.ts +9 -0
  115. package/dist/components/given/GivensPanel.d.ts +2 -2
  116. package/dist/components/given/paramCodec.d.ts +8 -1
  117. package/dist/components/index.d.ts +3 -2
  118. package/dist/components/styles.d.ts +4 -4
  119. package/dist/hooks/givenValue.d.ts +6 -0
  120. package/dist/hooks/index.d.ts +2 -0
  121. package/dist/hooks/useCompiledDocument.d.ts +23 -0
  122. package/dist/hooks/useDocumentControls.d.ts +6 -1
  123. package/dist/hooks/useNarrowScreen.d.ts +4 -0
  124. package/dist/hooks/useNearViewport.d.ts +16 -0
  125. package/dist/hooks/useQueryResult.d.ts +2 -0
  126. package/dist/hooks/useQueryWithApiError.d.ts +7 -2
  127. package/dist/hooks/useSettled.d.ts +14 -0
  128. package/dist/hooks/useSuggestOptions.d.ts +9 -2
  129. package/dist/index.cjs.js +23 -24
  130. package/dist/index.es.js +9041 -7002
  131. package/dist/text/index.cjs.js +1 -0
  132. package/dist/text/index.d.ts +2 -0
  133. package/dist/text/index.es.js +6 -0
  134. package/dist/text-entry-BJwltZiy.cjs.js +7 -0
  135. package/dist/text-entry-CA0LZ1xL.es.js +196 -0
  136. package/dist/text-entry.d.ts +2 -0
  137. package/dist/theme/accent.d.ts +29 -0
  138. package/dist/theme/buildVegaThemeOverride.d.ts +3 -3
  139. package/dist/theme/index.d.ts +3 -0
  140. package/dist/theme/keys.d.ts +1 -1
  141. package/dist/theme/motion.d.ts +31 -0
  142. package/dist/theme/readChartAnnotations.d.ts +1 -1
  143. package/dist/theme/resolveTheme.d.ts +4 -4
  144. package/dist/theme/types.d.ts +33 -5
  145. package/dist/{Dashboard-H1kJlDFo.es.js → useCompiledDocument-BU6d8FPp.es.js} +17904 -19057
  146. package/dist/useCompiledDocument-pOg2W-Yt.cjs.js +142 -0
  147. package/dist/utils/clock.d.ts +2 -0
  148. package/dist/utils/malloyText.d.ts +104 -0
  149. package/package.json +20 -11
  150. package/src/builder-entry.ts +36 -0
  151. package/src/client-entry.ts +8 -0
  152. package/src/clientEntry.spec.ts +17 -0
  153. package/src/components/ApiErrorDisplay.tsx +37 -18
  154. package/src/components/AppDialog.tsx +8 -7
  155. package/src/components/Dashboard/Dashboard.spec.tsx +3 -32
  156. package/src/components/Dashboard/Dashboard.tsx +29 -280
  157. package/src/components/Dashboard/DashboardGrid.tsx +87 -8
  158. package/src/components/Dashboard/DashboardTile.spec.tsx +121 -2
  159. package/src/components/Dashboard/DashboardTile.tsx +121 -30
  160. package/src/components/Dashboard/DashboardView.spec.tsx +368 -0
  161. package/src/components/Dashboard/DashboardView.tsx +428 -0
  162. package/src/components/Dashboard/RowsDialog.tsx +4 -3
  163. package/src/components/Dashboard/TileCard.tsx +60 -11
  164. package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
  165. package/src/components/Dashboard/TileFilterTag.tsx +78 -0
  166. package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
  167. package/src/components/Dashboard/dropValueUrlTags.spec.ts +177 -0
  168. package/src/components/Dashboard/dropValueUrlTags.ts +108 -0
  169. package/src/components/Dashboard/index.ts +13 -1
  170. package/src/components/Dashboard/telemetry.ts +17 -5
  171. package/src/components/Dashboard/textSource.spec.ts +36 -0
  172. package/src/components/Dashboard/textSource.ts +39 -0
  173. package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
  174. package/src/components/DashboardBuilder/AddTileDialog.tsx +124 -138
  175. package/src/components/DashboardBuilder/BuilderDialogs.tsx +162 -0
  176. package/src/components/DashboardBuilder/BuilderGrid.tsx +245 -0
  177. package/src/components/DashboardBuilder/BuilderHeader.tsx +107 -0
  178. package/src/components/DashboardBuilder/BuilderToolbar.tsx +111 -80
  179. package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
  180. package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
  181. package/src/components/DashboardBuilder/ChartPicker.tsx +156 -0
  182. package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
  183. package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +183 -0
  184. package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +373 -0
  185. package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +310 -0
  186. package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +105 -0
  187. package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +117 -0
  188. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +146 -108
  189. package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +179 -0
  190. package/src/components/DashboardBuilder/DashboardBuilder.tsx +330 -512
  191. package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +55 -25
  192. package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +142 -0
  193. package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
  194. package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +310 -0
  195. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +39 -13
  196. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +9 -26
  197. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +102 -25
  198. package/src/components/DashboardBuilder/DashboardEditor.textSource.spec.tsx +317 -0
  199. package/src/components/DashboardBuilder/DashboardEditor.tsx +252 -780
  200. package/src/components/DashboardBuilder/DrillDialog.tsx +2 -2
  201. package/src/components/DashboardBuilder/EditorSurface.tsx +471 -0
  202. package/src/components/DashboardBuilder/FilterDialog.tsx +23 -11
  203. package/src/components/DashboardBuilder/FilterStrip.tsx +130 -70
  204. package/src/components/DashboardBuilder/InlineMarkdown.tsx +182 -0
  205. package/src/components/DashboardBuilder/InlineText.tsx +112 -0
  206. package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
  207. package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
  208. package/src/components/DashboardBuilder/TextTileBody.tsx +31 -0
  209. package/src/components/DashboardBuilder/TileFrame.tsx +302 -163
  210. package/src/components/DashboardBuilder/TileMenu.tsx +125 -97
  211. package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
  212. package/src/components/DashboardBuilder/annotationText.ts +17 -0
  213. package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
  214. package/src/components/DashboardBuilder/artifactTagParity.spec.ts +46 -0
  215. package/src/components/DashboardBuilder/builderReport.ts +74 -0
  216. package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
  217. package/src/components/DashboardBuilder/catalog.spec.ts +2 -44
  218. package/src/components/DashboardBuilder/catalog.ts +61 -57
  219. package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
  220. package/src/components/DashboardBuilder/changedTile.ts +28 -0
  221. package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
  222. package/src/components/DashboardBuilder/chartLine.ts +121 -0
  223. package/src/components/DashboardBuilder/controls.spec.ts +21 -10
  224. package/src/components/DashboardBuilder/controls.ts +22 -8
  225. package/src/components/DashboardBuilder/document.ts +53 -5
  226. package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
  227. package/src/components/DashboardBuilder/documentSession.ts +258 -0
  228. package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
  229. package/src/components/DashboardBuilder/imports.spec.ts +61 -0
  230. package/src/components/DashboardBuilder/imports.ts +93 -0
  231. package/src/components/DashboardBuilder/inlineEdit.tsx +78 -0
  232. package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
  233. package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
  234. package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
  235. package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
  236. package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
  237. package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
  238. package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
  239. package/src/components/DashboardBuilder/malloyTree.ts +159 -7
  240. package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
  241. package/src/components/DashboardBuilder/newDashboard.ts +30 -3
  242. package/src/components/DashboardBuilder/openDraft.ts +52 -0
  243. package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
  244. package/src/components/DashboardBuilder/preview.spec.ts +159 -12
  245. package/src/components/DashboardBuilder/preview.ts +83 -9
  246. package/src/components/DashboardBuilder/readDocument.spec.ts +174 -26
  247. package/src/components/DashboardBuilder/readDocument.ts +137 -45
  248. package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
  249. package/src/components/DashboardBuilder/readForEditor.ts +52 -0
  250. package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
  251. package/src/components/DashboardBuilder/sortable.spec.ts +89 -0
  252. package/src/components/DashboardBuilder/sortable.tsx +11 -10
  253. package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
  254. package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
  255. package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
  256. package/src/components/DashboardBuilder/spliceDocument.ts +768 -131
  257. package/src/components/DashboardBuilder/spliceResult.ts +15 -0
  258. package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
  259. package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
  260. package/src/components/DashboardBuilder/tagParse.ts +103 -0
  261. package/src/components/DashboardBuilder/telemetry.ts +47 -0
  262. package/src/components/DashboardBuilder/testing/artifactTagParity.json +253 -0
  263. package/src/components/DashboardBuilder/testing/documentKindRule.json +40 -0
  264. package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
  265. package/src/components/DashboardBuilder/testing/inline.ts +25 -0
  266. package/src/components/DashboardBuilder/testing/resize.ts +48 -0
  267. package/src/components/DashboardBuilder/testing/urlRenderTags.json +62 -0
  268. package/src/components/DashboardBuilder/textTiles.spec.ts +760 -0
  269. package/src/components/DashboardBuilder/tileDisplayTitle.ts +13 -0
  270. package/src/components/DashboardBuilder/useBuilderSelection.ts +121 -0
  271. package/src/components/DashboardBuilder/useBuilderSession.spec.ts +250 -0
  272. package/src/components/DashboardBuilder/useBuilderSession.ts +255 -0
  273. package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +97 -0
  274. package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
  275. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +45 -9
  276. package/src/components/DashboardBuilder/useControlBindings.ts +152 -0
  277. package/src/components/DashboardBuilder/useConversionConfirm.ts +55 -0
  278. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
  279. package/src/components/DashboardBuilder/useDashboardEditor.ts +57 -181
  280. package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
  281. package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
  282. package/src/components/DashboardBuilder/useDraft.ts +15 -2
  283. package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
  284. package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
  285. package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
  286. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
  287. package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
  288. package/src/components/DashboardBuilder/useHostCopy.ts +104 -0
  289. package/src/components/DashboardBuilder/useOpenDraftCommit.ts +47 -0
  290. package/src/components/DashboardBuilder/useOpenedDocument.ts +314 -0
  291. package/src/components/DashboardBuilder/useSaveChannel.ts +275 -0
  292. package/src/components/DashboardBuilder/useTileEditing.ts +141 -0
  293. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
  294. package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
  295. package/src/components/DashboardBuilder/useTileResize.spec.tsx +30 -5
  296. package/src/components/DashboardBuilder/useTileResize.ts +31 -8
  297. package/src/components/DataAppViewer/DataAppViewer.tsx +7 -4
  298. package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
  299. package/src/components/DocumentCreate/canRetry.ts +19 -0
  300. package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
  301. package/src/components/DocumentCreate/createDocument.ts +159 -0
  302. package/src/components/DocumentCreate/documentPath.ts +40 -0
  303. package/src/components/DocumentCreate/events.ts +15 -0
  304. package/src/components/DocumentCreate/exportedSources.ts +25 -0
  305. package/src/components/DocumentCreate/guards.ts +45 -0
  306. package/src/components/DocumentCreate/index.ts +27 -0
  307. package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
  308. package/src/components/DocumentCreate/newNotebook.ts +44 -0
  309. package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
  310. package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
  311. package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
  312. package/src/components/Environment/Environment.tsx +0 -10
  313. package/src/components/Loading.tsx +14 -0
  314. package/src/components/Model/Model.tsx +16 -9
  315. package/src/components/Model/ModelExplorer.spec.tsx +2 -2
  316. package/src/components/Model/ModelExplorer.tsx +2 -2
  317. package/src/components/Model/SourcesExplorer.tsx +2 -4
  318. package/src/components/NarrowEditGate.spec.tsx +73 -0
  319. package/src/components/NarrowEditGate.tsx +29 -0
  320. package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
  321. package/src/components/Notebook/Notebook.tsx +72 -29
  322. package/src/components/Notebook/NotebookCell.tsx +90 -215
  323. package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
  324. package/src/components/Package/NewDocumentDialog.tsx +401 -0
  325. package/src/components/Package/Package.artifacts.spec.tsx +186 -0
  326. package/src/components/Package/Package.create.spec.tsx +401 -0
  327. package/src/components/Package/Package.notebooks.spec.tsx +18 -0
  328. package/src/components/Package/Package.tsx +396 -177
  329. package/src/components/Package/documentLocation.spec.ts +81 -0
  330. package/src/components/Package/documentLocation.ts +55 -0
  331. package/src/components/Package/index.ts +14 -1
  332. package/src/components/Package/useDocumentLocation.ts +59 -0
  333. package/src/components/PackageSection.tsx +2 -2
  334. package/src/components/Prose.spec.tsx +37 -0
  335. package/src/components/Prose.tsx +35 -5
  336. package/src/components/RenderedResult/RenderedResult.tsx +23 -8
  337. package/src/components/RenderedResult/ResultContainer.tsx +51 -13
  338. package/src/components/RenderedResult/ResultPanel.tsx +24 -5
  339. package/src/components/RenderedResult/loadRenderer.ts +42 -0
  340. package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
  341. package/src/components/RenderedResult/resultSizing.ts +14 -3
  342. package/src/components/ServerProvider.tsx +2 -1
  343. package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
  344. package/src/components/UnsavedChangesDialog.tsx +49 -0
  345. package/src/components/given/GivenInput.spec.tsx +5 -5
  346. package/src/components/given/GivenInput.tsx +46 -38
  347. package/src/components/given/GivensPanel.spec.tsx +6 -6
  348. package/src/components/given/GivensPanel.tsx +5 -11
  349. package/src/components/given/paramCodec.ts +27 -1
  350. package/src/components/index.ts +3 -2
  351. package/src/components/styles.ts +4 -5
  352. package/src/hooks/givenValue.ts +9 -0
  353. package/src/hooks/index.ts +7 -0
  354. package/src/hooks/useCompiledDocument.spec.tsx +86 -0
  355. package/src/hooks/useCompiledDocument.ts +59 -0
  356. package/src/hooks/useDimensionalFilterRangeData.ts +3 -1
  357. package/src/hooks/useDocumentControls.ts +13 -1
  358. package/src/hooks/useNarrowScreen.ts +21 -0
  359. package/src/hooks/useNearViewport.spec.tsx +150 -0
  360. package/src/hooks/useNearViewport.ts +102 -0
  361. package/src/hooks/useQueryResult.ts +23 -1
  362. package/src/hooks/useQueryWithApiError.ts +10 -3
  363. package/src/hooks/useRawQueryData.ts +3 -1
  364. package/src/hooks/useSettled.spec.ts +41 -0
  365. package/src/hooks/useSettled.ts +27 -0
  366. package/src/hooks/useSuggestOptions.dom.spec.ts +40 -1
  367. package/src/hooks/useSuggestOptions.ts +42 -10
  368. package/src/mainEntry.spec.ts +145 -0
  369. package/src/text-entry.ts +12 -0
  370. package/src/textEntry.spec.ts +112 -0
  371. package/src/theme/accent.spec.ts +116 -0
  372. package/src/theme/accent.ts +148 -0
  373. package/src/theme/buildTableCssVars.spec.ts +24 -0
  374. package/src/theme/buildTableCssVars.ts +1 -2
  375. package/src/theme/buildVegaThemeOverride.spec.ts +38 -2
  376. package/src/theme/buildVegaThemeOverride.ts +5 -5
  377. package/src/theme/defaults.ts +34 -0
  378. package/src/theme/index.ts +9 -0
  379. package/src/theme/keys.ts +6 -0
  380. package/src/theme/motion.ts +44 -0
  381. package/src/theme/readChartAnnotations.spec.ts +18 -0
  382. package/src/theme/readChartAnnotations.ts +1 -1
  383. package/src/theme/resolveTheme.spec.ts +73 -0
  384. package/src/theme/resolveTheme.ts +61 -20
  385. package/src/theme/types.ts +30 -5
  386. package/src/utils/clock.spec.ts +12 -0
  387. package/src/utils/clock.ts +6 -0
  388. package/src/{components/DashboardBuilder → utils}/malloyText.spec.ts +48 -0
  389. package/src/utils/malloyText.ts +368 -0
  390. package/src/utils/queryClient.ts +8 -0
  391. package/vite.config.ts +4 -0
  392. package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
  393. package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
  394. package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
  395. package/dist/components/Dashboard/DashboardBar.d.ts +0 -21
  396. package/dist/components/Dashboard/ExploreDialog.d.ts +0 -20
  397. package/dist/components/DashboardBuilder/DiffDialog.d.ts +0 -15
  398. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +0 -20
  399. package/dist/components/DashboardBuilder/diff.d.ts +0 -35
  400. package/dist/components/DashboardBuilder/malloyText.d.ts +0 -64
  401. package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
  402. package/src/components/Dashboard/DashboardBar.tsx +0 -88
  403. package/src/components/Dashboard/ExploreDialog.tsx +0 -89
  404. package/src/components/DashboardBuilder/DiffDialog.tsx +0 -122
  405. package/src/components/DashboardBuilder/SettingsPopover.tsx +0 -168
  406. package/src/components/DashboardBuilder/diff.spec.ts +0 -44
  407. package/src/components/DashboardBuilder/diff.ts +0 -93
  408. package/src/components/DashboardBuilder/malloyText.ts +0 -214
  409. package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
  410. 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,156 @@
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
+ variant = "standard",
92
+ }: {
93
+ state: ChartState;
94
+ /** The catalog's view this cell runs, when it is one the catalog knows. */
95
+ view: Pick<CatalogView, "chart" | "aggregateOnly"> | undefined;
96
+ /** Why `view` is absent, worded into the reasons on the charts that need its shape. */
97
+ viewStatus?: ViewStatus;
98
+ /** Which cell this is, so the control is named apart from its neighbours. */
99
+ cellLabel: string;
100
+ disabledReason?: string;
101
+ /** The choices are being looked at, which is when a host may fetch what it needs to offer more. */
102
+ onOpen?: () => void;
103
+ onChange: (next: ChartState) => void;
104
+ /** The field's look: underlined in a compact menu, outlined beside a dialog's other fields. */
105
+ variant?: "standard" | "outlined";
106
+ }) {
107
+ const choices = chartChoices(view, state, viewStatus);
108
+ const reasonId = useId();
109
+ return (
110
+ <TextField
111
+ select
112
+ size="small"
113
+ variant={variant}
114
+ label="Viz type"
115
+ value={state}
116
+ disabled={disabledReason !== undefined}
117
+ onChange={(event) => {
118
+ const next = event.target.value as ChartState;
119
+ // A disabled item still receives a click from a focusable-disabled menu.
120
+ if (!choices.find((choice) => choice.value === next)?.disabled)
121
+ onChange(next);
122
+ }}
123
+ // On screen and described-by, not only in a tooltip that a keyboard or screen reader never reaches.
124
+ helperText={disabledReason}
125
+ FormHelperTextProps={{ id: reasonId }}
126
+ SelectProps={{
127
+ ...(onOpen ? { onOpen } : {}),
128
+ // The menu items carry a reason line; the closed field shows the label alone.
129
+ renderValue: (value) =>
130
+ choices.find((choice) => choice.value === value)?.label ??
131
+ String(value),
132
+ // A disabled choice stays focusable so a keyboard user reaches its reason.
133
+ MenuProps: { MenuListProps: { disabledItemsFocusable: true } },
134
+ SelectDisplayProps: {
135
+ "aria-label": `Viz type, ${cellLabel}`,
136
+ "aria-labelledby": undefined,
137
+ ...(disabledReason ? { "aria-describedby": reasonId } : {}),
138
+ },
139
+ }}
140
+ sx={{ minWidth: 140 }}
141
+ >
142
+ {choices.map((choice) => (
143
+ <MenuItem
144
+ key={choice.value}
145
+ value={choice.value}
146
+ disabled={choice.value === "custom" || choice.disabled === true}
147
+ >
148
+ <ListItemText
149
+ primary={choice.label}
150
+ {...(choice.reason ? { secondary: choice.reason } : {})}
151
+ />
152
+ </MenuItem>
153
+ ))}
154
+ </TextField>
155
+ );
156
+ }
@@ -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", 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",
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", 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", 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,183 @@
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
+ onSave?: (source: string) => Promise<void> | void;
32
+ onDirtyChange?: (dirty: boolean) => void;
33
+ onExit?: () => void;
34
+ } = {},
35
+ ) => {
36
+ const document = await openDocument(SOURCE);
37
+ return render(
38
+ <DashboardBuilder
39
+ source={SOURCE}
40
+ document={document}
41
+ {...(options.onSave ? { onSave: options.onSave } : {})}
42
+ {...(options.onExit ? { onExit: options.onExit } : {})}
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
+ afterEach(cleanup);
61
+
62
+ describe("DashboardBuilder: leaving", () => {
63
+ it("draws Save and no Close when it can save", async () => {
64
+ await mount({ onSave: async () => {} });
65
+ expect(button("Saved").hasAttribute("disabled")).toBe(true);
66
+ retitle();
67
+ expect(button("Save")).toBeDefined();
68
+ expect(screen.queryByRole("button", { name: "Close" })).toBeNull();
69
+ });
70
+
71
+ it("Save saves in place and stays in the builder", async () => {
72
+ const onSave = mock(async () => {});
73
+ await mount({ onSave });
74
+ retitle();
75
+ fireEvent.click(button("Save"));
76
+ await waitFor(() => expect(button("Saved")).toBeDefined());
77
+ expect(onSave).toHaveBeenCalledTimes(1);
78
+ });
79
+
80
+ it("stays open when the save fails", async () => {
81
+ const onSave = mock(async () => {
82
+ throw new Error("nope");
83
+ });
84
+ await mount({ onSave });
85
+ retitle();
86
+ fireEvent.click(button("Save"));
87
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
88
+ await screen.findByText(/nope/);
89
+ });
90
+
91
+ it("reports clean when it unmounts dirty", async () => {
92
+ const onDirtyChange = mock((_dirty: boolean) => {});
93
+ const view = await mount({ onDirtyChange, onSave: async () => {} });
94
+ retitle();
95
+ expect(onDirtyChange.mock.calls.at(-1)?.[0]).toBe(true);
96
+ view.unmount();
97
+ expect(onDirtyChange.mock.calls.at(-1)?.[0]).toBe(false);
98
+ });
99
+ });
100
+
101
+ const removeTile = () => {
102
+ fireEvent.click(screen.getByLabelText("Settings for By category"));
103
+ fireEvent.click(screen.getByRole("button", { name: "Delete" }));
104
+ };
105
+
106
+ describe("DashboardBuilder: leaving with a structural edit", () => {
107
+ it("Save writes a structural edit at once, once, and stays open", async () => {
108
+ const onSave = mock(async () => {});
109
+ await mount({ onSave });
110
+ removeTile();
111
+ fireEvent.click(button("Save"));
112
+ await waitFor(() => expect(button("Saved")).toBeDefined());
113
+ expect(onSave).toHaveBeenCalledTimes(1);
114
+ });
115
+
116
+ it("holds the button through a save in flight, so a second press cannot write twice", async () => {
117
+ let finish = () => {};
118
+ const onSave = mock(
119
+ () => new Promise<void>((resolve) => (finish = resolve)),
120
+ );
121
+ await mount({ onSave });
122
+ retitle();
123
+ shortcut("s");
124
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
125
+ expect(button("Saving…").hasAttribute("disabled")).toBe(true);
126
+ fireEvent.click(button("Saving…"));
127
+ await act(async () => finish());
128
+ await screen.findByRole("button", { name: "Saved" });
129
+ expect(onSave).toHaveBeenCalledTimes(1);
130
+ });
131
+ });
132
+
133
+ describe("DashboardBuilder: a host's opt-in Close", () => {
134
+ it("draws no Close unless the host passes onExit", async () => {
135
+ await mount({ onSave: async () => {} });
136
+ expect(screen.queryByRole("button", { name: "Close" })).toBeNull();
137
+ });
138
+
139
+ it("draws Close beside Save, and leaves at once when nothing is unsaved", async () => {
140
+ const onExit = mock(() => {});
141
+ await mount({ onSave: async () => {}, onExit });
142
+ expect(button("Saved")).toBeDefined();
143
+ fireEvent.click(button("Close"));
144
+ expect(onExit).toHaveBeenCalledTimes(1);
145
+ });
146
+
147
+ it("asks first when there are edits, and Keep editing stays", async () => {
148
+ const onExit = mock(() => {});
149
+ await mount({ onSave: async () => {}, onExit });
150
+ retitle();
151
+ fireEvent.click(button("Close"));
152
+ fireEvent.click(
153
+ await screen.findByRole("button", { name: "Keep editing" }),
154
+ );
155
+ expect(onExit).not.toHaveBeenCalled();
156
+ });
157
+
158
+ it("Discard changes leaves without saving", async () => {
159
+ const onExit = mock(() => {});
160
+ const onSave = mock(async () => {});
161
+ await mount({ onSave, onExit });
162
+ retitle();
163
+ fireEvent.click(button("Close"));
164
+ fireEvent.click(
165
+ await screen.findByRole("button", { name: "Discard changes" }),
166
+ );
167
+ expect(onExit).toHaveBeenCalledTimes(1);
168
+ expect(onSave).not.toHaveBeenCalled();
169
+ });
170
+
171
+ it("Save and exit saves, then leaves", async () => {
172
+ const onExit = mock(() => {});
173
+ const onSave = mock(async () => {});
174
+ await mount({ onSave, onExit });
175
+ retitle();
176
+ fireEvent.click(button("Close"));
177
+ fireEvent.click(
178
+ await screen.findByRole("button", { name: "Save and exit" }),
179
+ );
180
+ await waitFor(() => expect(onExit).toHaveBeenCalledTimes(1));
181
+ expect(onSave).toHaveBeenCalledTimes(1);
182
+ });
183
+ });