removed double query for realm roles (#471)

This commit is contained in:
Erik Jan de Wit 2021-03-29 20:46:46 +02:00 committed by GitHub
parent f10661444d
commit 17a3fe51bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,29 +1,13 @@
import React, { useEffect, useState } from "react"; import React from "react";
import { PageSection } from "@patternfly/react-core"; import { PageSection } from "@patternfly/react-core";
import { ViewHeader } from "../components/view-header/ViewHeader"; import { ViewHeader } from "../components/view-header/ViewHeader";
import { asyncStateFetch, useAdminClient } from "../context/auth/AdminClient"; import { useAdminClient } from "../context/auth/AdminClient";
import { RolesList } from "./RolesList"; import { RolesList } from "./RolesList";
import { useErrorHandler } from "react-error-boundary";
export const RealmRolesSection = () => { export const RealmRolesSection = () => {
const adminClient = useAdminClient(); const adminClient = useAdminClient();
const [listRoles, setListRoles] = useState(false);
const handleError = useErrorHandler();
useEffect(() => { const loader = (first?: number, max?: number, search?: string) => {
return asyncStateFetch(
() => {
return Promise.all([adminClient.roles.find()]);
},
(response) => {
setListRoles(!(response[0] && response[0].length > 0));
},
handleError
);
}, []);
const loader = async (first?: number, max?: number, search?: string) => {
const params: { [name: string]: string | number } = { const params: { [name: string]: string | number } = {
first: first!, first: first!,
max: max!, max: max!,
@ -35,11 +19,7 @@ export const RealmRolesSection = () => {
params.search = searchParam; params.search = searchParam;
} }
if (!listRoles && !searchParam) { return adminClient.roles.find(params);
return [];
}
return await adminClient.roles.find(params);
}; };
return ( return (