2021-03-22 08:14:24 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
2021-01-29 13:59:03 +00:00
|
|
|
import { PageSection } from "@patternfly/react-core";
|
2020-11-12 12:55:52 +00:00
|
|
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
2021-03-22 08:14:24 +00:00
|
|
|
import { asyncStateFetch, useAdminClient } from "../context/auth/AdminClient";
|
2021-01-29 13:59:03 +00:00
|
|
|
import { RolesList } from "./RolesList";
|
2021-03-22 08:14:24 +00:00
|
|
|
import { useErrorHandler } from "react-error-boundary";
|
2020-09-09 09:07:17 +00:00
|
|
|
|
2020-09-10 18:04:03 +00:00
|
|
|
export const RealmRolesSection = () => {
|
2020-11-12 12:55:52 +00:00
|
|
|
const adminClient = useAdminClient();
|
2021-03-22 08:14:24 +00:00
|
|
|
const [listRoles, setListRoles] = useState(false);
|
|
|
|
const handleError = useErrorHandler();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return asyncStateFetch(
|
|
|
|
() => {
|
|
|
|
return Promise.all([adminClient.roles.find()]);
|
|
|
|
},
|
|
|
|
|
|
|
|
(response) => {
|
|
|
|
setListRoles(!(response[0] && response[0].length > 0));
|
|
|
|
},
|
|
|
|
handleError
|
|
|
|
);
|
|
|
|
}, []);
|
2021-02-23 13:36:37 +00:00
|
|
|
|
2021-02-18 06:38:23 +00:00
|
|
|
const loader = async (first?: number, max?: number, search?: string) => {
|
2020-12-07 19:23:18 +00:00
|
|
|
const params: { [name: string]: string | number } = {
|
2021-02-18 06:38:23 +00:00
|
|
|
first: first!,
|
2020-12-07 19:23:18 +00:00
|
|
|
max: max!,
|
|
|
|
};
|
2021-03-22 08:14:24 +00:00
|
|
|
|
|
|
|
const searchParam = search || "";
|
|
|
|
|
|
|
|
if (searchParam) {
|
|
|
|
params.search = searchParam;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (listRoles) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2020-12-07 19:23:18 +00:00
|
|
|
return await adminClient.roles.find(params);
|
|
|
|
};
|
2021-03-22 08:14:24 +00:00
|
|
|
|
2020-09-18 08:04:55 +00:00
|
|
|
return (
|
2020-10-07 15:47:03 +00:00
|
|
|
<>
|
|
|
|
<ViewHeader titleKey="roles:title" subKey="roles:roleExplain" />
|
2021-03-22 08:14:24 +00:00
|
|
|
<PageSection variant="light" padding={{ default: "noPadding" }}>
|
2021-01-29 13:59:03 +00:00
|
|
|
<RolesList loader={loader} />
|
2020-10-07 15:47:03 +00:00
|
|
|
</PageSection>
|
|
|
|
</>
|
2020-09-18 08:04:55 +00:00
|
|
|
);
|
2020-09-09 09:07:17 +00:00
|
|
|
};
|