Added basic string replacement when a node changes name

This commit is contained in:
frikky
2022-05-21 16:57:23 +02:00
parent 7e42553fee
commit a10007c832
3 changed files with 80 additions and 18 deletions
+71 -8
View File
@@ -2257,7 +2257,7 @@ const ParsedAction = (props) => {
//}
//console.log("env: ", selectedActionEnvironment)
const baselabel = selectedAction.label;
var baselabel = selectedAction.label;
return (
<div style={appApiViewStyle} id="parsed_action_view">
@@ -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
}}
/>
</div>
@@ -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<actionlist[i].example.length; j++){
// console.log(j)
// allVariable.push('$'+actionlist[i].example[j].toLowerCase().substring(0, 25))
@@ -160,12 +159,12 @@ const CodeEditor = (props) => {
var variable_occurences = code_line.match(/[$]{1}([a-zA-Z0-9_-]+\.?){1}([a-zA-Z0-9#_-]+\.?){0,}/g)
try{
for(var occ = 0; occ<variable_occurences.length; occ++){
for(var occ = 0; occ < variable_occurences.length; occ++){
dollar_occurences_len.push(variable_occurences[occ].length)
}
} catch (e) {}
for(var occ = 0; occ<dollar_occurences.length; occ++){
for(var occ = 0; occ < dollar_occurences.length; occ++){
// var temp_arr = []
// for(var occ_len = 0; occ_len<dollar_occurences_len[occ]; occ_len++){
// temp_arr.push(dollar_occurences[occ]+occ_len)
@@ -174,10 +173,13 @@ const CodeEditor = (props) => {
// 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<dollar_occurences_len[occ]; occ_len++){
for(var occ_len = 0; occ_len < dollar_occurences_len[occ]; occ_len++){
temp_arr.push(dollar_occurences[occ]+occ_len+1)
}
if(temp_arr.length==1){temp_arr.push(temp_arr[temp_arr.length-1]+1)}
if(temp_arr.length==1) {
temp_arr.push(temp_arr[temp_arr.length-1]+1)
}
variable_ranges.push(temp_arr)
}
+2 -5
View File
@@ -1839,15 +1839,13 @@ const AngularWorkflow = (defaultprops) => {
// 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
}
}