@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
@@ -1,13 +1,18 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
+ import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
4
5
  import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
5
6
  import OpenInNewIcon from "@mui/icons-material/OpenInNew";
6
7
  import {
7
8
  Alert,
8
9
  Box,
10
+ Button,
9
11
  Container,
10
12
  IconButton,
13
+ Menu,
14
+ MenuItem,
15
+ Stack,
11
16
  Table,
12
17
  TableBody,
13
18
  TableCell,
@@ -17,45 +22,78 @@ import {
17
22
  Typography,
18
23
  } from "@mui/material";
19
24
  import { useQueryClient } from "@tanstack/react-query";
20
- import React, { useCallback, useEffect, useState } from "react";
25
+ import React, { useCallback, useEffect, useMemo, useState } from "react";
21
26
  import { Database } from "../../client";
27
+ import { useNarrowScreen } from "../../hooks/useNarrowScreen";
22
28
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
23
29
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
24
30
  import { Loading } from "../Loading";
25
- import type { DocumentLocator } from "../DocumentStorage/DocumentStorage";
31
+ import { chooseWorkspace } from "../DashboardBuilder/documentSession";
32
+ import { createRoute, type CreateTarget } from "../DocumentCreate";
33
+ import type {
34
+ DocumentLocator,
35
+ DocumentType,
36
+ Workspace,
37
+ } from "../DocumentStorage/DocumentStorage";
26
38
  import { useOptionalDocumentStorage } from "../DocumentStorage/DocumentStorageProvider";
27
39
  import { Notebook } from "../Notebook";
28
40
  import { useServer } from "../ServerProvider";
29
- import { NewDashboardDialog } from "./NewDashboardDialog";
41
+ import { NewDocumentDialog } from "./NewDocumentDialog";
30
42
  import { encodeResourceUri, parseResourceUri } from "../../utils/formatting";
31
43
  import { serverBaseUrl } from "../../utils/dataAppEmbed";
32
44
  import ContentTypeIcon, {
33
45
  CONTENT_TINT,
34
46
  type ContentType,
35
47
  } from "./ContentTypeIcon";
36
- import { AddButton } from "../buttons";
37
48
  import { AppDialog } from "../AppDialog";
38
- import { BackLink } from "../BackLink";
39
49
  import { ItemRow } from "../ItemRow";
40
50
  import { Materializations } from "../Materializations";
41
51
  import { PackageSection } from "../PackageSection";
52
+ import {
53
+ documentRoute,
54
+ documentSlug,
55
+ type DocumentKind,
56
+ } from "./documentLocation";
42
57
 
43
58
  // The pinned README: the root `.malloynb`, or a served notebook named README in `notebooks/`.
44
59
  const README_NOTEBOOK = "README.malloynb";
45
60
  const isServedReadme = (path: string | undefined) =>
46
61
  path?.toLowerCase() === "notebooks/readme.malloy";
47
62
 
63
+ const draftPrefix = (
64
+ environmentName: string,
65
+ packageName: string,
66
+ kind: DocumentType,
67
+ ) => `${environmentName}/${packageName}/${kind}s/`;
68
+
48
69
  /** A served notebook opens by slug, like a dashboard; a `.malloynb` opens by path. */
49
- const servedNotebookSlug = (path: string | undefined) =>
50
- /^notebooks\/([^/]+)\.malloy$/.exec(path ?? "")?.[1];
70
+
71
+ /** A dashboard or notebook the package page asks its host to open, and how. */
72
+ export interface OpenDocumentRequest {
73
+ kind: DocumentKind;
74
+ slug: string;
75
+ /** `edit` for a document just created or a draft picked up; `view` otherwise. */
76
+ mode: "view" | "edit";
77
+ }
51
78
 
52
79
  interface PackageProps {
53
80
  onClickPackageFile?: (to: string, event?: React.MouseEvent) => void;
81
+ /**
82
+ * Open a dashboard or notebook, to read or to edit. Where reading and
83
+ * editing live is the host's business, not the package page's, so a host
84
+ * with a builder of its own routes this. Absent, the page navigates to the
85
+ * Console's own routes: the document's, and `/edit` under it to edit.
86
+ */
87
+ onOpenDocument?: (
88
+ request: OpenDocumentRequest,
89
+ event?: React.MouseEvent,
90
+ ) => void;
54
91
  resourceUri: string;
55
92
  }
56
93
 
57
94
  export default function Package({
58
95
  onClickPackageFile,
96
+ onOpenDocument,
59
97
  resourceUri,
60
98
  }: PackageProps) {
61
99
  const { apiClients, server, mutable } = useServer();
@@ -67,37 +105,66 @@ export default function Package({
67
105
  });
68
106
  const { environmentName, packageName, versionId } =
69
107
  parseResourceUri(resourceUri);
108
+ const openDocument =
109
+ onOpenDocument ??
110
+ ((request: OpenDocumentRequest, event?: React.MouseEvent) => {
111
+ const to = `${documentRoute(environmentName, packageName, request.kind, request.slug)}${request.mode === "edit" ? "/edit" : ""}`;
112
+ // Without an event, called exactly as before this hook existed.
113
+ if (event) onClick(to, event);
114
+ else onClick(to);
115
+ });
70
116
 
71
117
  const [schemaDatabase, setSchemaDatabase] = useState<Database | null>(null);
72
- const [creating, setCreating] = useState(false);
118
+ const [creating, setCreating] = useState<DocumentType | undefined>(
119
+ undefined,
120
+ );
121
+ const [newMenu, setNewMenu] = useState<HTMLElement | null>(null);
122
+ const narrow = useNarrowScreen();
73
123
 
74
- // Dashboards the host keeps for this package and the package does not have:
75
- // the builder's drafts, listed so they are found rather than stumbled on.
124
+ // Dashboards and notebooks the host keeps for this package and the package
125
+ // does not have: the builder's drafts, listed so they are found rather than
126
+ // stumbled on.
76
127
  // Each carries the workspace's own description, because where a document is
77
128
  // kept is the backend's to say and only one host's answer is "this browser".
78
129
  const storage = useOptionalDocumentStorage()?.documentStorage;
79
130
  const [drafts, setDrafts] = useState<
80
131
  { locator: DocumentLocator; where: string }[]
81
132
  >([]);
82
- const draftPrefix = `${environmentName}/${packageName}/dashboards/`;
133
+ // Where a create may land is the chosen workspace's to say, so New waits
134
+ // for the answer; a host whose workspaces cannot be listed gets no New
135
+ // rather than a guess that could write the package under its record.
136
+ const [workspace, setWorkspace] = useState<
137
+ { state: "pending" | "failed" } | { state: "ready"; chosen?: Workspace }
138
+ >({ state: storage ? "pending" : "ready" });
83
139
  const refreshDrafts = useCallback(async () => {
84
140
  if (!storage) return;
85
- const workspaces = await storage.listWorkspaces(true);
141
+ let workspaces: Workspace[];
142
+ try {
143
+ workspaces = await storage.listWorkspaces(false);
144
+ } catch {
145
+ setWorkspace({ state: "failed" });
146
+ return;
147
+ }
148
+ setWorkspace({ state: "ready", chosen: chooseWorkspace(workspaces) });
86
149
  const found: { locator: DocumentLocator; where: string }[] = [];
87
- for (const workspace of workspaces)
88
- for (const locator of await storage.listDocuments(
89
- workspace,
90
- "dashboard",
91
- ))
92
- if (locator.path.startsWith(draftPrefix))
93
- found.push({ locator, where: workspace.description });
150
+ for (const candidate of workspaces.filter((w) => w.writeable))
151
+ for (const kind of ["dashboard", "notebook"] as const)
152
+ for (const locator of await storage.listDocuments(candidate, kind))
153
+ if (
154
+ locator.path.startsWith(
155
+ draftPrefix(environmentName, packageName, kind),
156
+ )
157
+ )
158
+ found.push({ locator, where: candidate.description });
94
159
  setDrafts(found);
95
- }, [storage, draftPrefix]);
160
+ }, [storage, environmentName, packageName]);
96
161
  useEffect(() => {
97
162
  void refreshDrafts();
98
163
  }, [refreshDrafts]);
99
164
  const draftSlug = (locator: DocumentLocator) =>
100
- locator.path.slice(draftPrefix.length).replace(/\.malloy$/, "");
165
+ locator.path
166
+ .slice(draftPrefix(environmentName, packageName, locator.type).length)
167
+ .replace(/\.malloy$/, "");
101
168
 
102
169
  const pkgQuery = useQueryWithApiError({
103
170
  queryKey: ["package", environmentName, packageName, versionId],
@@ -112,12 +179,26 @@ export default function Package({
112
179
 
113
180
  const notebooksQuery = useQueryWithApiError({
114
181
  queryKey: ["notebooks", environmentName, packageName, versionId],
115
- queryFn: () =>
116
- apiClients.notebooks.listNotebooks(
117
- environmentName,
118
- packageName,
119
- versionId,
120
- ),
182
+ queryFn: async () => {
183
+ try {
184
+ return await apiClients.notebooks.listNotebooks(
185
+ environmentName,
186
+ packageName,
187
+ versionId,
188
+ );
189
+ } catch (e) {
190
+ // Non-fatal like the dashboards list: an older Publisher without
191
+ // the route has no notebooks to list.
192
+ const status = (e as { response?: { status?: number } })?.response
193
+ ?.status;
194
+ if (status === 404 || status === undefined) {
195
+ return { data: [] } as Awaited<
196
+ ReturnType<typeof apiClients.notebooks.listNotebooks>
197
+ >;
198
+ }
199
+ throw e;
200
+ }
201
+ },
121
202
  });
122
203
 
123
204
  const modelsQuery = useQueryWithApiError({
@@ -195,28 +276,12 @@ export default function Package({
195
276
  }
196
277
  },
197
278
  });
198
- // Sorted by the string the row actually SHOWS, not by the slug or the path
199
- // underneath it. A list labelled by title and ordered by filename reads as
200
- // unsorted: `overview` titled "Business Overview" sorts ahead of `regions`
201
- // titled "Regional Sales". Notebooks acquired that mismatch here too, when
202
- // they started being listed by title while still being ordered by path.
203
- const dashboardLabel = (dashboard: { name?: string; title?: string }) =>
204
- dashboard.title && dashboard.title !== dashboard.name
205
- ? dashboard.title
206
- : (dashboard.name ?? "");
207
- const notebookLabel = (notebook: { path?: string; title?: string }) =>
208
- notebook.title && notebook.title !== notebook.path
209
- ? notebook.title
210
- : (notebook.path ?? "");
211
-
212
- const dashboards = (dashboardsQuery.data?.data ?? [])
213
- .slice()
214
- .sort((a, b) => dashboardLabel(a).localeCompare(dashboardLabel(b)));
215
-
279
+ const dashboards = dashboardsQuery.data?.data ?? [];
216
280
  const notebooks = (notebooksQuery.data?.data ?? [])
217
281
  .slice()
218
- .sort((a, b) => notebookLabel(a).localeCompare(notebookLabel(b)));
219
- // A dashboard is listed once, under Dashboards. Its file is a model like any
282
+ .sort((a, b) => (a.path ?? "").localeCompare(b.path ?? ""));
283
+ const artifacts = artifactRows(dashboards, notebooks);
284
+ // A dashboard is listed once, under Artifacts. Its file is a model like any
220
285
  // other, so it would otherwise appear a second time under Semantic Models
221
286
  // where clicking it opens the Explorer rather than the dashboard. Untagged
222
287
  // shared includes in `dashboards/` are not dashboards and stay in the model
@@ -234,6 +299,74 @@ export default function Package({
234
299
  .slice()
235
300
  .sort((a, b) => a.path.localeCompare(b.path));
236
301
 
302
+ // A non-authoritative browser workspace is never a create target: a
303
+ // document made there would look saved and exist for one reader only.
304
+ const route =
305
+ workspace.state === "ready"
306
+ ? createRoute({
307
+ authoritative: workspace.chosen?.authoritative === true,
308
+ mutable,
309
+ canStore: workspace.chosen?.writeable === true,
310
+ ...(versionId === undefined ? {} : { versionId }),
311
+ })
312
+ : undefined;
313
+ // A name is chosen against the listings, so New waits for all three rather than offering names a still-loading listing would have taken.
314
+ const listingsSettled = [dashboardsQuery, notebooksQuery, modelsQuery].every(
315
+ (q) => q.isSuccess || q.isError,
316
+ );
317
+ const canCreate = route !== undefined && listingsSettled;
318
+ // The editors step aside on a narrow screen, so no entry point to one is offered there.
319
+ const canNew = canCreate && !narrow;
320
+ const createTarget = useMemo((): CreateTarget | undefined => {
321
+ if (!canCreate) return undefined;
322
+ const existing = [
323
+ ...(dashboardsQuery.data?.data ?? []).flatMap((d) =>
324
+ d.path ? [d.path] : [],
325
+ ),
326
+ ...(notebooksQuery.data?.data ?? []).flatMap((n) =>
327
+ n.path ? [n.path] : [],
328
+ ),
329
+ ...(modelsQuery.data?.data ?? []).flatMap((m) =>
330
+ m.path ? [m.path] : [],
331
+ ),
332
+ ];
333
+ if (route === "storage" && storage && workspace.state === "ready") {
334
+ if (!workspace.chosen) return undefined;
335
+ return {
336
+ route,
337
+ storage,
338
+ workspace: workspace.chosen,
339
+ environmentName,
340
+ packageName,
341
+ existing,
342
+ };
343
+ }
344
+ if (route !== "package") return undefined;
345
+ return {
346
+ route,
347
+ existing,
348
+ write: async (path, source) => {
349
+ await apiClients.models.updateModelSource(
350
+ environmentName,
351
+ packageName,
352
+ path,
353
+ { source },
354
+ );
355
+ },
356
+ };
357
+ }, [
358
+ canCreate,
359
+ route,
360
+ storage,
361
+ workspace,
362
+ environmentName,
363
+ packageName,
364
+ apiClients,
365
+ dashboardsQuery.data,
366
+ notebooksQuery.data,
367
+ modelsQuery.data,
368
+ ]);
369
+
237
370
  const description = pkgQuery.data?.data?.description ?? "";
238
371
  // The root `.malloynb` wins when both exist, so a listing order never flips the pin.
239
372
  const readmePath = (
@@ -287,10 +420,6 @@ export default function Package({
287
420
  sx={{ maxWidth: 1024, mx: "auto", px: 3, py: 6 }}
288
421
  >
289
422
  <Box sx={{ mb: 4 }}>
290
- <BackLink
291
- label={environmentName}
292
- onClick={(event) => onClick(`/${environmentName}/`, event)}
293
- />
294
423
  <Typography
295
424
  variant="h4"
296
425
  component="h1"
@@ -311,111 +440,163 @@ export default function Package({
311
440
 
312
441
  {isLoading && <Loading text="Loading package..." />}
313
442
 
314
- <NewDashboardDialog
315
- open={creating}
316
- environmentName={environmentName}
317
- packageName={packageName}
318
- models={models
319
- .map((model) => model.path)
320
- .filter(
321
- (path): path is string =>
322
- typeof path === "string" &&
323
- path.endsWith(".malloy") &&
324
- !path.startsWith("dashboards/"),
325
- )}
326
- existing={dashboards
327
- .map((dashboard) => dashboard.name)
328
- .filter((name): name is string => typeof name === "string")}
329
- onClose={() => setCreating(false)}
330
- onCreated={(slug) => {
331
- setCreating(false);
332
- void queryClient.invalidateQueries({ queryKey: ["dashboards"] });
333
- onClick(
334
- `/${environmentName}/${packageName}/dashboards/${encodeURIComponent(slug)}/edit`,
335
- );
336
- }}
337
- />
443
+ <Menu
444
+ anchorEl={newMenu}
445
+ open={newMenu !== null}
446
+ onClose={() => setNewMenu(null)}
447
+ >
448
+ {(["dashboard", "notebook"] as const).map((kind) => (
449
+ <MenuItem
450
+ key={kind}
451
+ onClick={() => {
452
+ setNewMenu(null);
453
+ setCreating(kind);
454
+ }}
455
+ >
456
+ {kind === "dashboard" ? "Dashboard" : "Notebook"}
457
+ </MenuItem>
458
+ ))}
459
+ </Menu>
460
+
461
+ {createTarget && (
462
+ <NewDocumentDialog
463
+ open={creating !== undefined}
464
+ kind={creating ?? "dashboard"}
465
+ environmentName={environmentName}
466
+ packageName={packageName}
467
+ {...(versionId !== undefined ? { versionId } : {})}
468
+ models={models
469
+ .map((model) => model.path)
470
+ .filter(
471
+ (path): path is string =>
472
+ typeof path === "string" &&
473
+ path.endsWith(".malloy") &&
474
+ !path.startsWith("dashboards/") &&
475
+ !path.startsWith("notebooks/"),
476
+ )}
477
+ modelsLoading={modelsQuery.isPending}
478
+ {...(modelsQuery.isError
479
+ ? { modelsError: modelsQuery.error }
480
+ : {})}
481
+ onRetryModels={() => void modelsQuery.refetch()}
482
+ target={createTarget}
483
+ onClose={() => setCreating(undefined)}
484
+ onCreated={(created) => {
485
+ setCreating(undefined);
486
+ for (const key of ["dashboards", "notebooks", "models"])
487
+ void queryClient.invalidateQueries({ queryKey: [key] });
488
+ openDocument({
489
+ kind: created.kind,
490
+ slug: created.slug,
491
+ mode: "edit",
492
+ });
493
+ }}
494
+ />
495
+ )}
338
496
 
339
497
  {!isLoading && (
340
498
  <>
341
- {/* First: the at-a-glance artifact a visitor most likely wants,
342
- ahead of the notebooks and models it is built on. Hidden when
343
- empty, like Data Apps. */}
344
499
  {/* A listing that FAILED renders identically to a package with
345
- no dashboards: `dashboards` falls back to `[]` and the
346
- section hides itself. Only `pkgQuery` reaches the error page,
347
- so nothing else here would say a word. Now that the listing
348
- carries a `versionId`, a host that resolves it on some routes
349
- and refuses it on others has a new way in, and "this package
350
- has no dashboards" is the wrong thing to conclude from a
351
- transport error. The 404 above stays swallowed: that one is
352
- an older Publisher with no route, which genuinely has none. */}
353
- {dashboardsQuery.isError && (
500
+ none: the list falls back to `[]` and the section hides
501
+ itself. Only `pkgQuery` reaches the error page, so nothing
502
+ else here would say a word, and one failed list hides only
503
+ half the artifacts. The 404 swallowed in each query is an
504
+ older Publisher with no route, which genuinely has none. */}
505
+ {(dashboardsQuery.isError || notebooksQuery.isError) && (
354
506
  <Box sx={{ mb: 4 }}>
355
507
  <Alert severity="warning">
356
- Could not list this package&apos;s dashboards, so any it
357
- has are missing from this page.
508
+ Could not list some artifacts, so any this package has
509
+ are missing from this page.
358
510
  </Alert>
359
511
  </Box>
360
512
  )}
361
- {(dashboards.length > 0 || mutable) && (
513
+ {(artifacts.length > 0 || canCreate) && (
362
514
  <PackageSection
363
- title="Dashboards"
364
- count={dashboards.length}
365
- action={
366
- mutable ? (
367
- <AddButton
368
- label="Dashboard"
369
- onClick={() => setCreating(true)}
370
- />
371
- ) : undefined
372
- }
515
+ title="Artifacts"
516
+ count={artifacts.length}
517
+ {...(canNew
518
+ ? {
519
+ action: (
520
+ <Button
521
+ variant="outlined"
522
+ size="small"
523
+ endIcon={<ArrowDropDownIcon />}
524
+ aria-haspopup="menu"
525
+ aria-label="New"
526
+ onClick={(event) =>
527
+ setNewMenu(event.currentTarget)
528
+ }
529
+ >
530
+ New
531
+ </Button>
532
+ ),
533
+ }
534
+ : {})}
373
535
  >
374
- {dashboards.length === 0 && (
375
- <EmptyRow label="No dashboards yet" />
536
+ {artifacts.length === 0 && (
537
+ <EmptyRow
538
+ label="No artifacts yet"
539
+ {...(canNew
540
+ ? {
541
+ action: {
542
+ label: "New artifact",
543
+ onClick: (event) =>
544
+ setNewMenu(event.currentTarget),
545
+ },
546
+ }
547
+ : {})}
548
+ />
376
549
  )}
377
- {dashboards.map((dashboard) => {
378
- // A title equal to the slug is what the server falls
379
- // back to when the file names itself neither way, so
380
- // showing both would print the same word twice.
381
- const hasTitle =
382
- !!dashboard.title &&
383
- dashboard.title !== dashboard.name;
384
- return (
385
- <PackageItemRow
386
- key={dashboard.name}
387
- type="dashboard"
388
- label={
389
- hasTitle ? dashboard.title! : dashboard.name!
390
- }
391
- rightLabel={hasTitle ? dashboard.name : undefined}
392
- onClick={(event) =>
393
- onClick(
394
- `/${environmentName}/${packageName}/dashboards/` +
395
- // The slug comes from a filename, which
396
- // can hold characters that would read as
397
- // structure in a path. The server encodes
398
- // it in `resource` for the same reason.
399
- encodeURIComponent(dashboard.name ?? ""),
400
- event,
401
- )
402
- }
403
- />
404
- );
405
- })}
550
+ {artifacts.map((artifact) => (
551
+ <PackageItemRow
552
+ key={`${artifact.kind}:${artifact.path}`}
553
+ type={
554
+ artifact.kind === "dashboard"
555
+ ? "dashboard"
556
+ : "report"
557
+ }
558
+ label={artifact.label}
559
+ {...(artifact.secondary === undefined
560
+ ? {}
561
+ : { description: artifact.secondary })}
562
+ onClick={(event) =>
563
+ artifact.slug === undefined
564
+ ? onClick(
565
+ `/${environmentName}/${packageName}/${artifact.path}`,
566
+ event,
567
+ )
568
+ : openDocument(
569
+ {
570
+ kind: artifact.kind,
571
+ slug: artifact.slug,
572
+ mode: "view",
573
+ },
574
+ event,
575
+ )
576
+ }
577
+ />
578
+ ))}
406
579
  </PackageSection>
407
580
  )}
408
581
  {drafts.length > 0 && (
409
582
  <PackageSection title="Drafts" count={drafts.length}>
410
583
  {drafts.map(({ locator, where }) => (
411
584
  <PackageItemRow
412
- key={locator.path}
413
- type="dashboard"
585
+ key={`${locator.type}:${locator.path}`}
586
+ type={
587
+ locator.type === "dashboard"
588
+ ? "dashboard"
589
+ : "report"
590
+ }
414
591
  label={draftSlug(locator)}
415
592
  rightLabel={where}
416
593
  onClick={(event) =>
417
- onClick(
418
- `/${environmentName}/${packageName}/dashboards/${encodeURIComponent(draftSlug(locator))}/edit`,
594
+ openDocument(
595
+ {
596
+ kind: locator.type,
597
+ slug: draftSlug(locator),
598
+ mode: "edit",
599
+ },
419
600
  event,
420
601
  )
421
602
  }
@@ -440,40 +621,6 @@ export default function Package({
440
621
  </PackageSection>
441
622
  )}
442
623
 
443
- {/* Hidden when empty, like Dashboards and Data Apps. A package
444
- that holds no notebooks is not a package missing them, and a
445
- heading over the words "No notebooks" is a row of furniture
446
- saying nothing. */}
447
- {notebooks.length > 0 && (
448
- <PackageSection title="Notebooks" count={notebooks.length}>
449
- {notebooks.map((notebook) => {
450
- // Named the way dashboards and data apps are: a notebook
451
- // that titles itself is listed by that title, with the
452
- // filename kept as the secondary label so the path a
453
- // reader needs to find the file is never lost.
454
- const hasTitle =
455
- !!notebook.title && notebook.title !== notebook.path;
456
- const slug = servedNotebookSlug(notebook.path);
457
- return (
458
- <PackageItemRow
459
- key={notebook.path}
460
- type="report"
461
- label={hasTitle ? notebook.title! : notebook.path}
462
- rightLabel={hasTitle ? notebook.path : undefined}
463
- onClick={(event) =>
464
- onClick(
465
- slug === undefined
466
- ? `/${environmentName}/${packageName}/${notebook.path}`
467
- : `/${environmentName}/${packageName}/notebooks/${encodeURIComponent(slug)}`,
468
- event,
469
- )
470
- }
471
- />
472
- );
473
- })}
474
- </PackageSection>
475
- )}
476
-
477
624
  {dataApps.length > 0 && (
478
625
  <PackageSection title="Data Apps" count={dataApps.length}>
479
626
  {dataApps.map((dataApp) => {
@@ -628,12 +775,14 @@ export default function Package({
628
775
  function PackageItemRow({
629
776
  type,
630
777
  label,
778
+ description,
631
779
  rightLabel,
632
780
  onClick,
633
781
  trailingAction,
634
782
  }: {
635
783
  type: ContentType;
636
784
  label: string;
785
+ description?: string;
637
786
  rightLabel?: string;
638
787
  onClick?: (event: React.MouseEvent) => void;
639
788
  /** Optional element rendered at the end of the row (e.g. an
@@ -647,6 +796,7 @@ function PackageItemRow({
647
796
  tint={CONTENT_TINT[type]}
648
797
  label={label}
649
798
  mono
799
+ {...(description === undefined ? {} : { description })}
650
800
  {...(rightLabel === undefined ? {} : { rightLabel })}
651
801
  {...(onClick === undefined ? {} : { onClick })}
652
802
  {...(trailingAction === undefined ? {} : { trailingAction })}
@@ -654,15 +804,84 @@ function PackageItemRow({
654
804
  );
655
805
  }
656
806
 
657
- function EmptyRow({ label }: { label: string }) {
807
+ interface ArtifactRow {
808
+ kind: DocumentKind;
809
+ path: string;
810
+ /** Absent for a `.malloynb`, which opens by path. */
811
+ slug: string | undefined;
812
+ label: string;
813
+ /** The path, when the label alone does not say which file this is. */
814
+ secondary: string | undefined;
815
+ }
816
+
817
+ /** Dashboards and notebooks as one list: the title when set, else the slug, ordered by what is shown. */
818
+ function artifactRows(
819
+ dashboards: readonly { name?: string; path?: string; title?: string }[],
820
+ notebooks: readonly { path?: string; title?: string }[],
821
+ ): ArtifactRow[] {
822
+ const rows = [
823
+ ...dashboards.map((d) => ({
824
+ kind: "dashboard" as const,
825
+ path: d.path ?? "",
826
+ slug: d.name ?? documentSlug(d.path),
827
+ title: d.title,
828
+ })),
829
+ ...notebooks.map((n) => ({
830
+ kind: "notebook" as const,
831
+ path: n.path ?? "",
832
+ slug: documentSlug(n.path),
833
+ title: n.title,
834
+ })),
835
+ ];
836
+ const slugCount = new Map<string, number>();
837
+ for (const row of rows)
838
+ if (row.slug !== undefined)
839
+ slugCount.set(row.slug, (slugCount.get(row.slug) ?? 0) + 1);
840
+ return rows
841
+ .map(({ title, ...row }): ArtifactRow => {
842
+ // A title equal to the slug or path is the server's fallback for a file that names itself neither way.
843
+ const hasTitle = !!title && title !== row.slug && title !== row.path;
844
+ const ambiguous =
845
+ row.slug !== undefined && (slugCount.get(row.slug) ?? 0) > 1;
846
+ return {
847
+ ...row,
848
+ label: hasTitle ? title : (row.slug ?? row.path),
849
+ secondary: (row.slug === undefined ? hasTitle : ambiguous)
850
+ ? row.path
851
+ : undefined,
852
+ };
853
+ })
854
+ .sort(
855
+ (a, b) =>
856
+ a.label.localeCompare(b.label) || a.path.localeCompare(b.path),
857
+ );
858
+ }
859
+
860
+ function EmptyRow({
861
+ label,
862
+ action,
863
+ }: {
864
+ label: string;
865
+ action?: {
866
+ label: string;
867
+ onClick: (event: React.MouseEvent<HTMLElement>) => void;
868
+ };
869
+ }) {
658
870
  return (
659
- <Typography
660
- variant="body2"
661
- color="text.secondary"
662
- sx={{ py: 1, fontStyle: "italic" }}
663
- >
664
- {label}
665
- </Typography>
871
+ <Stack direction="row" sx={{ alignItems: "center", gap: 1, py: 1 }}>
872
+ <Typography
873
+ variant="body2"
874
+ color="text.secondary"
875
+ sx={{ fontStyle: "italic" }}
876
+ >
877
+ {label}
878
+ </Typography>
879
+ {action && (
880
+ <Button size="small" onClick={action.onClick}>
881
+ {action.label}
882
+ </Button>
883
+ )}
884
+ </Stack>
666
885
  );
667
886
  }
668
887