@evenicanpm/admin-integrate 1.2.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/documents/ConfigImport/configuration-import.ts +54 -0
  2. package/documents/CopyProcess/copy.ts +25 -0
  3. package/documents/Endpoint/fragments.ts +9 -0
  4. package/documents/Endpoint/list.ts +30 -0
  5. package/documents/Process/fragments.ts +22 -0
  6. package/documents/Process/get-process-details.ts +72 -0
  7. package/documents/Process/list.ts +24 -0
  8. package/documents/ProcessConfig/fragments.ts +116 -0
  9. package/documents/ProcessConfig/read.ts +35 -0
  10. package/documents/ProcessExecution/fragments.ts +12 -0
  11. package/documents/ProcessExecution/list.ts +30 -1
  12. package/documents/ProcessExecutionDetails/fragments.ts +96 -0
  13. package/documents/ProcessExecutionDetails/read.ts +12 -0
  14. package/documents/ProcessExport/read.ts +108 -0
  15. package/documents/ProcessScheduleGroup/read.ts +43 -0
  16. package/documents/ProcessTask/fragments.ts +288 -0
  17. package/documents/ProcessTask/read.ts +12 -0
  18. package/documents/ProcessTemplate/fragments.ts +74 -0
  19. package/documents/ProcessTemplate/list.ts +67 -0
  20. package/documents/ProcessTemplate/read.ts +12 -0
  21. package/documents/RunProcess/run.ts +11 -0
  22. package/package.json +4 -3
  23. package/src/api/Integrations/queries/get-process.query.ts +12 -12
  24. package/src/api/Integrations/queries/get-process.server.ts +7 -2
  25. package/src/api/configuration/queries/configuration-export.query.ts +48 -0
  26. package/src/api/configuration/queries/configuration-export.server.ts +9 -0
  27. package/src/api/configuration/queries/index.ts +1 -0
  28. package/src/api/dashboard/queries/get-process-executions.query.ts +6 -3
  29. package/src/api/dashboard/queries/get-process-executions.server.ts +1 -1
  30. package/src/api/execution-details/queries/get-process-execution-details.query.ts +46 -0
  31. package/src/api/execution-details/queries/get-process-execution-details.server.ts +11 -0
  32. package/src/api/execution-details/queries/get-process-executions-by-process.query.ts +48 -0
  33. package/src/api/execution-details/queries/get-process-executions-by-process.server.ts +11 -0
  34. package/src/api/execution-details/queries/index.ts +2 -0
  35. package/src/api/process/mutations/copy-process.mutation.ts +45 -0
  36. package/src/api/process/mutations/copy-process.server.ts +14 -0
  37. package/src/api/process/mutations/index.ts +2 -0
  38. package/src/api/process/mutations/run-process.mutation.ts +41 -0
  39. package/src/api/process/mutations/run-process.server.ts +14 -0
  40. package/src/api/process/queries/get-process-by-id.query.ts +85 -0
  41. package/src/api/process/queries/get-process-by-id.server.ts +20 -0
  42. package/src/api/process/queries/index.ts +4 -0
  43. package/src/api/process-config/mutation/index.ts +2 -0
  44. package/src/api/process-config/mutation/process-config-import.mutation.ts +42 -0
  45. package/src/api/process-config/mutation/process-config-import.server.ts +14 -0
  46. package/src/api/process-config/mutation/process-config-merge.mutation.ts +33 -0
  47. package/src/api/process-config/mutation/process-config-merge.server.ts +14 -0
  48. package/src/api/process-task/queries/get-process-task-by-id.query.ts +46 -0
  49. package/src/api/process-task/queries/get-process-task-by-id.server.ts +9 -0
  50. package/src/api/process-task/queries/index.ts +1 -0
  51. package/src/api/scheduler/mutation/create-process-schedule-group-details.mutation.ts +47 -0
  52. package/src/api/scheduler/mutation/create-process-schedule-group-details.server.ts +14 -0
  53. package/src/api/scheduler/mutation/index.ts +2 -0
  54. package/src/api/scheduler/mutation/update-process-schedule-group-details.mutation.ts +47 -0
  55. package/src/api/scheduler/mutation/update-process-schedule-group-details.server.ts +14 -0
  56. package/src/api/scheduler/queries/get-non-scheduled-processes.query.ts +48 -0
  57. package/src/api/scheduler/queries/get-non-scheduled-processes.server.ts +11 -0
  58. package/src/api/scheduler/queries/get-process-schedule-group-details.query.ts +6 -3
  59. package/src/api/scheduler/queries/get-process-schedule-group-details.server.ts +3 -3
  60. package/src/api/scheduler/queries/get-process-schedule.query.ts +6 -3
  61. package/src/api/scheduler/queries/get-process-schedule.server.ts +3 -3
  62. package/src/api/scheduler/queries/get-scheduled-processes.query.ts +6 -3
  63. package/src/api/scheduler/queries/get-scheduled-processes.server.ts +1 -1
  64. package/src/api/scheduler/queries/index.ts +3 -2
  65. package/src/api/templates/queries/get-process-template-groups.query.ts +48 -0
  66. package/src/api/templates/queries/get-process-template-groups.server.ts +11 -0
  67. package/src/api/templates/queries/get-process-template-records.query.ts +48 -0
  68. package/src/api/templates/queries/get-process-template-records.server.ts +11 -0
  69. package/src/api/templates/queries/get-process-template.query.ts +48 -0
  70. package/src/api/templates/queries/get-process-template.server.ts +9 -0
  71. package/src/api/templates/queries/get-process-templates.query.ts +45 -0
  72. package/src/api/templates/queries/get-process-templates.server.ts +9 -0
  73. package/src/api/templates/queries/index.ts +5 -0
  74. package/src/api/templates/queries/template-input-search.query.ts +39 -0
  75. package/src/api/templates/queries/template-input-search.server.ts +42 -0
  76. package/src/api/templates/queries/types.ts +34 -0
  77. package/src/components/breadcrumbs/breadcrumbs.tsx +33 -6
  78. package/src/components/button/outlined-icon-button.tsx +2 -2
  79. package/src/components/core/date-time-popover.tsx +12 -5
  80. package/src/components/core/drawer-buttons.tsx +52 -0
  81. package/src/components/core/edited-typography.tsx +2 -2
  82. package/src/components/core/index.ts +4 -2
  83. package/src/components/core/loading.tsx +1 -1
  84. package/src/components/core/status-tag.tsx +97 -0
  85. package/src/components/core/title-edit.tsx +31 -22
  86. package/src/components/dashboard-list/dashboard-list-row.tsx +22 -29
  87. package/src/components/dashboard-list/dashboard-list.tsx +20 -16
  88. package/src/components/data-table/table-header.tsx +6 -8
  89. package/src/components/data-table/table-pagination.tsx +1 -1
  90. package/src/components/data-table/table-row.tsx +1 -1
  91. package/src/components/data-table/table-skeleton.tsx +10 -5
  92. package/src/components/execution/execution-filter.ts +1 -1
  93. package/src/components/execution/execution-status-icon.tsx +7 -7
  94. package/src/components/execution/execution-tag.tsx +12 -77
  95. package/src/components/execution/index.ts +1 -1
  96. package/src/components/execution-history-drawer/execution-history-drawer.tsx +202 -0
  97. package/src/components/execution-history-drawer/executions-card.tsx +85 -0
  98. package/src/components/execution-history-drawer/index.ts +1 -0
  99. package/src/components/footer/footer.tsx +10 -6
  100. package/src/components/header/dashboard-list-header.tsx +12 -7
  101. package/src/components/header/execution-details-header.tsx +35 -26
  102. package/src/components/header/header.tsx +10 -3
  103. package/src/components/header/index.ts +1 -1
  104. package/src/components/header/integration-details-header.tsx +108 -45
  105. package/src/components/integration-list/index.ts +2 -1
  106. package/src/components/integration-list/integration-filter.ts +1 -1
  107. package/src/components/integration-list/integration-status-icon.tsx +7 -8
  108. package/src/components/integration-list/integration-tag.tsx +6 -50
  109. package/src/components/integration-list/list/integration-list-row.tsx +161 -0
  110. package/src/components/integration-list/list/integration-list-table.tsx +62 -0
  111. package/src/{pages/integrations/integration-list → components/integration-list/list}/integration-list.tsx +47 -51
  112. package/src/components/integration-view/animated-svg.tsx +31 -0
  113. package/src/components/integration-view/edges/default-edge.tsx +2 -6
  114. package/src/components/integration-view/elk-layout-options.ts +2 -2
  115. package/src/components/integration-view/elk-types.ts +35 -6
  116. package/src/components/integration-view/flow-types.tsx +12 -0
  117. package/src/components/integration-view/integration-view.tsx +562 -56
  118. package/src/components/integration-view/nodes/add-node.tsx +20 -0
  119. package/src/components/integration-view/nodes/empty-node.tsx +65 -0
  120. package/src/components/integration-view/nodes/entry-node.tsx +98 -4
  121. package/src/components/integration-view/nodes/execution-entry-node.tsx +107 -0
  122. package/src/components/integration-view/nodes/execution-task-node.tsx +88 -0
  123. package/src/components/integration-view/nodes/group-node.tsx +33 -13
  124. package/src/components/integration-view/nodes/row-node.tsx +19 -0
  125. package/src/components/integration-view/nodes/task-node.tsx +50 -16
  126. package/src/components/integration-view/task-icon.tsx +193 -0
  127. package/src/components/integration-view/temp-data/initialElements.tsx +34 -32
  128. package/src/components/integration-view/types.ts +2 -2
  129. package/src/components/integration-view/utils/mapping.ts +404 -0
  130. package/src/components/layouts/main-layout.tsx +3 -4
  131. package/src/components/layouts/root-container.tsx +5 -11
  132. package/src/components/link-cards/link-card.tsx +15 -4
  133. package/src/components/link-cards/styles.ts +1 -1
  134. package/src/components/list-filter/date-filter.tsx +7 -4
  135. package/src/components/list-filter/date-range-filter.tsx +15 -7
  136. package/src/components/list-filter/index.ts +1 -1
  137. package/src/components/list-filter/list-filter.tsx +31 -26
  138. package/src/components/list-filter/multi-select-filter.tsx +11 -10
  139. package/src/components/list-filter/select-filter.tsx +23 -12
  140. package/src/components/scheduler/day-selector.tsx +29 -15
  141. package/src/components/scheduler/day-tag.tsx +14 -51
  142. package/src/components/scheduler/index.ts +2 -1
  143. package/src/components/scheduler/schedule-drawer/details-reducer.ts +217 -0
  144. package/src/components/scheduler/schedule-drawer/schedule-details-integrations.tsx +501 -0
  145. package/src/{pages → components}/scheduler/schedule-drawer/schedule-details-main.tsx +137 -100
  146. package/src/components/scheduler/schedule-drawer/schedule-details-name.tsx +94 -0
  147. package/src/{pages → components}/scheduler/schedule-drawer/schedule-details-skeleton.tsx +1 -2
  148. package/src/{pages → components}/scheduler/schedule-drawer/schedule-details.tsx +10 -14
  149. package/src/components/scheduler/schedule-drawer/schedule-drawer-group.tsx +214 -0
  150. package/src/{pages → components}/scheduler/schedule-drawer/schedule-drawer-legacy.tsx +7 -26
  151. package/src/components/scheduler/schedule-drawer/schedule-drawer.tsx +116 -0
  152. package/src/components/scheduler/schedule-drawer/sortable-integration-row.tsx +130 -0
  153. package/src/components/scheduler/schedule-filter.ts +1 -1
  154. package/src/components/scheduler/schedule-icon.tsx +5 -6
  155. package/src/components/scheduler/schedule-integration-icon.tsx +31 -0
  156. package/src/components/templates/index.ts +1 -0
  157. package/src/components/templates/inputs/index.tsx +1392 -0
  158. package/src/components/templates/template-filter.ts +5 -0
  159. package/src/components/templates/templates-list/index.ts +1 -0
  160. package/src/components/templates/templates-list/templates-list-row.tsx +55 -0
  161. package/src/components/templates/templates-list/templates-list-table.tsx +58 -0
  162. package/src/components/templates/templates-list/templates-list.tsx +253 -0
  163. package/src/components/templates/types.tsx +76 -0
  164. package/src/components/templates/wizard.tsx +737 -0
  165. package/src/hooks/use-breadcrumbs.ts +1 -1
  166. package/src/hooks/use-recurrence.tsx +1 -2
  167. package/src/pages/dashboard/dashboard-link-cards.tsx +8 -11
  168. package/src/pages/dashboard/dashboard-list-sections.tsx +8 -10
  169. package/src/pages/dashboard/dashboard.tsx +1 -2
  170. package/src/pages/execution-details/execution-details.tsx +212 -14
  171. package/src/pages/execution-details/task-execution-details.tsx +160 -0
  172. package/src/pages/execution-details/task-execution-drawer.tsx +54 -0
  173. package/src/pages/executions/executions-list/executions-list-row.tsx +21 -27
  174. package/src/pages/executions/executions-list/executions-list-table.tsx +29 -36
  175. package/src/pages/executions/executions-list/executions-list.tsx +24 -18
  176. package/src/pages/executions/executions.tsx +11 -15
  177. package/src/pages/integration-create/index.ts +1 -0
  178. package/src/pages/integration-create/integration-create.tsx +216 -0
  179. package/src/pages/integration-create/pre-creation-step.tsx +84 -0
  180. package/src/pages/integration-create/select-step.tsx +105 -0
  181. package/src/pages/integration-create/template-list-step.tsx +77 -0
  182. package/src/pages/integration-create/wizard-step.tsx +51 -0
  183. package/src/pages/integration-details/import-process/copy-tasks-list.tsx +265 -0
  184. package/src/pages/integration-details/import-process/copy-tasks-row.tsx +77 -0
  185. package/src/pages/integration-details/import-process/import-confirm.tsx +61 -0
  186. package/src/pages/integration-details/import-process/import-drawer.tsx +48 -0
  187. package/src/pages/integration-details/import-process/import-process-reducer.ts +90 -0
  188. package/src/pages/integration-details/import-process/import-process.tsx +149 -0
  189. package/src/pages/integration-details/index.ts +1 -0
  190. package/src/pages/integration-details/integration-details.tsx +468 -0
  191. package/src/pages/integration-details/task-drawer/add-task.tsx +172 -0
  192. package/src/pages/integration-details/task-drawer/edit-task.tsx +161 -0
  193. package/src/pages/integration-details/task-drawer/task-drawer.tsx +157 -0
  194. package/src/pages/integration-details/task-drawer/task-reducer.ts +103 -0
  195. package/src/pages/integrations/integrations.tsx +11 -14
  196. package/src/pages/scheduler/scheduler.tsx +12 -24
  197. package/src/pages/scheduler/schedules-list/schedules-list-row.tsx +27 -37
  198. package/src/pages/scheduler/schedules-list/schedules-list-table.tsx +28 -43
  199. package/src/pages/scheduler/schedules-list/schedules-list.tsx +48 -21
  200. package/src/utils/date-functions.ts +69 -0
  201. package/src/utils/slugify.ts +3 -0
  202. package/tsconfig.json +12 -4
  203. package/src/hooks/use-timestamp.tsx +0 -25
  204. package/src/pages/integrations/integration-list/integration-list-row.tsx +0 -147
  205. package/src/pages/integrations/integration-list/integration-list-table.tsx +0 -78
  206. package/src/pages/scheduler/schedule-drawer/schedule-details-integrations.tsx +0 -227
  207. package/src/pages/scheduler/schedule-drawer/schedule-details-name.tsx +0 -77
  208. package/src/pages/scheduler/schedule-drawer/schedule-drawer-buttons.tsx +0 -72
  209. package/src/pages/scheduler/schedule-drawer/schedule-drawer-group.tsx +0 -103
  210. package/src/pages/scheduler/schedule-drawer/schedule-drawer.tsx +0 -101
  211. package/src/pages/scheduler/schedule-drawer/sortable-integration-row.tsx +0 -93
  212. /package/src/{pages/integrations/integration-list → components/integration-list/list}/index.ts +0 -0
  213. /package/src/{pages → components}/scheduler/schedule-drawer/edited/edited-types.ts +0 -0
  214. /package/src/{pages → components}/scheduler/schedule-drawer/edited/index.ts +0 -0
  215. /package/src/{pages → components}/scheduler/schedule-drawer/index.ts +0 -0
@@ -0,0 +1,149 @@
1
+ import type {
2
+ GetProcessByIdWithTasksQuery,
3
+ GetProcessesQuery,
4
+ ProcessInput,
5
+ } from "@evenicanpm/admin-core/api/e4/graphqlRequestSdk";
6
+ import { getProcesses } from "@evenicanpm/admin-integrate/api/Integrations/queries";
7
+ import { getProcessByIdWithTasks } from "@evenicanpm/admin-integrate/api/process/queries";
8
+ import type { Head } from "@evenicanpm/admin-integrate/components/data-table/table-header";
9
+ import { IntegrationList } from "@evenicanpm/admin-integrate/components/integration-list";
10
+ import { Alert, Box, type Theme, Typography, useTheme } from "@mui/material";
11
+ import { useParams } from "next/navigation";
12
+ import { useTranslations } from "next-intl";
13
+ import { useEffect, useState } from "react";
14
+ import ImportConfirm from "./import-confirm";
15
+ import {
16
+ type AlertAction,
17
+ type ImportAction,
18
+ ImportActionType,
19
+ type ImportState,
20
+ type SelectProcessAction,
21
+ } from "./import-process-reducer";
22
+
23
+ interface Props {
24
+ importState: ImportState;
25
+ dispatch: React.Dispatch<ImportAction>;
26
+ }
27
+
28
+ export default function ImportProcess(props: Readonly<Props>) {
29
+ const t = useTranslations("Integrate.IntegrationDetails.ImportProcess");
30
+ const l = useTranslations("Integrate.IntegrationList.ListHeader");
31
+
32
+ const params = useParams<{ processId: string }>();
33
+
34
+ const theme = useTheme();
35
+ const styles = getStyles(theme);
36
+
37
+ const heading: Head[] = [
38
+ {
39
+ id: "name",
40
+ label: l("integrationName"),
41
+ align: "left",
42
+ width: "30%",
43
+ sortable: true,
44
+ },
45
+ {
46
+ id: "id",
47
+ label: l("id"),
48
+ align: "left",
49
+ width: "15%",
50
+ },
51
+ {
52
+ id: "view",
53
+ label: l("actions"),
54
+ align: "center",
55
+ width: "5%",
56
+ },
57
+ ];
58
+
59
+ // TODO: initialize input based on url query params
60
+ const [input, setInput] = useState<ProcessInput>({
61
+ skip: 0,
62
+ sort: "name",
63
+ sortDesc: false,
64
+ top: 10,
65
+ integrationTags: null,
66
+ search: null,
67
+ });
68
+
69
+ const { data: processes, isLoading: processesLoading } = getProcesses.useData(
70
+ {
71
+ input: input,
72
+ },
73
+ );
74
+
75
+ const { data: current } = getProcessByIdWithTasks.useData({
76
+ id: params.processId,
77
+ });
78
+
79
+ useEffect(() => {
80
+ const typedData = current as GetProcessByIdWithTasksQuery;
81
+ if (typedData?.processById?.processTasks) {
82
+ if (typedData.processById.processTasks.length > 0) {
83
+ props.dispatch({
84
+ type: ImportActionType.ALERT,
85
+ alert: t("Alert.notEmpty"),
86
+ } as AlertAction);
87
+ }
88
+ }
89
+ }, [current]);
90
+
91
+ const handleRedirect = (id: string) => {
92
+ props.dispatch({
93
+ type: ImportActionType.SELECT,
94
+ selectedId: id,
95
+ } as SelectProcessAction);
96
+ };
97
+
98
+ return (
99
+ <Box sx={styles.main}>
100
+ <Box>
101
+ <Typography variant="h6">{t("title")}</Typography>
102
+ {props.importState.step === 0 && (
103
+ <Typography variant="caption" color="grey">
104
+ {t("descList")}
105
+ </Typography>
106
+ )}
107
+ {props.importState.step === 1 && (
108
+ <Typography variant="caption" color="grey">
109
+ {t("descTasks")}
110
+ </Typography>
111
+ )}
112
+ </Box>
113
+ {props.importState.alert && (
114
+ <Alert sx={styles.alert} severity="error">
115
+ {props.importState.alert}
116
+ </Alert>
117
+ )}
118
+ {props.importState.step === 0 && (
119
+ <IntegrationList
120
+ heading={heading}
121
+ data={processes as GetProcessesQuery}
122
+ loading={processesLoading}
123
+ input={input}
124
+ setInput={setInput}
125
+ handleRedirect={handleRedirect}
126
+ isImportMode
127
+ readOnly={!!props.importState.alert}
128
+ />
129
+ )}
130
+ {props.importState.step === 1 && (
131
+ <ImportConfirm
132
+ importState={props.importState}
133
+ dispatch={props.dispatch}
134
+ />
135
+ )}
136
+ </Box>
137
+ );
138
+ }
139
+
140
+ const getStyles = (theme: Theme) => {
141
+ return {
142
+ main: {
143
+ padding: theme.spacing(2),
144
+ },
145
+ alert: {
146
+ marginTop: theme.spacing(2),
147
+ },
148
+ };
149
+ };
@@ -0,0 +1 @@
1
+ export { default } from "./integration-details";
@@ -0,0 +1,468 @@
1
+ import type {
2
+ ConfigExport,
3
+ ConfigImport,
4
+ ConfigurationExportQuery,
5
+ GetProcessByIdQuery,
6
+ } from "@evenicanpm/admin-core/api/e4/graphqlRequestSdk";
7
+ import { getProcessById } from "@evenicanpm/admin-integrate/api/process/queries";
8
+ import { buildProcessByIdQueryKey } from "@evenicanpm/admin-integrate/api/process/queries/get-process-by-id.query";
9
+ import {
10
+ type Crumb,
11
+ IntegrateBreadcrumbs,
12
+ } from "@evenicanpm/admin-integrate/components/breadcrumbs";
13
+ import { Loading } from "@evenicanpm/admin-integrate/components/core";
14
+ import { IntegrationDetailsHeader } from "@evenicanpm/admin-integrate/components/header";
15
+ import IntegrationView from "@evenicanpm/admin-integrate/components/integration-view/integration-view";
16
+ import type { DrawerOpen } from "@evenicanpm/admin-integrate/components/scheduler/schedule-drawer/schedule-drawer";
17
+ import ScheduleDrawer from "@evenicanpm/admin-integrate/components/scheduler/schedule-drawer/schedule-drawer";
18
+ import CancelIcon from "@mui/icons-material/Cancel";
19
+ import SaveIcon from "@mui/icons-material/Save";
20
+ import { Box, Button, CircularProgress, useTheme } from "@mui/material";
21
+ import { useParams, useRouter } from "next/navigation";
22
+ import { useTranslations } from "next-intl";
23
+ import { useEffect, useReducer, useState } from "react";
24
+ import { configurationExport } from "../../api/configuration/queries";
25
+ import { buildConfigurationExportQueryKey } from "../../api/configuration/queries/configuration-export.query";
26
+ import { processConfigImport } from "../../api/process-config/mutation";
27
+ import ImportDrawer from "./import-process/import-drawer";
28
+ import {
29
+ ImportActionType,
30
+ importReducer,
31
+ } from "./import-process/import-process-reducer";
32
+ import TaskDrawer from "./task-drawer/task-drawer";
33
+ import {
34
+ type EditAction,
35
+ TaskActionType,
36
+ TaskMode,
37
+ taskReducer,
38
+ } from "./task-drawer/task-reducer";
39
+
40
+ function mergeByKey(
41
+ keyFields: string | string[],
42
+ arr1: any[] = [],
43
+ arr2: any[] = [],
44
+ ) {
45
+ const keys = Array.isArray(keyFields) ? keyFields : [keyFields];
46
+
47
+ // Build lookup maps for each key -> value => baseItem (from arr1)
48
+ const lookupByKey: Record<string, Map<any, any>> = {};
49
+ for (const k of keys) {
50
+ lookupByKey[k] = new Map();
51
+ }
52
+
53
+ for (const item of arr1) {
54
+ for (const key of keys) {
55
+ const val = item?.[key];
56
+ if (val !== undefined && val !== null) {
57
+ lookupByKey[key].set(val, item);
58
+ }
59
+ }
60
+ }
61
+
62
+ // Use a Set to preserve insertion order and ensure uniqueness
63
+ const resultSet = new Set<any>(arr1);
64
+
65
+ for (const item of arr2) {
66
+ let matchedBase: any = null;
67
+
68
+ // Try keys in order of priority
69
+ for (const key of keys) {
70
+ const val = item?.[key];
71
+ if (val !== undefined && val !== null) {
72
+ const candidate = lookupByKey[key].get(val);
73
+ if (candidate) {
74
+ matchedBase = candidate;
75
+ break;
76
+ }
77
+ }
78
+ }
79
+
80
+ if (matchedBase) {
81
+ // Merge properties from item into matched base (respecting exclusions)
82
+ for (const prop of Object.keys(item)) {
83
+ if (prop !== "Sort" && prop !== "ParallelProcessingGroup") {
84
+ matchedBase[prop] = item[prop];
85
+ }
86
+ }
87
+ } else {
88
+ // No match found by any tiered key -> add as new
89
+ resultSet.add(item);
90
+ // Register the newly added item in lookups so subsequent arr2 items can match it
91
+ for (const key of keys) {
92
+ const val = item?.[key];
93
+ if (val !== undefined && val !== null) {
94
+ lookupByKey[key].set(val, item);
95
+ }
96
+ }
97
+ }
98
+ }
99
+
100
+ return Array.from(resultSet);
101
+ }
102
+
103
+ export default function IntegrationDetails() {
104
+ const t = useTranslations("Integrate");
105
+ const params = useParams<{ processId: string }>();
106
+ const theme = useTheme();
107
+ const router = useRouter();
108
+
109
+ const [config, setConfig] = useState<ConfigExport | null>(null);
110
+
111
+ const [breadcrumbs, setBreadcrumbs] = useState<Crumb[]>([
112
+ {
113
+ name: t("Header.dashboard"),
114
+ url: "/e4integrate",
115
+ },
116
+ {
117
+ name: t("Header.integrations"),
118
+ url: "/e4integrate/integrations",
119
+ },
120
+ ]);
121
+
122
+ const [taskState, dispatchTaskState] = useReducer(taskReducer, {
123
+ open: false,
124
+ mode: TaskMode.NONE,
125
+ step: null,
126
+ });
127
+
128
+ const [importState, dispatchImportState] = useReducer(importReducer, {
129
+ open: false,
130
+ step: null,
131
+ alert: null,
132
+ loading: false,
133
+ });
134
+
135
+ const { data, isLoading } = getProcessById.useData(
136
+ {
137
+ id: params.processId,
138
+ },
139
+ {
140
+ queryKey: buildProcessByIdQueryKey.byInput({ id: params.processId }),
141
+ refetchOnWindowFocus: false, // prevents refetching while user is in process of editing the integration
142
+ },
143
+ );
144
+
145
+ const {
146
+ data: configFromApi,
147
+ isLoading: configLoading,
148
+ refetch,
149
+ } = configurationExport.useData(
150
+ {
151
+ processId: params.processId,
152
+ includeIds: true,
153
+ useSourceEndpoint: true,
154
+ },
155
+ {
156
+ queryKey: buildConfigurationExportQueryKey.byInput({
157
+ processId: params.processId,
158
+ includeIds: true,
159
+ useSourceEndpoint: true,
160
+ }),
161
+ refetchOnWindowFocus: false, // prevents refetching while user is in process of editing the integration
162
+ },
163
+ );
164
+
165
+ const handleUpdateConfig = (newConfig: ConfigExport) => {
166
+ dispatchTaskState({
167
+ type: TaskActionType.CLOSE,
168
+ });
169
+ // TODO: update config state with newConfig from configMerge
170
+
171
+ // when config export is implemented, change functionality to instead update the config state, rather than replace it
172
+ // this is so we can do things like change a single task's name, because doing an overwrite will replace the new name
173
+ // since config merge will generate names for the tasks automatically.
174
+ // also don't want to do things like overwrite parallel processing group, sort, Process name, etc.
175
+ //setConfig(newConfig);
176
+
177
+ const configData: ConfigExport =
178
+ config ?? (configFromApi as any)?.configurationExport;
179
+
180
+ configData.DepotGroups = mergeByKey(
181
+ "DepotGroup",
182
+ configData.DepotGroups || [],
183
+ newConfig.DepotGroups || [],
184
+ );
185
+
186
+ configData.Depots = mergeByKey(
187
+ "Depot",
188
+ configData.Depots || [],
189
+ newConfig.Depots || [],
190
+ );
191
+
192
+ configData.Endpoints = mergeByKey(
193
+ "Endpoint",
194
+ configData.Endpoints || [],
195
+ newConfig.Endpoints || [],
196
+ );
197
+
198
+ configData.Entities = mergeByKey(
199
+ "Entity",
200
+ configData.Entities || [],
201
+ newConfig.Entities || [],
202
+ );
203
+
204
+ if (newConfig?.Processes?.[0])
205
+ newConfig.Processes[0].ProcessTasks =
206
+ newConfig?.Processes[0]?.ProcessTasks?.map((newTask) => {
207
+ if (newTask)
208
+ newTask.Name =
209
+ newTask?.Name || newTask?.ProcessTask?.replaceAll("_", " ");
210
+
211
+ return newTask;
212
+ });
213
+
214
+ if (configData?.Processes?.[0])
215
+ configData.Processes[0].ProcessTasks = mergeByKey(
216
+ ["ProcessTaskId", "ProcessTask"],
217
+ configData.Processes?.[0]?.ProcessTasks || [],
218
+ newConfig.Processes?.[0]?.ProcessTasks || [],
219
+ );
220
+
221
+ setConfig(configData);
222
+ };
223
+
224
+ const processConfigImportMutation = processConfigImport();
225
+
226
+ const handleProcessConfigImport = () => {
227
+ if (config) {
228
+ processConfigImportMutation.mutate(
229
+ {
230
+ config: config as ConfigImport,
231
+ reRoutedFromMerge: true,
232
+ },
233
+ {
234
+ onSuccess: () => {
235
+ setConfig(null);
236
+ },
237
+ onError: (error) => {
238
+ console.error("Update failed:", error);
239
+ },
240
+ },
241
+ );
242
+ }
243
+ };
244
+
245
+ const details = data as GetProcessByIdQuery | undefined;
246
+
247
+ useEffect(() => {
248
+ const typedData = details as GetProcessByIdQuery;
249
+ if (typedData?.processById) {
250
+ if (breadcrumbs.length === 2) {
251
+ const newCrumbs: Crumb[] = structuredClone(breadcrumbs);
252
+ newCrumbs.push({ name: typedData.processById.name as string });
253
+ setBreadcrumbs(newCrumbs);
254
+ }
255
+ }
256
+ }, [details]);
257
+
258
+ const [drawerOpen, setDrawerOpen] = useState<DrawerOpen | null>(null);
259
+ const [scheduleLoading, setScheduleLoading] = useState<boolean>(false);
260
+
261
+ const handleScheduleDrawerOpen = () => {
262
+ if (details?.processById) {
263
+ if (details.processById.processScheduleGroup) {
264
+ setDrawerOpen({
265
+ id: details.processById.processScheduleGroup.id,
266
+ group: true,
267
+ addMode: false,
268
+ });
269
+ } else {
270
+ setDrawerOpen({
271
+ id: "",
272
+ group: true,
273
+ addMode: true,
274
+ });
275
+ }
276
+ }
277
+ };
278
+
279
+ const [viewRefreshKey, setViewRefreshKey] = useState<number>(Date.now());
280
+ useEffect(() => {
281
+ setViewRefreshKey(Date.now());
282
+ }, [data, config]);
283
+
284
+ useEffect(() => {
285
+ if (!scheduleLoading) {
286
+ setViewRefreshKey(Date.now());
287
+ }
288
+ }, [scheduleLoading]);
289
+
290
+ const onAdd = (data: any) => {
291
+ dispatchTaskState({
292
+ type: TaskActionType.OPEN_ADD,
293
+ sort: data.sort,
294
+ parallelProcessingGroup: data.paralellelProcessingGroup,
295
+ } as EditAction);
296
+ };
297
+
298
+ useEffect(() => {
299
+ const handler = (e: CustomEvent) => onAdd(e.detail);
300
+
301
+ document.addEventListener("addItem", handler as EventListener);
302
+ }, []);
303
+
304
+ if (isLoading || configLoading) {
305
+ return (
306
+ <Box sx={{ padding: theme.spacing(10, 3) }}>
307
+ <Loading />
308
+ </Box>
309
+ );
310
+ }
311
+
312
+ return (
313
+ <Box>
314
+ <IntegrateBreadcrumbs breadcrumbs={breadcrumbs} />
315
+ <IntegrationDetailsHeader
316
+ name={
317
+ (config || (configFromApi as any)?.configurationExport)?.Processes[0]
318
+ ?.Name || "Untitled Integration"
319
+ }
320
+ icon={details?.processById?.processIcon ?? ""}
321
+ setName={(name) => {
322
+ const configData =
323
+ config || (configFromApi as any)?.configurationExport;
324
+ configData.Processes[0].Name = name;
325
+ setConfig(configData);
326
+ }}
327
+ onImportClick={() => {
328
+ if (!config) {
329
+ dispatchImportState({ type: ImportActionType.OPEN });
330
+ }
331
+ }}
332
+ onScheduleClick={() => {
333
+ if (!config) {
334
+ handleScheduleDrawerOpen();
335
+ }
336
+ }}
337
+ onExecutionsClick={() =>
338
+ router.push(`/e4integrate/executions/${params.processId}`)
339
+ }
340
+ >
341
+ {config ? (
342
+ <Button
343
+ variant="contained"
344
+ color="error"
345
+ startIcon={<CancelIcon />}
346
+ sx={{ padding: theme.spacing(1.3, 2) }}
347
+ onClick={() => {
348
+ refetch().then(() => {
349
+ setConfig(null);
350
+ });
351
+ }}
352
+ >
353
+ Cancel
354
+ </Button>
355
+ ) : null}
356
+ <Button
357
+ variant="contained"
358
+ color="info"
359
+ startIcon={<SaveIcon />}
360
+ sx={{ padding: theme.spacing(1.3, 2) }}
361
+ onClick={handleProcessConfigImport}
362
+ disabled={!config}
363
+ >
364
+ {t("IntegrationDetails.save")}
365
+ </Button>
366
+ </IntegrationDetailsHeader>
367
+
368
+ <Box
369
+ sx={{
370
+ display: "flex",
371
+ height: "80vh",
372
+ width: "100%",
373
+ overflow: "hidden",
374
+ backgroundColor: theme.palette.background.default,
375
+ border: `1px solid ${theme.palette.grey[400]}`,
376
+ alignItems: scheduleLoading || importState.loading ? "center" : null,
377
+ justifyContent:
378
+ scheduleLoading || importState.loading ? "center" : null,
379
+ }}
380
+ >
381
+ {!scheduleLoading &&
382
+ !importState.loading &&
383
+ (config || configFromApi) ? (
384
+ <IntegrationView
385
+ canEdit
386
+ key={viewRefreshKey}
387
+ //data={(data as GetProcessByIdQuery)?.processById as Process}
388
+ config={
389
+ config ||
390
+ ((configFromApi as ConfigurationExportQuery)
391
+ .configurationExport as ConfigExport)
392
+ }
393
+ variant="process"
394
+ onTaskClick={(processTask: any) => {
395
+ const endpoint = (
396
+ config ??
397
+ (configFromApi as ConfigurationExportQuery).configurationExport
398
+ )?.Endpoints?.find(
399
+ (ep) => !!ep && ep.Name === processTask.endpoint,
400
+ );
401
+
402
+ let templateConfig: any;
403
+
404
+ if (endpoint) {
405
+ if (typeof endpoint.TemplateConfig === "string") {
406
+ templateConfig = endpoint.TemplateConfig;
407
+ } else if (typeof endpoint.TemplateConfig === "object") {
408
+ templateConfig = JSON.stringify(endpoint.TemplateConfig);
409
+ }
410
+ }
411
+
412
+ dispatchTaskState({
413
+ type: TaskActionType.OPEN_EDIT,
414
+ processTaskId: processTask.id,
415
+ templateConfig: templateConfig,
416
+ sort: processTask.sort,
417
+ parallelProcessingGroup: processTask.parallelProcessingGroup,
418
+ processTemplateId: endpoint?.ProcessTemplateId,
419
+ name: processTask.name,
420
+ } as EditAction);
421
+ }}
422
+ drawerOpen={taskState.open}
423
+ processTaskId={
424
+ taskState.processTaskId ? taskState.processTaskId : undefined
425
+ }
426
+ onConfigChange={setConfig}
427
+ onAdd={() => {}}
428
+ />
429
+ ) : (
430
+ <CircularProgress />
431
+ )}
432
+ <TaskDrawer
433
+ open={taskState.open}
434
+ onClose={() => dispatchTaskState({ type: TaskActionType.CLOSE })}
435
+ anchor="right"
436
+ taskState={taskState}
437
+ renderKey={taskState.processTaskId}
438
+ dispatch={dispatchTaskState}
439
+ handleUpdateConfig={handleUpdateConfig}
440
+ config={config ?? (configFromApi as any)?.configurationExport}
441
+ />
442
+ </Box>
443
+ <ScheduleDrawer
444
+ drawerOpen={drawerOpen}
445
+ setDrawerOpen={setDrawerOpen}
446
+ processData={data as GetProcessByIdQuery}
447
+ handleSave={(loading: boolean) => setScheduleLoading(loading)}
448
+ />
449
+
450
+ <ImportDrawer
451
+ open={importState.open}
452
+ onClose={() => dispatchImportState({ type: ImportActionType.CLOSE })}
453
+ anchor="right"
454
+ importState={importState}
455
+ dispatch={dispatchImportState}
456
+ />
457
+ {/* temporary ui below */}
458
+ {/* <Button
459
+ variant="contained"
460
+ color="primary"
461
+ onClick={() => dispatchTaskState({ type: TaskActionType.OPEN_ADD })}
462
+ // sx={{ visibility: "hidden" }}
463
+ >
464
+ Add task
465
+ </Button> */}
466
+ </Box>
467
+ );
468
+ }