diff --git a/packages/web/src/components/TestSubstep/index.jsx b/packages/web/src/components/TestSubstep/index.jsx index d678d23b..c957fc02 100644 --- a/packages/web/src/components/TestSubstep/index.jsx +++ b/packages/web/src/components/TestSubstep/index.jsx @@ -1,6 +1,5 @@ import PropTypes from 'prop-types'; 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'; @@ -10,37 +9,19 @@ 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 useTestStep from 'hooks/useTestStep'; import JSONViewer from 'components/JSONViewer'; import WebhookUrlInfo from 'components/WebhookUrlInfo'; import FlowSubstepTitle from 'components/FlowSubstepTitle'; import { useQueryClient } from '@tanstack/react-query'; import { StepPropType, SubstepPropType } from 'propTypes/propTypes'; -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,
@@ -48,15 +29,21 @@ function TestSubstep(props) {
} = props;
const formatMessage = useFormatMessage();
const editorContext = React.useContext(EditorContext);
- const [executeFlow, { data, error, loading, called, reset }] = useMutation(
- EXECUTE_FLOW,
- {
- context: { autoSnackbar: false },
- },
- );
- const response = data?.executeFlow?.data;
- const isCompleted = !error && called && !loading;
- const hasNoOutput = !response && isCompleted;
+ const {
+ mutateAsync: testStep,
+ isPending: isTestStepPending,
+ data,
+ isSuccess: isCompleted,
+ reset,
+ } = useTestStep(step.id);
+ const loading = isTestStepPending;
+ const lastExecutionStep = data?.data.lastExecutionStep;
+ const dataOut = lastExecutionStep?.dataOut;
+ const errorDetails = lastExecutionStep?.errorDetails;
+ const hasError = errorDetails && Object.values(errorDetails).length > 0;
+ const hasNoOutput = !hasError && isCompleted && !dataOut;
+ const hasOutput =
+ !hasError && isCompleted && dataOut && Object.values(dataOut).length > 0;
const { name } = substep;
const queryClient = useQueryClient();
@@ -75,18 +62,12 @@ function TestSubstep(props) {
return;
}
- await executeFlow({
- variables: {
- input: {
- stepId: step.id,
- },
- },
- });
+ await testStep();
await queryClient.invalidateQueries({
queryKey: ['flows', flowId],
});
- }, [onSubmit, onContinue, isCompleted, queryClient, flowId]);
+ }, [testStep, onContinue, isCompleted, queryClient, flowId]);
const onToggle = expanded ? onCollapse : onExpand;
@@ -102,14 +83,14 @@ function TestSubstep(props) {
alignItems: 'flex-start',
}}
>
- {!!error?.graphQLErrors?.length && (
+ {hasError && (
+ {JSON.stringify(errorDetails, null, 2)}
+