-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ConfigProvider to ensure config data is always available (#5465)
- Loading branch information
1 parent
1759e1b
commit a08a438
Showing
24 changed files
with
138 additions
and
165 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 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getConfigQueryOptions } from "@/entities/config/get-config.query"; | ||
import ErrorScreen from "@/shared/components/errors/error-screen"; | ||
import { InfrahubLoading } from "@/shared/components/loading/infrahub-loading"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import React from "react"; | ||
|
||
export const ConfigProvider = ({ children }: { children: React.ReactNode }) => { | ||
const { isPending, error } = useQuery(getConfigQueryOptions()); | ||
|
||
if (isPending) { | ||
return <InfrahubLoading>Loading config...</InfrahubLoading>; | ||
} | ||
|
||
if (error) { | ||
return <ErrorScreen message={error.message} />; | ||
} | ||
|
||
return children; | ||
}; |
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,13 @@ | ||
import { getConfig } from "@/entities/config/get-config"; | ||
import { queryOptions, useSuspenseQuery } from "@tanstack/react-query"; | ||
|
||
export const getConfigQueryOptions = () => { | ||
return queryOptions({ | ||
queryKey: ["config"], | ||
queryFn: getConfig, | ||
}); | ||
}; | ||
|
||
export const useConfig = () => { | ||
return useSuspenseQuery(getConfigQueryOptions()); | ||
}; |
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,12 @@ | ||
import { ConfigAPI } from "@/entities/config/types"; | ||
import { apiClient } from "@/shared/api/rest/client"; | ||
|
||
export type GetConfig = () => Promise<ConfigAPI>; | ||
|
||
export const getConfig: GetConfig = async () => { | ||
const { data, error } = await apiClient.GET("/api/config"); | ||
|
||
if (error) throw error; | ||
|
||
return 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { components } from "@/shared/api/rest/types.generated"; | ||
|
||
export type ConfigAPI = components["schemas"]["ConfigAPI"]; | ||
|
||
export type SSOProvider = components["schemas"]["SSOProviderInfo"]; |
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.