@@ -7,16 +7,42 @@ import type { StackProps } from "@mui/material/Stack";
77import { useTheme } from "@mui/material/styles" ;
88import { useTranslation } from "react-i18next" ;
99interface BasePageProps extends StackProps {
10+ loading ?: boolean ;
11+ error ?: boolean ;
1012 children : React . ReactNode ;
1113 breadcrumbOverride ?: string [ ] ;
1214}
1315
1416export const BasePage = ( {
17+ loading,
18+ error,
1519 children,
1620 breadcrumbOverride,
1721 ...props
1822} : BasePageProps ) => {
1923 const theme = useTheme ( ) ;
24+
25+ if ( loading ) {
26+ return (
27+ < Stack
28+ alignItems = "center"
29+ justifyContent = "center"
30+ sx = { { height : "100%" } }
31+ >
32+ < CircularProgress color = "primary" size = { 28 } />
33+ </ Stack >
34+ ) ;
35+ }
36+
37+ if ( error ) {
38+ return (
39+ < ErrorFallback
40+ title = "Something went wrong..."
41+ subtitle = "Please try again later"
42+ />
43+ ) ;
44+ }
45+
2046 return (
2147 < Stack spacing = { theme . spacing ( 10 ) } { ...props } >
2248 < Breadcrumb breadcrumbOverride = { breadcrumbOverride } />
@@ -49,27 +75,6 @@ export const BasePageWithStates = ({
4975} : BasePageWithStatesProps ) => {
5076 const showLoading = loading && ( ! items || items . length === 0 ) ;
5177
52- if ( showLoading ) {
53- return (
54- < Stack
55- alignItems = "center"
56- justifyContent = "center"
57- sx = { { height : "100%" } }
58- >
59- < CircularProgress color = "primary" size = { 28 } />
60- </ Stack >
61- ) ;
62- }
63-
64- if ( error ) {
65- return (
66- < ErrorFallback
67- title = "Something went wrong..."
68- subtitle = "Please try again later"
69- />
70- ) ;
71- }
72-
7378 if ( isEmpty ( items ) ) {
7479 return (
7580 < EmptyFallback
@@ -81,7 +86,11 @@ export const BasePageWithStates = ({
8186 ) ;
8287 }
8388
84- return < BasePage { ...props } > { children } </ BasePage > ;
89+ return (
90+ < BasePage loading = { showLoading } error = { error } { ...props } >
91+ { children }
92+ </ BasePage >
93+ ) ;
8594} ;
8695
8796interface MonitorBasePageWithStatesProps extends StackProps {
@@ -114,27 +123,6 @@ export const MonitorBasePageWithStates = ({
114123
115124 const showLoading = loading && ( ! items || items . length === 0 ) ;
116125
117- if ( showLoading ) {
118- return (
119- < Stack
120- alignItems = "center"
121- justifyContent = "center"
122- sx = { { height : "100%" } }
123- >
124- < CircularProgress color = "primary" size = { 28 } />
125- </ Stack >
126- ) ;
127- }
128-
129- if ( error ) {
130- return (
131- < ErrorFallback
132- title = "Something went wrong..."
133- subtitle = "Please try again later"
134- />
135- ) ;
136- }
137-
138126 if ( isEmpty ( items ) ) {
139127 return (
140128 < EmptyMonitorFallback
@@ -148,5 +136,9 @@ export const MonitorBasePageWithStates = ({
148136 ) ;
149137 }
150138
151- return < BasePage { ...props } > { children } </ BasePage > ;
139+ return (
140+ < BasePage loading = { showLoading } error = { error } { ...props } >
141+ { children }
142+ </ BasePage >
143+ ) ;
152144} ;
0 commit comments