From 6d3494b1e0b2b1af10da63a7c8871b5f7cc474ab Mon Sep 17 00:00:00 2001 From: Daniel Chang Date: Wed, 24 Jan 2024 22:49:20 -0500 Subject: [PATCH] provisionally working branch duplication interaction --- .../operator/tera-operator-header.vue | 9 +++++++-- .../src/components/operator/tera-operator.vue | 4 +++- .../hmi-client/src/services/workflow.ts | 19 ++++++++++++++----- .../hmi-client/src/workflow/tera-workflow.vue | 5 +++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/packages/client/hmi-client/src/components/operator/tera-operator-header.vue b/packages/client/hmi-client/src/components/operator/tera-operator-header.vue index 10f3e25c99..96cab6a1c4 100644 --- a/packages/client/hmi-client/src/components/operator/tera-operator-header.vue +++ b/packages/client/hmi-client/src/components/operator/tera-operator-header.vue @@ -17,7 +17,12 @@ import { OperatorStatus } from '@/types/workflow'; import Button from 'primevue/button'; import Menu from 'primevue/menu'; -const emit = defineEmits(['remove-operator', 'bring-to-front', 'open-in-new-window']); +const emit = defineEmits([ + 'remove-operator', + 'bring-to-front', + 'open-in-new-window', + 'duplicate-branch' +]); const props = defineProps({ name: { @@ -46,7 +51,7 @@ const toggleMenu = (event) => { }; const options = ref([ - { icon: 'pi pi-clone', label: 'Duplicate', command: () => emit('bring-to-front') }, + { icon: 'pi pi-clone', label: 'Duplicate', command: () => emit('duplicate-branch') }, { icon: 'pi pi-external-link', label: 'Open in new window', diff --git a/packages/client/hmi-client/src/components/operator/tera-operator.vue b/packages/client/hmi-client/src/components/operator/tera-operator.vue index 2e1100a34f..078d84ab25 100644 --- a/packages/client/hmi-client/src/components/operator/tera-operator.vue +++ b/packages/client/hmi-client/src/components/operator/tera-operator.vue @@ -14,6 +14,7 @@ :interaction-status="interactionStatus" @open-in-new-window="openInNewWindow" @remove-operator="emit('remove-operator', props.node.id)" + @duplicate-branch="emit('duplicate-branch')" @bring-to-front="bringToFront" /> { registry.set(port.id, uuidv4()); }); }); + copyEdges.forEach((edge) => { + registry.set(edge.id, uuidv4()); + }); copyEdges.forEach((edge) => { // Don't replace upstream edge sources, they are still valid if (upstreamEdges.map((e) => e.source).includes(edge.source) === false) { edge.source = registry.get(edge.source as string); + edge.sourcePortId = registry.get(edge.sourcePortId as string); } + edge.id = registry.get(edge.id) as string; edge.target = registry.get(edge.target as string); - edge.sourcePortId = registry.get(edge.sourcePortId as string); edge.targetPortId = registry.get(edge.targetPortId as string); }); copyNodes.forEach((node) => { @@ -455,6 +459,9 @@ export const branchWorkflow = (wf: Workflow, nodeId: string) => { node.outputs.forEach((port) => { port.id = registry.get(port.id) as string; }); + if (node.active) { + node.active = registry.get(node.active); + } }); // 5. Reposition new nodes so they don't exaclty overlap @@ -462,10 +469,12 @@ export const branchWorkflow = (wf: Workflow, nodeId: string) => { copyNodes.forEach((n) => { n.y += offset; }); - copyEdges.forEach((e) => { - if (!e.points || e.points.length < 2) return; - e.points[0].y += offset; - e.points[e.points.length - 1].y += offset; + copyEdges.forEach((edge) => { + if (!edge.points || edge.points.length < 2) return; + if (upstreamEdges.map((e) => e.source).includes(edge.source) === false) { + edge.points[0].y += offset; + } + edge.points[edge.points.length - 1].y += offset; }); // 6. Finally put everything back into the workflow diff --git a/packages/client/hmi-client/src/workflow/tera-workflow.vue b/packages/client/hmi-client/src/workflow/tera-workflow.vue index ea8acdb117..30febcaff2 100644 --- a/packages/client/hmi-client/src/workflow/tera-workflow.vue +++ b/packages/client/hmi-client/src/workflow/tera-workflow.vue @@ -77,6 +77,7 @@ @port-mouseover="onPortMouseover" @port-mouseleave="onPortMouseleave" @remove-operator="(event) => removeNode(event)" + @duplicate-branch="duplicateBranch(node.id)" @remove-edges="removeEdges" >