@@ -9,9 +9,11 @@ import {
99} from '@mui/material/styles' ;
1010import clsx from 'clsx' ;
1111import CircularProgress from '@mui/material/CircularProgress' ;
12- import { useLoading } from 'ra-core' ;
12+ import { Translate , useIsOffine , useLoading } from 'ra-core' ;
1313
1414import { RefreshIconButton , type RefreshIconButtonProps } from '../button' ;
15+ import { Badge , Tooltip } from '@mui/material' ;
16+ import { useMutationState } from '@tanstack/react-query' ;
1517
1618export const LoadingIndicator = ( inProps : LoadingIndicatorProps ) => {
1719 const props = useThemeProps ( {
@@ -20,6 +22,12 @@ export const LoadingIndicator = (inProps: LoadingIndicatorProps) => {
2022 } ) ;
2123 const { className, onClick, sx, ...rest } = props ;
2224 const loading = useLoading ( ) ;
25+ const isOffline = useIsOffine ( ) ;
26+ const pendingMutations = useMutationState ( {
27+ filters : {
28+ status : 'pending' ,
29+ } ,
30+ } ) ;
2331
2432 const theme = useTheme ( ) ;
2533 return (
@@ -30,18 +38,51 @@ export const LoadingIndicator = (inProps: LoadingIndicatorProps) => {
3038 } `}
3139 onClick = { onClick }
3240 />
33- { loading && (
34- < CircularProgress
35- className = { clsx (
36- 'app-loader' ,
37- LoadingIndicatorClasses . loader
38- ) }
39- color = "inherit"
40- size = { theme . spacing ( 2 ) }
41- thickness = { 6 }
42- { ...rest }
43- />
44- ) }
41+ { loading ? (
42+ isOffline ? (
43+ < Tooltip
44+ title = {
45+ < Translate
46+ i18nKey = "ra.notifications.pending_operations"
47+ options = { { smart_count : 1 } }
48+ >
49+ { pendingMutations . length > 1
50+ ? `There are ${ pendingMutations . length } pending
51+ operations due to network not being available`
52+ : `There is a pending operation due to network not being available` }
53+ </ Translate >
54+ }
55+ >
56+ < Badge
57+ className = { LoadingIndicatorClasses . loader }
58+ badgeContent = { pendingMutations . length }
59+ color = "primary"
60+ >
61+ < CircularProgress
62+ className = { clsx (
63+ 'app-loader' ,
64+ LoadingIndicatorClasses . loadedLoading
65+ ) }
66+ color = "inherit"
67+ size = { theme . spacing ( 2 ) }
68+ thickness = { 6 }
69+ { ...rest }
70+ />
71+ </ Badge >
72+ </ Tooltip >
73+ ) : (
74+ < CircularProgress
75+ className = { clsx (
76+ 'app-loader' ,
77+ LoadingIndicatorClasses . loader
78+ ) }
79+ color = "inherit"
80+ size = { theme . spacing ( 2 ) }
81+ thickness = { 6 }
82+ { ...rest }
83+ />
84+ )
85+ ) : null }
4586 </ Root >
4687 ) ;
4788} ;
0 commit comments