Skip to content

Commit

Permalink
refactor: reuse utility function to find a step
Browse files Browse the repository at this point in the history
  • Loading branch information
Devessier committed Sep 2, 2024
1 parent 284ef5d commit 3319d0b
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
WorkflowVersion,
WorkflowWithCurrentVersion,
} from '@/workflow/types/Workflow';
import { findStepPositionOrThrow } from '@/workflow/utils/findStepPositionOrThrow';
import { replaceStep } from '@/workflow/utils/replaceStep';
import { useRecoilValue } from 'recoil';
import { isDefined } from 'twenty-ui';
Expand Down Expand Up @@ -34,16 +35,18 @@ const getStepDefinition = ({
} as const;
}

const selectedNodeDefinition = currentVersion.steps?.find(
(step) => step.id === stepId,
);
if (selectedNodeDefinition === undefined) {
if (!isDefined(currentVersion.steps)) {
return undefined;
}

const selectedNodePosition = findStepPositionOrThrow({
steps: currentVersion.steps,
stepId: stepId,
});

return {
type: 'action',
definition: selectedNodeDefinition,
definition: selectedNodePosition.steps[selectedNodePosition.index],
} as const;
};

Expand Down

0 comments on commit 3319d0b

Please sign in to comment.