From 2ece629a62bce26d58bc0abe0b50970c8387ae69 Mon Sep 17 00:00:00 2001 From: frikky Date: Tue, 7 Jul 2020 06:30:00 +0200 Subject: [PATCH] #35: Started building autocomplete functionality --- frontend/src/AngularWorkflow.js | 170 ++++++++++++++++++++++++-------- 1 file changed, 128 insertions(+), 42 deletions(-) diff --git a/frontend/src/AngularWorkflow.js b/frontend/src/AngularWorkflow.js index ff9d1d5c..69a5431c 100644 --- a/frontend/src/AngularWorkflow.js +++ b/frontend/src/AngularWorkflow.js @@ -1543,7 +1543,10 @@ const AngularWorkflow = (props) => { ) })}
- +
What are EXECUTION variables? @@ -1603,7 +1606,10 @@ const AngularWorkflow = (props) => { ) })}
- +
@@ -2240,6 +2246,8 @@ const AngularWorkflow = (props) => { const AppActionArguments = (props) => { const [selectedActionParameters, setSelectedActionParameters] = React.useState([]) const [selectedVariableParameter, setSelectedVariableParameter] = React.useState() + const [showDropdown, setShowDropdown] = React.useState(false) + const [actionlist, setActionlist] = React.useState([]) useEffect(() => { if (selectedActionParameters !== null && selectedActionParameters.length === 0) { @@ -2257,9 +2265,51 @@ const AngularWorkflow = (props) => { setSelectedVariableParameter(workflow.workflow_variables[0].name) } + if (actionlist.length === 0) { + actionlist.push({"type": "Execution Argument", "name": "Execution Argument", "value": "$exec", "highlight": "exec", "autocomplete": "$exec"}) + if (workflow.workflow_variables !== null && workflow.workflow_variables !== undefined && workflow.workflow_variables.length > 0) { + for (var key in workflow.workflow_variables) { + const item = workflow.workflow_variables[key] + actionlist.push({"type": "workflow_variable", "name": item.name, "value": item.value, "id": item.id, "autocomplete": `${item.name.split(" ").join("_")}`}) + } + } + + // FIXME: Add values from previous executions if they exist + if (workflow.execution_variables !== null && workflow.execution_variables !== undefined && workflow.execution_variables.length > 0) { + for (var key in workflow.execution_variables) { + const item = workflow.execution_variables[key] + actionlist.push({"type": "execution_variable", "name": item.name, "value": item.value, "id": item.id, "autocomplete": `${item.name.split(" ").join("_")}`}) + } + } + + var parents = getParents(selectedAction) + if (parents.length > 1) { + for (var key in parents) { + const item = parents[key] + if (item.label === "Execution Argument") { + continue + } + actionlist.push({"type": "action", "id": item.id, "name": item.label, "autocomplete": `${item.label.split(" ").join("_")}`}) + } + } + + setActionlist(actionlist) + } }) const changeActionParameter = (event, count) => { + console.log("EVENT: ", event.target.value) + if (event.target.value[event.target.value.length-1] === "$") { + console.log("LAST IS $ - SHOULD SHOW DROPDOWN") + if (!showDropdown) { + setShowDropdown(true) + } + } else { + if (showDropdown) { + setShowDropdown(false) + } + } + selectedActionParameters[count].value = event.target.value selectedAction.parameters[count].value = event.target.value setSelectedAction(selectedAction) @@ -2344,6 +2394,38 @@ const AngularWorkflow = (props) => { if (Object.getOwnPropertyNames(selectedAction).length > 0 && selectedActionParameters.length > 0) { return (
+ + {showDropdown ? + + : null} + + Arguments {selectedActionParameters.map((data, count) => { if (data.variant === "") { @@ -2419,45 +2501,46 @@ const AngularWorkflow = (props) => { datafield =
- - Example: $.body will get "data" from {'{"body": "data"}'}
} - placeholder="Action variable ($.)" - onChange={(event) => { - changeActionParameter(event, count) - }} - />
+ + Example: $.body will get "data" from {'{"body": "data"}'}} + placeholder="Action variable ($.)" + onChange={(event) => { + changeActionParameter(event, count) + }} + /> + } else if (data.variant === "WORKFLOW_VARIABLE") { varcolor = "#f85a3e" @@ -2469,7 +2552,10 @@ const AngularWorkflow = (props) => { Looks like you don't have any variables yet.
- +
} else {