@malloy-publisher/sdk 0.0.382-dev → 0.2.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 (277) 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-CTopDUWW.cjs.js +1 -0
  5. package/dist/ServerProvider-DUFPY6Rv.es.js +4072 -0
  6. package/dist/client/api.d.ts +3718 -1507
  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 +85 -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 +49 -0
  14. package/dist/components/Dashboard/DashboardTile.d.ts +48 -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-hLahnv0W.cjs.js} +1 -1
  66. package/dist/{core-CjeTkq8O.es.js → core-lb28vQkR.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-DvEanVgc.cjs.js +339 -0
  78. package/dist/{index-DRDu9kIV.es.js → index-txw04ZbN.es.js} +40531 -27964
  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 +25 -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 +30 -2
  104. package/src/components/Connections/DeleteConnectionDialog.tsx +14 -3
  105. package/src/components/Connections/EditConnectionDialog.tsx +33 -4
  106. package/src/components/Connections/common.ts +64 -1
  107. package/src/components/DOMElement/DOMElement.tsx +3 -0
  108. package/src/components/DOMElement/index.ts +3 -0
  109. package/src/components/Dashboard/Dashboard.tsx +398 -0
  110. package/src/components/Dashboard/DashboardTile.tsx +153 -0
  111. package/src/components/Dashboard/index.ts +5 -0
  112. package/src/components/DataAppViewer/DataAppViewer.tsx +214 -0
  113. package/src/components/DataAppViewer/index.ts +4 -0
  114. package/src/components/{Project → Environment}/About.tsx +11 -4
  115. package/src/components/Environment/AddPackageDialog.tsx +202 -0
  116. package/src/components/{Project → Environment}/ConnectionExplorer.tsx +17 -14
  117. package/src/components/Environment/Connections.tsx +391 -0
  118. package/src/components/{Project → Environment}/DeletePackageDialog.tsx +8 -4
  119. package/src/components/{Project → Environment}/EditPackageDialog.tsx +21 -13
  120. package/src/components/Environment/Environment.tsx +89 -0
  121. package/src/components/Environment/Packages.tsx +206 -0
  122. package/src/components/Environment/index.ts +5 -0
  123. package/src/components/Home/{AddProjectDialog.tsx → AddEnvironmentDialog.tsx} +25 -19
  124. package/src/components/Home/{DeleteProjectDialog.tsx → DeleteEnvironmentDialog.tsx} +20 -15
  125. package/src/components/Home/{EditProjectDialog.tsx → EditEnvironmentDialog.tsx} +35 -28
  126. package/src/components/Home/Home.tsx +386 -408
  127. package/src/components/Home/index.ts +3 -0
  128. package/src/components/Loading.tsx +3 -0
  129. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +179 -0
  130. package/src/components/Materializations/CreateMaterializationDialog.tsx +112 -0
  131. package/src/components/Materializations/DeleteMaterializationDialog.tsx +109 -0
  132. package/src/components/Materializations/EnvironmentMaterializations.tsx +267 -0
  133. package/src/components/Materializations/ManifestView.tsx +87 -0
  134. package/src/components/Materializations/MaterializationDetailDialog.tsx +259 -0
  135. package/src/components/Materializations/MaterializationRunsList.tsx +256 -0
  136. package/src/components/Materializations/Materializations.tsx +355 -0
  137. package/src/components/Materializations/ScheduleCard.tsx +231 -0
  138. package/src/components/Materializations/SectionLabel.tsx +30 -0
  139. package/src/components/Materializations/SetScheduleDialog.tsx +162 -0
  140. package/src/components/Materializations/TriggerChip.tsx +44 -0
  141. package/src/components/Materializations/cron.ts +124 -0
  142. package/src/components/Materializations/index.ts +5 -0
  143. package/src/components/Materializations/utils.ts +145 -0
  144. package/src/components/Model/Model.tsx +44 -2
  145. package/src/components/Model/ModelCell.tsx +14 -5
  146. package/src/components/Model/ModelExplorer.tsx +3 -0
  147. package/src/components/Model/ModelExplorerDialog.tsx +4 -1
  148. package/src/components/Model/SourcesExplorer.tsx +9 -6
  149. package/src/components/Model/index.ts +3 -0
  150. package/src/components/Model/useModelData.ts +6 -3
  151. package/src/components/Notebook/Notebook.tsx +475 -339
  152. package/src/components/Notebook/NotebookCell.tsx +264 -25
  153. package/src/components/Notebook/index.ts +3 -0
  154. package/src/components/Notebook/runPlan.spec.ts +155 -0
  155. package/src/components/Notebook/runPlan.ts +67 -0
  156. package/src/components/Notebook/types.ts +14 -0
  157. package/src/components/Package/ContentTypeIcon.spec.ts +91 -0
  158. package/src/components/Package/ContentTypeIcon.tsx +177 -0
  159. package/src/components/Package/FileTreeView.tsx +3 -0
  160. package/src/components/Package/Models.tsx +7 -4
  161. package/src/components/Package/Package.tsx +666 -59
  162. package/src/components/Package/index.ts +3 -0
  163. package/src/components/QueryResult/QueryResult.tsx +17 -8
  164. package/src/components/QueryResult/index.ts +3 -0
  165. package/src/components/RenderedResult/RenderedResult.tsx +685 -67
  166. package/src/components/RenderedResult/ResultContainer.tsx +71 -2
  167. package/src/components/RenderedResult/index.ts +3 -0
  168. package/src/components/RenderedResult/renderLogs.spec.ts +58 -0
  169. package/src/components/RenderedResult/renderLogs.ts +43 -0
  170. package/src/components/ResultsDialog.tsx +13 -1
  171. package/src/components/ServerProvider.tsx +175 -51
  172. package/src/components/Workbook/BrowserWorkbookStorage.ts +3 -0
  173. package/src/components/Workbook/EditableMalloyCell.tsx +3 -0
  174. package/src/components/Workbook/ModelPicker.tsx +7 -4
  175. package/src/components/Workbook/MutableCell.tsx +10 -5
  176. package/src/components/Workbook/Workbook.tsx +8 -5
  177. package/src/components/Workbook/WorkbookList.tsx +3 -0
  178. package/src/components/Workbook/WorkbookManager.ts +3 -0
  179. package/src/components/Workbook/WorkbookStorage.ts +3 -0
  180. package/src/components/Workbook/WorkbookStorageProvider.tsx +3 -0
  181. package/src/components/Workbook/index.ts +3 -0
  182. package/src/components/click_helper.ts +17 -1
  183. package/src/components/drill/index.ts +28 -0
  184. package/src/components/drill/markDrillableCells.dom.spec.ts +313 -0
  185. package/src/components/drill/markDrillableCells.spec.ts +109 -0
  186. package/src/components/drill/markDrillableCells.ts +314 -0
  187. package/src/components/drill/resolveDrill.spec.ts +449 -0
  188. package/src/components/drill/resolveDrill.ts +375 -0
  189. package/src/components/drill/useDrill.tsx +203 -0
  190. package/src/components/filter/DimensionFilter.tsx +3 -0
  191. package/src/components/filter/index.ts +3 -0
  192. package/src/components/filter/utils.ts +16 -5
  193. package/src/components/given/GivenInput.spec.tsx +689 -0
  194. package/src/components/given/GivenInput.tsx +801 -0
  195. package/src/components/given/GivensPanel.spec.tsx +175 -0
  196. package/src/components/given/GivensPanel.tsx +195 -0
  197. package/src/components/given/filterValue.spec.ts +364 -0
  198. package/src/components/given/filterValue.ts +207 -0
  199. package/src/components/given/index.ts +9 -0
  200. package/src/components/given/paramCodec.spec.ts +857 -0
  201. package/src/components/given/paramCodec.ts +483 -0
  202. package/src/components/given/utils.spec.ts +60 -0
  203. package/src/components/given/utils.ts +79 -0
  204. package/src/components/highlighter.ts +22 -5
  205. package/src/components/index.ts +10 -2
  206. package/src/components/styles.ts +82 -33
  207. package/src/constants/docLinks.spec.ts +54 -0
  208. package/src/constants/docLinks.ts +46 -0
  209. package/src/hooks/givenValue.ts +13 -0
  210. package/src/hooks/index.ts +13 -0
  211. package/src/hooks/useDimensionFilters.ts +4 -7
  212. package/src/hooks/useDimensionFiltersFromSpec.ts +8 -5
  213. package/src/hooks/useDimensionFiltersQuery.ts +10 -13
  214. package/src/hooks/useDimensionalFilterRangeData.ts +11 -14
  215. package/src/hooks/useGivensState.spec.ts +449 -0
  216. package/src/hooks/useGivensState.ts +340 -0
  217. package/src/hooks/useModelGivens.ts +29 -0
  218. package/src/hooks/useQueryWithApiError.ts +3 -0
  219. package/src/hooks/useRawQueryData.ts +6 -3
  220. package/src/hooks/useSuggestOptions.spec.ts +112 -0
  221. package/src/hooks/useSuggestOptions.ts +263 -0
  222. package/src/index.ts +10 -1
  223. package/src/react-app-env.d.ts +3 -0
  224. package/src/theme/ThemeContext.tsx +86 -0
  225. package/src/theme/buildMalloyExplicitTheme.ts +61 -0
  226. package/src/theme/buildTableCssVars.spec.ts +67 -0
  227. package/src/theme/buildTableCssVars.ts +67 -0
  228. package/src/theme/buildVegaThemeOverride.spec.ts +56 -0
  229. package/src/theme/buildVegaThemeOverride.ts +47 -0
  230. package/src/theme/defaults.ts +78 -0
  231. package/src/theme/index.ts +11 -0
  232. package/src/theme/keys.ts +32 -0
  233. package/src/theme/readChartAnnotations.spec.ts +58 -0
  234. package/src/theme/readChartAnnotations.ts +69 -0
  235. package/src/theme/resolveTheme.spec.ts +160 -0
  236. package/src/theme/resolveTheme.ts +121 -0
  237. package/src/theme/types.ts +79 -0
  238. package/src/utils/dataAppEmbed.spec.ts +63 -0
  239. package/src/utils/dataAppEmbed.ts +84 -0
  240. package/src/utils/formatting.spec.ts +25 -21
  241. package/src/utils/formatting.ts +11 -7
  242. package/src/utils/malloyString.spec.ts +24 -0
  243. package/src/utils/malloyString.ts +12 -0
  244. package/src/utils/parsing.spec.ts +26 -19
  245. package/src/utils/parsing.ts +11 -6
  246. package/src/utils/queryClient.ts +17 -0
  247. package/test/README.md +141 -0
  248. package/test/setup.ts +29 -0
  249. package/tsconfig.json +12 -1
  250. package/tsconfig.spec.json +22 -0
  251. package/vite.config.ts +3 -0
  252. package/dist/ServerProvider-lOQXDlqB.cjs.js +0 -1
  253. package/dist/ServerProvider-on-8FH5Z.es.js +0 -3060
  254. package/dist/components/Home/AddProjectDialog.d.ts +0 -1
  255. package/dist/components/Home/DeleteProjectDialog.d.ts +0 -5
  256. package/dist/components/Home/EditProjectDialog.d.ts +0 -7
  257. package/dist/components/Package/Config.d.ts +0 -5
  258. package/dist/components/Package/Databases.d.ts +0 -5
  259. package/dist/components/Package/Notebooks.d.ts +0 -6
  260. package/dist/components/Project/Project.d.ts +0 -6
  261. package/dist/components/Project/index.d.ts +0 -2
  262. package/dist/index-BOLBP6_i.cjs.js +0 -233
  263. package/src/components/Package/Config.tsx +0 -97
  264. package/src/components/Package/Connections.tsx +0 -373
  265. package/src/components/Package/Databases.tsx +0 -228
  266. package/src/components/Package/Notebooks.tsx +0 -77
  267. package/src/components/Project/AddPackageDialog.tsx +0 -159
  268. package/src/components/Project/Packages.tsx +0 -191
  269. package/src/components/Project/Project.tsx +0 -52
  270. package/src/components/Project/index.ts +0 -2
  271. /package/dist/components/{Project → Environment}/About.d.ts +0 -0
  272. /package/dist/components/{Project → Environment}/AddPackageDialog.d.ts +0 -0
  273. /package/dist/components/{Project → Environment}/ConnectionExplorer.d.ts +0 -0
  274. /package/dist/components/{Package → Environment}/Connections.d.ts +0 -0
  275. /package/dist/components/{Project → Environment}/DeletePackageDialog.d.ts +0 -0
  276. /package/dist/components/{Project → Environment}/EditPackageDialog.d.ts +0 -0
  277. /package/dist/components/{Project → Environment}/Packages.d.ts +0 -0
@@ -0,0 +1,355 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import ArrowBackIcon from "@mui/icons-material/ArrowBack";
5
+ import {
6
+ Box,
7
+ Container,
8
+ Link,
9
+ Snackbar,
10
+ Stack,
11
+ Typography,
12
+ } from "@mui/material";
13
+ import { useQueryClient } from "@tanstack/react-query";
14
+ import React, { useState } from "react";
15
+ import {
16
+ Materialization,
17
+ MaterializationActionActionEnum,
18
+ PackageScopeEnum,
19
+ } from "../../client";
20
+ import {
21
+ useMutationWithApiError,
22
+ useQueryWithApiError,
23
+ } from "../../hooks/useQueryWithApiError";
24
+ import { parseResourceUri } from "../../utils/formatting";
25
+ import { ApiErrorDisplay } from "../ApiErrorDisplay";
26
+ import { Loading } from "../Loading";
27
+ import { useServer } from "../ServerProvider";
28
+ import CreateMaterializationDialog from "./CreateMaterializationDialog";
29
+ import MaterializationDetailDialog from "./MaterializationDetailDialog";
30
+ import MaterializationRunsList from "./MaterializationRunsList";
31
+ import ScheduleCard from "./ScheduleCard";
32
+ import { isActiveStatus } from "./utils";
33
+
34
+ const MATERIALIZATION_POLL_MS = 3000;
35
+
36
+ interface MaterializationsProps {
37
+ resourceUri: string;
38
+ onClickPackageFile?: (to: string, event?: React.MouseEvent) => void;
39
+ }
40
+
41
+ export default function Materializations({
42
+ resourceUri,
43
+ onClickPackageFile,
44
+ }: MaterializationsProps) {
45
+ const { apiClients, mutable } = useServer();
46
+ const queryClient = useQueryClient();
47
+ const { environmentName, packageName } = parseResourceUri(resourceUri);
48
+ const [notificationMessage, setNotificationMessage] = useState("");
49
+ const [selectedId, setSelectedId] = useState<string | null>(null);
50
+
51
+ const onClick =
52
+ onClickPackageFile ??
53
+ ((to: string) => {
54
+ window.location.href = to;
55
+ });
56
+
57
+ if (!packageName) {
58
+ throw new Error(
59
+ "Materializations requires a package in the resource URI",
60
+ );
61
+ }
62
+
63
+ const listQuery = useQueryWithApiError({
64
+ queryKey: ["materializations", environmentName, packageName],
65
+ queryFn: () =>
66
+ apiClients.materializations.listMaterializations(
67
+ environmentName,
68
+ packageName,
69
+ ),
70
+ refetchInterval: (query) => {
71
+ const payload = query.state.data as
72
+ | { data?: Materialization[] }
73
+ | undefined;
74
+ const rows = payload?.data ?? [];
75
+ return rows.some((row) => isActiveStatus(row.status))
76
+ ? MATERIALIZATION_POLL_MS
77
+ : false;
78
+ },
79
+ });
80
+
81
+ // The build plan is a property of the compiled package (Package.buildPlan),
82
+ // not of a historical run, so fetch it from the package for the detail view.
83
+ const packageQuery = useQueryWithApiError({
84
+ queryKey: ["package", environmentName, packageName],
85
+ queryFn: () =>
86
+ apiClients.packages.getPackage(environmentName, packageName),
87
+ });
88
+
89
+ const invalidateList = () =>
90
+ queryClient.invalidateQueries({
91
+ queryKey: ["materializations", environmentName, packageName],
92
+ });
93
+
94
+ // Auto-run: the publisher compiles, builds every persist source, and loads
95
+ // the resulting manifest in a single pass.
96
+ const createMaterialization = useMutationWithApiError({
97
+ mutationFn: (opts: { forceRefresh: boolean }) =>
98
+ apiClients.materializations.createMaterialization(
99
+ environmentName,
100
+ packageName,
101
+ {
102
+ forceRefresh: opts.forceRefresh,
103
+ },
104
+ ),
105
+ onSuccess() {
106
+ setNotificationMessage("Materialization requested");
107
+ invalidateList();
108
+ },
109
+ onError(error) {
110
+ setNotificationMessage(error.message);
111
+ invalidateList();
112
+ },
113
+ });
114
+
115
+ const stopMaterialization = useMutationWithApiError({
116
+ mutationFn: (materialization: Materialization) =>
117
+ apiClients.materializations.materializationAction(
118
+ environmentName,
119
+ packageName,
120
+ materialization.id as string,
121
+ MaterializationActionActionEnum.Stop,
122
+ ),
123
+ onSuccess() {
124
+ setNotificationMessage("Materialization stopped");
125
+ invalidateList();
126
+ },
127
+ onError(error) {
128
+ setNotificationMessage(error.message);
129
+ },
130
+ });
131
+
132
+ const deleteMaterialization = useMutationWithApiError({
133
+ mutationFn: ({
134
+ materialization,
135
+ dropTables,
136
+ }: {
137
+ materialization: Materialization;
138
+ dropTables: boolean;
139
+ }) =>
140
+ apiClients.materializations.deleteMaterialization(
141
+ environmentName,
142
+ packageName,
143
+ materialization.id as string,
144
+ dropTables,
145
+ ),
146
+ onSuccess() {
147
+ setNotificationMessage("Materialization deleted");
148
+ invalidateList();
149
+ },
150
+ onError(error) {
151
+ setNotificationMessage(error.message);
152
+ },
153
+ });
154
+
155
+ const currentPackage = packageQuery.data?.data;
156
+
157
+ // Edit the package's materialization.schedule (persisted to publisher.json).
158
+ // A schedule is legal only on a version-scoped package, so enabling one also
159
+ // sets scope: version; clearing (null) leaves scope untouched — scope is an
160
+ // explicit control (updateScope below), so clearing a schedule no longer
161
+ // strands scope: version with no way back. The running scheduler re-arms from
162
+ // the new cron on its next tick — no reload needed.
163
+ const updateSchedule = useMutationWithApiError({
164
+ mutationFn: (schedule: string | null) =>
165
+ apiClients.packages.updatePackage(environmentName, packageName, {
166
+ name: packageName,
167
+ // updatePackage overwrites description from the body — carry the
168
+ // current value through so a schedule edit doesn't drop it.
169
+ description: currentPackage?.description,
170
+ ...(schedule ? { scope: PackageScopeEnum.Version } : {}),
171
+ materialization: { schedule },
172
+ }),
173
+ onSuccess(_data, schedule) {
174
+ setNotificationMessage(
175
+ schedule ? "Schedule updated" : "Schedule cleared",
176
+ );
177
+ queryClient.invalidateQueries({
178
+ queryKey: ["package", environmentName, packageName],
179
+ });
180
+ },
181
+ onError(error) {
182
+ setNotificationMessage(error.message);
183
+ },
184
+ });
185
+
186
+ // Set the persist scope explicitly (package | version). Independent of the
187
+ // schedule so the version flip a schedule requires can be undone after the
188
+ // schedule is cleared. The server rejects scope: package while a schedule is
189
+ // still set (publish-gate Rule 2), so the UI only offers this when no
190
+ // schedule is active.
191
+ const updateScope = useMutationWithApiError({
192
+ mutationFn: (scope: PackageScopeEnum) =>
193
+ apiClients.packages.updatePackage(environmentName, packageName, {
194
+ name: packageName,
195
+ description: currentPackage?.description,
196
+ scope,
197
+ }),
198
+ onSuccess() {
199
+ setNotificationMessage("Scope updated");
200
+ queryClient.invalidateQueries({
201
+ queryKey: ["package", environmentName, packageName],
202
+ });
203
+ },
204
+ onError(error) {
205
+ setNotificationMessage(error.message);
206
+ },
207
+ });
208
+
209
+ const materializations = (listQuery.data?.data ?? []) as Materialization[];
210
+ const selected =
211
+ materializations.find((row) => row.id === selectedId) ?? null;
212
+ const hasActive = materializations.some((row) => isActiveStatus(row.status));
213
+ const isMutating =
214
+ createMaterialization.isPending ||
215
+ stopMaterialization.isPending ||
216
+ deleteMaterialization.isPending;
217
+
218
+ return (
219
+ <Container
220
+ maxWidth={false}
221
+ sx={{ maxWidth: 1024, mx: "auto", px: 3, py: 6 }}
222
+ >
223
+ <Box sx={{ mb: 4 }}>
224
+ <Link
225
+ onClick={(event: React.MouseEvent) =>
226
+ onClick(`/${environmentName}/${packageName}`, event)
227
+ }
228
+ underline="none"
229
+ sx={{
230
+ display: "inline-flex",
231
+ alignItems: "center",
232
+ gap: 0.5,
233
+ cursor: "pointer",
234
+ color: "text.secondary",
235
+ fontSize: "0.875rem",
236
+ mb: 2,
237
+ "&:hover": { color: "primary.main" },
238
+ }}
239
+ >
240
+ <ArrowBackIcon sx={{ fontSize: 18 }} />
241
+ Back to {packageName}
242
+ </Link>
243
+ <Stack
244
+ direction="row"
245
+ alignItems="flex-start"
246
+ justifyContent="space-between"
247
+ >
248
+ <Box>
249
+ <Typography
250
+ variant="h4"
251
+ component="h1"
252
+ sx={{
253
+ fontWeight: 600,
254
+ letterSpacing: "-0.025em",
255
+ mb: 0.5,
256
+ }}
257
+ >
258
+ Materializations
259
+ </Typography>
260
+ <Typography variant="body2" color="text.secondary">
261
+ Materialize the persist sources in {packageName} into
262
+ tables and serve queries from them
263
+ </Typography>
264
+ </Box>
265
+ {mutable && (
266
+ <CreateMaterializationDialog
267
+ onSubmit={(opts) =>
268
+ createMaterialization.mutateAsync(opts)
269
+ }
270
+ isSubmitting={createMaterialization.isPending}
271
+ disabled={hasActive}
272
+ disabledReason="A materialization is already pending or running for this package."
273
+ />
274
+ )}
275
+ </Stack>
276
+ </Box>
277
+
278
+ {packageQuery.isSuccess && (
279
+ <ScheduleCard
280
+ schedule={currentPackage?.materialization?.schedule ?? null}
281
+ scope={
282
+ currentPackage?.scope === PackageScopeEnum.Version
283
+ ? "version"
284
+ : "package"
285
+ }
286
+ manifestLocation={currentPackage?.manifestLocation ?? null}
287
+ hasFreshness={Boolean(
288
+ currentPackage?.materialization?.freshness,
289
+ )}
290
+ mutable={mutable}
291
+ isSubmitting={updateSchedule.isPending}
292
+ isScopeMutating={updateScope.isPending}
293
+ onSubmit={(schedule) => updateSchedule.mutateAsync(schedule)}
294
+ onScopeChange={(scope) =>
295
+ updateScope.mutateAsync(
296
+ scope === "version"
297
+ ? PackageScopeEnum.Version
298
+ : PackageScopeEnum.Package,
299
+ )
300
+ }
301
+ />
302
+ )}
303
+
304
+ <Box sx={{ mb: 6 }}>
305
+ <Typography
306
+ variant="h6"
307
+ sx={{ fontWeight: 600, letterSpacing: "-0.025em", mb: 1 }}
308
+ >
309
+ Runs
310
+ </Typography>
311
+ {listQuery.isError && (
312
+ <ApiErrorDisplay
313
+ error={listQuery.error}
314
+ context={`${environmentName} > ${packageName} > Materializations`}
315
+ />
316
+ )}
317
+ {!listQuery.isSuccess && !listQuery.isError && (
318
+ <Loading text="Loading materializations..." />
319
+ )}
320
+ {listQuery.isSuccess && (
321
+ <MaterializationRunsList
322
+ materializations={materializations}
323
+ mutable={mutable}
324
+ isMutating={isMutating}
325
+ onStop={(materialization) =>
326
+ stopMaterialization.mutate(materialization)
327
+ }
328
+ onDelete={(materialization, dropTables) =>
329
+ deleteMaterialization.mutate({
330
+ materialization,
331
+ dropTables,
332
+ })
333
+ }
334
+ onViewDetails={(materialization) =>
335
+ setSelectedId(materialization.id ?? null)
336
+ }
337
+ />
338
+ )}
339
+ </Box>
340
+
341
+ <MaterializationDetailDialog
342
+ materialization={selected}
343
+ buildPlan={packageQuery.data?.data?.buildPlan ?? null}
344
+ onClose={() => setSelectedId(null)}
345
+ />
346
+
347
+ <Snackbar
348
+ open={notificationMessage !== ""}
349
+ autoHideDuration={6000}
350
+ onClose={() => setNotificationMessage("")}
351
+ message={notificationMessage}
352
+ />
353
+ </Container>
354
+ );
355
+ }
@@ -0,0 +1,231 @@
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
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Typography } from "@mui/material";
5
+ import { ReactNode } from "react";
6
+
7
+ /**
8
+ * Small uppercase section heading for consistent hierarchy across the
9
+ * materialization views (detail dialog, manifest view). One source of truth for
10
+ * the style so the headings can't drift. Renders as an <h6> so it is a real
11
+ * heading (role="heading") — the caption styling is purely visual.
12
+ */
13
+ export default function SectionLabel({ children }: { children: ReactNode }) {
14
+ return (
15
+ <Typography
16
+ variant="caption"
17
+ component="h6"
18
+ sx={{
19
+ display: "block",
20
+ textTransform: "uppercase",
21
+ letterSpacing: "0.06em",
22
+ fontWeight: 600,
23
+ color: "text.secondary",
24
+ mb: 1,
25
+ }}
26
+ >
27
+ {children}
28
+ </Typography>
29
+ );
30
+ }