From fb04f4f163e61b94c0d088863a8ac8afb468cf53 Mon Sep 17 00:00:00 2001
From: Alvin Noe Ladines <ladinesalvinnoe@gmail.com>
Date: Wed, 19 Feb 2025 10:05:55 +0000
Subject: [PATCH] Resolve "create edges in the workflow"

Changelog: Added
---
 .../components/entry/properties/WorkflowCard.js  | 16 ++++++++++------
 nomad/datamodel/metainfo/workflow.py             | 11 ++++++++++-
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/gui/src/components/entry/properties/WorkflowCard.js b/gui/src/components/entry/properties/WorkflowCard.js
index 2e8eb39577..4af8bfd82b 100644
--- a/gui/src/components/entry/properties/WorkflowCard.js
+++ b/gui/src/components/entry/properties/WorkflowCard.js
@@ -203,6 +203,15 @@ const getLinks = async (source, query) => {
   const isLinked = (source, target) => {
     if (source.url === target.url) return false
 
+    const inputs = []
+    if (target.type === 'tasks' && target.nodes) {
+      inputs.push(...target.nodes.filter(node => node.type && node.type.startsWith('inputs')).map(node => node.url))
+    } else {
+      inputs.push(target.url)
+    }
+
+    if (inputs.includes(source.url)) return true
+
     const outputs = []
     if (source.type === 'tasks' && source.nodes) {
       outputs.push(...source.nodes.filter(node => node.type === 'outputs').map(node => node.url))
@@ -210,12 +219,7 @@ const getLinks = async (source, query) => {
       outputs.push(source.url)
     }
 
-    const inputs = []
-    if (target.type === 'tasks' && target.nodes) {
-      inputs.push(...target.nodes.filter(node => node.type && node.type.startsWith('inputs')).map(node => node.url))
-    } else {
-      inputs.push(target.url)
-    }
+    if (outputs.includes(target.url)) return true
 
     let linked = false
     for (const output of outputs) {
diff --git a/nomad/datamodel/metainfo/workflow.py b/nomad/datamodel/metainfo/workflow.py
index a77f0af398..2f446ebaee 100644
--- a/nomad/datamodel/metainfo/workflow.py
+++ b/nomad/datamodel/metainfo/workflow.py
@@ -98,9 +98,18 @@ class TaskReference(Task):
 
     def normalize(self, archive, logger):
         super().normalize(archive, logger)
-        if not self.name and self.task:
+        if self.task is None:
+            return
+
+        if not self.name:
             self.name = self.task.name
 
+        # add task inputs/outputs to inputs/outputs
+        self.inputs.extend([inp for inp in self.task.inputs if inp not in self.inputs])
+        self.outputs.extend(
+            [out for out in self.task.outputs if out not in self.outputs]
+        )
+
 
 class Workflow(Task, EntryData):
     """
-- 
GitLab