feat(frontend): add support for updating node template on code change in CodeAreaModal
fix(API): fix UpdateTemplate function return type to match the actual response fix(vite.config.ts): add dynamic_node route to apiRoutes array to proxy requests to backend
This commit is contained in:
parent
a458b2d91c
commit
a47dc9ae92
7 changed files with 86 additions and 46 deletions
|
|
@ -227,6 +227,8 @@ export default function ParameterComponent({
|
||||||
</div>
|
</div>
|
||||||
) : left === true && type === "code" ? (
|
) : left === true && type === "code" ? (
|
||||||
<CodeAreaComponent
|
<CodeAreaComponent
|
||||||
|
setTemplate={(template)=>{data.node.template = template}}
|
||||||
|
template={data.node.template}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={data.node.template[name].value ?? ""}
|
value={data.node.template[name].value ?? ""}
|
||||||
onChange={handleOnNewValue}
|
onChange={handleOnNewValue}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ export default function GenericNode({
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {}, [closePopUp, data.node.template]);
|
useEffect(() => {}, [closePopUp, data.node.template]);
|
||||||
|
console.log({data})
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<NodeToolbar>
|
<NodeToolbar>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { useContext, useEffect, useState } from "react";
|
||||||
import { PopUpContext } from "../../contexts/popUpContext";
|
import { PopUpContext } from "../../contexts/popUpContext";
|
||||||
import CodeAreaModal from "../../modals/codeAreaModal";
|
import CodeAreaModal from "../../modals/codeAreaModal";
|
||||||
import TextAreaModal from "../../modals/textAreaModal";
|
import TextAreaModal from "../../modals/textAreaModal";
|
||||||
import { TextAreaComponentType } from "../../types/components";
|
import { CodeAreaComponentType, TextAreaComponentType } from "../../types/components";
|
||||||
import { INPUT_STYLE } from "../../constants";
|
import { INPUT_STYLE } from "../../constants";
|
||||||
|
|
||||||
export default function CodeAreaComponent({
|
export default function CodeAreaComponent({
|
||||||
|
|
@ -11,7 +11,9 @@ export default function CodeAreaComponent({
|
||||||
onChange,
|
onChange,
|
||||||
disabled,
|
disabled,
|
||||||
editNode = false,
|
editNode = false,
|
||||||
}: TextAreaComponentType) {
|
template,
|
||||||
|
setTemplate,
|
||||||
|
}: CodeAreaComponentType) {
|
||||||
const [myValue, setMyValue] = useState(value);
|
const [myValue, setMyValue] = useState(value);
|
||||||
const { openPopUp } = useContext(PopUpContext);
|
const { openPopUp } = useContext(PopUpContext);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -37,6 +39,8 @@ export default function CodeAreaComponent({
|
||||||
openPopUp(
|
openPopUp(
|
||||||
<CodeAreaModal
|
<CodeAreaModal
|
||||||
value={myValue}
|
value={myValue}
|
||||||
|
template={template}
|
||||||
|
setTemplate={setTemplate}
|
||||||
setValue={(t: string) => {
|
setValue={(t: string) => {
|
||||||
setMyValue(t);
|
setMyValue(t);
|
||||||
onChange(t);
|
onChange(t);
|
||||||
|
|
@ -59,7 +63,9 @@ export default function CodeAreaComponent({
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
openPopUp(
|
openPopUp(
|
||||||
<CodeAreaModal
|
<CodeAreaModal
|
||||||
|
setTemplate={setTemplate}
|
||||||
value={myValue}
|
value={myValue}
|
||||||
|
template={template}
|
||||||
setValue={(t: string) => {
|
setValue={(t: string) => {
|
||||||
setMyValue(t);
|
setMyValue(t);
|
||||||
onChange(t);
|
onChange(t);
|
||||||
|
|
|
||||||
|
|
@ -322,6 +322,6 @@ export async function postBuildInit(
|
||||||
return await axios.post(`/api/v1/build/init`, flow);
|
return await axios.post(`/api/v1/build/init`, flow);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function UpdateTemplate(type:string, template:APITemplateType):Promise<AxiosResponse<APITemplateType>>{
|
export async function UpdateTemplate(type:string, template:APITemplateType):Promise<AxiosResponse<{template:APITemplateType}>>{
|
||||||
return await axios.post(`/api/v1/UpdateTemplate`);
|
return await axios.get(`/dynamic_node`);
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ import "ace-builds/src-noconflict/theme-twilight";
|
||||||
import "ace-builds/src-noconflict/ext-language_tools";
|
import "ace-builds/src-noconflict/ext-language_tools";
|
||||||
// import "ace-builds/webpack-resolver";
|
// import "ace-builds/webpack-resolver";
|
||||||
import { darkContext } from "../../contexts/darkContext";
|
import { darkContext } from "../../contexts/darkContext";
|
||||||
import { postValidateCode } from "../../controllers/API";
|
import { UpdateTemplate, postValidateCode } from "../../controllers/API";
|
||||||
import { alertContext } from "../../contexts/alertContext";
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
import { TabsContext } from "../../contexts/tabsContext";
|
import { TabsContext } from "../../contexts/tabsContext";
|
||||||
import {
|
import {
|
||||||
|
|
@ -22,16 +22,23 @@ import {
|
||||||
} from "../../components/ui/dialog";
|
} from "../../components/ui/dialog";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
import { CODE_PROMPT_DIALOG_SUBTITLE } from "../../constants";
|
import { CODE_PROMPT_DIALOG_SUBTITLE } from "../../constants";
|
||||||
|
import Loading from "../../components/ui/loading";
|
||||||
|
import { APITemplateType } from "../../types/api";
|
||||||
|
|
||||||
export default function CodeAreaModal({
|
export default function CodeAreaModal({
|
||||||
value,
|
value,
|
||||||
setValue,
|
setValue,
|
||||||
|
template,
|
||||||
|
setTemplate
|
||||||
}: {
|
}: {
|
||||||
setValue: (value: string) => void;
|
setValue: (value: string) => void;
|
||||||
value: string;
|
value: string;
|
||||||
|
template: APITemplateType,
|
||||||
|
setTemplate: (template: APITemplateType) => void;
|
||||||
}) {
|
}) {
|
||||||
const [open, setOpen] = useState(true);
|
const [open, setOpen] = useState(true);
|
||||||
const [code, setCode] = useState(value);
|
const [code, setCode] = useState(value);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
const { dark } = useContext(darkContext);
|
const { dark } = useContext(darkContext);
|
||||||
const { setErrorData, setSuccessData } = useContext(alertContext);
|
const { setErrorData, setSuccessData } = useContext(alertContext);
|
||||||
const { closePopUp } = useContext(PopUpContext);
|
const { closePopUp } = useContext(PopUpContext);
|
||||||
|
|
@ -44,6 +51,58 @@ export default function CodeAreaModal({
|
||||||
}, 300);
|
}, 300);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleClick() {
|
||||||
|
setLoading(true);
|
||||||
|
postValidateCode(code)
|
||||||
|
.then((apiReturn) => {
|
||||||
|
setLoading(false);
|
||||||
|
if (apiReturn.data) {
|
||||||
|
let importsErrors = apiReturn.data.imports.errors;
|
||||||
|
let funcErrors = apiReturn.data.function.errors;
|
||||||
|
if (funcErrors.length === 0 && importsErrors.length === 0) {
|
||||||
|
setSuccessData({
|
||||||
|
title: "Code is ready to run",
|
||||||
|
});
|
||||||
|
// setValue(code);
|
||||||
|
} else {
|
||||||
|
if (funcErrors.length !== 0) {
|
||||||
|
setErrorData({
|
||||||
|
title: "There is an error in your function",
|
||||||
|
list: funcErrors,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (importsErrors.length !== 0) {
|
||||||
|
setErrorData({
|
||||||
|
title: "There is an error in your imports",
|
||||||
|
list: importsErrors,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setErrorData({
|
||||||
|
title: "Something went wrong, please try again",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((_) => {
|
||||||
|
setLoading(false);
|
||||||
|
setErrorData({
|
||||||
|
title:
|
||||||
|
"There is something wrong with this code, please review it",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
UpdateTemplate('code',template).then((apiReturn) => {
|
||||||
|
const data = apiReturn.data;
|
||||||
|
if (data.template) {
|
||||||
|
console.log('updated')
|
||||||
|
setTemplate(data.template);
|
||||||
|
setModalOpen(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={true} onOpenChange={setModalOpen}>
|
<Dialog open={true} onOpenChange={setModalOpen}>
|
||||||
<DialogTrigger></DialogTrigger>
|
<DialogTrigger></DialogTrigger>
|
||||||
|
|
@ -80,47 +139,10 @@ export default function CodeAreaModal({
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button
|
<Button
|
||||||
className="mt-3"
|
className="mt-3"
|
||||||
onClick={() => {
|
onClick={handleClick}
|
||||||
postValidateCode(code)
|
|
||||||
.then((apiReturn) => {
|
|
||||||
if (apiReturn.data) {
|
|
||||||
let importsErrors = apiReturn.data.imports.errors;
|
|
||||||
let funcErrors = apiReturn.data.function.errors;
|
|
||||||
if (funcErrors.length === 0 && importsErrors.length === 0) {
|
|
||||||
setSuccessData({
|
|
||||||
title: "Code is ready to run",
|
|
||||||
});
|
|
||||||
setModalOpen(false);
|
|
||||||
setValue(code);
|
|
||||||
} else {
|
|
||||||
if (funcErrors.length !== 0) {
|
|
||||||
setErrorData({
|
|
||||||
title: "There is an error in your function",
|
|
||||||
list: funcErrors,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (importsErrors.length !== 0) {
|
|
||||||
setErrorData({
|
|
||||||
title: "There is an error in your imports",
|
|
||||||
list: importsErrors,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setErrorData({
|
|
||||||
title: "Something went wrong, please try again",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((_) =>
|
|
||||||
setErrorData({
|
|
||||||
title:
|
|
||||||
"There is something wrong with this code, please review it",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
type="submit"
|
type="submit"
|
||||||
>
|
>
|
||||||
|
{/* {loading?(<Loading/>):'Check & Save'} */}
|
||||||
Check & Save
|
Check & Save
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { ForwardRefExoticComponent, ReactElement, ReactNode } from "react";
|
import { ForwardRefExoticComponent, ReactElement, ReactNode } from "react";
|
||||||
import { NodeDataType } from "../flow/index";
|
import { NodeDataType } from "../flow/index";
|
||||||
import { typesContextType } from "../typesContext";
|
import { typesContextType } from "../typesContext";
|
||||||
|
import { APITemplateType } from "../api";
|
||||||
export type InputComponentType = {
|
export type InputComponentType = {
|
||||||
value: string;
|
value: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
|
@ -50,6 +51,15 @@ export type TextAreaComponentType = {
|
||||||
editNode?: boolean;
|
editNode?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CodeAreaComponentType = {
|
||||||
|
disabled: boolean;
|
||||||
|
onChange: (value: string[] | string) => void;
|
||||||
|
value: string;
|
||||||
|
editNode?: boolean;
|
||||||
|
template: APITemplateType;
|
||||||
|
setTemplate: (value: APITemplateType) => void;
|
||||||
|
};
|
||||||
|
|
||||||
export type FileComponentType = {
|
export type FileComponentType = {
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
onChange: (value: string[] | string) => void;
|
onChange: (value: string[] | string) => void;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import react from "@vitejs/plugin-react-swc";
|
import react from "@vitejs/plugin-react-swc";
|
||||||
import svgr from "vite-plugin-svgr";
|
import svgr from "vite-plugin-svgr";
|
||||||
const apiRoutes = ["^/api/v1/", "/health"];
|
const apiRoutes = ["^/api/v1/", "/health","/dynamic_node"];
|
||||||
|
|
||||||
// Use environment variable to determine the target.
|
// Use environment variable to determine the target.
|
||||||
const target = process.env.VITE_PROXY_TARGET || "http://127.0.0.1:7860";
|
const target = process.env.VITE_PROXY_TARGET || "http://127.0.0.1:7860";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue