@malloy-publisher/sdk 0.3.0 → 0.4.0

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 (244) hide show
  1. package/README.md +22 -9
  2. package/dist/DocumentStorageProvider-CyOJ0hqf.es.js +24443 -0
  3. package/dist/DocumentStorageProvider-DGPQEd_l.cjs.js +134 -0
  4. package/dist/RenderedResult-BnPzJ9Jf.es.js +549 -0
  5. package/dist/RenderedResult-Dp22kZsQ.cjs.js +115 -0
  6. package/dist/{ServerProvider-DSK9rfSY.es.js → ServerProvider-BWOEKg0O.es.js} +1256 -1318
  7. package/dist/ServerProvider-Cc489A3f.cjs.js +1 -0
  8. package/dist/builder/index.cjs.js +105 -0
  9. package/dist/builder/index.d.ts +2 -0
  10. package/dist/builder/index.es.js +9482 -0
  11. package/dist/builder-entry.d.ts +8 -0
  12. package/dist/client/api.d.ts +100 -42
  13. package/dist/client/index.cjs.js +1 -1
  14. package/dist/client/index.es.js +1 -1
  15. package/dist/components/AppDialog.d.ts +30 -0
  16. package/dist/components/BackLink.d.ts +32 -0
  17. package/dist/components/Dashboard/Dashboard.d.ts +19 -14
  18. package/dist/components/Dashboard/DashboardBar.d.ts +21 -0
  19. package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
  20. package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
  21. package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
  22. package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
  23. package/dist/components/Dashboard/TileCard.d.ts +44 -0
  24. package/dist/components/Dashboard/index.d.ts +2 -0
  25. package/dist/components/Dashboard/promoteMeasureRow.d.ts +7 -3
  26. package/dist/components/Dashboard/telemetry.d.ts +48 -0
  27. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
  28. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +31 -0
  29. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +118 -0
  30. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +30 -0
  31. package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
  32. package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
  33. package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
  34. package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
  35. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
  36. package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
  37. package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
  38. package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
  39. package/dist/components/DashboardBuilder/controls.d.ts +157 -0
  40. package/dist/components/DashboardBuilder/diff.d.ts +35 -0
  41. package/dist/components/DashboardBuilder/document.d.ts +218 -0
  42. package/dist/components/DashboardBuilder/layout.d.ts +71 -0
  43. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
  44. package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
  45. package/dist/components/DashboardBuilder/preview.d.ts +60 -0
  46. package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
  47. package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
  48. package/dist/components/DashboardBuilder/spliceDocument.d.ts +53 -0
  49. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
  50. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
  51. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
  52. package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
  53. package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
  54. package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
  55. package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
  56. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +7 -0
  57. package/dist/components/DocumentStorage/index.d.ts +1 -1
  58. package/dist/components/FloatingIconButton.d.ts +16 -0
  59. package/dist/components/ItemRow.d.ts +38 -0
  60. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +1 -2
  61. package/dist/components/Materializations/MaterializationRunsList.d.ts +1 -5
  62. package/dist/components/Materializations/Materializations.d.ts +7 -3
  63. package/dist/components/Materializations/ScopeButton.d.ts +18 -0
  64. package/dist/components/Materializations/SectionLabel.d.ts +7 -4
  65. package/dist/components/Materializations/TriggerLabel.d.ts +14 -0
  66. package/dist/components/Materializations/index.d.ts +0 -1
  67. package/dist/components/Package/ContentTypeIcon.d.ts +3 -5
  68. package/dist/components/Package/NewDashboardDialog.d.ts +18 -0
  69. package/dist/components/Package/index.d.ts +0 -1
  70. package/dist/components/PackageSection.d.ts +23 -0
  71. package/dist/components/Prose.d.ts +46 -0
  72. package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
  73. package/dist/components/RenderedResult/index.d.ts +1 -0
  74. package/dist/components/buttons.d.ts +53 -0
  75. package/dist/components/drill/index.d.ts +1 -1
  76. package/dist/components/drill/resolveDrill.d.ts +22 -0
  77. package/dist/components/drill/useDrill.d.ts +11 -2
  78. package/dist/components/index.d.ts +6 -0
  79. package/dist/components/styles.d.ts +49 -44
  80. package/dist/hooks/index.d.ts +2 -0
  81. package/dist/hooks/useCrudMutation.d.ts +42 -0
  82. package/dist/hooks/useDocumentControls.d.ts +70 -0
  83. package/dist/hooks/useQueryResult.d.ts +40 -0
  84. package/dist/index.cjs.js +22 -273
  85. package/dist/index.d.ts +1 -0
  86. package/dist/index.es.js +16888 -44451
  87. package/dist/telemetry/consoleEvents.d.ts +60 -0
  88. package/dist/utils/malloyLiteral.d.ts +11 -0
  89. package/dist/utils/sha256.d.ts +2 -0
  90. package/package.json +24 -9
  91. package/src/builder-entry.ts +55 -0
  92. package/src/components/AppDialog.tsx +115 -0
  93. package/src/components/BackLink.tsx +83 -0
  94. package/src/components/Connections/AddConnectionDialog.tsx +50 -70
  95. package/src/components/Connections/DeleteConnectionDialog.tsx +23 -50
  96. package/src/components/Connections/EditConnectionDialog.tsx +54 -73
  97. package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
  98. package/src/components/Dashboard/Dashboard.tsx +165 -175
  99. package/src/components/Dashboard/DashboardBar.tsx +88 -0
  100. package/src/components/Dashboard/DashboardGrid.tsx +124 -0
  101. package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
  102. package/src/components/Dashboard/DashboardTile.tsx +66 -123
  103. package/src/components/Dashboard/ExploreDialog.tsx +84 -0
  104. package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
  105. package/src/components/Dashboard/RowsDialog.tsx +234 -0
  106. package/src/components/Dashboard/TileCard.tsx +120 -0
  107. package/src/components/Dashboard/index.ts +2 -0
  108. package/src/components/Dashboard/promoteMeasureRow.spec.ts +70 -0
  109. package/src/components/Dashboard/promoteMeasureRow.ts +33 -2
  110. package/src/components/Dashboard/telemetry.ts +51 -0
  111. package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
  112. package/src/components/DashboardBuilder/AddTileDialog.tsx +247 -0
  113. package/src/components/DashboardBuilder/BuilderToolbar.tsx +162 -0
  114. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +852 -0
  115. package/src/components/DashboardBuilder/DashboardBuilder.tsx +666 -0
  116. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
  117. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +188 -0
  118. package/src/components/DashboardBuilder/DashboardEditor.tsx +567 -0
  119. package/src/components/DashboardBuilder/DiffDialog.tsx +122 -0
  120. package/src/components/DashboardBuilder/DrillDialog.tsx +269 -0
  121. package/src/components/DashboardBuilder/FilterDialog.tsx +562 -0
  122. package/src/components/DashboardBuilder/FilterStrip.tsx +126 -0
  123. package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
  124. package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
  125. package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
  126. package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
  127. package/src/components/DashboardBuilder/catalog.ts +225 -0
  128. package/src/components/DashboardBuilder/controls.spec.ts +243 -0
  129. package/src/components/DashboardBuilder/controls.ts +398 -0
  130. package/src/components/DashboardBuilder/diff.spec.ts +44 -0
  131. package/src/components/DashboardBuilder/diff.ts +93 -0
  132. package/src/components/DashboardBuilder/document.ts +209 -0
  133. package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
  134. package/src/components/DashboardBuilder/layout.ts +143 -0
  135. package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
  136. package/src/components/DashboardBuilder/malloyText.ts +151 -0
  137. package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
  138. package/src/components/DashboardBuilder/newDashboard.spec.ts +40 -0
  139. package/src/components/DashboardBuilder/newDashboard.ts +48 -0
  140. package/src/components/DashboardBuilder/preview.spec.ts +149 -0
  141. package/src/components/DashboardBuilder/preview.ts +172 -0
  142. package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
  143. package/src/components/DashboardBuilder/readDocument.ts +467 -0
  144. package/src/components/DashboardBuilder/sortable.tsx +151 -0
  145. package/src/components/DashboardBuilder/spliceDocument.spec.ts +1161 -0
  146. package/src/components/DashboardBuilder/spliceDocument.ts +1135 -0
  147. package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
  148. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
  149. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +311 -0
  150. package/src/components/DashboardBuilder/useDashboardEditor.ts +201 -0
  151. package/src/components/DashboardBuilder/useDraft.ts +43 -0
  152. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
  153. package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
  154. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
  155. package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
  156. package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
  157. package/src/components/DashboardBuilder/useTileResize.ts +110 -0
  158. package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
  159. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +12 -0
  160. package/src/components/DocumentStorage/index.ts +1 -0
  161. package/src/components/Environment/About.tsx +16 -62
  162. package/src/components/Environment/AddPackageDialog.tsx +85 -154
  163. package/src/components/Environment/Connections.tsx +125 -205
  164. package/src/components/Environment/DeletePackageDialog.tsx +32 -77
  165. package/src/components/Environment/EditPackageDialog.tsx +46 -58
  166. package/src/components/Environment/Environment.tsx +34 -36
  167. package/src/components/Environment/Packages.tsx +63 -128
  168. package/src/components/FloatingIconButton.tsx +41 -0
  169. package/src/components/Home/AddEnvironmentDialog.tsx +47 -70
  170. package/src/components/Home/DeleteEnvironmentDialog.tsx +32 -77
  171. package/src/components/Home/EditEnvironmentDialog.tsx +47 -61
  172. package/src/components/Home/Home.tsx +101 -214
  173. package/src/components/ItemRow.tsx +165 -0
  174. package/src/components/Materializations/CreateMaterializationDialog.tsx +34 -51
  175. package/src/components/Materializations/DeleteMaterializationDialog.tsx +31 -53
  176. package/src/components/Materializations/MaterializationDetailDialog.tsx +60 -69
  177. package/src/components/Materializations/MaterializationRunsList.tsx +29 -42
  178. package/src/components/Materializations/Materializations.tsx +137 -140
  179. package/src/components/Materializations/ScopeButton.tsx +85 -0
  180. package/src/components/Materializations/SectionLabel.tsx +7 -4
  181. package/src/components/Materializations/SetScheduleDialog.tsx +48 -89
  182. package/src/components/Materializations/TriggerLabel.tsx +36 -0
  183. package/src/components/Materializations/cron.spec.ts +113 -0
  184. package/src/components/Materializations/index.ts +0 -1
  185. package/src/components/Materializations/utils.spec.ts +182 -0
  186. package/src/components/Model/Model.tsx +6 -23
  187. package/src/components/Model/ModelCell.tsx +33 -72
  188. package/src/components/Notebook/Notebook.tsx +25 -88
  189. package/src/components/Notebook/NotebookCell.tsx +35 -183
  190. package/src/components/Package/ContentTypeIcon.spec.ts +22 -37
  191. package/src/components/Package/ContentTypeIcon.tsx +10 -12
  192. package/src/components/Package/NewDashboardDialog.spec.tsx +129 -0
  193. package/src/components/Package/NewDashboardDialog.tsx +265 -0
  194. package/src/components/Package/Package.tsx +179 -238
  195. package/src/components/Package/index.ts +0 -1
  196. package/src/components/PackageSection.tsx +85 -0
  197. package/src/components/Prose.spec.tsx +85 -0
  198. package/src/components/Prose.tsx +179 -0
  199. package/src/components/QueryResult/QueryResult.tsx +15 -43
  200. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +198 -0
  201. package/src/components/RenderedResult/RenderedResult.tsx +22 -8
  202. package/src/components/RenderedResult/ResultContainer.tsx +4 -12
  203. package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
  204. package/src/components/RenderedResult/ResultPanel.tsx +73 -0
  205. package/src/components/RenderedResult/index.ts +1 -0
  206. package/src/components/ResultsDialog.tsx +8 -32
  207. package/src/components/buttons.tsx +114 -0
  208. package/src/components/designSystem.spec.tsx +316 -0
  209. package/src/components/drill/index.ts +1 -0
  210. package/src/components/drill/resolveDrill.ts +22 -1
  211. package/src/components/drill/useDrill.spec.tsx +94 -0
  212. package/src/components/drill/useDrill.tsx +52 -12
  213. package/src/components/given/GivensPanel.tsx +1 -1
  214. package/src/components/given/paramCodec.spec.ts +1 -1
  215. package/src/components/index.ts +16 -0
  216. package/src/components/styles.ts +49 -122
  217. package/src/hooks/index.ts +13 -0
  218. package/src/hooks/useCrudMutation.spec.tsx +119 -0
  219. package/src/hooks/useCrudMutation.tsx +85 -0
  220. package/src/hooks/useDocumentControls.ts +170 -0
  221. package/src/hooks/useQueryResult.ts +82 -0
  222. package/src/index.ts +9 -0
  223. package/src/telemetry/consoleEvents.spec.ts +130 -0
  224. package/src/telemetry/consoleEvents.ts +124 -0
  225. package/src/theme/defaults.ts +34 -23
  226. package/src/theme/resolveTheme.spec.ts +9 -4
  227. package/src/theme/resolveTheme.ts +12 -8
  228. package/src/utils/malloyLiteral.spec.ts +43 -0
  229. package/src/utils/malloyLiteral.ts +76 -0
  230. package/src/utils/sha256.ts +13 -0
  231. package/test/README.md +1 -1
  232. package/test/serverProvider.tsx +5 -2
  233. package/vite.config.ts +5 -0
  234. package/dist/ServerProvider-CGnLjzag.cjs.js +0 -1
  235. package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +0 -14
  236. package/dist/components/Materializations/EnvironmentMaterializations.d.ts +0 -7
  237. package/dist/components/Materializations/ScheduleCard.d.ts +0 -20
  238. package/dist/components/Materializations/TriggerChip.d.ts +0 -10
  239. package/dist/components/Package/Models.d.ts +0 -6
  240. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +0 -179
  241. package/src/components/Materializations/EnvironmentMaterializations.tsx +0 -267
  242. package/src/components/Materializations/ScheduleCard.tsx +0 -231
  243. package/src/components/Materializations/TriggerChip.tsx +0 -44
  244. package/src/components/Package/Models.tsx +0 -71
@@ -1,19 +1,13 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import ArrowBackIcon from "@mui/icons-material/ArrowBack";
5
- import CloseIcon from "@mui/icons-material/Close";
4
+ import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
6
5
  import OpenInNewIcon from "@mui/icons-material/OpenInNew";
7
6
  import {
8
7
  Alert,
9
8
  Box,
10
9
  Container,
11
- Dialog,
12
- DialogContent,
13
- DialogTitle,
14
10
  IconButton,
15
- Link,
16
- Stack,
17
11
  Table,
18
12
  TableBody,
19
13
  TableCell,
@@ -22,20 +16,29 @@ import {
22
16
  Tooltip,
23
17
  Typography,
24
18
  } from "@mui/material";
25
- import React, { useState } from "react";
19
+ import { useQueryClient } from "@tanstack/react-query";
20
+ import React, { useCallback, useEffect, useState } from "react";
26
21
  import { Database } from "../../client";
27
22
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
28
23
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
29
24
  import { Loading } from "../Loading";
25
+ import type { DocumentLocator } from "../DocumentStorage/DocumentStorage";
26
+ import { useOptionalDocumentStorage } from "../DocumentStorage/DocumentStorageProvider";
30
27
  import { Notebook } from "../Notebook";
31
28
  import { useServer } from "../ServerProvider";
29
+ import { NewDashboardDialog } from "./NewDashboardDialog";
32
30
  import { encodeResourceUri, parseResourceUri } from "../../utils/formatting";
33
31
  import { serverBaseUrl } from "../../utils/dataAppEmbed";
34
- import { MONO_FONT_FAMILY } from "../styles";
35
32
  import ContentTypeIcon, {
36
33
  CONTENT_TINT,
37
34
  type ContentType,
38
35
  } from "./ContentTypeIcon";
36
+ import { AddButton } from "../buttons";
37
+ import { AppDialog } from "../AppDialog";
38
+ import { BackLink } from "../BackLink";
39
+ import { ItemRow } from "../ItemRow";
40
+ import { Materializations } from "../Materializations";
41
+ import { PackageSection } from "../PackageSection";
39
42
 
40
43
  const README_NOTEBOOK = "README.malloynb";
41
44
 
@@ -48,7 +51,8 @@ export default function Package({
48
51
  onClickPackageFile,
49
52
  resourceUri,
50
53
  }: PackageProps) {
51
- const { apiClients, server } = useServer();
54
+ const { apiClients, server, mutable } = useServer();
55
+ const queryClient = useQueryClient();
52
56
  const onClick =
53
57
  onClickPackageFile ??
54
58
  ((to: string) => {
@@ -58,6 +62,30 @@ export default function Package({
58
62
  parseResourceUri(resourceUri);
59
63
 
60
64
  const [schemaDatabase, setSchemaDatabase] = useState<Database | null>(null);
65
+ const [creating, setCreating] = useState(false);
66
+
67
+ // Dashboards saved in this browser and not (yet) in the package: the
68
+ // builder's drafts, listed so they are found rather than stumbled on.
69
+ const storage = useOptionalDocumentStorage()?.documentStorage;
70
+ const [drafts, setDrafts] = useState<DocumentLocator[]>([]);
71
+ const draftPrefix = `${environmentName}/${packageName}/dashboards/`;
72
+ const refreshDrafts = useCallback(async () => {
73
+ if (!storage) return;
74
+ const workspaces = await storage.listWorkspaces(true);
75
+ const found: DocumentLocator[] = [];
76
+ for (const workspace of workspaces)
77
+ for (const locator of await storage.listDocuments(
78
+ workspace,
79
+ "dashboard",
80
+ ))
81
+ if (locator.path.startsWith(draftPrefix)) found.push(locator);
82
+ setDrafts(found);
83
+ }, [storage, draftPrefix]);
84
+ useEffect(() => {
85
+ void refreshDrafts();
86
+ }, [refreshDrafts]);
87
+ const draftSlug = (locator: DocumentLocator) =>
88
+ locator.path.slice(draftPrefix.length).replace(/\.malloy$/, "");
61
89
 
62
90
  const pkgQuery = useQueryWithApiError({
63
91
  queryKey: ["package", environmentName, packageName, versionId],
@@ -243,25 +271,10 @@ export default function Package({
243
271
  sx={{ maxWidth: 1024, mx: "auto", px: 3, py: 6 }}
244
272
  >
245
273
  <Box sx={{ mb: 4 }}>
246
- <Link
247
- onClick={(event: React.MouseEvent) =>
248
- onClick(`/${environmentName}/`, event)
249
- }
250
- underline="none"
251
- sx={{
252
- display: "inline-flex",
253
- alignItems: "center",
254
- gap: 0.5,
255
- cursor: "pointer",
256
- color: "text.secondary",
257
- fontSize: "0.875rem",
258
- mb: 2,
259
- "&:hover": { color: "primary.main" },
260
- }}
261
- >
262
- <ArrowBackIcon sx={{ fontSize: 18 }} />
263
- Back to {environmentName}
264
- </Link>
274
+ <BackLink
275
+ label={environmentName}
276
+ onClick={(event) => onClick(`/${environmentName}/`, event)}
277
+ />
265
278
  <Typography
266
279
  variant="h4"
267
280
  component="h1"
@@ -282,6 +295,31 @@ export default function Package({
282
295
 
283
296
  {isLoading && <Loading text="Loading package..." />}
284
297
 
298
+ <NewDashboardDialog
299
+ open={creating}
300
+ environmentName={environmentName}
301
+ packageName={packageName}
302
+ models={models
303
+ .map((model) => model.path)
304
+ .filter(
305
+ (path): path is string =>
306
+ typeof path === "string" &&
307
+ path.endsWith(".malloy") &&
308
+ !path.startsWith("dashboards/"),
309
+ )}
310
+ existing={dashboards
311
+ .map((dashboard) => dashboard.name)
312
+ .filter((name): name is string => typeof name === "string")}
313
+ onClose={() => setCreating(false)}
314
+ onCreated={(slug) => {
315
+ setCreating(false);
316
+ void queryClient.invalidateQueries({ queryKey: ["dashboards"] });
317
+ onClick(
318
+ `/${environmentName}/${packageName}/dashboards/${encodeURIComponent(slug)}/edit`,
319
+ );
320
+ }}
321
+ />
322
+
285
323
  {!isLoading && (
286
324
  <>
287
325
  {/* First: the at-a-glance artifact a visitor most likely wants,
@@ -296,15 +334,6 @@ export default function Package({
296
334
  has no dashboards" is the wrong thing to conclude from a
297
335
  transport error. The 404 above stays swallowed: that one is
298
336
  an older Publisher with no route, which genuinely has none. */}
299
- {/* A listing that FAILED renders identically to a package with
300
- no dashboards: `dashboards` falls back to `[]` and the
301
- section hides itself. Only `pkgQuery` reaches the error page,
302
- so nothing else here would say a word. Now that the listing
303
- carries a `versionId`, a host that resolves it on some routes
304
- and refuses it on others has a new way in, and "this package
305
- has no dashboards" is the wrong thing to conclude from a
306
- transport error. The 404 above stays swallowed: that one is
307
- an older Publisher with no route, which genuinely has none. */}
308
337
  {dashboardsQuery.isError && (
309
338
  <Box sx={{ mb: 4 }}>
310
339
  <Alert severity="warning">
@@ -313,8 +342,22 @@ export default function Package({
313
342
  </Alert>
314
343
  </Box>
315
344
  )}
316
- {dashboards.length > 0 && (
317
- <PackageSection title="Dashboards" count={dashboards.length}>
345
+ {(dashboards.length > 0 || mutable) && (
346
+ <PackageSection
347
+ title="Dashboards"
348
+ count={dashboards.length}
349
+ action={
350
+ mutable ? (
351
+ <AddButton
352
+ label="Dashboard"
353
+ onClick={() => setCreating(true)}
354
+ />
355
+ ) : undefined
356
+ }
357
+ >
358
+ {dashboards.length === 0 && (
359
+ <EmptyRow label="No dashboards yet" />
360
+ )}
318
361
  {dashboards.map((dashboard) => {
319
362
  // A title equal to the slug is what the server falls
320
363
  // back to when the file names itself neither way, so
@@ -346,32 +389,71 @@ export default function Package({
346
389
  })}
347
390
  </PackageSection>
348
391
  )}
349
-
350
- <PackageSection title="Notebooks" count={notebooks.length}>
351
- {notebooks.map((notebook) => {
352
- // Named the way dashboards and data apps are: a notebook
353
- // that titles itself is listed by that title, with the
354
- // filename kept as the secondary label so the path a
355
- // reader needs to find the file is never lost.
356
- const hasTitle =
357
- !!notebook.title && notebook.title !== notebook.path;
358
- return (
392
+ {drafts.length > 0 && (
393
+ <PackageSection title="Drafts" count={drafts.length}>
394
+ {drafts.map((locator) => (
359
395
  <PackageItemRow
360
- key={notebook.path}
361
- type="report"
362
- label={hasTitle ? notebook.title! : notebook.path}
363
- rightLabel={hasTitle ? notebook.path : undefined}
396
+ key={locator.path}
397
+ type="dashboard"
398
+ label={draftSlug(locator)}
399
+ rightLabel="saved in this browser"
364
400
  onClick={(event) =>
365
401
  onClick(
366
- `/${environmentName}/${packageName}/${notebook.path}`,
402
+ `/${environmentName}/${packageName}/dashboards/${encodeURIComponent(draftSlug(locator))}/edit`,
367
403
  event,
368
404
  )
369
405
  }
406
+ trailingAction={
407
+ <Tooltip title="Delete this draft">
408
+ <IconButton
409
+ size="small"
410
+ aria-label={`Delete draft ${draftSlug(locator)}`}
411
+ onClick={(event) => {
412
+ event.stopPropagation();
413
+ void storage
414
+ ?.deleteDocument(locator)
415
+ .then(refreshDrafts);
416
+ }}
417
+ >
418
+ <DeleteOutlineIcon fontSize="small" />
419
+ </IconButton>
420
+ </Tooltip>
421
+ }
370
422
  />
371
- );
372
- })}
373
- {notebooks.length === 0 && <EmptyRow label="No notebooks" />}
374
- </PackageSection>
423
+ ))}
424
+ </PackageSection>
425
+ )}
426
+
427
+ {/* Hidden when empty, like Dashboards and Data Apps. A package
428
+ that holds no notebooks is not a package missing them, and a
429
+ heading over the words "No notebooks" is a row of furniture
430
+ saying nothing. */}
431
+ {notebooks.length > 0 && (
432
+ <PackageSection title="Notebooks" count={notebooks.length}>
433
+ {notebooks.map((notebook) => {
434
+ // Named the way dashboards and data apps are: a notebook
435
+ // that titles itself is listed by that title, with the
436
+ // filename kept as the secondary label so the path a
437
+ // reader needs to find the file is never lost.
438
+ const hasTitle =
439
+ !!notebook.title && notebook.title !== notebook.path;
440
+ return (
441
+ <PackageItemRow
442
+ key={notebook.path}
443
+ type="report"
444
+ label={hasTitle ? notebook.title! : notebook.path}
445
+ rightLabel={hasTitle ? notebook.path : undefined}
446
+ onClick={(event) =>
447
+ onClick(
448
+ `/${environmentName}/${packageName}/${notebook.path}`,
449
+ event,
450
+ )
451
+ }
452
+ />
453
+ );
454
+ })}
455
+ </PackageSection>
456
+ )}
375
457
 
376
458
  {dataApps.length > 0 && (
377
459
  <PackageSection title="Data Apps" count={dataApps.length}>
@@ -475,18 +557,7 @@ export default function Package({
475
557
  {databases.length === 0 && <EmptyRow label="No data files" />}
476
558
  </PackageSection>
477
559
 
478
- <PackageSection title="Materializations">
479
- <PackageItemRow
480
- type="materialization"
481
- label="Materializations"
482
- onClick={(event) =>
483
- onClick(
484
- `/${environmentName}/${packageName}/materializations`,
485
- event,
486
- )
487
- }
488
- />
489
- </PackageSection>
560
+ <Materializations resourceUri={resourceUri} />
490
561
 
491
562
  {hasReadme && (
492
563
  <Box sx={{ mt: 6 }}>
@@ -499,98 +570,42 @@ export default function Package({
499
570
  </>
500
571
  )}
501
572
 
502
- <Dialog
573
+ <AppDialog
503
574
  open={schemaDatabase !== null}
504
575
  onClose={() => setSchemaDatabase(null)}
505
- maxWidth="sm"
506
- fullWidth
507
- >
508
- <DialogTitle sx={{ pr: 6 }}>
509
- {schemaDatabase?.path}
510
- <IconButton
511
- aria-label="close"
512
- onClick={() => setSchemaDatabase(null)}
513
- sx={{ position: "absolute", right: 8, top: 8 }}
514
- >
515
- <CloseIcon fontSize="small" />
516
- </IconButton>
517
- </DialogTitle>
518
- <DialogContent>
519
- {schemaDatabase?.error && (
520
- <Typography variant="body2" color="error">
521
- {schemaDatabase.error}
522
- </Typography>
523
- )}
524
- {schemaDatabase?.info?.columns && (
525
- <Table size="small">
526
- <TableHead>
527
- <TableRow>
528
- <TableCell>Column</TableCell>
529
- <TableCell>Type</TableCell>
530
- </TableRow>
531
- </TableHead>
532
- <TableBody>
533
- {schemaDatabase.info.columns.map((column) => (
534
- <TableRow key={column.name}>
535
- <TableCell component="th" scope="row">
536
- {column.name}
537
- </TableCell>
538
- <TableCell>{column.type}</TableCell>
539
- </TableRow>
540
- ))}
541
- </TableBody>
542
- </Table>
543
- )}
544
- </DialogContent>
545
- </Dialog>
546
- </Container>
547
- );
548
- }
549
-
550
- function PackageSection({
551
- title,
552
- count,
553
- children,
554
- }: {
555
- title: string;
556
- count?: number;
557
- children: React.ReactNode;
558
- }) {
559
- return (
560
- <Box sx={{ mb: 4 }}>
561
- <Stack
562
- direction="row"
563
- alignItems="baseline"
564
- spacing={1}
565
- sx={{ mb: 1 }}
576
+ title={schemaDatabase?.path ?? "Columns"}
577
+ showClose
566
578
  >
567
- <Typography
568
- variant="h6"
569
- sx={{ fontWeight: 600, letterSpacing: "-0.025em" }}
570
- >
571
- {title}
572
- </Typography>
573
- {count !== undefined && (
574
- <Typography variant="caption" color="text.secondary">
575
- ({count})
579
+ {schemaDatabase?.error && (
580
+ <Typography variant="body2" color="error">
581
+ {schemaDatabase.error}
576
582
  </Typography>
577
583
  )}
578
- </Stack>
579
- <Box>{children}</Box>
580
- </Box>
584
+ {schemaDatabase?.info?.columns && (
585
+ <Table size="small">
586
+ <TableHead>
587
+ <TableRow>
588
+ <TableCell>Column</TableCell>
589
+ <TableCell>Type</TableCell>
590
+ </TableRow>
591
+ </TableHead>
592
+ <TableBody>
593
+ {schemaDatabase.info.columns.map((column) => (
594
+ <TableRow key={column.name}>
595
+ <TableCell component="th" scope="row">
596
+ {column.name}
597
+ </TableCell>
598
+ <TableCell>{column.type}</TableCell>
599
+ </TableRow>
600
+ ))}
601
+ </TableBody>
602
+ </Table>
603
+ )}
604
+ </AppDialog>
605
+ </Container>
581
606
  );
582
607
  }
583
608
 
584
- /**
585
- * A row names its content type once. The glyph and the color behind it are two
586
- * halves of one signal, so the row derives both rather than letting a caller
587
- * pair a dashboard's icon with a model's color.
588
- *
589
- * That is not hypothetical tidying: with the two passed separately, four of the
590
- * six rows on this page had been handed the same teal, so color told a reader
591
- * nothing about four of the kinds it was there to distinguish. A rule each call
592
- * site has to remember is a rule some call sites will forget.
593
- */
594
609
  function PackageItemRow({
595
610
  type,
596
611
  label,
@@ -607,90 +622,16 @@ function PackageItemRow({
607
622
  * `event.stopPropagation()` so the row click doesn't also fire. */
608
623
  trailingAction?: React.ReactNode;
609
624
  }) {
610
- const interactive = !!onClick;
611
- const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
612
- if (!onClick) return;
613
- if (event.key === "Enter" || event.key === " ") {
614
- event.preventDefault();
615
- onClick(event as unknown as React.MouseEvent);
616
- }
617
- };
618
625
  return (
619
- <Box
620
- onClick={onClick}
621
- onKeyDown={interactive ? handleKeyDown : undefined}
622
- role={interactive ? "button" : undefined}
623
- tabIndex={interactive ? 0 : undefined}
624
- sx={(theme) => ({
625
- display: "flex",
626
- alignItems: "center",
627
- gap: 1.5,
628
- py: 1,
629
- px: 1,
630
- mx: -1,
631
- cursor: interactive ? "pointer" : "default",
632
- borderRadius: 1.5,
633
- transition: "background-color 0.1s",
634
- "&:hover": interactive
635
- ? {
636
- backgroundColor:
637
- theme.palette.mode === "dark"
638
- ? "rgba(255, 255, 255, 0.08)"
639
- : "grey.100",
640
- }
641
- : undefined,
642
- "&:focus-visible": interactive
643
- ? {
644
- outline: "2px solid",
645
- outlineColor: "primary.main",
646
- outlineOffset: 2,
647
- }
648
- : undefined,
649
- })}
650
- >
651
- <Box
652
- sx={{
653
- width: 32,
654
- height: 32,
655
- borderRadius: 1,
656
- bgcolor: CONTENT_TINT[type],
657
- color: "#FFFFFF",
658
- display: "flex",
659
- alignItems: "center",
660
- justifyContent: "center",
661
- flexShrink: 0,
662
- }}
663
- >
664
- <ContentTypeIcon type={type} />
665
- </Box>
666
- <Typography
667
- variant="body2"
668
- sx={{
669
- fontFamily: MONO_FONT_FAMILY,
670
- flex: 1,
671
- minWidth: 0,
672
- overflow: "hidden",
673
- textOverflow: "ellipsis",
674
- whiteSpace: "nowrap",
675
- }}
676
- >
677
- {label}
678
- </Typography>
679
- {rightLabel && (
680
- <Typography
681
- variant="caption"
682
- color="text.secondary"
683
- sx={{ flexShrink: 0 }}
684
- >
685
- {rightLabel}
686
- </Typography>
687
- )}
688
- {trailingAction && (
689
- <Box sx={{ flexShrink: 0, display: "flex", alignItems: "center" }}>
690
- {trailingAction}
691
- </Box>
692
- )}
693
- </Box>
626
+ <ItemRow
627
+ icon={<ContentTypeIcon type={type} />}
628
+ tint={CONTENT_TINT[type]}
629
+ label={label}
630
+ mono
631
+ {...(rightLabel === undefined ? {} : { rightLabel })}
632
+ {...(onClick === undefined ? {} : { onClick })}
633
+ {...(trailingAction === undefined ? {} : { trailingAction })}
634
+ />
694
635
  );
695
636
  }
696
637
 
@@ -2,4 +2,3 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  export { default as Package } from "./Package";
5
- export { default as Models } from "./Models";
@@ -0,0 +1,85 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Box, Stack, Typography } from "@mui/material";
5
+ import * as React from "react";
6
+ import { useId } from "react";
7
+
8
+ /**
9
+ * One titled section of a page: a heading, how many things are in it, what they
10
+ * are, and the control that adds one.
11
+ *
12
+ * Every section on every page is this component, so moving between a package
13
+ * and the environment above it does not restate the same heading at a different
14
+ * size, indent or gap.
15
+ *
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
19
+ * to share a word with it.
20
+ */
21
+ export function PackageSection({
22
+ title,
23
+ count,
24
+ description,
25
+ action,
26
+ children,
27
+ }: {
28
+ title: string;
29
+ count?: number;
30
+ /** What the section holds, in a line, under the heading. */
31
+ description?: string;
32
+ /** A control on the heading's row, hard right. */
33
+ action?: React.ReactNode;
34
+ children: React.ReactNode;
35
+ }) {
36
+ const titleId = useId();
37
+ return (
38
+ <Box component="section" aria-labelledby={titleId} sx={{ mb: 4 }}>
39
+ <Stack
40
+ direction="row"
41
+ alignItems="center"
42
+ justifyContent="space-between"
43
+ // Tall enough for the section's add button whether or not it has
44
+ // one, so a section with nothing to add does not sit tighter than
45
+ // its neighbours. The action is pushed right by the layout rather
46
+ // than by a margin on itself: `Stack`'s own spacing rule outranks
47
+ // an `ml: auto` on a child, which is how the button ended up
48
+ // beside the heading instead of at the edge.
49
+ sx={{ mb: description ? 0 : 1, minHeight: 40 }}
50
+ >
51
+ <Stack direction="row" alignItems="baseline" spacing={1}>
52
+ <Typography
53
+ id={titleId}
54
+ variant="h6"
55
+ sx={{
56
+ fontWeight: 600,
57
+ letterSpacing: "-0.025em",
58
+ // The heading's box is centred against the buttons, but
59
+ // its ink is not: at the theme's 1.6 line height the
60
+ // leading sits mostly under a word with no descenders, so
61
+ // the title reads as riding high. Trim the box to the
62
+ // glyphs and the two line up by eye as well as by
63
+ // measurement.
64
+ lineHeight: 1.2,
65
+ }}
66
+ >
67
+ {title}
68
+ </Typography>
69
+ {count !== undefined && (
70
+ <Typography variant="caption" color="text.secondary">
71
+ ({count})
72
+ </Typography>
73
+ )}
74
+ </Stack>
75
+ {action}
76
+ </Stack>
77
+ {description && (
78
+ <Typography variant="body2" color="text.secondary" sx={{ mb: 1.5 }}>
79
+ {description}
80
+ </Typography>
81
+ )}
82
+ <Box>{children}</Box>
83
+ </Box>
84
+ );
85
+ }