Updated popup editor and added variable detection functionality

This commit is contained in:
gohil-jay
2021-12-19 22:29:07 +05:30
parent 8eadfceb68
commit a0d6631b31
2 changed files with 34 additions and 6 deletions
+2
View File
@@ -1218,6 +1218,7 @@ const ParsedAction = (props) => {
const shufflecode = <ShuffleCodeEditor
fieldCount = {fieldCount}
setFieldCount = {setFieldCount}
actionlist = {actionlist}
changeActionParameterCodeMirror = {changeActionParameterCodeMirror}
codedata={codedata}
setcodedata={setcodedata}
@@ -1738,6 +1739,7 @@ const ParsedAction = (props) => {
//}}
onClick={() => {
console.log("CLICKED: ", innerdata);
console.log(innerdata.example)
handleItemClick([innerdata]);
}}
>
+32 -6
View File
@@ -20,6 +20,7 @@ import 'codemirror/theme/gruvbox-dark.css';
const CodeEditor = (props) => {
const {fieldCount, setFieldCount} = props
const {actionlist} = props
const {changeActionParameterCodeMirror} = props
const {expansionModalOpen, setExpansionModalOpen} = props
const {codedata, setcodedata} = props
@@ -29,14 +30,37 @@ const CodeEditor = (props) => {
const [expOutput, setexpOutput] = React.useState(" ");
function expectedOutput(input) {
const found = input.match(/[$]{1}([a-zA-Z0-9_-]+\.?){1}([a-zA-Z0-9#_-]+\.?){0,}/g)
console.log(found)
for (var i = 0; i < found.length; i++) {
// console.log(found[i]);
for (var j = 0; j < actionlist.length; j++) {
if(found[i].slice(1,).toLowerCase() == actionlist[j].autocomplete.toLowerCase()){
input = input.replace(found[i], JSON.stringify(actionlist[j].example));
// console.log(input)
// console.log(actionlist[j].example)
}
// console.log(actionlist[j].autocomplete);
}
}
try {
// var x = document.getElementById("expOutput");
// x.innerHTML = JSON.stringify(JSON.parse(input), null, 4)
setexpOutput(JSON.stringify(JSON.parse(input), null, 4))
} catch (e) {
setexpOutput(input)
}
// const obj = JSON.parse(input);
// setexpOutput(JSON.stringify(JSON.parse(input), null, 4))
var x = document.getElementById("expOutput");
x.innerHTML = JSON.stringify(input, null, 4)
// x.innerHTML = JSON.stringify(JSON.parse(input), null, 4)
// x.innerHTML = "<span style='font-size: 30px'>" + JSON.stringify(input, null, 4) + "</span>"
// x.appendChild(document.createTextNode(JSON.stringify(JSON.parse(input), null, 4)));
// setexpOutput(JSON.stringify(input, null, 4))
// setexpOutput(JSON.stringify(input, undefined, 4).replace('\ ', '\n'))
// setexpOutput("Hi there \n Hey there")
// Variables + Syntax highlighting + Validation
}
@@ -80,6 +104,7 @@ const CodeEditor = (props) => {
onChange={(value) => {
setlocalcodedata(value.getValue())
expectedOutput(value.getValue())
// console.log(actionlist.slice(-1))
}}
options={{
theme: 'gruvbox-dark',
@@ -107,6 +132,7 @@ const CodeEditor = (props) => {
<p
id='expOutput'
style={{
whiteSpace: "pre-wrap",
color: "#f85a3e",
fontFamily: "monospace",
backgroundColor: "#282828",
@@ -116,7 +142,7 @@ const CodeEditor = (props) => {
borderRadius: theme.palette.borderRadius,
}}
>
{/* {expOutput} */}
{expOutput}
</p>
</div>