refactor(web): remove typescript
This commit is contained in:
@@ -3,33 +3,24 @@ import { useMutation } from '@apollo/client';
|
||||
import Box from '@mui/material/Box';
|
||||
import IconButton from '@mui/material/IconButton';
|
||||
import AddIcon from '@mui/icons-material/Add';
|
||||
import type { IFlow, IStep } from 'types';
|
||||
|
||||
import { GET_FLOW } from 'graphql/queries/get-flow';
|
||||
import { CREATE_STEP } from 'graphql/mutations/create-step';
|
||||
import { UPDATE_STEP } from 'graphql/mutations/update-step';
|
||||
import FlowStep from 'components/FlowStep';
|
||||
|
||||
type EditorProps = {
|
||||
flow: IFlow;
|
||||
};
|
||||
|
||||
function updateHandlerFactory(flowId: string, previousStepId: string) {
|
||||
return function createStepUpdateHandler(cache: any, mutationResult: any) {
|
||||
function updateHandlerFactory(flowId, previousStepId) {
|
||||
return function createStepUpdateHandler(cache, mutationResult) {
|
||||
const { data } = mutationResult;
|
||||
const { createStep: createdStep } = data;
|
||||
const { getFlow: flow } = cache.readQuery({
|
||||
query: GET_FLOW,
|
||||
variables: { id: flowId },
|
||||
});
|
||||
const steps = flow.steps.reduce((steps: any[], currentStep: any) => {
|
||||
const steps = flow.steps.reduce((steps, currentStep) => {
|
||||
if (currentStep.id === previousStepId) {
|
||||
return [...steps, currentStep, createdStep];
|
||||
}
|
||||
|
||||
return [...steps, currentStep];
|
||||
}, []);
|
||||
|
||||
cache.writeQuery({
|
||||
query: GET_FLOW,
|
||||
variables: { id: flowId },
|
||||
@@ -37,26 +28,20 @@ function updateHandlerFactory(flowId: string, previousStepId: string) {
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default function Editor(props: EditorProps): React.ReactElement {
|
||||
export default function Editor(props) {
|
||||
const [updateStep] = useMutation(UPDATE_STEP);
|
||||
const [createStep, { loading: creationInProgress }] = useMutation(
|
||||
CREATE_STEP,
|
||||
{
|
||||
refetchQueries: ['GetFlow'],
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const { flow } = props;
|
||||
const [triggerStep] = flow.steps;
|
||||
|
||||
const [currentStepId, setCurrentStepId] = React.useState<string | null>(
|
||||
triggerStep.id
|
||||
);
|
||||
|
||||
const [currentStepId, setCurrentStepId] = React.useState(triggerStep.id);
|
||||
const onStepChange = React.useCallback(
|
||||
(step: any) => {
|
||||
const mutationInput: Record<string, unknown> = {
|
||||
(step) => {
|
||||
const mutationInput = {
|
||||
id: step.id,
|
||||
key: step.key,
|
||||
parameters: step.parameters,
|
||||
@@ -67,16 +52,13 @@ export default function Editor(props: EditorProps): React.ReactElement {
|
||||
id: flow.id,
|
||||
},
|
||||
};
|
||||
|
||||
if (step.appKey) {
|
||||
mutationInput.appKey = step.appKey;
|
||||
}
|
||||
|
||||
updateStep({ variables: { input: mutationInput } });
|
||||
},
|
||||
[updateStep, flow.id]
|
||||
[updateStep, flow.id],
|
||||
);
|
||||
|
||||
const addStep = React.useCallback(
|
||||
async (previousStepId) => {
|
||||
const mutationInput = {
|
||||
@@ -87,24 +69,20 @@ export default function Editor(props: EditorProps): React.ReactElement {
|
||||
id: flow.id,
|
||||
},
|
||||
};
|
||||
|
||||
const createdStep = await createStep({
|
||||
variables: { input: mutationInput },
|
||||
update: updateHandlerFactory(flow.id, previousStepId),
|
||||
});
|
||||
const createdStepId = createdStep.data.createStep.id;
|
||||
|
||||
setCurrentStepId(createdStepId);
|
||||
},
|
||||
[createStep, flow.id]
|
||||
[createStep, flow.id],
|
||||
);
|
||||
|
||||
const openNextStep = React.useCallback((nextStep: IStep) => {
|
||||
const openNextStep = React.useCallback((nextStep) => {
|
||||
return () => {
|
||||
setCurrentStepId(nextStep?.id);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Box
|
||||
display="flex"
|
Reference in New Issue
Block a user