-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add useGetRefreshFlows mutation and update code to use it (#…
…3475) * Added refresh flows mutation * Changed places that used refreshFlows to use the mutation * removed old refreshFlows * removed readFlowsFromDatabase api call * Removed unused API calls from API.ts * Removed getFlowFromDatabase call
- Loading branch information
1 parent
0586d1e
commit 3a408c8
Showing
8 changed files
with
79 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/frontend/src/controllers/API/queries/flows/use-get-refresh-flows.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import useAlertStore from "@/stores/alertStore"; | ||
import useFlowsManagerStore from "@/stores/flowsManagerStore"; | ||
import { useFolderStore } from "@/stores/foldersStore"; | ||
import { useTypesStore } from "@/stores/typesStore"; | ||
import { useMutationFunctionType } from "@/types/api"; | ||
import { FlowType } from "@/types/flow"; | ||
import { | ||
extractFieldsFromComponenents, | ||
processFlows, | ||
} from "@/utils/reactflowUtils"; | ||
import { UseMutationResult } from "@tanstack/react-query"; | ||
import { api } from "../../api"; | ||
import { getURL } from "../../helpers/constants"; | ||
import { UseRequestProcessor } from "../../services/request-processor"; | ||
|
||
export const useGetRefreshFlows: useMutationFunctionType< | ||
undefined, | ||
undefined | ||
> = (options?) => { | ||
const { mutate } = UseRequestProcessor(); | ||
|
||
const setExamples = useFlowsManagerStore((state) => state.setExamples); | ||
const setFlows = useFlowsManagerStore((state) => state.setFlows); | ||
const setErrorData = useAlertStore((state) => state.setErrorData); | ||
const starterProjectId = useFolderStore((state) => state.starterProjectId); | ||
|
||
const getRefreshFlowsFn = async (): Promise<void> => { | ||
try { | ||
} catch (e) { | ||
setErrorData({ | ||
title: "Could not load flows from database", | ||
}); | ||
throw e; | ||
} | ||
const response = await api.get<FlowType[]>(`${getURL("FLOWS")}/`); | ||
const dbData = response.data; | ||
if (dbData) { | ||
const { data, flows } = processFlows(dbData); | ||
const examples = flows.filter( | ||
(flow) => flow.folder_id === starterProjectId, | ||
); | ||
setExamples(examples); | ||
|
||
const flowsWithoutStarterFolder = flows.filter( | ||
(flow) => flow.folder_id !== starterProjectId, | ||
); | ||
|
||
setFlows(flowsWithoutStarterFolder); | ||
useTypesStore.setState((state) => ({ | ||
data: { ...state.data, ["saved_components"]: data }, | ||
ComponentFields: extractFieldsFromComponenents({ | ||
...state.data, | ||
["saved_components"]: data, | ||
}), | ||
})); | ||
return; | ||
} | ||
}; | ||
|
||
const mutation: UseMutationResult<void, any, undefined> = mutate( | ||
["useGetRefreshFlows"], | ||
getRefreshFlowsFn, | ||
options, | ||
); | ||
|
||
return mutation; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.