@malloy-publisher/sdk 0.3.1 → 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 (129) hide show
  1. package/README.md +14 -9
  2. package/dist/{DocumentStorageProvider-tGvodI8f.es.js → DocumentStorageProvider-CyOJ0hqf.es.js} +7114 -6939
  3. package/dist/DocumentStorageProvider-DGPQEd_l.cjs.js +134 -0
  4. package/dist/{RenderedResult-mDE-4u8S.es.js → RenderedResult-BnPzJ9Jf.es.js} +64 -57
  5. package/dist/{RenderedResult-CPi6uQWq.cjs.js → RenderedResult-Dp22kZsQ.cjs.js} +2 -2
  6. package/dist/{ServerProvider-X2Ma0HRs.es.js → ServerProvider-BWOEKg0O.es.js} +1217 -1244
  7. package/dist/ServerProvider-Cc489A3f.cjs.js +1 -0
  8. package/dist/builder/index.cjs.js +41 -41
  9. package/dist/builder/index.es.js +2752 -2831
  10. package/dist/client/api.d.ts +100 -42
  11. package/dist/client/index.cjs.js +1 -1
  12. package/dist/client/index.es.js +1 -1
  13. package/dist/components/AppDialog.d.ts +30 -0
  14. package/dist/components/BackLink.d.ts +32 -0
  15. package/dist/components/Dashboard/DashboardBar.d.ts +21 -0
  16. package/dist/components/Dashboard/telemetry.d.ts +10 -5
  17. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +12 -10
  18. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +8 -2
  19. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +8 -10
  20. package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
  21. package/dist/components/DashboardBuilder/spliceDocument.d.ts +10 -1
  22. package/dist/components/ItemRow.d.ts +38 -0
  23. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +1 -2
  24. package/dist/components/Materializations/MaterializationRunsList.d.ts +1 -5
  25. package/dist/components/Materializations/Materializations.d.ts +7 -3
  26. package/dist/components/Materializations/ScopeButton.d.ts +18 -0
  27. package/dist/components/Materializations/SectionLabel.d.ts +7 -4
  28. package/dist/components/Materializations/TriggerLabel.d.ts +14 -0
  29. package/dist/components/Materializations/index.d.ts +0 -1
  30. package/dist/components/Package/ContentTypeIcon.d.ts +3 -5
  31. package/dist/components/Package/NewDashboardDialog.d.ts +18 -0
  32. package/dist/components/Package/index.d.ts +0 -1
  33. package/dist/components/PackageSection.d.ts +23 -0
  34. package/dist/components/buttons.d.ts +53 -0
  35. package/dist/components/index.d.ts +5 -0
  36. package/dist/components/styles.d.ts +49 -40
  37. package/dist/hooks/useCrudMutation.d.ts +42 -0
  38. package/dist/index.cjs.js +22 -26
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.es.js +17425 -20672
  41. package/dist/telemetry/consoleEvents.d.ts +60 -0
  42. package/dist/utils/sha256.d.ts +2 -0
  43. package/package.json +1 -1
  44. package/src/components/AppDialog.tsx +115 -0
  45. package/src/components/BackLink.tsx +83 -0
  46. package/src/components/Connections/AddConnectionDialog.tsx +50 -70
  47. package/src/components/Connections/DeleteConnectionDialog.tsx +23 -50
  48. package/src/components/Connections/EditConnectionDialog.tsx +54 -73
  49. package/src/components/Dashboard/DashboardBar.tsx +88 -0
  50. package/src/components/Dashboard/telemetry.ts +10 -3
  51. package/src/components/DashboardBuilder/AddTileDialog.tsx +141 -143
  52. package/src/components/DashboardBuilder/BuilderToolbar.tsx +110 -218
  53. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +5 -11
  54. package/src/components/DashboardBuilder/DashboardBuilder.tsx +184 -171
  55. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
  56. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +2 -25
  57. package/src/components/DashboardBuilder/DashboardEditor.tsx +135 -61
  58. package/src/components/DashboardBuilder/DiffDialog.tsx +75 -82
  59. package/src/components/DashboardBuilder/DrillDialog.tsx +144 -156
  60. package/src/components/DashboardBuilder/FilterDialog.tsx +276 -295
  61. package/src/components/DashboardBuilder/FilterStrip.tsx +11 -10
  62. package/src/components/DashboardBuilder/newDashboard.spec.ts +40 -0
  63. package/src/components/DashboardBuilder/newDashboard.ts +48 -0
  64. package/src/components/DashboardBuilder/spliceDocument.spec.ts +53 -0
  65. package/src/components/DashboardBuilder/spliceDocument.ts +45 -8
  66. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +56 -0
  67. package/src/components/DashboardBuilder/useDashboardEditor.ts +12 -4
  68. package/src/components/Environment/About.tsx +14 -28
  69. package/src/components/Environment/AddPackageDialog.tsx +85 -154
  70. package/src/components/Environment/Connections.tsx +125 -205
  71. package/src/components/Environment/DeletePackageDialog.tsx +32 -77
  72. package/src/components/Environment/EditPackageDialog.tsx +46 -58
  73. package/src/components/Environment/Environment.tsx +34 -36
  74. package/src/components/Environment/Packages.tsx +63 -128
  75. package/src/components/Home/AddEnvironmentDialog.tsx +47 -70
  76. package/src/components/Home/DeleteEnvironmentDialog.tsx +32 -77
  77. package/src/components/Home/EditEnvironmentDialog.tsx +47 -61
  78. package/src/components/Home/Home.tsx +101 -214
  79. package/src/components/ItemRow.tsx +165 -0
  80. package/src/components/Materializations/CreateMaterializationDialog.tsx +34 -51
  81. package/src/components/Materializations/DeleteMaterializationDialog.tsx +31 -53
  82. package/src/components/Materializations/MaterializationDetailDialog.tsx +60 -69
  83. package/src/components/Materializations/MaterializationRunsList.tsx +29 -42
  84. package/src/components/Materializations/Materializations.tsx +137 -140
  85. package/src/components/Materializations/ScopeButton.tsx +85 -0
  86. package/src/components/Materializations/SectionLabel.tsx +7 -4
  87. package/src/components/Materializations/SetScheduleDialog.tsx +48 -89
  88. package/src/components/Materializations/TriggerLabel.tsx +36 -0
  89. package/src/components/Materializations/cron.spec.ts +113 -0
  90. package/src/components/Materializations/index.ts +0 -1
  91. package/src/components/Materializations/utils.spec.ts +182 -0
  92. package/src/components/Package/ContentTypeIcon.spec.ts +22 -37
  93. package/src/components/Package/ContentTypeIcon.tsx +10 -12
  94. package/src/components/Package/NewDashboardDialog.spec.tsx +129 -0
  95. package/src/components/Package/NewDashboardDialog.tsx +265 -0
  96. package/src/components/Package/Package.tsx +179 -238
  97. package/src/components/Package/index.ts +0 -1
  98. package/src/components/PackageSection.tsx +85 -0
  99. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +198 -0
  100. package/src/components/RenderedResult/RenderedResult.tsx +22 -8
  101. package/src/components/ResultsDialog.tsx +8 -32
  102. package/src/components/buttons.tsx +114 -0
  103. package/src/components/designSystem.spec.tsx +316 -0
  104. package/src/components/given/paramCodec.spec.ts +1 -1
  105. package/src/components/index.ts +10 -0
  106. package/src/components/styles.ts +49 -85
  107. package/src/hooks/useCrudMutation.spec.tsx +119 -0
  108. package/src/hooks/useCrudMutation.tsx +85 -0
  109. package/src/index.ts +9 -0
  110. package/src/telemetry/consoleEvents.spec.ts +130 -0
  111. package/src/telemetry/consoleEvents.ts +124 -0
  112. package/src/theme/defaults.ts +34 -23
  113. package/src/theme/resolveTheme.spec.ts +9 -4
  114. package/src/theme/resolveTheme.ts +12 -8
  115. package/src/utils/sha256.ts +13 -0
  116. package/test/README.md +1 -1
  117. package/test/serverProvider.tsx +5 -2
  118. package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +0 -134
  119. package/dist/ServerProvider-CH71GsoL.cjs.js +0 -1
  120. package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +0 -14
  121. package/dist/components/Materializations/EnvironmentMaterializations.d.ts +0 -7
  122. package/dist/components/Materializations/ScheduleCard.d.ts +0 -20
  123. package/dist/components/Materializations/TriggerChip.d.ts +0 -10
  124. package/dist/components/Package/Models.d.ts +0 -6
  125. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +0 -179
  126. package/src/components/Materializations/EnvironmentMaterializations.tsx +0 -267
  127. package/src/components/Materializations/ScheduleCard.tsx +0 -231
  128. package/src/components/Materializations/TriggerChip.tsx +0 -44
  129. package/src/components/Package/Models.tsx +0 -71
@@ -1,15 +1,7 @@
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 {
6
- Box,
7
- Container,
8
- Link,
9
- Snackbar,
10
- Stack,
11
- Typography,
12
- } from "@mui/material";
4
+ import { Snackbar, Stack, Typography } from "@mui/material";
13
5
  import { useQueryClient } from "@tanstack/react-query";
14
6
  import React, { useState } from "react";
15
7
  import {
@@ -21,26 +13,34 @@ import {
21
13
  useMutationWithApiError,
22
14
  useQueryWithApiError,
23
15
  } from "../../hooks/useQueryWithApiError";
16
+ import { reporting } from "../../telemetry/consoleEvents";
24
17
  import { parseResourceUri } from "../../utils/formatting";
25
18
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
26
19
  import { Loading } from "../Loading";
20
+ import { PackageSection } from "../PackageSection";
27
21
  import { useServer } from "../ServerProvider";
22
+ import { describeCron, formatNextRun } from "./cron";
28
23
  import CreateMaterializationDialog from "./CreateMaterializationDialog";
29
24
  import MaterializationDetailDialog from "./MaterializationDetailDialog";
30
25
  import MaterializationRunsList from "./MaterializationRunsList";
31
- import ScheduleCard from "./ScheduleCard";
26
+ import ScopeButton from "./ScopeButton";
27
+ import SetScheduleDialog from "./SetScheduleDialog";
32
28
  import { isActiveStatus } from "./utils";
33
29
 
34
30
  const MATERIALIZATION_POLL_MS = 3000;
35
31
 
36
32
  interface MaterializationsProps {
37
33
  resourceUri: string;
38
- onClickPackageFile?: (to: string, event?: React.MouseEvent) => void;
39
34
  }
40
35
 
36
+ /**
37
+ * The package's materializations, as a section of its page: what has been
38
+ * built, and the three controls that change it — scope, schedule, and a new
39
+ * build. The runs are the package's own history, so they sit beside its
40
+ * dashboards and models rather than one click away on a page of their own.
41
+ */
41
42
  export default function Materializations({
42
43
  resourceUri,
43
- onClickPackageFile,
44
44
  }: MaterializationsProps) {
45
45
  const { apiClients, mutable } = useServer();
46
46
  const queryClient = useQueryClient();
@@ -48,12 +48,6 @@ export default function Materializations({
48
48
  const [notificationMessage, setNotificationMessage] = useState("");
49
49
  const [selectedId, setSelectedId] = useState<string | null>(null);
50
50
 
51
- const onClick =
52
- onClickPackageFile ??
53
- ((to: string) => {
54
- window.location.href = to;
55
- });
56
-
57
51
  if (!packageName) {
58
52
  throw new Error(
59
53
  "Materializations requires a package in the resource URI",
@@ -94,14 +88,18 @@ export default function Materializations({
94
88
  // Auto-run: the publisher compiles, builds every persist source, and loads
95
89
  // the resulting manifest in a single pass.
96
90
  const createMaterialization = useMutationWithApiError({
97
- mutationFn: (opts: { forceRefresh: boolean }) =>
98
- apiClients.materializations.createMaterialization(
99
- environmentName,
100
- packageName,
101
- {
102
- forceRefresh: opts.forceRefresh,
103
- },
104
- ),
91
+ mutationFn: reporting(
92
+ "materialization",
93
+ "create",
94
+ (opts: { forceRefresh: boolean }) =>
95
+ apiClients.materializations.createMaterialization(
96
+ environmentName,
97
+ packageName,
98
+ {
99
+ forceRefresh: opts.forceRefresh,
100
+ },
101
+ ),
102
+ ),
105
103
  onSuccess() {
106
104
  setNotificationMessage("Materialization requested");
107
105
  invalidateList();
@@ -113,13 +111,17 @@ export default function Materializations({
113
111
  });
114
112
 
115
113
  const stopMaterialization = useMutationWithApiError({
116
- mutationFn: (materialization: Materialization) =>
117
- apiClients.materializations.materializationAction(
118
- environmentName,
119
- packageName,
120
- materialization.id as string,
121
- MaterializationActionActionEnum.Stop,
122
- ),
114
+ mutationFn: reporting(
115
+ "materialization",
116
+ "update",
117
+ (materialization: Materialization) =>
118
+ apiClients.materializations.materializationAction(
119
+ environmentName,
120
+ packageName,
121
+ materialization.id as string,
122
+ MaterializationActionActionEnum.Stop,
123
+ ),
124
+ ),
123
125
  onSuccess() {
124
126
  setNotificationMessage("Materialization stopped");
125
127
  invalidateList();
@@ -130,19 +132,23 @@ export default function Materializations({
130
132
  });
131
133
 
132
134
  const deleteMaterialization = useMutationWithApiError({
133
- mutationFn: ({
134
- materialization,
135
- dropTables,
136
- }: {
137
- materialization: Materialization;
138
- dropTables: boolean;
139
- }) =>
140
- apiClients.materializations.deleteMaterialization(
141
- environmentName,
142
- packageName,
143
- materialization.id as string,
135
+ mutationFn: reporting(
136
+ "materialization",
137
+ "delete",
138
+ ({
139
+ materialization,
144
140
  dropTables,
145
- ),
141
+ }: {
142
+ materialization: Materialization;
143
+ dropTables: boolean;
144
+ }) =>
145
+ apiClients.materializations.deleteMaterialization(
146
+ environmentName,
147
+ packageName,
148
+ materialization.id as string,
149
+ dropTables,
150
+ ),
151
+ ),
146
152
  onSuccess() {
147
153
  setNotificationMessage("Materialization deleted");
148
154
  invalidateList();
@@ -161,7 +167,7 @@ export default function Materializations({
161
167
  // strands scope: version with no way back. The running scheduler re-arms from
162
168
  // the new cron on its next tick — no reload needed.
163
169
  const updateSchedule = useMutationWithApiError({
164
- mutationFn: (schedule: string | null) =>
170
+ mutationFn: reporting("schedule", "update", (schedule: string | null) =>
165
171
  apiClients.packages.updatePackage(environmentName, packageName, {
166
172
  name: packageName,
167
173
  // updatePackage overwrites description from the body — carry the
@@ -170,6 +176,7 @@ export default function Materializations({
170
176
  ...(schedule ? { scope: PackageScopeEnum.Version } : {}),
171
177
  materialization: { schedule },
172
178
  }),
179
+ ),
173
180
  onSuccess(_data, schedule) {
174
181
  setNotificationMessage(
175
182
  schedule ? "Schedule updated" : "Schedule cleared",
@@ -189,12 +196,13 @@ export default function Materializations({
189
196
  // still set (publish-gate Rule 2), so the UI only offers this when no
190
197
  // schedule is active.
191
198
  const updateScope = useMutationWithApiError({
192
- mutationFn: (scope: PackageScopeEnum) =>
199
+ mutationFn: reporting("scope", "update", (scope: PackageScopeEnum) =>
193
200
  apiClients.packages.updatePackage(environmentName, packageName, {
194
201
  name: packageName,
195
202
  description: currentPackage?.description,
196
203
  scope,
197
204
  }),
205
+ ),
198
206
  onSuccess() {
199
207
  setNotificationMessage("Scope updated");
200
208
  queryClient.invalidateQueries({
@@ -215,99 +223,88 @@ export default function Materializations({
215
223
  stopMaterialization.isPending ||
216
224
  deleteMaterialization.isPending;
217
225
 
218
- return (
219
- <Container
220
- maxWidth={false}
221
- sx={{ maxWidth: 1024, mx: "auto", px: 3, py: 6 }}
222
- >
223
- <Box sx={{ mb: 4 }}>
224
- <Link
225
- onClick={(event: React.MouseEvent) =>
226
- onClick(`/${environmentName}/${packageName}`, event)
227
- }
228
- underline="none"
229
- sx={{
230
- display: "inline-flex",
231
- alignItems: "center",
232
- gap: 0.5,
233
- cursor: "pointer",
234
- color: "text.secondary",
235
- fontSize: "0.875rem",
236
- mb: 2,
237
- "&:hover": { color: "primary.main" },
238
- }}
239
- >
240
- <ArrowBackIcon sx={{ fontSize: 18 }} />
241
- Back to {packageName}
242
- </Link>
243
- <Stack
244
- direction="row"
245
- alignItems="flex-start"
246
- justifyContent="space-between"
247
- >
248
- <Box>
249
- <Typography
250
- variant="h4"
251
- component="h1"
252
- sx={{
253
- fontWeight: 600,
254
- letterSpacing: "-0.025em",
255
- mb: 0.5,
256
- }}
257
- >
258
- Materializations
259
- </Typography>
260
- <Typography variant="body2" color="text.secondary">
261
- Materialize the persist sources in {packageName} into
262
- tables and serve queries from them
263
- </Typography>
264
- </Box>
265
- {mutable && (
266
- <CreateMaterializationDialog
267
- onSubmit={(opts) =>
268
- createMaterialization.mutateAsync(opts)
269
- }
270
- isSubmitting={createMaterialization.isPending}
271
- disabled={hasActive}
272
- disabledReason="A materialization is already pending or running for this package."
273
- />
274
- )}
275
- </Stack>
276
- </Box>
226
+ const schedule = currentPackage?.materialization?.schedule ?? null;
227
+ const scope =
228
+ currentPackage?.scope === PackageScopeEnum.Version
229
+ ? "version"
230
+ : "package";
231
+ const orchestrated = Boolean(currentPackage?.manifestLocation);
232
+ const hasFreshness = Boolean(currentPackage?.materialization?.freshness);
233
+ const cron = schedule ? describeCron(schedule) : null;
277
234
 
278
- {packageQuery.isSuccess && (
279
- <ScheduleCard
280
- schedule={currentPackage?.materialization?.schedule ?? null}
281
- scope={
282
- currentPackage?.scope === PackageScopeEnum.Version
283
- ? "version"
284
- : "package"
285
- }
286
- manifestLocation={currentPackage?.manifestLocation ?? null}
287
- hasFreshness={Boolean(
288
- currentPackage?.materialization?.freshness,
289
- )}
290
- mutable={mutable}
291
- isSubmitting={updateSchedule.isPending}
292
- isScopeMutating={updateScope.isPending}
293
- onSubmit={(schedule) => updateSchedule.mutateAsync(schedule)}
294
- onScopeChange={(scope) =>
295
- updateScope.mutateAsync(
296
- scope === "version"
297
- ? PackageScopeEnum.Version
298
- : PackageScopeEnum.Package,
299
- )
300
- }
301
- />
302
- )}
235
+ // What the settings currently say, in one line. The controls that change
236
+ // them are buttons on the heading row, so the page no longer needs a card to
237
+ // hold them — but a reader still has to see what is in force without opening
238
+ // anything.
239
+ const summary = orchestrated
240
+ ? "Control-plane managed: refresh is driven by the control plane, not the built-in scheduler."
241
+ : [
242
+ cron
243
+ ? cron.valid
244
+ ? `${cron.description} (${schedule}), next run ${formatNextRun(cron.nextRun)}`
245
+ : `Unrecognized cron expression (${schedule})`
246
+ : hasFreshness
247
+ ? "Refreshed by a freshness policy; a cron schedule does not apply"
248
+ : "On demand only, no schedule set",
249
+ `scope: ${scope}`,
250
+ ].join(" · ");
303
251
 
304
- <Box sx={{ mb: 6 }}>
305
- <Typography
306
- variant="h6"
307
- sx={{ fontWeight: 600, letterSpacing: "-0.025em", mb: 1 }}
308
- >
309
- Runs
310
- </Typography>
252
+ return (
253
+ <>
254
+ <PackageSection
255
+ title="Materializations"
256
+ count={listQuery.isSuccess ? materializations.length : undefined}
257
+ action={
258
+ mutable && (
259
+ <Stack direction="row" spacing={1} alignItems="center">
260
+ {!orchestrated && (
261
+ <ScopeButton
262
+ scope={scope}
263
+ // A schedule requires version scope, so the server
264
+ // refuses `package` while one is set; clearing the
265
+ // schedule is the way back.
266
+ disabled={Boolean(schedule)}
267
+ disabledReason="A schedule requires version scope. Clear the schedule to change it."
268
+ isSubmitting={updateScope.isPending}
269
+ onChange={(next) =>
270
+ updateScope.mutateAsync(
271
+ next === "version"
272
+ ? PackageScopeEnum.Version
273
+ : PackageScopeEnum.Package,
274
+ )
275
+ }
276
+ />
277
+ )}
278
+ {!orchestrated && (
279
+ <SetScheduleDialog
280
+ currentSchedule={schedule}
281
+ isSubmitting={updateSchedule.isPending}
282
+ disabled={hasFreshness}
283
+ disabledReason="This package declares a freshness policy; a schedule and freshness are mutually exclusive."
284
+ onSubmit={(next) => updateSchedule.mutateAsync(next)}
285
+ />
286
+ )}
287
+ <CreateMaterializationDialog
288
+ onSubmit={(opts) =>
289
+ createMaterialization.mutateAsync(opts)
290
+ }
291
+ isSubmitting={createMaterialization.isPending}
292
+ disabled={hasActive}
293
+ disabledReason="A materialization is already pending or running for this package."
294
+ />
295
+ </Stack>
296
+ )
297
+ }
298
+ >
299
+ {packageQuery.isSuccess && (
300
+ <Typography
301
+ variant="body2"
302
+ color="text.secondary"
303
+ sx={{ mb: 1.5 }}
304
+ >
305
+ {summary}
306
+ </Typography>
307
+ )}
311
308
  {listQuery.isError && (
312
309
  <ApiErrorDisplay
313
310
  error={listQuery.error}
@@ -336,7 +333,7 @@ export default function Materializations({
336
333
  }
337
334
  />
338
335
  )}
339
- </Box>
336
+ </PackageSection>
340
337
 
341
338
  <MaterializationDetailDialog
342
339
  materialization={selected}
@@ -350,6 +347,6 @@ export default function Materializations({
350
347
  onClose={() => setNotificationMessage("")}
351
348
  message={notificationMessage}
352
349
  />
353
- </Container>
350
+ </>
354
351
  );
355
352
  }
@@ -0,0 +1,85 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import CheckIcon from "@mui/icons-material/Check";
5
+ import LayersOutlinedIcon from "@mui/icons-material/LayersOutlined";
6
+ import { ListItemIcon, ListItemText, Menu, MenuItem } from "@mui/material";
7
+ import { useState } from "react";
8
+ import { SecondaryButton } from "../buttons";
9
+
10
+ export type Scope = "package" | "version";
11
+
12
+ const WHAT_IT_MEANS: Record<Scope, string> = {
13
+ package: "Materialized artifacts are shared across versions",
14
+ version: "Materialized artifacts are per published version",
15
+ };
16
+
17
+ /**
18
+ * The package's persist scope, as one button.
19
+ *
20
+ * It is a menu rather than a pair of toggles because the two values are a
21
+ * choice, not a filter, and because the choice is usually made once and then
22
+ * left alone — the section's heading row is not the place for a permanent
23
+ * two-button control. What each value means is in the menu, where it is read at
24
+ * the moment of choosing rather than sitting on the page forever.
25
+ */
26
+ export default function ScopeButton({
27
+ scope,
28
+ disabled,
29
+ disabledReason,
30
+ isSubmitting,
31
+ onChange,
32
+ }: {
33
+ scope: Scope;
34
+ disabled?: boolean;
35
+ /** Why the control is disabled, shown on hover. */
36
+ disabledReason?: string;
37
+ isSubmitting?: boolean;
38
+ onChange: (scope: Scope) => Promise<unknown>;
39
+ }) {
40
+ const [anchor, setAnchor] = useState<HTMLElement | null>(null);
41
+
42
+ const choose = async (next: Scope) => {
43
+ setAnchor(null);
44
+ if (next !== scope) await onChange(next).catch(() => undefined);
45
+ };
46
+
47
+ return (
48
+ <>
49
+ <SecondaryButton
50
+ label="Scope"
51
+ icon={<LayersOutlinedIcon />}
52
+ onClick={(event) => setAnchor(event.currentTarget)}
53
+ disabled={disabled || isSubmitting}
54
+ {...(disabledReason ? { disabledReason } : {})}
55
+ ariaHasPopup="menu"
56
+ // The value is in the name, so the current scope is legible without
57
+ // opening the menu and a test can assert it.
58
+ ariaLabel={`Scope: ${scope}`}
59
+ />
60
+ <Menu
61
+ anchorEl={anchor}
62
+ open={Boolean(anchor)}
63
+ onClose={() => setAnchor(null)}
64
+ anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
65
+ transformOrigin={{ vertical: "top", horizontal: "right" }}
66
+ >
67
+ {(["package", "version"] as const).map((value) => (
68
+ <MenuItem
69
+ key={value}
70
+ selected={value === scope}
71
+ onClick={() => void choose(value)}
72
+ >
73
+ <ListItemIcon sx={{ minWidth: 32 }}>
74
+ {value === scope && <CheckIcon fontSize="small" />}
75
+ </ListItemIcon>
76
+ <ListItemText
77
+ primary={value}
78
+ secondary={WHAT_IT_MEANS[value]}
79
+ />
80
+ </MenuItem>
81
+ ))}
82
+ </Menu>
83
+ </>
84
+ );
85
+ }
@@ -5,10 +5,13 @@ import { Typography } from "@mui/material";
5
5
  import { ReactNode } from "react";
6
6
 
7
7
  /**
8
- * Small uppercase section heading for consistent hierarchy across the
9
- * materialization views (detail dialog, manifest view). One source of truth for
10
- * the style so the headings can't drift. Renders as an <h6> so it is a real
11
- * heading (role="heading") — the caption styling is purely visual.
8
+ * A sub-heading INSIDE a materialization view — the detail dialog and the
9
+ * manifest view — where `PackageSection` does not apply: those are sections of
10
+ * a dialog, not of a page. Small and uppercase to sit a level under the
11
+ * dialog's own title.
12
+ *
13
+ * Renders as an `<h6>`, so it is a real heading to anything navigating by
14
+ * them; the caption styling is purely visual.
12
15
  */
13
16
  export default function SectionLabel({ children }: { children: ReactNode }) {
14
17
  return (
@@ -2,21 +2,11 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import ScheduleIcon from "@mui/icons-material/Schedule";
5
- import {
6
- Alert,
7
- Box,
8
- Button,
9
- Dialog,
10
- DialogActions,
11
- DialogContent,
12
- DialogContentText,
13
- DialogTitle,
14
- TextField,
15
- Tooltip,
16
- Typography,
17
- } from "@mui/material";
5
+ import { Alert, Button, TextField } from "@mui/material";
18
6
  import { useState } from "react";
19
7
  import { MONO_FONT_FAMILY } from "../styles";
8
+ import { AppDialog } from "../AppDialog";
9
+ import { SecondaryButton } from "../buttons";
20
10
  import { describeCron, formatNextRun } from "./cron";
21
11
 
22
12
  type SetScheduleDialogProps = {
@@ -59,104 +49,73 @@ export default function SetScheduleDialog({
59
49
  }
60
50
  };
61
51
 
62
- const button = (
63
- <span>
64
- <Button
65
- variant="outlined"
66
- size="small"
67
- startIcon={<ScheduleIcon />}
68
- onClick={handleOpen}
69
- disabled={disabled}
70
- aria-label={currentSchedule ? "Edit schedule" : "Set schedule"}
71
- >
72
- {currentSchedule ? "Edit schedule" : "Set schedule"}
73
- </Button>
74
- </span>
75
- );
76
-
77
52
  return (
78
53
  <>
79
- {disabled && disabledReason ? (
80
- <Tooltip title={disabledReason}>{button}</Tooltip>
81
- ) : (
82
- button
83
- )}
54
+ <SecondaryButton
55
+ label="Schedule"
56
+ icon={<ScheduleIcon />}
57
+ onClick={handleOpen}
58
+ disabled={disabled}
59
+ {...(disabledReason ? { disabledReason } : {})}
60
+ ariaHasPopup="dialog"
61
+ // The label is the noun, like every other control on this row; the
62
+ // accessible name keeps the verb, and says which verb it is.
63
+ ariaLabel={currentSchedule ? "Edit schedule" : "Set schedule"}
64
+ />
84
65
 
85
- <Dialog
66
+ <AppDialog
86
67
  open={open}
87
68
  onClose={handleClose}
88
- maxWidth="xs"
89
- fullWidth
90
- aria-labelledby="set-schedule-title"
91
- >
92
- <DialogTitle id="set-schedule-title">
93
- {currentSchedule ? "Edit schedule" : "Set schedule"}
94
- </DialogTitle>
95
- <DialogContent>
96
- <DialogContentText sx={{ mb: 2 }}>
97
- The publisher rebuilds the materializations in this package on
98
- this cadence. Enter a 5-field UNIX cron, evaluated in UTC. In
99
- a hosted deployment, the change takes effect on your next
100
- publish.
101
- </DialogContentText>
102
- <TextField
103
- autoFocus
104
- fullWidth
105
- label="Cron expression"
106
- value={expr}
107
- onChange={(event) => setExpr(event.target.value)}
108
- error={expr.trim() !== "" && !info.valid}
109
- slotProps={{
110
- htmlInput: { style: { fontFamily: MONO_FONT_FAMILY } },
111
- }}
112
- />
113
- <Box sx={{ mt: 1.5, minHeight: 48 }}>
114
- {info.valid ? (
115
- <>
116
- <Typography variant="body2">
117
- {info.description}
118
- </Typography>
119
- <Typography variant="body2" color="text.secondary">
120
- Next run: {formatNextRun(info.nextRun)}
121
- </Typography>
122
- </>
123
- ) : (
124
- <Typography variant="body2" color="error">
125
- {info.error}
126
- </Typography>
127
- )}
128
- </Box>
129
- <Alert severity="info" sx={{ mt: 2 }}>
130
- A schedule runs only on version-scoped packages, so saving one
131
- sets <code>scope: version</code> for this package.
132
- </Alert>
133
- </DialogContent>
134
- <DialogActions sx={{ justifyContent: "space-between", px: 3 }}>
135
- <Box>
69
+ title={currentSchedule ? "Edit schedule" : "Set schedule"}
70
+ description="The publisher rebuilds this package's materializations on this cadence: a 5-field UNIX cron, in UTC. In a hosted deployment the change takes effect on your next publish."
71
+ actions={
72
+ <>
136
73
  {currentSchedule && (
137
74
  <Button
138
75
  color="error"
139
76
  loading={isSubmitting}
140
77
  onClick={() => submit(null)}
78
+ // The destructive option sits away from the pair that
79
+ // confirms and cancels.
80
+ sx={{ mr: "auto" }}
141
81
  >
142
82
  Clear schedule
143
83
  </Button>
144
84
  )}
145
- </Box>
146
- <Box>
147
85
  <Button onClick={handleClose}>Cancel</Button>
148
86
  <Button
149
87
  variant="contained"
150
88
  loading={isSubmitting}
151
89
  disabled={!info.valid}
152
90
  onClick={() => submit(expr.trim())}
153
- sx={{ ml: 1 }}
154
91
  >
155
- Save
92
+ Save schedule
156
93
  </Button>
157
- </Box>
158
- </DialogActions>
159
- </Dialog>
94
+ </>
95
+ }
96
+ >
97
+ <TextField
98
+ autoFocus
99
+ fullWidth
100
+ size="small"
101
+ label="Cron expression"
102
+ value={expr}
103
+ onChange={(event) => setExpr(event.target.value)}
104
+ error={expr.trim() !== "" && !info.valid}
105
+ helperText={
106
+ info.valid
107
+ ? `${info.description} · next run ${formatNextRun(info.nextRun)}`
108
+ : info.error
109
+ }
110
+ slotProps={{
111
+ htmlInput: { style: { fontFamily: MONO_FONT_FAMILY } },
112
+ }}
113
+ />
114
+ <Alert severity="info">
115
+ A schedule runs only on version-scoped packages, so saving one
116
+ sets <code>scope: version</code> for this package.
117
+ </Alert>
118
+ </AppDialog>
160
119
  </>
161
120
  );
162
121
  }