Fixed autocompleter in Code Editor to work with proper JSON examples
This commit is contained in:
@@ -371,7 +371,7 @@ class AppBase:
|
|||||||
# FIXME: Adding retries here.
|
# FIXME: Adding retries here.
|
||||||
try:
|
try:
|
||||||
finished = False
|
finished = False
|
||||||
for i in range (0, 5):
|
for i in range (0, 10):
|
||||||
try:
|
try:
|
||||||
ret = requests.post(url, headers=headers, json=action_result, timeout=10)
|
ret = requests.post(url, headers=headers, json=action_result, timeout=10)
|
||||||
|
|
||||||
@@ -384,22 +384,32 @@ class AppBase:
|
|||||||
|
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
self.logger.info(f"[DEBUG] Request problem: {e}")
|
self.logger.info(f"[DEBUG] Request problem: {e}")
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
#time.sleep(5)
|
#time.sleep(5)
|
||||||
continue
|
continue
|
||||||
except TimeoutError as e:
|
except TimeoutError as e:
|
||||||
self.logger.info(f"[DEBUG] Timeout or request: {e}")
|
self.logger.info(f"[DEBUG] Timeout or request: {e}")
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
#time.sleep(5)
|
#time.sleep(5)
|
||||||
continue
|
continue
|
||||||
except requests.exceptions.ConnectionError as e:
|
except requests.exceptions.ConnectionError as e:
|
||||||
self.logger.info(f"[DEBUG] Connectionerror: {e}")
|
self.logger.info(f"[DEBUG] Connectionerror: {e}")
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
#time.sleep(5)
|
#time.sleep(5)
|
||||||
continue
|
continue
|
||||||
except http.client.RemoteDisconnected as e:
|
except http.client.RemoteDisconnected as e:
|
||||||
self.logger.info(f"[DEBUG] Remote: {e}")
|
self.logger.info(f"[DEBUG] Remote: {e}")
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
#time.sleep(5)
|
#time.sleep(5)
|
||||||
continue
|
continue
|
||||||
except urllib3.exceptions.ProtocolError as e:
|
except urllib3.exceptions.ProtocolError as e:
|
||||||
self.logger.info(f"[DEBUG] Protocol err: {e}")
|
self.logger.info(f"[DEBUG] Protocol err: {e}")
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
#time.sleep(5)
|
#time.sleep(5)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -408,8 +418,8 @@ class AppBase:
|
|||||||
if not finished:
|
if not finished:
|
||||||
# Not sure why this would work tho :)
|
# Not sure why this would work tho :)
|
||||||
action_result["status"] = "FAILURE"
|
action_result["status"] = "FAILURE"
|
||||||
action_result["result"] = json.dumps({"success": False, "reason": "POST error: Failed connecting to %s over 5 retries" % url})
|
action_result["result"] = json.dumps({"success": False, "reason": "POST error: Failed connecting to %s over 10 retries to the backend" % url})
|
||||||
self.logger.info(f"[DEBUG] Before typeerror stream result - NOT finished after 5 requests")
|
self.logger.info(f"[DEBUG] Before typeerror stream result - NOT finished after 10 requests")
|
||||||
ret = requests.post("%s%s" % (self.base_url, stream_path), headers=headers, json=action_result)
|
ret = requests.post("%s%s" % (self.base_url, stream_path), headers=headers, json=action_result)
|
||||||
|
|
||||||
self.logger.info(f"""[DEBUG] Successful request result request: Status= {ret.status_code} & Response= {ret.text}. Action status: {action_result["status"]}""")
|
self.logger.info(f"""[DEBUG] Successful request result request: Status= {ret.status_code} & Response= {ret.text}. Action status: {action_result["status"]}""")
|
||||||
|
|||||||
@@ -1410,7 +1410,7 @@ const ParsedAction = (props) => {
|
|||||||
|
|
||||||
if (currentItem.description === openApiFieldDesc) {
|
if (currentItem.description === openApiFieldDesc) {
|
||||||
currentItem.field_active = !hideBody;
|
currentItem.field_active = !hideBody;
|
||||||
console.log("Changing", currentItem);
|
//console.log("Changing", currentItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
import Checkbox from '@mui/material/Checkbox';
|
import Checkbox from '@mui/material/Checkbox';
|
||||||
import { orange } from '@mui/material/colors';
|
import { orange } from '@mui/material/colors';
|
||||||
import { isMobile } from "react-device-detect"
|
import { isMobile } from "react-device-detect"
|
||||||
import { GetParsedPaths } from "../views/Apps.jsx";
|
import { GetParsedPaths, FindJsonPath } from "../views/Apps.jsx";
|
||||||
import NestedMenuItem from "material-ui-nested-menu-item";
|
import NestedMenuItem from "material-ui-nested-menu-item";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -345,9 +345,9 @@ const CodeEditor = (props) => {
|
|||||||
//console.log(found)
|
//console.log(found)
|
||||||
|
|
||||||
// Whelp this is inefficient af. Single loop pls
|
// Whelp this is inefficient af. Single loop pls
|
||||||
try{
|
// When the found array is empty.
|
||||||
// When the found array is empty.
|
for (var i = 0; i < found.length; i++) {
|
||||||
for (var i = 0; i < found.length; i++) {
|
try {
|
||||||
found[i] = found[i].toLowerCase()
|
found[i] = found[i].toLowerCase()
|
||||||
|
|
||||||
var valuefound = false
|
var valuefound = false
|
||||||
@@ -379,13 +379,28 @@ const CodeEditor = (props) => {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
input = input.replace(found[i], JSON.stringify(actionlist[k].example))
|
var new_input = FindJsonPath(fullpath, actionlist[k].example)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
input = input.replace(found[i], actionlist[k].example)
|
console.log("ERR IN INPUT: ", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof new_input === "object") {
|
||||||
|
new_input = JSON.stringify(new_input)
|
||||||
|
} else {
|
||||||
|
if (typeof new_input === "string") {
|
||||||
|
new_input = new_input
|
||||||
|
} else {
|
||||||
|
new_input = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
input = input.replace(found[i], new_input)
|
||||||
|
|
||||||
|
//} catch (e) {
|
||||||
|
// input = input.replace(found[i], actionlist[k].example)
|
||||||
|
//}
|
||||||
|
|
||||||
shouldbreak = true
|
shouldbreak = true
|
||||||
console.log("New input: ", input)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -395,9 +410,9 @@ const CodeEditor = (props) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Replace error: ", e)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
console.log("Replace error: ", e)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const tmpValidation = validateJson(input.valueOf())
|
const tmpValidation = validateJson(input.valueOf())
|
||||||
@@ -823,7 +838,6 @@ const CodeEditor = (props) => {
|
|||||||
//<ExpandMoreIcon style={iconStyle} />
|
//<ExpandMoreIcon style={iconStyle} />
|
||||||
|
|
||||||
const indentation_count = (pathdata.name.match(/\./g) || []).length+1
|
const indentation_count = (pathdata.name.match(/\./g) || []).length+1
|
||||||
const baseIndent = <div style={{marginLeft: 20, height: 30, width: 1, backgroundColor: coverColor,}} />
|
|
||||||
//const boxPadding = pathdata.type === "object" ? "10px 0px 0px 0px" : 0
|
//const boxPadding = pathdata.type === "object" ? "10px 0px 0px 0px" : 0
|
||||||
const boxPadding = 0
|
const boxPadding = 0
|
||||||
const namesplit = pathdata.name.split(".")
|
const namesplit = pathdata.name.split(".")
|
||||||
@@ -854,7 +868,7 @@ const CodeEditor = (props) => {
|
|||||||
<div style={{ display: "flex", height: 30, }}>
|
<div style={{ display: "flex", height: 30, }}>
|
||||||
{Array(indentation_count).fill().map((subdata, subindex) => {
|
{Array(indentation_count).fill().map((subdata, subindex) => {
|
||||||
return (
|
return (
|
||||||
baseIndent
|
<div key={subindex} style={{marginLeft: 20, height: 30, width: 1, backgroundColor: coverColor,}} />
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
{icon} {newname}
|
{icon} {newname}
|
||||||
|
|||||||
@@ -2590,6 +2590,7 @@ const AngularWorkflow = (defaultprops) => {
|
|||||||
a.loop_versions.includes(curaction.app_version)))
|
a.loop_versions.includes(curaction.app_version)))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
if (curaction.template === true) {
|
if (curaction.template === true) {
|
||||||
//newapps.
|
//newapps.
|
||||||
const parsedname = curaction.name.replaceAll(" ", "_").toLowerCase()
|
const parsedname = curaction.name.replaceAll(" ", "_").toLowerCase()
|
||||||
@@ -2630,6 +2631,12 @@ const AngularWorkflow = (defaultprops) => {
|
|||||||
setSelectedApp(tmpapp);
|
setSelectedApp(tmpapp);
|
||||||
setSelectedAction(curaction);
|
setSelectedAction(curaction);
|
||||||
} else {
|
} else {
|
||||||
|
console.log("CURAPP: ", curapp)
|
||||||
|
if (curapp.id !== curaction.id) {
|
||||||
|
curaction.app_id = curapp.id
|
||||||
|
//.valueOf()
|
||||||
|
}
|
||||||
|
|
||||||
setAuthenticationType(
|
setAuthenticationType(
|
||||||
curapp.authentication.type === "oauth2" &&
|
curapp.authentication.type === "oauth2" &&
|
||||||
curapp.authentication.redirect_uri !== undefined &&
|
curapp.authentication.redirect_uri !== undefined &&
|
||||||
@@ -2713,9 +2720,21 @@ const AngularWorkflow = (defaultprops) => {
|
|||||||
curaction.parameters[key].options[0];
|
curaction.parameters[key].options[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
console.log("Should check APP if it has the same params as ACTION")
|
||||||
|
for (var key in curapp.actions) {
|
||||||
|
const tmpaction = curapp.actions[key]
|
||||||
|
if (tmpaction.name === curaction.name) {
|
||||||
|
console.log("Found action - needs change?", tmpaction)
|
||||||
|
if (tmpaction.parameters !== undefined && tmpaction.parameters !== null && tmpaction.parameters.length > 0) {
|
||||||
|
curaction.parameters = JSON.parse(JSON.stringify(tmpaction.parameters))
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log("ACTION: ", curaction)
|
console.log("ACTION CLICK: ", curaction)
|
||||||
setSelectedApp(curapp);
|
setSelectedApp(curapp);
|
||||||
setSelectedAction(curaction);
|
setSelectedAction(curaction);
|
||||||
|
|
||||||
|
|||||||
@@ -3792,8 +3792,8 @@ const AppCreator = (defaultprops) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Found that dashes in the URL doesn't work
|
// Found that dashes in the URL doesn't work
|
||||||
parsedurl = parsedurl.replace("-", "_")
|
//parsedurl = parsedurl.replace("-", "_")
|
||||||
console.log("Actions: ", actions)
|
//console.log("Actions: ", actions)
|
||||||
|
|
||||||
if (baseUrl.length === 0 && parsedurl.includes("http")) {
|
if (baseUrl.length === 0 && parsedurl.includes("http")) {
|
||||||
const newurl = new URL(encodeURI(parsedurl))
|
const newurl = new URL(encodeURI(parsedurl))
|
||||||
|
|||||||
@@ -70,7 +70,72 @@ export const FixName = (name) => {
|
|||||||
return newAppname;
|
return newAppname;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Takes input of e.g. $node.data.#.asd and a matching value from a json blob
|
||||||
|
// Returns
|
||||||
|
export const FindJsonPath = (path, inputdata) => {
|
||||||
|
const splitkey = ".";
|
||||||
|
var parsedValues = [];
|
||||||
|
|
||||||
|
if (inputdata === undefined || inputdata === null) {
|
||||||
|
return inputdata
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof inputdata !== "object") {
|
||||||
|
return inputdata
|
||||||
|
}
|
||||||
|
|
||||||
|
var keysplit = path.split(splitkey)
|
||||||
|
if (path.startsWith("$") && keysplit.length > 1) {
|
||||||
|
keysplit = keysplit.slice(1,)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keysplit.length === 0) {
|
||||||
|
return inputdata
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Check list - always getting FIRST item, not digging too deep.
|
||||||
|
// If object, send further
|
||||||
|
if (keysplit[0].includes("#")) {
|
||||||
|
if (Object.prototype.toString.call(inputdata) === '[object Array]') {
|
||||||
|
if (inputdata.length === 0) {
|
||||||
|
return ""
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Fix the list
|
||||||
|
if (keysplit.length === 1) {
|
||||||
|
return inputdata[0]
|
||||||
|
} else {
|
||||||
|
const joinedsplit = keysplit.slice(1,).join(".")
|
||||||
|
return FindJsonPath(joinedsplit, inputdata[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(inputdata)) {
|
||||||
|
|
||||||
|
if (key === keysplit[0]) {
|
||||||
|
|
||||||
|
// Return if no more keys
|
||||||
|
// Else, dig deeper
|
||||||
|
if (keysplit.length === 1) {
|
||||||
|
return value
|
||||||
|
} else {
|
||||||
|
const joinedsplit = keysplit.slice(1,).join(".")
|
||||||
|
return FindJsonPath(joinedsplit, value)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//console.log("N: ", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return inputdata
|
||||||
|
}
|
||||||
|
|
||||||
// Parses JSON data into keys that can be used everywhere :)
|
// Parses JSON data into keys that can be used everywhere :)
|
||||||
|
// Reverse of this is FindJsonPath
|
||||||
export const GetParsedPaths = (inputdata, basekey) => {
|
export const GetParsedPaths = (inputdata, basekey) => {
|
||||||
const splitkey = ".";
|
const splitkey = ".";
|
||||||
var parsedValues = [];
|
var parsedValues = [];
|
||||||
@@ -92,7 +157,6 @@ export const GetParsedPaths = (inputdata, basekey) => {
|
|||||||
|
|
||||||
// Handle direct loop!
|
// Handle direct loop!
|
||||||
if (!isNaN(key) && basekey === "") {
|
if (!isNaN(key) && basekey === "") {
|
||||||
console.log("Handling direct loop.");
|
|
||||||
parsedValues.push({
|
parsedValues.push({
|
||||||
type: "object",
|
type: "object",
|
||||||
name: "Node",
|
name: "Node",
|
||||||
|
|||||||
Reference in New Issue
Block a user