-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix-component-set-functionality
- Loading branch information
Showing
6 changed files
with
63 additions
and
9 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
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
33 changes: 33 additions & 0 deletions
33
src/frontend/src/controllers/API/queries/variables/use-get-mutation-global-variables.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,33 @@ | ||
import { useGlobalVariablesStore } from "@/stores/globalVariablesStore/globalVariables"; | ||
import getUnavailableFields from "@/stores/globalVariablesStore/utils/get-unavailable-fields"; | ||
import { useMutationFunctionType } from "@/types/api"; | ||
import { GlobalVariable } from "@/types/global_variables"; | ||
import { UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; | ||
import { api } from "../../api"; | ||
import { getURL } from "../../helpers/constants"; | ||
import { UseRequestProcessor } from "../../services/request-processor"; | ||
|
||
export const useGetGlobalVariablesMutation: useMutationFunctionType< | ||
undefined | ||
> = (options?) => { | ||
const { mutate } = UseRequestProcessor(); | ||
|
||
const setGlobalVariablesEntries = useGlobalVariablesStore( | ||
(state) => state.setGlobalVariablesEntries, | ||
); | ||
const setUnavailableFields = useGlobalVariablesStore( | ||
(state) => state.setUnavailableFields, | ||
); | ||
|
||
const getGlobalVariablesFn = async (): Promise<GlobalVariable[]> => { | ||
const res = await api.get(`${getURL("VARIABLES")}/`); | ||
setGlobalVariablesEntries(res.data.map((entry) => entry.name)); | ||
setUnavailableFields(getUnavailableFields(res.data)); | ||
return res.data; | ||
}; | ||
|
||
const mutation: UseMutationResult<undefined, Error, GlobalVariable[]> = | ||
mutate(["useGetGlobalVariables"], getGlobalVariablesFn, 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