@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,25 +1,19 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import { AddCircleRounded } from "@mui/icons-material";
5
4
  import Button from "@mui/material/Button";
6
- import Dialog from "@mui/material/Dialog";
7
- import DialogActions from "@mui/material/DialogActions";
8
- import DialogContent from "@mui/material/DialogContent";
9
- import DialogContentText from "@mui/material/DialogContentText";
10
- import DialogTitle from "@mui/material/DialogTitle";
11
- import Snackbar from "@mui/material/Snackbar";
12
5
  import TextField from "@mui/material/TextField";
13
- import { useQueryClient } from "@tanstack/react-query";
14
6
  import React, { useState } from "react";
15
- import { useMutationWithApiError } from "../../hooks/useQueryWithApiError";
7
+ import { useCrudMutation } from "../../hooks/useCrudMutation";
16
8
  import { generateEnvironmentReadme } from "../../utils/parsing";
17
9
  import { useServer } from "../ServerProvider";
10
+ import { AddButton } from "../buttons";
11
+ import Stack from "@mui/material/Stack";
12
+ import { AppDialog } from "../AppDialog";
18
13
 
19
14
  export default function AddEnvironmentDialog() {
20
15
  const [open, setOpen] = useState(false);
21
16
  const { apiClients } = useServer();
22
- const [notificationMessage, setNotificationMessage] = useState("");
23
17
  const handleClickOpen = () => {
24
18
  setOpen(true);
25
19
  };
@@ -27,9 +21,8 @@ export default function AddEnvironmentDialog() {
27
21
  const handleClose = () => {
28
22
  setOpen(false);
29
23
  };
30
- const queryClient = useQueryClient();
31
- const addEnvironment = useMutationWithApiError({
32
- async mutationFn(variables: { name: string; description: string }) {
24
+ const addEnvironment = useCrudMutation({
25
+ mutationFn(variables: { name: string; description: string }) {
33
26
  return apiClients.environments.createEnvironment({
34
27
  name: variables.name,
35
28
  readme: generateEnvironmentReadme(
@@ -41,18 +34,11 @@ export default function AddEnvironmentDialog() {
41
34
  ),
42
35
  });
43
36
  },
44
- onSuccess() {
45
- handleClose();
46
- queryClient.invalidateQueries({ queryKey: ["environments"] });
47
- setNotificationMessage("Environment created successfully");
48
- },
49
- onError(error) {
50
- setNotificationMessage(
51
- error instanceof Error
52
- ? error.message
53
- : "An unknown error occurred",
54
- );
55
- },
37
+ success: "Environment created",
38
+ invalidates: [["environments"]],
39
+ closeDialog: handleClose,
40
+ resource: "environment",
41
+ action: "create",
56
42
  });
57
43
 
58
44
  const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
@@ -69,67 +55,58 @@ export default function AddEnvironmentDialog() {
69
55
 
70
56
  return (
71
57
  <React.Fragment>
72
- <Button
73
- variant="contained"
74
- onClick={handleClickOpen}
75
- startIcon={<AddCircleRounded />}
76
- sx={{ mt: 2 }}
58
+ <AddButton label="Environment" onClick={handleClickOpen} />
59
+ <AppDialog
60
+ open={open}
61
+ onClose={handleClose}
62
+ title="New environment"
63
+ description="An environment holds packages and the connections they query through."
64
+ actions={
65
+ <>
66
+ <Button
67
+ disabled={addEnvironment.isPending}
68
+ onClick={handleClose}
69
+ >
70
+ Cancel
71
+ </Button>
72
+ <Button
73
+ type="submit"
74
+ form="environment-form"
75
+ variant="contained"
76
+ loading={addEnvironment.isPending}
77
+ >
78
+ Create environment
79
+ </Button>
80
+ </>
81
+ }
77
82
  >
78
- Create New Environment
79
- </Button>
80
- <Dialog open={open} onClose={handleClose}>
81
- <DialogTitle>Create New Environment</DialogTitle>
82
- <DialogContent>
83
- <DialogContentText>
84
- Add a new environment to start exploring semantic models and
85
- analyzing data.
86
- </DialogContentText>
87
- <form onSubmit={handleSubmit} id="environment-form">
83
+ <form onSubmit={handleSubmit} id="environment-form">
84
+ <Stack sx={{ gap: 2 }}>
88
85
  <TextField
89
86
  autoFocus
90
87
  required
91
- margin="dense"
92
88
  id="name"
93
89
  name="name"
94
- label="Environment Name"
90
+ label="Name"
95
91
  type="text"
96
92
  fullWidth
97
- variant="standard"
93
+ size="small"
94
+ InputLabelProps={{ shrink: true }}
98
95
  />
99
96
  <TextField
100
- margin="dense"
101
97
  id="description"
102
98
  name="description"
103
- label="Environment Description"
99
+ label="Description"
104
100
  placeholder="Explore semantic models, run queries, and build dashboards"
105
101
  type="text"
106
102
  fullWidth
107
- variant="standard"
103
+ size="small"
104
+ InputLabelProps={{ shrink: true }}
108
105
  />
109
- </form>
110
- </DialogContent>
111
- <DialogActions>
112
- <Button
113
- disabled={addEnvironment.isPending}
114
- onClick={handleClose}
115
- >
116
- Cancel
117
- </Button>
118
- <Button
119
- type="submit"
120
- form="environment-form"
121
- loading={addEnvironment.isPending}
122
- >
123
- Create Environment
124
- </Button>
125
- </DialogActions>
126
- </Dialog>
127
- <Snackbar
128
- open={notificationMessage !== ""}
129
- autoHideDuration={6000}
130
- onClose={() => setNotificationMessage("")}
131
- message={notificationMessage}
132
- />
106
+ </Stack>
107
+ </form>
108
+ </AppDialog>
109
+ {addEnvironment.notice}
133
110
  </React.Fragment>
134
111
  );
135
112
  }
@@ -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
9
  import { Environment } from "../../client";
16
- import { useMutationWithApiError } from "../../hooks/useQueryWithApiError";
10
+ import { useCrudMutation } from "../../hooks/useCrudMutation";
17
11
  import { useServer } from "../ServerProvider";
18
- import { useQueryClient } from "@tanstack/react-query";
19
- import { MALLOY_BRAND } from "../styles";
12
+ import { AppDialog } from "../AppDialog";
20
13
 
21
14
  export default function DeleteEnvironmentDialog({
22
15
  environment,
@@ -27,8 +20,6 @@ export default function DeleteEnvironmentDialog({
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
  };
@@ -37,21 +28,14 @@ export default function DeleteEnvironmentDialog({
37
28
  onCloseDialog();
38
29
  };
39
30
 
40
- const deleteEnvironment = useMutationWithApiError({
31
+ const deleteEnvironment = useCrudMutation({
41
32
  mutationFn: () =>
42
33
  apiClients.environments.deleteEnvironment(environment.name),
43
- onSuccess() {
44
- handleClose();
45
- queryClient.invalidateQueries({ queryKey: ["environments"] });
46
- setNotificationMessage("Environment deleted successfully");
47
- },
48
- onError(error) {
49
- setNotificationMessage(
50
- error instanceof Error
51
- ? error.message
52
- : "An unknown error occurred",
53
- );
54
- },
34
+ success: "Environment deleted",
35
+ invalidates: [["environments"]],
36
+ closeDialog: handleClose,
37
+ resource: "environment",
38
+ action: "delete",
55
39
  });
56
40
 
57
41
  return (
@@ -62,60 +46,31 @@ export default function DeleteEnvironmentDialog({
62
46
  </ListItemIcon>
63
47
  <ListItemText>Delete</ListItemText>
64
48
  </MenuItem>
65
- <Dialog
66
- onClose={handleClose}
67
- aria-labelledby="customized-dialog-title"
49
+ <AppDialog
68
50
  open={open}
51
+ onClose={handleClose}
52
+ title="Delete environment"
53
+ actions={
54
+ <>
55
+ <Button onClick={handleClose}>Cancel</Button>
56
+ <Button
57
+ variant="contained"
58
+ color="error"
59
+ autoFocus
60
+ onClick={() => deleteEnvironment.mutate()}
61
+ loading={deleteEnvironment.isPending}
62
+ >
63
+ Delete environment
64
+ </Button>
65
+ </>
66
+ }
69
67
  >
70
- <DialogTitle sx={{ m: 0, p: 2 }} id="customized-dialog-title">
71
- Delete Environment
72
- </DialogTitle>
73
- <IconButton
74
- aria-label="close"
75
- onClick={handleClose}
76
- sx={(theme) => ({
77
- position: "absolute",
78
- right: 8,
79
- top: 8,
80
- color: theme.palette.grey[500],
81
- })}
82
- >
83
- <CloseIcon />
84
- </IconButton>
85
- <DialogContent dividers>
86
- <Typography gutterBottom>
87
- Are you sure you want to delete &quot;{environment.name}
88
- &quot;? This action cannot be undone.
89
- </Typography>
90
- </DialogContent>
91
- <DialogActions>
92
- <Button
93
- variant="outlined"
94
- onClick={handleClose}
95
- style={{
96
- borderColor: MALLOY_BRAND.teal,
97
- color: MALLOY_BRAND.teal,
98
- }}
99
- >
100
- Cancel
101
- </Button>
102
- <Button
103
- loading={deleteEnvironment.isPending}
104
- variant="contained"
105
- autoFocus
106
- onClick={() => deleteEnvironment.mutate()}
107
- color="error"
108
- >
109
- Delete
110
- </Button>
111
- </DialogActions>
112
- <Snackbar
113
- open={notificationMessage !== ""}
114
- autoHideDuration={6000}
115
- onClose={() => setNotificationMessage("")}
116
- message={notificationMessage}
117
- />
118
- </Dialog>
68
+ <Typography variant="body2">
69
+ Delete <strong>{environment.name}</strong>? Its packages stop
70
+ being served and this cannot be undone.
71
+ </Typography>
72
+ </AppDialog>
73
+ {deleteEnvironment.notice}
119
74
  </React.Fragment>
120
75
  );
121
76
  }
@@ -4,22 +4,18 @@
4
4
  import React from "react";
5
5
  import Button from "@mui/material/Button";
6
6
  import TextField from "@mui/material/TextField";
7
- import Dialog from "@mui/material/Dialog";
8
- import DialogActions from "@mui/material/DialogActions";
9
- import DialogContent from "@mui/material/DialogContent";
10
- import DialogContentText from "@mui/material/DialogContentText";
11
- import DialogTitle from "@mui/material/DialogTitle";
12
7
  import { useState } from "react";
13
8
  import { Edit } from "@mui/icons-material";
14
- import { MenuItem, ListItemIcon, ListItemText, Snackbar } from "@mui/material";
9
+ import { MenuItem, ListItemIcon, ListItemText } from "@mui/material";
15
10
  import { Environment } from "../../client";
16
11
  import {
17
12
  generateEnvironmentReadme,
18
13
  getEnvironmentDescription,
19
14
  } from "../../utils/parsing";
20
- import { useQueryClient } from "@tanstack/react-query";
21
- import { useMutationWithApiError } from "../../hooks/useQueryWithApiError";
15
+ import { useCrudMutation } from "../../hooks/useCrudMutation";
22
16
  import { useServer } from "../ServerProvider";
17
+ import Stack from "@mui/material/Stack";
18
+ import { AppDialog } from "../AppDialog";
23
19
 
24
20
  interface EditEnvironmentModalProps {
25
21
  environment: Environment;
@@ -32,8 +28,6 @@ export default function EditEnvironmentDialog({
32
28
  }: EditEnvironmentModalProps) {
33
29
  const [open, setOpen] = useState(false);
34
30
  const { apiClients } = useServer();
35
- const queryClient = useQueryClient();
36
- const [notificationMessage, setNotificationMessage] = useState("");
37
31
 
38
32
  const handleClickOpen = () => {
39
33
  setOpen(true);
@@ -44,8 +38,8 @@ export default function EditEnvironmentDialog({
44
38
  onCloseDialog();
45
39
  };
46
40
 
47
- const editEnvironment = useMutationWithApiError({
48
- async mutationFn(variables: { description: string }) {
41
+ const editEnvironment = useCrudMutation({
42
+ mutationFn(variables: { description: string }) {
49
43
  return apiClients.environments.updateEnvironment(environment.name, {
50
44
  name: environment.name,
51
45
  readme: generateEnvironmentReadme(
@@ -57,18 +51,11 @@ export default function EditEnvironmentDialog({
57
51
  ),
58
52
  });
59
53
  },
60
- onSuccess() {
61
- handleClose();
62
- queryClient.invalidateQueries({ queryKey: ["environments"] });
63
- setNotificationMessage("Environment updated successfully");
64
- },
65
- onError(error) {
66
- setNotificationMessage(
67
- error instanceof Error
68
- ? error.message
69
- : "An unknown error occurred",
70
- );
71
- },
54
+ success: "Environment updated",
55
+ invalidates: [["environments"]],
56
+ closeDialog: handleClose,
57
+ resource: "environment",
58
+ action: "update",
72
59
  });
73
60
 
74
61
  const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
@@ -87,62 +74,61 @@ export default function EditEnvironmentDialog({
87
74
  <ListItemText>Edit</ListItemText>
88
75
  </MenuItem>
89
76
 
90
- <Dialog open={open} onClose={handleClose}>
91
- <DialogTitle>Edit Environment</DialogTitle>
92
- <DialogContent>
93
- <DialogContentText>
94
- Edit this environment&apos;s description.
95
- </DialogContentText>
96
- <form onSubmit={handleSubmit} id="environment-form">
77
+ <AppDialog
78
+ open={open}
79
+ onClose={handleClose}
80
+ title="Edit environment"
81
+ description="What this environment is, for the people who open it."
82
+ actions={
83
+ <>
84
+ <Button
85
+ disabled={editEnvironment.isPending}
86
+ onClick={handleClose}
87
+ >
88
+ Cancel
89
+ </Button>
90
+ <Button
91
+ type="submit"
92
+ form="environment-form"
93
+ variant="contained"
94
+ loading={editEnvironment.isPending}
95
+ >
96
+ Save changes
97
+ </Button>
98
+ </>
99
+ }
100
+ >
101
+ <form onSubmit={handleSubmit} id="environment-form">
102
+ <Stack sx={{ gap: 2 }}>
97
103
  <TextField
98
104
  autoFocus
99
105
  required
100
- margin="dense"
101
106
  id="name"
102
107
  name="name"
103
- label="Environment Name"
108
+ label="Name"
104
109
  disabled
105
110
  type="text"
106
111
  fullWidth
107
- variant="standard"
112
+ size="small"
108
113
  defaultValue={environment.name}
114
+ InputLabelProps={{ shrink: true }}
109
115
  />
110
116
  <TextField
111
- margin="dense"
112
117
  id="description"
113
118
  name="description"
114
- label="Environment Description"
119
+ label="Description"
115
120
  type="text"
116
121
  fullWidth
117
- variant="standard"
122
+ size="small"
118
123
  defaultValue={getEnvironmentDescription(
119
124
  environment.readme,
120
125
  )}
126
+ InputLabelProps={{ shrink: true }}
121
127
  />
122
- </form>
123
- </DialogContent>
124
- <DialogActions>
125
- <Button
126
- disabled={editEnvironment.isPending}
127
- onClick={handleClose}
128
- >
129
- Cancel
130
- </Button>
131
- <Button
132
- type="submit"
133
- form="environment-form"
134
- loading={editEnvironment.isPending}
135
- >
136
- Save Changes
137
- </Button>
138
- </DialogActions>
139
- </Dialog>
140
- <Snackbar
141
- open={notificationMessage !== ""}
142
- autoHideDuration={6000}
143
- onClose={() => setNotificationMessage("")}
144
- message={notificationMessage}
145
- />
128
+ </Stack>
129
+ </form>
130
+ </AppDialog>
131
+ {editEnvironment.notice}
146
132
  </React.Fragment>
147
133
  );
148
134
  }