- Add the SAVE_EMAIL action. This action requires more setting parameters than the Serverless Function action. - Changed the way we computed the workflow diagram. It now preserves some properties, like the `selected` property. That's necessary to not close the right drawer when the workflow back-end data change. - Added the possibility to set a label to a TextArea. This uses a `<label>` HTML element and the `useId()` hook to create an id linking the label with the input.
34 lines
924 B
TypeScript
34 lines
924 B
TypeScript
import {
|
|
WorkflowDiagram,
|
|
WorkflowDiagramNode,
|
|
} from '@/workflow/types/WorkflowDiagram';
|
|
|
|
const nodePropertiesToPreserve: Array<keyof WorkflowDiagramNode> = ['selected'];
|
|
|
|
export const mergeWorkflowDiagrams = (
|
|
previousDiagram: WorkflowDiagram,
|
|
nextDiagram: WorkflowDiagram,
|
|
): WorkflowDiagram => {
|
|
const lastNodes = nextDiagram.nodes.map((nextNode) => {
|
|
const previousNode = previousDiagram.nodes.find(
|
|
(previousNode) => previousNode.id === nextNode.id,
|
|
);
|
|
|
|
const nodeWithPreservedProperties = nodePropertiesToPreserve.reduce(
|
|
(nodeToSet, propertyToPreserve) => {
|
|
return Object.assign(nodeToSet, {
|
|
[propertyToPreserve]: previousNode?.[propertyToPreserve],
|
|
});
|
|
},
|
|
{} as Partial<WorkflowDiagramNode>,
|
|
);
|
|
|
|
return Object.assign(nodeWithPreservedProperties, nextNode);
|
|
});
|
|
|
|
return {
|
|
nodes: lastNodes,
|
|
edges: nextDiagram.edges,
|
|
};
|
|
};
|