From 65d4035cfdceaa521690a81ba8be647989bb391d Mon Sep 17 00:00:00 2001 From: frikky Date: Thu, 9 Jul 2020 11:42:36 +0200 Subject: [PATCH] Added PoC autocomplete feature based on app return example --- backend/go-app/walkoff.go | 11 ++++ frontend/src/AngularWorkflow.js | 65 +++++++++++++++++++- frontend/src/Apps.js | 102 ++++++++++++++++++++++++++++++++ frontend/src/Workflows.js | 12 ++-- 4 files changed, 182 insertions(+), 8 deletions(-) diff --git a/backend/go-app/walkoff.go b/backend/go-app/walkoff.go index 7f40ec0f..b7b2baae 100644 --- a/backend/go-app/walkoff.go +++ b/backend/go-app/walkoff.go @@ -142,6 +142,7 @@ type WorkflowAppAction struct { } `json:"execution_variable" datastore:"execution_variables"` Returns struct { Description string `json:"description" datastore:"returns" yaml:"description,omitempty"` + Example string `json:"example" datastore:"example" yaml:"example"` ID string `json:"id" datastore:"id" yaml:"id,omitempty"` Schema SchemaDefinition `json:"schema" datastore:"schema" yaml:"schema"` } `json:"returns" datastore:"returns"` @@ -4205,6 +4206,16 @@ func iterateAppGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra strin } } + /* + if workflowapp.Name == "thehive" { + for _, action := range workflowapp.Actions { + if len(action.Returns.Example) > 0 { + log.Printf("ACTION: %#v", action) + } + } + } + */ + if skip { continue } diff --git a/frontend/src/AngularWorkflow.js b/frontend/src/AngularWorkflow.js index 5eaad198..d3d567ee 100644 --- a/frontend/src/AngularWorkflow.js +++ b/frontend/src/AngularWorkflow.js @@ -67,6 +67,7 @@ import cxtmenu from 'cytoscape-cxtmenu'; import { w3cwebsocket as W3CWebSocket } from "websocket"; import { useAlert } from "react-alert"; +import { GetParsedPaths } from "./Apps"; const surfaceColor = "#27292D" const inputColor = "#383B40" @@ -2256,6 +2257,7 @@ const AngularWorkflow = (props) => { const [showDropdown, setShowDropdown] = React.useState(false) const [showDropdownNumber, setShowDropdownNumber] = React.useState(0) const [actionlist, setActionlist] = React.useState([]) + const [jsonList, setJsonList] = React.useState([]) useEffect(() => { if (selectedActionParameters !== null && selectedActionParameters.length === 0) { @@ -2317,6 +2319,20 @@ const AngularWorkflow = (props) => { } } + if (event.target.value[event.target.value.length-1] === ".") { + console.log("GET THE LAST ARGUMENT FOR !") + //const [jsonList, getJsonList] = React.useState([]) + const inputdata = {"data": "1.2.3.4", "dataType": "4.5.6.6"} + const returnJson = GetParsedPaths(inputdata, "") + console.log(jsonList) + setJsonList(returnJson) + + if (!showDropdown) { + setShowDropdown(true) + setShowDropdownNumber(count) + } + } + selectedActionParameters[count].value = event.target.value selectedAction.parameters[count].value = event.target.value setSelectedAction(selectedAction) @@ -2605,7 +2621,49 @@ const AngularWorkflow = (props) => { {datafield} - {showDropdown && showDropdownNumber === count && data.variant === "STATIC_VALUE" ? + {showDropdown && showDropdownNumber === count && data.variant === "STATIC_VALUE" && jsonList.length > 0 ? + + Autocomplete + + + : null} + {showDropdown && showDropdownNumber === count && data.variant === "STATIC_VALUE" && jsonList.length === 0 ? Autocomplete