@malloy-publisher/sdk 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (292) hide show
  1. package/dist/{Dashboard-H1kJlDFo.es.js → DashboardTile-BFcxdv7R.es.js} +15918 -17760
  2. package/dist/DashboardTile-sg8LjUk8.cjs.js +137 -0
  3. package/dist/RenderedResult-B48wAjM8.cjs.js +141 -0
  4. package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-CBLHr32C.es.js} +193 -183
  5. package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-DCV8BUWD.es.js} +529 -521
  6. package/dist/ServerProvider-HRqT3w1C.cjs.js +1 -0
  7. package/dist/builder/index.cjs.js +146 -58
  8. package/dist/builder/index.es.js +9076 -6479
  9. package/dist/builder-entry.d.ts +4 -0
  10. package/dist/client/api.d.ts +82 -48
  11. package/dist/client/configuration.d.ts +1 -1
  12. package/dist/client/index.cjs.js +1 -1
  13. package/dist/client/index.d.ts +1 -1
  14. package/dist/client/index.es.js +84 -82
  15. package/dist/components/Dashboard/Dashboard.d.ts +8 -15
  16. package/dist/components/Dashboard/DashboardGrid.d.ts +23 -6
  17. package/dist/components/Dashboard/DashboardTile.d.ts +10 -1
  18. package/dist/components/Dashboard/DashboardView.d.ts +36 -0
  19. package/dist/components/Dashboard/TileCard.d.ts +15 -4
  20. package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
  21. package/dist/components/Dashboard/index.d.ts +3 -0
  22. package/dist/components/Dashboard/telemetry.d.ts +15 -3
  23. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -1
  24. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +16 -5
  25. package/dist/components/DashboardBuilder/ChartPicker.d.ts +29 -0
  26. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +48 -21
  27. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +17 -4
  28. package/dist/components/DashboardBuilder/DiffDialog.d.ts +2 -10
  29. package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
  30. package/dist/components/DashboardBuilder/FilterStrip.d.ts +3 -1
  31. package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
  32. package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
  33. package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
  34. package/dist/components/DashboardBuilder/SaveNotice.d.ts +27 -0
  35. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +19 -7
  36. package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
  37. package/dist/components/DashboardBuilder/TextTileBody.d.ts +7 -0
  38. package/dist/components/DashboardBuilder/TileFrame.d.ts +14 -12
  39. package/dist/components/DashboardBuilder/TileMenu.d.ts +11 -3
  40. package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
  41. package/dist/components/DashboardBuilder/catalog.d.ts +4 -0
  42. package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
  43. package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
  44. package/dist/components/DashboardBuilder/controls.d.ts +2 -2
  45. package/dist/components/DashboardBuilder/document.d.ts +42 -26
  46. package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
  47. package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
  48. package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
  49. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -5
  50. package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
  51. package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
  52. package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
  53. package/dist/components/DashboardBuilder/preview.d.ts +24 -4
  54. package/dist/components/DashboardBuilder/readDocument.d.ts +4 -1
  55. package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
  56. package/dist/components/DashboardBuilder/sortable.d.ts +14 -0
  57. package/dist/components/DashboardBuilder/spliceDocument.d.ts +13 -13
  58. package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
  59. package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
  60. package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
  61. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
  62. package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
  63. package/dist/components/DashboardBuilder/useBuilderSession.d.ts +89 -0
  64. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
  65. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +17 -55
  66. package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
  67. package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
  68. package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
  69. package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
  70. package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
  71. package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
  72. package/dist/components/DocumentCreate/events.d.ts +10 -0
  73. package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
  74. package/dist/components/DocumentCreate/guards.d.ts +12 -0
  75. package/dist/components/DocumentCreate/index.d.ts +6 -0
  76. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
  77. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
  78. package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
  79. package/dist/components/NarrowEditGate.d.ts +8 -0
  80. package/dist/components/Notebook/Notebook.d.ts +1 -1
  81. package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
  82. package/dist/components/Package/Package.d.ts +1 -0
  83. package/dist/components/Package/documentLocation.d.ts +28 -0
  84. package/dist/components/Package/index.d.ts +4 -0
  85. package/dist/components/Package/useDocumentLocation.d.ts +12 -0
  86. package/dist/components/PackageSection.d.ts +2 -2
  87. package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
  88. package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
  89. package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
  90. package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
  91. package/dist/components/ServerProvider.d.ts +2 -1
  92. package/dist/components/UnsavedChangesDialog.d.ts +9 -0
  93. package/dist/components/given/GivensPanel.d.ts +2 -2
  94. package/dist/components/index.d.ts +2 -0
  95. package/dist/hooks/index.d.ts +1 -0
  96. package/dist/hooks/useNarrowScreen.d.ts +4 -0
  97. package/dist/hooks/useQueryResult.d.ts +2 -0
  98. package/dist/hooks/useSettled.d.ts +14 -0
  99. package/dist/index.cjs.js +23 -24
  100. package/dist/index.es.js +9714 -7072
  101. package/dist/text/index.cjs.js +1 -0
  102. package/dist/text/index.d.ts +2 -0
  103. package/dist/text/index.es.js +6 -0
  104. package/dist/text-entry-BJwltZiy.cjs.js +7 -0
  105. package/dist/text-entry-CbbBcZl8.es.js +196 -0
  106. package/dist/text-entry.d.ts +2 -0
  107. package/dist/utils/clock.d.ts +2 -0
  108. package/package.json +10 -1
  109. package/src/builder-entry.ts +35 -0
  110. package/src/components/Dashboard/Dashboard.tsx +27 -278
  111. package/src/components/Dashboard/DashboardGrid.tsx +68 -7
  112. package/src/components/Dashboard/DashboardTile.spec.tsx +24 -0
  113. package/src/components/Dashboard/DashboardTile.tsx +31 -4
  114. package/src/components/Dashboard/DashboardView.spec.tsx +212 -0
  115. package/src/components/Dashboard/DashboardView.tsx +352 -0
  116. package/src/components/Dashboard/RowsDialog.tsx +1 -1
  117. package/src/components/Dashboard/TileCard.tsx +44 -10
  118. package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
  119. package/src/components/Dashboard/TileFilterTag.tsx +78 -0
  120. package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
  121. package/src/components/Dashboard/index.ts +3 -0
  122. package/src/components/Dashboard/telemetry.ts +16 -5
  123. package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
  124. package/src/components/DashboardBuilder/AddTileDialog.tsx +137 -111
  125. package/src/components/DashboardBuilder/BuilderToolbar.tsx +85 -27
  126. package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
  127. package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
  128. package/src/components/DashboardBuilder/ChartPicker.tsx +153 -0
  129. package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
  130. package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +192 -0
  131. package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +329 -0
  132. package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +363 -0
  133. package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +194 -0
  134. package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +157 -0
  135. package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +124 -0
  136. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +103 -78
  137. package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +177 -0
  138. package/src/components/DashboardBuilder/DashboardBuilder.tsx +610 -315
  139. package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +58 -8
  140. package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +191 -0
  141. package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
  142. package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +316 -0
  143. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +56 -10
  144. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +5 -22
  145. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +96 -14
  146. package/src/components/DashboardBuilder/DashboardEditor.tsx +482 -332
  147. package/src/components/DashboardBuilder/DiffDialog.spec.tsx +25 -0
  148. package/src/components/DashboardBuilder/DiffDialog.tsx +5 -24
  149. package/src/components/DashboardBuilder/DrillDialog.tsx +1 -1
  150. package/src/components/DashboardBuilder/FilterDialog.tsx +10 -3
  151. package/src/components/DashboardBuilder/FilterStrip.tsx +26 -4
  152. package/src/components/DashboardBuilder/InlineMarkdown.tsx +184 -0
  153. package/src/components/DashboardBuilder/InlineText.tsx +106 -0
  154. package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
  155. package/src/components/DashboardBuilder/SaveNotice.tsx +113 -0
  156. package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +87 -0
  157. package/src/components/DashboardBuilder/SettingsPopover.tsx +225 -67
  158. package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
  159. package/src/components/DashboardBuilder/TextTileBody.tsx +28 -0
  160. package/src/components/DashboardBuilder/TileFrame.tsx +89 -115
  161. package/src/components/DashboardBuilder/TileMenu.tsx +168 -90
  162. package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
  163. package/src/components/DashboardBuilder/annotationText.ts +17 -0
  164. package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
  165. package/src/components/DashboardBuilder/artifactTagParity.spec.ts +41 -0
  166. package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
  167. package/src/components/DashboardBuilder/catalog.spec.ts +2 -0
  168. package/src/components/DashboardBuilder/catalog.ts +61 -21
  169. package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
  170. package/src/components/DashboardBuilder/changedTile.ts +28 -0
  171. package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
  172. package/src/components/DashboardBuilder/chartLine.ts +121 -0
  173. package/src/components/DashboardBuilder/controls.spec.ts +21 -10
  174. package/src/components/DashboardBuilder/controls.ts +22 -8
  175. package/src/components/DashboardBuilder/document.ts +53 -5
  176. package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
  177. package/src/components/DashboardBuilder/documentSession.ts +257 -0
  178. package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
  179. package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
  180. package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
  181. package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
  182. package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
  183. package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
  184. package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
  185. package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
  186. package/src/components/DashboardBuilder/malloyText.spec.ts +48 -0
  187. package/src/components/DashboardBuilder/malloyText.ts +181 -27
  188. package/src/components/DashboardBuilder/malloyTree.ts +155 -7
  189. package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
  190. package/src/components/DashboardBuilder/newDashboard.ts +30 -3
  191. package/src/components/DashboardBuilder/openDraft.ts +52 -0
  192. package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
  193. package/src/components/DashboardBuilder/preview.spec.ts +159 -12
  194. package/src/components/DashboardBuilder/preview.ts +83 -9
  195. package/src/components/DashboardBuilder/readDocument.spec.ts +139 -27
  196. package/src/components/DashboardBuilder/readDocument.ts +130 -44
  197. package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
  198. package/src/components/DashboardBuilder/readForEditor.ts +47 -0
  199. package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
  200. package/src/components/DashboardBuilder/sortable.spec.ts +65 -0
  201. package/src/components/DashboardBuilder/sortable.tsx +2 -12
  202. package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
  203. package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
  204. package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
  205. package/src/components/DashboardBuilder/spliceDocument.ts +762 -130
  206. package/src/components/DashboardBuilder/spliceResult.ts +15 -0
  207. package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
  208. package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
  209. package/src/components/DashboardBuilder/tagParse.ts +103 -0
  210. package/src/components/DashboardBuilder/telemetry.ts +47 -0
  211. package/src/components/DashboardBuilder/testing/artifactTagParity.json +197 -0
  212. package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
  213. package/src/components/DashboardBuilder/testing/inline.ts +25 -0
  214. package/src/components/DashboardBuilder/textTiles.spec.ts +718 -0
  215. package/src/components/DashboardBuilder/useBuilderSession.spec.ts +335 -0
  216. package/src/components/DashboardBuilder/useBuilderSession.ts +292 -0
  217. package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +65 -0
  218. package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
  219. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +36 -10
  220. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
  221. package/src/components/DashboardBuilder/useDashboardEditor.ts +54 -181
  222. package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
  223. package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
  224. package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
  225. package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
  226. package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
  227. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
  228. package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
  229. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
  230. package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
  231. package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
  232. package/src/components/DocumentCreate/canRetry.ts +19 -0
  233. package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
  234. package/src/components/DocumentCreate/createDocument.ts +159 -0
  235. package/src/components/DocumentCreate/documentPath.ts +40 -0
  236. package/src/components/DocumentCreate/events.ts +15 -0
  237. package/src/components/DocumentCreate/exportedSources.ts +25 -0
  238. package/src/components/DocumentCreate/guards.ts +45 -0
  239. package/src/components/DocumentCreate/index.ts +27 -0
  240. package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
  241. package/src/components/DocumentCreate/newNotebook.ts +44 -0
  242. package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
  243. package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
  244. package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
  245. package/src/components/Model/ModelExplorer.spec.tsx +2 -2
  246. package/src/components/Model/SourcesExplorer.tsx +2 -4
  247. package/src/components/NarrowEditGate.spec.tsx +73 -0
  248. package/src/components/NarrowEditGate.tsx +29 -0
  249. package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
  250. package/src/components/Notebook/Notebook.tsx +66 -27
  251. package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
  252. package/src/components/Package/NewDocumentDialog.tsx +401 -0
  253. package/src/components/Package/Package.artifacts.spec.tsx +190 -0
  254. package/src/components/Package/Package.create.spec.tsx +380 -0
  255. package/src/components/Package/Package.notebooks.spec.tsx +18 -0
  256. package/src/components/Package/Package.tsx +366 -171
  257. package/src/components/Package/documentLocation.spec.ts +81 -0
  258. package/src/components/Package/documentLocation.ts +55 -0
  259. package/src/components/Package/index.ts +13 -0
  260. package/src/components/Package/useDocumentLocation.ts +59 -0
  261. package/src/components/PackageSection.tsx +2 -2
  262. package/src/components/RenderedResult/RenderedResult.tsx +18 -1
  263. package/src/components/RenderedResult/ResultContainer.tsx +44 -11
  264. package/src/components/RenderedResult/ResultPanel.tsx +4 -0
  265. package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
  266. package/src/components/RenderedResult/resultSizing.ts +14 -3
  267. package/src/components/ServerProvider.tsx +2 -1
  268. package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
  269. package/src/components/UnsavedChangesDialog.tsx +49 -0
  270. package/src/components/given/GivensPanel.spec.tsx +6 -6
  271. package/src/components/given/GivensPanel.tsx +3 -3
  272. package/src/components/index.ts +2 -0
  273. package/src/hooks/index.ts +3 -0
  274. package/src/hooks/useNarrowScreen.ts +21 -0
  275. package/src/hooks/useQueryResult.ts +16 -0
  276. package/src/hooks/useSettled.spec.ts +41 -0
  277. package/src/hooks/useSettled.ts +27 -0
  278. package/src/mainEntry.spec.ts +145 -0
  279. package/src/text-entry.ts +12 -0
  280. package/src/textEntry.spec.ts +118 -0
  281. package/src/utils/clock.spec.ts +12 -0
  282. package/src/utils/clock.ts +6 -0
  283. package/vite.config.ts +4 -0
  284. package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
  285. package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
  286. package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
  287. package/dist/components/DashboardBuilder/useTileResize.d.ts +0 -29
  288. package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
  289. package/src/components/DashboardBuilder/useTileResize.spec.tsx +0 -121
  290. package/src/components/DashboardBuilder/useTileResize.ts +0 -110
  291. package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
  292. package/src/components/Package/NewDashboardDialog.tsx +0 -265
@@ -0,0 +1,401 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import {
5
+ Alert,
6
+ Button,
7
+ MenuItem,
8
+ Stack,
9
+ TextField,
10
+ Tooltip,
11
+ } from "@mui/material";
12
+ import { useEffect, useMemo, useState } from "react";
13
+ import {
14
+ createDocument,
15
+ documentPathForTitle,
16
+ MAX_SLUG_ATTEMPTS,
17
+ newDocumentProblem,
18
+ useDocumentChoices,
19
+ type CreatedDocument,
20
+ type CreateTarget,
21
+ type DocumentCreatedEvent,
22
+ } from "../DocumentCreate";
23
+ import { canRetryRequest } from "../DocumentCreate/canRetry";
24
+ import type { DocumentType } from "../DocumentStorage/DocumentStorage";
25
+ import { AppDialog } from "../AppDialog";
26
+
27
+ const KIND_LABEL: Record<DocumentType, string> = {
28
+ dashboard: "Dashboard",
29
+ notebook: "Notebook",
30
+ };
31
+
32
+ export interface NewDocumentDialogProps {
33
+ open: boolean;
34
+ /** Which kind the dialog opens on. */
35
+ kind: DocumentType;
36
+ /** Whether the reader may switch to the other kind. Default true. */
37
+ allowKindChange?: boolean;
38
+ environmentName: string;
39
+ packageName: string;
40
+ versionId?: string;
41
+ /** The package's model files, relative to its root, to pick a source from. */
42
+ models: readonly string[];
43
+ /** The host is still listing `models`, so an empty list is not yet "no models". */
44
+ modelsLoading?: boolean;
45
+ /** The host's listing of `models` failed, so an empty list is not "no models". */
46
+ modelsError?: unknown;
47
+ /** Lists the models again; offered when `modelsError` is one a retry can clear. */
48
+ onRetryModels?: () => void;
49
+ /** Where the file is written, and (on the package route) which names are taken. */
50
+ target: CreateTarget;
51
+ /** The line under the title on the storage route, saying where the host keeps the new file. */
52
+ savedAs?: string;
53
+ onClose: () => void;
54
+ onCreated: (created: CreatedDocument) => void;
55
+ onEvent?: (event: DocumentCreatedEvent) => void;
56
+ }
57
+
58
+ /**
59
+ * A new dashboard or notebook: pick the model, the view its first tile or
60
+ * query shows, and a title. The file is the one the builder would write, so
61
+ * everything after this is the builder's; the host opens it from `onCreated`.
62
+ */
63
+ export function NewDocumentDialog({
64
+ open,
65
+ kind: initialKind,
66
+ allowKindChange = true,
67
+ environmentName,
68
+ packageName,
69
+ versionId,
70
+ models,
71
+ modelsLoading = false,
72
+ modelsError,
73
+ onRetryModels,
74
+ target,
75
+ savedAs,
76
+ onClose,
77
+ onCreated,
78
+ onEvent,
79
+ }: NewDocumentDialogProps) {
80
+ const [kind, setKind] = useState<DocumentType>(initialKind);
81
+ const [modelPath, setModelPath] = useState("");
82
+ /** The chosen view, as `source::view` — one value, so the pair is always valid. */
83
+ const [tile, setTile] = useState("");
84
+ const [title, setTitle] = useState("");
85
+ const [touchedTitle, setTouchedTitle] = useState(false);
86
+ const [attempted, setAttempted] = useState(false);
87
+ const [busy, setBusy] = useState(false);
88
+ const [failure, setFailure] = useState<string | undefined>(undefined);
89
+ const modelsFailed = modelsError !== undefined && modelsError !== null;
90
+
91
+ // Every model at once rather than the chosen one: a model that declares no
92
+ // source with a view cannot start a document, and the only way to offer a
93
+ // list without those is to know before the reader picks.
94
+ const { choices, isLoading, isSuccess, failed, retry, canRetry } =
95
+ useDocumentChoices({
96
+ environmentName,
97
+ packageName,
98
+ ...(versionId !== undefined ? { versionId } : {}),
99
+ models,
100
+ enabled: open && models.length > 0,
101
+ });
102
+
103
+ const tiles = useMemo(
104
+ () => choices.get(modelPath) ?? [],
105
+ [choices, modelPath],
106
+ );
107
+ const chosen = tiles.find((t) => `${t.source}::${t.view}` === tile);
108
+
109
+ useEffect(() => {
110
+ if (open) setKind(initialKind);
111
+ }, [open, initialKind]);
112
+
113
+ // Everything with one answer answers itself: a package with one usable
114
+ // model, a model with one view, and a title taken from that view.
115
+ useEffect(() => {
116
+ if (!open) return;
117
+ const usable = [...choices.keys()];
118
+ if (modelPath === "" && usable.length > 0) setModelPath(usable[0]);
119
+ }, [open, choices, modelPath]);
120
+
121
+ // Only a pick not yet made is filled in: a picked view that leaves the list stays unpicked, never swapped.
122
+ useEffect(() => {
123
+ if (!open || tiles.length === 0 || tile !== "") return;
124
+ setTile(`${tiles[0].source}::${tiles[0].view}`);
125
+ }, [open, tiles, tile]);
126
+
127
+ useEffect(() => {
128
+ if (!open || touchedTitle || chosen === undefined) return;
129
+ setTitle(chosen.view.replace(/_/g, " "));
130
+ }, [open, touchedTitle, chosen]);
131
+
132
+ useEffect(() => {
133
+ if (open) return;
134
+ // Reset on close, so the next open starts from the package again.
135
+ setModelPath("");
136
+ setTile("");
137
+ setTitle("");
138
+ setTouchedTitle(false);
139
+ setAttempted(false);
140
+ setFailure(undefined);
141
+ }, [open]);
142
+
143
+ // The first name the package listing leaves free; the storage route checks
144
+ // each name against the store itself when it writes.
145
+ const path = useMemo(() => {
146
+ if (title.trim() === "") return undefined;
147
+ for (let n = 1; n <= MAX_SLUG_ATTEMPTS; n++) {
148
+ const candidate = documentPathForTitle(kind, title, n);
149
+ if (!target.existing?.includes(candidate)) return candidate;
150
+ }
151
+ return undefined;
152
+ }, [kind, title, target]);
153
+ const problem =
154
+ chosen === undefined
155
+ ? undefined
156
+ : newDocumentProblem(kind, {
157
+ title,
158
+ modelPath,
159
+ source: chosen.source,
160
+ view: chosen.view,
161
+ });
162
+ const titleProblem =
163
+ problem ??
164
+ (title.trim() !== "" && path === undefined
165
+ ? "No free file name for this title; choose another."
166
+ : undefined);
167
+ // A blank title is said only once Create is pressed; anything else as it is typed.
168
+ const showTitleProblem =
169
+ titleProblem !== undefined && (attempted || title.trim() !== "");
170
+
171
+ const loading = modelsLoading || isLoading;
172
+ const unread = choices.size === 0 && (modelsFailed || failed.length > 0);
173
+ // Create is off only when nothing typed could make it succeed; the title is checked on press.
174
+ const blocked = loading
175
+ ? "Loading model views"
176
+ : unread
177
+ ? "Couldn't read the model views to start from"
178
+ : choices.size === 0
179
+ ? "No model view to start from yet"
180
+ : chosen === undefined
181
+ ? "Pick a view to start from"
182
+ : undefined;
183
+ const label = KIND_LABEL[kind].toLowerCase();
184
+ const createLabel = busy ? `Creating ${label}…` : `Create ${label}`;
185
+ const first = kind === "dashboard" ? "First tile" : "First query";
186
+ const picked = tile !== "" && chosen === undefined && tiles.length > 0;
187
+
188
+ const create = async () => {
189
+ if (blocked !== undefined || chosen === undefined || busy) return;
190
+ if (titleProblem !== undefined) {
191
+ setAttempted(true);
192
+ return;
193
+ }
194
+ setBusy(true);
195
+ setFailure(undefined);
196
+ try {
197
+ const created = await createDocument({
198
+ kind,
199
+ document: {
200
+ title,
201
+ modelPath,
202
+ source: chosen.source,
203
+ view: chosen.view,
204
+ },
205
+ target,
206
+ ...(onEvent ? { onEvent } : {}),
207
+ });
208
+ onCreated(created);
209
+ } catch (error) {
210
+ const message = (
211
+ error as { response?: { data?: { message?: string } } }
212
+ ).response?.data?.message;
213
+ setFailure(
214
+ message ?? (error instanceof Error ? error.message : String(error)),
215
+ );
216
+ } finally {
217
+ setBusy(false);
218
+ }
219
+ };
220
+
221
+ const retryButton = (onRetry: () => void) => (
222
+ <Button color="inherit" size="small" onClick={onRetry}>
223
+ Retry
224
+ </Button>
225
+ );
226
+
227
+ return (
228
+ <AppDialog
229
+ open={open}
230
+ // A write in flight is not abandoned by Escape or a backdrop click.
231
+ onClose={busy ? () => {} : onClose}
232
+ title={`New ${label}`}
233
+ description={
234
+ kind === "dashboard"
235
+ ? "A dashboard is a Malloy file in the package. Pick what its first tile shows; the rest is the builder."
236
+ : "A notebook is a Malloy file in the package that mixes text and queries. Pick what its first query runs; the rest is the builder."
237
+ }
238
+ actions={
239
+ <>
240
+ <Button onClick={onClose} disabled={busy}>
241
+ Cancel
242
+ </Button>
243
+ {/* A disabled button fires no events, so the tooltip hangs on a wrapper. */}
244
+ <Tooltip title={busy ? "" : (blocked ?? "")}>
245
+ <span>
246
+ <Button
247
+ variant="contained"
248
+ disabled={busy || blocked !== undefined}
249
+ aria-label={
250
+ !busy && blocked !== undefined
251
+ ? `${createLabel}: ${blocked}`
252
+ : createLabel
253
+ }
254
+ onClick={() => void create()}
255
+ >
256
+ {createLabel}
257
+ </Button>
258
+ </span>
259
+ </Tooltip>
260
+ </>
261
+ }
262
+ >
263
+ <Stack sx={{ gap: 2, pt: 1 }}>
264
+ {modelsFailed ? (
265
+ <Alert
266
+ severity="error"
267
+ action={
268
+ onRetryModels && canRetryRequest(modelsError)
269
+ ? retryButton(onRetryModels)
270
+ : undefined
271
+ }
272
+ >
273
+ Couldn&apos;t read this package&apos;s models, so no view is
274
+ listed to start from.
275
+ </Alert>
276
+ ) : models.length === 0 ? (
277
+ !modelsLoading && (
278
+ <Alert severity="info">
279
+ This package has no models yet. Add a .malloy file that
280
+ declares a source with a view, then create a {label} from
281
+ it.
282
+ </Alert>
283
+ )
284
+ ) : failed.length > 0 ? (
285
+ <Alert
286
+ severity="warning"
287
+ action={canRetry ? retryButton(retry) : undefined}
288
+ >
289
+ Couldn&apos;t read {failed.join(", ")}, so{" "}
290
+ {failed.length === 1 ? "its" : "their"} views aren&apos;t
291
+ listed.
292
+ </Alert>
293
+ ) : (
294
+ isSuccess &&
295
+ choices.size === 0 && (
296
+ <Alert severity="info">
297
+ A {label} starts from a view of a source, and no model in
298
+ this package declares one yet. Add a view to a source in a
299
+ model file and this list fills in.
300
+ </Alert>
301
+ )
302
+ )}
303
+ {allowKindChange && (
304
+ <TextField
305
+ select
306
+ size="small"
307
+ label="Type"
308
+ value={kind}
309
+ disabled={busy}
310
+ onChange={(event) =>
311
+ setKind(event.target.value as DocumentType)
312
+ }
313
+ inputProps={{ "aria-label": "Type" }}
314
+ >
315
+ {(Object.keys(KIND_LABEL) as DocumentType[]).map((k) => (
316
+ <MenuItem key={k} value={k}>
317
+ {KIND_LABEL[k]}
318
+ </MenuItem>
319
+ ))}
320
+ </TextField>
321
+ )}
322
+ <TextField
323
+ select
324
+ size="small"
325
+ label="Model"
326
+ value={choices.has(modelPath) ? modelPath : ""}
327
+ disabled={choices.size === 0 || busy}
328
+ onChange={(event) => {
329
+ setModelPath(event.target.value);
330
+ setTile("");
331
+ }}
332
+ inputProps={{ "aria-label": "Model" }}
333
+ helperText={
334
+ loading
335
+ ? "Reading the package's models…"
336
+ : choices.size === 1
337
+ ? "The only model with a view to start from."
338
+ : "Models with a view to start from."
339
+ }
340
+ >
341
+ {[...choices.keys()].map((modelFile) => (
342
+ <MenuItem key={modelFile} value={modelFile}>
343
+ {modelFile}
344
+ </MenuItem>
345
+ ))}
346
+ </TextField>
347
+ {/* One field, not two: the file needs a view OF a source, so the
348
+ pair is the thing being chosen. */}
349
+ <TextField
350
+ select
351
+ size="small"
352
+ label={first}
353
+ value={chosen ? tile : ""}
354
+ disabled={tiles.length === 0 || busy}
355
+ onChange={(event) => setTile(event.target.value)}
356
+ inputProps={{ "aria-label": first }}
357
+ error={picked}
358
+ helperText={
359
+ picked
360
+ ? "The view you picked is no longer in this model; pick another."
361
+ : tiles.length === 1
362
+ ? "The only view this model offers; more are added in the builder."
363
+ : "A view of a source; more are added in the builder."
364
+ }
365
+ >
366
+ {tiles.map((option) => (
367
+ <MenuItem
368
+ key={`${option.source}::${option.view}`}
369
+ value={`${option.source}::${option.view}`}
370
+ >
371
+ {option.source} → {option.view}
372
+ </MenuItem>
373
+ ))}
374
+ </TextField>
375
+ <TextField
376
+ size="small"
377
+ label="Title"
378
+ value={title}
379
+ disabled={busy}
380
+ onChange={(event) => {
381
+ setTouchedTitle(true);
382
+ setTitle(event.target.value);
383
+ }}
384
+ inputProps={{ "aria-label": `${KIND_LABEL[kind]} title` }}
385
+ error={showTitleProblem}
386
+ helperText={
387
+ showTitleProblem
388
+ ? titleProblem
389
+ : path
390
+ ? target.route === "package"
391
+ ? `Written as ${path}, and opened in the builder.`
392
+ : (savedAs ??
393
+ `Saved as a new ${label} in the host's store, and opened in the builder.`)
394
+ : "Names the file too."
395
+ }
396
+ />
397
+ {failure && <Alert severity="error">{failure}</Alert>}
398
+ </Stack>
399
+ </AppDialog>
400
+ );
401
+ }
@@ -0,0 +1,190 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /** The package page's one Artifacts list: dashboards and notebooks, named by one rule. */
5
+ import { cleanup, fireEvent, render, screen } from "@testing-library/react";
6
+ import { afterEach, beforeEach, expect, it, mock } from "bun:test";
7
+ import type { ReactNode } from "react";
8
+ import {
9
+ clearCache,
10
+ mockServerProvider,
11
+ pending,
12
+ serverWrapper,
13
+ } from "../../../test/serverProvider";
14
+ import type {
15
+ DocumentLocator,
16
+ DocumentStorage,
17
+ } from "../DocumentStorage/DocumentStorage";
18
+ import { DocumentStorageProvider } from "../DocumentStorage/DocumentStorageProvider";
19
+
20
+ let dashboards: { name: string; path: string; title?: string }[] = [];
21
+ let notebooks: { path: string; title?: string }[] = [];
22
+ const listDashboards = mock((_e: string, _p: string, _v?: string) =>
23
+ Promise.resolve({ data: dashboards }),
24
+ );
25
+ const listNotebooks = mock((_e: string, _p: string, _v?: string) =>
26
+ Promise.resolve({ data: notebooks }),
27
+ );
28
+
29
+ mockServerProvider(
30
+ {
31
+ packages: { getPackage: pending },
32
+ notebooks: { listNotebooks, getNotebook: pending },
33
+ models: { listModels: () => Promise.resolve({ data: [] }) },
34
+ databases: { listDatabases: () => Promise.resolve({ data: [] }) },
35
+ dataApps: { listDataApps: () => Promise.resolve({ data: [] }) },
36
+ dashboards: { listDashboards },
37
+ materializations: {
38
+ listMaterializations: () => Promise.resolve({ data: [] }),
39
+ },
40
+ },
41
+ { mutable: true },
42
+ );
43
+
44
+ const { default: Package } = await import("./Package");
45
+
46
+ const onClick = mock((_to: string) => {});
47
+
48
+ function mount(storage?: DocumentStorage) {
49
+ const wrap = ({ children }: { children: ReactNode }) =>
50
+ serverWrapper({
51
+ children: storage ? (
52
+ <DocumentStorageProvider documentStorage={storage}>
53
+ {children}
54
+ </DocumentStorageProvider>
55
+ ) : (
56
+ children
57
+ ),
58
+ });
59
+ return render(
60
+ <Package
61
+ resourceUri="publisher://environments/env/packages/pkg"
62
+ onClickPackageFile={onClick}
63
+ />,
64
+ { wrapper: wrap },
65
+ );
66
+ }
67
+
68
+ /** The artifact rows' text, top to bottom. */
69
+ const rows = async () => {
70
+ await screen.findByRole("heading", { name: "Artifacts" });
71
+ const section = screen.getByRole("region", { name: "Artifacts" });
72
+ return Array.from(section.querySelectorAll('[role="button"]'))
73
+ .map((row) => row.textContent ?? "")
74
+ .filter((text) => text !== "New");
75
+ };
76
+
77
+ beforeEach(() => {
78
+ clearCache();
79
+ dashboards = [];
80
+ notebooks = [];
81
+ onClick.mockClear();
82
+ listDashboards.mockClear();
83
+ listNotebooks.mockClear();
84
+ });
85
+ afterEach(cleanup);
86
+
87
+ it("lists a dashboard and a notebook in one section, each with its kind, ordered by what is shown", async () => {
88
+ dashboards = [
89
+ { name: "overview", path: "dashboards/overview.malloy", title: "Zebra" },
90
+ ];
91
+ notebooks = [
92
+ { path: "notebooks/tour.malloy", title: "Aardvark" },
93
+ { path: "notebooks/plain.malloy", title: "notebooks/plain.malloy" },
94
+ ];
95
+ mount();
96
+
97
+ expect(await rows()).toEqual([
98
+ "AardvarkNotebook",
99
+ "plainNotebook",
100
+ "ZebraDashboard",
101
+ ]);
102
+ expect(screen.queryByRole("heading", { name: "Dashboards" })).toBeNull();
103
+ expect(screen.queryByRole("heading", { name: "Notebooks" })).toBeNull();
104
+ });
105
+
106
+ it("shows the folder only to tell two files with one slug apart, and opens each by its kind", async () => {
107
+ dashboards = [{ name: "story", path: "dashboards/story.malloy" }];
108
+ notebooks = [
109
+ { path: "notebooks/story.malloy" },
110
+ { path: "notebooks/solo.malloy" },
111
+ ];
112
+ mount();
113
+
114
+ expect(await rows()).toEqual([
115
+ "solo" + "Notebook",
116
+ "story" + "dashboards/story.malloy" + "Dashboard",
117
+ "story" + "notebooks/story.malloy" + "Notebook",
118
+ ]);
119
+ fireEvent.click(screen.getByText("dashboards/story.malloy"));
120
+ fireEvent.click(screen.getByText("notebooks/story.malloy"));
121
+ expect(onClick.mock.calls.map((call) => call[0])).toEqual([
122
+ "/env/pkg/dashboards/story",
123
+ "/env/pkg/notebooks/story",
124
+ ]);
125
+ });
126
+
127
+ it("keeps a titled .malloynb's path as its secondary text", async () => {
128
+ notebooks = [{ path: "orders.malloynb", title: "Orders" }];
129
+ mount();
130
+
131
+ expect(await rows()).toEqual(["Ordersorders.malloynbNotebook"]);
132
+ });
133
+
134
+ it("says so when either list fails, and still lists the other", async () => {
135
+ dashboards = [{ name: "overview", path: "dashboards/overview.malloy" }];
136
+ listNotebooks.mockImplementationOnce(() =>
137
+ Promise.reject({ response: { status: 501 } }),
138
+ );
139
+ mount();
140
+
141
+ expect(
142
+ await screen.findByText(/Could not list some artifacts/),
143
+ ).toBeDefined();
144
+ expect(await rows()).toEqual(["overviewDashboard"]);
145
+ });
146
+
147
+ it("treats a 404 on the notebooks list as none, without an error", async () => {
148
+ dashboards = [{ name: "overview", path: "dashboards/overview.malloy" }];
149
+ listNotebooks.mockImplementationOnce(() =>
150
+ Promise.reject({ response: { status: 404 } }),
151
+ );
152
+ mount();
153
+
154
+ expect(await rows()).toEqual(["overviewDashboard"]);
155
+ expect(screen.queryByText(/Could not list/)).toBeNull();
156
+ });
157
+
158
+ it("lists host drafts of both kinds, each opening its own editor", async () => {
159
+ const draft = (
160
+ type: "dashboard" | "notebook",
161
+ slug: string,
162
+ ): DocumentLocator => ({
163
+ workspace: "browser",
164
+ type,
165
+ path: `env/pkg/${type}s/${slug}.malloy`,
166
+ });
167
+ const stored = [draft("dashboard", "d-one"), draft("notebook", "n-one")];
168
+ const storage: DocumentStorage = {
169
+ listWorkspaces: async () => [
170
+ { name: "browser", writeable: true, description: "This browser" },
171
+ ],
172
+ listDocuments: async (_workspace, type) =>
173
+ stored.filter((locator) => locator.type === type),
174
+ getDocument: async () => {
175
+ throw new Error("absent");
176
+ },
177
+ saveDocument: async () => {},
178
+ deleteDocument: async () => {},
179
+ moveDocument: async () => {},
180
+ };
181
+ dashboards = [{ name: "overview", path: "dashboards/overview.malloy" }];
182
+ mount(storage);
183
+
184
+ fireEvent.click(await screen.findByText("d-one"));
185
+ fireEvent.click(await screen.findByText("n-one"));
186
+ expect(onClick.mock.calls.map((call) => call[0])).toEqual([
187
+ "/env/pkg/dashboards/d-one/edit",
188
+ "/env/pkg/notebooks/n-one/edit",
189
+ ]);
190
+ });