-
Notifications
You must be signed in to change notification settings - Fork 5.7k
If else node followup changes #16974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
e6677c7
b880eb3
0ef56fa
ec18f65
85808f4
403724b
4d0150e
813185b
5fdeda7
b8cb712
0bbfdcd
3d42f38
ef982c5
4157ef9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient'; | ||
| import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; | ||
| import { useFindOneRecordQuery } from '@/object-record/hooks/useFindOneRecordQuery'; | ||
| import { DELETE_WORKFLOW_VERSION_STEP } from '@/workflow/graphql/mutations/deleteWorkflowVersionStep'; | ||
| import { useUpdateWorkflowVersionCache } from '@/workflow/workflow-steps/hooks/useUpdateWorkflowVersionCache'; | ||
| import { useMutation } from '@apollo/client'; | ||
|
|
@@ -13,6 +15,11 @@ export const useDeleteWorkflowVersionStep = () => { | |
|
|
||
| const { updateWorkflowVersionCache } = useUpdateWorkflowVersionCache(); | ||
|
|
||
| const { findOneRecordQuery: findOneWorkflowVersionQuery } = | ||
| useFindOneRecordQuery({ | ||
| objectNameSingular: CoreObjectNameSingular.WorkflowVersion, | ||
| }); | ||
|
|
||
| const [mutate] = useMutation< | ||
| DeleteWorkflowVersionStepMutation, | ||
| DeleteWorkflowVersionStepMutationVariables | ||
|
|
@@ -23,7 +30,16 @@ export const useDeleteWorkflowVersionStep = () => { | |
| const deleteWorkflowVersionStep = async ( | ||
| input: DeleteWorkflowVersionStepInput, | ||
| ) => { | ||
| const result = await mutate({ variables: { input } }); | ||
| const result = await mutate({ | ||
| variables: { input }, | ||
| awaitRefetchQueries: true, | ||
| refetchQueries: [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we stop removing the empty node, we can remove that refetch logic. Updating cache will be enough
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @FelixMalfait suggested that we should remove the empty nodes. LMK what should we do @thomtrp ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's keep it for now |
||
| { | ||
| query: findOneWorkflowVersionQuery, | ||
| variables: { objectRecordId: input.workflowVersionId }, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| const workflowVersionStepChanges = result?.data?.deleteWorkflowVersionStep; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import { isDefined } from 'twenty-shared/utils'; | ||
| import { TRIGGER_STEP_ID } from 'twenty-shared/workflow'; | ||
| import { TRIGGER_STEP_ID, type StepIfElseBranch } from 'twenty-shared/workflow'; | ||
|
|
||
| import { isWorkflowEmptyAction } from 'src/modules/workflow/workflow-executor/workflow-actions/empty/guards/is-workflow-empty-action.guard'; | ||
| import { isWorkflowIfElseAction } from 'src/modules/workflow/workflow-executor/workflow-actions/if-else/guards/is-workflow-if-else-action.guard'; | ||
| import { | ||
| type WorkflowAction, | ||
| WorkflowActionType, | ||
| type WorkflowAction, | ||
| } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type'; | ||
| import { type WorkflowTrigger } from 'src/modules/workflow/workflow-trigger/types/workflow-trigger.type'; | ||
|
|
||
|
|
@@ -29,6 +31,22 @@ const computeUpdatedNextStepIds = ({ | |
| ]; | ||
| }; | ||
|
|
||
| export const getEmptyChildStepIdsForIfElse = ({ | ||
| branches, | ||
| allSteps, | ||
| }: { | ||
| branches: StepIfElseBranch[]; | ||
| allSteps: WorkflowAction[]; | ||
| }): string[] => { | ||
| const childStepIds = branches.flatMap((branch) => branch.nextStepIds); | ||
|
|
||
| return childStepIds.filter((childStepId) => { | ||
| const childStep = allSteps.find((step) => step.id === childStepId); | ||
|
|
||
| return isDefined(childStep) && isWorkflowEmptyAction(childStep); | ||
| }); | ||
| }; | ||
|
|
||
| export const removeStep = ({ | ||
| existingTrigger, | ||
| existingSteps, | ||
|
|
@@ -48,17 +66,66 @@ export const removeStep = ({ | |
| }; | ||
| } | ||
|
|
||
| const stepToDelete = existingSteps?.find( | ||
| (step) => step.id === stepIdToDelete, | ||
| ); | ||
|
|
||
| let emptyChildStepIds: string[] = []; | ||
|
|
||
| if ( | ||
| isDefined(stepToDelete) && | ||
| isWorkflowIfElseAction(stepToDelete) && | ||
| isDefined(existingSteps) | ||
| ) { | ||
| emptyChildStepIds = getEmptyChildStepIdsForIfElse({ | ||
| branches: stepToDelete.settings.input.branches, | ||
| allSteps: existingSteps, | ||
| }); | ||
| } | ||
|
|
||
| const allRemovedStepIds = [stepIdToDelete, ...emptyChildStepIds]; | ||
|
|
||
| const allStepToDeleteChildrenIds = [ | ||
| ...(stepToDeleteChildrenIds || []), | ||
| ...emptyChildStepIds, | ||
| ]; | ||
|
||
|
|
||
| const updatedSteps = | ||
| existingSteps | ||
| ?.filter((step) => step.id !== stepIdToDelete) | ||
| ?.filter((step) => !allRemovedStepIds.includes(step.id)) | ||
| .map((step) => { | ||
| if ( | ||
| step.type === WorkflowActionType.IF_ELSE && | ||
| isWorkflowIfElseAction(step) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This behavior looks huge and is not consistent with iterators. For iterators, we let the user remove the empty node. The user can delete it by himself. I think we can do that for now and see if user complain. Wdyt?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok let's keep it for now. We'll see if we do the same for iterators at some point |
||
| ) { | ||
| const updatedBranches = step.settings.input.branches.map( | ||
| (branch) => ({ | ||
| ...branch, | ||
| nextStepIds: branch.nextStepIds.filter( | ||
abdulrahmancodes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (id) => !allRemovedStepIds.includes(id), | ||
| ), | ||
| }), | ||
| ); | ||
|
|
||
| return { | ||
| ...step, | ||
| settings: { | ||
| ...step.settings, | ||
| input: { | ||
| ...step.settings.input, | ||
| branches: updatedBranches, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| if (step.nextStepIds?.includes(stepIdToDelete)) { | ||
| return { | ||
| ...step, | ||
| nextStepIds: computeUpdatedNextStepIds({ | ||
| existingNextStepIds: step.nextStepIds, | ||
| stepIdToRemove: stepIdToDelete, | ||
| stepToDeleteChildrenIds: stepToDeleteChildrenIds, | ||
| stepToDeleteChildrenIds: allStepToDeleteChildrenIds, | ||
| }), | ||
| }; | ||
| } | ||
|
|
@@ -77,7 +144,7 @@ export const removeStep = ({ | |
| initialLoopStepIds: computeUpdatedNextStepIds({ | ||
| existingNextStepIds: step.settings.input.initialLoopStepIds, | ||
| stepIdToRemove: stepIdToDelete, | ||
| stepToDeleteChildrenIds: stepToDeleteChildrenIds, | ||
| stepToDeleteChildrenIds: allStepToDeleteChildrenIds, | ||
| }), | ||
| }, | ||
| }, | ||
|
|
@@ -96,7 +163,7 @@ export const removeStep = ({ | |
| nextStepIds: computeUpdatedNextStepIds({ | ||
| existingNextStepIds: existingTrigger.nextStepIds, | ||
| stepIdToRemove: stepIdToDelete, | ||
| stepToDeleteChildrenIds, | ||
| stepToDeleteChildrenIds: allStepToDeleteChildrenIds, | ||
| }), | ||
| }; | ||
| } | ||
|
|
@@ -105,6 +172,6 @@ export const removeStep = ({ | |
| return { | ||
| updatedSteps, | ||
| updatedTrigger, | ||
| removedStepIds: [stepIdToDelete], | ||
| removedStepIds: allRemovedStepIds, | ||
| }; | ||
| }; | ||
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.