From a10007c83221a51365f881761bf10843e0978157 Mon Sep 17 00:00:00 2001 From: frikky Date: Sat, 21 May 2022 16:57:23 +0200 Subject: [PATCH] Added basic string replacement when a node changes name --- frontend/src/components/ParsedAction.jsx | 79 +++++++++++++++++-- frontend/src/components/ShuffleCodeEditor.jsx | 12 +-- frontend/src/views/AngularWorkflow.jsx | 7 +- 3 files changed, 80 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/ParsedAction.jsx b/frontend/src/components/ParsedAction.jsx index 2e8d79cc..345a790f 100644 --- a/frontend/src/components/ParsedAction.jsx +++ b/frontend/src/components/ParsedAction.jsx @@ -2257,7 +2257,7 @@ const ParsedAction = (props) => { //} //console.log("env: ", selectedActionEnvironment) - const baselabel = selectedAction.label; + var baselabel = selectedAction.label; return (
@@ -2490,23 +2490,86 @@ const ParsedAction = (props) => { const name = e.target.value; console.log("CHANGED FROM2: ", baselabel); console.log("CHANGED TO: ", name); + + const parsedBaseLabel = "$"+baselabel.toLowerCase().replaceAll(" ", "_") + const newname = "$"+name.toLowerCase().replaceAll(" ", "_") + + // Change in actions, triggers & conditions + // Highlight the changes somehow with a glow? + for (var key in workflow.actions) { + if (workflow.actions[key].id === selectedAction.id) { + continue + } + for (var subkey in workflow.actions[key].parameters) { const param = workflow.actions[key].parameters[subkey]; - if (param.value.includes(baselabel)) { - //if (param.value.toLowerCase().includes(baselabel)) { - console.log("FOUND: ", param); + if (!param.value.includes("$")) { + continue + } - workflow.actions[key].parameters[subkey].value.replaceAll( - baselabel, - e.target.value - ); + console.log("PARAM: ", param) + + // Should have a smarter way of discovering node names + // Do regex? + // Finding index(es) and replacing at the location + + + 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 = param.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 (param.value.length > foundindex+parsedBaseLabel.length) { + console.log("Validate length if valid key if it's valid - don't replace if it is: ", param.value[foundindex+parsedBaseLabel.length]) + const regex = /[a-zA-Z0-9_]/g; + const match = param.value[foundindex+parsedBaseLabel.length].match(regex); + if (match !== null) { + continue + } + + console.log("Matching: ", match) + } + + console.log("Found: ", foundindex) + console.log("Old found: ", workflow.actions[key].parameters[subkey].value) + const extralength = newname.length-parsedBaseLabel.length + param.value = param.value.substring(0, foundindex) + newname + param.value.substring(foundindex-extralength+newname.length, param.value.length) + console.log("New: ", workflow.actions[key].parameters[subkey].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) } } } console.log("DID REPLACE ACTUALLY WORK?? - Something is buggy."); setWorkflow(workflow); + baselabel = name }} />
diff --git a/frontend/src/components/ShuffleCodeEditor.jsx b/frontend/src/components/ShuffleCodeEditor.jsx index 41456960..ba8bca78 100644 --- a/frontend/src/components/ShuffleCodeEditor.jsx +++ b/frontend/src/components/ShuffleCodeEditor.jsx @@ -75,7 +75,6 @@ const CodeEditor = (props) => { allVariable.push('$'+actionlist[i].autocomplete.toLowerCase()) mainVariables.push('$'+actionlist[i].autocomplete.toLowerCase()) // console.log(actionlist[i]) - console.log(actionlist[i].example.length) // for(var j=0; j { var variable_occurences = code_line.match(/[$]{1}([a-zA-Z0-9_-]+\.?){1}([a-zA-Z0-9#_-]+\.?){0,}/g) try{ - for(var occ = 0; occ { // temp_arr.push(temp_arr[temp_arr.length-1]+1) // variable_ranges.push(temp_arr) var temp_arr = [dollar_occurences[occ]] - for(var occ_len = 0; occ_len { // Wait for new node to possibly be selected //setTimeout(() => { const typeIds = cy.elements('node:selected').jsons(); - console.log("Found: ", typeIds) for (var idkey in typeIds) { const item = typeIds[idkey] - console.log("items: ", item) if (item.data.isButton === true) { - console.log("Reselect old node & return - or just return?") + //console.log("Reselect old node & return - or just return?") if (item.data.buttonType === "delete" && item.data.attachedTo === nodedata.id) { - console.log("delete of same node!") + //console.log("delete of same node!") } return } @@ -3699,7 +3697,6 @@ const AngularWorkflow = (defaultprops) => { for (var idkey in typeIds) { const item = typeIds[idkey] if (item.data.id === nodedata.id) { - console.log("items: ", item.data.id, nodedata.id) return } }