@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,97 +0,0 @@
1
- import ErrorIcon from "@mui/icons-material/ErrorOutlined";
2
- import { Box, List, ListItem, ListItemText } from "@mui/material";
3
- import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
4
- import { ApiErrorDisplay } from "../ApiErrorDisplay";
5
- import { Loading } from "../Loading";
6
- import {
7
- PackageCard,
8
- PackageCardContent,
9
- PackageSectionTitle,
10
- } from "../styles";
11
- import { parseResourceUri } from "../../utils/formatting";
12
- import { useServer } from "../ServerProvider";
13
-
14
- type Props = {
15
- resourceUri: string;
16
- };
17
-
18
- export default function Config({ resourceUri }: Props) {
19
- const { apiClients } = useServer();
20
- const {
21
- projectName: projectName,
22
- packageName: packageName,
23
- versionId: versionId,
24
- } = parseResourceUri(resourceUri);
25
-
26
- const { data, isSuccess, isError, error } = useQueryWithApiError({
27
- queryKey: ["package", projectName, packageName, versionId],
28
- queryFn: () =>
29
- apiClients.packages.getPackage(
30
- projectName,
31
- packageName,
32
- versionId,
33
- false,
34
- ),
35
- });
36
-
37
- return (
38
- <PackageCard>
39
- <PackageCardContent>
40
- <PackageSectionTitle>Package Config</PackageSectionTitle>
41
- <Box
42
- sx={{
43
- maxHeight: "200px",
44
- overflowY: "auto",
45
- }}
46
- >
47
- <List dense={true} disablePadding={true}>
48
- <ListItem dense={true} disablePadding={true}>
49
- <ListItemText
50
- primary="Name"
51
- primaryTypographyProps={{ fontWeight: "500" }}
52
- secondary={packageName}
53
- />
54
- </ListItem>
55
- {!isSuccess && !isError && (
56
- <ListItem>
57
- <Loading text="Fetching Package Metadata..." />
58
- </ListItem>
59
- )}
60
- {isSuccess &&
61
- ((data.data && (
62
- <ListItem dense={true} disablePadding={true}>
63
- <ListItemText
64
- primary="Description"
65
- primaryTypographyProps={{
66
- fontWeight: "500",
67
- }}
68
- secondary={data.data.description}
69
- />
70
- </ListItem>
71
- )) || (
72
- <ListItem
73
- disablePadding={true}
74
- dense={true}
75
- sx={{ mt: "20px" }}
76
- >
77
- <ErrorIcon
78
- sx={{
79
- color: "grey.600",
80
- mr: "10px",
81
- }}
82
- />
83
- <ListItemText primary={"No package manifest"} />
84
- </ListItem>
85
- ))}
86
- {isError && (
87
- <ApiErrorDisplay
88
- error={error}
89
- context={`${projectName} > ${packageName} > ${versionId}`}
90
- />
91
- )}
92
- </List>
93
- </Box>
94
- </PackageCardContent>
95
- </PackageCard>
96
- );
97
- }
@@ -1,373 +0,0 @@
1
- import SearchIcon from "@mui/icons-material/Search";
2
- import {
3
- Box,
4
- Dialog,
5
- DialogContent,
6
- DialogTitle,
7
- IconButton,
8
- Snackbar,
9
- Table,
10
- TableBody,
11
- TableCell,
12
- TableRow,
13
- Typography,
14
- } from "@mui/material";
15
- import { useQueryClient } from "@tanstack/react-query";
16
- import { useState } from "react";
17
- import { Connection as ApiConnection } from "../../client/api";
18
- import {
19
- useMutationWithApiError,
20
- useQueryWithApiError,
21
- } from "../../hooks/useQueryWithApiError";
22
- import { encodeResourceUri, parseResourceUri } from "../../utils/formatting";
23
- import { ApiErrorDisplay } from "../ApiErrorDisplay";
24
- import AddConnectionDialog from "../Connections/AddConnectionDialog";
25
- import DeleteConnectionDialog from "../Connections/DeleteConnectionDialog";
26
- import EditConnectionDialog from "../Connections/EditConnectionDialog";
27
- import ConnectionExplorer from "../Project/ConnectionExplorer";
28
- import { useServer } from "../ServerProvider";
29
- import {
30
- PackageCard,
31
- PackageCardContent,
32
- PackageSectionTitle,
33
- } from "../styles";
34
-
35
- type ConnectionProps = {
36
- connection: ApiConnection;
37
- onClick: () => void;
38
- onEdit: (connection: ApiConnection) => Promise<unknown>;
39
- onDelete: (connection: ApiConnection) => Promise<unknown> | void;
40
- isMutating: boolean;
41
- mutable: boolean;
42
- isAdding: boolean;
43
- };
44
-
45
- // TODO(jjs) - Move this UI to the ConnectionExplorer component
46
- function Connection({
47
- connection,
48
- onClick,
49
- onEdit,
50
- onDelete,
51
- isMutating,
52
- mutable,
53
- isAdding,
54
- }: ConnectionProps) {
55
- return (
56
- <TableRow
57
- key={connection.name}
58
- sx={{
59
- "&:hover": {
60
- backgroundColor: isAdding ? undefined : "action.hover",
61
- },
62
- }}
63
- >
64
- <TableCell
65
- sx={{
66
- cursor: isAdding ? "default" : "pointer",
67
- flexGrow: 1,
68
- opacity: isAdding ? 0.5 : 1,
69
- }}
70
- onClick={isAdding ? undefined : onClick}
71
- >
72
- <Box
73
- sx={{
74
- display: "flex",
75
- alignItems: "center",
76
- gap: 1,
77
- }}
78
- >
79
- <Typography variant="body2">{connection.name}</Typography>
80
- <SearchIcon
81
- sx={{
82
- fontSize: "1rem",
83
- color: "action.active",
84
- opacity: 0.7,
85
- }}
86
- />
87
- </Box>
88
- </TableCell>
89
- <TableCell sx={{ minWidth: "120px" }}>
90
- <Typography variant="body2">{connection.type}</Typography>
91
- </TableCell>
92
- {mutable && (
93
- <TableCell sx={{ minWidth: "120px" }}>
94
- <EditConnectionDialog
95
- connection={connection}
96
- onSubmit={onEdit}
97
- isSubmitting={isMutating}
98
- />
99
- <DeleteConnectionDialog
100
- connection={connection}
101
- onCloseDialog={() => {}}
102
- isMutating={isMutating}
103
- onDelete={() => onDelete(connection)}
104
- />
105
- </TableCell>
106
- )}
107
- </TableRow>
108
- );
109
- }
110
-
111
- type ConnectionsProps = {
112
- resourceUri: string;
113
- };
114
-
115
- export default function Connections({ resourceUri }: ConnectionsProps) {
116
- const { apiClients, mutable } = useServer();
117
- const queryClient = useQueryClient();
118
- const { projectName: projectName } = parseResourceUri(resourceUri);
119
- const [notificationMessage, setNotificationMessage] = useState("");
120
- const [selectedConnection, setSelectedConnection] = useState<string | null>(
121
- null,
122
- );
123
- const selectedConnectionResourceUri = encodeResourceUri({
124
- projectName: projectName,
125
- connectionName: selectedConnection,
126
- });
127
-
128
- const { data, isSuccess, isError, error } = useQueryWithApiError({
129
- queryKey: ["connections", projectName],
130
- queryFn: () => apiClients.connections.listConnections(projectName),
131
- });
132
-
133
- const handleConnectionClick = (connectionName: string) => {
134
- setSelectedConnection(connectionName);
135
- };
136
-
137
- const handleCloseDialog = () => {
138
- setSelectedConnection(null);
139
- };
140
-
141
- const addConnection = useMutationWithApiError({
142
- mutationFn: (payload: ApiConnection) => {
143
- return apiClients.projects.updateProject(projectName, {
144
- name: projectName,
145
- connections: [...data.data, payload],
146
- });
147
- },
148
- onSuccess() {
149
- setNotificationMessage("Connection added successfully");
150
- queryClient.invalidateQueries({
151
- queryKey: ["connections", projectName],
152
- });
153
- },
154
- onError(error) {
155
- setNotificationMessage(error.message);
156
- },
157
- });
158
-
159
- const updateConnection = useMutationWithApiError({
160
- mutationFn: (payload: ApiConnection) => {
161
- return apiClients.projects.updateProject(projectName, {
162
- name: projectName,
163
- connections: data.data.map((conn) =>
164
- conn.name === payload.name ? payload : conn,
165
- ),
166
- });
167
- },
168
- onSuccess(_data, variables) {
169
- setNotificationMessage(
170
- `Connection ${variables.name} updated successfully`,
171
- );
172
- queryClient.invalidateQueries({
173
- queryKey: ["connections", projectName],
174
- });
175
- },
176
- onError(error) {
177
- setNotificationMessage(error.message);
178
- },
179
- });
180
-
181
- const deleteConnection = useMutationWithApiError({
182
- mutationFn: (payload: ApiConnection) => {
183
- return apiClients.projects.updateProject(projectName, {
184
- name: projectName,
185
- connections: data.data.filter((conn) => conn.name !== payload.name),
186
- });
187
- },
188
- onSuccess(_data, variables) {
189
- setNotificationMessage(
190
- `Connection ${variables.name} deleted successfully`,
191
- );
192
- queryClient.invalidateQueries({
193
- queryKey: ["connections", projectName],
194
- });
195
- },
196
- onError(error) {
197
- setNotificationMessage(error.message);
198
- },
199
- });
200
-
201
- return (
202
- <>
203
- <PackageCard>
204
- <PackageCardContent>
205
- <PackageSectionTitle>Database Connections</PackageSectionTitle>
206
- <Box
207
- sx={{
208
- mb: 1,
209
- maxHeight: "200px",
210
- overflowY: "auto",
211
- }}
212
- >
213
- {!isSuccess && !isError && (
214
- <Typography variant="body2" sx={{ m: "auto" }}>
215
- Fetching Connections...
216
- </Typography>
217
- )}
218
- {isSuccess && data.data.length > 0 && (
219
- <Table
220
- size="small"
221
- sx={{
222
- borderCollapse: "collapse",
223
- "& .MuiTableRow-root": {
224
- display: "flex",
225
- width: "100%",
226
- },
227
- "& .MuiTableCell-root": {
228
- borderBottom: "1px solid #e0e0e0",
229
- display: "flex",
230
- alignItems: "center",
231
- },
232
- "& .MuiTableRow-root:last-child .MuiTableCell-root":
233
- {
234
- borderBottom: "none",
235
- },
236
- }}
237
- >
238
- <TableBody>
239
- <TableRow>
240
- <TableCell sx={{ flexGrow: 1 }}>
241
- <Typography
242
- variant="body2"
243
- fontWeight="500"
244
- color="text.secondary"
245
- >
246
- Connection Name
247
- </Typography>
248
- </TableCell>
249
- <TableCell sx={{ minWidth: "120px" }}>
250
- <Typography
251
- variant="body2"
252
- fontWeight="500"
253
- color="text.secondary"
254
- >
255
- Type
256
- </Typography>
257
- </TableCell>
258
- {mutable && (
259
- <TableCell sx={{ minWidth: "120px" }}>
260
- <Typography
261
- variant="body2"
262
- fontWeight="500"
263
- color="text.secondary"
264
- sx={{ mx: "auto" }}
265
- >
266
- Actions
267
- </Typography>
268
- </TableCell>
269
- )}
270
- </TableRow>
271
- {data.data.map((conn) => (
272
- <Connection
273
- key={conn.name}
274
- connection={conn}
275
- onClick={() =>
276
- handleConnectionClick(conn.name)
277
- }
278
- onEdit={(payload) =>
279
- updateConnection.mutateAsync(payload)
280
- }
281
- onDelete={(payload) => {
282
- if (!conn.resource) {
283
- deleteConnection.mutateAsync(payload);
284
- } else {
285
- setNotificationMessage(
286
- "Cannot delete this connection",
287
- );
288
- }
289
- }}
290
- isMutating={
291
- addConnection.isPending ||
292
- updateConnection.isPending ||
293
- deleteConnection.isPending
294
- }
295
- mutable={mutable}
296
- isAdding={addConnection.isPending}
297
- />
298
- ))}
299
- </TableBody>
300
- </Table>
301
- )}
302
- {isSuccess && data.data.length === 0 && (
303
- <Typography variant="body2">No Connections</Typography>
304
- )}
305
- {isError && (
306
- <ApiErrorDisplay
307
- error={error}
308
- context={`${projectName} > Connections`}
309
- />
310
- )}
311
- </Box>
312
- {mutable && (
313
- <Box sx={{ display: "flex", justifyContent: "flex-end" }}>
314
- <AddConnectionDialog
315
- onSubmit={(payload) =>
316
- addConnection.mutateAsync(payload)
317
- }
318
- isSubmitting={addConnection.isPending}
319
- />
320
- </Box>
321
- )}
322
- </PackageCardContent>
323
- </PackageCard>
324
-
325
- <Snackbar
326
- open={notificationMessage !== ""}
327
- autoHideDuration={6000}
328
- onClose={() => setNotificationMessage("")}
329
- message={notificationMessage}
330
- />
331
-
332
- {/* Connection Explorer Dialog */}
333
- <Dialog
334
- open={selectedConnection !== null}
335
- onClose={handleCloseDialog}
336
- maxWidth="lg"
337
- fullWidth
338
- >
339
- <DialogTitle>
340
- Connection Explorer: {selectedConnection}
341
- <IconButton
342
- aria-label="close"
343
- onClick={handleCloseDialog}
344
- sx={{ position: "absolute", right: 8, top: 8 }}
345
- >
346
- <Box
347
- sx={{
348
- width: 24,
349
- height: 24,
350
- display: "flex",
351
- alignItems: "center",
352
- justifyContent: "center",
353
- }}
354
- >
355
- X
356
- </Box>
357
- </IconButton>
358
- </DialogTitle>
359
- <DialogContent>
360
- {selectedConnection && (
361
- <ConnectionExplorer
362
- resourceUri={selectedConnectionResourceUri}
363
- connectionName={selectedConnection}
364
- connection={data?.data?.find(
365
- (c) => c.name === selectedConnection,
366
- )}
367
- />
368
- )}
369
- </DialogContent>
370
- </Dialog>
371
- </>
372
- );
373
- }
@@ -1,228 +0,0 @@
1
- import {
2
- Box,
3
- Dialog,
4
- DialogContent,
5
- DialogTitle,
6
- Table,
7
- TableBody,
8
- TableCell,
9
- TableContainer,
10
- TableHead,
11
- TableRow,
12
- Typography,
13
- IconButton,
14
- } from "@mui/material";
15
- import SearchIcon from "@mui/icons-material/Search";
16
- import React from "react";
17
- import { Database } from "../../client";
18
- import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
19
- import { ApiErrorDisplay } from "../ApiErrorDisplay";
20
- import { Loading } from "../Loading";
21
- import {
22
- PackageCard,
23
- PackageCardContent,
24
- PackageSectionTitle,
25
- } from "../styles";
26
- import { parseResourceUri } from "../../utils/formatting";
27
- import { useServer } from "../ServerProvider";
28
-
29
- type Props = {
30
- resourceUri: string;
31
- };
32
-
33
- export default function Databases({ resourceUri }: Props) {
34
- const { apiClients } = useServer();
35
- const {
36
- projectName: projectName,
37
- packageName: packageName,
38
- versionId: versionId,
39
- } = parseResourceUri(resourceUri);
40
-
41
- const [open, setOpen] = React.useState(false);
42
- const [selectedDatabase, setSelectedDatabase] =
43
- React.useState<Database | null>(null);
44
-
45
- const handleOpen = (database: Database) => {
46
- setSelectedDatabase(database);
47
- setOpen(true);
48
- };
49
-
50
- const handleClose = () => {
51
- setOpen(false);
52
- setSelectedDatabase(null);
53
- };
54
-
55
- const { data, isError, error, isSuccess } = useQueryWithApiError({
56
- queryKey: ["databases", projectName, packageName, versionId],
57
- queryFn: () =>
58
- apiClients.databases.listDatabases(
59
- projectName,
60
- packageName,
61
- versionId,
62
- ),
63
- });
64
- const formatRowSize = (size: number) => {
65
- if (size >= 1024 * 1024 * 1024 * 1024) {
66
- return `${(size / (1024 * 1024 * 1024)).toFixed(2)} T`;
67
- } else if (size >= 1024 * 1024 * 1024) {
68
- return `${(size / (1024 * 1024 * 1024)).toFixed(2)} G`;
69
- } else if (size >= 1024 * 1024) {
70
- return `${(size / (1024 * 1024)).toFixed(2)} M`;
71
- } else {
72
- return `${(size / 1024).toFixed(2)} K`;
73
- }
74
- };
75
- return (
76
- <>
77
- <PackageCard>
78
- <PackageCardContent>
79
- <PackageSectionTitle>Embedded Databases</PackageSectionTitle>
80
- <Box
81
- sx={{
82
- maxHeight: "200px",
83
- overflowY: "auto",
84
- }}
85
- >
86
- {!isSuccess && !isError && (
87
- <Loading text="Fetching Databases..." />
88
- )}
89
- {isError && (
90
- <ApiErrorDisplay
91
- error={error}
92
- context={`${projectName} > ${packageName} > Databases`}
93
- />
94
- )}
95
- {isSuccess && data.data.length > 0 && (
96
- <Table
97
- size="small"
98
- sx={{
99
- borderCollapse: "collapse",
100
- "& .MuiTableCell-root": {
101
- borderBottom: "1px solid #e0e0e0",
102
- },
103
- "& .MuiTableRow-root:last-child .MuiTableCell-root":
104
- {
105
- borderBottom: "none",
106
- },
107
- }}
108
- >
109
- <TableBody>
110
- <TableRow>
111
- <TableCell>
112
- <Typography
113
- variant="body2"
114
- fontWeight="500"
115
- color="text.secondary"
116
- >
117
- Name
118
- </Typography>
119
- </TableCell>
120
- <TableCell align="right">
121
- <Typography
122
- variant="body2"
123
- fontWeight="500"
124
- color="text.secondary"
125
- >
126
- Rows
127
- </Typography>
128
- </TableCell>
129
- </TableRow>
130
- {data.data.map((database) => (
131
- <TableRow
132
- key={database.path}
133
- onClick={() => handleOpen(database)}
134
- sx={{
135
- cursor: "pointer",
136
- "&:hover": {
137
- backgroundColor: "action.hover",
138
- },
139
- }}
140
- >
141
- <TableCell component="th" scope="row">
142
- <Box
143
- sx={{
144
- display: "flex",
145
- alignItems: "center",
146
- gap: 1,
147
- }}
148
- >
149
- <Typography variant="body2">
150
- {database.path}
151
- </Typography>
152
- <SearchIcon
153
- sx={{
154
- fontSize: "1rem",
155
- color: "action.active",
156
- opacity: 0.7,
157
- }}
158
- />
159
- </Box>
160
- </TableCell>
161
- <TableCell align="right">
162
- <Typography variant="body2">
163
- {formatRowSize(database.info.rowCount)}
164
- </Typography>
165
- </TableCell>
166
- </TableRow>
167
- ))}
168
- </TableBody>
169
- </Table>
170
- )}
171
- {isSuccess && data.data.length === 0 && (
172
- <Typography variant="body2" sx={{ m: "auto" }}>
173
- No databases found
174
- </Typography>
175
- )}
176
- </Box>
177
- </PackageCardContent>
178
- </PackageCard>
179
-
180
- <Dialog open={open} onClose={handleClose} maxWidth="sm" fullWidth>
181
- <DialogTitle>
182
- {selectedDatabase?.path}
183
- <IconButton
184
- aria-label="close"
185
- onClick={handleClose}
186
- sx={{ position: "absolute", right: 8, top: 8 }}
187
- >
188
- <Box
189
- sx={{
190
- width: 24,
191
- height: 24,
192
- display: "flex",
193
- alignItems: "center",
194
- justifyContent: "center",
195
- }}
196
- >
197
- X
198
- </Box>
199
- </IconButton>
200
- </DialogTitle>
201
- <DialogContent>
202
- {selectedDatabase?.info?.columns && (
203
- <TableContainer>
204
- <Table size="small">
205
- <TableHead>
206
- <TableRow>
207
- <TableCell>Column</TableCell>
208
- <TableCell>Type</TableCell>
209
- </TableRow>
210
- </TableHead>
211
- <TableBody>
212
- {selectedDatabase.info.columns.map((column) => (
213
- <TableRow key={column.name}>
214
- <TableCell component="th" scope="row">
215
- {column.name}
216
- </TableCell>
217
- <TableCell>{column.type}</TableCell>
218
- </TableRow>
219
- ))}
220
- </TableBody>
221
- </Table>
222
- </TableContainer>
223
- )}
224
- </DialogContent>
225
- </Dialog>
226
- </>
227
- );
228
- }