refactor(web): remove typescript

This commit is contained in:
Ali BARIN
2024-02-27 15:23:23 +00:00
parent 636870a075
commit b3ae2d2748
337 changed files with 2067 additions and 4997 deletions

View File

@@ -6,35 +6,20 @@ 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';
import type { IStep, ISubstep } from 'types';
type TestSubstepProps = {
substep: ISubstep;
expanded?: boolean;
showWebhookUrl?: boolean;
onExpand: () => void;
onCollapse: () => void;
onChange?: ({ step }: { step: IStep }) => void;
onSubmit?: () => void;
onContinue?: () => void;
step: IStep;
};
function serializeErrors(graphQLErrors: any) {
return graphQLErrors?.map((error: Record<string, unknown>) => {
function serializeErrors(graphQLErrors) {
return graphQLErrors?.map((error) => {
try {
return {
...error,
message: (
<pre style={{ margin: 0, whiteSpace: 'pre-wrap' }}>
{JSON.stringify(JSON.parse(error.message as string), null, 2)}
{JSON.stringify(JSON.parse(error.message), null, 2)}
</pre>
),
};
@@ -43,8 +28,7 @@ function serializeErrors(graphQLErrors: any) {
}
});
}
function TestSubstep(props: TestSubstepProps): React.ReactElement {
function TestSubstep(props) {
const {
substep,
expanded = false,
@@ -55,7 +39,6 @@ function TestSubstep(props: TestSubstepProps): React.ReactElement {
step,
showWebhookUrl = false,
} = props;
const formatMessage = useFormatMessage();
const editorContext = React.useContext(EditorContext);
const [executeFlow, { data, error, loading, called, reset }] = useMutation(
@@ -63,31 +46,25 @@ function TestSubstep(props: TestSubstepProps): React.ReactElement {
{
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]
[expanded, reset],
);
const handleSubmit = React.useCallback(() => {
if (isCompleted) {
onContinue?.();
return;
}
executeFlow({
variables: {
input: {
@@ -97,7 +74,6 @@ function TestSubstep(props: TestSubstepProps): React.ReactElement {
});
}, [onSubmit, onContinue, isCompleted, step.id]);
const onToggle = expanded ? onCollapse : onExpand;
return (
<React.Fragment>
<FlowSubstepTitle expanded={expanded} onClick={onToggle} title={name} />
@@ -115,7 +91,7 @@ function TestSubstep(props: TestSubstepProps): React.ReactElement {
severity="error"
sx={{ mb: 2, fontWeight: 500, width: '100%' }}
>
{serializeErrors(error.graphQLErrors).map((error: any) => (
{serializeErrors(error.graphQLErrors).map((error) => (
<div>{error.message}</div>
))}
</Alert>
@@ -164,5 +140,4 @@ function TestSubstep(props: TestSubstepProps): React.ReactElement {
</React.Fragment>
);
}
export default TestSubstep;