@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
@@ -1,42 +1,53 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import CheckIcon from "@mui/icons-material/Check";
5
4
  import { Alert, Box, Button, Stack, Typography } from "@mui/material";
6
5
  import { useQueryClient } from "@tanstack/react-query";
7
6
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
7
+ import type { DashboardManifest, Given } from "../../client";
8
+ import { modelResultsKey } from "../../hooks/useQueryResult";
8
9
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
9
10
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
10
11
  import { DashboardTile, tileTitle } from "../Dashboard/DashboardTile";
11
- import {
12
- now,
13
- type DashboardEvent,
14
- type DashboardEventHandler,
15
- } from "../Dashboard/telemetry";
12
+ import { tileIgnoredFilterLabels } from "../Dashboard/TileFilterTag";
13
+ import type { BuilderEvent } from "./telemetry";
14
+ import { now } from "../../utils/clock";
15
+ import { encodeResourceUri } from "../../utils/formatting";
16
16
  import { useDocumentControls } from "../../hooks/useDocumentControls";
17
- import { parseResourceUri } from "../../utils/formatting";
18
17
  import {
19
18
  isDocumentNotFound,
20
19
  useOptionalDocumentStorage,
21
- type DocumentLocator,
22
20
  type Workspace,
23
21
  } from "../DocumentStorage";
24
22
  import { GivensPanel } from "../given";
25
- import { SecondaryButton } from "../buttons";
26
23
  import { DashboardBar } from "../Dashboard/DashboardBar";
24
+ import type { TileHeadingSlots } from "../Dashboard/TileCard";
27
25
  import { Loading } from "../Loading";
28
26
  import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
29
27
  import { useServer } from "../ServerProvider";
30
28
  import {
31
29
  buildCatalog,
30
+ isDashboardModel,
32
31
  visibleToDashboard,
33
32
  type PackageCatalog,
34
33
  } from "./catalog";
34
+ import { locatorFor } from "../DocumentCreate/documentPath";
35
35
  import { DashboardBuilder } from "./DashboardBuilder";
36
- import type { DashboardDocument } from "./document";
37
- import { previewGivens, previewTileQuery } from "./preview";
38
- import { readDashboardDocument, readFailed } from "./readDocument";
39
- import { sha256Hex } from "../../utils/sha256";
36
+ import type { DashboardDocument, DocumentKind, QueryTile } from "./document";
37
+ import { previewGivens, previewTileQuery, tileExpressionKey } from "./preview";
38
+ import {
39
+ chooseWorkspace,
40
+ expectedHashFor,
41
+ resolveEditorTarget,
42
+ saveCaption,
43
+ saveTarget,
44
+ storageErrorMessage,
45
+ withWorkspace,
46
+ writePackageFile,
47
+ type SavesTo,
48
+ } from "./documentSession";
49
+ import { readForEditor } from "./readForEditor";
50
+ import type { SaveContext, SaveHandler } from "./useDocumentEditor";
40
51
 
41
52
  /**
42
53
  * The builder, opened on a package dashboard, with everything a host has to
@@ -75,13 +86,25 @@ export type DashboardEditorProps = (
75
86
  dashboardName: string;
76
87
  }
77
88
  ) & {
78
- /** Leave the editor: the host's "Done editing". Absent, no such button. */
89
+ /** Leave the editor: its "Close", which asks first when edits are unsaved. Absent, no such button. */
79
90
  onExit?: () => void;
80
91
  /**
81
92
  * What the editor does — opened, saved, refused — for the host to log or
82
- * count; see `DashboardEvent`.
93
+ * count; see `DashboardEvent`. A notebook reports `NotebookEvent`s instead.
94
+ */
95
+ onEvent?: (event: BuilderEvent) => void;
96
+ /**
97
+ * What the document is to the host: its storage locator and event names.
98
+ * Default `dashboard`. A notebook is a dashboard with one column, and is
99
+ * read with the authoring flag and served through the notebook endpoint.
83
100
  */
84
- onEvent?: DashboardEventHandler;
101
+ kind?: DocumentKind;
102
+ /**
103
+ * The document's file within the package, when it is not where its kind
104
+ * puts a new one (`dashboards/<slug>.malloy`, `notebooks/<slug>.malloy`):
105
+ * the kind comes from the file's own tag, so a document may sit in either.
106
+ */
107
+ path?: string;
85
108
  /**
86
109
  * Whether there are edits the record does not have, on every change and
87
110
  * whenever the editor opens a document.
@@ -93,53 +116,30 @@ export type DashboardEditorProps = (
93
116
  onDirtyChange?: (dirty: boolean) => void;
94
117
  };
95
118
 
96
- /** The Console's key for a dashboard's copy; see the storage seam's locator rule. */
97
- const dashboardLocator = (
98
- workspace: string,
99
- environmentName: string,
100
- packageName: string,
101
- modelPath: string,
102
- ): DocumentLocator => ({
103
- workspace,
104
- type: "dashboard",
105
- path: `${environmentName}/${packageName}/${modelPath}`,
106
- });
119
+ const LEGACY_REFUSAL =
120
+ "a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` notebook under notebooks/ to edit it here.";
121
+
122
+ const WITHHELD_REFUSAL =
123
+ "the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";
107
124
 
108
125
  export function DashboardEditor(props: DashboardEditorProps) {
109
- const { onExit, onEvent, onDirtyChange } = props;
110
- // Resolved once, so the rest of the body reads these locals and never the
111
- // union directly. Degraded, not thrown, on a bad URI: see `Dashboard`'s
112
- // note on the same call — a throw in a render body takes the host's whole
113
- // tree down, which is a white screen instead of a message. The deprecated
114
- // form cannot be malformed the same way, so it always names both.
115
- // `parseResourceUri` THROWS on a string that is not a `publisher://` URI at
116
- // all, which a render body must not do; only its missing-name case returns.
117
- const parsed = (() => {
118
- if (!("resourceUri" in props)) return undefined;
119
- try {
120
- return parseResourceUri(props.resourceUri);
121
- } catch {
122
- return undefined;
123
- }
124
- })();
125
- const environmentName =
126
- "resourceUri" in props
127
- ? (parsed?.environmentName ?? "")
128
- : props.environmentName;
129
- const packageName =
130
- "resourceUri" in props ? (parsed?.packageName ?? "") : props.packageName;
126
+ const { onExit, onEvent, onDirtyChange, kind = "dashboard", path } = props;
127
+ const notebook = kind === "notebook";
128
+ // Degraded, not thrown, on a bad URI: a throw in a render body takes the host's whole tree down.
129
+ const {
130
+ environmentName,
131
+ packageName,
132
+ versionId,
133
+ namesBoth: uriNamesBoth,
134
+ } = resolveEditorTarget(props);
131
135
  const dashboardName =
132
136
  "resourceUri" in props ? props.dashboard : props.dashboardName;
133
- const versionId = parsed?.versionId;
134
- // Keyed on the prop form, not on `parsed`: a URI that failed to parse at all
135
- // also leaves `parsed` undefined, and reading that as "no URI to check" would
136
- // skip the error display and run the editor against empty names.
137
- const uriNamesBoth =
138
- "resourceUri" in props
139
- ? !!parsed?.environmentName && !!parsed?.packageName
140
- : true;
137
+ const noun = notebook ? "notebook" : "dashboard";
138
+ const refusedEvent = notebook
139
+ ? ("notebook.open_refused" as const)
140
+ : ("dashboard.open_refused" as const);
141
141
 
142
- const { apiClients, mutable } = useServer();
142
+ const { apiClients, mutable, isLoadingStatus } = useServer();
143
143
  const queryClient = useQueryClient();
144
144
  // When the editor was asked for — or the reader chose what to open — so
145
145
  // "opened" can say how long it took. Read through refs by the open effect,
@@ -150,7 +150,8 @@ export function DashboardEditor(props: DashboardEditorProps) {
150
150
  const onDirtyChangeRef = useRef(onDirtyChange);
151
151
  onDirtyChangeRef.current = onDirtyChange;
152
152
  const storage = useOptionalDocumentStorage()?.documentStorage;
153
- const modelPath = `dashboards/${dashboardName}.malloy`;
153
+ const legacyFormat = notebook && /\.malloynb$/i.test(dashboardName);
154
+ const modelPath = path ?? `${kind}s/${dashboardName}.malloy`;
154
155
 
155
156
  // The file as the package has it. `sourceText` rides on the compiled model.
156
157
  const modelQuery = useQueryWithApiError({
@@ -160,15 +161,18 @@ export function DashboardEditor(props: DashboardEditorProps) {
160
161
  packageName,
161
162
  modelPath,
162
163
  versionId,
164
+ notebook,
163
165
  ],
166
+ // A curated package otherwise withholds the text of a notebook reading an off-surface source.
164
167
  queryFn: () =>
165
168
  apiClients.models.getModel(
166
169
  environmentName,
167
170
  packageName,
168
171
  modelPath,
169
172
  versionId,
173
+ notebook ? true : undefined,
170
174
  ),
171
- enabled: uriNamesBoth,
175
+ enabled: uriNamesBoth && !legacyFormat,
172
176
  });
173
177
  const packageText = (
174
178
  modelQuery.data?.data as { sourceText?: string } | undefined
@@ -198,18 +202,15 @@ export function DashboardEditor(props: DashboardEditorProps) {
198
202
  // Asking for writeable only would hide it and fall back to the
199
203
  // package, which on a server that takes writes means publishing a
200
204
  // deploy of the record over the record.
201
- const all = await storage.listWorkspaces(false);
202
- // The record when one declares itself, and otherwise the first
203
- // writeable one, which is what the editor has always taken.
204
- const chosen =
205
- all.find((candidate) => candidate.authoritative) ??
206
- all.find((candidate) => candidate.writeable);
205
+ const chosen = chooseWorkspace(await storage.listWorkspaces(false));
207
206
  if (stale) return;
208
207
  setWorkspace(chosen);
209
- if (chosen !== undefined) {
208
+ // Only a notebook's record is read: a copy beside the package is never offered back.
209
+ if (chosen !== undefined && (!notebook || chosen.authoritative)) {
210
210
  const text = await storage
211
211
  .getDocument(
212
- dashboardLocator(
212
+ locatorFor(
213
+ kind,
213
214
  chosen.name,
214
215
  environmentName,
215
216
  packageName,
@@ -234,7 +235,7 @@ export function DashboardEditor(props: DashboardEditorProps) {
234
235
  return () => {
235
236
  stale = true;
236
237
  };
237
- }, [storage, environmentName, packageName, modelPath]);
238
+ }, [storage, kind, notebook, environmentName, packageName, modelPath]);
238
239
 
239
240
  // The host's copy is the record: the editor opens it, writes back to it,
240
241
  // and never offers to "resume" it, because a record is not a pending edit.
@@ -251,10 +252,19 @@ export function DashboardEditor(props: DashboardEditorProps) {
251
252
  ? draft !== undefined
252
253
  : resume === true && draft !== undefined;
253
254
  const [opened, setOpened] = useState<
254
- | { source: string; document: DashboardDocument; generation: number }
255
+ | {
256
+ source: string;
257
+ document: DashboardDocument;
258
+ conversion?: { from: string; to: string };
259
+ /** The package file when this opened, which a draft's save overwrites. */
260
+ packageText?: string;
261
+ generation: number;
262
+ }
255
263
  | undefined
256
264
  >(undefined);
257
- const [openError, setOpenError] = useState<string | undefined>(undefined);
265
+ const [openError, setOpenError] = useState<string | undefined>(
266
+ legacyFormat ? LEGACY_REFUSAL : undefined,
267
+ );
258
268
  // The package's hash after this editor's last write, as the server computed
259
269
  // it: the base the next save is spliced against.
260
270
  const savedHashRef = useRef<string | undefined>(undefined);
@@ -287,6 +297,8 @@ export function DashboardEditor(props: DashboardEditorProps) {
287
297
  // Whether the builder holds edits the record does not have, and the version
288
298
  // being held back because of them.
289
299
  const [dirty, setDirty] = useState(false);
300
+ // A save that can still be undone is held like an edit, until the next edit: remounting on a newer version would drop the offer silently.
301
+ const [undoOffered, setUndoOffered] = useState(false);
290
302
  const [accepted, setAccepted] = useState<string | undefined>(undefined);
291
303
  // The text on this channel the editor has already reckoned with: what it
292
304
  // opened, and what it wrote. Compared against the CHANNEL rather than
@@ -300,7 +312,10 @@ export function DashboardEditor(props: DashboardEditorProps) {
300
312
  // save rather than the text the builder was opened with.
301
313
  const current = opened?.source;
302
314
  const holding =
303
- incoming && dirty && current !== undefined && latest !== accepted;
315
+ incoming &&
316
+ (dirty || undoOffered) &&
317
+ current !== undefined &&
318
+ latest !== accepted;
304
319
  const opening = holding ? current : incoming ? latest : (current ?? latest);
305
320
  const held = holding ? latest : undefined;
306
321
 
@@ -325,46 +340,101 @@ export function DashboardEditor(props: DashboardEditorProps) {
325
340
  let stale = false;
326
341
  const packageAtOpen = packageNowRef.current;
327
342
  const latestAtOpen = latestRef.current;
328
- void readDashboardDocument(opening).then((result) => {
329
- if (stale) return;
330
- if (readFailed(result)) {
331
- const reason = result.line
332
- ? `${result.reason} (line ${result.line})`
333
- : result.reason;
343
+ void readForEditor(opening, modelPath)
344
+ .then((result) => {
345
+ if (stale) return;
346
+ if (result.ok === false) {
347
+ setOpenError(result.reason);
348
+ onEventRef.current?.({
349
+ type: refusedEvent,
350
+ reason: result.reason,
351
+ });
352
+ return;
353
+ }
354
+ setOpenError(undefined);
355
+ // A different document is open, so what this editor wrote before is
356
+ // no longer the base anything is spliced against; the package file
357
+ // the reader is now answering for is the one current at this open.
358
+ savedHashRef.current = undefined;
359
+ packageBaseRef.current = packageAtOpen;
360
+ setWrote(undefined);
361
+ setAccepted(undefined);
362
+ setSeen(latestAtOpen);
363
+ setOpened((previous) => ({
364
+ source: opening,
365
+ document: result.document,
366
+ ...(result.conversion ? { conversion: result.conversion } : {}),
367
+ ...(packageAtOpen !== undefined
368
+ ? { packageText: packageAtOpen }
369
+ : {}),
370
+ generation: (previous?.generation ?? 0) + 1,
371
+ }));
372
+ onEventRef.current?.(
373
+ notebook || result.document.kind === "notebook"
374
+ ? {
375
+ type: "notebook.opened",
376
+ from:
377
+ fromRef.current === "package" ? "package" : "record",
378
+ cells: result.document.tiles.length,
379
+ durationMs: now() - startedAt.current,
380
+ }
381
+ : {
382
+ type: "dashboard.opened",
383
+ from: fromRef.current,
384
+ tiles: result.document.tiles.length,
385
+ durationMs: now() - startedAt.current,
386
+ },
387
+ );
388
+ })
389
+ .catch((error: unknown) => {
390
+ if (stale) return;
391
+ const reason = `Could not read the ${noun}: ${error instanceof Error ? error.message : String(error)}`;
334
392
  setOpenError(reason);
335
- onEventRef.current?.({ type: "dashboard.open_refused", reason });
336
- return;
337
- }
338
- setOpenError(undefined);
339
- // A different document is open, so what this editor wrote before is
340
- // no longer the base anything is spliced against; the package file
341
- // the reader is now answering for is the one current at this open.
342
- savedHashRef.current = undefined;
343
- packageBaseRef.current = packageAtOpen;
344
- setWrote(undefined);
345
- setAccepted(undefined);
346
- setSeen(latestAtOpen);
347
- setOpened((previous) => ({
348
- source: opening,
349
- document: result.document,
350
- generation: (previous?.generation ?? 0) + 1,
351
- }));
352
- onEventRef.current?.({
353
- type: "dashboard.opened",
354
- from: fromRef.current,
355
- tiles: result.document.tiles.length,
356
- durationMs: now() - startedAt.current,
393
+ onEventRef.current?.({ type: refusedEvent, reason });
357
394
  });
358
- });
359
395
  return () => {
360
396
  stale = true;
361
397
  };
362
- }, [opening, draftChecked, blockedOnRecord]);
398
+ }, [
399
+ opening,
400
+ modelPath,
401
+ draftChecked,
402
+ blockedOnRecord,
403
+ notebook,
404
+ noun,
405
+ refusedEvent,
406
+ ]);
407
+
408
+ useEffect(() => {
409
+ if (legacyFormat)
410
+ onEventRef.current?.({
411
+ type: "notebook.open_refused",
412
+ reason: LEGACY_REFUSAL,
413
+ });
414
+ }, [legacyFormat]);
415
+
416
+ const withheld =
417
+ notebook &&
418
+ !opened &&
419
+ draftChecked &&
420
+ !fromDraft &&
421
+ modelQuery.isSuccess &&
422
+ !modelQuery.isFetching &&
423
+ packageText === undefined;
424
+ useEffect(() => {
425
+ if (!withheld) return;
426
+ setOpenError(WITHHELD_REFUSAL);
427
+ onEventRef.current?.({
428
+ type: "notebook.open_refused",
429
+ reason: WITHHELD_REFUSAL,
430
+ });
431
+ }, [withheld]);
363
432
 
364
433
  const locator =
365
434
  workspace === undefined
366
435
  ? undefined
367
- : dashboardLocator(
436
+ : locatorFor(
437
+ kind,
368
438
  workspace.name,
369
439
  environmentName,
370
440
  packageName,
@@ -408,75 +478,82 @@ export function DashboardEditor(props: DashboardEditorProps) {
408
478
  // editing moves the fetch past that file, and a hash taken from it
409
479
  // would match, be accepted, and overwrite the change the reader was
410
480
  // just told about.
411
- const base = packageBaseRef.current;
412
- const expectedHash =
413
- savedHashRef.current ??
414
- (base === undefined ? undefined : await sha256Hex(base));
481
+ const expectedHash = await expectedHashFor(
482
+ savedHashRef.current,
483
+ packageBaseRef.current,
484
+ );
415
485
  if (expectedHash === undefined)
416
486
  throw new Error("The package file is still loading; try again.");
417
- let result;
418
- try {
419
- result = await apiClients.models.updateModelSource(
420
- environmentName,
421
- packageName,
422
- modelPath,
423
- { source, expectedHash },
424
- );
425
- } catch (error) {
426
- // A refused write usually means the file moved. Fetch it, so the
427
- // reader is offered that version rather than left re-saving
428
- // against a base the server will go on rejecting.
429
- void queryClient.invalidateQueries({
430
- queryKey: [
431
- "dashboard-editor-model",
432
- environmentName,
433
- packageName,
434
- modelPath,
435
- versionId,
436
- ],
437
- });
438
- throw new Error(apiErrorMessage(error));
439
- }
440
- setOpened((previous) => previous && { ...previous, source });
441
- setWrote({ text: source, onFetch: fetchedAtRef.current });
442
- setSeen(source);
443
- savedHashRef.current = result.data.contentHash;
444
- setSupersedeFailure(undefined);
445
- if (storage && locator) {
446
- try {
447
- await storage.deleteDocument(locator);
448
- setDraft(undefined);
449
- setOffered(false);
450
- } catch (error) {
451
- // Only absence means the copy is gone. Any other rejection
452
- // leaves it there, so the state must keep saying so.
453
- if (isDocumentNotFound(error)) {
454
- setDraft(undefined);
455
- setOffered(false);
456
- } else setSupersedeFailure(storageErrorMessage(error));
457
- }
458
- }
459
- // The package is what is open now, even if the copy beside it
460
- // survived the supersede: reading the channel off a stale copy would
461
- // put the builder back on the text this save replaced.
462
- setResume(false);
463
- // The package changed: the file, the manifest the live view reads,
464
- // the package's dashboards list, and the dashboard the reader sees.
465
- await queryClient.invalidateQueries({
466
- queryKey: [
467
- "dashboard-editor-model",
468
- environmentName,
469
- packageName,
470
- modelPath,
471
- versionId,
487
+ const modelKey = [
488
+ "dashboard-editor-model",
489
+ environmentName,
490
+ packageName,
491
+ modelPath,
492
+ versionId,
493
+ notebook,
494
+ ];
495
+ await writePackageFile({
496
+ apiClients,
497
+ queryClient,
498
+ environmentName,
499
+ packageName,
500
+ modelPath,
501
+ source,
502
+ expectedHash,
503
+ // A refused write usually means the file moved: fetching it offers the reader that version instead of re-saving against a base the server keeps rejecting.
504
+ invalidateOnError: [modelKey],
505
+ afterWrite: async (contentHash) => {
506
+ setOpened((previous) => previous && { ...previous, source });
507
+ setWrote({ text: source, onFetch: fetchedAtRef.current });
508
+ setSeen(source);
509
+ savedHashRef.current = contentHash;
510
+ setSupersedeFailure(undefined);
511
+ if (storage && locator) {
512
+ try {
513
+ await storage.deleteDocument(locator);
514
+ setDraft(undefined);
515
+ setOffered(false);
516
+ } catch (error) {
517
+ // Only absence means the copy is gone; any other rejection leaves it there, so the state must keep saying so.
518
+ if (isDocumentNotFound(error)) {
519
+ setDraft(undefined);
520
+ setOffered(false);
521
+ } else setSupersedeFailure(storageErrorMessage(error));
522
+ }
523
+ }
524
+ // The package is what is open now even if the copy survived the supersede; reading the channel off a stale copy would put the builder back on the text this save replaced.
525
+ setResume(false);
526
+ },
527
+ invalidate: [
528
+ { queryKey: modelKey, wait: true },
529
+ // A cached result is keyed on the query text, not the file, so a changed chart would otherwise be drawn from the old rows.
530
+ {
531
+ queryKey: modelResultsKey({
532
+ environmentName,
533
+ packageName,
534
+ versionId,
535
+ modelPath,
536
+ }),
537
+ },
538
+ { queryKey: ["dashboard-editor-manifest"] },
539
+ { queryKey: ["dashboards"] },
540
+ { queryKey: ["dashboard"] },
541
+ // The notebook viewer keys its read on the resource URI.
542
+ ...(notebook
543
+ ? [
544
+ {
545
+ queryKey: [
546
+ encodeResourceUri({
547
+ environmentName,
548
+ packageName,
549
+ modelPath,
550
+ }),
551
+ ],
552
+ },
553
+ ]
554
+ : []),
472
555
  ],
473
556
  });
474
- for (const key of [
475
- "dashboard-editor-manifest",
476
- "dashboards",
477
- "dashboard",
478
- ])
479
- void queryClient.invalidateQueries({ queryKey: [key] });
480
557
  },
481
558
  [
482
559
  apiClients,
@@ -484,53 +561,37 @@ export function DashboardEditor(props: DashboardEditorProps) {
484
561
  packageName,
485
562
  modelPath,
486
563
  versionId,
564
+ notebook,
487
565
  storage,
488
566
  locator,
489
567
  queryClient,
490
568
  ],
491
569
  );
492
- // `authoritative` wins outright rather than breaking a tie: a host whose
493
- // store is the record may well sit on a server that reports itself
494
- // writable, and writing the package there would edit a deploy of the
495
- // record instead of the record.
496
- const savesTo = authoritative ? "host" : mutable ? "package" : "browser";
497
570
  const canWriteWorkspace = workspace?.writeable === true;
498
- // A version is an immutable checkpoint, and `updateModelSource` cannot be
499
- // told to write against one (the server answers 501). Without this guard,
500
- // `expectedHash` would be the hash of the pinned text, the server would
501
- // refuse every save against the current file, and the catch would refetch
502
- // the same pinned text, so the "changed since you opened it" banner would
503
- // never fire either: a dead end with no way out. Storage-backed saves are
504
- // unaffected, since they never touch the package's compare-and-swap.
505
- const pinnedPackageSave = versionId !== undefined && savesTo === "package";
506
- const writer = authoritative
507
- ? storage && locator && canWriteWorkspace
571
+ // Unknown while `/status` loads, and a package write needs a yes.
572
+ const takesWrites = mutable === true;
573
+ const { savesTo, pinnedPackageSave, writer } = saveTarget({
574
+ authoritative,
575
+ mutable: takesWrites,
576
+ ...(versionId !== undefined ? { versionId } : {}),
577
+ // A notebook reads back only the record, so a copy anywhere else would be a write nobody sees.
578
+ canStore:
579
+ !!storage &&
580
+ !!locator &&
581
+ canWriteWorkspace &&
582
+ (!notebook || authoritative),
583
+ readFailed: readFailure !== undefined,
584
+ });
585
+ const save =
586
+ writer === "storage"
508
587
  ? saveToStorage
509
- : undefined
510
- : pinnedPackageSave
511
- ? undefined
512
- : mutable
513
- ? saveToPackage
514
- : storage && locator && canWriteWorkspace
515
- ? saveToStorage
516
- : undefined;
517
- // A copy that could not be read is not a copy that is not there. Saving on
518
- // that belief is what rewinds the record, so Save is off until a reader can
519
- // be told what actually happened.
520
- const save = readFailure === undefined ? writer : undefined;
588
+ : writer === "package"
589
+ ? saveToPackage
590
+ : undefined;
521
591
  const workspaceName = workspace?.name;
522
592
  const reportEvent = useCallback(
523
- (event: DashboardEvent) => {
524
- // Only where a workspace actually took the write: a save into the
525
- // package was not taken by one, and naming it there would say the
526
- // record moved somewhere it did not.
527
- onEventRef.current?.(
528
- event.type === "dashboard.saved" &&
529
- event.where !== "package" &&
530
- workspaceName !== undefined
531
- ? { ...event, workspace: workspaceName }
532
- : event,
533
- );
593
+ (event: BuilderEvent) => {
594
+ onEventRef.current?.(withWorkspace(event, workspaceName));
534
595
  },
535
596
  [workspaceName],
536
597
  );
@@ -551,30 +612,57 @@ export function DashboardEditor(props: DashboardEditorProps) {
551
612
  setAccepted(held);
552
613
  };
553
614
 
615
+ const saveLabel =
616
+ savesTo === "host" && workspace?.description
617
+ ? workspace.description
618
+ : undefined;
619
+ const caption =
620
+ !authoritative && mutable === undefined
621
+ ? isLoadingStatus
622
+ ? "Checking whether this server takes writes."
623
+ : "This server did not say whether it takes writes, so Save is off."
624
+ : saveCaption({
625
+ authoritative,
626
+ mutable: takesWrites,
627
+ pinnedPackageSave,
628
+ ...(workspace ? { workspace } : {}),
629
+ ...(readFailure !== undefined ? { readFailure } : {}),
630
+ ...(versionId !== undefined ? { versionId } : {}),
631
+ });
632
+ // The description is already the Save caption, so the note does not repeat it.
633
+ const note = caption === saveLabel ? "" : caption;
634
+
554
635
  // After every hook, so the hook order does not depend on the URI. Same
555
636
  // reasoning as `Dashboard`'s own check.
556
637
  if (!uriNamesBoth && "resourceUri" in props)
557
638
  return (
558
639
  <Alert severity="error" sx={{ m: 2 }}>
559
- A dashboard resource URI must name an environment and a package.
640
+ A {noun} resource URI must name an environment and a package.
560
641
  Received: {props.resourceUri}
561
642
  </Alert>
562
643
  );
563
- if (modelQuery.isError)
644
+ if (openError)
645
+ return (
646
+ <Alert severity="error" sx={{ m: 2 }}>
647
+ This {noun} cannot be opened in the builder: {openError}
648
+ </Alert>
649
+ );
650
+ // Only before an open: after one, a failed refetch is a banner above the builder so unsaved edits survive it.
651
+ if (modelQuery.isError && !opened)
564
652
  return (
565
653
  <ApiErrorDisplay
566
654
  error={modelQuery.error}
567
- context="Opening the dashboard"
655
+ context={`Opening the ${noun}`}
568
656
  />
569
657
  );
570
- if (!packageText || !draftChecked)
658
+ if (!opened && (!packageText || !draftChecked))
571
659
  // The bar first, so the page it is opening into is already the right
572
660
  // shape: the reader's view had a bar in this spot, and a spinner where
573
661
  // the bar was made the switch look like a page reload.
574
662
  return (
575
663
  <Stack sx={{ gap: 2 }}>
576
664
  <DashboardBar />
577
- <Loading text="Opening the dashboard…" />
665
+ <Loading text={`Opening the ${noun}…`} />
578
666
  </Stack>
579
667
  );
580
668
  // Where the host's copy IS the document, a copy that could not be read
@@ -583,37 +671,40 @@ export function DashboardEditor(props: DashboardEditorProps) {
583
671
  if (blockedOnRecord)
584
672
  return (
585
673
  <Alert severity="error" sx={{ m: 2 }}>
586
- This dashboard cannot be opened: {readFailure}
674
+ This {noun} cannot be opened: {readFailure}
587
675
  </Alert>
588
676
  );
589
- if (openError)
590
- return (
591
- <Alert severity="error" sx={{ m: 2 }}>
592
- This dashboard cannot be opened in the builder: {openError}
593
- </Alert>
594
- );
595
-
596
677
  const draftDiffers = draft !== undefined && draft !== packageText;
597
678
  return (
598
679
  <Stack sx={{ gap: 2 }}>
599
- {!authoritative && offered && draftDiffers && resume === undefined && (
600
- <Alert
601
- severity="info"
602
- action={
603
- <Stack direction="row" sx={{ gap: 1 }}>
604
- <Button size="small" onClick={() => choose(true)}>
605
- Resume
606
- </Button>
607
- <Button size="small" onClick={() => choose(false)}>
608
- Start from the package
609
- </Button>
610
- </Stack>
611
- }
612
- >
613
- You have edits to this dashboard saved in this browser that the
614
- package does not have.
680
+ {modelQuery.isError && (
681
+ <Alert severity="warning">
682
+ The {noun} could not be re-read from the server:{" "}
683
+ {modelQuery.error?.message}. Your edits are still here.
615
684
  </Alert>
616
685
  )}
686
+ {!notebook &&
687
+ !authoritative &&
688
+ offered &&
689
+ draftDiffers &&
690
+ resume === undefined && (
691
+ <Alert
692
+ severity="info"
693
+ action={
694
+ <Stack direction="row" sx={{ gap: 1 }}>
695
+ <Button size="small" onClick={() => choose(true)}>
696
+ Resume
697
+ </Button>
698
+ <Button size="small" onClick={() => choose(false)}>
699
+ Start from the package
700
+ </Button>
701
+ </Stack>
702
+ }
703
+ >
704
+ You have edits to this dashboard saved in this browser that
705
+ the package does not have.
706
+ </Alert>
707
+ )}
617
708
  {held !== undefined && (
618
709
  <Alert
619
710
  severity="warning"
@@ -623,11 +714,13 @@ export function DashboardEditor(props: DashboardEditorProps) {
623
714
  </Button>
624
715
  }
625
716
  >
626
- {savesTo === "package"
627
- ? "This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and until you do, saving is refused."
628
- : savesTo === "host"
629
- ? "This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and saving keeps yours and writes over it."
630
- : "The package's copy of this dashboard changed since you opened it. Your edits are still here; loading the new version replaces them."}
717
+ {!dirty
718
+ ? "This dashboard changed since you opened it. Loading the new version drops Undo save."
719
+ : savesTo === "package"
720
+ ? "This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and until you do, saving is refused."
721
+ : savesTo === "host"
722
+ ? "This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and saving keeps yours and writes over it."
723
+ : "The package's copy of this dashboard changed since you opened it. Your edits are still here; loading the new version replaces them."}
631
724
  </Alert>
632
725
  )}
633
726
  {supersedeFailure !== undefined && (
@@ -640,74 +733,36 @@ export function DashboardEditor(props: DashboardEditorProps) {
640
733
  {opened && (
641
734
  <Surface
642
735
  key={opened.generation}
736
+ kind={kind}
643
737
  environmentName={environmentName}
644
738
  packageName={packageName}
645
739
  modelPath={modelPath}
646
740
  slug={dashboardName}
741
+ modelGivens={
742
+ (modelQuery.data?.data as { givens?: Given[] } | undefined)
743
+ ?.givens
744
+ }
647
745
  {...(versionId !== undefined ? { versionId } : {})}
648
746
  opened={opened}
747
+ {...(fromDraft &&
748
+ writer === "package" &&
749
+ opened.packageText !== undefined
750
+ ? { replaces: opened.packageText }
751
+ : {})}
649
752
  onSave={save}
650
753
  onDirtyChange={reportDirty}
754
+ onSaveNoticeChange={setUndoOffered}
651
755
  savesTo={savesTo}
756
+ {...(saveLabel ? { saveLabel } : {})}
652
757
  {...(onEvent ? { onEvent: reportEvent } : {})}
653
- toolbar={
654
- onExit && (
655
- <SecondaryButton
656
- label="Done editing"
657
- icon={<CheckIcon />}
658
- onClick={onExit}
659
- />
660
- )
661
- }
662
- note={caption({
663
- authoritative,
664
- mutable,
665
- pinnedPackageSave,
666
- ...(workspace ? { workspace } : {}),
667
- ...(readFailure !== undefined ? { readFailure } : {}),
668
- ...(versionId !== undefined ? { versionId } : {}),
669
- })}
758
+ {...(onExit ? { onExit } : {})}
759
+ note={note}
670
760
  />
671
761
  )}
672
762
  </Stack>
673
763
  );
674
764
  }
675
765
 
676
- /**
677
- * What the toolbar says about where Save goes, in the backend's own words
678
- * wherever it has any: a workspace carries a `description` precisely so the
679
- * editor does not have to guess, and "this browser" is one host's answer
680
- * rather than the interface's.
681
- */
682
- function caption({
683
- authoritative,
684
- mutable,
685
- pinnedPackageSave,
686
- workspace,
687
- readFailure,
688
- versionId,
689
- }: {
690
- authoritative: boolean;
691
- mutable: boolean;
692
- pinnedPackageSave: boolean;
693
- workspace?: Workspace;
694
- readFailure?: string;
695
- versionId?: string;
696
- }): string {
697
- if (readFailure !== undefined)
698
- return `The saved copy could not be read, so Save is off: ${readFailure}`;
699
- if (authoritative && workspace)
700
- return workspace.writeable
701
- ? workspace.description
702
- : `${workspace.description}: you cannot save into it.`;
703
- if (pinnedPackageSave)
704
- return `Reading version ${versionId}: a version is a fixed point in history, so Save is off.`;
705
- if (mutable) return "Save writes the file into the package.";
706
- if (workspace)
707
- return `${workspace.description}: this server does not take writes.`;
708
- return "This server does not take writes.";
709
- }
710
-
711
766
  /**
712
767
  * The builder under a real control row, with the controls driving the tiles,
713
768
  * both following the LIVE document rather than the saved file.
@@ -720,66 +775,113 @@ function caption({
720
775
  * a literal, so it works the moment it is added.
721
776
  */
722
777
  function Surface({
778
+ kind,
779
+ modelGivens,
723
780
  environmentName,
724
781
  packageName,
725
782
  modelPath,
726
783
  slug,
727
784
  versionId,
728
785
  opened,
786
+ replaces,
729
787
  onSave,
730
788
  onDirtyChange,
789
+ onSaveNoticeChange,
731
790
  onEvent,
732
791
  savesTo,
733
- toolbar,
792
+ saveLabel,
793
+ onExit,
734
794
  note,
735
795
  }: {
796
+ kind: DocumentKind;
797
+ /** The model's own givens, for a cell-format notebook whose manifest the server cannot build until it is saved. */
798
+ modelGivens?: Given[];
736
799
  environmentName: string;
737
800
  packageName: string;
738
801
  modelPath: string;
739
802
  slug: string;
740
803
  versionId?: string;
741
- opened: { source: string; document: DashboardDocument; generation: number };
804
+ opened: {
805
+ source: string;
806
+ document: DashboardDocument;
807
+ conversion?: { from: string; to: string };
808
+ generation: number;
809
+ };
810
+ replaces?: string;
742
811
  onSave?: (source: string) => Promise<void>;
743
812
  onDirtyChange: (dirty: boolean) => void;
744
- onEvent?: DashboardEventHandler;
745
- savesTo: "package" | "browser" | "host";
746
- toolbar: React.ReactNode;
813
+ onSaveNoticeChange: (showing: boolean) => void;
814
+ onEvent?: (event: BuilderEvent) => void;
815
+ savesTo: SavesTo;
816
+ saveLabel?: string;
817
+ onExit?: () => void;
747
818
  note: string;
748
819
  }) {
749
820
  const { apiClients } = useServer();
821
+ const notebook = kind === "notebook";
750
822
 
751
- const { data, isSuccess } = useQueryWithApiError({
823
+ // The server serves a dashboard only once the package file has a tile, so
824
+ // an empty start becomes servable when a save puts the first one there.
825
+ const [served, setServed] = useState(opened.document.tiles.length > 0);
826
+ useEffect(
827
+ () => setServed(opened.document.tiles.length > 0),
828
+ [opened.generation, opened.document],
829
+ );
830
+
831
+ const { data, isSuccess, isError } = useQueryWithApiError({
752
832
  queryKey: [
753
833
  "dashboard-editor-manifest",
754
834
  environmentName,
755
835
  packageName,
756
836
  slug,
757
837
  versionId,
838
+ kind,
758
839
  ],
759
- queryFn: () =>
760
- apiClients.dashboards.getDashboard(
761
- environmentName,
762
- packageName,
763
- slug,
764
- versionId,
765
- ),
840
+ // A layout notebook's manifest rides on its notebook read; one in the cell format has only the tag's starting values until it is saved.
841
+ queryFn: async (): Promise<DashboardManifest> => {
842
+ if (!notebook)
843
+ return (
844
+ await apiClients.dashboards.getDashboard(
845
+ environmentName,
846
+ packageName,
847
+ slug,
848
+ versionId,
849
+ )
850
+ ).data;
851
+ const read = (
852
+ await apiClients.notebooks.getNotebook(
853
+ environmentName,
854
+ packageName,
855
+ modelPath,
856
+ versionId,
857
+ )
858
+ ).data;
859
+ return (
860
+ read.dashboard ?? {
861
+ ...(read.startingGivens
862
+ ? { startingGivens: read.startingGivens }
863
+ : {}),
864
+ ...(read.autorun === undefined ? {} : { autorun: read.autorun }),
865
+ }
866
+ );
867
+ },
868
+ // The server does not serve a dashboard with no tiles, so asking would 404.
869
+ enabled: served,
766
870
  });
767
- const manifest = data?.data;
871
+ const manifest = data;
768
872
 
769
873
  // The package's other dashboards, by slug: where a clicked cell can go.
770
874
  const { data: dashboardList } = useQueryWithApiError({
771
- queryKey: [
772
- "dashboard-editor-dashboards",
773
- environmentName,
774
- packageName,
775
- versionId,
776
- ],
875
+ // Shares the listing the page's location lookup already fetches.
876
+ queryKey: ["dashboards", environmentName, packageName, versionId],
877
+ staleTime: 60_000,
777
878
  queryFn: () =>
778
879
  apiClients.dashboards.listDashboards(
779
880
  environmentName,
780
881
  packageName,
781
882
  versionId,
782
883
  ),
884
+ enabled: !notebook,
783
885
  });
784
886
  const otherDashboards = useMemo(
785
887
  () =>
@@ -818,7 +920,14 @@ function Surface({
818
920
  packageName,
819
921
  versionId,
820
922
  )
821
- ).data.filter((m) => m.path && !m.error);
923
+ ).data.filter(
924
+ // The catalog leaves dashboards out, and this file's own text is already fetched above.
925
+ (m) =>
926
+ m.path &&
927
+ !m.error &&
928
+ !isDashboardModel(m.path) &&
929
+ !m.path.startsWith("notebooks/"),
930
+ );
822
931
  // One model that fails to load (a reload racing this fetch, say)
823
932
  // costs the catalog that model's sources, not every suggestion.
824
933
  const settled = await Promise.allSettled(
@@ -838,7 +947,25 @@ function Surface({
838
947
 
839
948
  const [doc, setDoc] = useState(opened.document);
840
949
  useEffect(() => setDoc(opened.document), [opened.document]);
841
- const modelSpecs = useMemo(() => manifest?.givens ?? [], [manifest]);
950
+ // Only a package write can make the package serve it; a copy in the host's store does not.
951
+ const saveThenServe = useMemo<SaveHandler<DashboardDocument> | undefined>(
952
+ () =>
953
+ onSave && savesTo === "package"
954
+ ? async (
955
+ source: string,
956
+ context: SaveContext<DashboardDocument>,
957
+ ) => {
958
+ await onSave(source);
959
+ // An undone first save writes back a file with no tile, which the server stops serving.
960
+ setServed(context.document.tiles.length > 0);
961
+ }
962
+ : onSave,
963
+ [onSave, savesTo],
964
+ );
965
+ const modelSpecs = useMemo(
966
+ () => manifest?.givens ?? (opened.conversion ? (modelGivens ?? []) : []),
967
+ [manifest, opened.conversion, modelGivens],
968
+ );
842
969
  const runnable = useMemo(
843
970
  () =>
844
971
  new Set(
@@ -856,7 +983,7 @@ function Surface({
856
983
  specs,
857
984
  loaded: isSuccess,
858
985
  startingValues: manifest?.startingGivens,
859
- documentKey: `${environmentName}/${packageName}/${versionId ?? ""}/${slug}/edit`,
986
+ documentKey: `${environmentName}/${packageName}/${versionId ?? ""}/${notebook ? "notebook/" : ""}${slug}/edit`,
860
987
  autorun: manifest?.autorun !== false,
861
988
  environmentName,
862
989
  packageName,
@@ -865,10 +992,33 @@ function Surface({
865
992
  documentName: slug,
866
993
  });
867
994
 
995
+ const manifestSettled = !served || isSuccess || isError;
996
+ // What the saved file's compiled tiles read, keyed as the server keys a tile expression.
997
+ const servedReads = useMemo(
998
+ () =>
999
+ new Map(
1000
+ (manifest?.tiles ?? []).flatMap((tile) =>
1001
+ tile.kind !== "text" && tile.query && tile.givenNames
1002
+ ? [[tileExpressionKey(tile.query), tile.givenNames] as const]
1003
+ : [],
1004
+ ),
1005
+ ),
1006
+ [manifest],
1007
+ );
868
1008
  const renderTile = useMemo(
869
1009
  () =>
870
- function LiveTile(tile: DashboardDocument["tiles"][number]) {
871
- const query = previewTileQuery(doc, tile, runnable, applied);
1010
+ function LiveTile(tile: QueryTile, heading?: TileHeadingSlots) {
1011
+ // The bindings a tile runs with come from the manifest; running before it lands queries every tile once unbound and again bound.
1012
+ if (!manifestSettled) return <Loading text="Running…" />;
1013
+ const query = previewTileQuery(
1014
+ doc,
1015
+ tile,
1016
+ runnable,
1017
+ applied,
1018
+ servedReads.get(
1019
+ tileExpressionKey(`${tile.source} -> ${tile.name}`),
1020
+ ),
1021
+ );
872
1022
  return (
873
1023
  <DashboardTile
874
1024
  environmentName={environmentName}
@@ -876,27 +1026,35 @@ function Surface({
876
1026
  versionId={versionId}
877
1027
  modelPath={modelPath}
878
1028
  tile={query.expression}
1029
+ {...(query.annotation
1030
+ ? { annotation: query.annotation }
1031
+ : {})}
879
1032
  label={
880
1033
  tile.label ?? tileTitle(`${tile.source} -> ${tile.name}`)
881
1034
  }
882
1035
  subtitle={tile.subtitle}
1036
+ {...(heading ? { heading } : {})}
883
1037
  borderless={tile.borderless}
884
1038
  givens={applied}
885
1039
  declaredTypes={declaredTypes}
886
1040
  givenNames={query.givenNames}
1041
+ ignoredFilters={tileIgnoredFilterLabels(query.reads, specs)}
887
1042
  height={TILE_MAX_HEIGHT}
888
1043
  />
889
1044
  );
890
1045
  },
891
1046
  [
892
1047
  doc,
1048
+ manifestSettled,
893
1049
  runnable,
1050
+ servedReads,
894
1051
  environmentName,
895
1052
  packageName,
896
1053
  versionId,
897
1054
  modelPath,
898
1055
  applied,
899
1056
  declaredTypes,
1057
+ specs,
900
1058
  ],
901
1059
  );
902
1060
 
@@ -918,15 +1076,20 @@ function Surface({
918
1076
  }))}
919
1077
  onChange={setDoc}
920
1078
  onDirtyChange={onDirtyChange}
1079
+ onSaveNoticeChange={onSaveNoticeChange}
1080
+ {...(opened.conversion ? { conversion: opened.conversion } : {})}
921
1081
  {...(catalog ? { catalog } : {})}
922
1082
  dashboards={otherDashboards}
923
1083
  {...(onEvent ? { onEvent } : {})}
924
- toolbar={toolbar}
1084
+ {...(onExit ? { onExit } : {})}
925
1085
  controls={
926
1086
  isSuccess ? <GivensPanel {...panel} layout="bar" /> : undefined
927
1087
  }
928
- {...(onSave ? { onSave } : {})}
1088
+ {...(saveThenServe ? { onSave: saveThenServe } : {})}
929
1089
  savesTo={savesTo}
1090
+ {...(saveLabel ? { saveLabel } : {})}
1091
+ {...(replaces !== undefined ? { replaces } : {})}
1092
+ modelPath={modelPath}
930
1093
  />
931
1094
  <Box sx={{ px: 0.5 }}>
932
1095
  <Typography variant="caption" sx={{ opacity: 0.7 }}>
@@ -936,16 +1099,3 @@ function Surface({
936
1099
  </Stack>
937
1100
  );
938
1101
  }
939
-
940
- /** What a storage backend said went wrong, for a reader who has to act on it. */
941
- function storageErrorMessage(error: unknown): string {
942
- return error instanceof Error ? error.message : String(error);
943
- }
944
-
945
- /** The server's own reason for a refused write, when it gave one. */
946
- function apiErrorMessage(error: unknown): string {
947
- const data = (error as { response?: { data?: { message?: string } } })
948
- .response?.data;
949
- if (data?.message) return data.message;
950
- return error instanceof Error ? error.message : String(error);
951
- }