@@ -51,6 +51,7 @@ export const ListBase = <RecordType extends RaRecord = any>({
5151 loading,
5252 offline,
5353 error,
54+ empty,
5455 render,
5556 ...props
5657} : ListBaseProps < RecordType > ) => {
@@ -71,6 +72,11 @@ export const ListBase = <RecordType extends RaRecord = any>({
7172 isPending,
7273 isPlaceholderData,
7374 error : errorState ,
75+ data,
76+ total,
77+ hasPreviousPage,
78+ hasNextPage,
79+ filterValues,
7480 } = controllerProps ;
7581
7682 const showAuthLoading =
@@ -95,7 +101,24 @@ export const ListBase = <RecordType extends RaRecord = any>({
95101
96102 const showError = errorState && error !== false && error !== undefined ;
97103
98- const showEmpty = isPending && ! showOffline && emptyWhileLoading === true ;
104+ const showEmptyWhileLoading =
105+ isPending && ! showOffline && emptyWhileLoading === true ;
106+
107+ const showEmpty =
108+ ! errorState &&
109+ // the list is not loading data for the first time
110+ ! isPending &&
111+ // the API returned no data (using either normal or partial pagination)
112+ ( total === 0 ||
113+ ( total == null &&
114+ hasPreviousPage === false &&
115+ hasNextPage === false &&
116+ // @ts -ignore FIXME total may be undefined when using partial pagination but the ListControllerResult type is wrong about it
117+ data . length === 0 ) ) &&
118+ // the user didn't set any filters
119+ ! Object . keys ( filterValues ) . length &&
120+ // there is an empty page component
121+ empty !== false ;
99122
100123 return (
101124 // We pass props.resource here as we don't need to create a new ResourceContext if the props is not provided
@@ -109,11 +132,13 @@ export const ListBase = <RecordType extends RaRecord = any>({
109132 ? offline
110133 : showError
111134 ? error
112- : showEmpty
135+ : showEmptyWhileLoading
113136 ? null
114- : render
115- ? render ( controllerProps )
116- : children }
137+ : showEmpty
138+ ? empty
139+ : render
140+ ? render ( controllerProps )
141+ : children }
117142 </ ListContextProvider >
118143 </ OptionalResourceContextProvider >
119144 ) ;
@@ -126,6 +151,7 @@ export interface ListBaseProps<RecordType extends RaRecord = any>
126151 loading ?: ReactNode ;
127152 offline ?: ReactNode ;
128153 error ?: ReactNode ;
154+ empty ?: ReactNode ;
129155 children ?: ReactNode ;
130156 render ?: ( props : ListControllerResult < RecordType , Error > ) => ReactNode ;
131157}
0 commit comments