@malloy-publisher/sdk 0.0.382-dev → 0.2.1

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 (284) hide show
  1. package/README.md +115 -95
  2. package/TREE_SHAKING.md +16 -11
  3. package/bunfig.toml +7 -0
  4. package/dist/ServerProvider-Cn_LhKda.cjs.js +1 -0
  5. package/dist/ServerProvider-sfabtriY.es.js +4076 -0
  6. package/dist/client/api.d.ts +3773 -1515
  7. package/dist/client/configuration.d.ts +1 -1
  8. package/dist/client/index.cjs.js +1 -1
  9. package/dist/client/index.d.ts +1 -1
  10. package/dist/client/index.es.js +86 -59
  11. package/dist/components/Connections/EditConnectionDialog.d.ts +2 -1
  12. package/dist/components/Connections/common.d.ts +8 -2
  13. package/dist/components/Dashboard/Dashboard.d.ts +62 -0
  14. package/dist/components/Dashboard/DashboardTile.d.ts +57 -0
  15. package/dist/components/Dashboard/index.d.ts +2 -0
  16. package/dist/components/DataAppViewer/DataAppViewer.d.ts +23 -0
  17. package/dist/components/DataAppViewer/index.d.ts +1 -0
  18. package/dist/components/Environment/Environment.d.ts +6 -0
  19. package/dist/components/Environment/index.d.ts +2 -0
  20. package/dist/components/Home/AddEnvironmentDialog.d.ts +1 -0
  21. package/dist/components/Home/DeleteEnvironmentDialog.d.ts +5 -0
  22. package/dist/components/Home/EditEnvironmentDialog.d.ts +7 -0
  23. package/dist/components/Home/Home.d.ts +2 -2
  24. package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +14 -0
  25. package/dist/components/Materializations/CreateMaterializationDialog.d.ts +10 -0
  26. package/dist/components/Materializations/DeleteMaterializationDialog.d.ts +7 -0
  27. package/dist/components/Materializations/EnvironmentMaterializations.d.ts +7 -0
  28. package/dist/components/Materializations/ManifestView.d.ts +13 -0
  29. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +9 -0
  30. package/dist/components/Materializations/MaterializationRunsList.d.ts +15 -0
  31. package/dist/components/Materializations/Materializations.d.ts +7 -0
  32. package/dist/components/Materializations/ScheduleCard.d.ts +20 -0
  33. package/dist/components/Materializations/SectionLabel.d.ts +10 -0
  34. package/dist/components/Materializations/SetScheduleDialog.d.ts +11 -0
  35. package/dist/components/Materializations/TriggerChip.d.ts +10 -0
  36. package/dist/components/Materializations/cron.d.ts +23 -0
  37. package/dist/components/Materializations/index.d.ts +2 -0
  38. package/dist/components/Materializations/utils.d.ts +46 -0
  39. package/dist/components/Notebook/Notebook.d.ts +47 -4
  40. package/dist/components/Notebook/NotebookCell.d.ts +37 -1
  41. package/dist/components/Notebook/runPlan.d.ts +29 -0
  42. package/dist/components/Notebook/types.d.ts +10 -0
  43. package/dist/components/Package/ContentTypeIcon.d.ts +31 -0
  44. package/dist/components/Package/Package.d.ts +1 -4
  45. package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
  46. package/dist/components/RenderedResult/ResultContainer.d.ts +5 -1
  47. package/dist/components/RenderedResult/renderLogs.d.ts +6 -0
  48. package/dist/components/ResultsDialog.d.ts +6 -1
  49. package/dist/components/ServerProvider.d.ts +28 -4
  50. package/dist/components/click_helper.d.ts +10 -1
  51. package/dist/components/drill/index.d.ts +3 -0
  52. package/dist/components/drill/markDrillableCells.d.ts +55 -0
  53. package/dist/components/drill/resolveDrill.d.ts +139 -0
  54. package/dist/components/drill/useDrill.d.ts +63 -0
  55. package/dist/components/given/GivenInput.d.ts +52 -0
  56. package/dist/components/given/GivensPanel.d.ts +47 -0
  57. package/dist/components/given/filterValue.d.ts +97 -0
  58. package/dist/components/given/index.d.ts +2 -0
  59. package/dist/components/given/paramCodec.d.ts +60 -0
  60. package/dist/components/given/utils.d.ts +17 -0
  61. package/dist/components/highlighter.d.ts +6 -1
  62. package/dist/components/index.d.ts +7 -2
  63. package/dist/components/styles.d.ts +47 -0
  64. package/dist/constants/docLinks.d.ts +12 -0
  65. package/dist/{core-YNpOLuB1.cjs.js → core-CqRKhtoy.cjs.js} +1 -1
  66. package/dist/{core-CjeTkq8O.es.js → core-DyU47reh.es.js} +1 -1
  67. package/dist/github-dark-BKL9xNgN.cjs.js +1 -0
  68. package/dist/github-dark-DenFmJkN.es.js +4 -0
  69. package/dist/hooks/givenValue.d.ts +10 -0
  70. package/dist/hooks/index.d.ts +4 -0
  71. package/dist/hooks/useDimensionFiltersFromSpec.d.ts +3 -3
  72. package/dist/hooks/useDimensionFiltersQuery.d.ts +3 -3
  73. package/dist/hooks/useDimensionalFilterRangeData.d.ts +4 -4
  74. package/dist/hooks/useGivensState.d.ts +64 -0
  75. package/dist/hooks/useModelGivens.d.ts +10 -0
  76. package/dist/hooks/useSuggestOptions.d.ts +78 -0
  77. package/dist/{index-DRDu9kIV.es.js → index-CAkFE4Ol.es.js} +41278 -28504
  78. package/dist/index-DD4b_bt0.cjs.js +356 -0
  79. package/dist/index.cjs.js +1 -1
  80. package/dist/index.d.ts +4 -1
  81. package/dist/index.es.js +79 -48
  82. package/dist/malloy-explorer.css +12 -1
  83. package/dist/sdk.css +1 -1
  84. package/dist/theme/ThemeContext.d.ts +45 -0
  85. package/dist/theme/buildMalloyExplicitTheme.d.ts +34 -0
  86. package/dist/theme/buildTableCssVars.d.ts +41 -0
  87. package/dist/theme/buildVegaThemeOverride.d.ts +16 -0
  88. package/dist/theme/defaults.d.ts +7 -0
  89. package/dist/theme/index.d.ts +8 -0
  90. package/dist/theme/keys.d.ts +20 -0
  91. package/dist/theme/readChartAnnotations.d.ts +23 -0
  92. package/dist/theme/resolveTheme.d.ts +22 -0
  93. package/dist/theme/types.d.ts +70 -0
  94. package/dist/utils/dataAppEmbed.d.ts +44 -0
  95. package/dist/utils/formatting.d.ts +1 -1
  96. package/dist/utils/malloyString.d.ts +7 -0
  97. package/dist/utils/parsing.d.ts +2 -2
  98. package/dist/utils/queryClient.d.ts +5 -0
  99. package/package.json +19 -8
  100. package/src/client-entry.ts +3 -0
  101. package/src/components/AnalyzePackageButton.tsx +9 -3
  102. package/src/components/ApiErrorDisplay.tsx +3 -0
  103. package/src/components/Connections/AddConnectionDialog.tsx +132 -25
  104. package/src/components/Connections/DeleteConnectionDialog.tsx +14 -3
  105. package/src/components/Connections/EditConnectionDialog.tsx +167 -37
  106. package/src/components/Connections/common.ts +94 -3
  107. package/src/components/DOMElement/DOMElement.tsx +3 -0
  108. package/src/components/DOMElement/index.ts +3 -0
  109. package/src/components/Dashboard/Dashboard.spec.tsx +216 -0
  110. package/src/components/Dashboard/Dashboard.tsx +458 -0
  111. package/src/components/Dashboard/DashboardTile.spec.tsx +81 -0
  112. package/src/components/Dashboard/DashboardTile.tsx +199 -0
  113. package/src/components/Dashboard/index.ts +5 -0
  114. package/src/components/Dashboard/tileGridColumn.spec.ts +35 -0
  115. package/src/components/DataAppViewer/DataAppViewer.tsx +214 -0
  116. package/src/components/DataAppViewer/index.ts +4 -0
  117. package/src/components/{Project → Environment}/About.tsx +11 -4
  118. package/src/components/Environment/AddPackageDialog.tsx +202 -0
  119. package/src/components/{Project → Environment}/ConnectionExplorer.tsx +17 -14
  120. package/src/components/Environment/Connections.tsx +391 -0
  121. package/src/components/{Project → Environment}/DeletePackageDialog.tsx +8 -4
  122. package/src/components/{Project → Environment}/EditPackageDialog.tsx +21 -13
  123. package/src/components/Environment/Environment.tsx +89 -0
  124. package/src/components/Environment/Packages.tsx +206 -0
  125. package/src/components/Environment/index.ts +5 -0
  126. package/src/components/Home/{AddProjectDialog.tsx → AddEnvironmentDialog.tsx} +25 -19
  127. package/src/components/Home/{DeleteProjectDialog.tsx → DeleteEnvironmentDialog.tsx} +20 -15
  128. package/src/components/Home/{EditProjectDialog.tsx → EditEnvironmentDialog.tsx} +35 -28
  129. package/src/components/Home/Home.tsx +386 -408
  130. package/src/components/Home/index.ts +3 -0
  131. package/src/components/Loading.tsx +3 -0
  132. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +179 -0
  133. package/src/components/Materializations/CreateMaterializationDialog.tsx +112 -0
  134. package/src/components/Materializations/DeleteMaterializationDialog.tsx +109 -0
  135. package/src/components/Materializations/EnvironmentMaterializations.tsx +267 -0
  136. package/src/components/Materializations/ManifestView.tsx +87 -0
  137. package/src/components/Materializations/MaterializationDetailDialog.tsx +259 -0
  138. package/src/components/Materializations/MaterializationRunsList.tsx +256 -0
  139. package/src/components/Materializations/Materializations.tsx +355 -0
  140. package/src/components/Materializations/ScheduleCard.tsx +231 -0
  141. package/src/components/Materializations/SectionLabel.tsx +30 -0
  142. package/src/components/Materializations/SetScheduleDialog.tsx +162 -0
  143. package/src/components/Materializations/TriggerChip.tsx +44 -0
  144. package/src/components/Materializations/cron.ts +124 -0
  145. package/src/components/Materializations/index.ts +5 -0
  146. package/src/components/Materializations/utils.ts +145 -0
  147. package/src/components/Model/Model.tsx +44 -2
  148. package/src/components/Model/ModelCell.tsx +14 -5
  149. package/src/components/Model/ModelExplorer.tsx +3 -0
  150. package/src/components/Model/ModelExplorerDialog.tsx +4 -1
  151. package/src/components/Model/SourcesExplorer.tsx +9 -6
  152. package/src/components/Model/index.ts +3 -0
  153. package/src/components/Model/useModelData.ts +6 -3
  154. package/src/components/Notebook/Notebook.spec.tsx +88 -0
  155. package/src/components/Notebook/Notebook.tsx +476 -339
  156. package/src/components/Notebook/NotebookCell.tsx +264 -25
  157. package/src/components/Notebook/index.ts +3 -0
  158. package/src/components/Notebook/runPlan.spec.ts +155 -0
  159. package/src/components/Notebook/runPlan.ts +67 -0
  160. package/src/components/Notebook/types.ts +14 -0
  161. package/src/components/Package/ContentTypeIcon.spec.ts +91 -0
  162. package/src/components/Package/ContentTypeIcon.tsx +177 -0
  163. package/src/components/Package/FileTreeView.tsx +3 -0
  164. package/src/components/Package/Models.tsx +7 -4
  165. package/src/components/Package/Package.spec.tsx +113 -0
  166. package/src/components/Package/Package.tsx +692 -59
  167. package/src/components/Package/index.ts +3 -0
  168. package/src/components/QueryResult/QueryResult.tsx +17 -8
  169. package/src/components/QueryResult/index.ts +3 -0
  170. package/src/components/RenderedResult/RenderedResult.tsx +725 -67
  171. package/src/components/RenderedResult/ResultContainer.tsx +71 -2
  172. package/src/components/RenderedResult/index.ts +3 -0
  173. package/src/components/RenderedResult/renderLogs.spec.ts +58 -0
  174. package/src/components/RenderedResult/renderLogs.ts +43 -0
  175. package/src/components/ResultsDialog.tsx +13 -1
  176. package/src/components/ServerProvider.tsx +175 -51
  177. package/src/components/Workbook/BrowserWorkbookStorage.ts +3 -0
  178. package/src/components/Workbook/EditableMalloyCell.tsx +3 -0
  179. package/src/components/Workbook/ModelPicker.tsx +7 -4
  180. package/src/components/Workbook/MutableCell.tsx +10 -5
  181. package/src/components/Workbook/Workbook.tsx +8 -5
  182. package/src/components/Workbook/WorkbookList.tsx +3 -0
  183. package/src/components/Workbook/WorkbookManager.ts +3 -0
  184. package/src/components/Workbook/WorkbookStorage.ts +3 -0
  185. package/src/components/Workbook/WorkbookStorageProvider.tsx +3 -0
  186. package/src/components/Workbook/index.ts +3 -0
  187. package/src/components/click_helper.ts +17 -1
  188. package/src/components/drill/index.ts +28 -0
  189. package/src/components/drill/markDrillableCells.dom.spec.ts +313 -0
  190. package/src/components/drill/markDrillableCells.spec.ts +109 -0
  191. package/src/components/drill/markDrillableCells.ts +314 -0
  192. package/src/components/drill/resolveDrill.spec.ts +449 -0
  193. package/src/components/drill/resolveDrill.ts +375 -0
  194. package/src/components/drill/useDrill.tsx +203 -0
  195. package/src/components/filter/DimensionFilter.tsx +3 -0
  196. package/src/components/filter/index.ts +3 -0
  197. package/src/components/filter/utils.ts +16 -5
  198. package/src/components/given/GivenInput.spec.tsx +689 -0
  199. package/src/components/given/GivenInput.tsx +801 -0
  200. package/src/components/given/GivensPanel.spec.tsx +175 -0
  201. package/src/components/given/GivensPanel.tsx +195 -0
  202. package/src/components/given/filterValue.spec.ts +364 -0
  203. package/src/components/given/filterValue.ts +207 -0
  204. package/src/components/given/index.ts +9 -0
  205. package/src/components/given/paramCodec.spec.ts +857 -0
  206. package/src/components/given/paramCodec.ts +483 -0
  207. package/src/components/given/utils.spec.ts +60 -0
  208. package/src/components/given/utils.ts +79 -0
  209. package/src/components/highlighter.ts +22 -5
  210. package/src/components/index.ts +10 -2
  211. package/src/components/styles.ts +82 -33
  212. package/src/constants/docLinks.spec.ts +54 -0
  213. package/src/constants/docLinks.ts +46 -0
  214. package/src/hooks/givenValue.ts +13 -0
  215. package/src/hooks/index.ts +13 -0
  216. package/src/hooks/useDimensionFilters.ts +4 -7
  217. package/src/hooks/useDimensionFiltersFromSpec.ts +8 -5
  218. package/src/hooks/useDimensionFiltersQuery.ts +10 -13
  219. package/src/hooks/useDimensionalFilterRangeData.ts +11 -14
  220. package/src/hooks/useGivensState.spec.ts +449 -0
  221. package/src/hooks/useGivensState.ts +340 -0
  222. package/src/hooks/useModelGivens.ts +29 -0
  223. package/src/hooks/useQueryWithApiError.ts +3 -0
  224. package/src/hooks/useRawQueryData.ts +6 -3
  225. package/src/hooks/useSuggestOptions.dom.spec.ts +91 -0
  226. package/src/hooks/useSuggestOptions.spec.ts +112 -0
  227. package/src/hooks/useSuggestOptions.ts +268 -0
  228. package/src/index.ts +10 -1
  229. package/src/react-app-env.d.ts +3 -0
  230. package/src/theme/ThemeContext.tsx +86 -0
  231. package/src/theme/buildMalloyExplicitTheme.ts +61 -0
  232. package/src/theme/buildTableCssVars.spec.ts +86 -0
  233. package/src/theme/buildTableCssVars.ts +98 -0
  234. package/src/theme/buildVegaThemeOverride.spec.ts +56 -0
  235. package/src/theme/buildVegaThemeOverride.ts +47 -0
  236. package/src/theme/defaults.ts +78 -0
  237. package/src/theme/index.ts +11 -0
  238. package/src/theme/keys.ts +32 -0
  239. package/src/theme/readChartAnnotations.spec.ts +58 -0
  240. package/src/theme/readChartAnnotations.ts +69 -0
  241. package/src/theme/resolveTheme.spec.ts +160 -0
  242. package/src/theme/resolveTheme.ts +121 -0
  243. package/src/theme/types.ts +79 -0
  244. package/src/utils/dataAppEmbed.spec.ts +63 -0
  245. package/src/utils/dataAppEmbed.ts +84 -0
  246. package/src/utils/formatting.spec.ts +25 -21
  247. package/src/utils/formatting.ts +11 -7
  248. package/src/utils/malloyString.spec.ts +24 -0
  249. package/src/utils/malloyString.ts +12 -0
  250. package/src/utils/parsing.spec.ts +26 -19
  251. package/src/utils/parsing.ts +11 -6
  252. package/src/utils/queryClient.ts +17 -0
  253. package/test/README.md +185 -0
  254. package/test/serverProvider.tsx +72 -0
  255. package/test/setup.ts +29 -0
  256. package/tsconfig.json +12 -1
  257. package/tsconfig.spec.json +22 -0
  258. package/vite.config.ts +3 -0
  259. package/dist/ServerProvider-lOQXDlqB.cjs.js +0 -1
  260. package/dist/ServerProvider-on-8FH5Z.es.js +0 -3060
  261. package/dist/components/Home/AddProjectDialog.d.ts +0 -1
  262. package/dist/components/Home/DeleteProjectDialog.d.ts +0 -5
  263. package/dist/components/Home/EditProjectDialog.d.ts +0 -7
  264. package/dist/components/Package/Config.d.ts +0 -5
  265. package/dist/components/Package/Databases.d.ts +0 -5
  266. package/dist/components/Package/Notebooks.d.ts +0 -6
  267. package/dist/components/Project/Project.d.ts +0 -6
  268. package/dist/components/Project/index.d.ts +0 -2
  269. package/dist/index-BOLBP6_i.cjs.js +0 -233
  270. package/src/components/Package/Config.tsx +0 -97
  271. package/src/components/Package/Connections.tsx +0 -373
  272. package/src/components/Package/Databases.tsx +0 -228
  273. package/src/components/Package/Notebooks.tsx +0 -77
  274. package/src/components/Project/AddPackageDialog.tsx +0 -159
  275. package/src/components/Project/Packages.tsx +0 -191
  276. package/src/components/Project/Project.tsx +0 -52
  277. package/src/components/Project/index.ts +0 -2
  278. /package/dist/components/{Project → Environment}/About.d.ts +0 -0
  279. /package/dist/components/{Project → Environment}/AddPackageDialog.d.ts +0 -0
  280. /package/dist/components/{Project → Environment}/ConnectionExplorer.d.ts +0 -0
  281. /package/dist/components/{Package → Environment}/Connections.d.ts +0 -0
  282. /package/dist/components/{Project → Environment}/DeletePackageDialog.d.ts +0 -0
  283. /package/dist/components/{Project → Environment}/EditPackageDialog.d.ts +0 -0
  284. /package/dist/components/{Project → Environment}/Packages.d.ts +0 -0
@@ -1 +1,4 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  export { default as Home } from "./Home";
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { Box, CircularProgress, Typography } from "@mui/material";
2
5
 
3
6
  export interface LoadingProps {
@@ -0,0 +1,179 @@
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
+ }
@@ -0,0 +1,112 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import AddIcon from "@mui/icons-material/Add";
5
+ import {
6
+ Button,
7
+ Dialog,
8
+ DialogActions,
9
+ DialogContent,
10
+ DialogContentText,
11
+ DialogTitle,
12
+ FormControlLabel,
13
+ FormGroup,
14
+ Switch,
15
+ Tooltip,
16
+ } from "@mui/material";
17
+ import { useState } from "react";
18
+
19
+ type CreateMaterializationDialogProps = {
20
+ onSubmit: (opts: { forceRefresh: boolean }) => Promise<unknown>;
21
+ isSubmitting: boolean;
22
+ disabled?: boolean;
23
+ disabledReason?: string;
24
+ };
25
+
26
+ export default function CreateMaterializationDialog({
27
+ onSubmit,
28
+ isSubmitting,
29
+ disabled,
30
+ disabledReason,
31
+ }: CreateMaterializationDialogProps) {
32
+ const [open, setOpen] = useState(false);
33
+ const [forceRefresh, setForceRefresh] = useState(false);
34
+
35
+ const handleClose = () => setOpen(false);
36
+
37
+ const handleRun = async () => {
38
+ try {
39
+ await onSubmit({ forceRefresh });
40
+ setOpen(false);
41
+ } catch {
42
+ // The mutation surfaces the error through the caller's Snackbar;
43
+ // keep the dialog open so the user can retry or cancel.
44
+ }
45
+ };
46
+
47
+ const button = (
48
+ <span>
49
+ <Button
50
+ variant="contained"
51
+ startIcon={<AddIcon />}
52
+ onClick={() => setOpen(true)}
53
+ disabled={disabled}
54
+ aria-label="New materialization"
55
+ >
56
+ New materialization
57
+ </Button>
58
+ </span>
59
+ );
60
+
61
+ return (
62
+ <>
63
+ {disabled && disabledReason ? (
64
+ <Tooltip title={disabledReason}>{button}</Tooltip>
65
+ ) : (
66
+ button
67
+ )}
68
+
69
+ <Dialog
70
+ open={open}
71
+ onClose={handleClose}
72
+ maxWidth="xs"
73
+ fullWidth
74
+ aria-labelledby="create-materialization-title"
75
+ >
76
+ <DialogTitle id="create-materialization-title">
77
+ New materialization
78
+ </DialogTitle>
79
+ <DialogContent>
80
+ <DialogContentText sx={{ mb: 2 }}>
81
+ Materialize every persist source in this package: compile,
82
+ build the tables, and load them so queries serve from the
83
+ materialized tables.
84
+ </DialogContentText>
85
+ <FormGroup>
86
+ <FormControlLabel
87
+ control={
88
+ <Switch
89
+ checked={forceRefresh}
90
+ onChange={(event) =>
91
+ setForceRefresh(event.target.checked)
92
+ }
93
+ />
94
+ }
95
+ label="Force refresh (rebuild even if unchanged)"
96
+ />
97
+ </FormGroup>
98
+ </DialogContent>
99
+ <DialogActions>
100
+ <Button onClick={handleClose}>Cancel</Button>
101
+ <Button
102
+ variant="contained"
103
+ loading={isSubmitting}
104
+ onClick={handleRun}
105
+ >
106
+ Materialize
107
+ </Button>
108
+ </DialogActions>
109
+ </Dialog>
110
+ </>
111
+ );
112
+ }
@@ -0,0 +1,109 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Delete } from "@mui/icons-material";
5
+ import CloseIcon from "@mui/icons-material/Close";
6
+ import Button from "@mui/material/Button";
7
+ import Checkbox from "@mui/material/Checkbox";
8
+ import Dialog from "@mui/material/Dialog";
9
+ import DialogActions from "@mui/material/DialogActions";
10
+ import DialogContent from "@mui/material/DialogContent";
11
+ import DialogTitle from "@mui/material/DialogTitle";
12
+ import FormControlLabel from "@mui/material/FormControlLabel";
13
+ import IconButton from "@mui/material/IconButton";
14
+ import ListItemIcon from "@mui/material/ListItemIcon";
15
+ import ListItemText from "@mui/material/ListItemText";
16
+ import MenuItem from "@mui/material/MenuItem";
17
+ import Typography from "@mui/material/Typography";
18
+ import React, { useState } from "react";
19
+ import { Materialization } from "../../client";
20
+
21
+ export default function DeleteMaterializationDialog({
22
+ materialization,
23
+ onCloseDialog,
24
+ isMutating,
25
+ onDelete,
26
+ }: {
27
+ materialization: Materialization;
28
+ onCloseDialog: () => void;
29
+ isMutating: boolean;
30
+ onDelete: (dropTables: boolean) => void;
31
+ }) {
32
+ const [open, setOpen] = useState(false);
33
+ const [dropTables, setDropTables] = useState(false);
34
+
35
+ const handleClickOpen = () => setOpen(true);
36
+ const handleClose = () => {
37
+ setOpen(false);
38
+ setDropTables(false);
39
+ onCloseDialog();
40
+ };
41
+
42
+ return (
43
+ <React.Fragment>
44
+ <MenuItem
45
+ aria-label={`Delete materialization ${materialization?.id ?? ""}`.trim()}
46
+ onClick={(event) => {
47
+ event.stopPropagation();
48
+ handleClickOpen();
49
+ }}
50
+ sx={{ color: "error.main" }}
51
+ >
52
+ <ListItemIcon sx={{ color: "inherit" }}>
53
+ <Delete fontSize="small" />
54
+ </ListItemIcon>
55
+ <ListItemText>Delete</ListItemText>
56
+ </MenuItem>
57
+
58
+ <Dialog
59
+ onClose={handleClose}
60
+ open={open}
61
+ aria-labelledby="delete-materialization-title"
62
+ >
63
+ <DialogTitle sx={{ m: 0, p: 2 }} id="delete-materialization-title">
64
+ Delete Materialization
65
+ </DialogTitle>
66
+ <IconButton
67
+ aria-label="close"
68
+ onClick={handleClose}
69
+ sx={(theme) => ({
70
+ position: "absolute",
71
+ right: 8,
72
+ top: 8,
73
+ color: theme.palette.grey[500],
74
+ })}
75
+ >
76
+ <CloseIcon />
77
+ </IconButton>
78
+ <DialogContent dividers>
79
+ <Typography gutterBottom>
80
+ Are you sure you want to delete this materialization record?
81
+ This action cannot be undone.
82
+ </Typography>
83
+ <FormControlLabel
84
+ control={
85
+ <Checkbox
86
+ checked={dropTables}
87
+ onChange={(event) =>
88
+ setDropTables(event.target.checked)
89
+ }
90
+ />
91
+ }
92
+ label="Also drop the materialized table(s) this run produced"
93
+ />
94
+ </DialogContent>
95
+ <DialogActions>
96
+ <Button
97
+ loading={isMutating}
98
+ variant="contained"
99
+ autoFocus
100
+ onClick={() => onDelete(dropTables)}
101
+ color="error"
102
+ >
103
+ Delete
104
+ </Button>
105
+ </DialogActions>
106
+ </Dialog>
107
+ </React.Fragment>
108
+ );
109
+ }
@@ -0,0 +1,267 @@
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
+ }