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
while (!finished) {
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
return validationResults.every((result) => result);

View file

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

View file

@ -2,6 +2,7 @@ import axios, { AxiosError, AxiosInstance } from "axios";
import { useContext, useEffect, useRef } from "react";
import { URL_EXCLUDED_FROM_ERROR_RETRIES } from "../../constants/constants";
import { alertContext } from "../../contexts/alertContext";
import { errorsVarType } from "../../types/tabs";
// Create a new Axios instance
const api: AxiosInstance = axios.create({
@ -37,7 +38,7 @@ function ApiInterceptor(): null {
"Check if the backend is up",
"Endpoint: " + error.config?.url,
],
});
} as errorsVarType);
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 {
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 { EXPORT_CODE_DIALOG } from "../../constants/constants";
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 {
getCurlCode,
@ -26,7 +26,7 @@ import {
} from "../../utils/utils";
import BaseModal from "../baseModal";
import { tweakType } from "../../types/components";
import { APITemplateType } from "../../types/api";
import { APITemplateType, TemplateVariableType } from "../../types/api";
const ApiModal = forwardRef(
(
@ -43,7 +43,7 @@ const ApiModal = forwardRef(
) => {
const [open, setOpen] = useState(false);
const [activeTab, setActiveTab] = useState("0");
const tweak = useRef<tweakType[]>([]);
const tweak = useRef<tweakType>([]);
const tweaksList = useRef<string[]>([]);
const { setTweak, getTweak, tabsState } = useContext(TabsContext);
const pythonApiCode = getPythonApiCode(flow, tweak.current, tabsState);
@ -92,7 +92,7 @@ const ApiModal = forwardRef(
}
useEffect(() => {
if (flow["data"]["nodes"].length == 0) {
if (flow["data"]!["nodes"].length == 0) {
startState();
} else {
tweak.current = [];
@ -179,12 +179,12 @@ const ApiModal = forwardRef(
},
]);
}
}, [flow["data"]["nodes"], open]);
}, [flow["data"]!["nodes"], open]);
function filterNodes() {
let arrNodesWithValues: string[] = [];
flow["data"]["nodes"].forEach((t) => {
flow["data"]!["nodes"].forEach((t) => {
Object.keys(t["data"]["node"]["template"])
.filter(
(n) =>
@ -207,7 +207,7 @@ const ApiModal = forwardRef(
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") {
changes = parseFloat(changes);
}

View file

@ -317,7 +317,7 @@ export default function FormModal({
setErrorData({
title: "There was an error sending the message",
list: [error.message],
});
} as errorsVarType);
setChatValue(data.inputs);
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 ShadTooltip from "../../components/ShadTooltipComponent";
import IconComponent from "../../components/genericIconComponent";
@ -42,7 +42,7 @@ export default function GenericModal({
const [wordsHighlight, setWordsHighlight] = useState<string[]>([]);
const { setErrorData, setSuccessData, setNoticeData } =
useContext(alertContext);
const ref = useRef<HTMLTextAreaElement | undefined>();
const ref = useRef<RefObject<HTMLTextAreaElement>>();
const divRef = useRef(null);
const divRefPrompt = useRef(null);
@ -208,7 +208,7 @@ export default function GenericModal({
<TextAreaContentView />
) : type !== TypeModal.PROMPT ? (
<Textarea
ref={ref!}
ref={ref}
className="form-input h-full w-full rounded-lg focus-visible:ring-1"
value={inputValue}
onChange={(e) => {

View file

@ -1,10 +1,10 @@
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
export type APIObjectType = { kind?: APIKindType; [key: string]: APIKindType };
export type APIDataType = { [key: string]: APIKindType }
export type APIObjectType = { kind: APIKindType; [key: string]: APIKindType };
export type APIKindType = { class: APIClassType; [key: string]: APIClassType };
export type APITemplateType = {
variable?: TemplateVariableType;
variable: TemplateVariableType;
[key: string]: TemplateVariableType;
};
export type APIClassType = {

View file

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

View file

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

View file

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

View file

@ -5,7 +5,7 @@ import { IVarHighlightType, groupDataType, groupedObjType, tweakType } from "../
import { FlowType, NodeType } from "../types/flow";
import { TabsState } from "../types/tabs";
import { buildTweaks } from "./reactflowUtils";
import { APIClassType, APIObjectType } from "../types/api";
import { APIClassType, APIDataType, APIObjectType } from "../types/api";
export function classNames(...classes: Array<string>): string {
return classes.filter(Boolean).join(" ");
@ -89,7 +89,7 @@ export function checkUpperWords(str: string): string {
export const isWrappedWithClass = (event: any, className: string | undefined) =>
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"));
let arrOfPossibleInputs: 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;
}
export function buildTweakObject(tweak: tweakType[]) {
export function buildTweakObject(tweak: tweakType) {
tweak.forEach((el) => {
Object.keys(el).forEach((key) => {
for (let kp in el[key]) {