keycloak-scim/js/apps/admin-ui/src/realm-roles/RealmRolesSection.tsx
2023-09-25 09:06:56 +02:00

51 lines
1.4 KiB
TypeScript

import { PageSection } from "@patternfly/react-core";
import { adminClient } from "../admin-client";
import { RolesList } from "../components/roles-list/RolesList";
import { ViewHeader } from "../components/view-header/ViewHeader";
import { useAccess } from "../context/access/Access";
import { useRealm } from "../context/realm-context/RealmContext";
import helpUrls from "../help-urls";
import { toAddRole } from "./routes/AddRole";
import { toRealmRole } from "./routes/RealmRole";
export default function RealmRolesSection() {
const { realm } = useRealm();
const { hasAccess } = useAccess();
const isManager = hasAccess("manage-realm");
const loader = (first?: number, max?: number, search?: string) => {
const params: { [name: string]: string | number } = {
first: first!,
max: max!,
};
const searchParam = search || "";
if (searchParam) {
params.search = searchParam;
}
return adminClient.roles.find(params);
};
return (
<>
<ViewHeader
titleKey="titleRoles"
subKey="roleExplain"
helpUrl={helpUrls.realmRolesUrl}
/>
<PageSection variant="light" padding={{ default: "noPadding" }}>
<RolesList
loader={loader}
toCreate={toAddRole({ realm })}
toDetail={(roleId) =>
toRealmRole({ realm, id: roleId, tab: "details" })
}
isReadOnly={!isManager}
/>
</PageSection>
</>
);
}