Skip to content

Commit

Permalink
Fix workflow selection for scheduled events
Browse files Browse the repository at this point in the history
When changing a workflow for a scheduled
event in the event details, the selected workflow
would not be saved. This patch fixes that.
  • Loading branch information
Arnei committed Dec 18, 2024
1 parent 02e9b65 commit bf83863
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from "react";
import { Formik, FormikErrors } from "formik";
import { Formik } from "formik";
import {
deletingWorkflow as getDeletingWorkflow,
getBaseWorkflow,
Expand All @@ -14,7 +14,6 @@ import Notifications from "../../../shared/Notifications";
import RenderWorkflowConfig from "../wizards/RenderWorkflowConfig";
import { getUserInformation } from "../../../../selectors/userInfoSelectors";
import { hasAccess, parseBooleanInObject } from "../../../../utils/utils";
import { setDefaultConfig } from "../../../../utils/workflowPanelUtils";
import DropDown from "../../../shared/DropDown";
import { useAppDispatch, useAppSelector } from "../../../../store";
import {
Expand All @@ -24,7 +23,6 @@ import {
saveWorkflowConfig,
setModalWorkflowId,
setModalWorkflowTabHierarchy,
updateWorkflow,
} from "../../../../slices/eventDetailsSlice";
import { removeNotificationWizardForm } from "../../../../slices/notificationSlice";
import { renderValidDate } from "../../../../utils/dateUtils";
Expand Down Expand Up @@ -96,20 +94,6 @@ const EventDetailsWorkflowTab = ({
return true;
};

const changeWorkflow = (value: string, changeFormikValue: (field: string, value: unknown) => Promise<void | FormikErrors<any>>) => {
let currentConfiguration = {};

if (value === baseWorkflow.workflowId) {
currentConfiguration = parseBooleanInObject(baseWorkflow.configuration as { [key: string]: any });
} else {
currentConfiguration = setDefaultConfig(workflowDefinitions, value);
}

changeFormikValue("configuration", currentConfiguration);
changeFormikValue("workflowDefinition", value);
dispatch(updateWorkflow(value));
};

const setInitialValues = () => {
let initialConfig = undefined;

Expand Down Expand Up @@ -357,10 +341,7 @@ const EventDetailsWorkflowTab = ({
required={true}
handleChange={(element) => {
if (element) {
changeWorkflow(
element.value,
formik.setFieldValue
)
formik.setFieldValue("workflowDefinition", element.value)
}
}}
placeholder={
Expand Down Expand Up @@ -453,10 +434,6 @@ const EventDetailsWorkflowTab = ({
<button
type="reset"
onClick={() => {
changeWorkflow(
baseWorkflow.workflowId,
formik.setFieldValue
);
formik.resetForm();
}}
disabled={!formik.isValid}
Expand Down
21 changes: 0 additions & 21 deletions src/slices/eventDetailsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
getMetadata,
getExtendedMetadata,
getSchedulingSource,
getWorkflowDefinitions,
getWorkflows,
getStatistics,
} from "../selectors/eventDetailsSelectors";
Expand Down Expand Up @@ -1841,19 +1840,6 @@ export const deleteCommentReply = createAppAsyncThunk('eventDetails/deleteCommen
return true;
});

export const updateWorkflow = createAppAsyncThunk('eventDetails/updateWorkflow', async (workflowId: string, { dispatch, getState }) => {
const state = getState();
const workflowDefinitions = getWorkflowDefinitions(state);
const workflowDef = workflowDefinitions.find((def) => def.id === workflowId);
await dispatch(
setEventWorkflow({
workflowId: workflowId,
description: workflowDef?.description,
configuration: workflowDef?.configuration_panel_json // previously `workflowDef.configuration`. Might cause error
})
);
});

export const saveWorkflowConfig = createAppAsyncThunk('eventDetails/saveWorkflowConfig', async (params: {
values: {
workflowDefinition: string,
Expand Down Expand Up @@ -2565,13 +2551,6 @@ const eventDetailsSlice = createSlice({
.addCase(deleteComment.rejected, (state, action) => {
console.error(action.error);
})
.addCase(updateWorkflow.fulfilled, (state, action) => {
if ("workflowId" in state.workflows.workflow && !!state.workflows.workflow.workflowId) {
state.workflowConfiguration = state.workflows.workflow;
} else {
state.workflowConfiguration = state.baseWorkflow;
}
})
// fetch Tobira data
.addCase(fetchEventDetailsTobira.pending, (state) => {
state.statusTobiraData = 'loading';
Expand Down

0 comments on commit bf83863

Please sign in to comment.