Fixed autocompletion issue for exec and added errors for bad variables

This commit is contained in:
Frikky
2022-01-21 21:20:25 +00:00
committed by GitHub
parent 9ce92d6e1f
commit 2230cef978
4 changed files with 141 additions and 79 deletions
+117 -72
View File
@@ -1,8 +1,8 @@
import React, { useState, useEffect, useLayoutEffect } from "react"; import React, { useState, useEffect, useLayoutEffect } from "react";
import { makeStyles, createStyles } from "@material-ui/core/styles"; import { makeStyles, createStyles } from "@material-ui/core/styles";
import { validateJson, GetIconInfo } from "../views/Workflows.jsx";
import { GetParsedPaths } from "../views/Apps.jsx"; import { GetParsedPaths } from "../views/Apps.jsx";
import { GetIconInfo } from "../views/Workflows.jsx";
import { sortByKey } from "../views/AngularWorkflow.jsx"; import { sortByKey } from "../views/AngularWorkflow.jsx";
import { useTheme } from "@material-ui/core/styles"; import { useTheme } from "@material-ui/core/styles";
import NestedMenuItem from "material-ui-nested-menu-item"; import NestedMenuItem from "material-ui-nested-menu-item";
@@ -306,6 +306,8 @@ const ParsedAction = (props) => {
}); });
}; };
const defineStartnode = () => { const defineStartnode = () => {
if (cy === undefined) { if (cy === undefined) {
return; return;
@@ -393,14 +395,46 @@ const ParsedAction = (props) => {
if (actionlist.length === 0) { if (actionlist.length === 0) {
// FIXME: Have previous execution values in here // FIXME: Have previous execution values in here
actionlist.push({ if (workflowExecutions.length > 0) {
type: "Execution Argument", for (var key in workflowExecutions) {
name: "Execution Argument", if (
value: "$exec", workflowExecutions[key].execution_argument === undefined ||
highlight: "exec", workflowExecutions[key].execution_argument === null ||
autocomplete: "exec", workflowExecutions[key].execution_argument.length === 0
example: "", ) {
}); continue;
}
console.log("EXEC: ", workflowExecutions[key].execution_argument)
const valid = validateJson(workflowExecutions[key].execution_argument)
console.log("VALID: ", valid)
if (valid.valid) {
actionlist.push({
type: "Execution Argument",
name: "Execution Argument",
value: "$exec",
highlight: "exec",
autocomplete: "exec",
example: valid.result,
})
break
}
}
}
if (actionlist.length === 0) {
actionlist.push({
type: "Execution Argument",
name: "Execution Argument",
value: "$exec",
highlight: "exec",
autocomplete: "exec",
example: "",
})
}
actionlist.push({ actionlist.push({
type: "Shuffle DB", type: "Shuffle DB",
name: "Shuffle DB", name: "Shuffle DB",
@@ -477,51 +511,11 @@ const ParsedAction = (props) => {
continue; continue;
} }
foundResult.result = foundResult.result.trim(); const valid = validateJson(foundResult)
foundResult.result = foundResult.result if (valid.valid) {
.split(" None")
.join(' "None"');
foundResult.result = foundResult.result
.split(" False")
.join(" false");
foundResult.result = foundResult.result
.split(" True")
.join(" true");
var jsonvalid = true;
try {
const tmp = String(JSON.parse(foundResult.result));
if (
!foundResult.result.includes("{") &&
!foundResult.result.includes("[")
) {
jsonvalid = false;
}
} catch (e) {
try {
foundResult.result = foundResult.result
.split("'")
.join('"');
const tmp = String(JSON.parse(foundResult.result));
if (
!foundResult.result.includes("{") &&
!foundResult.result.includes("[")
) {
jsonvalid = false;
}
} catch (e) {
jsonvalid = false;
}
}
// Finds the FIRST json only
if (jsonvalid) {
exampledata = JSON.parse(foundResult.result); exampledata = JSON.parse(foundResult.result);
break; break;
} }
//else {
// console.log("Invalid JSON: ", foundResult.result)
//}
} }
} }
@@ -546,6 +540,59 @@ const ParsedAction = (props) => {
} }
}); });
const calculateHelpertext = (input_data) => {
var helperText = ""
var looperText = ""
const found = input_data.match(/[$]{1}([a-zA-Z0-9_-]+\.?){1}([a-zA-Z0-9#_-]+\.?){0,}/g)
if (found !== null) {
try {
// When the found array is empty.
for (var i = 0; i < found.length; i++) {
const variableSplit = found[i].split(".#")
if ((variableSplit.length-1) > 1) {
//console.log("Larger than 1: ", variableSplit)
if (looperText.length === 0) {
looperText += "PS: Double looping (.#) may cause problems."
}
}
var foundSlice = false
for (var j = 0; j < actionlist.length; j++) {
//console.log("ACTION: ", found[i], actionlist[j])
//console.log("ACTION :", found[i].split(".")[0].slice(1,).toLowerCase(), actionlist[j].autocomplete.toLowerCase())
if(found[i].split(".")[0].slice(1,).toLowerCase() == actionlist[j].autocomplete.toLowerCase()){
//console.log("Found: ", found[i])
// Validate path?
foundSlice = true
}
}
if (!foundSlice) {
if (!helperText.includes("Invalid variables")) {
helperText+= "Invalid variables: "
}
helperText+= found[i] + ", "
}
}
} catch (e) {
console.log("Parsing error: ", e)
}
}
if (looperText.length > 0) {
if (helperText.length > 0) {
helperText += ". "
}
helperText += looperText
}
return helperText
}
const changeActionParameter = (event, count, data) => { const changeActionParameter = (event, count, data) => {
//console.log("Action change: ", selectedAction, data) //console.log("Action change: ", selectedAction, data)
if (data.name.startsWith("${") && data.name.endsWith("}")) { if (data.name.startsWith("${") && data.name.endsWith("}")) {
@@ -1284,21 +1331,27 @@ const ParsedAction = (props) => {
const clickedFieldId = "rightside_field_" + count; const clickedFieldId = "rightside_field_" + count;
const shufflecode = <ShuffleCodeEditor const shufflecode = fieldCount !== count ? null :
fieldCount = {fieldCount} (
setFieldCount = {setFieldCount} <ShuffleCodeEditor
actionlist = {actionlist} fieldCount = {fieldCount}
changeActionParameterCodeMirror = {changeActionParameterCodeMirror} setFieldCount = {setFieldCount}
codedata={codedata} actionlist = {actionlist}
setcodedata={setcodedata} changeActionParameterCodeMirror = {changeActionParameterCodeMirror}
expansionModalOpen={expansionModalOpen} codedata={codedata}
setExpansionModalOpen={setExpansionModalOpen} setcodedata={setcodedata}
/> expansionModalOpen={expansionModalOpen}
setExpansionModalOpen={setExpansionModalOpen}
/>
)
//<TextareaAutosize //<TextareaAutosize
// <CodeMirror // <CodeMirror
//fullWidth //fullWidth
var baseHelperText = ""
if (data.value.length > 0) {
baseHelperText = calculateHelpertext(data.value)
}
var datafield = ( var datafield = (
<TextField <TextField
@@ -1407,7 +1460,7 @@ const ParsedAction = (props) => {
//changeActionParameterCodemirror(event, count, data) //changeActionParameterCodemirror(event, count, data)
changeActionParameter(event, count, data); changeActionParameter(event, count, data);
}} }}
helperText={ helperText={baseHelperText.length > 0 ? baseHelperText :
selectedApp.generated && selectedApp.generated &&
selectedApp.activated && selectedApp.activated &&
data.name === "body" ? ( data.name === "body" ? (
@@ -1425,15 +1478,7 @@ const ParsedAction = (props) => {
) : null ) : null
} }
onBlur={(event) => { onBlur={(event) => {
// Super basic check baseHelperText = calculateHelpertext(event.target.value)
//if (event.target.value.startsWith("{")) {
// console.log("VALIDATING JSON")
// try {
// JSON.parse(event.target.value)
// } catch (e) {
// alert.error("Failed to parse json: ", e)
// }
//}
}} }}
/> />
); );
+1 -2
View File
@@ -340,8 +340,7 @@ const AngularWorkflow = (defaultprops) => {
const [_, setUpdate] = useState(""); // Used for rendring, don't remove const [_, setUpdate] = useState(""); // Used for rendring, don't remove
const [workflowExecutions, setWorkflowExecutions] = React.useState([]); const [workflowExecutions, setWorkflowExecutions] = React.useState([]);
const [defaultEnvironmentIndex, setDefaultEnvironmentIndex] = const [defaultEnvironmentIndex, setDefaultEnvironmentIndex] = React.useState(0);
React.useState(0);
// This should all be set once, not on every iteration // This should all be set once, not on every iteration
// Use states and don't update lol // Use states and don't update lol
+21 -3
View File
@@ -381,9 +381,27 @@ const chipStyle = {
}; };
export const validateJson = (showResult) => { export const validateJson = (showResult) => {
//showResult = showResult.split(" None").join(" \"None\"") console.log("INPUT: ", showResult, typeof showResult)
showResult = showResult.split(" False").join(" false"); if (typeof showResult === 'string') {
showResult = showResult.split(" True").join(" true"); //showResult = showResult.split(" None").join(" \"None\"")
showResult = showResult.split(" False").join(" false");
showResult = showResult.split(" True").join(" true");
//return {
// valid: false,
// result: showResult,
//};
}
//if (typeof showResult === undefined) {
//}
if (typeof showResult === "object" || typeof showResult === "array") {
return {
valid: true,
result: showResult,
};
}
var jsonvalid = true; var jsonvalid = true;
try { try {
+2 -2
View File
@@ -1517,7 +1517,7 @@ func executionInit(workflowExecution shuffle.WorkflowExecution) error {
onpremApps := []string{} onpremApps := []string{}
toExecuteOnprem := []string{} toExecuteOnprem := []string{}
for _, action := range workflowExecution.Workflow.Actions { for _, action := range workflowExecution.Workflow.Actions {
if action.Environment != environment { if strings.ToLower(action.Environment) != strings.ToLower(environment) {
continue continue
} }
@@ -1599,7 +1599,7 @@ func handleDefaultExecution(client *http.Client, req *http.Request, workflowExec
err := executionInit(workflowExecution) err := executionInit(workflowExecution)
if err != nil { if err != nil {
log.Printf("[INFO] Workflow setup failed: %s", workflowExecution.ExecutionId, err) log.Printf("[INFO] Workflow setup failed for %s: %s", workflowExecution.ExecutionId, err)
log.Printf("[DEBUG] Shutting down (18)") log.Printf("[DEBUG] Shutting down (18)")
shutdown(workflowExecution, "", "", true) shutdown(workflowExecution, "", "", true)
} }