-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathNewProcessingPage.tsx
More file actions
141 lines (129 loc) · 4.15 KB
/
NewProcessingPage.tsx
File metadata and controls
141 lines (129 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { getWorkflowDef } from "../../../../selectors/workflowSelectors";
import RenderWorkflowConfig from "../wizards/RenderWorkflowConfig";
import { setDefaultConfig } from "../../../../utils/workflowPanelUtils";
import DropDown from "../../../shared/DropDown";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { fetchWorkflowDef } from "../../../../slices/workflowSlice";
import { FormikProps } from "formik";
import { formatWorkflowsForDropdown } from "../../../../utils/dropDownUtils";
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";
import ModalContentTable from "../../../shared/modals/ModalContentTable";
/**
* This component renders the processing page for new events in the new event wizard.
*/
interface RequiredFormProps {
sourceMode: string,
processingWorkflow: string,
}
const NewProcessingPage = <T extends RequiredFormProps>({
formik,
nextPage,
previousPage,
}: {
formik: FormikProps<T>,
nextPage: (values: T) => void,
previousPage: (values: T, twoPagesBack?: boolean) => void,
}) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const workflowDef = useAppSelector(state => getWorkflowDef(state));
useEffect(() => {
// Load workflow definitions for selecting
if (formik.values.sourceMode !== "UPLOAD") {
dispatch(fetchWorkflowDef("new-event-schedule"));
} else {
dispatch(fetchWorkflowDef("new-event-upload"));
}
}, [dispatch, formik.values.sourceMode]);
// Preselect the first item
useEffect(() => {
if (workflowDef.length === 1) {
setDefaultValues(workflowDef[0].id);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [workflowDef]);
const previous = () => {
// if not UPLOAD is chosen as source mode, then back to source page
if (formik.values.sourceMode !== "UPLOAD") {
previousPage(formik.values, true);
} else {
previousPage(formik.values, false);
}
};
const setDefaultValues = (value: string) => {
const workflowId = value;
// fill values with default configuration of chosen workflow
const defaultConfiguration = setDefaultConfig(workflowDef, workflowId);
// set default configuration in formik
formik.setFieldValue("configuration", defaultConfiguration);
// set chosen workflow in formik
formik.setFieldValue("processingWorkflow", workflowId);
};
return (
<>
<ModalContentTable>
{/* Workflow definition Selection*/}
<div className="obj quick-actions">
<header>
{t("EVENTS.EVENTS.NEW.PROCESSING.SELECT_WORKFLOW")}
</header>
<div className="obj-container padded">
{workflowDef.length > 0 ? (
<div className="editable">
<DropDown
value={formik.values.processingWorkflow}
text={
workflowDef.find(
workflow =>
formik.values.processingWorkflow === workflow.id,
)?.title ?? ""
}
options={formatWorkflowsForDropdown(workflowDef)}
required={true}
handleChange={element => {
if (element) {
setDefaultValues(element.value);
}
}}
placeholder={t(
"EVENTS.EVENTS.NEW.PROCESSING.SELECT_WORKFLOW",
)}
customCSS={{ width: "100%" }}
/>
</div>
) : (
<span>
{t("EVENTS.EVENTS.NEW.PROCESSING.SELECT_WORKFLOW_EMPTY")}
</span>
)}
{/* Configuration panel of selected workflow */}
<div className="collapsible-box">
<div
id="new-event-workflow-configuration"
className="checkbox-container obj-container"
>
{formik.values.processingWorkflow ? (
<RenderWorkflowConfig
displayDescription
workflowId={formik.values.processingWorkflow}
// @ts-expect-error TS(7006):
formik={formik}
/>
) : null}
</div>
</div>
</div>
</div>
</ModalContentTable>
{/* Button for navigation to next page and previous page */}
<WizardNavigationButtons
formik={formik}
nextPage={nextPage}
previousPage={() => previous()}
/>
</>
);
};
export default NewProcessingPage;