From d7260b709b680f79b81804c2a402a511107da63c Mon Sep 17 00:00:00 2001 From: frikky Date: Tue, 28 Jun 2022 20:41:35 +0200 Subject: [PATCH] Fixed issues with names in conditions when changing --- backend/app_sdk/app_base.py | 4 +- frontend/src/components/ParsedAction.jsx | 112 +++++++++++++++++++++++ frontend/src/views/AngularWorkflow.jsx | 6 +- 3 files changed, 117 insertions(+), 5 deletions(-) diff --git a/backend/app_sdk/app_base.py b/backend/app_sdk/app_base.py index 354a6c55..23bde802 100644 --- a/backend/app_sdk/app_base.py +++ b/backend/app_sdk/app_base.py @@ -2025,7 +2025,6 @@ class AppBase: errors = False error_msg = "" try: - #self.logger.info("In liquid") if len(template) > 10000000: self.logger.info("[DEBUG] Skipping liquid - size too big (%d)" % len(template)) return template @@ -2240,7 +2239,6 @@ class AppBase: #self.logger.info("STATIC PARSED: %s" % actualitem) #self.logger.info("[INFO] Done with regex matching") if len(actualitem) > 0: - #self.logger.info("[DEBUG] Matches: ", actualitem) for replace in actualitem: try: to_be_replaced = replace[0] @@ -2798,7 +2796,7 @@ class AppBase: })) if parameter["name"] == "body": - self.logger.info("[INFO] Should debug field with liquid and other checks as it's BODY: %s" % value) + self.logger.info(f"[INFO] Should debug field with liquid and other checks as it's BODY: {value}") # Custom format for ${name[0,1,2,...]}$ #submatch = "([${]{2}([0-9a-zA-Z_-]+)(\[.*\])[}$]{2})" diff --git a/frontend/src/components/ParsedAction.jsx b/frontend/src/components/ParsedAction.jsx index 7ba3f923..03413bcb 100644 --- a/frontend/src/components/ParsedAction.jsx +++ b/frontend/src/components/ParsedAction.jsx @@ -2666,6 +2666,117 @@ const ParsedAction = (props) => { // Change in actions, triggers & conditions // Highlight the changes somehow with a glow? + // + // Should make it a function lol + if (workflow.branches !== undefined && workflow.branches !== null) { + for (var key in workflow.branches) { + for (var subkey in workflow.branches[key].conditions) { + const condition = workflow.branches[key].conditions[subkey] + const sourceparam = condition.source + const destinationparam = condition.destination + + // Should have a smarter way of discovering node names + // Finding index(es) and replacing at the location + if (sourceparam.value.includes("$")) { + try { + var cnt = -1 + var previous = 0 + while (true) { + cnt += 1 + // Need to make sure e.g. changing the first here doesn't change the 2nd + // $change_me + // $change_me_2 + + const foundindex = sourceparam.value.toLowerCase().indexOf(parsedBaseLabel, previous) + if (foundindex === previous && foundindex !== 0) { + break + } + + if (foundindex >= 0) { + previous = foundindex+newname.length + // Need to add diff of length to word + + // Check location: + // If it's a-zA-Z_ then don't replace + if (sourceparam.value.length > foundindex+parsedBaseLabel.length) { + const regex = /[a-zA-Z0-9_]/g; + const match = sourceparam.value[foundindex+parsedBaseLabel.length].match(regex); + if (match !== null) { + continue + } + } + + console.log("Old found: ", workflow.branches[key].conditions[subkey].source.value) + const extralength = newname.length-parsedBaseLabel.length + sourceparam.value = sourceparam.value.substring(0, foundindex) + newname + sourceparam.value.substring(foundindex-extralength+newname.length, sourceparam.value.length) + + console.log("New: ", workflow.branches[key].conditions[subkey].source.value) + } else { + break + } + + // Break no matter what after 5 replaces. May need to increase + if (cnt >= 5) { + break + } + + } + } catch (e) { + console.log("Failed value replacement based on index: ", e) + } + } + + if (destinationparam.value.includes("$")) { + try { + var cnt = -1 + var previous = 0 + while (true) { + cnt += 1 + // Need to make sure e.g. changing the first here doesn't change the 2nd + // $change_me + // $change_me_2 + + const foundindex = destinationparam.value.toLowerCase().indexOf(parsedBaseLabel, previous) + if (foundindex === previous && foundindex !== 0) { + break + } + + if (foundindex >= 0) { + previous = foundindex+newname.length + // Need to add diff of length to word + + // Check location: + // If it's a-zA-Z_ then don't replace + if (destinationparam.value.length > foundindex+parsedBaseLabel.length) { + const regex = /[a-zA-Z0-9_]/g; + const match = destinationparam.value[foundindex+parsedBaseLabel.length].match(regex); + if (match !== null) { + continue + } + } + + console.log("Old found: ", workflow.branches[key].conditions[subkey].destination.value) + const extralength = newname.length-parsedBaseLabel.length + destinationparam.value = destinationparam.value.substring(0, foundindex) + newname + destinationparam.value.substring(foundindex-extralength+newname.length, destinationparam.value.length) + + console.log("New: ", workflow.branches[key].conditions[subkey].destination.value) + } else { + break + } + + // Break no matter what after 5 replaces. May need to increase + if (cnt >= 5) { + break + } + + } + } catch (e) { + console.log("Failed value replacement based on index: ", e) + } + } + } + } + } for (var key in workflow.actions) { if (workflow.actions[key].id === selectedAction.id) { @@ -2681,6 +2792,7 @@ const ParsedAction = (props) => { // Should have a smarter way of discovering node names // Do regex? // Finding index(es) and replacing at the location + // try { var cnt = -1 diff --git a/frontend/src/views/AngularWorkflow.jsx b/frontend/src/views/AngularWorkflow.jsx index 962f3090..804c2d62 100644 --- a/frontend/src/views/AngularWorkflow.jsx +++ b/frontend/src/views/AngularWorkflow.jsx @@ -7055,8 +7055,10 @@ const AngularWorkflow = (defaultprops) => { } var currentedge = cy.getElementById(selectedEdge.id); - if (currentedge !== undefined && currentedge !== null) { - currentedge.data().label = label; + if (currentedge !== undefined && currentedge !== null && label !== undefined) { + currentedge.data("label", label) + //.label = label; + //oldstartnode[0].data("isStartNode", false); } setSelectedEdge(selectedEdge);