Merge pull request #1460 from Monilprajapati/flipBranchDirection

Flip branch direction
This commit is contained in:
Frikky
2024-07-31 19:53:06 +02:00
committed by GitHub
2 changed files with 123 additions and 53 deletions
+91 -24
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 { toast } from 'react-toastify';
import { makeStyles, createStyles } from "@mui/styles"; import { makeStyles, createStyles } from "@mui/styles";
import theme from '../theme.jsx'; import theme from '../theme.jsx';
@@ -180,22 +180,15 @@ const ParsedAction = (props) => {
const [hideBody, setHideBody] = React.useState(true) const [hideBody, setHideBody] = React.useState(true)
const [activateHidingBodyButton, setActivateHidingBodyButton] = React.useState(false) const [activateHidingBodyButton, setActivateHidingBodyButton] = React.useState(false)
const [appActionName, setAppActionName] = React.useState(selectedAction.label); const [appActionName, setAppActionName] = React.useState(selectedAction?.label);
const [delay, setDelay] = React.useState(selectedAction?.execution_delay || 0); const [delay, setDelay] = React.useState(selectedAction?.execution_delay || 0);
const [prevActionName, setPrevActionName] = React.useState(selectedAction.label); const [prevActionName, setPrevActionName] = React.useState(selectedAction?.label);
const [fieldCount, setFieldCount] = React.useState(0); const [fieldCount, setFieldCount] = React.useState(0);
const [hiddenDescription, setHiddenDescription] = React.useState(true); const [hiddenDescription, setHiddenDescription] = React.useState(true);
const [autoCompleting, setAutocompleting] = React.useState(false); const [autoCompleting, setAutocompleting] = React.useState(false);
const [selectedActionParameters, setSelectedActionParameters] = React.useState(selectedAction?.parameters || []); const [selectedActionParameters, setSelectedActionParameters] = React.useState(selectedAction?.parameters || []);
const [selectedVariableParameter, setSelectedVariableParameter] = React.useState(""); const [selectedVariableParameter, setSelectedVariableParameter] = React.useState("");
const [paramValues, setParamValues] = React.useState( const [paramUpdate, setParamUpdate] = React.useState("");
selectedAction?.parameters.map((param) => {
return {
name: param.name,
value: param.value,
}
})
);
const [actionlist, setActionlist] = React.useState([]); const [actionlist, setActionlist] = React.useState([]);
const [jsonList, setJsonList] = React.useState([]); const [jsonList, setJsonList] = React.useState([]);
const [showDropdown, setShowDropdown] = React.useState(false); const [showDropdown, setShowDropdown] = React.useState(false);
@@ -210,6 +203,7 @@ const ParsedAction = (props) => {
} }
}, [expansionModalOpen]) }, [expansionModalOpen])
useEffect(() => { useEffect(() => {
if (selectedActionEnvironment === undefined || selectedActionEnvironment === null || Object.keys(selectedActionEnvironment).length === 0) { if (selectedActionEnvironment === undefined || selectedActionEnvironment === null || Object.keys(selectedActionEnvironment).length === 0) {
@@ -237,6 +231,7 @@ const ParsedAction = (props) => {
selectedAction, selectedApp,setNewSelectedAction, workflow, selectedAction, selectedApp,setNewSelectedAction, workflow,
]) ])
useEffect(() => { useEffect(() => {
if (selectedAction.parameters === null || selectedAction.parameters === undefined) { if (selectedAction.parameters === null || selectedAction.parameters === undefined) {
return return
@@ -436,8 +431,8 @@ const ParsedAction = (props) => {
} }
// Only set selected action parameters if they have changed // Only set selected action parameters if they have changed
if (selectedAction.parameters && selectedAction.parameters.length > 0) { if (selectedAction?.parameters && selectedAction?.parameters.length > 0) {
setSelectedActionParameters(selectedAction.parameters); setSelectedActionParameters(selectedAction?.parameters);
} }
// Only set selected variable parameter if it is null or undefined // Only set selected variable parameter if it is null or undefined
@@ -452,6 +447,7 @@ const ParsedAction = (props) => {
useEffect(() => { useEffect(() => {
const newActionList = []; const newActionList = [];
const parentActionList = [];
// Process workflowExecutions // Process workflowExecutions
if (workflowExecutions.length > 0) { if (workflowExecutions.length > 0) {
@@ -579,14 +575,66 @@ const ParsedAction = (props) => {
autocomplete: parentNode.label.split(" ").join("_"), autocomplete: parentNode.label.split(" ").join("_"),
example: exampleData, example: exampleData,
}); });
parentActionList.push({
type: "action",
id: parentNode.id,
name: parentNode.label,
autocomplete: parentNode.label.split(" ").join("_"),
example: exampleData,
});
} }
} }
} }
} }
// Update the actionlist state let newParameters = selectedAction?.parameters?.map((param) => {
let paramvalue = param.value;
let errorVars = [];
if(paramvalue.includes("$")){
let actions = workflow.actions?.map((action) => {
return "$"+action.label.toLowerCase();
})
if(newActionList?.length > 0){
let appParentActions = parentActionList?.map(action => "$" + action.name.toLowerCase());
let notPresentAction = actions?.filter((action) => !appParentActions?.includes(action))
notPresentAction?.forEach((action) => {
action = action.replace(" ", "_");
if(paramvalue.includes(action)){
errorVars.push(action);
// paramvalue = paramvalue.replace(action, "")
// paramvalue = paramvalue.replace(/^\s*[\r\n]/gm, "");
}
})
}
}
let message = "";
if(errorVars.length > 0){
if(errorVars.length === 1){
message = errorVars[0] + " is not accessible in this action.";
}else{
message = errorVars.join(", ") + " are not accessible in this action.";
}
}
if (param?.configuration) {
let regex = /(^|[^\\])\$/;
if (regex.test(paramvalue)) {
if(message.length > 0){
message += "\nUse \"\\$\" instead of \"$\".";
}else{
message = "Use \"\\$\" instead of \"$\".";
}
}
}
return {...param, value: paramvalue, error: message}
});
setSelectedActionParameters(newParameters);
setActionlist(newActionList); setActionlist(newActionList);
}, [workflow.execution_variables, workflow.workflow_variables, workflowExecutions, workflow, selectedAction, listCache, getParents]); }, [workflow.execution_variables,paramUpdate, workflow.workflow_variables, workflowExecutions, workflow, selectedAction, listCache, getParents,setNewSelectedAction]);
useEffect(() => { useEffect(() => {
selectedNameChange(appActionName) selectedNameChange(appActionName)
@@ -597,13 +645,14 @@ const ParsedAction = (props) => {
},[appActionName,delay]) },[appActionName,delay])
const handleParamChange = (event, count,data) => { const handleParamChange = (event, count,data) => {
const newParams = [...paramValues]; const newParams = [...selectedActionParameters];
newParams.map((param) => { newParams.map((param) => {
if (param.name === data.name) { if (param.name === data.name) {
param.value = event.target.value; param.value = event.target.value;
} }
}) })
setParamValues(newParams); setSelectedActionParameters(newParams);
setParamUpdate(event.target.value);
changeActionParameter(event, count, data) changeActionParameter(event, count, data)
} }
@@ -1132,6 +1181,15 @@ const ParsedAction = (props) => {
return helperText return helperText
} }
const errorHelperText = (name, value, error) => {
return (
<div style={{ whiteSpace: 'pre-line' }}>
{error}
</div>
);
}
const analyzeFields = () => { const analyzeFields = () => {
if (selectedAction === undefined || selectedAction === null) { if (selectedAction === undefined || selectedAction === null) {
@@ -1193,7 +1251,7 @@ const ParsedAction = (props) => {
} }
// FIXME: Issue #40 - selectedActionParameters not reset // FIXME: Issue #40 - selectedActionParameters not reset
if (Object.getOwnPropertyNames(selectedAction).length > 0 && selectedActionParameters.length > 0) { if (Object.getOwnPropertyNames(selectedAction)?.length > 0 && selectedActionParameters?.length > 0) {
var wrapperapp = { var wrapperapp = {
"id": "", "id": "",
"name": "noapp", "name": "noapp",
@@ -2779,7 +2837,7 @@ const ParsedAction = (props) => {
{suggestionInfo()} {suggestionInfo()}
{selectedActionParameters.map((data, count) => { {selectedActionParameters?.map((data, count) => {
if (data.variant === "") { if (data.variant === "") {
data.variant = "STATIC_VALUE"; data.variant = "STATIC_VALUE";
} }
@@ -3238,10 +3296,12 @@ const ParsedAction = (props) => {
color="primary" color="primary"
// defaultValue={data.value} // defaultValue={data.value}
value={ value={
paramValues.find((param) => param.name === data.name) !== undefined data?.value
? paramValues.find((param) => param.name === data.name).value
: ""
} }
error={
data?.error?.length > 0 ? true : false
}
helperText={data?.error?.length > 0 ? errorHelperText(data?.name,data?.value,data?.error) : returnHelperText(data.name, data.value)}
//options={{ //options={{
// theme: 'gruvbox-dark', // theme: 'gruvbox-dark',
// keyMap: 'sublime', // keyMap: 'sublime',
@@ -3264,7 +3324,6 @@ const ParsedAction = (props) => {
// changeActionParameter(event, count, data); // changeActionParameter(event, count, data);
handleParamChange(event, count, data) handleParamChange(event, count, data)
}} }}
helperText={returnHelperText(data.name, data.value)}
onBlur={(event) => { onBlur={(event) => {
baseHelperText = calculateHelpertext(event.target.value) baseHelperText = calculateHelpertext(event.target.value)
if (setLastSaved !== undefined) { if (setLastSaved !== undefined) {
@@ -4019,6 +4078,14 @@ const ParsedAction = (props) => {
<Typography variant="body2"> <Typography variant="body2">
- Description: {description} - Description: {description}
</Typography> </Typography>
{
data?.configuration ?
(
<Typography Typography variant="body2">
- Use "\$" instead of "$"
</Typography>
) : null
}
</span> </span>
); );
+29 -26
View File
@@ -127,7 +127,7 @@ import {
ArrowForward as ArrowForwardIcon, ArrowForward as ArrowForwardIcon,
} from "@mui/icons-material"; } from "@mui/icons-material";
import SwapHorizIcon from '@mui/icons-material/SwapHoriz';
//import * as cytoscape from "cytoscape"; //import * as cytoscape from "cytoscape";
import cytoscape from "cytoscape"; import cytoscape from "cytoscape";
@@ -11754,10 +11754,10 @@ const releaseToConnectLabel = "Release to Connect"
</Typography> </Typography>
: null} : null}
<div style={{position: "absolute", bottom: 10, width: "90%", margin: "auto", }}> <div style={{position: "absolute", bottom: 15, width: "90%", margin: "auto", }}>
{/*
<Button <Button
style={{ margin: "auto", marginTop: "10px" }} style={{ margin: "auto", marginTop: "15px" }}
color="secondary" color="secondary"
fullWidth fullWidth
variant="outlined" variant="outlined"
@@ -11771,33 +11771,37 @@ const releaseToConnectLabel = "Release to Connect"
var branchdata = JSON.parse(JSON.stringify(foundBranch.data())) var branchdata = JSON.parse(JSON.stringify(foundBranch.data()))
console.log("BEFORE: ", branchdata) console.log("BEFORE: ", branchdata)
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
const newid = uuidv4() foundBranch.remove()
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)
cy.add({
group: "edges",
source: target,
target: source,
data: branchdata,
})
selectedEdge.id = newid
setSelectedEdge(selectedEdge)
toast("Branch direction changed!")
}
} }
}} }}
fullWidth fullWidth
> >
<DeleteIcon style={{marginRight: 10, }}/> <SwapHorizIcon style={{marginRight: 10 }}/>
Change Direction Flip Branch
</Button> </Button>
<Button {/*<Button
style={{ margin: "auto", }} style={{ margin: "auto", }}
color="secondary" color="secondary"
fullWidth fullWidth
@@ -11823,7 +11827,7 @@ const releaseToConnectLabel = "Release to Connect"
</Button> </Button>
*/} */}
<Button <Button
style={{ margin: "auto", marginTop: 50, }} style={{ margin: "auto", marginTop: 20, }}
color="secondary" color="secondary"
fullWidth fullWidth
variant="outlined" variant="outlined"
@@ -11833,7 +11837,6 @@ const releaseToConnectLabel = "Release to Connect"
if (foundBranch !== undefined && foundBranch !== null) { if (foundBranch !== undefined && foundBranch !== null) {
foundBranch.remove() foundBranch.remove()
} }
setConditionsModalOpen(false) setConditionsModalOpen(false)
setSelectedEdge({}) setSelectedEdge({})
}} }}