import * as React from 'react'; import { useMutation } from '@apollo/client'; import Box from '@mui/material/Box'; import Collapse from '@mui/material/Collapse'; import ListItem from '@mui/material/ListItem'; import Alert from '@mui/material/Alert'; import AlertTitle from '@mui/material/AlertTitle'; import LoadingButton from '@mui/lab/LoadingButton'; import { EditorContext } from 'contexts/Editor'; import useFormatMessage from 'hooks/useFormatMessage'; import { EXECUTE_FLOW } from 'graphql/mutations/execute-flow'; import JSONViewer from 'components/JSONViewer'; import WebhookUrlInfo from 'components/WebhookUrlInfo'; import FlowSubstepTitle from 'components/FlowSubstepTitle'; function serializeErrors(graphQLErrors) { return graphQLErrors?.map((error) => { try { return { ...error, message: (
{JSON.stringify(JSON.parse(error.message), null, 2)}
),
};
} catch {
return error;
}
});
}
function TestSubstep(props) {
const {
substep,
expanded = false,
onExpand,
onCollapse,
onSubmit,
onContinue,
step,
showWebhookUrl = false,
} = props;
const formatMessage = useFormatMessage();
const editorContext = React.useContext(EditorContext);
const [executeFlow, { data, error, loading, called, reset }] = useMutation(
EXECUTE_FLOW,
{
refetchQueries: ['GetStepWithTestExecutions'],
context: { autoSnackbar: false },
},
);
const response = data?.executeFlow?.data;
const isCompleted = !error && called && !loading;
const hasNoOutput = !response && isCompleted;
const { name } = substep;
React.useEffect(
function resetTestDataOnSubstepToggle() {
if (!expanded) {
reset();
}
},
[expanded, reset],
);
const handleSubmit = React.useCallback(() => {
if (isCompleted) {
onContinue?.();
return;
}
executeFlow({
variables: {
input: {
stepId: step.id,
},
},
});
}, [onSubmit, onContinue, isCompleted, step.id]);
const onToggle = expanded ? onCollapse : onExpand;
return (