11import * as React from 'react' ;
22import { useState , useEffect } from 'react' ;
3+ import { styled , useThemeProps } from '@mui/material/styles' ;
4+ import { Box , Typography } from '@mui/material' ;
5+ import Inbox from '@mui/icons-material/Inbox' ;
36
47import {
58 ListBase ,
@@ -10,6 +13,7 @@ import {
1013 RaRecord ,
1114 usePrevious ,
1215 useLocation ,
16+ useTranslate ,
1317} from 'ra-core' ;
1418
1519import { ListProps } from './List' ;
@@ -44,6 +48,7 @@ export const ListGuesser = <RecordType extends RaRecord = any>(
4448 debounce,
4549 disableAuthentication,
4650 disableSyncWithLocation,
51+ empty,
4752 exporter,
4853 filter,
4954 filterDefaultValues,
@@ -66,6 +71,7 @@ export const ListGuesser = <RecordType extends RaRecord = any>(
6671 debounce = { debounce }
6772 disableAuthentication = { disableAuthentication }
6873 disableSyncWithLocation = { disableSyncWithLocation }
74+ empty = { empty === undefined ? < GuesserEmpty /> : empty }
6975 exporter = { exporter }
7076 filter = { filter }
7177 filterDefaultValues = { filterDefaultValues }
@@ -150,3 +156,57 @@ ${inferredChild.getRepresentation()}
150156
151157 return < ListView { ...rest } > { child } </ ListView > ;
152158} ;
159+
160+ const GuesserEmpty = ( inProps : GuesserEmptyProps ) => {
161+ const props = useThemeProps ( {
162+ props : inProps ,
163+ name : GUESSER_EMPTY_PREFIX ,
164+ } ) ;
165+ const { className } = props ;
166+ const translate = useTranslate ( ) ;
167+
168+ return (
169+ < GuesserEmptyRoot className = { className } >
170+ < Box className = { GuesserEmptyClasses . message } >
171+ < Inbox className = { GuesserEmptyClasses . icon } />
172+ < Typography variant = "h4" paragraph >
173+ { translate ( 'ra.guesser.empty.title' , {
174+ _ : 'No data to display' ,
175+ } ) }
176+ </ Typography >
177+ < Typography variant = "body1" >
178+ { translate ( 'ra.guesser.empty.message' , {
179+ _ : 'Please check your data provider' ,
180+ } ) }
181+ </ Typography >
182+ </ Box >
183+ </ GuesserEmptyRoot >
184+ ) ;
185+ } ;
186+
187+ interface GuesserEmptyProps {
188+ className ?: string ;
189+ }
190+
191+ const GUESSER_EMPTY_PREFIX = 'RaGuesserEmpty' ;
192+
193+ const GuesserEmptyClasses = {
194+ message : `${ GUESSER_EMPTY_PREFIX } -message` ,
195+ icon : `${ GUESSER_EMPTY_PREFIX } -icon` ,
196+ } ;
197+
198+ const GuesserEmptyRoot = styled ( 'span' , {
199+ name : GUESSER_EMPTY_PREFIX ,
200+ overridesResolver : ( props , styles ) => styles . root ,
201+ } ) ( ( { theme } ) => ( {
202+ flex : 1 ,
203+ [ `& .${ GuesserEmptyClasses . message } ` ] : {
204+ textAlign : 'center' ,
205+ margin : '0 1em' ,
206+ color : ( theme . vars || theme ) . palette . text . disabled ,
207+ } ,
208+ [ `& .${ GuesserEmptyClasses . icon } ` ] : {
209+ width : '9em' ,
210+ height : '9em' ,
211+ } ,
212+ } ) ) ;
0 commit comments