Update workflow nodes configuration (#6861)
- Improve the design of the right drawer - Allow to update the trigger of the workflow: the object and the event listened to - Allow to update the selected serverless function that a code action should execute - Change how we determine which workflow version to display in the visualizer. We fetch the selected workflow's data, including whether it has a draft or a published version. If the workflow has a draft version, it gets displayed; otherwise, we display the last published version. - I used the type `WorkflowWithCurrentVersion` to forward the currently edited workflow with its _current_ version embedded across the app. - I created single-responsibility hooks like `useFindWorkflowWithCurrentVersion`, `useFindShowPageWorkflow`, `useUpdateWorkflowVersionTrigger` or `useUpdateWorkflowVersionStep`. - I updated the types for workflow related objects, like `Workflow` and `WorkflowVersion`. See `packages/twenty-front/src/modules/workflow/types/Workflow.ts`. - This introduced the possibility to have `null` values for triggers and steps. I made the according changes in the codebase and in the tests. - I created a utility function to extract both parts of object-event format (`company.created`): `packages/twenty-front/src/modules/workflow/utils/splitWorkflowTriggerEventName.ts`
This commit is contained in:
committed by
GitHub
parent
c55dfbde6e
commit
a2b1062db6
@ -0,0 +1,88 @@
|
||||
import { WorkflowEditActionForm } from '@/workflow/components/WorkflowEditActionForm';
|
||||
import { WorkflowEditTriggerForm } from '@/workflow/components/WorkflowEditTriggerForm';
|
||||
import { TRIGGER_STEP_ID } from '@/workflow/constants/TriggerStepId';
|
||||
import { useUpdateWorkflowVersionStep } from '@/workflow/hooks/useUpdateWorkflowVersionStep';
|
||||
import { useUpdateWorkflowVersionTrigger } from '@/workflow/hooks/useUpdateWorkflowVersionTrigger';
|
||||
import { workflowSelectedNodeState } from '@/workflow/states/workflowSelectedNodeState';
|
||||
import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow';
|
||||
import { findStepPositionOrThrow } from '@/workflow/utils/findStepPositionOrThrow';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { isDefined } from 'twenty-ui';
|
||||
|
||||
const getStepDefinitionOrThrow = ({
|
||||
stepId,
|
||||
workflow,
|
||||
}: {
|
||||
stepId: string;
|
||||
workflow: WorkflowWithCurrentVersion;
|
||||
}) => {
|
||||
const currentVersion = workflow.currentVersion;
|
||||
if (!isDefined(currentVersion)) {
|
||||
throw new Error('Expected to find a current version');
|
||||
}
|
||||
|
||||
if (stepId === TRIGGER_STEP_ID) {
|
||||
if (!isDefined(currentVersion.trigger)) {
|
||||
throw new Error('Expected to find the definition of the trigger');
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'trigger',
|
||||
definition: currentVersion.trigger,
|
||||
} as const;
|
||||
}
|
||||
|
||||
if (!isDefined(currentVersion.steps)) {
|
||||
throw new Error('Expected to find an array of steps');
|
||||
}
|
||||
|
||||
const selectedNodePosition = findStepPositionOrThrow({
|
||||
steps: currentVersion.steps,
|
||||
stepId: stepId,
|
||||
});
|
||||
|
||||
return {
|
||||
type: 'action',
|
||||
definition: selectedNodePosition.steps[selectedNodePosition.index],
|
||||
} as const;
|
||||
};
|
||||
|
||||
export const RightDrawerWorkflowEditStepContent = ({
|
||||
workflow,
|
||||
}: {
|
||||
workflow: WorkflowWithCurrentVersion;
|
||||
}) => {
|
||||
const workflowSelectedNode = useRecoilValue(workflowSelectedNodeState);
|
||||
if (!isDefined(workflowSelectedNode)) {
|
||||
throw new Error(
|
||||
'Expected a node to be selected. Selecting a node is mandatory to edit it.',
|
||||
);
|
||||
}
|
||||
|
||||
const { updateTrigger } = useUpdateWorkflowVersionTrigger({ workflow });
|
||||
const { updateStep } = useUpdateWorkflowVersionStep({
|
||||
workflow,
|
||||
stepId: workflowSelectedNode,
|
||||
});
|
||||
|
||||
const stepDefinition = getStepDefinitionOrThrow({
|
||||
stepId: workflowSelectedNode,
|
||||
workflow,
|
||||
});
|
||||
|
||||
if (stepDefinition.type === 'trigger') {
|
||||
return (
|
||||
<WorkflowEditTriggerForm
|
||||
trigger={stepDefinition.definition}
|
||||
onUpdateTrigger={updateTrigger}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<WorkflowEditActionForm
|
||||
action={stepDefinition.definition}
|
||||
onUpdateAction={updateStep}
|
||||
/>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user