Added branch flip feature

This commit is contained in:
monilprajapati
2024-07-04 17:28:07 +05:30
parent 3c6ad85fcb
commit 1f9a132b75
2 changed files with 115 additions and 39 deletions
+84 -11
View File
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useLayoutEffect } from "react";
import React, { useState, useEffect, useLayoutEffect, useMemo } from "react";
import { toast } from 'react-toastify';
import { makeStyles, createStyles } from "@mui/styles";
import theme from '../theme.jsx';
@@ -207,16 +207,16 @@ const ParsedAction = (props) => {
}
}, [expansionModalOpen])
useEffect(() => {
setParamValues(selectedAction.parameters.map((param) => {
return {
name: param.name,
value: param.value,
}
}))
},[
selectedAction, selectedApp,setNewSelectedAction, workflow,
])
// useEffect(() => {
// setParamValues(selectedAction.parameters?.map((param) => {
// return {
// name: param.name,
// value: param.value,
// }
// }))
// },[
// selectedAction, selectedApp,setNewSelectedAction, workflow,
// ])
useEffect(() => {
if (selectedAction.parameters === null || selectedAction.parameters === undefined) {
@@ -565,6 +565,79 @@ const ParsedAction = (props) => {
setActionlist(newActionList);
}, [workflow.execution_variables, workflow.workflow_variables, workflowExecutions, workflow, selectedAction, listCache, getParents]);
const memoizedParam = useMemo(() => {
let appActions = [];
if (getParents) {
const parents = getParents(selectedAction);
if (parents.length > 1) {
const labels = [];
for (let parentNode of parents) {
if (parentNode.label !== "Execution Argument" && !labels.includes(parentNode.label)) {
labels.push(parentNode.label);
let exampleData = parentNode.example ?? "";
if (!exampleData && workflowExecutions.length > 0) {
for (let exec of workflowExecutions) {
const foundResult = exec.results?.find(result => result.action.id === parentNode.id);
if (foundResult) {
const valid = validateJson(foundResult.result);
if (valid.valid && valid.result.success !== false) {
exampleData = valid.result;
break;
}
}
}
}
appActions.push({
type: "action",
id: parentNode.id,
name: parentNode.label,
autocomplete: parentNode.label.split(" ").join("_"),
example: exampleData,
});
}
}
}
}
let newParameters = selectedAction.parameters?.map((param) => {
let paramvalue = param.value;
if(paramvalue.includes("$")){
let actions = workflow.actions?.map((action) => {
return "$"+action.label.toLowerCase();
})
if(actionlist.length > 0){
let appParentActions = appActions?.map(action => "$" + action.name.toLowerCase());
let notPresentAction = actions?.filter((action) => !appParentActions?.includes(action))
console.log("ACTIONS: ", actions)
console.log("APP ACTIONS: ", appParentActions)
console.log("NOT PRESENT: ", notPresentAction)
notPresentAction?.forEach((action) => {
console.log("Not included Action: ", action)
if(paramvalue.includes(action)){
paramvalue = paramvalue.replace(action, "")
paramvalue = paramvalue.replace(/^\s*[\r\n]/gm, "");
}
})
}
}
console.log("After removing param value: ", paramvalue)
return {...param, value: paramvalue}
});
selectedAction.parameters = newParameters;
setSelectedAction(selectedAction);
return newParameters;
},[actionlist,selectedAction,workflow.actions,workflow,selectedApp,setNewSelectedAction])
useEffect(() => {
setParamValues(memoizedParam.map((param) => {
return {
name: param.name,
value: param.value,
}
}))
},[memoizedParam])
useEffect(() => {
selectedNameChange(appActionName)
+31 -28
View File
@@ -126,7 +126,7 @@ import {
ArrowForward as ArrowForwardIcon,
} from "@mui/icons-material";
import SwapHorizIcon from '@mui/icons-material/SwapHoriz';
//import * as cytoscape from "cytoscape";
import cytoscape from "cytoscape";
@@ -11672,10 +11672,10 @@ const releaseToConnectLabel = "Release to Connect"
</Typography>
: null}
<div style={{position: "absolute", bottom: 10, width: "90%", margin: "auto", }}>
{/*
<div style={{position: "absolute", bottom: 15, width: "90%", margin: "auto", }}>
<Button
style={{ margin: "auto", marginTop: "10px" }}
style={{ margin: "auto", marginTop: "15px" }}
color="secondary"
fullWidth
variant="outlined"
@@ -11689,33 +11689,37 @@ const releaseToConnectLabel = "Release to Connect"
var branchdata = JSON.parse(JSON.stringify(foundBranch.data()))
console.log("BEFORE: ", branchdata)
const newid = uuidv4()
branchdata.source = target
branchdata.target = source
branchdata.id = newid
branchdata._id = newid
foundBranch.remove()
setTimeout(() => {
toast("Edge being added!")
cy.add({
group: "edges",
source: target,
target: source,
data: branchdata,
})
}, 2500)
console.log("Start node", workflow.start)
const startNode = workflow.start
if(source === startNode){
toast("Can't point to Start Node")
}else{
const newid = uuidv4()
branchdata.source = target
branchdata.target = source
branchdata.id = newid
branchdata._id = newid
foundBranch.remove()
cy.add({
group: "edges",
source: target,
target: source,
data: branchdata,
})
selectedEdge.id = newid
setSelectedEdge(selectedEdge)
toast("Branch direction changed!")
}
}
}}
fullWidth
>
<DeleteIcon style={{marginRight: 10, }}/>
Change Direction
<SwapHorizIcon style={{marginRight: 10 }}/>
Flip Branch
</Button>
<Button
{/*<Button
style={{ margin: "auto", }}
color="secondary"
fullWidth
@@ -11741,7 +11745,7 @@ const releaseToConnectLabel = "Release to Connect"
</Button>
*/}
<Button
style={{ margin: "auto", marginTop: 50, }}
style={{ margin: "auto", marginTop: 20, }}
color="secondary"
fullWidth
variant="outlined"
@@ -11751,7 +11755,6 @@ const releaseToConnectLabel = "Release to Connect"
if (foundBranch !== undefined && foundBranch !== null) {
foundBranch.remove()
}
setConditionsModalOpen(false)
setSelectedEdge({})
}}