@@ -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,25 @@ 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 !== undefined &&
122+ empty !== false ;
99123
100124 return (
101125 // We pass props.resource here as we don't need to create a new ResourceContext if the props is not provided
@@ -109,11 +133,13 @@ export const ListBase = <RecordType extends RaRecord = any>({
109133 ? offline
110134 : showError
111135 ? error
112- : showEmpty
136+ : showEmptyWhileLoading
113137 ? null
114- : render
115- ? render ( controllerProps )
116- : children }
138+ : showEmpty
139+ ? empty
140+ : render
141+ ? render ( controllerProps )
142+ : children }
117143 </ ListContextProvider >
118144 </ OptionalResourceContextProvider >
119145 ) ;
@@ -126,6 +152,7 @@ export interface ListBaseProps<RecordType extends RaRecord = any>
126152 loading ?: ReactNode ;
127153 offline ?: ReactNode ;
128154 error ?: ReactNode ;
155+ empty ?: ReactNode ;
129156 children ?: ReactNode ;
130157 render ?: ( props : ListControllerResult < RecordType , Error > ) => ReactNode ;
131158}
0 commit comments