formatting
This commit is contained in:
parent
5ece7e2fbc
commit
352cb8bc85
8 changed files with 211 additions and 205 deletions
|
|
@ -268,9 +268,9 @@ export default function ParameterComponent({
|
||||||
></Dropdown>
|
></Dropdown>
|
||||||
</div>
|
</div>
|
||||||
) : left === true && type === "code" ? (
|
) : left === true && type === "code" ? (
|
||||||
<div className="mt-2 w-full">
|
<div className="mt-2 w-full">
|
||||||
<CodeAreaComponent
|
<CodeAreaComponent
|
||||||
dynamic = {data.node.template[name].dynamic ?? false}
|
dynamic={data.node.template[name].dynamic ?? false}
|
||||||
setNodeClass={(nodeClass) => {
|
setNodeClass={(nodeClass) => {
|
||||||
data.node = nodeClass;
|
data.node = nodeClass;
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,6 @@ export default function InputFileComponent({
|
||||||
input.click();
|
input.click();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={disabled ? "input-component-div" : "w-full"}>
|
<div className={disabled ? "input-component-div" : "w-full"}>
|
||||||
<div className="input-file-component">
|
<div className="input-file-component">
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ export default function EditNodeModal({ data }: { data: NodeDataType }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => { }, [closePopUp, data.node.template]);
|
useEffect(() => {}, [closePopUp, data.node.template]);
|
||||||
|
|
||||||
function changeAdvanced(node): void {
|
function changeAdvanced(node): void {
|
||||||
Object.keys(data.node.template).filter((n, i) => {
|
Object.keys(data.node.template).filter((n, i) => {
|
||||||
|
|
@ -140,7 +140,7 @@ export default function EditNodeModal({ data }: { data: NodeDataType }) {
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="w-[300px] p-0 text-center text-xs text-foreground ">
|
<TableCell className="w-[300px] p-0 text-center text-xs text-foreground ">
|
||||||
{data.node.template[n].type === "str" &&
|
{data.node.template[n].type === "str" &&
|
||||||
!data.node.template[n].options ? (
|
!data.node.template[n].options ? (
|
||||||
<div className="mx-auto">
|
<div className="mx-auto">
|
||||||
{data.node.template[n].list ? (
|
{data.node.template[n].list ? (
|
||||||
<InputListComponent
|
<InputListComponent
|
||||||
|
|
@ -148,7 +148,7 @@ export default function EditNodeModal({ data }: { data: NodeDataType }) {
|
||||||
disabled={false}
|
disabled={false}
|
||||||
value={
|
value={
|
||||||
!data.node.template[n].value ||
|
!data.node.template[n].value ||
|
||||||
data.node.template[n].value === ""
|
data.node.template[n].value === ""
|
||||||
? [""]
|
? [""]
|
||||||
: data.node.template[n].value
|
: data.node.template[n].value
|
||||||
}
|
}
|
||||||
|
|
@ -261,7 +261,9 @@ export default function EditNodeModal({ data }: { data: NodeDataType }) {
|
||||||
) : data.node.template[n].type === "code" ? (
|
) : data.node.template[n].type === "code" ? (
|
||||||
<div className="mx-auto">
|
<div className="mx-auto">
|
||||||
<CodeAreaComponent
|
<CodeAreaComponent
|
||||||
dynamic={data.node.template[n].dynamic ?? false}
|
dynamic={
|
||||||
|
data.node.template[n].dynamic ?? false
|
||||||
|
}
|
||||||
setNodeClass={(nodeClass) => {
|
setNodeClass={(nodeClass) => {
|
||||||
data.node = nodeClass;
|
data.node = nodeClass;
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ export default function ModalField({
|
||||||
disabled={false}
|
disabled={false}
|
||||||
value={
|
value={
|
||||||
!data.node.template[name].value ||
|
!data.node.template[name].value ||
|
||||||
data.node.template[name].value === ""
|
data.node.template[name].value === ""
|
||||||
? [""]
|
? [""]
|
||||||
: data.node.template[name].value
|
: data.node.template[name].value
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,76 +1,67 @@
|
||||||
import { ReactNode, useContext, useEffect, useRef } from "react";
|
import { ReactNode, useContext } from "react";
|
||||||
|
|
||||||
import _ from "lodash";
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogTrigger,
|
|
||||||
} from "../../components/ui/dialog";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "../../components/ui/dialog";
|
||||||
import { PopUpContext } from "../../contexts/popUpContext";
|
import { PopUpContext } from "../../contexts/popUpContext";
|
||||||
|
|
||||||
type ContentProps = {children:ReactNode};
|
type ContentProps = { children: ReactNode };
|
||||||
type HeaderProps = {children:ReactNode,description:string};
|
type HeaderProps = { children: ReactNode; description: string };
|
||||||
|
|
||||||
|
|
||||||
const Content: React.FC<ContentProps> = ({ children }) => {
|
const Content: React.FC<ContentProps> = ({ children }) => {
|
||||||
return (
|
return <div className="h-full w-full">{children}</div>;
|
||||||
<div className="w-full h-full">
|
};
|
||||||
{children}
|
|
||||||
</div>)
|
|
||||||
}
|
|
||||||
|
|
||||||
const Header: React.FC<{ children: ReactNode, description:string }> = ({ children,description }) => {
|
const Header: React.FC<{ children: ReactNode; description: string }> = ({
|
||||||
return (
|
children,
|
||||||
<DialogHeader>
|
description,
|
||||||
<DialogTitle className="flex items-center">
|
}) => {
|
||||||
{children}
|
return (
|
||||||
</DialogTitle>
|
<DialogHeader>
|
||||||
<DialogDescription>{description}</DialogDescription>
|
<DialogTitle className="flex items-center">{children}</DialogTitle>
|
||||||
</DialogHeader>
|
<DialogDescription>{description}</DialogDescription>
|
||||||
)
|
</DialogHeader>
|
||||||
}
|
);
|
||||||
|
};
|
||||||
interface BaseModalProps {
|
interface BaseModalProps {
|
||||||
children: [React.ReactElement<ContentProps>, React.ReactElement<HeaderProps>];
|
children: [React.ReactElement<ContentProps>, React.ReactElement<HeaderProps>];
|
||||||
open: boolean;
|
open: boolean;
|
||||||
setOpen: (open: boolean) => void;
|
setOpen: (open: boolean) => void;
|
||||||
|
}
|
||||||
|
function BaseModal({ open, setOpen, children }: BaseModalProps) {
|
||||||
|
const { closePopUp, setCloseEdit } = useContext(PopUpContext);
|
||||||
|
|
||||||
|
function setModalOpen(x: boolean) {
|
||||||
|
setOpen(x);
|
||||||
|
if (x === false) {
|
||||||
|
setTimeout(() => {
|
||||||
|
setCloseEdit("editcode");
|
||||||
|
closePopUp();
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function BaseModal({
|
const headerChild = React.Children.toArray(children).find(
|
||||||
open,
|
(child) => (child as React.ReactElement).type === Header
|
||||||
setOpen,
|
);
|
||||||
children,
|
const ContentChild = React.Children.toArray(children).find(
|
||||||
}: BaseModalProps) {
|
(child) => (child as React.ReactElement).type === Content
|
||||||
const {closePopUp, setCloseEdit} = useContext(PopUpContext)
|
);
|
||||||
|
//UPDATE COLORS AND STYLE CLASSSES
|
||||||
function setModalOpen(x: boolean) {
|
return (
|
||||||
setOpen(x);
|
<Dialog open={open} onOpenChange={setModalOpen}>
|
||||||
if (x === false) {
|
<DialogTrigger className="hidden"></DialogTrigger>
|
||||||
setTimeout(() => {
|
<DialogContent className="min-w-[80vw]">
|
||||||
setCloseEdit("editcode");
|
{headerChild}
|
||||||
closePopUp();
|
<div className="mt-2 flex h-[80vh] w-full ">{ContentChild}</div>
|
||||||
}, 300);
|
</DialogContent>
|
||||||
}
|
</Dialog>
|
||||||
}
|
);
|
||||||
const headerChild = React.Children.toArray(children).find((child) => (child as React.ReactElement).type === Header);
|
|
||||||
const ContentChild = React.Children.toArray(children).find(
|
|
||||||
(child) => (child as React.ReactElement).type === Content
|
|
||||||
);
|
|
||||||
//UPDATE COLORS AND STYLE CLASSSES
|
|
||||||
return (
|
|
||||||
<Dialog open={open} onOpenChange={setModalOpen}>
|
|
||||||
<DialogTrigger className="hidden"></DialogTrigger>
|
|
||||||
<DialogContent className="min-w-[80vw]">
|
|
||||||
{headerChild}
|
|
||||||
<div className="flex h-[80vh] w-full mt-2 ">
|
|
||||||
{ContentChild}
|
|
||||||
</div>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseModal.Content = Content;
|
BaseModal.Content = Content;
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
|
// organize-imports-ignore
|
||||||
import { useContext, useEffect, useRef, useState } from "react";
|
import { useContext, useEffect, useRef, useState } from "react";
|
||||||
import { PopUpContext } from "../../contexts/popUpContext";
|
import { PopUpContext } from "../../contexts/popUpContext";
|
||||||
import 'ace-builds/src-noconflict/ace';
|
import "ace-builds/src-noconflict/ace";
|
||||||
import { darkContext } from "../../contexts/darkContext";
|
import { darkContext } from "../../contexts/darkContext";
|
||||||
import { postCustomComponent, postValidateCode } from "../../controllers/API";
|
import { postCustomComponent, postValidateCode } from "../../controllers/API";
|
||||||
import { alertContext } from "../../contexts/alertContext";
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
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 { APIClassType } from "../../types/api";
|
import { APIClassType } from "../../types/api";
|
||||||
import TwoColumnsModal from "../baseModal";
|
|
||||||
import { DialogTitle } from "@radix-ui/react-dialog";
|
import { DialogTitle } from "@radix-ui/react-dialog";
|
||||||
import { TerminalSquare } from "lucide-react";
|
import { TerminalSquare } from "lucide-react";
|
||||||
import AceEditor from "react-ace";
|
import AceEditor from "react-ace";
|
||||||
|
|
@ -15,143 +15,157 @@ import "ace-builds/src-noconflict/mode-python";
|
||||||
import "ace-builds/src-noconflict/theme-github";
|
import "ace-builds/src-noconflict/theme-github";
|
||||||
import "ace-builds/src-noconflict/theme-twilight";
|
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/src-noconflict/ace';
|
import "ace-builds/src-noconflict/ace";
|
||||||
import { XCircle } from 'lucide-react';
|
|
||||||
import BaseModal from "../baseModal";
|
import BaseModal from "../baseModal";
|
||||||
|
|
||||||
export default function CodeAreaModal({
|
export default function CodeAreaModal({
|
||||||
value,
|
value,
|
||||||
setValue,
|
setValue,
|
||||||
nodeClass,
|
nodeClass,
|
||||||
setNodeClass,
|
setNodeClass,
|
||||||
dynamic
|
dynamic,
|
||||||
}: {
|
}: {
|
||||||
setValue: (value: string) => void;
|
setValue: (value: string) => void;
|
||||||
value: string;
|
value: string;
|
||||||
nodeClass: APIClassType;
|
nodeClass: APIClassType;
|
||||||
setNodeClass: (Class: APIClassType) => void;
|
setNodeClass: (Class: APIClassType) => void;
|
||||||
dynamic?: boolean;
|
dynamic?: boolean;
|
||||||
}) {
|
}) {
|
||||||
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 [loading, setLoading] = useState(false);
|
||||||
const { dark } = useContext(darkContext);
|
const { dark } = useContext(darkContext);
|
||||||
const { setErrorData, setSuccessData } = useContext(alertContext);
|
const { setErrorData, setSuccessData } = useContext(alertContext);
|
||||||
const [activeTab, setActiveTab] = useState("0");
|
const [activeTab, setActiveTab] = useState("0");
|
||||||
const [error, setError] = useState<{ detail: { error: string, traceback: string } }>(null)
|
const [error, setError] = useState<{
|
||||||
const { closePopUp, setCloseEdit } = useContext(PopUpContext);
|
detail: { error: string; traceback: string };
|
||||||
const ref = useRef();
|
}>(null);
|
||||||
function setModalOpen(x: boolean) {
|
const { closePopUp, setCloseEdit } = useContext(PopUpContext);
|
||||||
setOpen(x);
|
const ref = useRef();
|
||||||
if (x === false) {
|
function setModalOpen(x: boolean) {
|
||||||
setTimeout(() => {
|
setOpen(x);
|
||||||
setCloseEdit("editcode");
|
if (x === false) {
|
||||||
closePopUp();
|
setTimeout(() => {
|
||||||
}, 300);
|
setCloseEdit("editcode");
|
||||||
}
|
closePopUp();
|
||||||
|
}, 300);
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
}
|
||||||
setValue(code);
|
useEffect(() => {
|
||||||
}, [code, setValue])
|
setValue(code);
|
||||||
|
}, [code, setValue]);
|
||||||
|
|
||||||
function handleClick() {
|
function handleClick() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
if (!dynamic) {
|
if (!dynamic) {
|
||||||
postValidateCode(code)
|
postValidateCode(code)
|
||||||
.then((apiReturn) => {
|
.then((apiReturn) => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
if (apiReturn.data) {
|
if (apiReturn.data) {
|
||||||
let importsErrors = apiReturn.data.imports.errors;
|
let importsErrors = apiReturn.data.imports.errors;
|
||||||
let funcErrors = apiReturn.data.function.errors;
|
let funcErrors = apiReturn.data.function.errors;
|
||||||
if (funcErrors.length === 0 && importsErrors.length === 0) {
|
if (funcErrors.length === 0 && importsErrors.length === 0) {
|
||||||
setSuccessData({
|
setSuccessData({
|
||||||
title: "Code is ready to run",
|
title: "Code is ready to run",
|
||||||
});
|
});
|
||||||
// setValue(code);
|
// setValue(code);
|
||||||
} else {
|
} else {
|
||||||
if (funcErrors.length !== 0) {
|
if (funcErrors.length !== 0) {
|
||||||
setErrorData({
|
setErrorData({
|
||||||
title: "There is an error in your function",
|
title: "There is an error in your function",
|
||||||
list: funcErrors,
|
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",
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
if (importsErrors.length !== 0) {
|
||||||
postCustomComponent(code, nodeClass).then((apiReturn) => {
|
setErrorData({
|
||||||
const { data } = apiReturn;
|
title: "There is an error in your imports",
|
||||||
if (data) {
|
list: importsErrors,
|
||||||
setNodeClass(data);
|
});
|
||||||
setModalOpen(false);
|
}
|
||||||
}
|
}
|
||||||
}).catch((err) => {
|
} else {
|
||||||
setError(err.response.data);
|
setErrorData({
|
||||||
|
title: "Something went wrong, please try again",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.catch((_) => {
|
||||||
|
setLoading(false);
|
||||||
|
setErrorData({
|
||||||
|
title: "There is something wrong with this code, please review it",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
postCustomComponent(code, nodeClass)
|
||||||
|
.then((apiReturn) => {
|
||||||
|
const { data } = apiReturn;
|
||||||
|
if (data) {
|
||||||
|
setNodeClass(data);
|
||||||
|
setModalOpen(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
setError(err.response.data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const tabs = [{ name: "code" }, { name: "errors" }]
|
}
|
||||||
|
const tabs = [{ name: "code" }, { name: "errors" }];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseModal open={true} setOpen={setOpen}>
|
<BaseModal open={true} setOpen={setOpen}>
|
||||||
<BaseModal.Header description={CODE_PROMPT_DIALOG_SUBTITLE}>
|
<BaseModal.Header description={CODE_PROMPT_DIALOG_SUBTITLE}>
|
||||||
<DialogTitle className="flex items-center">
|
<DialogTitle className="flex items-center">
|
||||||
<span className="pr-2">Edit Code</span>
|
<span className="pr-2">Edit Code</span>
|
||||||
<TerminalSquare
|
<TerminalSquare
|
||||||
strokeWidth={1.5}
|
strokeWidth={1.5}
|
||||||
className="h-6 w-6 text-primary pl-1 "
|
className="h-6 w-6 pl-1 text-primary "
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
/>
|
/>
|
||||||
</DialogTitle></BaseModal.Header>
|
</DialogTitle>
|
||||||
<BaseModal.Content>
|
</BaseModal.Header>
|
||||||
<div className="w-full h-full flex flex-col transition-all">
|
<BaseModal.Content>
|
||||||
<div className="h-full w-full">
|
<div className="flex h-full w-full flex-col transition-all">
|
||||||
<AceEditor
|
<div className="h-full w-full">
|
||||||
value={code}
|
<AceEditor
|
||||||
mode="python"
|
value={code}
|
||||||
highlightActiveLine={true}
|
mode="python"
|
||||||
showPrintMargin={false}
|
highlightActiveLine={true}
|
||||||
fontSize={14}
|
showPrintMargin={false}
|
||||||
showGutter
|
fontSize={14}
|
||||||
enableLiveAutocompletion
|
showGutter
|
||||||
theme={dark ? "twilight" : "github"}
|
enableLiveAutocompletion
|
||||||
name="CodeEditor"
|
theme={dark ? "twilight" : "github"}
|
||||||
onChange={(value) => {
|
name="CodeEditor"
|
||||||
setCode(value);
|
onChange={(value) => {
|
||||||
}}
|
setCode(value);
|
||||||
className="w-full rounded-lg h-full custom-scroll border-[1px] border-gray-300 dark:border-gray-600"
|
}}
|
||||||
/>
|
className="h-full w-full rounded-lg border-[1px] border-gray-300 custom-scroll dark:border-gray-600"
|
||||||
</div>
|
/>
|
||||||
<div className={"w-full transition-all delay-500 " + (error?.detail.error !== undefined ? "h-2/6" : "h-0")}>
|
</div>
|
||||||
<div className="w-full h-full overflow-y-scroll overflow-x-clip custom-scroll text-left mt-1">
|
<div
|
||||||
<h1 className="text-destructive text-lg">{error?.detail?.error}</h1>
|
className={
|
||||||
<div className="text-status-red text-sm ml-2 w-full break-all"><pre className="w-full break-all whitespace-pre-wrap">{error?.detail?.traceback}</pre></div>
|
"w-full transition-all delay-500 " +
|
||||||
</div>
|
(error?.detail.error !== undefined ? "h-2/6" : "h-0")
|
||||||
</div>
|
}
|
||||||
<div className="h-fit w-full flex justify-end">
|
>
|
||||||
<Button className="mt-3" onClick={handleClick} type="submit">
|
<div className="mt-1 h-full w-full overflow-x-clip overflow-y-scroll text-left custom-scroll">
|
||||||
Check & Save
|
<h1 className="text-lg text-destructive">
|
||||||
</Button></div>
|
{error?.detail?.error}
|
||||||
</div>
|
</h1>
|
||||||
</BaseModal.Content>
|
<div className="ml-2 w-full break-all text-sm text-status-red">
|
||||||
</BaseModal>
|
<pre className="w-full whitespace-pre-wrap break-all">
|
||||||
);
|
{error?.detail?.traceback}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex h-fit w-full justify-end">
|
||||||
|
<Button className="mt-3" onClick={handleClick} type="submit">
|
||||||
|
Check & Save
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</BaseModal.Content>
|
||||||
|
</BaseModal>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,10 @@ import {
|
||||||
Paperclip,
|
Paperclip,
|
||||||
Rocket,
|
Rocket,
|
||||||
Scissors,
|
Scissors,
|
||||||
|
Sparkles,
|
||||||
TerminalSquare,
|
TerminalSquare,
|
||||||
Wand2,
|
Wand2,
|
||||||
Wrench,
|
Wrench,
|
||||||
Sparkles,
|
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { ComponentType, SVGProps } from "react";
|
import { ComponentType, SVGProps } from "react";
|
||||||
import { Connection, Edge, Node, ReactFlowInstance } from "reactflow";
|
import { Connection, Edge, Node, ReactFlowInstance } from "reactflow";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue