@@ -51,6 +51,7 @@ export const ListBase = <RecordType extends RaRecord = any>({
51
51
loading,
52
52
offline,
53
53
error,
54
+ empty,
54
55
render,
55
56
...props
56
57
} : ListBaseProps < RecordType > ) => {
@@ -71,6 +72,11 @@ export const ListBase = <RecordType extends RaRecord = any>({
71
72
isPending,
72
73
isPlaceholderData,
73
74
error : errorState ,
75
+ data,
76
+ total,
77
+ hasPreviousPage,
78
+ hasNextPage,
79
+ filterValues,
74
80
} = controllerProps ;
75
81
76
82
const showAuthLoading =
@@ -95,7 +101,25 @@ export const ListBase = <RecordType extends RaRecord = any>({
95
101
96
102
const showError = errorState && error !== false && error !== undefined ;
97
103
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 ;
99
123
100
124
return (
101
125
// 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>({
109
133
? offline
110
134
: showError
111
135
? error
112
- : showEmpty
136
+ : showEmptyWhileLoading
113
137
? null
114
- : render
115
- ? render ( controllerProps )
116
- : children }
138
+ : showEmpty
139
+ ? empty
140
+ : render
141
+ ? render ( controllerProps )
142
+ : children }
117
143
</ ListContextProvider >
118
144
</ OptionalResourceContextProvider >
119
145
) ;
@@ -126,6 +152,7 @@ export interface ListBaseProps<RecordType extends RaRecord = any>
126
152
loading ?: ReactNode ;
127
153
offline ?: ReactNode ;
128
154
error ?: ReactNode ;
155
+ empty ?: ReactNode ;
129
156
children ?: ReactNode ;
130
157
render ?: ( props : ListControllerResult < RecordType , Error > ) => ReactNode ;
131
158
}
0 commit comments