@malloy-publisher/sdk 0.9.7 → 0.9.8

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 (350) hide show
  1. package/README.md +117 -17
  2. package/dist/{RenderedResult-qnpbr4tc.cjs.js → RenderedResult-BrvrMDAP.cjs.js} +1 -1
  3. package/dist/{RenderedResult-CkUS04tl.es.js → RenderedResult-DZj-FnOJ.es.js} +2 -2
  4. package/dist/{ServerProvider-DnLLeXEX.es.js → ServerProvider-B_bPAsu2.es.js} +583 -398
  5. package/dist/ServerProvider-DuEOzwPc.cjs.js +1 -0
  6. package/dist/builder/index.cjs.js +93 -93
  7. package/dist/builder/index.es.js +4630 -4562
  8. package/dist/builder-entry.d.ts +13 -12
  9. package/dist/client/api.d.ts +472 -94
  10. package/dist/client/index.cjs.js +1 -1
  11. package/dist/client/index.es.js +105 -95
  12. package/dist/components/Dashboard/DashboardTile.d.ts +3 -1
  13. package/dist/components/Dashboard/DashboardView.d.ts +1 -3
  14. package/dist/components/Dashboard/index.d.ts +0 -2
  15. package/dist/components/DocumentCreate/createDocument.d.ts +29 -9
  16. package/dist/components/DocumentCreate/documentPath.d.ts +21 -6
  17. package/dist/components/DocumentCreate/guards.d.ts +2 -3
  18. package/dist/components/DocumentCreate/index.d.ts +2 -3
  19. package/dist/components/DocumentCreate/newNotebook.d.ts +14 -5
  20. package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +6 -0
  21. package/dist/components/DocumentStorage/DocumentStorage.d.ts +52 -24
  22. package/dist/components/Loading.d.ts +1 -1
  23. package/dist/components/Package/DataSchemaDialog.d.ts +26 -0
  24. package/dist/components/Package/NewDocumentDialog.d.ts +19 -10
  25. package/dist/components/Package/Package.d.ts +14 -9
  26. package/dist/components/Package/documentLocation.d.ts +66 -23
  27. package/dist/components/Package/index.d.ts +3 -2
  28. package/dist/components/Package/reportQueries.d.ts +8 -0
  29. package/dist/components/Package/useDocumentLocation.d.ts +36 -6
  30. package/dist/components/Package/useDraftLayout.d.ts +20 -0
  31. package/dist/components/Report/CellReport.d.ts +89 -0
  32. package/dist/components/Report/LinearReport.d.ts +18 -0
  33. package/dist/components/Report/Report.d.ts +62 -0
  34. package/dist/components/Report/index.d.ts +2 -0
  35. package/dist/components/Report/telemetry.d.ts +163 -0
  36. package/dist/components/{DashboardBuilder → ReportBuilder}/BuilderDialogs.d.ts +2 -2
  37. package/dist/components/{DashboardBuilder → ReportBuilder}/BuilderGrid.d.ts +2 -2
  38. package/dist/components/{DashboardBuilder → ReportBuilder}/BuilderHeader.d.ts +5 -4
  39. package/dist/components/{DashboardBuilder → ReportBuilder}/BuilderToolbar.d.ts +5 -1
  40. package/dist/components/{DashboardBuilder → ReportBuilder}/EditorSurface.d.ts +10 -7
  41. package/dist/components/{DashboardBuilder/DashboardBuilder.d.ts → ReportBuilder/ReportBuilder.d.ts} +17 -8
  42. package/dist/components/{DashboardBuilder/DashboardEditor.d.ts → ReportBuilder/ReportEditor.d.ts} +41 -14
  43. package/dist/components/ReportBuilder/builderReport.d.ts +14 -0
  44. package/dist/components/{DashboardBuilder → ReportBuilder}/catalog.d.ts +8 -5
  45. package/dist/components/{DashboardBuilder → ReportBuilder}/document.d.ts +3 -4
  46. package/dist/components/{DashboardBuilder → ReportBuilder}/documentSession.d.ts +1 -1
  47. package/dist/components/{DashboardBuilder → ReportBuilder}/imports.d.ts +5 -1
  48. package/dist/components/{DashboardBuilder → ReportBuilder}/malloyTree.d.ts +9 -0
  49. package/dist/components/{DashboardBuilder → ReportBuilder}/newDashboard.d.ts +7 -1
  50. package/dist/components/{DashboardBuilder → ReportBuilder}/readDocument.d.ts +7 -5
  51. package/dist/components/{DashboardBuilder → ReportBuilder}/readForEditor.d.ts +1 -1
  52. package/dist/components/ReportBuilder/reportTag.d.ts +52 -0
  53. package/dist/components/{DashboardBuilder → ReportBuilder}/spliceDocument.d.ts +1 -7
  54. package/dist/components/{DashboardBuilder → ReportBuilder}/useBuilderSelection.d.ts +2 -2
  55. package/dist/components/{DashboardBuilder → ReportBuilder}/useControlBindings.d.ts +2 -2
  56. package/dist/components/ReportBuilder/useEditorCatalog.d.ts +25 -0
  57. package/dist/components/{DashboardBuilder → ReportBuilder}/useHostCopy.d.ts +5 -3
  58. package/dist/components/{DashboardBuilder → ReportBuilder}/useOpenedDocument.d.ts +7 -5
  59. package/dist/components/{DashboardBuilder/useDashboardEditor.d.ts → ReportBuilder/useReportEditor.d.ts} +3 -7
  60. package/dist/components/{DashboardBuilder → ReportBuilder}/useSaveChannel.d.ts +6 -4
  61. package/dist/components/{DashboardBuilder → ReportBuilder}/useTileEditing.d.ts +2 -2
  62. package/dist/components/ServerProvider.d.ts +2 -1
  63. package/dist/components/drill/resolveDrill.d.ts +8 -1
  64. package/dist/components/drill/useDrillSelf.d.ts +4 -2
  65. package/dist/components/index.d.ts +2 -1
  66. package/dist/components/{Dashboard → legacy}/Dashboard.d.ts +15 -9
  67. package/dist/components/legacy/MalloynbCells.d.ts +13 -0
  68. package/dist/components/legacy/Notebook.d.ts +15 -0
  69. package/dist/components/{DashboardBuilder → legacy}/NotebookEditor.d.ts +3 -3
  70. package/dist/components/legacy/builderNames.d.ts +10 -0
  71. package/dist/components/legacy/index.d.ts +11 -0
  72. package/dist/components/legacy/kindAdapter.d.ts +11 -0
  73. package/dist/components/legacy/kindTypedDrafts.d.ts +10 -0
  74. package/dist/components/legacy/nameAlias.d.ts +44 -0
  75. package/dist/components/legacy/queryKeys.d.ts +8 -0
  76. package/dist/index.cjs.js +19 -19
  77. package/dist/index.es.js +7984 -7452
  78. package/dist/text/index.es.js +2 -2
  79. package/dist/{text-entry-CA0LZ1xL.es.js → text-entry-72YFLeNk.es.js} +10 -10
  80. package/dist/useCompiledDocument-oocN5cGE.cjs.js +141 -0
  81. package/dist/{useCompiledDocument-Bf72Ob5v.es.js → useCompiledDocument-x0B2RAH3.es.js} +4593 -4395
  82. package/package.json +2 -2
  83. package/src/builder-entry.ts +32 -24
  84. package/src/components/Dashboard/DashboardTile.tsx +17 -0
  85. package/src/components/Dashboard/DashboardView.spec.tsx +0 -21
  86. package/src/components/Dashboard/DashboardView.tsx +8 -24
  87. package/src/components/Dashboard/dropValueUrlTags.spec.ts +1 -4
  88. package/src/components/Dashboard/index.ts +0 -2
  89. package/src/components/DocumentCreate/createDocument.spec.ts +346 -53
  90. package/src/components/DocumentCreate/createDocument.ts +143 -63
  91. package/src/components/DocumentCreate/documentPath.ts +41 -12
  92. package/src/components/DocumentCreate/guards.ts +7 -15
  93. package/src/components/DocumentCreate/index.ts +3 -7
  94. package/src/components/DocumentCreate/newNotebook.spec.ts +113 -43
  95. package/src/components/DocumentCreate/newNotebook.ts +32 -10
  96. package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +130 -28
  97. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +78 -40
  98. package/src/components/DocumentStorage/DocumentStorage.contract.spec.tsx +426 -0
  99. package/src/components/DocumentStorage/DocumentStorage.ts +57 -24
  100. package/src/components/Home/AddEnvironmentDialog.tsx +1 -1
  101. package/src/components/Home/Home.tsx +1 -1
  102. package/src/components/Loading.tsx +1 -1
  103. package/src/components/Model/SourcesExplorer.tsx +1 -1
  104. package/src/components/Notebook/NotebookCell.tsx +6 -5
  105. package/src/components/Notebook/cellKind.spec.ts +15 -7
  106. package/src/components/Package/DataSchemaDialog.spec.tsx +85 -0
  107. package/src/components/Package/DataSchemaDialog.tsx +367 -0
  108. package/src/components/Package/NewDocumentDialog.spec.tsx +145 -88
  109. package/src/components/Package/NewDocumentDialog.tsx +93 -48
  110. package/src/components/Package/Package.artifacts.spec.tsx +79 -60
  111. package/src/components/Package/Package.create.spec.tsx +126 -112
  112. package/src/components/Package/Package.notebooks.spec.tsx +46 -27
  113. package/src/components/Package/Package.spec.tsx +43 -30
  114. package/src/components/Package/Package.tsx +173 -292
  115. package/src/components/Package/documentLocation.spec.ts +145 -50
  116. package/src/components/Package/documentLocation.ts +118 -39
  117. package/src/components/Package/index.ts +12 -3
  118. package/src/components/Package/reportQueries.ts +25 -0
  119. package/src/components/Package/useDocumentLocation.spec.ts +58 -0
  120. package/src/components/Package/useDocumentLocation.ts +90 -32
  121. package/src/components/Package/useDraftLayout.spec.tsx +143 -0
  122. package/src/components/Package/useDraftLayout.ts +81 -0
  123. package/src/components/Prose.spec.tsx +3 -3
  124. package/src/components/RenderedResult/RenderedResult.tsx +1 -1
  125. package/src/components/Report/CellReport.spec.tsx +155 -0
  126. package/src/components/{Notebook/Notebook.tsx → Report/CellReport.tsx} +178 -220
  127. package/src/components/Report/LinearReport.tsx +71 -0
  128. package/src/components/Report/Report.spec.tsx +238 -0
  129. package/src/components/Report/Report.telemetry.spec.tsx +292 -0
  130. package/src/components/Report/Report.tsx +277 -0
  131. package/src/components/Report/index.ts +12 -0
  132. package/src/components/Report/telemetry.spec.ts +90 -0
  133. package/src/components/Report/telemetry.ts +250 -0
  134. package/src/components/{DashboardBuilder → ReportBuilder}/BuilderDialogs.tsx +5 -5
  135. package/src/components/{DashboardBuilder → ReportBuilder}/BuilderGrid.tsx +2 -2
  136. package/src/components/{DashboardBuilder → ReportBuilder}/BuilderHeader.tsx +6 -7
  137. package/src/components/{DashboardBuilder → ReportBuilder}/BuilderToolbar.tsx +33 -0
  138. package/src/components/{DashboardBuilder → ReportBuilder}/DrillDialog.tsx +2 -2
  139. package/src/components/{DashboardBuilder → ReportBuilder}/EditorSurface.tsx +67 -107
  140. package/src/components/{DashboardBuilder → ReportBuilder}/FilterDialog.tsx +3 -4
  141. package/src/components/{DashboardBuilder/DashboardBuilder.charts.spec.tsx → ReportBuilder/ReportBuilder.charts.spec.tsx} +4 -4
  142. package/src/components/{DashboardBuilder/DashboardBuilder.exit.spec.tsx → ReportBuilder/ReportBuilder.exit.spec.tsx} +5 -5
  143. package/src/components/{DashboardBuilder/DashboardBuilder.inline.spec.tsx → ReportBuilder/ReportBuilder.inline.spec.tsx} +4 -4
  144. package/src/components/ReportBuilder/ReportBuilder.layoutSwitch.spec.tsx +145 -0
  145. package/src/components/{DashboardBuilder/DashboardBuilder.notebook.spec.tsx → ReportBuilder/ReportBuilder.notebook.spec.tsx} +22 -21
  146. package/src/components/{DashboardBuilder/DashboardBuilder.openDraft.spec.tsx → ReportBuilder/ReportBuilder.openDraft.spec.tsx} +3 -3
  147. package/src/components/{DashboardBuilder/DashboardBuilder.sources.spec.tsx → ReportBuilder/ReportBuilder.sources.spec.tsx} +19 -8
  148. package/src/components/{DashboardBuilder/DashboardBuilder.spec.tsx → ReportBuilder/ReportBuilder.spec.tsx} +34 -34
  149. package/src/components/{DashboardBuilder/DashboardBuilder.textTiles.spec.tsx → ReportBuilder/ReportBuilder.textTiles.spec.tsx} +5 -5
  150. package/src/components/{DashboardBuilder/DashboardBuilder.tsx → ReportBuilder/ReportBuilder.tsx} +46 -21
  151. package/src/components/{DashboardBuilder/DashboardEditor.authoritative.spec.tsx → ReportBuilder/ReportEditor.authoritative.spec.tsx} +28 -20
  152. package/src/components/{DashboardBuilder/DashboardEditor.emptyStart.spec.tsx → ReportBuilder/ReportEditor.emptyStart.spec.tsx} +19 -11
  153. package/src/components/{DashboardBuilder/DashboardEditor.filterTag.spec.tsx → ReportBuilder/ReportEditor.filterTag.spec.tsx} +7 -7
  154. package/src/components/{DashboardBuilder/DashboardEditor.notebook.spec.tsx → ReportBuilder/ReportEditor.notebook.spec.tsx} +70 -49
  155. package/src/components/{DashboardBuilder/DashboardEditor.package.spec.tsx → ReportBuilder/ReportEditor.package.spec.tsx} +52 -8
  156. package/src/components/{DashboardBuilder/DashboardEditor.resourceUri.spec.tsx → ReportBuilder/ReportEditor.resourceUri.spec.tsx} +50 -18
  157. package/src/components/{DashboardBuilder/DashboardEditor.spec.tsx → ReportBuilder/ReportEditor.spec.tsx} +65 -20
  158. package/src/components/{DashboardBuilder/DashboardEditor.textSource.spec.tsx → ReportBuilder/ReportEditor.textSource.spec.tsx} +6 -6
  159. package/src/components/{DashboardBuilder/DashboardEditor.tsx → ReportBuilder/ReportEditor.tsx} +92 -35
  160. package/src/components/{DashboardBuilder → ReportBuilder}/addTile.compile.spec.ts +1 -3
  161. package/src/components/{DashboardBuilder → ReportBuilder}/addTileToDocument.spec.ts +1 -0
  162. package/src/components/{DashboardBuilder → ReportBuilder}/artifactBlock.spec.ts +21 -29
  163. package/src/components/ReportBuilder/builderReport.ts +53 -0
  164. package/src/components/{DashboardBuilder → ReportBuilder}/catalog.spec.ts +28 -10
  165. package/src/components/{DashboardBuilder → ReportBuilder}/catalog.ts +17 -10
  166. package/src/components/{DashboardBuilder → ReportBuilder}/controls.spec.ts +1 -0
  167. package/src/components/{DashboardBuilder → ReportBuilder}/document.ts +4 -7
  168. package/src/components/{DashboardBuilder → ReportBuilder}/documentSession.spec.ts +5 -5
  169. package/src/components/{DashboardBuilder → ReportBuilder}/documentSession.ts +1 -1
  170. package/src/components/{DashboardBuilder → ReportBuilder}/imports.spec.ts +6 -2
  171. package/src/components/{DashboardBuilder → ReportBuilder}/imports.ts +8 -4
  172. package/src/components/{DashboardBuilder → ReportBuilder}/legacyNotebook.chart.spec.ts +1 -1
  173. package/src/components/{DashboardBuilder → ReportBuilder}/legacyNotebook.convert.spec.ts +9 -13
  174. package/src/components/{DashboardBuilder → ReportBuilder}/legacyNotebook.read.spec.ts +15 -15
  175. package/src/components/{DashboardBuilder → ReportBuilder}/legacyNotebook.ts +7 -2
  176. package/src/components/{DashboardBuilder → ReportBuilder}/malloyTree.ts +25 -0
  177. package/src/components/{DashboardBuilder → ReportBuilder}/newDashboard.spec.ts +12 -4
  178. package/src/components/{DashboardBuilder → ReportBuilder}/newDashboard.ts +11 -24
  179. package/src/components/{DashboardBuilder → ReportBuilder}/preview.spec.ts +1 -0
  180. package/src/components/{DashboardBuilder → ReportBuilder}/readDocument.spec.ts +64 -36
  181. package/src/components/{DashboardBuilder → ReportBuilder}/readDocument.ts +33 -32
  182. package/src/components/ReportBuilder/readForEditor.spec.ts +96 -0
  183. package/src/components/{DashboardBuilder → ReportBuilder}/readForEditor.ts +3 -11
  184. package/src/components/ReportBuilder/reportTag.ts +108 -0
  185. package/src/components/{DashboardBuilder → ReportBuilder}/spliceDocument.imports.spec.ts +28 -1
  186. package/src/components/{DashboardBuilder → ReportBuilder}/spliceDocument.spec.ts +32 -3
  187. package/src/components/{DashboardBuilder → ReportBuilder}/spliceDocument.ts +37 -60
  188. package/src/components/{DashboardBuilder → ReportBuilder}/tagParse.spec.ts +3 -3
  189. package/src/components/{DashboardBuilder → ReportBuilder}/testing/artifactTagParity.json +2 -2
  190. package/src/components/ReportBuilder/testing/drillResolution.json +279 -0
  191. package/src/components/ReportBuilder/testing/reportLayoutParity.json +125 -0
  192. package/src/components/{DashboardBuilder → ReportBuilder}/textTiles.spec.ts +66 -143
  193. package/src/components/{DashboardBuilder → ReportBuilder}/useBuilderSelection.ts +2 -2
  194. package/src/components/{DashboardBuilder → ReportBuilder}/useControlBindings.ts +2 -2
  195. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +156 -0
  196. package/src/components/ReportBuilder/useEditorCatalog.ts +119 -0
  197. package/src/components/{DashboardBuilder → ReportBuilder}/useHostCopy.ts +7 -5
  198. package/src/components/{DashboardBuilder → ReportBuilder}/useOpenedDocument.ts +56 -35
  199. package/src/components/{DashboardBuilder/useDashboardEditor.spec.ts → ReportBuilder/useReportEditor.spec.ts} +6 -6
  200. package/src/components/{DashboardBuilder/useDashboardEditor.ts → ReportBuilder/useReportEditor.ts} +6 -17
  201. package/src/components/{DashboardBuilder → ReportBuilder}/useSaveChannel.ts +36 -35
  202. package/src/components/{DashboardBuilder → ReportBuilder}/useTileEditing.ts +2 -2
  203. package/src/components/ServerProvider.tsx +2 -0
  204. package/src/components/drill/resolveDrill.ts +9 -2
  205. package/src/components/drill/useDrill.tsx +1 -0
  206. package/src/components/drill/useDrillSelf.spec.tsx +60 -7
  207. package/src/components/drill/useDrillSelf.ts +29 -12
  208. package/src/components/index.ts +2 -1
  209. package/src/components/{Dashboard → legacy}/Dashboard.spec.tsx +1 -1
  210. package/src/components/{Dashboard → legacy}/Dashboard.tsx +40 -28
  211. package/src/components/legacy/MalloynbCells.tsx +88 -0
  212. package/src/components/{Notebook → legacy}/Notebook.served.spec.tsx +17 -13
  213. package/src/components/{Notebook → legacy}/Notebook.spec.tsx +24 -20
  214. package/src/components/legacy/Notebook.tsx +44 -0
  215. package/src/components/{DashboardBuilder → legacy}/NotebookEditor.tsx +7 -4
  216. package/src/components/legacy/builderNames.ts +25 -0
  217. package/src/components/legacy/index.ts +20 -0
  218. package/src/components/legacy/kindAdapter.ts +19 -0
  219. package/src/components/legacy/kindTypedDrafts.ts +34 -0
  220. package/src/components/legacy/nameAlias.spec.ts +124 -0
  221. package/src/components/legacy/nameAlias.ts +95 -0
  222. package/src/components/legacy/queryKeys.ts +26 -0
  223. package/src/hooks/useGivensState.spec.ts +9 -9
  224. package/src/mainEntry.spec.ts +1 -1
  225. package/src/textEntry.spec.ts +9 -9
  226. package/src/utils/formatting.spec.ts +5 -5
  227. package/src/utils/parsing.spec.ts +1 -1
  228. package/src/utils/parsing.ts +1 -1
  229. package/dist/ServerProvider-Gj-im5VD.cjs.js +0 -1
  230. package/dist/components/Dashboard/telemetry.d.ts +0 -73
  231. package/dist/components/DashboardBuilder/builderReport.d.ts +0 -13
  232. package/dist/components/DashboardBuilder/telemetry.d.ts +0 -43
  233. package/dist/components/DocumentCreate/events.d.ts +0 -10
  234. package/dist/components/Notebook/Notebook.d.ts +0 -52
  235. package/dist/components/Notebook/index.d.ts +0 -1
  236. package/dist/useCompiledDocument-tBejqZ7s.cjs.js +0 -142
  237. package/src/components/Dashboard/telemetry.ts +0 -75
  238. package/src/components/DashboardBuilder/builderReport.ts +0 -74
  239. package/src/components/DashboardBuilder/readForEditor.spec.ts +0 -80
  240. package/src/components/DashboardBuilder/telemetry.ts +0 -47
  241. package/src/components/DashboardBuilder/testing/documentKindRule.json +0 -40
  242. package/src/components/DocumentCreate/events.ts +0 -15
  243. package/src/components/Notebook/index.ts +0 -4
  244. /package/dist/components/{DashboardBuilder → ReportBuilder}/AddTileDialog.d.ts +0 -0
  245. /package/dist/components/{DashboardBuilder → ReportBuilder}/ChartPicker.d.ts +0 -0
  246. /package/dist/components/{DashboardBuilder → ReportBuilder}/DrillDialog.d.ts +0 -0
  247. /package/dist/components/{DashboardBuilder → ReportBuilder}/FilterDialog.d.ts +0 -0
  248. /package/dist/components/{DashboardBuilder → ReportBuilder}/FilterStrip.d.ts +0 -0
  249. /package/dist/components/{DashboardBuilder → ReportBuilder}/InlineMarkdown.d.ts +0 -0
  250. /package/dist/components/{DashboardBuilder → ReportBuilder}/InlineText.d.ts +0 -0
  251. /package/dist/components/{DashboardBuilder → ReportBuilder}/SourceViewPicker.d.ts +0 -0
  252. /package/dist/components/{DashboardBuilder → ReportBuilder}/TextTileBody.d.ts +0 -0
  253. /package/dist/components/{DashboardBuilder → ReportBuilder}/TileFrame.d.ts +0 -0
  254. /package/dist/components/{DashboardBuilder → ReportBuilder}/TileMenu.d.ts +0 -0
  255. /package/dist/components/{DashboardBuilder → ReportBuilder}/addTileToDocument.d.ts +0 -0
  256. /package/dist/components/{DashboardBuilder → ReportBuilder}/annotationText.d.ts +0 -0
  257. /package/dist/components/{DashboardBuilder → ReportBuilder}/changedTile.d.ts +0 -0
  258. /package/dist/components/{DashboardBuilder → ReportBuilder}/chartLine.d.ts +0 -0
  259. /package/dist/components/{DashboardBuilder → ReportBuilder}/controls.d.ts +0 -0
  260. /package/dist/components/{DashboardBuilder → ReportBuilder}/inlineEdit.d.ts +0 -0
  261. /package/dist/components/{DashboardBuilder → ReportBuilder}/layout.d.ts +0 -0
  262. /package/dist/components/{DashboardBuilder → ReportBuilder}/legacyNotebook.d.ts +0 -0
  263. /package/dist/components/{DashboardBuilder → ReportBuilder}/loadMalloy.d.ts +0 -0
  264. /package/dist/components/{DashboardBuilder → ReportBuilder}/openDraft.d.ts +0 -0
  265. /package/dist/components/{DashboardBuilder → ReportBuilder}/preview.d.ts +0 -0
  266. /package/dist/components/{DashboardBuilder → ReportBuilder}/sortable.d.ts +0 -0
  267. /package/dist/components/{DashboardBuilder → ReportBuilder}/spliceResult.d.ts +0 -0
  268. /package/dist/components/{DashboardBuilder → ReportBuilder}/tagParse.d.ts +0 -0
  269. /package/dist/components/{DashboardBuilder → ReportBuilder}/testing/fixtures.d.ts +0 -0
  270. /package/dist/components/{DashboardBuilder → ReportBuilder}/testing/inline.d.ts +0 -0
  271. /package/dist/components/{DashboardBuilder → ReportBuilder}/testing/resize.d.ts +0 -0
  272. /package/dist/components/{DashboardBuilder → ReportBuilder}/tileDisplayTitle.d.ts +0 -0
  273. /package/dist/components/{DashboardBuilder → ReportBuilder}/useBuilderSession.d.ts +0 -0
  274. /package/dist/components/{DashboardBuilder → ReportBuilder}/useBuilderShortcuts.d.ts +0 -0
  275. /package/dist/components/{DashboardBuilder → ReportBuilder}/useConversionConfirm.d.ts +0 -0
  276. /package/dist/components/{DashboardBuilder → ReportBuilder}/useDocumentEditor.d.ts +0 -0
  277. /package/dist/components/{DashboardBuilder → ReportBuilder}/useDraft.d.ts +0 -0
  278. /package/dist/components/{DashboardBuilder → ReportBuilder}/useExitGuard.d.ts +0 -0
  279. /package/dist/components/{DashboardBuilder → ReportBuilder}/useFilterForm.d.ts +0 -0
  280. /package/dist/components/{DashboardBuilder → ReportBuilder}/useOpenDraftCommit.d.ts +0 -0
  281. /package/dist/components/{DashboardBuilder → ReportBuilder}/useTileReorder.d.ts +0 -0
  282. /package/dist/components/{DashboardBuilder → ReportBuilder}/useTileResize.d.ts +0 -0
  283. /package/src/components/{DashboardBuilder → ReportBuilder}/AddTileDialog.spec.tsx +0 -0
  284. /package/src/components/{DashboardBuilder → ReportBuilder}/AddTileDialog.tsx +0 -0
  285. /package/src/components/{DashboardBuilder → ReportBuilder}/ChartPicker.render.spec.tsx +0 -0
  286. /package/src/components/{DashboardBuilder → ReportBuilder}/ChartPicker.spec.ts +0 -0
  287. /package/src/components/{DashboardBuilder → ReportBuilder}/ChartPicker.tsx +0 -0
  288. /package/src/components/{DashboardBuilder → ReportBuilder}/FilterStrip.tsx +0 -0
  289. /package/src/components/{DashboardBuilder → ReportBuilder}/InlineMarkdown.tsx +0 -0
  290. /package/src/components/{DashboardBuilder → ReportBuilder}/InlineText.tsx +0 -0
  291. /package/src/components/{DashboardBuilder → ReportBuilder}/SourceViewPicker.tsx +0 -0
  292. /package/src/components/{DashboardBuilder → ReportBuilder}/TextTileBody.tsx +0 -0
  293. /package/src/components/{DashboardBuilder → ReportBuilder}/TileFrame.tsx +0 -0
  294. /package/src/components/{DashboardBuilder → ReportBuilder}/TileMenu.tsx +0 -0
  295. /package/src/components/{DashboardBuilder → ReportBuilder}/__test__/inventory.ts +0 -0
  296. /package/src/components/{DashboardBuilder → ReportBuilder}/addTileToDocument.ts +0 -0
  297. /package/src/components/{DashboardBuilder → ReportBuilder}/annotationText.spec.ts +0 -0
  298. /package/src/components/{DashboardBuilder → ReportBuilder}/annotationText.ts +0 -0
  299. /package/src/components/{DashboardBuilder → ReportBuilder}/artifactTagParity.spec.ts +0 -0
  300. /package/src/components/{DashboardBuilder → ReportBuilder}/catalog.aggregate.spec.ts +0 -0
  301. /package/src/components/{DashboardBuilder → ReportBuilder}/changedTile.spec.ts +0 -0
  302. /package/src/components/{DashboardBuilder → ReportBuilder}/changedTile.ts +0 -0
  303. /package/src/components/{DashboardBuilder → ReportBuilder}/chartLine.spec.ts +0 -0
  304. /package/src/components/{DashboardBuilder → ReportBuilder}/chartLine.ts +0 -0
  305. /package/src/components/{DashboardBuilder → ReportBuilder}/controls.ts +0 -0
  306. /package/src/components/{DashboardBuilder → ReportBuilder}/emptyStart.spec.ts +0 -0
  307. /package/src/components/{DashboardBuilder → ReportBuilder}/inlineEdit.tsx +0 -0
  308. /package/src/components/{DashboardBuilder → ReportBuilder}/invariants.spec.ts +0 -0
  309. /package/src/components/{DashboardBuilder → ReportBuilder}/keepRowStructure.spec.ts +0 -0
  310. /package/src/components/{DashboardBuilder → ReportBuilder}/layout.ts +0 -0
  311. /package/src/components/{DashboardBuilder → ReportBuilder}/loadMalloy.spec.ts +0 -0
  312. /package/src/components/{DashboardBuilder → ReportBuilder}/loadMalloy.ts +0 -0
  313. /package/src/components/{DashboardBuilder → ReportBuilder}/malloyTree.spec.ts +0 -0
  314. /package/src/components/{DashboardBuilder → ReportBuilder}/moveIntoGap.spec.ts +0 -0
  315. /package/src/components/{DashboardBuilder → ReportBuilder}/openDraft.ts +0 -0
  316. /package/src/components/{DashboardBuilder → ReportBuilder}/preview.shapes.spec.ts +0 -0
  317. /package/src/components/{DashboardBuilder → ReportBuilder}/preview.ts +0 -0
  318. /package/src/components/{DashboardBuilder → ReportBuilder}/scannerShapes.spec.ts +0 -0
  319. /package/src/components/{DashboardBuilder → ReportBuilder}/sortable.spec.ts +0 -0
  320. /package/src/components/{DashboardBuilder → ReportBuilder}/sortable.tsx +0 -0
  321. /package/src/components/{DashboardBuilder → ReportBuilder}/spliceDocument.chart.spec.ts +0 -0
  322. /package/src/components/{DashboardBuilder → ReportBuilder}/spliceResult.ts +0 -0
  323. /package/src/components/{DashboardBuilder → ReportBuilder}/statementExtent.spec.ts +0 -0
  324. /package/src/components/{DashboardBuilder → ReportBuilder}/tagParse.ts +0 -0
  325. /package/src/components/{DashboardBuilder → ReportBuilder}/testing/fixtures.ts +0 -0
  326. /package/src/components/{DashboardBuilder → ReportBuilder}/testing/inline.ts +0 -0
  327. /package/src/components/{DashboardBuilder → ReportBuilder}/testing/resize.ts +0 -0
  328. /package/src/components/{DashboardBuilder → ReportBuilder}/testing/urlRenderTags.json +0 -0
  329. /package/src/components/{DashboardBuilder → ReportBuilder}/tileDisplayTitle.ts +0 -0
  330. /package/src/components/{DashboardBuilder → ReportBuilder}/useBuilderSession.spec.ts +0 -0
  331. /package/src/components/{DashboardBuilder → ReportBuilder}/useBuilderSession.ts +0 -0
  332. /package/src/components/{DashboardBuilder → ReportBuilder}/useBuilderShortcuts.overlay.spec.tsx +0 -0
  333. /package/src/components/{DashboardBuilder → ReportBuilder}/useBuilderShortcuts.spec.tsx +0 -0
  334. /package/src/components/{DashboardBuilder → ReportBuilder}/useBuilderShortcuts.ts +0 -0
  335. /package/src/components/{DashboardBuilder → ReportBuilder}/useConversionConfirm.ts +0 -0
  336. /package/src/components/{DashboardBuilder → ReportBuilder}/useDocumentEditor.spec.ts +0 -0
  337. /package/src/components/{DashboardBuilder → ReportBuilder}/useDocumentEditor.ts +0 -0
  338. /package/src/components/{DashboardBuilder → ReportBuilder}/useDraft.ts +0 -0
  339. /package/src/components/{DashboardBuilder → ReportBuilder}/useExitGuard.spec.ts +0 -0
  340. /package/src/components/{DashboardBuilder → ReportBuilder}/useExitGuard.ts +0 -0
  341. /package/src/components/{DashboardBuilder → ReportBuilder}/useFilterForm.existing.spec.tsx +0 -0
  342. /package/src/components/{DashboardBuilder → ReportBuilder}/useFilterForm.spec.tsx +0 -0
  343. /package/src/components/{DashboardBuilder → ReportBuilder}/useFilterForm.ts +0 -0
  344. /package/src/components/{DashboardBuilder → ReportBuilder}/useOpenDraftCommit.ts +0 -0
  345. /package/src/components/{DashboardBuilder → ReportBuilder}/useTileReorder.spec.tsx +0 -0
  346. /package/src/components/{DashboardBuilder → ReportBuilder}/useTileReorder.ts +0 -0
  347. /package/src/components/{DashboardBuilder → ReportBuilder}/useTileResize.spec.tsx +0 -0
  348. /package/src/components/{DashboardBuilder → ReportBuilder}/useTileResize.ts +0 -0
  349. /package/src/components/{DashboardBuilder → ReportBuilder}/withGaps.spec.ts +0 -0
  350. /package/src/components/{Notebook → legacy}/Notebook.layout.spec.tsx +0 -0
@@ -2,80 +2,175 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
+ import * as fs from "fs";
6
+ import * as path from "path";
5
7
  import {
6
- documentRoute,
7
8
  documentSlug,
8
- locateDocument,
9
+ locateReport,
10
+ reportEditRoute,
11
+ reportRoute,
12
+ reportRoutePath,
13
+ resolveDrillTarget,
9
14
  } from "./documentLocation";
10
15
 
11
16
  describe("documentSlug", () => {
12
- it("reads the slug from either folder", () => {
17
+ it("is the basename of any path, at any depth", () => {
18
+ expect(documentSlug("tour.malloy")).toBe("tour");
13
19
  expect(documentSlug("notebooks/tour.malloy")).toBe("tour");
14
20
  expect(documentSlug("dashboards/tour.malloy")).toBe("tour");
21
+ expect(documentSlug("sales/2024/q3.malloy")).toBe("q3");
15
22
  });
16
23
 
17
- it("is undefined for anything that is not a document path", () => {
18
- expect(documentSlug("models/tour.malloy")).toBeUndefined();
19
- expect(documentSlug("notebooks/a/b.malloy")).toBeUndefined();
20
- expect(documentSlug("notebooks/tour.malloynb")).toBeUndefined();
24
+ it("drops a .malloynb suffix too", () => {
25
+ expect(documentSlug("README.malloynb")).toBe("README");
26
+ expect(documentSlug("old/orders.malloynb")).toBe("orders");
27
+ });
28
+
29
+ it("is undefined for no path", () => {
21
30
  expect(documentSlug(undefined)).toBeUndefined();
31
+ expect(documentSlug("")).toBeUndefined();
22
32
  });
23
33
  });
24
34
 
25
- describe("documentRoute", () => {
26
- it("encodes the slug and leaves the rest alone", () => {
27
- expect(documentRoute("env", "pkg", "notebook", "a#b")).toBe(
28
- "/env/pkg/notebooks/a%23b",
35
+ describe("reportRoute", () => {
36
+ it("is the package path without .malloy, each segment encoded", () => {
37
+ expect(reportRoute("env", "pkg", "sales/q3.malloy")).toBe(
38
+ "/env/pkg/sales/q3",
39
+ );
40
+ expect(reportRoutePath("a#b/c d.malloy")).toBe("a%23b/c%20d");
41
+ });
42
+
43
+ it("edits with ?edit, so a report named edit keeps its own route", () => {
44
+ expect(reportEditRoute("env", "pkg", "sales/q3.malloy")).toBe(
45
+ "/env/pkg/sales/q3?edit",
46
+ );
47
+ expect(reportRoute("env", "pkg", "sales/edit.malloy")).toBe(
48
+ "/env/pkg/sales/edit",
49
+ );
50
+ expect(reportEditRoute("env", "pkg", "sales/edit.malloy")).toBe(
51
+ "/env/pkg/sales/edit?edit",
52
+ );
53
+ });
54
+
55
+ it("keeps a .malloynb suffix, which opens by path", () => {
56
+ expect(reportRoutePath("old.malloynb")).toBe("old.malloynb");
57
+ });
58
+
59
+ it("encodes the environment and package too, so no caller encodes again", () => {
60
+ expect(reportRoute("my env", "a#b", "q3.malloy")).toBe(
61
+ "/my%20env/a%23b/q3",
29
62
  );
30
63
  });
31
64
  });
32
65
 
33
- describe("locateDocument", () => {
34
- const dashboards = [
35
- { name: "overview", path: "dashboards/overview.malloy" },
36
- { name: "tour", path: "notebooks/tour.malloy" },
37
- ];
38
- const notebooks = [
39
- { path: "notebooks/review.malloy" },
40
- { path: "dashboards/story.malloy" },
41
- ];
42
- const find = (
43
- kind: "dashboard" | "notebook",
44
- slug: string,
45
- withNotebooks = notebooks,
46
- ) => locateDocument({ kind, slug, dashboards, notebooks: withNotebooks });
47
-
48
- it("finds a document in its own folder", () => {
49
- expect(find("dashboard", "overview")).toEqual({
50
- kind: "dashboard",
51
- path: "dashboards/overview.malloy",
66
+ const REPORTS = [
67
+ { path: "overview.malloy", layout: "grid" },
68
+ { path: "dashboards/overview.malloy", layout: "grid" },
69
+ { path: "notebooks/overview.malloy", layout: "linear" },
70
+ { path: "sales/q3.malloy", layout: "linear", editable: false },
71
+ ];
72
+
73
+ describe("locateReport", () => {
74
+ it("matches the exact path only", () => {
75
+ expect(locateReport("sales/q3.malloy", REPORTS)).toEqual({
76
+ layout: "linear",
77
+ path: "sales/q3.malloy",
78
+ editable: false,
52
79
  });
80
+ expect(locateReport("q3.malloy", REPORTS)).toBeUndefined();
81
+ expect(locateReport("sales/q3", REPORTS)).toBeUndefined();
53
82
  });
54
83
 
55
- it("takes the kind from the listing, not the folder or the route", () => {
56
- expect(find("notebook", "story")).toEqual({
57
- kind: "notebook",
58
- path: "dashboards/story.malloy",
59
- });
60
- expect(find("notebook", "tour")).toEqual({
61
- kind: "dashboard",
62
- path: "notebooks/tour.malloy",
63
- });
84
+ it("reads the layout from the listing, never the directory", () => {
85
+ expect(
86
+ locateReport("notebooks/x.malloy", [
87
+ { path: "notebooks/x.malloy", layout: "grid" },
88
+ ])?.layout,
89
+ ).toBe("grid");
64
90
  });
91
+ });
65
92
 
66
- it("prefers the route's kind when both folders hold the slug", () => {
67
- const both = [{ path: "notebooks/overview.malloy" }];
68
- expect(find("notebook", "overview", both)).toEqual({
69
- kind: "notebook",
70
- path: "notebooks/overview.malloy",
71
- });
72
- expect(find("dashboard", "overview", both)).toEqual({
73
- kind: "dashboard",
74
- path: "dashboards/overview.malloy",
93
+ describe("resolveDrillTarget", () => {
94
+ it("reads a target as a package path from the root", () => {
95
+ const target = resolveDrillTarget("sales/q3", REPORTS);
96
+ expect(target.kind).toBe("path");
97
+ expect("report" in target && target.report.path).toBe("sales/q3.malloy");
98
+ });
99
+
100
+ it("refuses a target that is not a plain package path: . or .. segments, empty segments, a leading /", () => {
101
+ for (const to of [
102
+ "../../x",
103
+ "../sales/q3",
104
+ "sales/../q3",
105
+ "./sales/q3",
106
+ "/sales/q3",
107
+ "sales//q3",
108
+ "sales/q3/",
109
+ ".",
110
+ "..",
111
+ "",
112
+ ]) {
113
+ expect(resolveDrillTarget(to, REPORTS)).toEqual({
114
+ kind: "unresolved",
115
+ });
116
+ }
117
+ });
118
+
119
+ it("reads a bare name at the root path first, with no fallback", () => {
120
+ const target = resolveDrillTarget("overview", REPORTS);
121
+ expect(target.kind).toBe("path");
122
+ expect("report" in target && target.report.path).toBe("overview.malloy");
123
+ });
124
+
125
+ it("reads a bare name as a root file only: a report elsewhere with that basename is not looked up", () => {
126
+ expect(resolveDrillTarget("overview", REPORTS.slice(1))).toEqual({
127
+ kind: "unresolved",
75
128
  });
76
129
  });
77
130
 
78
- it("is undefined for a document no listing has", () => {
79
- expect(find("dashboard", "ghost")).toBeUndefined();
131
+ it("is unresolved for a path nothing is at", () => {
132
+ expect(resolveDrillTarget("x/q3", REPORTS)).toEqual({
133
+ kind: "unresolved",
134
+ });
80
135
  });
81
136
  });
137
+
138
+ /** The SDK's column of the drill case table the server's `resolveDrillDestination` shares. */
139
+ describe("resolveDrillTarget: the shared drill case table", () => {
140
+ type Answer = { kind: string; path?: string; malformed?: boolean };
141
+ const { cases } = JSON.parse(
142
+ fs.readFileSync(
143
+ path.resolve(
144
+ import.meta.dir,
145
+ "../ReportBuilder/testing/drillResolution.json",
146
+ ),
147
+ "utf8",
148
+ ),
149
+ ) as {
150
+ cases: {
151
+ name: string;
152
+ to: string;
153
+ reports: { path: string; layout: string; dropped?: boolean }[];
154
+ server: Answer;
155
+ /** What the SDK answers where it differs from the server by design; `knownDifference` says why. */
156
+ sdk?: Answer;
157
+ knownDifference?: string;
158
+ }[];
159
+ };
160
+ for (const testCase of cases) {
161
+ it(testCase.name, () => {
162
+ // The listing: a report dropped at discovery is not in it.
163
+ const listed = testCase.reports.filter((r) => !r.dropped);
164
+ const target = resolveDrillTarget(testCase.to, listed);
165
+ const answer: Answer =
166
+ target.kind === "unresolved"
167
+ ? { kind: target.kind }
168
+ : { kind: target.kind, path: target.report.path };
169
+ const { malformed: _malformed, ...server } = testCase.server;
170
+ expect(testCase.sdk === undefined).toBe(
171
+ testCase.knownDifference === undefined,
172
+ );
173
+ expect(answer).toEqual(testCase.sdk ?? server);
174
+ });
175
+ }
176
+ });
@@ -1,55 +1,134 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- /** A layout document is a dashboard or a notebook; the artifact tag says which, not the folder. */
5
- export type DocumentKind = "dashboard" | "notebook";
4
+ /**
5
+ * A report's layout: `grid` places tiles by columns, `linear` reads top to
6
+ * bottom. The artifact tag decides it; where the file lives never does.
7
+ */
8
+ export type ReportLayout = "grid" | "linear";
9
+
10
+ /** One report as the package's listing (`GET …/reports`) has it. */
11
+ export interface ListedReport {
12
+ path?: string;
13
+ name?: string;
14
+ layout?: string;
15
+ title?: string;
16
+ editable?: boolean;
17
+ }
6
18
 
7
19
  export interface LocatedDocument {
8
- kind: DocumentKind;
9
- /** The file within the package, wherever it lives. */
20
+ layout: ReportLayout;
21
+ /** The file within the package, wherever it lives: the report's identity. */
10
22
  path: string;
23
+ /** Whether the builder opens it; false for a `.malloynb` or a `run:`-cell report. */
24
+ editable: boolean;
11
25
  }
12
26
 
13
- const DOCUMENT_PATH = /^(?:dashboards|notebooks)\/([^/]+)\.malloy$/;
27
+ const REPORT_SUFFIX = /\.malloy(nb)?$/;
28
+
29
+ /**
30
+ * A report's display label: the basename of any path, without `.malloy` or
31
+ * `.malloynb`. `sales/q3.malloy` is `q3`. A label only: two reports in
32
+ * different directories may share it.
33
+ */
34
+ export const documentSlug = (path: string | undefined): string | undefined => {
35
+ if (!path) return undefined;
36
+ const base = path.slice(path.lastIndexOf("/") + 1);
37
+ return base.replace(REPORT_SUFFIX, "") || undefined;
38
+ };
39
+
40
+ /** The route segment of a report's path: the path without `.malloy`, each segment encoded. A `.malloynb` keeps its suffix, since it opens by path. */
41
+ export const reportRoutePath = (path: string) =>
42
+ path
43
+ .replace(/\.malloy$/, "")
44
+ .split("/")
45
+ .map(encodeURIComponent)
46
+ .join("/");
47
+
48
+ /**
49
+ * The Console route of a report: `/<env>/<pkg>/sales/q3` for
50
+ * `sales/q3.malloy`. Every segment is encoded here, the environment and
51
+ * package included, so no caller encodes any of them again.
52
+ */
53
+ export const reportRoute = (
54
+ environmentName: string,
55
+ packageName: string,
56
+ path: string,
57
+ ) =>
58
+ `/${encodeURIComponent(environmentName)}/${encodeURIComponent(packageName)}/${reportRoutePath(path)}`;
14
59
 
15
- /** The slug of a document in either folder: `notebooks/tour.malloy` and `dashboards/tour.malloy` are `tour`. */
16
- export const documentSlug = (path: string | undefined) =>
17
- DOCUMENT_PATH.exec(path ?? "")?.[1];
60
+ /**
61
+ * The query parameter that opens a report's route in the builder:
62
+ * `/<env>/<pkg>/sales/q3?edit`. A parameter rather than a trailing `/edit`
63
+ * segment, because a segment is also a path: `sales/edit.malloy` is a report
64
+ * whose route is `/<env>/<pkg>/sales/edit`.
65
+ */
66
+ export const REPORT_EDIT_PARAM = "edit";
18
67
 
19
- /** The Console route of a document of this kind; the slug is a filename, so it is encoded. */
20
- export const documentRoute = (
68
+ /** The Console route that edits a report: its {@link reportRoute} with `?edit`. */
69
+ export const reportEditRoute = (
21
70
  environmentName: string,
22
71
  packageName: string,
23
- kind: DocumentKind,
24
- slug: string,
25
- ) => `/${environmentName}/${packageName}/${kind}s/${encodeURIComponent(slug)}`;
72
+ path: string,
73
+ ) => `${reportRoute(environmentName, packageName, path)}?${REPORT_EDIT_PARAM}`;
74
+
75
+ /** A listed report's layout: anything but `linear` draws as a grid. */
76
+ export const listedLayout = (report: ListedReport): ReportLayout =>
77
+ report.layout === "linear" ? "linear" : "grid";
78
+
79
+ /** A listed report with a path, as a host opens it. */
80
+ export const locatedReport = (
81
+ report: ListedReport & { path: string },
82
+ ): LocatedDocument => ({
83
+ layout: listedLayout(report),
84
+ path: report.path,
85
+ editable: report.editable !== false,
86
+ });
87
+
88
+ /** The listed report at exactly this path, or undefined. */
89
+ export function locateReport(
90
+ path: string,
91
+ reports: readonly ListedReport[],
92
+ ): LocatedDocument | undefined {
93
+ const found = reports.find((r) => r.path === path);
94
+ return found?.path
95
+ ? locatedReport({ ...found, path: found.path })
96
+ : undefined;
97
+ }
98
+
99
+ /** Where a `# drill { to=… }` lands. */
100
+ export type DrillTarget =
101
+ | { kind: "path"; report: LocatedDocument }
102
+ | { kind: "unresolved" };
103
+
104
+ /**
105
+ * Whether a `# drill { to=… }` is a plain package path: non-empty segments,
106
+ * none `.` or `..`, and no leading `/`. Anything else could name a route
107
+ * outside the package (`../../x`), so it resolves to nothing and a host must
108
+ * not build a route from it. The server's `isDrillTargetPath` is the same rule.
109
+ */
110
+ export function isDrillTargetPath(to: string): boolean {
111
+ if (to === "" || to.startsWith("/")) return false;
112
+ return to
113
+ .split("/")
114
+ .every(
115
+ (segment) => segment !== "" && segment !== "." && segment !== "..",
116
+ );
117
+ }
26
118
 
27
119
  /**
28
- * Where the document a route names really is, and what kind its tag makes it.
29
- *
30
- * The listings sort by tag, so a hit in one says the kind. The route's own kind
31
- * is tried first, so a slug in both folders opens the one the link was built for.
120
+ * A `# drill` destination, by the server's rule (`resolveDrillDestination`):
121
+ * a package path from the root, with or without `.malloy` (`sales/overview`
122
+ * is `sales/overview.malloy`, and a bare name is a file at the root).
32
123
  */
33
- export function locateDocument({
34
- kind,
35
- slug,
36
- dashboards,
37
- notebooks,
38
- }: {
39
- kind: DocumentKind;
40
- slug: string;
41
- dashboards: readonly { name?: string; path?: string }[];
42
- notebooks: readonly { path?: string }[];
43
- }): LocatedDocument | undefined {
44
- const asDashboard = (): LocatedDocument | undefined => {
45
- const found = dashboards.find((d) => d.name === slug && d.path);
46
- return found?.path ? { kind: "dashboard", path: found.path } : undefined;
47
- };
48
- const asNotebook = (): LocatedDocument | undefined => {
49
- const found = notebooks.find((n) => documentSlug(n.path) === slug);
50
- return found?.path ? { kind: "notebook", path: found.path } : undefined;
51
- };
52
- return kind === "dashboard"
53
- ? (asDashboard() ?? asNotebook())
54
- : (asNotebook() ?? asDashboard());
124
+ export function resolveDrillTarget(
125
+ to: string,
126
+ reports: readonly ListedReport[],
127
+ ): DrillTarget {
128
+ if (!isDrillTargetPath(to)) return { kind: "unresolved" };
129
+ for (const candidate of [`${to}.malloy`, to]) {
130
+ const report = locateReport(candidate, reports);
131
+ if (report) return { kind: "path", report };
132
+ }
133
+ return { kind: "unresolved" };
55
134
  }
@@ -3,12 +3,21 @@
3
3
 
4
4
  export { default as Package, type OpenDocumentRequest } from "./Package";
5
5
  export {
6
- documentRoute,
7
6
  documentSlug,
8
- locateDocument,
7
+ isDrillTargetPath,
8
+ locateReport,
9
+ REPORT_EDIT_PARAM,
10
+ reportEditRoute,
11
+ reportRoute,
12
+ reportRoutePath,
13
+ resolveDrillTarget,
14
+ type DrillTarget,
15
+ type ListedReport,
9
16
  type LocatedDocument,
17
+ type ReportLayout,
10
18
  } from "./documentLocation";
11
- export { useDocumentLocation } from "./useDocumentLocation";
19
+ export { useDocumentLocation, useReportListing } from "./useDocumentLocation";
20
+ export { useDraftLayout } from "./useDraftLayout";
12
21
  export {
13
22
  NewDocumentDialog,
14
23
  type NewDocumentDialogProps,
@@ -0,0 +1,25 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type { QueryClient } from "@tanstack/react-query";
5
+ import { legacyReportQueryKeys } from "../legacy/queryKeys";
6
+
7
+ /**
8
+ * Drop every cached read of a package's reports after a write changed them:
9
+ * each report's manifest, the listing, and the deprecated readers' copies,
10
+ * whose listings a layout switch moves a report between. With `modelPath`,
11
+ * the one report's own cached reads too.
12
+ */
13
+ export function invalidateReportQueries(
14
+ queryClient: QueryClient,
15
+ environmentName: string,
16
+ packageName: string,
17
+ modelPath?: string,
18
+ ): void {
19
+ for (const queryKey of [
20
+ ["report"],
21
+ ["reports"],
22
+ ...legacyReportQueryKeys(environmentName, packageName, modelPath),
23
+ ])
24
+ void queryClient.invalidateQueries({ queryKey });
25
+ }
@@ -0,0 +1,58 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import type { ApiClients } from "../ServerProvider";
6
+ import { fetchReportListing } from "./useDocumentLocation";
7
+
8
+ const clientsAnswering = (answer: () => Promise<unknown>) =>
9
+ ({ reports: { listReports: answer } }) as unknown as ApiClients;
10
+
11
+ describe("fetchReportListing", () => {
12
+ it("returns the listing", async () => {
13
+ const reports = [{ path: "a.malloy", layout: "grid" }];
14
+ expect(
15
+ await fetchReportListing(
16
+ clientsAnswering(async () => ({ data: reports })),
17
+ "env",
18
+ "pkg",
19
+ ),
20
+ ).toEqual(reports as never);
21
+ });
22
+
23
+ it("reads a 404 as an older server with no reports to list", async () => {
24
+ expect(
25
+ await fetchReportListing(
26
+ clientsAnswering(() =>
27
+ Promise.reject({ response: { status: 404 } }),
28
+ ),
29
+ "env",
30
+ "pkg",
31
+ ),
32
+ ).toEqual([]);
33
+ });
34
+
35
+ it("raises a failure with no answer, rather than reading it as no reports", async () => {
36
+ // Every reader caches this listing; an empty one cached for a minute
37
+ // would say "nothing here" about a package that has reports.
38
+ await expect(
39
+ fetchReportListing(
40
+ clientsAnswering(() => Promise.reject(new Error("Network Error"))),
41
+ "env",
42
+ "pkg",
43
+ ),
44
+ ).rejects.toThrow("Network Error");
45
+ });
46
+
47
+ it("raises a server error", async () => {
48
+ await expect(
49
+ fetchReportListing(
50
+ clientsAnswering(() =>
51
+ Promise.reject({ response: { status: 500 } }),
52
+ ),
53
+ "env",
54
+ "pkg",
55
+ ),
56
+ ).rejects.toEqual({ response: { status: 500 } });
57
+ });
58
+ });
@@ -2,58 +2,116 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
5
- import { useServer } from "../ServerProvider";
5
+ import { useServer, type ApiClients } from "../ServerProvider";
6
6
  import {
7
- locateDocument,
8
- type DocumentKind,
7
+ locateReport,
8
+ type ListedReport,
9
9
  type LocatedDocument,
10
10
  } from "./documentLocation";
11
11
 
12
+ /** The query key of a package's report listing, so every reader shares one request and one invalidation. */
13
+ const reportsQueryKey = (
14
+ environmentName: string,
15
+ packageName: string,
16
+ versionId?: string,
17
+ ) => ["reports", environmentName, packageName, versionId];
18
+
12
19
  /**
13
- * Where a routed document really lives, from the package's listings.
14
- *
15
- * `settled` is false until both listings have answered; a document neither
16
- * lists (a draft, or an older server) has a `location` of undefined and the
17
- * caller falls back to the folder its route names.
20
+ * `GET …/reports`, as the array every reader of {@link reportsQueryKey} caches.
21
+ * An older server with no such route (404) is a package with no reports to
22
+ * list rather than an error. Anything else, including no answer at all, is
23
+ * raised: every reader caches this listing, and an empty one standing in for
24
+ * a failure would say "nothing here" about a package that has reports.
18
25
  */
19
- export function useDocumentLocation(
26
+ export async function fetchReportListing(
27
+ apiClients: ApiClients,
20
28
  environmentName: string,
21
29
  packageName: string,
22
- kind: DocumentKind,
23
- slug: string,
24
30
  versionId?: string,
25
- ): { location: LocatedDocument | undefined; settled: boolean } {
26
- const { apiClients } = useServer();
27
- const dashboards = useQueryWithApiError({
28
- queryKey: ["dashboards", environmentName, packageName, versionId],
29
- queryFn: () =>
30
- apiClients.dashboards.listDashboards(
31
+ ): Promise<ListedReport[]> {
32
+ try {
33
+ return (
34
+ await apiClients.reports.listReports(
31
35
  environmentName,
32
36
  packageName,
33
37
  versionId,
34
- ),
35
- });
36
- const notebooks = useQueryWithApiError({
37
- queryKey: ["notebooks", environmentName, packageName, versionId],
38
+ )
39
+ ).data;
40
+ } catch (e) {
41
+ const status = (e as { response?: { status?: number } })?.response
42
+ ?.status;
43
+ if (status === 404) return [];
44
+ throw e;
45
+ }
46
+ }
47
+
48
+ /**
49
+ * The package's reports, from `GET …/reports`: one listing for both layouts.
50
+ *
51
+ * `settled` is false until it has answered. An older server with no such
52
+ * route answers 404, which reads as a package with no reports rather than an
53
+ * error, so a host still renders. Any other failure is `isError`, with
54
+ * `refetch` to try again: a caller shows it rather than an empty listing.
55
+ * `isFetching` is true while a request is in flight, including the refetch
56
+ * that follows a write's invalidation, when the cached `reports` predate it.
57
+ */
58
+ export function useReportListing(
59
+ environmentName: string,
60
+ packageName: string,
61
+ versionId?: string,
62
+ enabled = true,
63
+ ) {
64
+ const { apiClients } = useServer();
65
+ const query = useQueryWithApiError({
66
+ queryKey: reportsQueryKey(environmentName, packageName, versionId),
38
67
  queryFn: () =>
39
- apiClients.notebooks.listNotebooks(
68
+ fetchReportListing(
69
+ apiClients,
40
70
  environmentName,
41
71
  packageName,
42
72
  versionId,
43
73
  ),
74
+ enabled,
75
+ // One request per page however many readers mount: the route, the
76
+ // header's Edit button, drill and the builder all read this listing, and
77
+ // a save invalidates it.
78
+ staleTime: 60_000,
44
79
  });
45
- const settled = [dashboards, notebooks].every(
46
- (query) => query.isSuccess || query.isError,
80
+ return {
81
+ reports: (query.data ?? []) as ListedReport[],
82
+ settled: query.isSuccess || query.isError,
83
+ isFetching: query.isFetching,
84
+ isError: query.isError,
85
+ error: query.error,
86
+ refetch: query.refetch,
87
+ };
88
+ }
89
+
90
+ /**
91
+ * The report at a package path, from the package's listing, matched exactly.
92
+ *
93
+ * `settled` is false until the listing has answered; a path the listing does
94
+ * not have (a draft, a model, or an older server) has a `location` of
95
+ * undefined, and the caller decides what that path is instead.
96
+ */
97
+ export function useDocumentLocation(
98
+ environmentName: string,
99
+ packageName: string,
100
+ path: string,
101
+ versionId?: string,
102
+ ): {
103
+ location: LocatedDocument | undefined;
104
+ settled: boolean;
105
+ reports: readonly ListedReport[];
106
+ } {
107
+ const { reports, settled } = useReportListing(
108
+ environmentName,
109
+ packageName,
110
+ versionId,
47
111
  );
48
112
  return {
49
113
  settled,
50
- location: settled
51
- ? locateDocument({
52
- kind,
53
- slug,
54
- dashboards: dashboards.data?.data ?? [],
55
- notebooks: notebooks.data?.data ?? [],
56
- })
57
- : undefined,
114
+ reports,
115
+ location: settled ? locateReport(path, reports) : undefined,
58
116
  };
59
117
  }