refresh the when we need to refresh (#27028)

fixes: #27002

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Erik Jan de Wit 2024-02-14 13:19:52 +00:00 committed by GitHub
parent f7a594acb6
commit ba91f2aacc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -221,7 +221,8 @@ export function KeycloakDataTable<T>({
const prevSearch = useRef<string>();
const [key, setKey] = useState(0);
const refresh = () => setKey(new Date().getTime());
const prevKey = useRef<number>();
const refresh = () => setKey(key + 1);
const id = useId();
const renderCell = (columns: (Field<T> | DetailField<T>)[], value: T) => {
@ -325,11 +326,13 @@ export function KeycloakDataTable<T>({
}
prevSearch.current = search;
return typeof loader === "function"
? unPaginatedData ||
(await loader(newSearch ? 0 : first, max + 1, search))
? key === prevKey.current && unPaginatedData
? unPaginatedData
: await loader(newSearch ? 0 : first, max + 1, search)
: loader;
},
(data) => {
prevKey.current = key;
if (!isPaginated) {
setUnPaginatedData(data);
if (data.length > first) {