@malloy-publisher/sdk 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (292) hide show
  1. package/dist/{Dashboard-H1kJlDFo.es.js → DashboardTile-BFcxdv7R.es.js} +15918 -17760
  2. package/dist/DashboardTile-sg8LjUk8.cjs.js +137 -0
  3. package/dist/RenderedResult-B48wAjM8.cjs.js +141 -0
  4. package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-CBLHr32C.es.js} +193 -183
  5. package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-DCV8BUWD.es.js} +529 -521
  6. package/dist/ServerProvider-HRqT3w1C.cjs.js +1 -0
  7. package/dist/builder/index.cjs.js +146 -58
  8. package/dist/builder/index.es.js +9076 -6479
  9. package/dist/builder-entry.d.ts +4 -0
  10. package/dist/client/api.d.ts +77 -47
  11. package/dist/client/configuration.d.ts +1 -1
  12. package/dist/client/index.cjs.js +1 -1
  13. package/dist/client/index.d.ts +1 -1
  14. package/dist/client/index.es.js +84 -82
  15. package/dist/components/Dashboard/Dashboard.d.ts +8 -15
  16. package/dist/components/Dashboard/DashboardGrid.d.ts +23 -6
  17. package/dist/components/Dashboard/DashboardTile.d.ts +10 -1
  18. package/dist/components/Dashboard/DashboardView.d.ts +36 -0
  19. package/dist/components/Dashboard/TileCard.d.ts +15 -4
  20. package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
  21. package/dist/components/Dashboard/index.d.ts +3 -0
  22. package/dist/components/Dashboard/telemetry.d.ts +15 -3
  23. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -1
  24. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +16 -5
  25. package/dist/components/DashboardBuilder/ChartPicker.d.ts +29 -0
  26. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +48 -21
  27. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +17 -4
  28. package/dist/components/DashboardBuilder/DiffDialog.d.ts +2 -10
  29. package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
  30. package/dist/components/DashboardBuilder/FilterStrip.d.ts +3 -1
  31. package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
  32. package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
  33. package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
  34. package/dist/components/DashboardBuilder/SaveNotice.d.ts +27 -0
  35. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +19 -7
  36. package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
  37. package/dist/components/DashboardBuilder/TextTileBody.d.ts +7 -0
  38. package/dist/components/DashboardBuilder/TileFrame.d.ts +14 -12
  39. package/dist/components/DashboardBuilder/TileMenu.d.ts +11 -3
  40. package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
  41. package/dist/components/DashboardBuilder/catalog.d.ts +4 -0
  42. package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
  43. package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
  44. package/dist/components/DashboardBuilder/controls.d.ts +2 -2
  45. package/dist/components/DashboardBuilder/document.d.ts +42 -26
  46. package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
  47. package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
  48. package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
  49. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -5
  50. package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
  51. package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
  52. package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
  53. package/dist/components/DashboardBuilder/preview.d.ts +24 -4
  54. package/dist/components/DashboardBuilder/readDocument.d.ts +4 -1
  55. package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
  56. package/dist/components/DashboardBuilder/sortable.d.ts +14 -0
  57. package/dist/components/DashboardBuilder/spliceDocument.d.ts +13 -13
  58. package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
  59. package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
  60. package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
  61. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
  62. package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
  63. package/dist/components/DashboardBuilder/useBuilderSession.d.ts +89 -0
  64. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
  65. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +17 -55
  66. package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
  67. package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
  68. package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
  69. package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
  70. package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
  71. package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
  72. package/dist/components/DocumentCreate/events.d.ts +10 -0
  73. package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
  74. package/dist/components/DocumentCreate/guards.d.ts +12 -0
  75. package/dist/components/DocumentCreate/index.d.ts +6 -0
  76. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
  77. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
  78. package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
  79. package/dist/components/NarrowEditGate.d.ts +8 -0
  80. package/dist/components/Notebook/Notebook.d.ts +1 -1
  81. package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
  82. package/dist/components/Package/Package.d.ts +1 -0
  83. package/dist/components/Package/documentLocation.d.ts +28 -0
  84. package/dist/components/Package/index.d.ts +4 -0
  85. package/dist/components/Package/useDocumentLocation.d.ts +12 -0
  86. package/dist/components/PackageSection.d.ts +2 -2
  87. package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
  88. package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
  89. package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
  90. package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
  91. package/dist/components/ServerProvider.d.ts +2 -1
  92. package/dist/components/UnsavedChangesDialog.d.ts +9 -0
  93. package/dist/components/given/GivensPanel.d.ts +2 -2
  94. package/dist/components/index.d.ts +2 -0
  95. package/dist/hooks/index.d.ts +1 -0
  96. package/dist/hooks/useNarrowScreen.d.ts +4 -0
  97. package/dist/hooks/useQueryResult.d.ts +2 -0
  98. package/dist/hooks/useSettled.d.ts +14 -0
  99. package/dist/index.cjs.js +23 -24
  100. package/dist/index.es.js +9714 -7072
  101. package/dist/text/index.cjs.js +1 -0
  102. package/dist/text/index.d.ts +2 -0
  103. package/dist/text/index.es.js +6 -0
  104. package/dist/text-entry-BJwltZiy.cjs.js +7 -0
  105. package/dist/text-entry-CbbBcZl8.es.js +196 -0
  106. package/dist/text-entry.d.ts +2 -0
  107. package/dist/utils/clock.d.ts +2 -0
  108. package/package.json +10 -1
  109. package/src/builder-entry.ts +35 -0
  110. package/src/components/Dashboard/Dashboard.tsx +27 -278
  111. package/src/components/Dashboard/DashboardGrid.tsx +68 -7
  112. package/src/components/Dashboard/DashboardTile.spec.tsx +24 -0
  113. package/src/components/Dashboard/DashboardTile.tsx +31 -4
  114. package/src/components/Dashboard/DashboardView.spec.tsx +212 -0
  115. package/src/components/Dashboard/DashboardView.tsx +352 -0
  116. package/src/components/Dashboard/RowsDialog.tsx +1 -1
  117. package/src/components/Dashboard/TileCard.tsx +44 -10
  118. package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
  119. package/src/components/Dashboard/TileFilterTag.tsx +78 -0
  120. package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
  121. package/src/components/Dashboard/index.ts +3 -0
  122. package/src/components/Dashboard/telemetry.ts +16 -5
  123. package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
  124. package/src/components/DashboardBuilder/AddTileDialog.tsx +137 -111
  125. package/src/components/DashboardBuilder/BuilderToolbar.tsx +85 -27
  126. package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
  127. package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
  128. package/src/components/DashboardBuilder/ChartPicker.tsx +153 -0
  129. package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
  130. package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +192 -0
  131. package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +329 -0
  132. package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +363 -0
  133. package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +194 -0
  134. package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +157 -0
  135. package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +124 -0
  136. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +103 -78
  137. package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +177 -0
  138. package/src/components/DashboardBuilder/DashboardBuilder.tsx +610 -315
  139. package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +58 -8
  140. package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +191 -0
  141. package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
  142. package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +316 -0
  143. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +56 -10
  144. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +5 -22
  145. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +96 -14
  146. package/src/components/DashboardBuilder/DashboardEditor.tsx +482 -332
  147. package/src/components/DashboardBuilder/DiffDialog.spec.tsx +25 -0
  148. package/src/components/DashboardBuilder/DiffDialog.tsx +5 -24
  149. package/src/components/DashboardBuilder/DrillDialog.tsx +1 -1
  150. package/src/components/DashboardBuilder/FilterDialog.tsx +10 -3
  151. package/src/components/DashboardBuilder/FilterStrip.tsx +26 -4
  152. package/src/components/DashboardBuilder/InlineMarkdown.tsx +184 -0
  153. package/src/components/DashboardBuilder/InlineText.tsx +106 -0
  154. package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
  155. package/src/components/DashboardBuilder/SaveNotice.tsx +113 -0
  156. package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +87 -0
  157. package/src/components/DashboardBuilder/SettingsPopover.tsx +225 -67
  158. package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
  159. package/src/components/DashboardBuilder/TextTileBody.tsx +28 -0
  160. package/src/components/DashboardBuilder/TileFrame.tsx +89 -115
  161. package/src/components/DashboardBuilder/TileMenu.tsx +168 -90
  162. package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
  163. package/src/components/DashboardBuilder/annotationText.ts +17 -0
  164. package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
  165. package/src/components/DashboardBuilder/artifactTagParity.spec.ts +41 -0
  166. package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
  167. package/src/components/DashboardBuilder/catalog.spec.ts +2 -0
  168. package/src/components/DashboardBuilder/catalog.ts +61 -21
  169. package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
  170. package/src/components/DashboardBuilder/changedTile.ts +28 -0
  171. package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
  172. package/src/components/DashboardBuilder/chartLine.ts +121 -0
  173. package/src/components/DashboardBuilder/controls.spec.ts +21 -10
  174. package/src/components/DashboardBuilder/controls.ts +22 -8
  175. package/src/components/DashboardBuilder/document.ts +53 -5
  176. package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
  177. package/src/components/DashboardBuilder/documentSession.ts +257 -0
  178. package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
  179. package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
  180. package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
  181. package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
  182. package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
  183. package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
  184. package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
  185. package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
  186. package/src/components/DashboardBuilder/malloyText.spec.ts +48 -0
  187. package/src/components/DashboardBuilder/malloyText.ts +181 -27
  188. package/src/components/DashboardBuilder/malloyTree.ts +155 -7
  189. package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
  190. package/src/components/DashboardBuilder/newDashboard.ts +30 -3
  191. package/src/components/DashboardBuilder/openDraft.ts +52 -0
  192. package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
  193. package/src/components/DashboardBuilder/preview.spec.ts +159 -12
  194. package/src/components/DashboardBuilder/preview.ts +83 -9
  195. package/src/components/DashboardBuilder/readDocument.spec.ts +139 -27
  196. package/src/components/DashboardBuilder/readDocument.ts +130 -44
  197. package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
  198. package/src/components/DashboardBuilder/readForEditor.ts +47 -0
  199. package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
  200. package/src/components/DashboardBuilder/sortable.spec.ts +65 -0
  201. package/src/components/DashboardBuilder/sortable.tsx +2 -12
  202. package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
  203. package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
  204. package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
  205. package/src/components/DashboardBuilder/spliceDocument.ts +762 -130
  206. package/src/components/DashboardBuilder/spliceResult.ts +15 -0
  207. package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
  208. package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
  209. package/src/components/DashboardBuilder/tagParse.ts +103 -0
  210. package/src/components/DashboardBuilder/telemetry.ts +47 -0
  211. package/src/components/DashboardBuilder/testing/artifactTagParity.json +197 -0
  212. package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
  213. package/src/components/DashboardBuilder/testing/inline.ts +25 -0
  214. package/src/components/DashboardBuilder/textTiles.spec.ts +718 -0
  215. package/src/components/DashboardBuilder/useBuilderSession.spec.ts +335 -0
  216. package/src/components/DashboardBuilder/useBuilderSession.ts +292 -0
  217. package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +65 -0
  218. package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
  219. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +36 -10
  220. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
  221. package/src/components/DashboardBuilder/useDashboardEditor.ts +54 -181
  222. package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
  223. package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
  224. package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
  225. package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
  226. package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
  227. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
  228. package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
  229. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
  230. package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
  231. package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
  232. package/src/components/DocumentCreate/canRetry.ts +19 -0
  233. package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
  234. package/src/components/DocumentCreate/createDocument.ts +159 -0
  235. package/src/components/DocumentCreate/documentPath.ts +40 -0
  236. package/src/components/DocumentCreate/events.ts +15 -0
  237. package/src/components/DocumentCreate/exportedSources.ts +25 -0
  238. package/src/components/DocumentCreate/guards.ts +45 -0
  239. package/src/components/DocumentCreate/index.ts +27 -0
  240. package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
  241. package/src/components/DocumentCreate/newNotebook.ts +44 -0
  242. package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
  243. package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
  244. package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
  245. package/src/components/Model/ModelExplorer.spec.tsx +2 -2
  246. package/src/components/Model/SourcesExplorer.tsx +2 -4
  247. package/src/components/NarrowEditGate.spec.tsx +73 -0
  248. package/src/components/NarrowEditGate.tsx +29 -0
  249. package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
  250. package/src/components/Notebook/Notebook.tsx +66 -27
  251. package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
  252. package/src/components/Package/NewDocumentDialog.tsx +401 -0
  253. package/src/components/Package/Package.artifacts.spec.tsx +190 -0
  254. package/src/components/Package/Package.create.spec.tsx +380 -0
  255. package/src/components/Package/Package.notebooks.spec.tsx +18 -0
  256. package/src/components/Package/Package.tsx +366 -171
  257. package/src/components/Package/documentLocation.spec.ts +81 -0
  258. package/src/components/Package/documentLocation.ts +55 -0
  259. package/src/components/Package/index.ts +13 -0
  260. package/src/components/Package/useDocumentLocation.ts +59 -0
  261. package/src/components/PackageSection.tsx +2 -2
  262. package/src/components/RenderedResult/RenderedResult.tsx +18 -1
  263. package/src/components/RenderedResult/ResultContainer.tsx +44 -11
  264. package/src/components/RenderedResult/ResultPanel.tsx +4 -0
  265. package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
  266. package/src/components/RenderedResult/resultSizing.ts +14 -3
  267. package/src/components/ServerProvider.tsx +2 -1
  268. package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
  269. package/src/components/UnsavedChangesDialog.tsx +49 -0
  270. package/src/components/given/GivensPanel.spec.tsx +6 -6
  271. package/src/components/given/GivensPanel.tsx +3 -3
  272. package/src/components/index.ts +2 -0
  273. package/src/hooks/index.ts +3 -0
  274. package/src/hooks/useNarrowScreen.ts +21 -0
  275. package/src/hooks/useQueryResult.ts +16 -0
  276. package/src/hooks/useSettled.spec.ts +41 -0
  277. package/src/hooks/useSettled.ts +27 -0
  278. package/src/mainEntry.spec.ts +145 -0
  279. package/src/text-entry.ts +12 -0
  280. package/src/textEntry.spec.ts +118 -0
  281. package/src/utils/clock.spec.ts +12 -0
  282. package/src/utils/clock.ts +6 -0
  283. package/vite.config.ts +4 -0
  284. package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
  285. package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
  286. package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
  287. package/dist/components/DashboardBuilder/useTileResize.d.ts +0 -29
  288. package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
  289. package/src/components/DashboardBuilder/useTileResize.spec.tsx +0 -121
  290. package/src/components/DashboardBuilder/useTileResize.ts +0 -110
  291. package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
  292. package/src/components/Package/NewDashboardDialog.tsx +0 -265
@@ -0,0 +1,81 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import {
6
+ documentRoute,
7
+ documentSlug,
8
+ locateDocument,
9
+ } from "./documentLocation";
10
+
11
+ describe("documentSlug", () => {
12
+ it("reads the slug from either folder", () => {
13
+ expect(documentSlug("notebooks/tour.malloy")).toBe("tour");
14
+ expect(documentSlug("dashboards/tour.malloy")).toBe("tour");
15
+ });
16
+
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();
21
+ expect(documentSlug(undefined)).toBeUndefined();
22
+ });
23
+ });
24
+
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",
29
+ );
30
+ });
31
+ });
32
+
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",
52
+ });
53
+ });
54
+
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
+ });
64
+ });
65
+
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",
75
+ });
76
+ });
77
+
78
+ it("is undefined for a document no listing has", () => {
79
+ expect(find("dashboard", "ghost")).toBeUndefined();
80
+ });
81
+ });
@@ -0,0 +1,55 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
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";
6
+
7
+ export interface LocatedDocument {
8
+ kind: DocumentKind;
9
+ /** The file within the package, wherever it lives. */
10
+ path: string;
11
+ }
12
+
13
+ const DOCUMENT_PATH = /^(?:dashboards|notebooks)\/([^/]+)\.malloy$/;
14
+
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];
18
+
19
+ /** The Console route of a document of this kind; the slug is a filename, so it is encoded. */
20
+ export const documentRoute = (
21
+ environmentName: string,
22
+ packageName: string,
23
+ kind: DocumentKind,
24
+ slug: string,
25
+ ) => `/${environmentName}/${packageName}/${kind}s/${encodeURIComponent(slug)}`;
26
+
27
+ /**
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.
32
+ */
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());
55
+ }
@@ -2,3 +2,16 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  export { default as Package } from "./Package";
5
+ export {
6
+ documentRoute,
7
+ documentSlug,
8
+ locateDocument,
9
+ type LocatedDocument,
10
+ } from "./documentLocation";
11
+ export { useDocumentLocation } from "./useDocumentLocation";
12
+ export {
13
+ NewDocumentDialog,
14
+ type NewDocumentDialogProps,
15
+ } from "./NewDocumentDialog";
16
+ // Exported so a host decides Retry on its own failed requests as the dialog does.
17
+ export { canRetryRequest } from "../DocumentCreate/canRetry";
@@ -0,0 +1,59 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
5
+ import { useServer } from "../ServerProvider";
6
+ import {
7
+ locateDocument,
8
+ type DocumentKind,
9
+ type LocatedDocument,
10
+ } from "./documentLocation";
11
+
12
+ /**
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.
18
+ */
19
+ export function useDocumentLocation(
20
+ environmentName: string,
21
+ packageName: string,
22
+ kind: DocumentKind,
23
+ slug: string,
24
+ 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
+ environmentName,
32
+ packageName,
33
+ versionId,
34
+ ),
35
+ });
36
+ const notebooks = useQueryWithApiError({
37
+ queryKey: ["notebooks", environmentName, packageName, versionId],
38
+ queryFn: () =>
39
+ apiClients.notebooks.listNotebooks(
40
+ environmentName,
41
+ packageName,
42
+ versionId,
43
+ ),
44
+ });
45
+ const settled = [dashboards, notebooks].every(
46
+ (query) => query.isSuccess || query.isError,
47
+ );
48
+ return {
49
+ settled,
50
+ location: settled
51
+ ? locateDocument({
52
+ kind,
53
+ slug,
54
+ dashboards: dashboards.data?.data ?? [],
55
+ notebooks: notebooks.data?.data ?? [],
56
+ })
57
+ : undefined,
58
+ };
59
+ }
@@ -14,8 +14,8 @@ import { useId } from "react";
14
14
  * size, indent or gap.
15
15
  *
16
16
  * The section is a landmark named by its own heading, which is what makes
17
- * "Dashboards" addressable — to a screen reader moving by region, and to a test
18
- * that wants the dashboards list rather than every row on the page that happens
17
+ * "Artifacts" addressable — to a screen reader moving by region, and to a test
18
+ * that wants the artifacts list rather than every row on the page that happens
19
19
  * to share a word with it.
20
20
  */
21
21
  export function PackageSection({
@@ -37,6 +37,7 @@ import {
37
37
  type DrillMetadataSource,
38
38
  } from "../drill/markDrillableCells";
39
39
  import type { DrillClickPayload } from "../drill/resolveDrill";
40
+ import { loadMalloyTag } from "../DashboardBuilder/loadMalloy";
40
41
  import type { DrillBinding } from "../drill/useDrill";
41
42
 
42
43
  type MalloyRenderElement = HTMLElement & Record<string, unknown>;
@@ -106,8 +107,12 @@ interface RenderedResultProps {
106
107
  * nothing can act on one, and then the result renders inert.
107
108
  */
108
109
  drill?: DrillBinding;
110
+ /** The box is a cell to fill: a table's root stretches to it. See `ResultContainer`. */
111
+ fill?: boolean;
109
112
  }
110
113
 
114
+ const FILL_ATTR = "data-publisher-fill";
115
+
111
116
  const createRenderer = async (
112
117
  theme: ResolvedTheme,
113
118
  onClick?: DrillBinding["onClick"],
@@ -173,7 +178,7 @@ async function extractChartThemeOverride(parsed: unknown) {
173
178
 
174
179
  let parseAnnotation: typeof import("@malloydata/malloy-tag").parseAnnotation;
175
180
  try {
176
- ({ parseAnnotation } = await import("@malloydata/malloy-tag"));
181
+ ({ parseAnnotation } = await loadMalloyTag());
177
182
  } catch {
178
183
  // Missing peer dep is an acceptable fallback. Charts render with the
179
184
  // shell theme only.
@@ -301,6 +306,12 @@ div.malloy-render .malloy-dashboard .dashboard-row-header {
301
306
  .malloy-render .malloy-dashboard .dashboard-row-header-separator {
302
307
  background: var(--malloy-render--table-border) !important;
303
308
  }
309
+ /* !important because the malloy-explorer stylesheet pins these same properties with it. */
310
+ [${FILL_ATTR}] .malloy-table.root {
311
+ height: 100% !important;
312
+ align-content: start !important;
313
+ grid-template-columns: repeat(var(--total-header-size), minmax(max-content, 1fr)) !important;
314
+ }
304
315
  .malloy-render .malloy-table .th.column-cell {
305
316
  /* Non-pinned tables have no header background in the renderer's
306
317
  own CSS (only pinned scrolled tables paint the pinned-header
@@ -379,6 +390,7 @@ function RenderedResultInner({
379
390
  drill,
380
391
  onSizeChange,
381
392
  onSizing,
393
+ fill,
382
394
  }: RenderedResultProps) {
383
395
  const ref = useRef<HTMLDivElement>(null);
384
396
  // The renderer binds its click handler at construction, so a changing
@@ -507,10 +519,14 @@ function RenderedResultInner({
507
519
  const remeasures = remeasuresAfterReady(renderAs, strategy);
508
520
  if (hasMeasuredRef.current && !remeasures) return;
509
521
 
522
+ // A filled table root is as tall as its box, which would read back as its content.
523
+ const stretched = element.hasAttribute(FILL_ATTR);
524
+ if (stretched) element.removeAttribute(FILL_ATTR);
510
525
  const renderedHeight = measureContentHeight(
511
526
  root,
512
527
  contentNodeDepth(renderAs),
513
528
  );
529
+ if (stretched) element.setAttribute(FILL_ATTR, "");
514
530
 
515
531
  if (renderedHeight > 0) {
516
532
  hasMeasuredRef.current = true;
@@ -930,6 +946,7 @@ function RenderedResultInner({
930
946
  return (
931
947
  <div
932
948
  ref={ref}
949
+ {...(fill ? { [FILL_ATTR]: "" } : {})}
933
950
  style={{
934
951
  width: "100%",
935
952
  height: inputHeight ? `${inputHeight}px` : "400px",
@@ -4,7 +4,7 @@
4
4
  import { Warning } from "@mui/icons-material";
5
5
  import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
6
6
  import { Box, Button, Tooltip, Typography } from "@mui/material";
7
- import { lazy, Suspense, useRef, useState } from "react";
7
+ import { lazy, Suspense, useEffect, useRef, useState } from "react";
8
8
  import { LogMessage } from "../../client";
9
9
  import type { DrillBinding } from "../drill/useDrill";
10
10
  import { FloatingIconButton } from "../FloatingIconButton";
@@ -34,6 +34,13 @@ interface ResultContainerProps {
34
34
  // is the one render path dashboards and notebooks share, which is what lets
35
35
  // drill be implemented once for both.
36
36
  drill?: DrillBinding;
37
+ /**
38
+ * Stretch to the cell this sits in: a content-sized result is floored at
39
+ * the cell's height, so a short table reaches the bottom of its card. The
40
+ * parent has to be a flex column with a definite height, which a dashboard
41
+ * tile's card is. Leave it off wherever the result sets the surface's height.
42
+ */
43
+ fill?: boolean;
37
44
  }
38
45
 
39
46
  // ResultContainer is a component that renders a result, with a toggle button to expand/collapse the result.
@@ -46,6 +53,7 @@ export default function ResultContainer({
46
53
  maxResultSize = 0,
47
54
  renderLogs,
48
55
  drill,
56
+ fill = false,
49
57
  }: ResultContainerProps) {
50
58
  const containerRef = useRef<HTMLDivElement>(null);
51
59
  // Both start unknown and are filled in by the render: `sizing` as soon as
@@ -56,8 +64,20 @@ export default function ResultContainer({
56
64
  undefined,
57
65
  );
58
66
  const [userAcknowledged, setUserAcknowledged] = useState(false);
67
+ const [cellHeight, setCellHeight] = useState<number | undefined>(undefined);
59
68
  const renderLogSummary = summarizeRenderLogs(renderLogs);
60
69
 
70
+ const hasResult = Boolean(result);
71
+ useEffect(() => {
72
+ const box = containerRef.current;
73
+ if (!fill || !box) return;
74
+ const observer = new ResizeObserver(([entry]) =>
75
+ setCellHeight(Math.round(entry.contentRect.height)),
76
+ );
77
+ observer.observe(box);
78
+ return () => observer.disconnect();
79
+ }, [fill, hasResult, userAcknowledged]);
80
+
61
81
  if (!result) {
62
82
  return null;
63
83
  }
@@ -102,7 +122,20 @@ export default function ResultContainer({
102
122
  sizing,
103
123
  contentHeight,
104
124
  maxHeight,
125
+ fillHeight: fill ? cellHeight : undefined,
105
126
  });
127
+ const renderedResult = (
128
+ <Suspense fallback={loading}>
129
+ <RenderedResult
130
+ result={result}
131
+ height={renderedHeight}
132
+ onSizeChange={setContentHeight}
133
+ onSizing={setSizing}
134
+ drill={drill}
135
+ fill={fill}
136
+ />
137
+ </Suspense>
138
+ );
106
139
 
107
140
  return (
108
141
  <Box
@@ -113,18 +146,18 @@ export default function ResultContainer({
113
146
  border: "0px",
114
147
  borderRadius: 0,
115
148
  overflow: "hidden",
149
+ // Grows from the unfloored height, so a result that gets shorter
150
+ // lets its row shrink; the result is out of flow for the same reason.
151
+ ...(fill && {
152
+ flex: `1 1 ${resolveResultHeight({ sizing, contentHeight, maxHeight })}px`,
153
+ minHeight: 0,
154
+ }),
116
155
  }}
117
156
  >
118
- {result && (
119
- <Suspense fallback={loading}>
120
- <RenderedResult
121
- result={result}
122
- height={renderedHeight}
123
- onSizeChange={setContentHeight}
124
- onSizing={setSizing}
125
- drill={drill}
126
- />
127
- </Suspense>
157
+ {fill ? (
158
+ <Box sx={{ position: "absolute", inset: 0 }}>{renderedResult}</Box>
159
+ ) : (
160
+ renderedResult
128
161
  )}
129
162
  {renderLogSummary && (
130
163
  // Overlaid rather than stacked, so the note cannot change the height
@@ -18,6 +18,8 @@ export interface ResultPanelProps {
18
18
  maxHeight?: number;
19
19
  maxResultSize?: number;
20
20
  drill?: DrillBinding;
21
+ /** See `ResultContainer`: stretch the result to its cell. */
22
+ fill?: boolean;
21
23
  /**
22
24
  * Rewrites the result before it is rendered — a dashboard tile promotes a
23
25
  * one-row measure result to KPI cards this way. Memoized on the result
@@ -44,6 +46,7 @@ export function ResultPanel({
44
46
  maxHeight,
45
47
  maxResultSize,
46
48
  drill,
49
+ fill,
47
50
  transform,
48
51
  }: ResultPanelProps) {
49
52
  const { data, isSuccess, isError, error } = state;
@@ -68,6 +71,7 @@ export function ResultPanel({
68
71
  maxResultSize={maxResultSize}
69
72
  renderLogs={data.data.renderLogs}
70
73
  drill={drill}
74
+ fill={fill}
71
75
  />
72
76
  );
73
77
  }
@@ -247,3 +247,71 @@ describe("resolveResultHeight", () => {
247
247
  expect(at("content", 0, 400)).toBe(400);
248
248
  });
249
249
  });
250
+
251
+ describe("resolveResultHeight with a cell to fill", () => {
252
+ const fill = (
253
+ sizing: "content" | "container" | undefined,
254
+ contentHeight: number | undefined,
255
+ maxHeight: number | undefined,
256
+ fillHeight: number | undefined,
257
+ ) => resolveResultHeight({ sizing, contentHeight, maxHeight, fillHeight });
258
+
259
+ it("floors a short table at the cell height", () => {
260
+ expect(fill("content", 308, 400, 440)).toBe(440);
261
+ });
262
+
263
+ it("still caps a tall table at the cap when the cell is no taller", () => {
264
+ expect(fill("content", 4000, 400, 400)).toBe(400);
265
+ expect(fill("content", 4000, 400, 300)).toBe(400);
266
+ });
267
+
268
+ it("lets a cell taller than the cap win, so the table reaches its bottom", () => {
269
+ expect(fill("content", 4000, 400, 520)).toBe(520);
270
+ });
271
+
272
+ it("leaves a chart at its cap", () => {
273
+ expect(fill("container", undefined, 400, 520)).toBe(400);
274
+ });
275
+
276
+ it("keeps the seed for a table not measured yet", () => {
277
+ expect(fill("content", undefined, 400, 520)).toBe(400);
278
+ expect(fill("content", 0, 400, 520)).toBe(400);
279
+ });
280
+
281
+ it("returns today's numbers without a cell to fill", () => {
282
+ expect(fill("content", 308, 400, undefined)).toBe(308);
283
+ expect(fill("content", 4000, 400, undefined)).toBe(400);
284
+ expect(fill("content", 4000, undefined, undefined)).toBe(4000);
285
+ });
286
+
287
+ // `.malloy-table.root` is `height: fit-content; max-height: 100%`, so its
288
+ // scrollHeight is its content however tall the stage under it is. The floor
289
+ // is therefore a fixed point: painting at it reads back the same content,
290
+ // and nothing is re-reported.
291
+ it("settles in one pass: the floor never feeds back into the measurement", () => {
292
+ const content = 308;
293
+ const scrollHeightAt = (_stage: number) => content;
294
+ const cell = 440;
295
+ let painted = fill("content", undefined, 400, cell);
296
+ const seen: number[] = [];
297
+ for (let pass = 0; pass < 5; pass++) {
298
+ const measured = scrollHeightAt(painted);
299
+ seen.push(measured);
300
+ const next = fill("content", measured, 400, cell);
301
+ if (next === painted) break;
302
+ painted = next;
303
+ }
304
+ expect(new Set(seen)).toEqual(new Set([content]));
305
+ expect(painted).toBe(cell);
306
+ });
307
+
308
+ // The cell a container reports to itself is its flex basis grown to fit, and
309
+ // the basis is the height WITHOUT the floor; a basis that included it could
310
+ // never shrink when the table's rows do.
311
+ it("takes its basis from the unfloored height, so a shorter table lets the row shrink", () => {
312
+ const basis = (content: number) =>
313
+ fill("content", content, 400, undefined);
314
+ expect(basis(308)).toBe(308);
315
+ expect(basis(100)).toBe(100);
316
+ });
317
+ });
@@ -286,15 +286,24 @@ export function initialResultHeight(maxHeight: number | undefined): number {
286
286
  * `maxHeight` is a CAP and `undefined` means uncapped — it is not a height
287
287
  * request, which is why "no cap" is expressed by leaving it out rather than by
288
288
  * passing a number big enough to mean the same thing.
289
+ *
290
+ * `fillHeight` is the room the surface has to give, for a cell that stretches
291
+ * its result (a dashboard tile). It is a FLOOR on a measured content-sized
292
+ * result and wins over the cap, so a short table reaches the bottom of its cell
293
+ * and a long one still scrolls inside it. A container-sized result ignores it,
294
+ * and so does one not measured yet, which would otherwise paint at a made-up
295
+ * height.
289
296
  */
290
297
  export function resolveResultHeight({
291
298
  sizing,
292
299
  contentHeight,
293
300
  maxHeight,
301
+ fillHeight,
294
302
  }: {
295
303
  sizing: ResultSizing | undefined;
296
304
  contentHeight: number | undefined;
297
305
  maxHeight: number | undefined;
306
+ fillHeight?: number | undefined;
298
307
  }): number {
299
308
  if (sizing === "container") {
300
309
  return maxHeight ?? UNCAPPED_CONTAINER_HEIGHT;
@@ -302,7 +311,9 @@ export function resolveResultHeight({
302
311
  if (contentHeight === undefined || contentHeight <= 0) {
303
312
  return initialResultHeight(maxHeight);
304
313
  }
305
- return maxHeight === undefined
306
- ? contentHeight
307
- : Math.min(maxHeight, contentHeight);
314
+ const own =
315
+ maxHeight === undefined
316
+ ? contentHeight
317
+ : Math.min(maxHeight, contentHeight);
318
+ return fillHeight === undefined ? own : Math.max(own, fillHeight);
308
319
  }
@@ -75,7 +75,8 @@ export interface ServerContextValue {
75
75
  server: string;
76
76
  getAccessToken?: () => Promise<string>;
77
77
  apiClients: ApiClients;
78
- mutable: boolean;
78
+ /** `undefined` while `/status` loads (or failed) and the host passed no `mutable`. */
79
+ mutable: boolean | undefined;
79
80
  isLoadingStatus: boolean;
80
81
  /**
81
82
  * Instance-wide default theme, pulled from the `/api/v0/status` response.
@@ -0,0 +1,70 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { cleanup, fireEvent, render, screen } from "@testing-library/react";
5
+ import { afterEach, describe, expect, it, mock } from "bun:test";
6
+ import { UnsavedChangesDialog } from "./UnsavedChangesDialog";
7
+
8
+ afterEach(cleanup);
9
+
10
+ const mount = (
11
+ props: { open?: boolean; canSave?: boolean; noSave?: boolean } = {},
12
+ ) => {
13
+ const handlers = {
14
+ onKeepEditing: mock(() => {}),
15
+ onDiscard: mock(() => {}),
16
+ onSaveAndExit: mock(() => {}),
17
+ };
18
+ const { onSaveAndExit, ...rest } = handlers;
19
+ render(
20
+ <UnsavedChangesDialog
21
+ open={props.open ?? true}
22
+ canSave={props.canSave ?? true}
23
+ {...rest}
24
+ {...(props.noSave ? {} : { onSaveAndExit })}
25
+ />,
26
+ );
27
+ return handlers;
28
+ };
29
+
30
+ describe("UnsavedChangesDialog", () => {
31
+ it("renders nothing while closed", () => {
32
+ mount({ open: false });
33
+ expect(screen.queryByRole("dialog")).toBeNull();
34
+ });
35
+
36
+ it("offers all three ways out when it can save", () => {
37
+ const h = mount();
38
+ fireEvent.click(screen.getByRole("button", { name: "Keep editing" }));
39
+ fireEvent.click(screen.getByRole("button", { name: "Discard changes" }));
40
+ fireEvent.click(screen.getByRole("button", { name: "Save and exit" }));
41
+ expect(h.onKeepEditing).toHaveBeenCalledTimes(1);
42
+ expect(h.onDiscard).toHaveBeenCalledTimes(1);
43
+ expect(h.onSaveAndExit).toHaveBeenCalledTimes(1);
44
+ });
45
+
46
+ it("leaves out Save and exit where nothing can be written", () => {
47
+ mount({ canSave: false });
48
+ expect(
49
+ screen.queryByRole("button", { name: "Save and exit" }),
50
+ ).toBeNull();
51
+ expect(
52
+ screen.getByRole("button", { name: "Discard changes" }),
53
+ ).toBeTruthy();
54
+ });
55
+
56
+ it("treats Escape as Keep editing", () => {
57
+ const h = mount();
58
+ fireEvent.keyDown(screen.getByRole("dialog"), { key: "Escape" });
59
+ expect(h.onKeepEditing).toHaveBeenCalledTimes(1);
60
+ expect(h.onDiscard).not.toHaveBeenCalled();
61
+ });
62
+
63
+ it("does not offer to save in its copy when it shows no Save button", () => {
64
+ mount({ noSave: true });
65
+ expect(
66
+ screen.queryByRole("button", { name: "Save and exit" }),
67
+ ).toBeNull();
68
+ expect(screen.queryByText(/Save them/)).toBeNull();
69
+ });
70
+ });
@@ -0,0 +1,49 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Button } from "@mui/material";
5
+ import { AppDialog } from "./AppDialog";
6
+
7
+ /** What to do with edits the record does not have yet, asked when someone leaves with them. */
8
+ export function UnsavedChangesDialog({
9
+ open,
10
+ canSave,
11
+ onKeepEditing,
12
+ onDiscard,
13
+ onSaveAndExit,
14
+ }: {
15
+ open: boolean;
16
+ /** False where nothing can be written (read-only, a pinned version): the way out is discarding. */
17
+ canSave: boolean;
18
+ onKeepEditing: () => void;
19
+ onDiscard: () => void;
20
+ onSaveAndExit?: () => void;
21
+ }) {
22
+ return (
23
+ <AppDialog
24
+ open={open}
25
+ onClose={onKeepEditing}
26
+ title="Leave with unsaved changes?"
27
+ description={
28
+ canSave && onSaveAndExit
29
+ ? "Your edits have not been saved. Save them, or leave without them."
30
+ : "Leaving now discards your unsaved edits."
31
+ }
32
+ actions={
33
+ <>
34
+ <Button onClick={onKeepEditing}>Keep editing</Button>
35
+ <Button color="error" onClick={onDiscard}>
36
+ Discard changes
37
+ </Button>
38
+ {canSave && onSaveAndExit && (
39
+ <Button variant="contained" onClick={onSaveAndExit}>
40
+ Save and exit
41
+ </Button>
42
+ )}
43
+ </>
44
+ }
45
+ >
46
+ {null}
47
+ </AppDialog>
48
+ );
49
+ }