removed double query for realm roles (#471)
This commit is contained in:
parent
f10661444d
commit
17a3fe51bb
1 changed files with 4 additions and 24 deletions
|
@ -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 (
|
||||||
|
|
Loading…
Reference in a new issue