parent
f5282fbc75
commit
57b52309f0
2 changed files with 11 additions and 3 deletions
|
@ -4,6 +4,7 @@ import {
|
||||||
ReactNode,
|
ReactNode,
|
||||||
useEffect,
|
useEffect,
|
||||||
useMemo,
|
useMemo,
|
||||||
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
@ -207,6 +208,7 @@ export function KeycloakDataTable<T>({
|
||||||
const [max, setMax] = useState(10);
|
const [max, setMax] = useState(10);
|
||||||
const [first, setFirst] = useState(0);
|
const [first, setFirst] = useState(0);
|
||||||
const [search, setSearch] = useState<string>("");
|
const [search, setSearch] = useState<string>("");
|
||||||
|
const prevSearch = useRef<string>();
|
||||||
|
|
||||||
const [key, setKey] = useState(0);
|
const [key, setKey] = useState(0);
|
||||||
const refresh = () => setKey(new Date().getTime());
|
const refresh = () => setKey(new Date().getTime());
|
||||||
|
@ -297,8 +299,15 @@ export function KeycloakDataTable<T>({
|
||||||
useFetch(
|
useFetch(
|
||||||
async () => {
|
async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
const newSearch = prevSearch.current === "" && search !== "";
|
||||||
|
|
||||||
|
if (newSearch) {
|
||||||
|
setFirst(0);
|
||||||
|
}
|
||||||
|
prevSearch.current = search;
|
||||||
return typeof loader === "function"
|
return typeof loader === "function"
|
||||||
? unPaginatedData || (await loader(first, max + 1, search))
|
? unPaginatedData ||
|
||||||
|
(await loader(newSearch ? 0 : first, max + 1, search))
|
||||||
: loader;
|
: loader;
|
||||||
},
|
},
|
||||||
(data) => {
|
(data) => {
|
||||||
|
|
|
@ -24,8 +24,7 @@ public abstract class RoleMappingResource {
|
||||||
public final List<ClientRole> mapping(Predicate<RoleModel> predicate, long first, long max, final String search) {
|
public final List<ClientRole> mapping(Predicate<RoleModel> predicate, long first, long max, final String search) {
|
||||||
|
|
||||||
return mapping(predicate).filter(clientRole -> clientRole.getClient().contains(search) || clientRole.getRole().contains(search))
|
return mapping(predicate).filter(clientRole -> clientRole.getClient().contains(search) || clientRole.getRole().contains(search))
|
||||||
|
.skip(first).limit(max).collect(Collectors.toList());
|
||||||
.skip("".equals(search) ? first : 0).limit(max).collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RoleMappingResource(RealmModel realm, AdminPermissionEvaluator auth) {
|
public RoleMappingResource(RealmModel realm, AdminPermissionEvaluator auth) {
|
||||||
|
|
Loading…
Reference in a new issue