@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
@@ -2,20 +2,16 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { Edit } from "@mui/icons-material";
5
- import { ListItemIcon, ListItemText, MenuItem, Snackbar } from "@mui/material";
5
+ import { ListItemIcon, ListItemText, MenuItem } from "@mui/material";
6
6
  import Button from "@mui/material/Button";
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 TextField from "@mui/material/TextField";
13
- import { useQueryClient } from "@tanstack/react-query";
14
8
  import React, { useState } from "react";
15
9
  import { Package } from "../../client";
16
- import { useMutationWithApiError } from "../../hooks/useQueryWithApiError";
10
+ import { useCrudMutation } from "../../hooks/useCrudMutation";
17
11
  import { parseResourceUri } from "../../utils/formatting";
18
12
  import { useServer } from "../ServerProvider";
13
+ import { Stack } from "@mui/material";
14
+ import { AppDialog } from "../AppDialog";
19
15
 
20
16
  interface EditPackageDialogProps {
21
17
  package: Package;
@@ -30,8 +26,6 @@ export default function EditPackageDialog({
30
26
  }: EditPackageDialogProps) {
31
27
  const [open, setOpen] = useState(false);
32
28
  const { apiClients } = useServer();
33
- const queryClient = useQueryClient();
34
- const [notificationMessage, setNotificationMessage] = useState("");
35
29
 
36
30
  const handleClickOpen = () => {
37
31
  setOpen(true);
@@ -43,8 +37,8 @@ export default function EditPackageDialog({
43
37
  };
44
38
 
45
39
  const { packageName, environmentName } = parseResourceUri(resourceUri);
46
- const editPackage = useMutationWithApiError({
47
- async mutationFn(variables: { description: string }) {
40
+ const editPackage = useCrudMutation({
41
+ mutationFn(variables: { description: string }) {
48
42
  return apiClients.packages.updatePackage(
49
43
  environmentName,
50
44
  packageName,
@@ -54,20 +48,11 @@ export default function EditPackageDialog({
54
48
  },
55
49
  );
56
50
  },
57
- onSuccess() {
58
- handleClose();
59
- setNotificationMessage("Package updated successfully");
60
- queryClient.invalidateQueries({
61
- queryKey: ["packages", environmentName],
62
- });
63
- },
64
- onError(error) {
65
- setNotificationMessage(
66
- error instanceof Error
67
- ? error.message
68
- : "An unknown error occurred",
69
- );
70
- },
51
+ success: "Package updated",
52
+ invalidates: [["packages", environmentName]],
53
+ closeDialog: handleClose,
54
+ resource: "package",
55
+ action: "update",
71
56
  });
72
57
 
73
58
  const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
@@ -86,25 +71,44 @@ export default function EditPackageDialog({
86
71
  <ListItemText>Edit</ListItemText>
87
72
  </MenuItem>
88
73
 
89
- <Dialog open={open} onClose={handleClose}>
90
- <DialogTitle>Edit Package</DialogTitle>
91
- <DialogContent>
92
- <DialogContentText>
93
- Update the details for &quot;{_package.name}&quot;.
94
- </DialogContentText>
95
- <form onSubmit={handleSubmit} id="package-form">
74
+ <AppDialog
75
+ open={open}
76
+ onClose={handleClose}
77
+ title="Edit package"
78
+ description={`What ${_package.name} is, for the people who open it.`}
79
+ actions={
80
+ <>
81
+ <Button
82
+ disabled={editPackage.isPending}
83
+ onClick={handleClose}
84
+ >
85
+ Cancel
86
+ </Button>
87
+ <Button
88
+ type="submit"
89
+ form="package-form"
90
+ variant="contained"
91
+ loading={editPackage.isPending}
92
+ >
93
+ Save changes
94
+ </Button>
95
+ </>
96
+ }
97
+ >
98
+ <form onSubmit={handleSubmit} id="package-form">
99
+ <Stack sx={{ gap: 2 }}>
96
100
  <TextField
97
101
  autoFocus
98
102
  required
99
- margin="dense"
100
103
  id="name"
101
104
  name="name"
102
- label="Package Name"
105
+ label="Name"
103
106
  disabled
104
107
  type="text"
105
108
  fullWidth
106
- variant="standard"
109
+ size="small"
107
110
  defaultValue={_package.name}
111
+ InputLabelProps={{ shrink: true }}
108
112
  />
109
113
  <TextField
110
114
  id="description"
@@ -113,30 +117,14 @@ export default function EditPackageDialog({
113
117
  multiline
114
118
  fullWidth
115
119
  rows={4}
120
+ size="small"
116
121
  defaultValue={_package.description}
117
- variant="standard"
122
+ InputLabelProps={{ shrink: true }}
118
123
  />
119
- </form>
120
- </DialogContent>
121
- <DialogActions>
122
- <Button disabled={editPackage.isPending} onClick={handleClose}>
123
- Cancel
124
- </Button>
125
- <Button
126
- type="submit"
127
- form="package-form"
128
- loading={editPackage.isPending}
129
- >
130
- Save Changes
131
- </Button>
132
- </DialogActions>
133
- </Dialog>
134
- <Snackbar
135
- open={notificationMessage !== ""}
136
- autoHideDuration={6000}
137
- onClose={() => setNotificationMessage("")}
138
- message={notificationMessage}
139
- />
124
+ </Stack>
125
+ </form>
126
+ </AppDialog>
127
+ {editPackage.notice}
140
128
  </React.Fragment>
141
129
  );
142
130
  }
@@ -1,10 +1,12 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import { Box, Container, Stack, Typography } from "@mui/material";
4
+ import { Box, Container, Typography } from "@mui/material";
5
5
  import { useEffect } from "react";
6
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
6
7
  import { parseResourceUri } from "../../utils/formatting";
7
- import { EnvironmentMaterializations } from "../Materializations";
8
+ import { BackLink } from "../BackLink";
9
+ import { PackageSection } from "../PackageSection";
8
10
  import { useServer } from "../ServerProvider";
9
11
  import About from "./About";
10
12
  import AddPackageDialog from "./AddPackageDialog";
@@ -20,8 +22,14 @@ export default function Environment({
20
22
  onSelectPackage,
21
23
  resourceUri,
22
24
  }: EnvironmentProps) {
23
- const { mutable } = useServer();
25
+ const { apiClients, mutable } = useServer();
24
26
  const { environmentName } = parseResourceUri(resourceUri);
27
+ // Only for the heading's count: the list below runs the same query under the
28
+ // same key, so this shares its cache rather than fetching twice.
29
+ const packages = useQueryWithApiError({
30
+ queryKey: ["packages", environmentName],
31
+ queryFn: () => apiClients.packages.listPackages(environmentName),
32
+ });
25
33
 
26
34
  useEffect(() => {
27
35
  window.scrollTo({ top: 0, behavior: "auto" });
@@ -30,9 +38,18 @@ export default function Environment({
30
38
  return (
31
39
  <Container
32
40
  maxWidth={false}
33
- sx={{ maxWidth: 1024, mx: "auto", px: 4, py: 3 }}
41
+ sx={{ maxWidth: 1024, mx: "auto", px: 3, py: 6 }}
34
42
  >
35
- <Box sx={{ mb: 5 }}>
43
+ <Box sx={{ mb: 4 }}>
44
+ {/* The environment's parent is the server itself, which is what
45
+ home lists. `onSelectPackage` is this component's one navigation
46
+ hook; the name is narrow but the job is not. */}
47
+ <Box>
48
+ <BackLink
49
+ label="Publisher"
50
+ onClick={(event) => onSelectPackage("/", event)}
51
+ />
52
+ </Box>
36
53
  <Typography
37
54
  variant="h4"
38
55
  component="h1"
@@ -46,42 +63,23 @@ export default function Environment({
46
63
  </Typography>
47
64
  </Box>
48
65
 
49
- <Box sx={{ mb: 5 }}>
50
- <Stack
51
- direction="row"
52
- justifyContent="space-between"
53
- alignItems="flex-start"
54
- sx={{ mb: 3 }}
55
- >
56
- <Box>
57
- <Typography
58
- variant="h6"
59
- sx={{ fontWeight: 600, letterSpacing: "-0.025em" }}
60
- >
61
- Packages
62
- </Typography>
63
- <Typography variant="body2" color="text.secondary">
64
- Published packages available for use in this environment
65
- </Typography>
66
- </Box>
67
- {mutable && <AddPackageDialog resourceUri={resourceUri} />}
68
- </Stack>
66
+ <PackageSection
67
+ title="Packages"
68
+ {...(packages.isSuccess
69
+ ? { count: packages.data.data.length }
70
+ : {})}
71
+ description="Published packages available for use in this environment"
72
+ {...(mutable
73
+ ? { action: <AddPackageDialog resourceUri={resourceUri} /> }
74
+ : {})}
75
+ >
69
76
  <Packages
70
77
  onSelectPackage={onSelectPackage}
71
78
  resourceUri={resourceUri}
72
79
  />
73
- </Box>
74
-
75
- <Box sx={{ mb: 5 }}>
76
- <Connections resourceUri={resourceUri} />
77
- </Box>
80
+ </PackageSection>
78
81
 
79
- <Box sx={{ mb: 5 }}>
80
- <EnvironmentMaterializations
81
- resourceUri={resourceUri}
82
- onClickPackageFile={onSelectPackage}
83
- />
84
- </Box>
82
+ <Connections resourceUri={resourceUri} />
85
83
 
86
84
  <About resourceUri={resourceUri} />
87
85
  </Container>
@@ -3,21 +3,14 @@
3
3
 
4
4
  import { MoreVert } from "@mui/icons-material";
5
5
  import Inventory2OutlinedIcon from "@mui/icons-material/Inventory2Outlined";
6
- import {
7
- Box,
8
- Card,
9
- CardContent,
10
- Grid,
11
- IconButton,
12
- Menu,
13
- Tooltip,
14
- Typography,
15
- } from "@mui/material";
6
+ import { IconButton, Menu, Stack } from "@mui/material";
16
7
  import { useState } from "react";
17
8
  import { Package } from "../../client";
18
9
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
19
10
  import { encodeResourceUri, parseResourceUri } from "../../utils/formatting";
20
11
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
12
+ import { ItemRow } from "../ItemRow";
13
+ import { SURFACE_TINT } from "../styles";
21
14
  import { Loading } from "../Loading";
22
15
  import { useServer } from "../ServerProvider";
23
16
  import DeletePackageDialog from "./DeletePackageDialog";
@@ -55,27 +48,29 @@ export default function Packages({
55
48
  const packages = [...data.data].sort((a, b) => a.name.localeCompare(b.name));
56
49
 
57
50
  return (
58
- <Grid container spacing={2}>
51
+ // The labelled region is the `PackageSection` above this: a reader can
52
+ // jump to the packages, and a test can name one without catching the
53
+ // same package's name in the materializations table below.
54
+ <Stack>
59
55
  {packages.map((pkg) => {
60
56
  const packageResourceUri = encodeResourceUri({
61
57
  environmentName,
62
58
  packageName: pkg.name,
63
59
  });
64
60
  return (
65
- <Grid size={{ xs: 12, sm: 6, md: 4 }} key={pkg.name}>
66
- <PackageCard
67
- pkg={pkg}
68
- packageResourceUri={packageResourceUri}
69
- onSelectPackage={onSelectPackage}
70
- />
71
- </Grid>
61
+ <PackageRow
62
+ key={pkg.name}
63
+ pkg={pkg}
64
+ packageResourceUri={packageResourceUri}
65
+ onSelectPackage={onSelectPackage}
66
+ />
72
67
  );
73
68
  })}
74
- </Grid>
69
+ </Stack>
75
70
  );
76
71
  }
77
72
 
78
- function PackageCard({
73
+ function PackageRow({
79
74
  pkg,
80
75
  packageResourceUri,
81
76
  onSelectPackage,
@@ -88,119 +83,59 @@ function PackageCard({
88
83
  const [menuAnchorEl, setMenuAnchorEl] = useState<null | HTMLElement>(null);
89
84
  const menuOpen = Boolean(menuAnchorEl);
90
85
 
91
- const handleClick = (event: React.MouseEvent) => {
92
- onSelectPackage(pkg.name, event);
93
- };
94
-
95
86
  const handleMenuClick = (event: React.MouseEvent<HTMLElement>) => {
96
87
  event.stopPropagation();
97
88
  setMenuAnchorEl(event.currentTarget);
98
89
  };
99
-
100
- const handleMenuClose = () => {
101
- setMenuAnchorEl(null);
102
- };
103
-
104
- const description = pkg.description ?? "";
90
+ const handleMenuClose = () => setMenuAnchorEl(null);
105
91
 
106
92
  return (
107
- <Card
108
- variant="outlined"
109
- onClick={handleClick}
110
- sx={{
111
- height: "100%",
112
- cursor: "pointer",
113
- borderRadius: 3,
114
- borderColor: "divider",
115
- boxShadow: "none",
116
- transition: "all 0.2s ease-in-out",
117
- "&:hover": { boxShadow: 2, borderColor: "primary.main" },
118
- }}
119
- >
120
- <CardContent sx={{ p: 2.5, "&:last-child": { pb: 2.5 } }}>
121
- <Box sx={{ display: "flex", alignItems: "flex-start", gap: 1.5 }}>
122
- <Box
123
- sx={(theme) => ({
124
- width: 36,
125
- height: 36,
126
- borderRadius: 1.5,
127
- bgcolor:
128
- theme.palette.mode === "dark"
129
- ? "rgba(255, 255, 255, 0.08)"
130
- : "grey.100",
131
- display: "flex",
132
- alignItems: "center",
133
- justifyContent: "center",
134
- flexShrink: 0,
135
- color: "text.primary",
136
- })}
137
- >
138
- <Inventory2OutlinedIcon sx={{ fontSize: 20 }} />
139
- </Box>
140
- <Box sx={{ flex: 1, minWidth: 0 }}>
141
- <Typography
142
- variant="subtitle1"
143
- component="h6"
144
- noWrap
145
- sx={{ fontWeight: 600, mb: 0.5 }}
146
- >
147
- {pkg.name}
148
- </Typography>
149
- <Tooltip title={description} followCursor enterDelay={1000}>
150
- <Typography
151
- variant="body2"
152
- color="text.secondary"
153
- sx={{
154
- overflow: "hidden",
155
- textOverflow: "ellipsis",
156
- display: "-webkit-box",
157
- WebkitLineClamp: 2,
158
- WebkitBoxOrient: "vertical",
159
- lineHeight: 1.5,
160
- }}
161
- >
162
- {description}
163
- </Typography>
164
- </Tooltip>
165
- </Box>
166
- {mutable && (
167
- <>
168
- <IconButton
169
- size="small"
170
- onClick={handleMenuClick}
171
- aria-label={`Package actions for ${pkg.name}`}
172
- sx={{ flexShrink: 0, mt: -0.5, mr: -0.5 }}
173
- >
174
- <MoreVert fontSize="small" />
175
- </IconButton>
176
- <Menu
177
- anchorEl={menuAnchorEl}
178
- open={menuOpen}
179
- onClose={handleMenuClose}
180
- onClick={(e) => e.stopPropagation()}
181
- anchorOrigin={{
182
- vertical: "bottom",
183
- horizontal: "right",
184
- }}
185
- transformOrigin={{
186
- vertical: "top",
187
- horizontal: "right",
188
- }}
189
- >
190
- <EditPackageDialog
191
- package={pkg}
192
- resourceUri={packageResourceUri}
193
- onCloseDialog={handleMenuClose}
194
- />
195
- <DeletePackageDialog
196
- resourceUri={packageResourceUri}
197
- onCloseDialog={handleMenuClose}
198
- />
199
- </Menu>
200
- </>
201
- )}
202
- </Box>
203
- </CardContent>
204
- </Card>
93
+ <ItemRow
94
+ icon={<Inventory2OutlinedIcon sx={{ fontSize: 18 }} />}
95
+ tint={SURFACE_TINT.package}
96
+ label={pkg.name}
97
+ ariaLabel={pkg.name}
98
+ {...(pkg.description ? { description: pkg.description } : {})}
99
+ onClick={(event) => onSelectPackage(pkg.name, event)}
100
+ {...(mutable
101
+ ? {
102
+ trailingAction: (
103
+ <>
104
+ <IconButton
105
+ size="small"
106
+ onClick={handleMenuClick}
107
+ aria-label={`Package actions for ${pkg.name}`}
108
+ >
109
+ <MoreVert fontSize="small" />
110
+ </IconButton>
111
+ <Menu
112
+ anchorEl={menuAnchorEl}
113
+ open={menuOpen}
114
+ onClose={handleMenuClose}
115
+ onClick={(event) => event.stopPropagation()}
116
+ anchorOrigin={{
117
+ vertical: "bottom",
118
+ horizontal: "right",
119
+ }}
120
+ transformOrigin={{
121
+ vertical: "top",
122
+ horizontal: "right",
123
+ }}
124
+ >
125
+ <EditPackageDialog
126
+ package={pkg}
127
+ resourceUri={packageResourceUri}
128
+ onCloseDialog={handleMenuClose}
129
+ />
130
+ <DeletePackageDialog
131
+ resourceUri={packageResourceUri}
132
+ onCloseDialog={handleMenuClose}
133
+ />
134
+ </Menu>
135
+ </>
136
+ ),
137
+ }
138
+ : {})}
139
+ />
205
140
  );
206
141
  }
@@ -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
  }