From 1ff74809ca0450ade43005777562e0a5ce4b685e Mon Sep 17 00:00:00 2001
From: Leonardo Christino <lchristino@graphpolaris.com>
Date: Thu, 27 Mar 2025 16:36:54 +0000
Subject: [PATCH] fix: logic pill connection to equal another attribute did not
 trigger query call

---
 src/lib/data-access/store/sessionSlice.ts     | 48 ++++++++++---------
 .../querybuilder/model/graphology/utils.ts    |  2 +-
 2 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/src/lib/data-access/store/sessionSlice.ts b/src/lib/data-access/store/sessionSlice.ts
index e6247f734..ba839a366 100644
--- a/src/lib/data-access/store/sessionSlice.ts
+++ b/src/lib/data-access/store/sessionSlice.ts
@@ -353,37 +353,39 @@ export const selectQuerybuilderHash = (state: RootState): string => {
     return ''; // Return an empty string if no active graph exists
   }
 
-  function isEmptyLogicPill(node: any) {
-    if (node == null || node.attributes.inputs == null) return false;
-    const input = Object.values(node.attributes.inputs)[0];
-    return node.attributes.type == 'logic' && input != null && input == node.attributes.logic.input.default;
+  function isNotEmptyLogicPill(node: any) {
+    if (node == null) {
+      return false; // is empty
+    } else if (node.attributes.type !== 'logic') {
+      return true; // is not a logic
+    } else if (node.attributes.logic.numExtraInputs === 0) {
+      return true; // is a logic with no extra inputs required
+    } else if (node.attributes.inputs == null || Object.values(node.attributes.inputs).some(i => i == null || i === '')) {
+      return false; // there is a missing input to be filled in, so assume empty
+    }
+
+    return true; // default
   }
 
-  const hashedNodes = activeQuery.graph.nodes
-    .filter(n => {
-      if (isEmptyLogicPill(n)) return false;
-      return true;
-    })
-    .map(n => {
-      const node = { ...n };
-      if (n?.attributes) {
-        const newAttributes = { ...n?.attributes };
-        newAttributes.x = 0;
-        newAttributes.y = 0;
-        newAttributes.height = 0;
-        newAttributes.width = 0;
-        node.attributes = newAttributes;
-      }
-      return node;
-    });
+  const hashedNodes = activeQuery.graph.nodes.filter(isNotEmptyLogicPill).map(n => {
+    const node = { ...n };
+    if (n?.attributes) {
+      const newAttributes = { ...n?.attributes };
+      newAttributes.x = 0;
+      newAttributes.y = 0;
+      newAttributes.height = 0;
+      newAttributes.width = 0;
+      node.attributes = newAttributes;
+    }
+    return node;
+  });
 
   const ret = {
     nodes: hashedNodes,
     edges: activeQuery.graph.edges
       .filter(e => {
         const targetNode = activeQuery.graph.nodes.find(n => n.key == e.target);
-        if (isEmptyLogicPill(targetNode)) return false;
-        return true;
+        return isNotEmptyLogicPill(targetNode);
       })
       .map(n => ({
         key: n.key,
diff --git a/src/lib/querybuilder/model/graphology/utils.ts b/src/lib/querybuilder/model/graphology/utils.ts
index f259c21b1..7f4fc96ae 100644
--- a/src/lib/querybuilder/model/graphology/utils.ts
+++ b/src/lib/querybuilder/model/graphology/utils.ts
@@ -126,7 +126,7 @@ export class QueryMultiGraphology extends MultiGraph<QueryGraphNodes, QueryGraph
         attributes.logic.inputs.forEach((input, i) => {
           // Setup default non-linked inputs as regular values matching the input expected type
           if (!attributes.inputs) attributes.inputs = {};
-          attributes.inputs[input.name] = inputValues?.[input.name] || input.default;
+          attributes.inputs[input.name] = inputValues?.[input.name] || input.default || '';
         });
         // (attributes as LogicNodeAttributes).leftEntityHandleId = getHandleId(attributes.id, name, type, Handles.RelationLeft, '');
         // (attributes as LogicNodeAttributes).rightEntityHandleId = getHandleId(attributes.id, name, type, Handles.RelationRight, '');
-- 
GitLab