-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Move the workflow draft version overriding to the backend #9328
Move the workflow draft version overriding to the backend #9328
Conversation
packages/twenty-server/src/engine/core-modules/workflow/dtos/override-workflow-draft-version.ts
Outdated
Show resolved
Hide resolved
...er/src/modules/workflow/common/workspace-services/workflow-version-step.workspace-service.ts
Outdated
Show resolved
Hide resolved
...twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts
Show resolved
Hide resolved
6694098
to
70261ad
Compare
70261ad
to
9299f08
Compare
…ting steps and trigger
…low id instead of the current draft workflow version id
if ( | ||
fieldMetadata.type === FieldMetadataType.RAW_JSON && | ||
typeof value === 'string' | ||
) { | ||
return JSON.parse(value as string); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discussed this change with @Weiko
Hi @martmull! I would be glad if you could look at my PR when you return to work. It's related to serverless functions, and I want to confirm everything is okay for you. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR moves workflow draft version overriding functionality from frontend to backend, improving architecture and data handling.
- Added new
overrideWorkflowDraftVersion
mutation in/packages/twenty-server/src/engine/core-modules/workflow/resolvers/workflow-version-step.resolver.ts
to handle draft version management - Added
copyOneServerlessFunction
method inserverless-function.service.ts
to properly duplicate serverless functions when copying workflow steps - Modified
formatFieldMetadataValue
in/packages/twenty-server/src/engine/twenty-orm/utils/format-data.util.ts
to handle unserialized JSON data for TypeORM's save() method - Added type safety with
assertWorkflowVersionHasSteps
utility in/packages/twenty-server/src/modules/workflow/common/utils/assert-workflow-version-has-steps.ts
- Updated frontend components to use new backend mutation instead of handling draft version creation client-side
13 file(s) reviewed, 18 comment(s)
Edit PR Review Bot Settings | Greptile
...gle-record/workflow-version-actions/hooks/useUseAsDraftWorkflowVersionSingleRecordAction.tsx
Outdated
Show resolved
Hide resolved
await overrideWorkflowDraftVersion({ | ||
workflowId: workflowVersion.workflow.id, | ||
name: `v${workflowVersion.workflow.versions.length + 1}`, | ||
status: 'DRAFT', | ||
trigger: workflowVersion.trigger, | ||
steps: workflowVersion.steps, | ||
workflowVersionIdToCopy: workflowVersion.id, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: No error handling for failed override operation. Consider wrapping in try/catch.
mutation OverrideWorkflowDraftVersion( | ||
$input: OverrideWorkflowDraftVersionInput! | ||
) { | ||
overrideWorkflowDraftVersion(input: $input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: mutation response type is not specified - should define exact return type for better type safety
@@ -9,7 +9,7 @@ export const getServerlessFolder = ({ | |||
version, | |||
}: { | |||
serverlessFunction: ServerlessFunctionEntity; | |||
version?: string; | |||
version?: 'draft' | 'latest' | (string & NonNullable<unknown>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: The type string & NonNullable<unknown>
is redundant since string is already non-nullable. Consider using just string
or creating a specific type/enum for versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure this change helps a lot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use constants instead of hard-coded strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't because version can be '1', '2', etc...
description: 'Workflow version ID', | ||
nullable: false, | ||
}) | ||
workflowVersionIdToCopy: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: field name 'workflowVersionIdToCopy' could be more concise, e.g. 'sourceVersionId'
): asserts workflowVersion is WorkflowVersionWorkspaceEntity & { | ||
steps: WorkflowAction[]; | ||
} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: assertion type could be more specific by using Required<Pick<WorkflowVersionWorkspaceEntity, 'steps'>> to ensure steps property exists
if (Array.isArray(draftWorkflowVersion.steps)) { | ||
await Promise.all( | ||
draftWorkflowVersion.steps.map((step) => | ||
this.runWorkflowVersionStepDeletionSideEffects({ | ||
step, | ||
workspaceId, | ||
}), | ||
), | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: potential race condition if multiple deletion operations fail - consider using Promise.allSettled and handling partial failures
...er/src/modules/workflow/common/workspace-services/workflow-version-step.workspace-service.ts
Outdated
Show resolved
Hide resolved
return stepToDelete; | ||
} | ||
|
||
async overrideWorkflowDraftVersion({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: no return type specified for overrideWorkflowDraftVersion method
for (const step of workflowVersionToCopy.steps) { | ||
const duplicatedStep = await this.duplicateStep({ | ||
step, | ||
workspaceId, | ||
}); | ||
|
||
newWorkflowVersionSteps.push(duplicatedStep); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: duplicating steps sequentially could be slow for large workflows - consider using Promise.all for parallel execution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice code, I left some minor comments but the overall logic looks good to me
...gle-record/workflow-version-actions/hooks/useUseAsDraftWorkflowVersionSingleRecordAction.tsx
Outdated
Show resolved
Hide resolved
@@ -9,7 +9,7 @@ export const getServerlessFolder = ({ | |||
version, | |||
}: { | |||
serverlessFunction: ServerlessFunctionEntity; | |||
version?: string; | |||
version?: 'draft' | 'latest' | (string & NonNullable<unknown>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure this change helps a lot
...twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts
Outdated
Show resolved
Hide resolved
...twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts
Outdated
Show resolved
Hide resolved
...er/src/modules/workflow/common/workspace-services/workflow-version-step.workspace-service.ts
Outdated
Show resolved
Hide resolved
We want to rename the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work 🔥
}); | ||
} | ||
|
||
assertWorkflowVersionIsDraft(draftWorkflowVersion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be in else {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log
|
formatFieldMetadataValue
function, allow people to call TypeORM'ssave()
method with unserialized JSON data.overrideWorkflowDraftVersion
mutation that takes a workflow id and the id of the workflow version to use as the new draftoverrideWorkflowDraftVersion
mutation in the old workflow header and in the new Cmd+K actions