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:
committed by
GitHub
parent
3c4168759a
commit
3548751be2
@ -7,7 +7,7 @@ describe('getWorkflowVersionDiagram', () => {
|
||||
expect(result).toEqual({ nodes: [], edges: [] });
|
||||
});
|
||||
|
||||
it('returns an empty diagram if the provided workflow version has no trigger', () => {
|
||||
it('returns a diagram with an empty-trigger node if the provided workflow version has no trigger', () => {
|
||||
const result = getWorkflowVersionDiagram({
|
||||
__typename: 'WorkflowVersion',
|
||||
status: 'ACTIVE',
|
||||
@ -20,10 +20,20 @@ describe('getWorkflowVersionDiagram', () => {
|
||||
workflowId: '',
|
||||
});
|
||||
|
||||
expect(result).toEqual({ nodes: [], edges: [] });
|
||||
expect(result).toEqual({
|
||||
nodes: [
|
||||
{
|
||||
data: {},
|
||||
id: 'trigger',
|
||||
position: { x: 0, y: 0 },
|
||||
type: 'empty-trigger',
|
||||
},
|
||||
],
|
||||
edges: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an empty diagram if the provided workflow version has no steps', () => {
|
||||
it('returns a diagram with an empty-trigger node if the provided workflow version has no steps', () => {
|
||||
const result = getWorkflowVersionDiagram({
|
||||
__typename: 'WorkflowVersion',
|
||||
status: 'ACTIVE',
|
||||
@ -39,7 +49,19 @@ describe('getWorkflowVersionDiagram', () => {
|
||||
workflowId: '',
|
||||
});
|
||||
|
||||
expect(result).toEqual({ nodes: [], edges: [] });
|
||||
expect(result).toEqual({
|
||||
nodes: [
|
||||
{
|
||||
data: {
|
||||
label: 'Company is Created',
|
||||
nodeType: 'trigger',
|
||||
},
|
||||
id: 'trigger',
|
||||
position: { x: 0, y: 0 },
|
||||
},
|
||||
],
|
||||
edges: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the diagram for the last version', () => {
|
||||
|
||||
@ -7,6 +7,7 @@ import {
|
||||
} from '@/workflow/types/WorkflowDiagram';
|
||||
import { splitWorkflowTriggerEventName } from '@/workflow/utils/splitWorkflowTriggerEventName';
|
||||
import { MarkerType } from '@xyflow/react';
|
||||
import { isDefined } from 'twenty-ui';
|
||||
import { v4 } from 'uuid';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
@ -14,7 +15,7 @@ export const generateWorkflowDiagram = ({
|
||||
trigger,
|
||||
steps,
|
||||
}: {
|
||||
trigger: WorkflowTrigger;
|
||||
trigger: WorkflowTrigger | undefined;
|
||||
steps: Array<WorkflowStep>;
|
||||
}): WorkflowDiagram => {
|
||||
const nodes: Array<WorkflowDiagramNode> = [];
|
||||
@ -55,20 +56,34 @@ export const generateWorkflowDiagram = ({
|
||||
|
||||
// Start with the trigger node
|
||||
const triggerNodeId = TRIGGER_STEP_ID;
|
||||
const triggerEvent = splitWorkflowTriggerEventName(
|
||||
trigger.settings.eventName,
|
||||
);
|
||||
nodes.push({
|
||||
id: triggerNodeId,
|
||||
data: {
|
||||
nodeType: 'trigger',
|
||||
label: `${capitalize(triggerEvent.objectType)} is ${capitalize(triggerEvent.event)}`,
|
||||
},
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
});
|
||||
|
||||
if (isDefined(trigger)) {
|
||||
const triggerEvent = splitWorkflowTriggerEventName(
|
||||
trigger.settings.eventName,
|
||||
);
|
||||
|
||||
nodes.push({
|
||||
id: triggerNodeId,
|
||||
data: {
|
||||
nodeType: 'trigger',
|
||||
label: `${capitalize(triggerEvent.objectType)} is ${capitalize(triggerEvent.event)}`,
|
||||
},
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
nodes.push({
|
||||
id: triggerNodeId,
|
||||
type: 'empty-trigger',
|
||||
data: {} as any,
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
let lastStepId = triggerNodeId;
|
||||
|
||||
|
||||
@ -11,18 +11,12 @@ const EMPTY_DIAGRAM: WorkflowDiagram = {
|
||||
export const getWorkflowVersionDiagram = (
|
||||
workflowVersion: WorkflowVersion | undefined,
|
||||
): WorkflowDiagram => {
|
||||
if (
|
||||
!(
|
||||
isDefined(workflowVersion) &&
|
||||
isDefined(workflowVersion.trigger) &&
|
||||
isDefined(workflowVersion.steps)
|
||||
)
|
||||
) {
|
||||
if (!isDefined(workflowVersion)) {
|
||||
return EMPTY_DIAGRAM;
|
||||
}
|
||||
|
||||
return generateWorkflowDiagram({
|
||||
trigger: workflowVersion.trigger,
|
||||
steps: workflowVersion.steps,
|
||||
trigger: workflowVersion.trigger ?? undefined,
|
||||
steps: workflowVersion.steps ?? [],
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user