small refactor (#484)

This commit is contained in:
Erik Jan de Wit 2021-03-31 21:08:56 +02:00 committed by GitHub
parent 6102770fbf
commit f1a658da01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -89,16 +89,9 @@ export const AssociatedRolesTab = ({
return _.sortBy(rolesList, (role) => role.name?.toUpperCase()); return _.sortBy(rolesList, (role) => role.name?.toUpperCase());
}; };
const loader = async (first?: number, max?: number, search?: string) => { const loader = async () => {
if (isInheritedHidden) { if (isInheritedHidden) {
const filteredRoles = additionalRoles.filter( return alphabetize(additionalRoles);
(role) =>
!search ||
role.name?.toLowerCase().includes(search) ||
role.description?.toLowerCase().includes(search)
);
const roles = alphabetize(filteredRoles);
return roles;
} }
const fetchedRoles: Promise<RoleRepresentation[]> = additionalRoles.reduce( const fetchedRoles: Promise<RoleRepresentation[]> = additionalRoles.reduce(
@ -113,14 +106,7 @@ export const AssociatedRolesTab = ({
); );
return fetchedRoles.then((results: RoleRepresentation[]) => { return fetchedRoles.then((results: RoleRepresentation[]) => {
const filteredRoles = results.filter( return alphabetize(results);
(role) =>
!search ||
role.name?.toLowerCase().includes(search) ||
role.description?.toLowerCase().includes(search)
);
const roles = alphabetize(filteredRoles);
return roles;
}); });
}; };
@ -205,7 +191,6 @@ export const AssociatedRolesTab = ({
<KeycloakDataTable <KeycloakDataTable
key={key} key={key}
loader={loader} loader={loader}
isPaginated
ariaLabelKey="roles:roleList" ariaLabelKey="roles:roleList"
searchPlaceholderKey="roles:searchFor" searchPlaceholderKey="roles:searchFor"
canSelectAll canSelectAll
@ -280,8 +265,8 @@ export const AssociatedRolesTab = ({
emptyState={ emptyState={
<ListEmptyState <ListEmptyState
hasIcon={true} hasIcon={true}
message={t("noRolesInThisRealm")} message={t("noRoles")}
instructions={t("noRolesInThisRealmInstructions")} instructions={t("noRolesInstructions")}
primaryActionText={t("createRole")} primaryActionText={t("createRole")}
onPrimaryAction={goToCreate} onPrimaryAction={goToCreate}
/> />