From e1b5c70fa351e06536d250ee3528240b73b02bcc Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Thu, 16 Jan 2025 18:11:07 -0300 Subject: [PATCH] refactor: enhance flow type safety and clean up unused code (#5669) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 📝 (use-save-flow.ts): add AllNodeType and EdgeType imports to improve type safety in useSaveFlow hook 📝 (index.tsx): remove unused setNoticeData function to clean up code and improve readability * refactor: Remove unused code in GeneralPage component * refactor: Remove unused code in cardComponent/index.tsx --------- Co-authored-by: anovazzi1 --- src/frontend/src/components/core/cardComponent/index.tsx | 1 - src/frontend/src/hooks/flows/use-save-flow.ts | 7 +++++-- .../src/pages/FlowPage/components/PageComponent/index.tsx | 1 - .../src/pages/SettingsPage/pages/GeneralPage/index.tsx | 7 +------ 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/components/core/cardComponent/index.tsx b/src/frontend/src/components/core/cardComponent/index.tsx index 231602533..6e446fd6c 100644 --- a/src/frontend/src/components/core/cardComponent/index.tsx +++ b/src/frontend/src/components/core/cardComponent/index.tsx @@ -18,7 +18,6 @@ import { } from "../../ui/card"; import { Checkbox } from "../../ui/checkbox"; import { FormControl, FormField } from "../../ui/form"; -import Loading from "../../ui/loading"; import useDragStart from "./hooks/use-on-drag-start"; import { convertTestName } from "./utils/convert-test-name"; diff --git a/src/frontend/src/hooks/flows/use-save-flow.ts b/src/frontend/src/hooks/flows/use-save-flow.ts index df08aad5a..e4a9d36ed 100644 --- a/src/frontend/src/hooks/flows/use-save-flow.ts +++ b/src/frontend/src/hooks/flows/use-save-flow.ts @@ -3,7 +3,7 @@ import { usePatchUpdateFlow } from "@/controllers/API/queries/flows/use-patch-up import useAlertStore from "@/stores/alertStore"; import useFlowsManagerStore from "@/stores/flowsManagerStore"; import useFlowStore from "@/stores/flowStore"; -import { FlowType } from "@/types/flow"; +import { AllNodeType, EdgeType, FlowType } from "@/types/flow"; import { customStringify } from "@/utils/reactflowUtils"; import { ReactFlowJsonObject } from "@xyflow/react"; @@ -52,7 +52,10 @@ const useSaveFlow = () => { { id: flow!.id }, { onSuccess: (flowResponse) => { - flow!.data = flowResponse.data as ReactFlowJsonObject; + flow!.data = flowResponse.data as ReactFlowJsonObject< + AllNodeType, + EdgeType + >; }, }, ); diff --git a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx index d5f6d2c3e..800012454 100644 --- a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx @@ -115,7 +115,6 @@ export default function Page({ view }: { view?: boolean }): JSX.Element { ); const onConnect = useFlowStore((state) => state.onConnect); const setErrorData = useAlertStore((state) => state.setErrorData); - const setNoticeData = useAlertStore((state) => state.setNoticeData); const updateCurrentFlow = useFlowStore((state) => state.updateCurrentFlow); const [selectionMenuVisible, setSelectionMenuVisible] = useState(false); const edgeUpdateSuccessful = useRef(true); diff --git a/src/frontend/src/pages/SettingsPage/pages/GeneralPage/index.tsx b/src/frontend/src/pages/SettingsPage/pages/GeneralPage/index.tsx index 2f6546201..719c55174 100644 --- a/src/frontend/src/pages/SettingsPage/pages/GeneralPage/index.tsx +++ b/src/frontend/src/pages/SettingsPage/pages/GeneralPage/index.tsx @@ -24,7 +24,6 @@ import { patchUserInputStateType, } from "../../../../types/components"; import useScrollToElement from "../hooks/use-scroll-to-element"; -import StoreApiKeyFormComponent from "../StoreApiKeyPage/components/StoreApiKeyForm"; import GeneralPageHeaderComponent from "./components/GeneralPageHeader"; import PasswordFormComponent from "./components/PasswordForm"; import ProfilePictureFormComponent from "./components/ProfilePictureForm"; @@ -39,11 +38,7 @@ export const GeneralPage = () => { const setSuccessData = useAlertStore((state) => state.setSuccessData); const setErrorData = useAlertStore((state) => state.setErrorData); const { userData, setUserData } = useContext(AuthContext); - const hasStore = useStoreStore((state) => state.hasStore); - const validApiKey = useStoreStore((state) => state.validApiKey); - const hasApiKey = useStoreStore((state) => state.hasApiKey); - const loadingApiKey = useStoreStore((state) => state.loadingApiKey); - const { password, cnfPassword, profilePicture, apikey } = inputState; + const { password, cnfPassword, profilePicture } = inputState; const autoLogin = useAuthStore((state) => state.autoLogin); const { storeApiKey } = useContext(AuthContext);