From d2c2fe6db0b0bac77c2170b562cd30a35dcedffe Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Thu, 3 Aug 2023 18:35:13 -0300 Subject: [PATCH] added some types in problematic points --- .../components/parameterComponent/index.tsx | 12 ++++++++++-- .../chatComponent/buildTrigger/index.tsx | 4 +++- .../headerComponent/components/menuBar/index.tsx | 6 ++++-- src/frontend/src/contexts/tabsContext.tsx | 15 ++++++++++----- src/frontend/src/contexts/typesContext.tsx | 5 +++-- src/frontend/src/modals/exportModal/index.tsx | 1 - src/frontend/src/types/components/index.ts | 1 - src/frontend/src/types/flow/index.ts | 2 +- src/frontend/src/types/tabs/index.ts | 6 ++++-- src/frontend/src/types/typesContext/index.ts | 2 +- 10 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index d0a10f791..dc660938e 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -1,5 +1,11 @@ import { cloneDeep } from "lodash"; -import React, { ReactNode, useContext, useEffect, useRef, useState } from "react"; +import React, { + ReactNode, + useContext, + useEffect, + useRef, + useState, +} from "react"; import { Handle, Position, useUpdateNodeInternals } from "reactflow"; import ShadTooltip from "../../../../components/ShadTooltipComponent"; import CodeAreaComponent from "../../../../components/codeAreaComponent"; @@ -17,6 +23,7 @@ import { TOOLTIP_EMPTY } from "../../../../constants/constants"; import { TabsContext } from "../../../../contexts/tabsContext"; import { typesContext } from "../../../../contexts/typesContext"; import { ParameterComponentType } from "../../../../types/components"; +import { TabsState } from "../../../../types/tabs"; import { isValidConnection } from "../../../../utils/reactflowUtils"; import { nodeColors, @@ -71,7 +78,8 @@ export default function ParameterComponent({ newData.node!.template[name].value = newValue; setData(newData); // Set state to pending - setTabsState((prev) => { + //@ts-ignore + setTabsState((prev: TabsState) => { return { ...prev, [tabId]: { diff --git a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx index 25053fbeb..d29f7ea7b 100644 --- a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx +++ b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx @@ -9,6 +9,7 @@ import { FlowType } from "../../../types/flow"; import { TabsContext } from "../../../contexts/tabsContext"; import { parsedDataType } from "../../../types/components"; +import { TabsState } from "../../../types/tabs"; import { validateNodes } from "../../../utils/reactflowUtils"; import RadialProgressComponent from "../../RadialProgress"; import IconComponent from "../../genericIconComponent"; @@ -90,7 +91,8 @@ export default function BuildTrigger({ // If the event is a log, log it setSuccessData({ title: parsedData.log }); } else if (parsedData.input_keys) { - setTabsState((old) => { + //@ts-ignore + setTabsState((old: TabsState) => { return { ...old, [flowId]: { diff --git a/src/frontend/src/components/headerComponent/components/menuBar/index.tsx b/src/frontend/src/components/headerComponent/components/menuBar/index.tsx index eb2e65ce5..3b3611f16 100644 --- a/src/frontend/src/components/headerComponent/components/menuBar/index.tsx +++ b/src/frontend/src/components/headerComponent/components/menuBar/index.tsx @@ -26,7 +26,7 @@ export const MenuBar = ({ flows, tabId }: menuBarPropsType): JSX.Element => { function handleAddFlow() { try { - addFlow(null, true).then((id) => { + addFlow(undefined, true).then((id) => { navigate("/flow/" + id); }); // saveFlowStyleInDataBase(); @@ -46,7 +46,9 @@ export const MenuBar = ({ flows, tabId }: menuBarPropsType): JSX.Element => { diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index 8f5eea2e3..c90427670 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -7,7 +7,7 @@ import { useRef, useState, } from "react"; -import { addEdge } from "reactflow"; +import { Node, addEdge } from "reactflow"; import ShortUniqueId from "short-unique-id"; import { deleteFlowFromDatabase, @@ -18,7 +18,7 @@ import { uploadFlowsToDatabase, } from "../controllers/API"; import { APIClassType, APITemplateType } from "../types/api"; -import { FlowType, NodeType } from "../types/flow"; +import { FlowType, NodeDataType, NodeType } from "../types/flow"; import { TabsContextType, TabsState } from "../types/tabs"; import { addVersionToDuplicates, @@ -73,7 +73,10 @@ export function TabsProvider({ children }: { children: ReactNode }) { const [flows, setFlows] = useState>([]); const [id, setId] = useState(uid()); const { templates, reactFlowInstance } = useContext(typesContext); - const [lastCopiedSelection, setLastCopiedSelection] = useState(null); + const [lastCopiedSelection, setLastCopiedSelection] = useState<{ + nodes: any; + edges: any; + } | null>(null); const [tabsState, setTabsState] = useState({}); const [getTweak, setTweak] = useState([]); @@ -318,7 +321,9 @@ export function TabsProvider({ children }: { children: ReactNode }) { // add a change event listener to the file input input.onchange = (e: Event) => { // check if the file type is application/json - if ((e.target as HTMLInputElement).files![0].type === "application/json") { + if ( + (e.target as HTMLInputElement).files![0].type === "application/json" + ) { // get the file from the file input const file = (e.target as HTMLInputElement).files![0]; // read the file as text @@ -357,7 +362,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { let minimumX = Infinity; let minimumY = Infinity; let idsMap = {}; - let nodes = reactFlowInstance!.getNodes(); + let nodes: Node[] = reactFlowInstance!.getNodes(); let edges = reactFlowInstance!.getEdges(); selectionInstance.nodes.forEach((n) => { if (n.position.y < minimumY) { diff --git a/src/frontend/src/contexts/typesContext.tsx b/src/frontend/src/contexts/typesContext.tsx index 70e1e7e83..3f7a1810b 100644 --- a/src/frontend/src/contexts/typesContext.tsx +++ b/src/frontend/src/contexts/typesContext.tsx @@ -8,7 +8,7 @@ import { typesContextType } from "../types/typesContext"; const initialValue: typesContextType = { reactFlowInstance: null, - setReactFlowInstance: () => {}, + setReactFlowInstance: (newState: ReactFlowInstance) => {}, deleteNode: () => {}, types: {}, setTypes: () => {}, @@ -22,7 +22,8 @@ export const typesContext = createContext(initialValue); export function TypesProvider({ children }: { children: ReactNode }) { const [types, setTypes] = useState({}); - const [reactFlowInstance, setReactFlowInstance] = useState(null); + const [reactFlowInstance, setReactFlowInstance] = + useState(null); const [templates, setTemplates] = useState({}); const [data, setData] = useState({}); diff --git a/src/frontend/src/modals/exportModal/index.tsx b/src/frontend/src/modals/exportModal/index.tsx index 7d797ad66..5aff51b9d 100644 --- a/src/frontend/src/modals/exportModal/index.tsx +++ b/src/frontend/src/modals/exportModal/index.tsx @@ -37,7 +37,6 @@ const ExportModal = forwardRef( tabId={tabId} setName={setName} setDescription={setDescription} - updateFlow={updateFlow} />
void; setDescription: (description: string) => void; - updateFlow: (flow: { id: string; name: string; }) => void; setInvalidName: (invalidName: boolean) => void; }; diff --git a/src/frontend/src/types/flow/index.ts b/src/frontend/src/types/flow/index.ts index dce4e0044..c19301ebb 100644 --- a/src/frontend/src/types/flow/index.ts +++ b/src/frontend/src/types/flow/index.ts @@ -11,7 +11,7 @@ export type FlowType = { export type NodeType = { id: string; type?: string; - position: XYPosition | undefined; + position: XYPosition; data: NodeDataType; }; diff --git a/src/frontend/src/types/tabs/index.ts b/src/frontend/src/types/tabs/index.ts index 6ced6a789..deb2b21ed 100644 --- a/src/frontend/src/types/tabs/index.ts +++ b/src/frontend/src/types/tabs/index.ts @@ -1,4 +1,3 @@ -import { Dispatch, SetStateAction } from "react"; import { FlowType, TweaksType } from "../flow"; export type TabsContextType = { @@ -8,7 +7,10 @@ export type TabsContextType = { setTabId: (index: string) => void; flows: Array; removeFlow: (id: string) => void; - addFlow: (flowData?: FlowType | undefined | null, newProject?: boolean) => Promise; + addFlow: ( + flow?: FlowType, + newProject?: Boolean + ) => Promise; updateFlow: (newFlow: FlowType) => void; incrementNodeId: () => string; downloadFlow: ( diff --git a/src/frontend/src/types/typesContext/index.ts b/src/frontend/src/types/typesContext/index.ts index 0506e3e34..974f8e1ed 100644 --- a/src/frontend/src/types/typesContext/index.ts +++ b/src/frontend/src/types/typesContext/index.ts @@ -8,7 +8,7 @@ const data: { [char: string]: string } = {}; export type typesContextType = { reactFlowInstance: ReactFlowInstance | null; - setReactFlowInstance: () => void; + setReactFlowInstance: (newState: ReactFlowInstance) => void; deleteNode: (idx: string) => void; types: typeof types; setTypes: (newState: {}) => void;