Scaffold empty workflow (#6926)

- Create a workflow version when the user visits an empty workflow.
- If the trigger is not defined yet and the user selects either the
standard object type or the event type first, we automatically select
the first option of the other value. Indeed, every state update is
automatically saved on the backend and we need both standard object and
event types to save the event name.
- Introduces a change in the backend. I removed the assertions that
throw when a workflow version is not complete, that is, when it doesn't
have a defined trigger, which is the case when scaffolding a new
workflow with a first empty workflow version.
- We should keep validating the workflow versions, at least when we
publish them. That should be done in a second step.
This commit is contained in:
Baptiste Devessier
2024-09-12 17:01:10 +02:00
committed by GitHub
parent 3c4168759a
commit 3548751be2
26 changed files with 548 additions and 269 deletions

View File

@ -6,6 +6,7 @@ import {
WorkflowVersion,
WorkflowWithCurrentVersion,
} from '@/workflow/types/Workflow';
import { useMemo } from 'react';
import { isDefined } from 'twenty-ui';
export const useWorkflowWithCurrentVersion = (
@ -22,34 +23,37 @@ export const useWorkflowWithCurrentVersion = (
skip: !isDefined(workflowId),
});
const { records: mostRecentWorkflowVersions } =
useFindManyRecords<WorkflowVersion>({
objectNameSingular: CoreObjectNameSingular.WorkflowVersion,
filter: {
workflowId: {
eq: workflowId,
},
const {
records: mostRecentWorkflowVersions,
loading: loadingMostRecentWorkflowVersions,
} = useFindManyRecords<WorkflowVersion>({
objectNameSingular: CoreObjectNameSingular.WorkflowVersion,
filter: {
workflowId: {
eq: workflowId,
},
orderBy: [
{
createdAt: 'DescNullsLast',
},
],
limit: 1,
skip: !isDefined(workflowId),
});
},
orderBy: [
{
createdAt: 'DescNullsLast',
},
],
limit: 1,
skip: !isDefined(workflowId),
});
if (!isDefined(workflow)) {
return undefined;
}
const workflowWithCurrentVersion = useMemo(() => {
if (!isDefined(workflow) || loadingMostRecentWorkflowVersions) {
return undefined;
}
const currentVersion = mostRecentWorkflowVersions?.[0];
if (!isDefined(currentVersion)) {
return undefined;
}
const currentVersion = mostRecentWorkflowVersions?.[0];
return {
...workflow,
currentVersion,
};
return {
...workflow,
currentVersion,
};
}, [loadingMostRecentWorkflowVersions, mostRecentWorkflowVersions, workflow]);
return workflowWithCurrentVersion;
};