generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
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 feat/1594-adjustments-for-orchard-screen
- Loading branch information
Showing
15 changed files
with
680 additions
and
98 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,60 @@ | ||
import React, { ReactNode } from 'react'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { isAxiosError } from 'axios'; | ||
|
||
import { useNavigateContext } from '../../contexts/NavigationContext'; | ||
|
||
const HTTP_STATUS_TO_NOT_RETRY = [400, 401, 403, 404]; | ||
const MAX_RETRIES = 3; | ||
|
||
// Function to generate a QueryClient with error handling | ||
// and redirect, this will guarantee the redirect for all | ||
// requests in the application | ||
const useCustomQueryClient = () => { | ||
const { redirectTo403 } = useNavigateContext(); | ||
|
||
const queryClient = new QueryClient( | ||
{ | ||
defaultOptions: { | ||
queries: { | ||
refetchOnMount: false, | ||
refetchOnWindowFocus: false, | ||
// Do not retry on errors defined above | ||
retry: (failureCount, error) => { | ||
if (failureCount > MAX_RETRIES) { | ||
return false; | ||
} | ||
if (isAxiosError(error)) { | ||
const status = error.response?.status; | ||
if (status && HTTP_STATUS_TO_NOT_RETRY.includes(status)) { | ||
if (status === 403) { | ||
redirectTo403(); | ||
} | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
); | ||
|
||
return queryClient; | ||
}; | ||
|
||
interface CustomQueryProviderProps { | ||
children: ReactNode; | ||
} | ||
|
||
const CustomQueryProvider = ({ children }: CustomQueryProviderProps) => { | ||
const queryClient = useCustomQueryClient(); | ||
|
||
return ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
); | ||
}; | ||
|
||
export default CustomQueryProvider; |
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,32 @@ | ||
import React, { createContext, useContext, useMemo } from 'react'; | ||
|
||
interface NavigateContextType { | ||
redirectTo403: Function; | ||
} | ||
|
||
const NavigationContext = createContext<NavigateContextType | undefined>(undefined); | ||
|
||
// This a navigation provider, where a a context will be used to access the useNavigate | ||
// without necessarily being inside a router context | ||
export const NavigateProvider: React.FC<{ | ||
children: React.ReactNode, | ||
onRedirect: () => void | ||
}> = ({ children, onRedirect }) => { | ||
const value = useMemo(() => ({ redirectTo403: onRedirect }), [onRedirect]); | ||
|
||
return ( | ||
<NavigationContext.Provider value={value}> | ||
{children} | ||
</NavigationContext.Provider> | ||
); | ||
}; | ||
|
||
export const useNavigateContext = () => { | ||
const context = useContext(NavigationContext); | ||
|
||
if (!context) { | ||
throw new Error('useNavigateContext must be used within a NavigateProvider'); | ||
} | ||
|
||
return context; | ||
}; |
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
4 changes: 2 additions & 2 deletions
4
frontend/src/views/FourOhFour/index.tsx → ...src/views/ErrorViews/FourOhFour/index.tsx
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
File renamed without changes.
Oops, something went wrong.