-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
# Description Replace v1 queries related to services for React-Query closes #5975 # Self Check: Strike through any lines that are not applicable (`~~line~~`) then check the box - [ ] Attached issue to pull request - [ ] Changelog entry - [ ] Code is clear and sufficiently documented - [ ] Sufficient test cases (reproduces the bug/tests the requested feature) - [ ] Correct, in line with design - [ ] End user documentation is included or an issue is created for end-user documentation (add ref to issue here: )
- Loading branch information
1 parent
fe1a154
commit f202703
Showing
30 changed files
with
729 additions
and
561 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
description: REplace service queries for react Query | ||
issue-nr: 5975 | ||
change-type: patch | ||
destination-branches: [master, iso8] | ||
sections: | ||
minor-improvement: "{{description}}" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./useDeleteService"; |
56 changes: 56 additions & 0 deletions
56
src/Data/Managers/V2/DELETE/DeleteService/useDeleteService.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,56 @@ | ||
import { | ||
UseMutationResult, | ||
useMutation, | ||
useQueryClient, | ||
} from "@tanstack/react-query"; | ||
import { PrimaryBaseUrlManager } from "@/UI"; | ||
import { useFetchHelpers } from "../../helpers"; | ||
|
||
/** | ||
* React Query hook for Deleting an Service. | ||
* | ||
* @returns {Mutation} - The mutation object provided by `useMutation` hook. | ||
*/ | ||
export const useDeleteService = ( | ||
environment: string, | ||
service_entity: string, | ||
): UseMutationResult<void, Error, void, unknown> => { | ||
const client = useQueryClient(); | ||
const { createHeaders, handleErrors } = useFetchHelpers(); | ||
const headers = createHeaders(environment); | ||
|
||
const baseUrlManager = new PrimaryBaseUrlManager( | ||
globalThis.location.origin, | ||
globalThis.location.pathname, | ||
); | ||
|
||
const baseUrl = baseUrlManager.getBaseUrl(process.env.API_BASEURL); | ||
|
||
/** | ||
* Delete an Service. | ||
* | ||
* @returns {Promise<void>} - A promise that resolves when the Service is successfully deleted | ||
*/ | ||
const deleteService = async (): Promise<void> => { | ||
const response = await fetch( | ||
baseUrl + `/lsm/v1/service_catalog/${service_entity}`, | ||
{ | ||
method: "DELETE", | ||
headers: headers, | ||
}, | ||
); | ||
|
||
await handleErrors(response); | ||
}; | ||
|
||
return useMutation({ | ||
mutationFn: deleteService, | ||
mutationKey: ["delete_service"], | ||
onSuccess: () => { | ||
client.refetchQueries({ queryKey: ["get_service_models-continuous"] }); | ||
client.refetchQueries({ queryKey: ["get_service_models-one_time"] }); | ||
client.refetchQueries({ queryKey: ["get_service_model-one_time"] }); | ||
client.refetchQueries({ queryKey: ["get_service_model-continuous"] }); | ||
}, | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
export * from "./useGetServiceConfig"; |
60 changes: 60 additions & 0 deletions
60
src/Data/Managers/V2/GETTERS/GetServiceConfig/useGetServiceConfig.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,60 @@ | ||
import { UseQueryResult, useQuery } from "@tanstack/react-query"; | ||
import { Config } from "@/Core"; | ||
import { PrimaryBaseUrlManager } from "@/UI"; | ||
import { useFetchHelpers } from "../../helpers"; | ||
|
||
/** | ||
* Return Signature of the useGetServiceConfig React Query | ||
*/ | ||
interface GetServiceConfig { | ||
useOneTime: () => UseQueryResult<Config, Error>; | ||
} | ||
|
||
/** | ||
* React Query hook to fetch the service config | ||
* | ||
* @param service {string} - the service entity | ||
* @param environment {string} - the environment in which the instance belongs | ||
* | ||
* @returns {GetServiceConfig} An object containing the different available queries. | ||
* @returns {UseQueryResult<Config, Error>} returns.useOneTime - Fetch the service config with a single query. | ||
*/ | ||
export const useGetServiceConfig = ( | ||
service: string, | ||
environment: string, | ||
): GetServiceConfig => { | ||
const { createHeaders, handleErrors } = useFetchHelpers(); | ||
const headers = createHeaders(environment); | ||
|
||
const baseUrlManager = new PrimaryBaseUrlManager( | ||
globalThis.location.origin, | ||
globalThis.location.pathname, | ||
); | ||
const baseUrl = baseUrlManager.getBaseUrl(process.env.API_BASEURL); | ||
|
||
const fetchInstance = async (): Promise<{ data: Config }> => { | ||
const response = await fetch( | ||
`${baseUrl}/lsm/v1/service_catalog/${service}/config`, | ||
{ | ||
headers, | ||
}, | ||
); | ||
|
||
await handleErrors( | ||
response, | ||
`Failed to fetch Service Config for: ${service}`, | ||
); | ||
|
||
return response.json(); | ||
}; | ||
|
||
return { | ||
useOneTime: (): UseQueryResult<Config, Error> => | ||
useQuery({ | ||
queryKey: ["get_service_config-one_time", service], | ||
queryFn: fetchInstance, | ||
retry: false, | ||
select: (data) => data.data, | ||
}), | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./UseGetServiceModel"; | ||
export * from "./useGetServiceModel"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./useGetServiceModels"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./useExportCatalog"; |
53 changes: 53 additions & 0 deletions
53
src/Data/Managers/V2/POST/ExportCatalog/useExportCatalog.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,53 @@ | ||
import { | ||
UseMutationResult, | ||
useMutation, | ||
useQueryClient, | ||
} from "@tanstack/react-query"; | ||
import { PrimaryBaseUrlManager } from "@/UI"; | ||
import { useFetchHelpers } from "../../helpers"; | ||
|
||
/** | ||
* React Query hook for updating environment catalog. | ||
* | ||
* @param {string} environment - The environment to use for creating headers. | ||
* @returns {UseMutationResult<void, Error, void, unknown>}- The mutation object from `useMutation` hook. | ||
*/ | ||
export const useExportCatalog = ( | ||
environment: string, | ||
): UseMutationResult<void, Error, void, unknown> => { | ||
const client = useQueryClient(); | ||
const baseUrlManager = new PrimaryBaseUrlManager( | ||
globalThis.location.origin, | ||
globalThis.location.pathname, | ||
); | ||
const { createHeaders, handleErrors } = useFetchHelpers(); | ||
const headers = createHeaders(environment); | ||
const baseUrl = baseUrlManager.getBaseUrl(process.env.API_BASEURL); | ||
|
||
/** | ||
* Update the environment catalog. | ||
* | ||
* @returns {Promise<void>} - The promise object of the fetch request. | ||
* @throws {Error} If the response is not successful, an error with the error message is thrown. | ||
*/ | ||
const updateCatalog = async (): Promise<void> => { | ||
const response = await fetch( | ||
baseUrl + `/lsm/v1/exporter/export_service_definition`, | ||
{ | ||
method: "POST", | ||
headers, | ||
}, | ||
); | ||
|
||
await handleErrors(response); | ||
}; | ||
|
||
return useMutation({ | ||
mutationFn: updateCatalog, | ||
mutationKey: ["update_catalog"], | ||
onSuccess: () => { | ||
client.invalidateQueries({ queryKey: ["get_service_models-one_time"] }); | ||
client.invalidateQueries({ queryKey: ["get_service_models-continuous"] }); | ||
}, | ||
}); | ||
}; |
Oops, something went wrong.