@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,179 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import AddIcon from "@mui/icons-material/Add";
5
- import {
6
- Box,
7
- Button,
8
- Checkbox,
9
- Dialog,
10
- DialogActions,
11
- DialogContent,
12
- DialogContentText,
13
- DialogTitle,
14
- FormControlLabel,
15
- FormGroup,
16
- Switch,
17
- Typography,
18
- } from "@mui/material";
19
- import { useState } from "react";
20
-
21
- type CreateEnvMaterializationDialogProps = {
22
- /** Packages in the environment the user can materialize. */
23
- packages: { name: string }[];
24
- onSubmit: (opts: {
25
- packageNames: string[];
26
- forceRefresh: boolean;
27
- }) => Promise<unknown>;
28
- isSubmitting: boolean;
29
- disabled?: boolean;
30
- };
31
-
32
- export default function CreateEnvMaterializationDialog({
33
- packages,
34
- onSubmit,
35
- isSubmitting,
36
- disabled,
37
- }: CreateEnvMaterializationDialogProps) {
38
- const [open, setOpen] = useState(false);
39
- const [selected, setSelected] = useState<Record<string, boolean>>({});
40
- const [forceRefresh, setForceRefresh] = useState(false);
41
-
42
- const handleOpen = () => {
43
- setSelected({});
44
- setForceRefresh(false);
45
- setOpen(true);
46
- };
47
- const handleClose = () => setOpen(false);
48
-
49
- const selectedNames = packages
50
- .map((p) => p.name)
51
- .filter((name) => selected[name]);
52
-
53
- const toggle = (name: string) =>
54
- setSelected((prev) => ({ ...prev, [name]: !prev[name] }));
55
-
56
- const allSelected =
57
- packages.length > 0 && selectedNames.length === packages.length;
58
-
59
- const handleRun = async () => {
60
- try {
61
- await onSubmit({ packageNames: selectedNames, forceRefresh });
62
- setOpen(false);
63
- } catch {
64
- // The caller surfaces the error through its Snackbar; keep the dialog
65
- // open so the user can retry or adjust the selection.
66
- }
67
- };
68
-
69
- return (
70
- <>
71
- <Button
72
- variant="contained"
73
- startIcon={<AddIcon />}
74
- onClick={handleOpen}
75
- disabled={disabled}
76
- aria-label="New materialization"
77
- >
78
- New materialization
79
- </Button>
80
-
81
- <Dialog
82
- open={open}
83
- onClose={handleClose}
84
- maxWidth="xs"
85
- fullWidth
86
- aria-labelledby="create-env-materialization-title"
87
- >
88
- <DialogTitle id="create-env-materialization-title">
89
- New materialization
90
- </DialogTitle>
91
- <DialogContent>
92
- <DialogContentText sx={{ mb: 1 }}>
93
- Pick the packages to materialize. Each runs an independent
94
- build of every persist source in that package.
95
- </DialogContentText>
96
-
97
- {packages.length === 0 ? (
98
- <Typography variant="body2" color="text.secondary">
99
- No packages in this environment.
100
- </Typography>
101
- ) : (
102
- <>
103
- <FormControlLabel
104
- control={
105
- <Checkbox
106
- checked={allSelected}
107
- indeterminate={
108
- selectedNames.length > 0 && !allSelected
109
- }
110
- onChange={(event) => {
111
- const next: Record<string, boolean> = {};
112
- if (event.target.checked) {
113
- packages.forEach(
114
- (p) => (next[p.name] = true),
115
- );
116
- }
117
- setSelected(next);
118
- }}
119
- />
120
- }
121
- label={
122
- <Typography variant="body2">Select all</Typography>
123
- }
124
- />
125
- <Box
126
- sx={{
127
- maxHeight: 240,
128
- overflowY: "auto",
129
- pl: 1,
130
- borderLeft: "2px solid",
131
- borderColor: "divider",
132
- }}
133
- >
134
- <FormGroup>
135
- {packages.map((p) => (
136
- <FormControlLabel
137
- key={p.name}
138
- control={
139
- <Checkbox
140
- checked={!!selected[p.name]}
141
- onChange={() => toggle(p.name)}
142
- />
143
- }
144
- label={p.name}
145
- />
146
- ))}
147
- </FormGroup>
148
- </Box>
149
- <FormControlLabel
150
- sx={{ mt: 1 }}
151
- control={
152
- <Switch
153
- checked={forceRefresh}
154
- onChange={(event) =>
155
- setForceRefresh(event.target.checked)
156
- }
157
- />
158
- }
159
- label="Force refresh (rebuild even if unchanged)"
160
- />
161
- </>
162
- )}
163
- </DialogContent>
164
- <DialogActions>
165
- <Button onClick={handleClose}>Cancel</Button>
166
- <Button
167
- variant="contained"
168
- loading={isSubmitting}
169
- disabled={selectedNames.length === 0}
170
- onClick={handleRun}
171
- >
172
- Materialize
173
- {selectedNames.length > 0 ? ` (${selectedNames.length})` : ""}
174
- </Button>
175
- </DialogActions>
176
- </Dialog>
177
- </>
178
- );
179
- }
@@ -1,267 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import { Box, Button, Snackbar, Stack, Typography } from "@mui/material";
5
- import { useQueryClient } from "@tanstack/react-query";
6
- import React, { useState } from "react";
7
- import { Materialization, MaterializationActionActionEnum } from "../../client";
8
- import {
9
- useMutationWithApiError,
10
- useQueryWithApiError,
11
- } from "../../hooks/useQueryWithApiError";
12
- import { parseResourceUri } from "../../utils/formatting";
13
- import { ApiErrorDisplay } from "../ApiErrorDisplay";
14
- import { Loading } from "../Loading";
15
- import { useServer } from "../ServerProvider";
16
- import CreateEnvMaterializationDialog from "./CreateEnvMaterializationDialog";
17
- import MaterializationDetailDialog from "./MaterializationDetailDialog";
18
- import MaterializationRunsList from "./MaterializationRunsList";
19
- import { isActiveStatus } from "./utils";
20
-
21
- const MATERIALIZATION_POLL_MS = 3000;
22
- const PAGE_SIZE = 10;
23
-
24
- interface EnvironmentMaterializationsProps {
25
- resourceUri: string;
26
- onClickPackageFile?: (to: string, event?: React.MouseEvent) => void;
27
- }
28
-
29
- export default function EnvironmentMaterializations({
30
- resourceUri,
31
- onClickPackageFile,
32
- }: EnvironmentMaterializationsProps) {
33
- const { apiClients, mutable } = useServer();
34
- const queryClient = useQueryClient();
35
- const { environmentName } = parseResourceUri(resourceUri);
36
- const [notificationMessage, setNotificationMessage] = useState("");
37
- const [selectedId, setSelectedId] = useState<string | null>(null);
38
- // Show the most recent runs and page in more on demand — a busy environment
39
- // (e.g. a frequent schedule) accumulates runs without bound, so never render
40
- // the full history at once.
41
- const [limit, setLimit] = useState(PAGE_SIZE);
42
-
43
- const onClick =
44
- onClickPackageFile ??
45
- ((to: string) => {
46
- window.location.href = to;
47
- });
48
-
49
- const listQuery = useQueryWithApiError({
50
- queryKey: ["env-materializations", environmentName, limit],
51
- queryFn: () =>
52
- apiClients.materializations.listEnvironmentMaterializations(
53
- environmentName,
54
- limit,
55
- ),
56
- // "Show more" grows `limit` (part of the key), so keep the current rows on
57
- // screen while the larger page loads instead of flashing back to the
58
- // loading state.
59
- placeholderData: (previousData) => previousData,
60
- refetchInterval: (query) => {
61
- const payload = query.state.data as
62
- | { data?: Materialization[] }
63
- | undefined;
64
- const rows = payload?.data ?? [];
65
- return rows.some((row) => isActiveStatus(row.status))
66
- ? MATERIALIZATION_POLL_MS
67
- : false;
68
- },
69
- });
70
-
71
- const packagesQuery = useQueryWithApiError({
72
- queryKey: ["packages", environmentName],
73
- queryFn: () => apiClients.packages.listPackages(environmentName),
74
- });
75
-
76
- const invalidateList = () =>
77
- queryClient.invalidateQueries({
78
- queryKey: ["env-materializations", environmentName],
79
- });
80
-
81
- // Fire one create per selected package. Each package builds independently, so
82
- // a failure on one (e.g. an already-active materialization) does not block the
83
- // others — report an aggregate outcome.
84
- const createMaterializations = useMutationWithApiError({
85
- mutationFn: async (opts: {
86
- packageNames: string[];
87
- forceRefresh: boolean;
88
- }) => {
89
- const results = await Promise.allSettled(
90
- opts.packageNames.map((pkg) =>
91
- apiClients.materializations.createMaterialization(
92
- environmentName,
93
- pkg,
94
- { forceRefresh: opts.forceRefresh },
95
- ),
96
- ),
97
- );
98
- const failed = results.filter((r) => r.status === "rejected").length;
99
- return { total: opts.packageNames.length, failed };
100
- },
101
- onSuccess(result) {
102
- const started = result.total - result.failed;
103
- setNotificationMessage(
104
- result.failed === 0
105
- ? `Started ${started} materialization${started === 1 ? "" : "s"}`
106
- : `Started ${started} of ${result.total} (${result.failed} could not start — a build may already be active)`,
107
- );
108
- invalidateList();
109
- },
110
- onError(error) {
111
- setNotificationMessage(error.message);
112
- invalidateList();
113
- },
114
- });
115
-
116
- const stopMaterialization = useMutationWithApiError({
117
- mutationFn: (materialization: Materialization) =>
118
- apiClients.materializations.materializationAction(
119
- environmentName,
120
- materialization.packageName as string,
121
- materialization.id as string,
122
- MaterializationActionActionEnum.Stop,
123
- ),
124
- onSuccess() {
125
- setNotificationMessage("Materialization stopped");
126
- invalidateList();
127
- },
128
- onError(error) {
129
- setNotificationMessage(error.message);
130
- },
131
- });
132
-
133
- const deleteMaterialization = useMutationWithApiError({
134
- mutationFn: ({
135
- materialization,
136
- dropTables,
137
- }: {
138
- materialization: Materialization;
139
- dropTables: boolean;
140
- }) =>
141
- apiClients.materializations.deleteMaterialization(
142
- environmentName,
143
- materialization.packageName as string,
144
- materialization.id as string,
145
- dropTables,
146
- ),
147
- onSuccess() {
148
- setNotificationMessage("Materialization deleted");
149
- invalidateList();
150
- },
151
- onError(error) {
152
- setNotificationMessage(error.message);
153
- },
154
- });
155
-
156
- const materializations = (listQuery.data?.data ?? []) as Materialization[];
157
- const packages = (packagesQuery.data?.data ?? []) as { name: string }[];
158
- const selected =
159
- materializations.find((row) => row.id === selectedId) ?? null;
160
- const isMutating =
161
- createMaterializations.isPending ||
162
- stopMaterialization.isPending ||
163
- deleteMaterialization.isPending;
164
- // A full page implies there may be older runs beyond the current window.
165
- const hasMore = materializations.length >= limit;
166
-
167
- return (
168
- <Box>
169
- <Box
170
- sx={{
171
- display: "flex",
172
- alignItems: "flex-start",
173
- justifyContent: "space-between",
174
- mb: 3,
175
- }}
176
- >
177
- <Box>
178
- <Typography
179
- variant="h6"
180
- sx={{ fontWeight: 600, letterSpacing: "-0.025em" }}
181
- >
182
- Materializations
183
- </Typography>
184
- <Typography variant="body2" color="text.secondary">
185
- All materialization builds across the packages in this
186
- environment
187
- </Typography>
188
- </Box>
189
- {mutable && (
190
- <CreateEnvMaterializationDialog
191
- packages={packages}
192
- onSubmit={(opts) => createMaterializations.mutateAsync(opts)}
193
- isSubmitting={createMaterializations.isPending}
194
- />
195
- )}
196
- </Box>
197
-
198
- {listQuery.isError && (
199
- <ApiErrorDisplay
200
- error={listQuery.error}
201
- context={`${environmentName} > Materializations`}
202
- />
203
- )}
204
- {!listQuery.isSuccess && !listQuery.isError && (
205
- <Loading text="Loading materializations..." />
206
- )}
207
- {listQuery.isSuccess && (
208
- <MaterializationRunsList
209
- materializations={materializations}
210
- mutable={mutable}
211
- isMutating={isMutating}
212
- showPackage
213
- onClickPackage={(packageName) =>
214
- onClick(`/${environmentName}/${packageName}/materializations`)
215
- }
216
- onStop={(materialization) =>
217
- stopMaterialization.mutate(materialization)
218
- }
219
- onDelete={(materialization, dropTables) =>
220
- deleteMaterialization.mutate({ materialization, dropTables })
221
- }
222
- onViewDetails={(materialization) =>
223
- setSelectedId(materialization.id ?? null)
224
- }
225
- />
226
- )}
227
- {listQuery.isSuccess && materializations.length > 0 && (
228
- <Stack
229
- direction="row"
230
- alignItems="center"
231
- justifyContent="center"
232
- spacing={2}
233
- sx={{ mt: 2 }}
234
- >
235
- <Typography variant="caption" color="text.secondary">
236
- {hasMore
237
- ? `Showing ${materializations.length} most recent`
238
- : `${materializations.length} materialization${materializations.length === 1 ? "" : "s"}`}
239
- </Typography>
240
- {hasMore && (
241
- <Button
242
- size="small"
243
- onClick={() => setLimit((l) => l + PAGE_SIZE)}
244
- disabled={listQuery.isFetching}
245
- >
246
- Show more
247
- </Button>
248
- )}
249
- </Stack>
250
- )}
251
-
252
- <MaterializationDetailDialog
253
- materialization={selected}
254
- buildPlan={null}
255
- showBuildPlan={false}
256
- onClose={() => setSelectedId(null)}
257
- />
258
-
259
- <Snackbar
260
- open={notificationMessage !== ""}
261
- autoHideDuration={6000}
262
- onClose={() => setNotificationMessage("")}
263
- message={notificationMessage}
264
- />
265
- </Box>
266
- );
267
- }
@@ -1,231 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import ScheduleIcon from "@mui/icons-material/Schedule";
5
- import {
6
- Box,
7
- Card,
8
- CardContent,
9
- Chip,
10
- Stack,
11
- ToggleButton,
12
- ToggleButtonGroup,
13
- Tooltip,
14
- Typography,
15
- } from "@mui/material";
16
- import { MONO_FONT_FAMILY } from "../styles";
17
- import { describeCron, formatNextRun } from "./cron";
18
- import SetScheduleDialog from "./SetScheduleDialog";
19
-
20
- type Scope = "package" | "version";
21
-
22
- type ScheduleCardProps = {
23
- /** The package's cron, or null when no schedule is declared. */
24
- schedule: string | null;
25
- /** The package's persist scope. */
26
- scope: Scope;
27
- /** When set, the package is control-plane-driven (orchestrated). */
28
- manifestLocation: string | null;
29
- /** True when the package declares a freshness policy (schedule N/A). */
30
- hasFreshness: boolean;
31
- mutable: boolean;
32
- isSubmitting: boolean;
33
- /** True while a scope change is in flight. */
34
- isScopeMutating?: boolean;
35
- onSubmit: (schedule: string | null) => Promise<unknown>;
36
- /** Persist a new scope (package | version). */
37
- onScopeChange?: (scope: Scope) => Promise<unknown>;
38
- };
39
-
40
- export default function ScheduleCard({
41
- schedule,
42
- scope,
43
- manifestLocation,
44
- hasFreshness,
45
- mutable,
46
- isSubmitting,
47
- isScopeMutating,
48
- onSubmit,
49
- onScopeChange,
50
- }: ScheduleCardProps) {
51
- const orchestrated = Boolean(manifestLocation);
52
- const info = schedule ? describeCron(schedule) : null;
53
- // A schedule requires version scope, so scope is locked while one is set —
54
- // the server would reject scope: package (publish-gate Rule 2). Clearing the
55
- // schedule unlocks it, giving an explicit way back to package scope.
56
- const scopeLocked = Boolean(schedule);
57
-
58
- return (
59
- <Card variant="outlined" sx={{ borderRadius: 2, mb: 6 }}>
60
- <CardContent>
61
- <Stack
62
- direction="row"
63
- justifyContent="space-between"
64
- alignItems="flex-start"
65
- spacing={2}
66
- >
67
- <Box sx={{ minWidth: 0 }}>
68
- <Stack
69
- direction="row"
70
- alignItems="center"
71
- spacing={1}
72
- sx={{ mb: 1 }}
73
- >
74
- <ScheduleIcon fontSize="small" color="action" />
75
- <Typography
76
- variant="h6"
77
- sx={{ fontWeight: 600, letterSpacing: "-0.025em" }}
78
- >
79
- Schedule
80
- </Typography>
81
- </Stack>
82
-
83
- {orchestrated ? (
84
- <Box>
85
- <Chip
86
- size="small"
87
- color="default"
88
- variant="outlined"
89
- label="Control-plane managed"
90
- sx={{ mb: 1 }}
91
- />
92
- <Typography variant="body2" color="text.secondary">
93
- Refresh is driven by the control plane; the built-in
94
- scheduler does not fire this package.
95
- </Typography>
96
- </Box>
97
- ) : info ? (
98
- <Box>
99
- <Stack
100
- direction="row"
101
- alignItems="center"
102
- spacing={1}
103
- sx={{ mb: 0.5, flexWrap: "wrap" }}
104
- >
105
- <Chip
106
- size="small"
107
- color="success"
108
- variant="outlined"
109
- icon={<ScheduleIcon fontSize="small" />}
110
- label="Active"
111
- />
112
- <Box
113
- component="code"
114
- sx={{
115
- fontFamily: MONO_FONT_FAMILY,
116
- fontSize: "0.8125rem",
117
- px: 0.75,
118
- py: 0.25,
119
- borderRadius: 1,
120
- bgcolor: "action.hover",
121
- }}
122
- >
123
- {schedule}
124
- </Box>
125
- </Stack>
126
- <Typography variant="body2">
127
- {info.valid
128
- ? info.description
129
- : "Unrecognized cron expression."}
130
- </Typography>
131
- {info.valid && (
132
- <Typography variant="body2" color="text.secondary">
133
- Next run: {formatNextRun(info.nextRun)}
134
- </Typography>
135
- )}
136
- </Box>
137
- ) : hasFreshness ? (
138
- <Typography variant="body2" color="text.secondary">
139
- This package uses a freshness policy; a cron schedule is
140
- not applicable.
141
- </Typography>
142
- ) : (
143
- <Typography variant="body2" color="text.secondary">
144
- On-demand only — no schedule set.
145
- </Typography>
146
- )}
147
-
148
- {!orchestrated && (
149
- <Box sx={{ mt: 2 }}>
150
- <Typography
151
- variant="caption"
152
- color="text.secondary"
153
- sx={{ display: "block", mb: 0.5 }}
154
- >
155
- Scope
156
- </Typography>
157
- <Tooltip
158
- title={
159
- scopeLocked
160
- ? "A schedule requires version scope. Clear the schedule to change it."
161
- : ""
162
- }
163
- >
164
- <span>
165
- <ToggleButtonGroup
166
- size="small"
167
- exclusive
168
- value={scope}
169
- disabled={
170
- !mutable ||
171
- !onScopeChange ||
172
- scopeLocked ||
173
- Boolean(isScopeMutating)
174
- }
175
- onChange={(_e, next: Scope | null) => {
176
- if (next && next !== scope) {
177
- onScopeChange?.(next);
178
- }
179
- }}
180
- >
181
- <ToggleButton value="package">
182
- package
183
- </ToggleButton>
184
- <ToggleButton value="version">
185
- version
186
- </ToggleButton>
187
- </ToggleButtonGroup>
188
- </span>
189
- </Tooltip>
190
- <Typography
191
- variant="caption"
192
- color="text.secondary"
193
- sx={{ display: "block", mt: 0.5 }}
194
- >
195
- {scope === "version"
196
- ? "Materialized artifacts are per version (required for a schedule)."
197
- : "Materialized artifacts are shared across versions."}
198
- </Typography>
199
- </Box>
200
- )}
201
-
202
- <Typography
203
- variant="caption"
204
- color="text.secondary"
205
- sx={{ display: "block", mt: 1.5 }}
206
- >
207
- Declared in <code>publisher.json</code>.
208
- {!orchestrated && (
209
- <>
210
- {" "}
211
- In a hosted deployment, a change takes effect on your
212
- next publish.
213
- </>
214
- )}
215
- </Typography>
216
- </Box>
217
-
218
- {mutable && !orchestrated && (
219
- <SetScheduleDialog
220
- currentSchedule={schedule}
221
- isSubmitting={isSubmitting}
222
- disabled={hasFreshness}
223
- disabledReason="This package declares a freshness policy; a schedule and freshness are mutually exclusive."
224
- onSubmit={onSubmit}
225
- />
226
- )}
227
- </Stack>
228
- </CardContent>
229
- </Card>
230
- );
231
- }