@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
@@ -3,19 +3,7 @@
3
3
 
4
4
  import { MoreVert } from "@mui/icons-material";
5
5
  import StorageOutlinedIcon from "@mui/icons-material/StorageOutlined";
6
- import {
7
- Box,
8
- Card,
9
- CardContent,
10
- Dialog,
11
- DialogContent,
12
- DialogTitle,
13
- Grid,
14
- IconButton,
15
- Menu,
16
- Snackbar,
17
- Typography,
18
- } from "@mui/material";
6
+ import { IconButton, Menu, Snackbar, Stack, Typography } from "@mui/material";
19
7
  import { useQueryClient } from "@tanstack/react-query";
20
8
  import { useState } from "react";
21
9
  import { Connection as ApiConnection } from "../../client/api";
@@ -25,6 +13,11 @@ import {
25
13
  } from "../../hooks/useQueryWithApiError";
26
14
  import { encodeResourceUri, parseResourceUri } from "../../utils/formatting";
27
15
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
16
+ import { AppDialog } from "../AppDialog";
17
+ import { ItemRow } from "../ItemRow";
18
+ import { PackageSection } from "../PackageSection";
19
+ import { reporting } from "../../telemetry/consoleEvents";
20
+ import { SURFACE_TINT } from "../styles";
28
21
  import AddConnectionDialog from "../Connections/AddConnectionDialog";
29
22
  import DeleteConnectionDialog from "../Connections/DeleteConnectionDialog";
30
23
  import EditConnectionDialog from "../Connections/EditConnectionDialog";
@@ -72,17 +65,13 @@ export default function Connections({ resourceUri }: ConnectionsProps) {
72
65
  queryFn: () => apiClients.connections.listConnections(environmentName),
73
66
  });
74
67
 
75
- const handleCloseDialog = () => {
76
- setSelectedConnection(null);
77
- };
78
-
79
68
  const addConnection = useMutationWithApiError({
80
- mutationFn: (payload: ApiConnection) => {
81
- return apiClients.environments.updateEnvironment(environmentName, {
69
+ mutationFn: reporting("connection", "create", (payload: ApiConnection) =>
70
+ apiClients.environments.updateEnvironment(environmentName, {
82
71
  name: environmentName,
83
72
  connections: [...data!.data, payload],
84
- });
85
- },
73
+ }),
74
+ ),
86
75
  onSuccess() {
87
76
  setNotificationMessage("Connection added successfully");
88
77
  queryClient.invalidateQueries({
@@ -95,14 +84,14 @@ export default function Connections({ resourceUri }: ConnectionsProps) {
95
84
  });
96
85
 
97
86
  const updateConnection = useMutationWithApiError({
98
- mutationFn: (payload: ApiConnection) => {
99
- return apiClients.environments.updateEnvironment(environmentName, {
87
+ mutationFn: reporting("connection", "update", (payload: ApiConnection) =>
88
+ apiClients.environments.updateEnvironment(environmentName, {
100
89
  name: environmentName,
101
90
  connections: data!.data.map((conn) =>
102
91
  conn.name === payload.name ? payload : conn,
103
92
  ),
104
- });
105
- },
93
+ }),
94
+ ),
106
95
  onSuccess(_data, variables) {
107
96
  setNotificationMessage(
108
97
  `Connection ${variables.name} updated successfully`,
@@ -122,15 +111,19 @@ export default function Connections({ resourceUri }: ConnectionsProps) {
122
111
  // row for one that went away, so a deleted connection came back on the
123
112
  // next boot. This path removes the row and cleans up a duckdb/ducklake
124
113
  // connection's database file.
125
- mutationFn: (payload: ApiConnection) => {
126
- if (!payload.name) {
127
- throw new Error("Cannot delete a connection with no name");
128
- }
129
- return apiClients.connections.deleteConnection(
130
- environmentName,
131
- payload.name,
132
- );
133
- },
114
+ mutationFn: reporting(
115
+ "connection",
116
+ "delete",
117
+ (payload: ApiConnection) => {
118
+ if (!payload.name) {
119
+ throw new Error("Cannot delete a connection with no name");
120
+ }
121
+ return apiClients.connections.deleteConnection(
122
+ environmentName,
123
+ payload.name,
124
+ );
125
+ },
126
+ ),
134
127
  onSuccess(_data, variables) {
135
128
  setNotificationMessage(
136
129
  `Connection ${variables.name} deleted successfully`,
@@ -156,34 +149,23 @@ export default function Connections({ resourceUri }: ConnectionsProps) {
156
149
  deleteConnection.isPending;
157
150
 
158
151
  return (
159
- <Box>
160
- <Box
161
- sx={{
162
- display: "flex",
163
- alignItems: "flex-start",
164
- justifyContent: "space-between",
165
- mb: 3,
166
- }}
167
- >
168
- <Box>
169
- <Typography
170
- variant="h6"
171
- sx={{ fontWeight: 600, letterSpacing: "-0.025em" }}
172
- >
173
- Connections
174
- </Typography>
175
- <Typography variant="body2" color="text.secondary">
176
- Database connections available to packages in this environment
177
- </Typography>
178
- </Box>
179
- {mutable && isSuccess && (
180
- <AddConnectionDialog
181
- onSubmit={(payload) => addConnection.mutateAsync(payload)}
182
- isSubmitting={addConnection.isPending}
183
- />
184
- )}
185
- </Box>
186
-
152
+ <PackageSection
153
+ title="Connections"
154
+ {...(isSuccess ? { count: connections.length } : {})}
155
+ description="Database connections available to packages in this environment"
156
+ {...(mutable && isSuccess
157
+ ? {
158
+ action: (
159
+ <AddConnectionDialog
160
+ onSubmit={(payload) =>
161
+ addConnection.mutateAsync(payload)
162
+ }
163
+ isSubmitting={addConnection.isPending}
164
+ />
165
+ ),
166
+ }
167
+ : {})}
168
+ >
187
169
  {!isSuccess && !isError && (
188
170
  <Typography variant="body2" color="text.secondary">
189
171
  Fetching Connections...
@@ -201,26 +183,23 @@ export default function Connections({ resourceUri }: ConnectionsProps) {
201
183
  </Typography>
202
184
  )}
203
185
  {isSuccess && connections.length > 0 && (
204
- <Grid container spacing={2}>
186
+ <Stack>
205
187
  {connections.map((conn) => (
206
- <Grid size={{ xs: 12, sm: 6, md: 4 }} key={conn.name}>
207
- <ConnectionCard
208
- connection={conn}
209
- mutable={mutable}
210
- isMutating={isMutating}
211
- onOpenExplorer={() =>
212
- setSelectedConnection(conn.name ?? null)
213
- }
214
- onEdit={(payload) =>
215
- updateConnection.mutateAsync(payload)
216
- }
217
- onDelete={(payload) =>
218
- deleteConnection.mutateAsync(payload)
219
- }
220
- />
221
- </Grid>
188
+ <ConnectionRow
189
+ key={conn.name}
190
+ connection={conn}
191
+ mutable={mutable}
192
+ isMutating={isMutating}
193
+ onOpenExplorer={() =>
194
+ setSelectedConnection(conn.name ?? null)
195
+ }
196
+ onEdit={(payload) => updateConnection.mutateAsync(payload)}
197
+ onDelete={(payload) =>
198
+ deleteConnection.mutateAsync(payload)
199
+ }
200
+ />
222
201
  ))}
223
- </Grid>
202
+ </Stack>
224
203
  )}
225
204
 
226
205
  <Snackbar
@@ -230,45 +209,24 @@ export default function Connections({ resourceUri }: ConnectionsProps) {
230
209
  message={notificationMessage}
231
210
  />
232
211
 
233
- <Dialog
212
+ <AppDialog
234
213
  open={selectedConnection !== null}
235
- onClose={handleCloseDialog}
214
+ onClose={() => setSelectedConnection(null)}
236
215
  maxWidth="lg"
237
- fullWidth
216
+ title={`Connection explorer: ${selectedConnection ?? ""}`}
217
+ showClose
238
218
  >
239
- <DialogTitle>
240
- Connection Explorer: {selectedConnection}
241
- <IconButton
242
- aria-label="close"
243
- onClick={handleCloseDialog}
244
- sx={{ position: "absolute", right: 8, top: 8 }}
245
- >
246
- <Box
247
- sx={{
248
- width: 24,
249
- height: 24,
250
- display: "flex",
251
- alignItems: "center",
252
- justifyContent: "center",
253
- }}
254
- >
255
- X
256
- </Box>
257
- </IconButton>
258
- </DialogTitle>
259
- <DialogContent>
260
- {selectedConnection && (
261
- <ConnectionExplorer
262
- resourceUri={selectedConnectionResourceUri}
263
- connectionName={selectedConnection}
264
- connection={data?.data?.find(
265
- (c) => c.name === selectedConnection,
266
- )}
267
- />
268
- )}
269
- </DialogContent>
270
- </Dialog>
271
- </Box>
219
+ {selectedConnection && (
220
+ <ConnectionExplorer
221
+ resourceUri={selectedConnectionResourceUri}
222
+ connectionName={selectedConnection}
223
+ connection={data?.data?.find(
224
+ (c) => c.name === selectedConnection,
225
+ )}
226
+ />
227
+ )}
228
+ </AppDialog>
229
+ </PackageSection>
272
230
  );
273
231
  }
274
232
 
@@ -281,7 +239,7 @@ type ConnectionCardProps = {
281
239
  onDelete: (connection: ApiConnection) => Promise<unknown> | void;
282
240
  };
283
241
 
284
- function ConnectionCard({
242
+ function ConnectionRow({
285
243
  connection,
286
244
  mutable,
287
245
  isMutating,
@@ -296,96 +254,58 @@ function ConnectionCard({
296
254
  event.stopPropagation();
297
255
  setMenuAnchorEl(event.currentTarget);
298
256
  };
299
-
300
- const handleMenuClose = () => {
301
- setMenuAnchorEl(null);
302
- };
257
+ const handleMenuClose = () => setMenuAnchorEl(null);
303
258
 
304
259
  return (
305
- <Card
306
- variant="outlined"
260
+ <ItemRow
261
+ icon={<StorageOutlinedIcon sx={{ fontSize: 18 }} />}
262
+ tint={SURFACE_TINT.connection}
263
+ label={connection.name ?? ""}
264
+ ariaLabel={connection.name ?? ""}
265
+ description={typeLabel(connection.type)}
307
266
  onClick={onOpenExplorer}
308
- sx={{
309
- height: "100%",
310
- cursor: "pointer",
311
- borderRadius: 3,
312
- borderColor: "divider",
313
- boxShadow: "none",
314
- transition: "all 0.2s ease-in-out",
315
- "&:hover": { boxShadow: 2, borderColor: "primary.main" },
316
- }}
317
- >
318
- <CardContent sx={{ p: 2.5, "&:last-child": { pb: 2.5 } }}>
319
- <Box sx={{ display: "flex", alignItems: "flex-start", gap: 1.5 }}>
320
- <Box
321
- sx={{
322
- width: 36,
323
- height: 36,
324
- borderRadius: 1.5,
325
- bgcolor: "warning.light",
326
- display: "flex",
327
- alignItems: "center",
328
- justifyContent: "center",
329
- flexShrink: 0,
330
- color: "warning.main",
331
- }}
332
- >
333
- <StorageOutlinedIcon sx={{ fontSize: 20 }} />
334
- </Box>
335
- <Box sx={{ flex: 1, minWidth: 0 }}>
336
- <Typography
337
- variant="subtitle1"
338
- component="h6"
339
- noWrap
340
- sx={{ fontWeight: 600, mb: 0.5 }}
341
- >
342
- {connection.name}
343
- </Typography>
344
- <Typography variant="body2" color="text.secondary" noWrap>
345
- {typeLabel(connection.type)}
346
- </Typography>
347
- </Box>
348
- {mutable && (
349
- <>
350
- <IconButton
351
- size="small"
352
- onClick={handleMenuClick}
353
- aria-label={`Connection actions for ${connection.name ?? ""}`.trim()}
354
- sx={{ flexShrink: 0, mt: -0.5, mr: -0.5 }}
355
- >
356
- <MoreVert fontSize="small" />
357
- </IconButton>
358
- <Menu
359
- anchorEl={menuAnchorEl}
360
- open={menuOpen}
361
- onClose={handleMenuClose}
362
- onClick={(e) => e.stopPropagation()}
363
- anchorOrigin={{
364
- vertical: "bottom",
365
- horizontal: "right",
366
- }}
367
- transformOrigin={{
368
- vertical: "top",
369
- horizontal: "right",
370
- }}
371
- >
372
- <EditConnectionDialog
373
- connection={connection}
374
- onSubmit={onEdit}
375
- isSubmitting={isMutating}
376
- onCloseDialog={handleMenuClose}
377
- />
378
- <DeleteConnectionDialog
379
- connection={connection}
380
- onCloseDialog={handleMenuClose}
381
- isMutating={isMutating}
382
- onDelete={() => onDelete(connection)}
383
- />
384
- </Menu>
385
- </>
386
- )}
387
- </Box>
388
- </CardContent>
389
- </Card>
267
+ {...(mutable
268
+ ? {
269
+ trailingAction: (
270
+ <>
271
+ <IconButton
272
+ size="small"
273
+ onClick={handleMenuClick}
274
+ aria-label={`Connection actions for ${connection.name ?? ""}`.trim()}
275
+ >
276
+ <MoreVert fontSize="small" />
277
+ </IconButton>
278
+ <Menu
279
+ anchorEl={menuAnchorEl}
280
+ open={menuOpen}
281
+ onClose={handleMenuClose}
282
+ onClick={(event) => event.stopPropagation()}
283
+ anchorOrigin={{
284
+ vertical: "bottom",
285
+ horizontal: "right",
286
+ }}
287
+ transformOrigin={{
288
+ vertical: "top",
289
+ horizontal: "right",
290
+ }}
291
+ >
292
+ <EditConnectionDialog
293
+ connection={connection}
294
+ onSubmit={onEdit}
295
+ isSubmitting={isMutating}
296
+ onCloseDialog={handleMenuClose}
297
+ />
298
+ <DeleteConnectionDialog
299
+ connection={connection}
300
+ onCloseDialog={handleMenuClose}
301
+ isMutating={isMutating}
302
+ onDelete={() => onDelete(connection)}
303
+ />
304
+ </Menu>
305
+ </>
306
+ ),
307
+ }
308
+ : {})}
309
+ />
390
310
  );
391
311
  }
@@ -3,20 +3,13 @@
3
3
 
4
4
  import React, { useState } from "react";
5
5
  import Button from "@mui/material/Button";
6
- import Dialog from "@mui/material/Dialog";
7
- import DialogTitle from "@mui/material/DialogTitle";
8
- import DialogContent from "@mui/material/DialogContent";
9
- import DialogActions from "@mui/material/DialogActions";
10
- import IconButton from "@mui/material/IconButton";
11
- import CloseIcon from "@mui/icons-material/Close";
12
6
  import Typography from "@mui/material/Typography";
13
- import { ListItemIcon, ListItemText, MenuItem, Snackbar } from "@mui/material";
7
+ import { ListItemIcon, ListItemText, MenuItem } from "@mui/material";
14
8
  import { Delete } from "@mui/icons-material";
15
- import { useMutationWithApiError } from "../../hooks/useQueryWithApiError";
9
+ import { useCrudMutation } from "../../hooks/useCrudMutation";
16
10
  import { useServer } from "../ServerProvider";
17
- import { useQueryClient } from "@tanstack/react-query";
18
11
  import { parseResourceUri } from "../../utils/formatting";
19
- import { MALLOY_BRAND } from "../styles";
12
+ import { AppDialog } from "../AppDialog";
20
13
 
21
14
  export default function DeletePackageDialog({
22
15
  resourceUri,
@@ -27,8 +20,6 @@ export default function DeletePackageDialog({
27
20
  }) {
28
21
  const [open, setOpen] = useState(false);
29
22
  const { apiClients } = useServer();
30
- const queryClient = useQueryClient();
31
- const [notificationMessage, setNotificationMessage] = useState("");
32
23
  const handleClickOpen = () => {
33
24
  setOpen(true);
34
25
  };
@@ -38,21 +29,14 @@ export default function DeletePackageDialog({
38
29
  };
39
30
  const { environmentName, packageName } = parseResourceUri(resourceUri);
40
31
 
41
- const deletePackage = useMutationWithApiError({
32
+ const deletePackage = useCrudMutation({
42
33
  mutationFn: () =>
43
34
  apiClients.packages.deletePackage(environmentName, packageName),
44
- onSuccess() {
45
- handleClose();
46
- queryClient.invalidateQueries({ queryKey: ["packages"] });
47
- setNotificationMessage("Package deleted successfully");
48
- },
49
- onError(error) {
50
- setNotificationMessage(
51
- error instanceof Error
52
- ? error.message
53
- : "An unknown error occurred",
54
- );
55
- },
35
+ success: "Package deleted",
36
+ invalidates: [["packages", environmentName]],
37
+ closeDialog: handleClose,
38
+ resource: "package",
39
+ action: "delete",
56
40
  });
57
41
 
58
42
  return (
@@ -63,60 +47,31 @@ export default function DeletePackageDialog({
63
47
  </ListItemIcon>
64
48
  <ListItemText>Delete</ListItemText>
65
49
  </MenuItem>
66
- <Dialog
67
- onClose={handleClose}
68
- aria-labelledby="customized-dialog-title"
50
+ <AppDialog
69
51
  open={open}
52
+ onClose={handleClose}
53
+ title="Delete package"
54
+ actions={
55
+ <>
56
+ <Button onClick={handleClose}>Cancel</Button>
57
+ <Button
58
+ variant="contained"
59
+ color="error"
60
+ autoFocus
61
+ onClick={() => deletePackage.mutate()}
62
+ loading={deletePackage.isPending}
63
+ >
64
+ Delete package
65
+ </Button>
66
+ </>
67
+ }
70
68
  >
71
- <DialogTitle sx={{ m: 0, p: 2 }} id="customized-dialog-title">
72
- Delete Package
73
- </DialogTitle>
74
- <IconButton
75
- aria-label="close"
76
- onClick={handleClose}
77
- sx={(theme) => ({
78
- position: "absolute",
79
- right: 8,
80
- top: 8,
81
- color: theme.palette.grey[500],
82
- })}
83
- >
84
- <CloseIcon />
85
- </IconButton>
86
- <DialogContent dividers>
87
- <Typography gutterBottom>
88
- Are you sure you want to delete &quot;{packageName}&quot;?
89
- This action cannot be undone.
90
- </Typography>
91
- </DialogContent>
92
- <DialogActions>
93
- <Button
94
- variant="outlined"
95
- onClick={handleClose}
96
- style={{
97
- borderColor: MALLOY_BRAND.teal,
98
- color: MALLOY_BRAND.teal,
99
- }}
100
- >
101
- Cancel
102
- </Button>
103
- <Button
104
- variant="contained"
105
- autoFocus
106
- onClick={() => deletePackage.mutate()}
107
- color="error"
108
- loading={deletePackage.isPending}
109
- >
110
- Delete
111
- </Button>
112
- </DialogActions>
113
- <Snackbar
114
- open={notificationMessage !== ""}
115
- autoHideDuration={6000}
116
- onClose={() => setNotificationMessage("")}
117
- message={notificationMessage}
118
- />
119
- </Dialog>
69
+ <Typography variant="body2">
70
+ Delete <strong>{packageName}</strong>? The package stops being
71
+ served and this cannot be undone.
72
+ </Typography>
73
+ </AppDialog>
74
+ {deletePackage.notice}
120
75
  </React.Fragment>
121
76
  );
122
77
  }