1414 * limitations under the License.
1515 */
1616
17+ import { Typography } from '@mui/material' ;
1718import Box from '@mui/material/Box' ;
1819import Button from '@mui/material/Button' ;
1920import Container from '@mui/material/Container' ;
@@ -23,7 +24,7 @@ import { styled } from '@mui/material/styles';
2324import { Dispatch , UnknownAction } from '@reduxjs/toolkit' ;
2425import { useQuery } from '@tanstack/react-query' ;
2526import { useEffect } from 'react' ;
26- import { useTranslation } from 'react-i18next' ;
27+ import { Trans , useTranslation } from 'react-i18next' ;
2728import { useDispatch } from 'react-redux' ;
2829import { getCluster } from '../../lib/cluster' ;
2930import { getSelectedClusters } from '../../lib/cluster' ;
@@ -37,6 +38,7 @@ import store from '../../redux/stores/store';
3738import { useUIPanelsGroupedBySide } from '../../redux/uiSlice' ;
3839import { fetchStatelessClusterKubeConfigs , isEqualClusterConfigs } from '../../stateless/' ;
3940import { ActivitiesRenderer } from '../activity/Activity' ;
41+ import { ErrorPage , Loader } from '../common' ;
4042import ActionsNotifier from '../common/ActionsNotifier' ;
4143import AlertNotification from '../common/AlertNotification' ;
4244import DetailsDrawer from '../common/Resource/DetailsDrawer' ;
@@ -190,10 +192,14 @@ export default function Layout({}: LayoutProps) {
190192 * indexDB and then sends the backend to parse it and then updates the parsed value into redux
191193 * store on an interval.
192194 * */
193- useQuery ( {
195+ const {
196+ data : config ,
197+ isLoading,
198+ error,
199+ } = useQuery ( {
194200 queryKey : [ 'cluster-fetch' ] ,
195201 queryFn : ( ) => fetchConfig ( dispatch ) ,
196- refetchInterval : CLUSTER_FETCH_INTERVAL ,
202+ refetchInterval : query => ( query . state . status === 'error' ? false : CLUSTER_FETCH_INTERVAL ) ,
197203 } ) ;
198204
199205 // Remove splash screen styles from the body
@@ -214,6 +220,40 @@ export default function Layout({}: LayoutProps) {
214220
215221 const panels = useUIPanelsGroupedBySide ( ) ;
216222
223+ if ( error && ! config ) {
224+ return < ErrorPage message = { < Trans > Failed to connect to the backend</ Trans > } error = { error } /> ;
225+ }
226+
227+ if ( isLoading ) {
228+ return (
229+ < Box
230+ sx = { {
231+ position : 'fixed' ,
232+ top : 0 ,
233+ left : 0 ,
234+ width : '100dvw' ,
235+ height : '100dvh' ,
236+ display : 'flex' ,
237+ alignItems : 'center' ,
238+ justifyContent : 'center' ,
239+ gap : 2 ,
240+ animation : 'loader-appear' ,
241+ animationFillMode : 'both' ,
242+ animationDelay : '2s' ,
243+ animationDuration : '0.3s' ,
244+
245+ '@keyframes loader-appear' : {
246+ from : { opacity : 0 } ,
247+ to : { opacity : 1 } ,
248+ } ,
249+ } }
250+ >
251+ < Loader title = { t ( 'Connecting to backend...' ) } />
252+ < Typography > { t ( 'Connecting to backend...' ) } </ Typography >
253+ </ Box >
254+ ) ;
255+ }
256+
217257 return (
218258 < >
219259 < Link
0 commit comments