add more types

This commit is contained in:
Igor Carvalho 2023-08-06 19:19:48 -03:00
commit bdc100d188
12 changed files with 36 additions and 33 deletions

View file

@ -121,7 +121,7 @@ export default function BuildTrigger({
// Step 3: Wait for the stream to finish // Step 3: Wait for the stream to finish
while (!finished) { while (!finished) {
await new Promise((resolve) => setTimeout(resolve, 100)); await new Promise((resolve) => setTimeout(resolve, 100));
finished = validationResults.length === flow.data.nodes.length; finished = validationResults.length === flow.data!.nodes.length;
} }
// Step 4: Return true if all nodes are valid, false otherwise // Step 4: Return true if all nodes are valid, false otherwise
return validationResults.every((result) => result); return validationResults.every((result) => result);

View file

@ -28,6 +28,7 @@ import {
import { getRandomDescription, getRandomName } from "../utils/utils"; import { getRandomDescription, getRandomName } from "../utils/utils";
import { alertContext } from "./alertContext"; import { alertContext } from "./alertContext";
import { typesContext } from "./typesContext"; import { typesContext } from "./typesContext";
import { tweakType } from "../types/components";
const uid = new ShortUniqueId({ length: 5 }); const uid = new ShortUniqueId({ length: 5 });
@ -78,7 +79,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
edges: any; edges: any;
} | null>(null); } | null>(null);
const [tabsState, setTabsState] = useState<TabsState>({}); const [tabsState, setTabsState] = useState<TabsState>({});
const [getTweak, setTweak] = useState<TweaksType[]>([]); const [getTweak, setTweak] = useState<tweakType>([]);
const newNodeId = useRef(uid()); const newNodeId = useRef(uid());
function incrementNodeId() { function incrementNodeId() {

View file

@ -2,6 +2,7 @@ import axios, { AxiosError, AxiosInstance } from "axios";
import { useContext, useEffect, useRef } from "react"; import { useContext, useEffect, useRef } from "react";
import { URL_EXCLUDED_FROM_ERROR_RETRIES } from "../../constants/constants"; import { URL_EXCLUDED_FROM_ERROR_RETRIES } from "../../constants/constants";
import { alertContext } from "../../contexts/alertContext"; import { alertContext } from "../../contexts/alertContext";
import { errorsVarType } from "../../types/tabs";
// Create a new Axios instance // Create a new Axios instance
const api: AxiosInstance = axios.create({ const api: AxiosInstance = axios.create({
@ -37,7 +38,7 @@ function ApiInterceptor(): null {
"Check if the backend is up", "Check if the backend is up",
"Endpoint: " + error.config?.url, "Endpoint: " + error.config?.url,
], ],
}); } as errorsVarType);
return Promise.reject(error); return Promise.reject(error);
} }
} }

View file

@ -179,7 +179,7 @@ export async function downloadFlowsFromDatabase() {
} }
} }
export async function uploadFlowsToDatabase(flows: FlowType[]) { export async function uploadFlowsToDatabase(flows: FormData) {
try { try {
const response = await api.post(`/api/v1/flows/upload/`, flows); const response = await api.post(`/api/v1/flows/upload/`, flows);

View file

@ -16,7 +16,7 @@ import CodeTabsComponent from "../../components/codeTabsComponent";
import IconComponent from "../../components/genericIconComponent"; import IconComponent from "../../components/genericIconComponent";
import { EXPORT_CODE_DIALOG } from "../../constants/constants"; import { EXPORT_CODE_DIALOG } from "../../constants/constants";
import { TabsContext } from "../../contexts/tabsContext"; import { TabsContext } from "../../contexts/tabsContext";
import { FlowType, NodeType } from "../../types/flow/index"; import { FlowType, NodeType, TweaksType } from "../../types/flow/index";
import { buildTweaks } from "../../utils/reactflowUtils"; import { buildTweaks } from "../../utils/reactflowUtils";
import { import {
getCurlCode, getCurlCode,
@ -26,7 +26,7 @@ import {
} from "../../utils/utils"; } from "../../utils/utils";
import BaseModal from "../baseModal"; import BaseModal from "../baseModal";
import { tweakType } from "../../types/components"; import { tweakType } from "../../types/components";
import { APITemplateType } from "../../types/api"; import { APITemplateType, TemplateVariableType } from "../../types/api";
const ApiModal = forwardRef( const ApiModal = forwardRef(
( (
@ -43,7 +43,7 @@ const ApiModal = forwardRef(
) => { ) => {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [activeTab, setActiveTab] = useState("0"); const [activeTab, setActiveTab] = useState("0");
const tweak = useRef<tweakType[]>([]); const tweak = useRef<tweakType>([]);
const tweaksList = useRef<string[]>([]); const tweaksList = useRef<string[]>([]);
const { setTweak, getTweak, tabsState } = useContext(TabsContext); const { setTweak, getTweak, tabsState } = useContext(TabsContext);
const pythonApiCode = getPythonApiCode(flow, tweak.current, tabsState); const pythonApiCode = getPythonApiCode(flow, tweak.current, tabsState);
@ -92,7 +92,7 @@ const ApiModal = forwardRef(
} }
useEffect(() => { useEffect(() => {
if (flow["data"]["nodes"].length == 0) { if (flow["data"]!["nodes"].length == 0) {
startState(); startState();
} else { } else {
tweak.current = []; tweak.current = [];
@ -179,12 +179,12 @@ const ApiModal = forwardRef(
}, },
]); ]);
} }
}, [flow["data"]["nodes"], open]); }, [flow["data"]!["nodes"], open]);
function filterNodes() { function filterNodes() {
let arrNodesWithValues: string[] = []; let arrNodesWithValues: string[] = [];
flow["data"]["nodes"].forEach((t) => { flow["data"]!["nodes"].forEach((t) => {
Object.keys(t["data"]["node"]["template"]) Object.keys(t["data"]["node"]["template"])
.filter( .filter(
(n) => (n) =>
@ -207,7 +207,7 @@ const ApiModal = forwardRef(
return self.indexOf(value) === index; return self.indexOf(value) === index;
}); });
} }
function buildTweakObject(tw: string, changes: string | string[], template: APITemplateType) { function buildTweakObject(tw: string | string[], changes: string | string[] | boolean, template: TemplateVariableType) {
if (template.type === "float") { if (template.type === "float") {
changes = parseFloat(changes); changes = parseFloat(changes);
} }

View file

@ -317,7 +317,7 @@ export default function FormModal({
setErrorData({ setErrorData({
title: "There was an error sending the message", title: "There was an error sending the message",
list: [error.message], list: [error.message],
}); } as errorsVarType);
setChatValue(data.inputs); setChatValue(data.inputs);
connectWS(); connectWS();
} }

View file

@ -1,4 +1,4 @@
import { useContext, useEffect, useRef, useState } from "react"; import { Ref, RefObject, useContext, useEffect, useRef, useState } from "react";
import SanitizedHTMLWrapper from "../../components/SanitizedHTMLWrapper"; import SanitizedHTMLWrapper from "../../components/SanitizedHTMLWrapper";
import ShadTooltip from "../../components/ShadTooltipComponent"; import ShadTooltip from "../../components/ShadTooltipComponent";
import IconComponent from "../../components/genericIconComponent"; import IconComponent from "../../components/genericIconComponent";
@ -42,7 +42,7 @@ export default function GenericModal({
const [wordsHighlight, setWordsHighlight] = useState<string[]>([]); const [wordsHighlight, setWordsHighlight] = useState<string[]>([]);
const { setErrorData, setSuccessData, setNoticeData } = const { setErrorData, setSuccessData, setNoticeData } =
useContext(alertContext); useContext(alertContext);
const ref = useRef<HTMLTextAreaElement | undefined>(); const ref = useRef<RefObject<HTMLTextAreaElement>>();
const divRef = useRef(null); const divRef = useRef(null);
const divRefPrompt = useRef(null); const divRefPrompt = useRef(null);
@ -208,7 +208,7 @@ export default function GenericModal({
<TextAreaContentView /> <TextAreaContentView />
) : type !== TypeModal.PROMPT ? ( ) : type !== TypeModal.PROMPT ? (
<Textarea <Textarea
ref={ref!} ref={ref}
className="form-input h-full w-full rounded-lg focus-visible:ring-1" className="form-input h-full w-full rounded-lg focus-visible:ring-1"
value={inputValue} value={inputValue}
onChange={(e) => { onChange={(e) => {

View file

@ -1,10 +1,10 @@
import { Edge, Node, Viewport } from "reactflow"; import { Edge, Node, Viewport } from "reactflow";
//kind and class are just representative names to represent the actual structure of the object received by the API //kind and class are just representative names to represent the actual structure of the object received by the API
export type APIDataType = { [key: string]: APIKindType }
export type APIObjectType = { kind?: APIKindType; [key: string]: APIKindType }; export type APIObjectType = { kind: APIKindType; [key: string]: APIKindType };
export type APIKindType = { class: APIClassType; [key: string]: APIClassType }; export type APIKindType = { class: APIClassType; [key: string]: APIClassType };
export type APITemplateType = { export type APITemplateType = {
variable?: TemplateVariableType; variable: TemplateVariableType;
[key: string]: TemplateVariableType; [key: string]: TemplateVariableType;
}; };
export type APIClassType = { export type APIClassType = {

View file

@ -1,6 +1,6 @@
import { ReactElement, ReactNode } from "react"; import { ReactElement, ReactNode } from "react";
import { ReactFlowJsonObject } from "reactflow"; import { ReactFlowJsonObject } from "reactflow";
import { APIClassType, APITemplateType } from "../api"; import { APIClassType, APITemplateType, TemplateVariableType } from "../api";
import { ChatMessageType } from "../chat"; import { ChatMessageType } from "../chat";
import { FlowStyleType, FlowType, NodeDataType, NodeType } from "../flow/index"; import { FlowStyleType, FlowType, NodeDataType, NodeType } from "../flow/index";
import { typesContextType } from "../typesContext"; import { typesContextType } from "../typesContext";
@ -217,11 +217,11 @@ type test = {
export type tweakType = { export type tweakType = Array<{
[key: string]: { [key: string]: {
[char: string]: string; [char: string]: string;
}; } & FlowStyleType;
}; }>;
export type apiModalTweakType = { export type apiModalTweakType = {
current: Array<{ current: Array<{
@ -419,7 +419,7 @@ export type codeTabsPropsType = {
setActiveTab: (value: string) => void; setActiveTab: (value: string) => void;
isMessage?: boolean; isMessage?: boolean;
tweaks?: { tweaks?: {
tweak?: { current: Array<tweakType> }; tweak?: { current: tweakType };
tweaksList?: { current: Array<string> }; tweaksList?: { current: Array<string> };
buildContent?: (value: string) => ReactNode; buildContent?: (value: string) => ReactNode;
getValue?: ( getValue?: (
@ -428,9 +428,9 @@ export type codeTabsPropsType = {
template: APITemplateType template: APITemplateType
) => string; ) => string;
buildTweakObject?: ( buildTweakObject?: (
tw: string, tw: string | string[],
changes: string | string[] | boolean | number, changes: string | string[] | boolean,
template: APITemplateType template: TemplateVariableType
) => string | void; ) => string | void;
}; };
}; };

View file

@ -1,5 +1,6 @@
import { Dispatch, SetStateAction } from "react"; import { Dispatch, SetStateAction } from "react";
import { FlowType, TweaksType } from "../flow"; import { FlowType, TweaksType } from "../flow";
import { tweakType } from "../components";
export type TabsContextType = { export type TabsContextType = {
saveFlow: (flow: FlowType) => Promise<void>; saveFlow: (flow: FlowType) => Promise<void>;
@ -34,8 +35,8 @@ export type TabsContextType = {
) => void; ) => void;
lastCopiedSelection: { nodes: any; edges: any } | null; lastCopiedSelection: { nodes: any; edges: any } | null;
setLastCopiedSelection: (selection: { nodes: any; edges: any }) => void; setLastCopiedSelection: (selection: { nodes: any; edges: any }) => void;
setTweak: Dispatch<SetStateAction<TweaksType[]>>; setTweak: (tweak: tweakType) => tweakType | void;
getTweak: TweaksType[]; getTweak: tweakType;
}; };
export type TabsState = { export type TabsState = {

View file

@ -1,6 +1,6 @@
import { Edge, Node, ReactFlowInstance } from "reactflow"; import { Edge, Node, ReactFlowInstance } from "reactflow";
import { AlertItemType } from "../alerts"; import { AlertItemType } from "../alerts";
import { APIClassType, APIObjectType } from "../api"; import { APIClassType, APIDataType, APIObjectType } from "../api";
const types: { [char: string]: string } = {}; const types: { [char: string]: string } = {};
const template: { [char: string]: APIClassType } = {}; const template: { [char: string]: APIClassType } = {};
@ -14,7 +14,7 @@ export type typesContextType = {
setTypes: (newState: {}) => void; setTypes: (newState: {}) => void;
templates: typeof template; templates: typeof template;
setTemplates: (newState: {}) => void; setTemplates: (newState: {}) => void;
data: APIObjectType; data: APIDataType;
setData: (newState: {}) => void; setData: (newState: {}) => void;
}; };

View file

@ -5,7 +5,7 @@ import { IVarHighlightType, groupDataType, groupedObjType, tweakType } from "../
import { FlowType, NodeType } from "../types/flow"; import { FlowType, NodeType } from "../types/flow";
import { TabsState } from "../types/tabs"; import { TabsState } from "../types/tabs";
import { buildTweaks } from "./reactflowUtils"; import { buildTweaks } from "./reactflowUtils";
import { APIClassType, APIObjectType } from "../types/api"; import { APIClassType, APIDataType, APIObjectType } from "../types/api";
export function classNames(...classes: Array<string>): string { export function classNames(...classes: Array<string>): string {
return classes.filter(Boolean).join(" "); return classes.filter(Boolean).join(" ");
@ -89,7 +89,7 @@ export function checkUpperWords(str: string): string {
export const isWrappedWithClass = (event: any, className: string | undefined) => export const isWrappedWithClass = (event: any, className: string | undefined) =>
event.target.closest(`.${className}`); event.target.closest(`.${className}`);
export function groupByFamily(data: APIObjectType, baseClasses: string, left: boolean, flow?: NodeType[]): groupedObjType[] { export function groupByFamily(data: APIDataType, baseClasses: string, left: boolean, flow?: NodeType[]): groupedObjType[] {
const baseClassesSet = new Set(baseClasses.split("\n")); const baseClassesSet = new Set(baseClasses.split("\n"));
let arrOfPossibleInputs: Array<{ category: string; nodes: string[]; full: boolean; }> = []; let arrOfPossibleInputs: Array<{ category: string; nodes: string[]; full: boolean; }> = [];
let arrOfPossibleOutputs: Array<{ category: string; nodes: string[]; full: boolean; }> = []; let arrOfPossibleOutputs: Array<{ category: string; nodes: string[]; full: boolean; }> = [];
@ -234,7 +234,7 @@ export function varHighlightHTML({ name }: IVarHighlightType): string {
return html; return html;
} }
export function buildTweakObject(tweak: tweakType[]) { export function buildTweakObject(tweak: tweakType) {
tweak.forEach((el) => { tweak.forEach((el) => {
Object.keys(el).forEach((key) => { Object.keys(el).forEach((key) => {
for (let kp in el[key]) { for (let kp in el[key]) {