💡 (hooks): add TypeScript types to hook parameters for better type safety
💡 (index.tsx): add non-null assertion operator to playground variable ♻️ (use-on-file-drop.tsx): add type annotations for folderId and folderChangeCallback ♻️ (use-auto-resize-text-area.tsx): add type annotations for value and inputRef ♻️ (use-drag-and-drop.tsx): add type annotations for setIsDragging, setFiles, currentFlowId, and setErrorData ♻️ (use-focus-unlock.tsx): add type annotations for lockChat and inputRef ♻️ (use-upload.tsx): add type annotations for uploadFile, currentFlowId, setFiles, and lockChat ♻️ (use-column-defs.tsx): add type annotation for myData ♻️ (use-row-data.tsx): add type annotations for myData and open ♻️ (index.tsx): remove commented-out code ♻️ (use-filtered-flows.tsx): add type annotations for flowsFromFolder, searchFlowsComponents, and setAllFlows 💡 (index.tsx): add non-null assertion operator to flowsFromFolder variable
This commit is contained in:
parent
1d7dd4550e
commit
1031e62ede
22 changed files with 104 additions and 73 deletions
|
|
@ -6,13 +6,14 @@ import {
|
||||||
} from "../../constants/constants";
|
} from "../../constants/constants";
|
||||||
import useAlertStore from "../../stores/alertStore";
|
import useAlertStore from "../../stores/alertStore";
|
||||||
import { ResponseErrorDetailAPI } from "../../types/api";
|
import { ResponseErrorDetailAPI } from "../../types/api";
|
||||||
|
import { NodeDataType } from "../../types/flow";
|
||||||
|
|
||||||
const useFetchDataOnMount = (
|
const useFetchDataOnMount = (
|
||||||
data,
|
data: NodeDataType,
|
||||||
name,
|
name: string,
|
||||||
handleUpdateValues,
|
handleUpdateValues: (name: string, data: NodeDataType) => Promise<any>,
|
||||||
setNode,
|
setNode: (id: string, callback: (oldNode: any) => any) => void,
|
||||||
setIsLoading,
|
setIsLoading: (value: boolean) => void,
|
||||||
) => {
|
) => {
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,16 @@ import {
|
||||||
} from "../../constants/constants";
|
} from "../../constants/constants";
|
||||||
import useAlertStore from "../../stores/alertStore";
|
import useAlertStore from "../../stores/alertStore";
|
||||||
import { ResponseErrorTypeAPI } from "../../types/api";
|
import { ResponseErrorTypeAPI } from "../../types/api";
|
||||||
|
import { NodeDataType } from "../../types/flow";
|
||||||
|
|
||||||
const useHandleOnNewValue = (
|
const useHandleOnNewValue = (
|
||||||
data,
|
data: NodeDataType,
|
||||||
name,
|
name: string,
|
||||||
takeSnapshot,
|
takeSnapshot: () => void,
|
||||||
handleUpdateValues,
|
handleUpdateValues: (name: string, data: NodeDataType) => Promise<any>,
|
||||||
debouncedHandleUpdateValues,
|
debouncedHandleUpdateValues: any,
|
||||||
setNode,
|
setNode: (id: string, callback: (oldNode: any) => any) => void,
|
||||||
setIsLoading,
|
setIsLoading: (value: boolean) => void,
|
||||||
) => {
|
) => {
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import { cloneDeep } from "lodash";
|
import { cloneDeep } from "lodash";
|
||||||
|
import { NodeDataType } from "../../types/flow";
|
||||||
|
|
||||||
const useHandleNodeClass = (
|
const useHandleNodeClass = (
|
||||||
data,
|
data: NodeDataType,
|
||||||
name,
|
name: string,
|
||||||
takeSnapshot,
|
takeSnapshot: () => void,
|
||||||
setNode,
|
setNode: (id: string, callback: (oldNode: any) => any) => void,
|
||||||
updateNodeInternals,
|
updateNodeInternals: (id: string) => void,
|
||||||
) => {
|
) => {
|
||||||
const handleNodeClass = (newNodeClass, code, type?: string) => {
|
const handleNodeClass = (newNodeClass, code, type?: string) => {
|
||||||
if (!data.node) return;
|
if (!data.node) return;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,10 @@ import useAlertStore from "../../stores/alertStore";
|
||||||
import { ResponseErrorDetailAPI } from "../../types/api";
|
import { ResponseErrorDetailAPI } from "../../types/api";
|
||||||
import { handleUpdateValues } from "../../utils/parameterUtils";
|
import { handleUpdateValues } from "../../utils/parameterUtils";
|
||||||
|
|
||||||
const useHandleRefreshButtonPress = (setIsLoading, setNode) => {
|
const useHandleRefreshButtonPress = (
|
||||||
|
setIsLoading: (value: boolean) => void,
|
||||||
|
setNode: (id: string, callback: (oldNode: any) => any) => void,
|
||||||
|
) => {
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
|
|
||||||
const handleRefreshButtonPress = async (name, data) => {
|
const handleRefreshButtonPress = async (name, data) => {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
import { FlowPoolType } from "../../types/zustand/flow";
|
||||||
|
|
||||||
const useUpdateValidationStatus = (dataId, flowPool, setValidationStatus) => {
|
const useUpdateValidationStatus = (
|
||||||
|
dataId: string,
|
||||||
|
flowPool: FlowPoolType,
|
||||||
|
setValidationStatus: (value: any) => void,
|
||||||
|
) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const relevantData =
|
const relevantData =
|
||||||
flowPool[dataId] && flowPool[dataId]?.length > 0
|
flowPool[dataId] && flowPool[dataId]?.length > 0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { isErrorLog } from "../../types/utils/typeCheckingUtils";
|
||||||
|
|
||||||
const useValidationStatusString = (
|
const useValidationStatusString = (
|
||||||
validationStatus: VertexBuildTypeAPI | null,
|
validationStatus: VertexBuildTypeAPI | null,
|
||||||
setValidationString,
|
setValidationString: (value: any) => void,
|
||||||
) => {
|
) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (validationStatus && validationStatus.data?.outputs) {
|
if (validationStatus && validationStatus.data?.outputs) {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
import { storeComponent } from "../../../types/store";
|
||||||
|
|
||||||
const useDataEffect = (
|
const useDataEffect = (
|
||||||
data,
|
data: storeComponent,
|
||||||
setLikedByUser,
|
setLikedByUser: (value: any) => void,
|
||||||
setLikesCount,
|
setLikesCount: (value: any) => void,
|
||||||
setDownloadsCount,
|
setDownloadsCount: (value: any) => void,
|
||||||
) => {
|
) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,18 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { getComponent } from "../../../controllers/API";
|
import { getComponent } from "../../../controllers/API";
|
||||||
import useFlowsManagerStore from "../../../stores/flowsManagerStore";
|
import useFlowsManagerStore from "../../../stores/flowsManagerStore";
|
||||||
|
import { storeComponent } from "../../../types/store";
|
||||||
import cloneFlowWithParent from "../../../utils/storeUtils";
|
import cloneFlowWithParent from "../../../utils/storeUtils";
|
||||||
|
|
||||||
const useInstallComponent = (
|
const useInstallComponent = (
|
||||||
data,
|
data: storeComponent,
|
||||||
name,
|
name: string,
|
||||||
isStore,
|
isStore: boolean,
|
||||||
downloadsCount,
|
downloadsCount: number,
|
||||||
setDownloadsCount,
|
setDownloadsCount: (value: any) => void,
|
||||||
setLoading,
|
setLoading: (value: boolean) => void,
|
||||||
setSuccessData,
|
setSuccessData: (value: { title: string }) => void,
|
||||||
setErrorData,
|
setErrorData: (value: { title: string; list: string[] }) => void,
|
||||||
) => {
|
) => {
|
||||||
const addFlow = useFlowsManagerStore((state) => state.addFlow);
|
const addFlow = useFlowsManagerStore((state) => state.addFlow);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
import { postLikeComponent } from "../../../controllers/API";
|
import { postLikeComponent } from "../../../controllers/API";
|
||||||
|
import { storeComponent } from "../../../types/store";
|
||||||
|
|
||||||
const useLikeComponent = (
|
const useLikeComponent = (
|
||||||
data,
|
data: storeComponent,
|
||||||
name,
|
name: string,
|
||||||
setLoadingLike,
|
setLoadingLike: (value: boolean) => void,
|
||||||
likedByUser,
|
likedByUser: boolean | null | undefined,
|
||||||
likesCount,
|
likesCount: number,
|
||||||
setLikedByUser,
|
setLikedByUser: (value: any) => void,
|
||||||
setLikesCount,
|
setLikesCount: (value: any) => void,
|
||||||
setValidApiKey,
|
setValidApiKey: (value: boolean) => void,
|
||||||
setErrorData,
|
setErrorData: (value: { title: string; list: string[] }) => void,
|
||||||
) => {
|
) => {
|
||||||
const handleLike = () => {
|
const handleLike = () => {
|
||||||
setLoadingLike(true);
|
setLoadingLike(true);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import useFlowsManagerStore from "../../../stores/flowsManagerStore";
|
import useFlowsManagerStore from "../../../stores/flowsManagerStore";
|
||||||
|
import { storeComponent } from "../../../types/store";
|
||||||
import DragCardComponent from "../components/dragCardComponent";
|
import DragCardComponent from "../components/dragCardComponent";
|
||||||
|
|
||||||
const useDragStart = (data) => {
|
const useDragStart = (data: storeComponent) => {
|
||||||
const getFlowById = useFlowsManagerStore((state) => state.getFlowById);
|
const getFlowById = useFlowsManagerStore((state) => state.getFlowById);
|
||||||
|
|
||||||
const onDragStart = useCallback(
|
const onDragStart = useCallback(
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
import { FlowType } from "../../../types/flow";
|
||||||
|
|
||||||
const usePlaygroundEffect = (
|
const usePlaygroundEffect = (
|
||||||
currentFlowId,
|
currentFlowId: string,
|
||||||
playground,
|
playground: boolean,
|
||||||
openPlayground,
|
openPlayground: boolean,
|
||||||
currentFlow,
|
currentFlow: FlowType | undefined,
|
||||||
setNodes,
|
setNodes: (value: any, value2: boolean) => void,
|
||||||
setEdges,
|
setEdges: (value: any, value2: boolean) => void,
|
||||||
cleanFlowPool,
|
cleanFlowPool: () => void,
|
||||||
) => {
|
) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentFlowId && playground) {
|
if (currentFlowId && playground) {
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ export default function CollectionCardComponent({
|
||||||
|
|
||||||
usePlaygroundEffect(
|
usePlaygroundEffect(
|
||||||
currentFlowId,
|
currentFlowId,
|
||||||
playground,
|
playground!,
|
||||||
openPlayground,
|
openPlayground,
|
||||||
currentFlow,
|
currentFlow,
|
||||||
setNodes,
|
setNodes,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,10 @@ import useFlowsManagerStore from "../../../stores/flowsManagerStore";
|
||||||
import { useFolderStore } from "../../../stores/foldersStore";
|
import { useFolderStore } from "../../../stores/foldersStore";
|
||||||
import { addVersionToDuplicates } from "../../../utils/reactflowUtils";
|
import { addVersionToDuplicates } from "../../../utils/reactflowUtils";
|
||||||
|
|
||||||
const useFileDrop = (folderId, folderChangeCallback) => {
|
const useFileDrop = (
|
||||||
|
folderId: string,
|
||||||
|
folderChangeCallback: (folderId: string) => void,
|
||||||
|
) => {
|
||||||
const setFolderDragging = useFolderStore((state) => state.setFolderDragging);
|
const setFolderDragging = useFolderStore((state) => state.setFolderDragging);
|
||||||
const setFolderIdDragging = useFolderStore(
|
const setFolderIdDragging = useFolderStore(
|
||||||
(state) => state.setFolderIdDragging,
|
(state) => state.setFolderIdDragging,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
||||||
const useAutoResizeTextArea = (value, inputRef) => {
|
const useAutoResizeTextArea = (
|
||||||
|
value: string,
|
||||||
|
inputRef: React.RefObject<HTMLInputElement>,
|
||||||
|
) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (inputRef.current && inputRef.current.scrollHeight! !== 0) {
|
if (inputRef.current && inputRef.current.scrollHeight! !== 0) {
|
||||||
inputRef.current.style!.height = "inherit"; // Reset the height
|
inputRef.current.style!.height = "inherit"; // Reset the height
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@ import {
|
||||||
import useFileUpload from "./use-file-upload";
|
import useFileUpload from "./use-file-upload";
|
||||||
|
|
||||||
const useDragAndDrop = (
|
const useDragAndDrop = (
|
||||||
setIsDragging,
|
setIsDragging: (value: boolean) => void,
|
||||||
setFiles,
|
setFiles: (value: any) => void,
|
||||||
currentFlowId,
|
currentFlowId: string,
|
||||||
setErrorData,
|
setErrorData: (value: any) => void,
|
||||||
) => {
|
) => {
|
||||||
const dragOver = (e) => {
|
const dragOver = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
||||||
const useFocusOnUnlock = (lockChat, inputRef) => {
|
const useFocusOnUnlock = (
|
||||||
|
lockChat: boolean,
|
||||||
|
inputRef: React.RefObject<HTMLInputElement>,
|
||||||
|
) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!lockChat && inputRef.current) {
|
if (!lockChat && inputRef.current) {
|
||||||
inputRef.current.focus();
|
inputRef.current.focus();
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { AxiosResponse } from "axios";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import ShortUniqueId from "short-unique-id";
|
import ShortUniqueId from "short-unique-id";
|
||||||
import {
|
import {
|
||||||
|
|
@ -6,9 +7,18 @@ import {
|
||||||
SN_ERROR_TEXT,
|
SN_ERROR_TEXT,
|
||||||
} from "../../../../../../constants/constants";
|
} from "../../../../../../constants/constants";
|
||||||
import useAlertStore from "../../../../../../stores/alertStore";
|
import useAlertStore from "../../../../../../stores/alertStore";
|
||||||
|
import { UploadFileTypeAPI } from "../../../../../../types/api";
|
||||||
import useFileUpload from "./use-file-upload";
|
import useFileUpload from "./use-file-upload";
|
||||||
|
|
||||||
const useUpload = (uploadFile, currentFlowId, setFiles, lockChat) => {
|
const useUpload = (
|
||||||
|
uploadFile: (
|
||||||
|
file: File,
|
||||||
|
id: string,
|
||||||
|
) => Promise<AxiosResponse<UploadFileTypeAPI>>,
|
||||||
|
currentFlowId: string,
|
||||||
|
setFiles: any,
|
||||||
|
lockChat: boolean,
|
||||||
|
) => {
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handlePaste = (event: ClipboardEvent): void => {
|
const handlePaste = (event: ClipboardEvent): void => {
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@ import { ColDef, ValueGetterParams } from "ag-grid-community";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import TableNodeCellRender from "../../../components/tableComponent/components/tableNodeCellRender";
|
import TableNodeCellRender from "../../../components/tableComponent/components/tableNodeCellRender";
|
||||||
import TableToggleCellRender from "../../../components/tableComponent/components/tableToggleCellRender";
|
import TableToggleCellRender from "../../../components/tableComponent/components/tableToggleCellRender";
|
||||||
|
import { NodeDataType } from "../../../types/flow";
|
||||||
|
|
||||||
const useColumnDefs = (
|
const useColumnDefs = (
|
||||||
myData: any,
|
myData: NodeDataType,
|
||||||
handleOnNewValue: (newValue: any, name: string) => void,
|
handleOnNewValue: (newValue: any, name: string) => void,
|
||||||
handleOnChangeDb: (value: boolean, key: string) => void,
|
handleOnChangeDb: (value: boolean, key: string) => void,
|
||||||
changeAdvanced: (n: string) => void,
|
changeAdvanced: (n: string) => void,
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { LANGFLOW_SUPPORTED_TYPES } from "../../../constants/constants";
|
import { LANGFLOW_SUPPORTED_TYPES } from "../../../constants/constants";
|
||||||
import { TemplateVariableType } from "../../../types/api";
|
import { NodeDataType } from "../../../types/flow";
|
||||||
|
|
||||||
const useRowData = (myData, open) => {
|
const useRowData = (myData: NodeDataType, open: boolean) => {
|
||||||
const rowData = useMemo(() => {
|
const rowData = useMemo(() => {
|
||||||
return Object.keys(myData.node!.template)
|
return Object.keys(myData.node!.template)
|
||||||
.filter((key: string) => {
|
.filter((key: string) => {
|
||||||
const templateParam = myData.node!.template[
|
const templateParam = myData.node!.template[key] as any;
|
||||||
key
|
|
||||||
] as TemplateVariableType;
|
|
||||||
return (
|
return (
|
||||||
key.charAt(0) !== "_" &&
|
key.charAt(0) !== "_" &&
|
||||||
templateParam.show &&
|
templateParam.show &&
|
||||||
|
|
@ -20,9 +18,7 @@ const useRowData = (myData, open) => {
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.map((key: string) => {
|
.map((key: string) => {
|
||||||
const templateParam = myData.node!.template[
|
const templateParam = myData.node!.template[key] as any;
|
||||||
key
|
|
||||||
] as TemplateVariableType;
|
|
||||||
return {
|
return {
|
||||||
...templateParam,
|
...templateParam,
|
||||||
key: key,
|
key: key,
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,11 @@ const EditNodeModal = forwardRef(
|
||||||
nodeLength,
|
nodeLength,
|
||||||
open,
|
open,
|
||||||
setOpen,
|
setOpen,
|
||||||
// setOpenWDoubleClick,
|
|
||||||
data,
|
data,
|
||||||
}: {
|
}: {
|
||||||
nodeLength: number;
|
nodeLength: number;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
setOpen: (open: boolean) => void;
|
setOpen: (open: boolean) => void;
|
||||||
// setOpenWDoubleClick: (open: boolean) => void;
|
|
||||||
data: NodeDataType;
|
data: NodeDataType;
|
||||||
},
|
},
|
||||||
ref,
|
ref,
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import cloneDeep from "lodash/cloneDeep";
|
import cloneDeep from "lodash/cloneDeep";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
import { FlowType } from "../../../../../types/flow";
|
||||||
|
|
||||||
const useFilteredFlows = (
|
const useFilteredFlows = (
|
||||||
flowsFromFolder,
|
flowsFromFolder: FlowType[],
|
||||||
searchFlowsComponents,
|
searchFlowsComponents: string,
|
||||||
setAllFlows,
|
setAllFlows: (value: any[]) => void,
|
||||||
) => {
|
) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const newFlows = cloneDeep(flowsFromFolder || []);
|
const newFlows = cloneDeep(flowsFromFolder || []);
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ export default function ComponentsComponent({
|
||||||
getFolderById(folderId ? folderId : myCollectionId);
|
getFolderById(folderId ? folderId : myCollectionId);
|
||||||
}, [location]);
|
}, [location]);
|
||||||
|
|
||||||
useFilteredFlows(flowsFromFolder, searchFlowsComponents, setAllFlows);
|
useFilteredFlows(flowsFromFolder!, searchFlowsComponents, setAllFlows);
|
||||||
|
|
||||||
const resetFilter = () => {
|
const resetFilter = () => {
|
||||||
setPageIndex(1);
|
setPageIndex(1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue