improvement of error check on code modal

This commit is contained in:
anovazzi1 2023-03-28 20:17:51 -03:00
commit 2c235402ca
5 changed files with 81 additions and 36 deletions

View file

@ -23,7 +23,6 @@ export default function GenericNode({
const { types, deleteNode } = useContext(typesContext); const { types, deleteNode } = useContext(typesContext);
const Icon = nodeIcons[types[data.type]]; const Icon = nodeIcons[types[data.type]];
if (!Icon) { if (!Icon) {
console.log(data);
if (showError.current) { if (showError.current) {
setErrorData({ setErrorData({
title: data.type title: data.type
@ -34,7 +33,6 @@ export default function GenericNode({
} }
return; return;
} }
console.log(data)
return ( return (
<div <div
className={classNames( className={classNames(

View file

@ -5,7 +5,11 @@ import CodeAreaModal from "../../modals/codeAreaModal";
import TextAreaModal from "../../modals/textAreaModal"; import TextAreaModal from "../../modals/textAreaModal";
import { TextAreaComponentType } from "../../types/components"; import { TextAreaComponentType } from "../../types/components";
export default function CodeAreaComponent({ value, onChange, disabled }:TextAreaComponentType) { export default function CodeAreaComponent({
value,
onChange,
disabled,
}: TextAreaComponentType) {
const [myValue, setMyValue] = useState(value); const [myValue, setMyValue] = useState(value);
const { openPopUp } = useContext(PopUpContext); const { openPopUp } = useContext(PopUpContext);
useEffect(() => { useEffect(() => {
@ -15,17 +19,29 @@ export default function CodeAreaComponent({ value, onChange, disabled }:TextArea
} }
}, [disabled, onChange]); }, [disabled, onChange]);
return ( return (
<div className={disabled ? "pointer-events-none cursor-not-allowed" : ""}> <div className={disabled ? "pointer-events-none cursor-not-allowed w-full" : "w-full"}>
<div className="w-full flex items-center gap-3"> <div className="w-full flex items-center gap-3">
<span <span
className={ className={
"truncate block w-full text-gray-500 px-3 py-2 rounded-md border border-gray-300 dark:border-gray-700 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" + "truncate block max-w-full text-gray-500 px-3 py-2 rounded-md border border-gray-300 dark:border-gray-700 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" +
(disabled ? " bg-gray-200" : "") (disabled ? " bg-gray-200" : "")
} }
> >
{myValue !== "" ? myValue : 'Text empty'} {myValue !== "" ? myValue : "Text empty"}
</span> </span>
<button onClick={()=>{openPopUp(<CodeAreaModal value={myValue} setValue={(t:string) => {setMyValue(t); onChange(t);}}/>)}}> <button
onClick={() => {
openPopUp(
<CodeAreaModal
value={myValue}
setValue={(t: string) => {
setMyValue(t);
onChange(t);
}}
/>
);
}}
>
<ArrowTopRightOnSquareIcon className="w-6 h-6 hover:text-blue-600" /> <ArrowTopRightOnSquareIcon className="w-6 h-6 hover:text-blue-600" />
</button> </button>
</div> </div>

View file

@ -1,3 +1,4 @@
import { errorsTypeAPI } from './../../types/api/index';
import { APIObjectType, sendAllProps } from '../../types/api/index'; import { APIObjectType, sendAllProps } from '../../types/api/index';
import axios, { AxiosResponse } from "axios"; import axios, { AxiosResponse } from "axios";
@ -9,7 +10,7 @@ export async function sendAll(data:sendAllProps) {
return await axios.post(`/predict`, data); return await axios.post(`/predict`, data);
} }
export async function checkCode(code:string){ export async function checkCode(code:string):Promise<AxiosResponse<errorsTypeAPI>>{
return await axios.post('/validate',{code}) return await axios.post('/validate',{code})
} }

View file

@ -120,13 +120,42 @@ export default function CodeAreaModal({
type="button" type="button"
className="inline-flex w-full justify-center rounded-md border border-transparent bg-indigo-600 px-4 py-2 text-base font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 sm:ml-3 sm:w-auto sm:text-sm" className="inline-flex w-full justify-center rounded-md border border-transparent bg-indigo-600 px-4 py-2 text-base font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 sm:ml-3 sm:w-auto sm:text-sm"
onClick={() => { onClick={() => {
setValue(code)
checkCode(code) checkCode(code)
.then((_) =>{ .then((apiReturn) => {
setSuccessData({ title: "Code is ready to run" }) console.log(apiReturn);
setModalOpen(false) if (apiReturn.data) {
console.log(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((_) => .catch((_) =>
setErrorData({ setErrorData({
title: title:

View file

@ -16,3 +16,4 @@ export type sendAllProps={
chatHistory:{message:string,isSend:boolean}[], chatHistory:{message:string,isSend:boolean}[],
}; };
export type errorsTypeAPI={function:{errors:Array<string>},imports:{errors:Array<string>}}