feat: persist parameters values in FlowSubstep (#1505)
* feat: persist parameters values in FlowSubstep * feat: add missing import * feat: use usePrevious hook
This commit is contained in:
@@ -5,11 +5,13 @@ import Collapse from '@mui/material/Collapse';
|
|||||||
import ListItem from '@mui/material/ListItem';
|
import ListItem from '@mui/material/ListItem';
|
||||||
import Button from '@mui/material/Button';
|
import Button from '@mui/material/Button';
|
||||||
import Stack from '@mui/material/Stack';
|
import Stack from '@mui/material/Stack';
|
||||||
|
import isEqual from 'lodash/isEqual';
|
||||||
import { EditorContext } from 'contexts/Editor';
|
import { EditorContext } from 'contexts/Editor';
|
||||||
import FlowSubstepTitle from 'components/FlowSubstepTitle';
|
import FlowSubstepTitle from 'components/FlowSubstepTitle';
|
||||||
import InputCreator from 'components/InputCreator';
|
import InputCreator from 'components/InputCreator';
|
||||||
import FilterConditions from './FilterConditions';
|
import FilterConditions from './FilterConditions';
|
||||||
import { StepPropType, SubstepPropType } from 'propTypes/propTypes';
|
import { StepPropType, SubstepPropType } from 'propTypes/propTypes';
|
||||||
|
import { usePrevious } from 'hooks/usePrevious';
|
||||||
|
|
||||||
function FlowSubstep(props) {
|
function FlowSubstep(props) {
|
||||||
const {
|
const {
|
||||||
@@ -19,13 +21,27 @@ function FlowSubstep(props) {
|
|||||||
onCollapse,
|
onCollapse,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
step,
|
step,
|
||||||
|
onChange,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
const prevStep = usePrevious(step);
|
||||||
|
|
||||||
const { name, arguments: args } = substep;
|
const { name, arguments: args } = substep;
|
||||||
const editorContext = React.useContext(EditorContext);
|
const editorContext = React.useContext(EditorContext);
|
||||||
const formContext = useFormContext();
|
const formContext = useFormContext();
|
||||||
const validationStatus = formContext.formState.isValid;
|
const validationStatus = formContext.formState.isValid;
|
||||||
const onToggle = expanded ? onCollapse : onExpand;
|
const onToggle = expanded ? onCollapse : onExpand;
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (!isEqual(prevStep?.parameters, formContext.getValues('parameters'))) {
|
||||||
|
onChange({
|
||||||
|
step: { ...step, parameters: formContext.getValues('parameters') },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<FlowSubstepTitle
|
<FlowSubstepTitle
|
||||||
|
Reference in New Issue
Block a user