From 47ba3eb02361876699a13560aa97659be66f3eb7 Mon Sep 17 00:00:00 2001 From: Devessier Date: Mon, 7 Oct 2024 12:33:30 +0200 Subject: [PATCH] feat: replace the trigger and steps of the current draft version if one exists --- .../RecordShowPageWorkflowVersionHeader.tsx | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/twenty-front/src/modules/workflow/components/RecordShowPageWorkflowVersionHeader.tsx b/packages/twenty-front/src/modules/workflow/components/RecordShowPageWorkflowVersionHeader.tsx index 39fe17403c3d..47d93311d437 100644 --- a/packages/twenty-front/src/modules/workflow/components/RecordShowPageWorkflowVersionHeader.tsx +++ b/packages/twenty-front/src/modules/workflow/components/RecordShowPageWorkflowVersionHeader.tsx @@ -1,5 +1,6 @@ import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords'; +import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord'; import { Button } from '@/ui/input/button/components/Button'; import { useActivateWorkflowVersion } from '@/workflow/hooks/useActivateWorkflowVersion'; import { useCreateNewWorkflowVersion } from '@/workflow/hooks/useCreateNewWorkflowVersion'; @@ -46,6 +47,11 @@ export const RecordShowPageWorkflowVersionHeader = ({ const { deactivateWorkflowVersion } = useDeactivateWorkflowVersion(); const { createNewWorkflowVersion } = useCreateNewWorkflowVersion(); + const { updateOneRecord: updateOneWorkflowVersion } = + useUpdateOneRecord({ + objectNameSingular: CoreObjectNameSingular.WorkflowVersion, + }); + return ( <> {showUseAsDraftButton ? ( @@ -54,14 +60,24 @@ export const RecordShowPageWorkflowVersionHeader = ({ variant="secondary" Icon={IconPencil} disabled={isWaitingForWorkflowVersion} - onClick={() => { - return createNewWorkflowVersion({ - workflowId: workflowVersion.workflow.id, - name: `v${workflowVersion.workflow.versions.length + 1}`, - status: 'DRAFT', - trigger: workflowVersion.trigger, - steps: workflowVersion.steps, - }); + onClick={async () => { + if (hasAlreadyDraftVersion) { + await updateOneWorkflowVersion({ + idToUpdate: draftWorkflowVersions[0].id, + updateOneRecordInput: { + trigger: workflowVersion.trigger, + steps: workflowVersion.steps, + }, + }); + } else { + await createNewWorkflowVersion({ + workflowId: workflowVersion.workflow.id, + name: `v${workflowVersion.workflow.versions.length + 1}`, + status: 'DRAFT', + trigger: workflowVersion.trigger, + steps: workflowVersion.steps, + }); + } }} /> ) : null}