Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ import Notifications from "../../../shared/Notifications";
import RenderWorkflowConfig from "../wizards/RenderWorkflowConfig";
import { getUserInformation } from "../../../../selectors/userInfoSelectors";
import { hasAccess, parseBooleanInObject } from "../../../../utils/utils";
import DropDown from "../../../shared/DropDown";
import { useAppDispatch, useAppSelector } from "../../../../store";
import {
fetchWorkflows,
saveWorkflowConfig,
} from "../../../../slices/eventDetailsSlice";
import { removeNotificationWizardForm } from "../../../../slices/notificationSlice";
import { useTranslation } from "react-i18next";
import { formatWorkflowsForDropdown } from "../../../../utils/dropDownUtils";
import ModalContent from "../../../shared/modals/ModalContent";
import RenderWorkflowSelect from "../wizards/RenderWorkflowSelect";

type InitialValues = {
workflowDefinition: string;
workflowId: string;
configuration: {
[key: string]: any;
} | undefined;
Expand Down Expand Up @@ -73,15 +72,15 @@ const EventDetailsWorkflowSchedulingTab = ({
}

return {
workflowDefinition: "workflowId" in workflow && !!workflow.workflowId
workflowId: "workflowId" in workflow && !!workflow.workflowId
? workflow.workflowId
: baseWorkflow.workflowId,
configuration: initialConfig,
};
};

const handleSubmit = (values: {
workflowDefinition: string,
workflowId: string,
configuration: { [key: string]: unknown } | undefined
}) => {
dispatch(saveWorkflowConfig({ values, eventId }));
Expand Down Expand Up @@ -119,48 +118,14 @@ const EventDetailsWorkflowSchedulingTab = ({
<tr>
<td>
<div className="obj-container padded">
<div className="editable">
<DropDown
value={
formik.values.workflowDefinition
}
text={
workflowDefinitions.find(
workflowDef =>
workflowDef.id ===
formik.values.workflowDefinition,
)?.title ?? ""
}
options={
!!workflowDefinitions &&
workflowDefinitions.length > 0
? formatWorkflowsForDropdown(workflowDefinitions)
: []
}
required={true}
handleChange={element => {
if (element) {
formik.setFieldValue("workflowDefinition", element.value);
}
}}
placeholder={
!!workflowDefinitions &&
workflowDefinitions.length > 0
? t(
"EVENTS.EVENTS.NEW.PROCESSING.SELECT_WORKFLOW",
)
: t(
"EVENTS.EVENTS.NEW.PROCESSING.SELECT_WORKFLOW_EMPTY",
)
}
disabled={
!hasCurrentAgentAccess() ||
!isRoleWorkflowEdit
}
customCSS={{ width: "100%" }}
/>
{/* pre-select-from="workflowDefinitionIds" */}
</div>
<RenderWorkflowSelect
formik={formik}
workflowDefinitions={workflowDefinitions}
disabled={
!hasCurrentAgentAccess() ||
!isRoleWorkflowEdit
}
/>
<div className="obj-container padded">
{workflow.description}
</div>
Expand Down Expand Up @@ -195,7 +160,7 @@ const EventDetailsWorkflowSchedulingTab = ({
>
<RenderWorkflowConfig
workflowId={
workflowConfiguration.workflowId
formik.values.workflowId
}
formik={formik}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ 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 { setDefaultValues } from "../../../../utils/workflowPanelUtils";
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";
import RenderWorkflowSelect from "../wizards/RenderWorkflowSelect";

/**
* This component renders the processing page for new events in the new event wizard.
*/
interface RequiredFormProps {
sourceMode: string,
processingWorkflow: string,
workflowId: string,
}

const NewProcessingPage = <T extends RequiredFormProps>({
Expand All @@ -31,7 +30,7 @@ const NewProcessingPage = <T extends RequiredFormProps>({
const { t } = useTranslation();
const dispatch = useAppDispatch();

const workflowDef = useAppSelector(state => getWorkflowDef(state));
const workflowDefinitions = useAppSelector(state => getWorkflowDef(state));

useEffect(() => {
// Load workflow definitions for selecting
Expand All @@ -44,11 +43,11 @@ const NewProcessingPage = <T extends RequiredFormProps>({

// Preselect the first item
useEffect(() => {
if (workflowDef.length === 1) {
setDefaultValues(workflowDef[0].id);
if (workflowDefinitions.length === 1) {
setDefaultValues(formik, workflowDefinitions, workflowDefinitions[0].id);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [workflowDef]);
}, [workflowDefinitions]);

const previous = () => {
// if not UPLOAD is chosen as source mode, then back to source page
Expand All @@ -59,17 +58,6 @@ const NewProcessingPage = <T extends RequiredFormProps>({
}
};

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>
Expand All @@ -79,45 +67,21 @@ const NewProcessingPage = <T extends RequiredFormProps>({
{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>
)}
<RenderWorkflowSelect
formik={formik}
workflowDefinitions={workflowDefinitions}
/>

{/* Configuration panel of selected workflow */}
<div className="collapsible-box">
<div
id="new-event-workflow-configuration"
className="checkbox-container obj-container"
>
{formik.values.processingWorkflow ? (
{formik.values.workflowId ? (
<RenderWorkflowConfig
displayDescription
workflowId={formik.values.processingWorkflow}
workflowId={formik.values.workflowId}
// @ts-expect-error TS(7006):
formik={formik}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import RenderWorkflowConfig from "../wizards/RenderWorkflowConfig";
import { getWorkflowDef } from "../../../../selectors/workflowSelectors";
import { setDefaultConfig } from "../../../../utils/workflowPanelUtils";
import DropDown from "../../../shared/DropDown";
import { setDefaultValues } from "../../../../utils/workflowPanelUtils";
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";
import RenderWorkflowSelect from "../wizards/RenderWorkflowSelect";

/**
* This component renders the workflow selection for start task bulk action
*/
interface RequiredFormProps {
workflow: string,
workflowId: string,
}

const StartTaskWorkflowPage = <T extends RequiredFormProps>({
Expand All @@ -32,7 +31,7 @@ const StartTaskWorkflowPage = <T extends RequiredFormProps>({
const { t } = useTranslation();

const dispatch = useAppDispatch();
const workflowDef = useAppSelector(state => getWorkflowDef(state));
const workflowDefinitions = useAppSelector(state => getWorkflowDef(state));

useEffect(() => {
// Load workflow definitions for selecting
Expand All @@ -42,22 +41,11 @@ const StartTaskWorkflowPage = <T extends RequiredFormProps>({

// Preselect the first item
useEffect(() => {
if (workflowDef.length === 1) {
setDefaultValues(workflowDef[0].id);
if (workflowDefinitions.length === 1) {
setDefaultValues(formik, workflowDefinitions, workflowDefinitions[0].id);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [workflowDef]);

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("workflow", workflowId);
};
}, [workflowDefinitions]);

return (
<>
Expand All @@ -66,32 +54,12 @@ const StartTaskWorkflowPage = <T extends RequiredFormProps>({
<div className="obj list-obj">
<header>{t("BULK_ACTIONS.SCHEDULE_TASK.TASKS.SELECT")}</header>
<div className="obj-container">
{workflowDef.length > 0 && (
<div className="editable">
<DropDown
value={formik.values.workflow}
text={
workflowDef.find(
workflowDef =>
workflowDef.id === formik.values.workflow,
)?.title ?? ""
}
options={formatWorkflowsForDropdown(workflowDef)}
required={true}
handleChange={element => {
if (element) {
setDefaultValues(element.value);
}
}}
placeholder={t(
"EVENTS.EVENTS.DETAILS.PUBLICATIONS.SELECT_WORKFLOW",
)}
tabIndex={99}
customCSS={{ width: "100%" }}
/>
</div>
)}
{formik.values.workflow && (
<RenderWorkflowSelect
formik={formik}
workflowDefinitions={workflowDefinitions}
/>

{formik.values.workflowId && (
<>
{/* Configuration panel of selected workflow */}
<div
Expand All @@ -100,7 +68,7 @@ const StartTaskWorkflowPage = <T extends RequiredFormProps>({
>
<RenderWorkflowConfig
displayDescription
workflowId={formik.values.workflow}
workflowId={formik.values.workflowId}
// @ts-expect-error TS(7006):
formik={formik}
/>
Expand All @@ -122,7 +90,7 @@ const StartTaskWorkflowPage = <T extends RequiredFormProps>({
setPageCompleted([]);
}
}}
customValidation={!(formik.values.workflow && formik.isValid)}
customValidation={!(formik.values.workflowId && formik.isValid)}
/>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/events/partials/wizards/NewEventSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { UploadAssetsTrack } from "../../../../slices/eventSlice";
* This component renders the summary page for new events in the new event wizard.
*/
interface RequiredFormProps {
processingWorkflow: string
workflowId: string
sourceMode: string
startDate?: string
location: string
Expand Down Expand Up @@ -92,7 +92,7 @@ const NewEventSummary = <T extends RequiredFormProps>({

// Get additional information about chosen workflow definition
const workflowDefinition = workflowDef.find(
workflow => workflow.id === formik.values.processingWorkflow,
workflow => workflow.id === formik.values.workflowId,
);

const endsOnSameDay = formik.values.scheduleStartDate === formik.values.scheduleEndDate;
Expand Down
Loading
Loading