keycloak-scim/src/realm-roles/UsersInRoleTab.tsx

107 lines
3.4 KiB
TypeScript
Raw Normal View History

2021-03-01 15:55:54 +00:00
import React, { useEffect } from "react";
2021-03-01 17:20:58 +00:00
import { useHistory, useParams } from "react-router-dom";
2021-02-24 13:47:27 +00:00
import { useTranslation } from "react-i18next";
2021-03-01 17:20:58 +00:00
import { Button, PageSection, Popover } from "@patternfly/react-core";
2021-02-24 13:47:27 +00:00
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable";
import { boolFormatter, emptyFormatter } from "../util";
import { useAdminClient } from "../context/auth/AdminClient";
2021-03-01 17:20:58 +00:00
import { QuestionCircleIcon } from "@patternfly/react-icons";
import { useRealm } from "../context/realm-context/RealmContext";
2021-02-24 13:47:27 +00:00
2021-02-24 20:05:19 +00:00
export const UsersInRoleTab = () => {
2021-03-01 17:20:58 +00:00
const history = useHistory();
const { realm } = useRealm();
2021-02-24 13:47:27 +00:00
const { t } = useTranslation("roles");
2021-02-24 20:05:19 +00:00
const { id } = useParams<{ id: string }>();
2021-02-24 13:47:27 +00:00
const adminClient = useAdminClient();
const loader = async () => {
2021-02-24 20:05:19 +00:00
const role = await adminClient.roles.findOneById({ id: id });
const usersWithRole = await adminClient.roles.findUsersWithRole({
name: role.name!,
});
return usersWithRole;
2021-02-24 13:47:27 +00:00
};
return (
<>
2021-03-01 15:22:25 +00:00
<PageSection data-testid="users-page" variant="light">
2021-03-01 15:30:16 +00:00
<KeycloakDataTable
loader={loader}
ariaLabelKey="roles:roleList"
searchPlaceholderKey=""
2021-03-01 17:20:58 +00:00
toolbarItem={
<Popover
aria-label="Basic popover"
position="bottom"
bodyContent={
<div>
{t("roles:whoWillAppearPopoverText")}
<Button
className="kc-groups-link"
variant="link"
onClick={() => history.push(`/${realm}/groups`)}
>
{t("groups")}
</Button>
{t("or")}
<Button
className="kc-users-link"
variant="link"
onClick={() => history.push(`/${realm}/users`)}
>
{t("users")}.
</Button>
</div>
}
footerContent={t("roles:whoWillAppearPopoverFooterText")}
>
<Button
variant="link"
className="kc-who-will-appear-button"
key="who-will-appear-button"
icon={<QuestionCircleIcon />}
>
{t("roles:whoWillAppearLinkText")}
</Button>
</Popover>
}
2021-03-01 15:30:16 +00:00
emptyState={
<ListEmptyState
hasIcon={true}
message={t("noDirectUsers")}
instructions={t("noUsersEmptyStateDescription")}
/>
}
columns={[
{
name: "username",
displayKey: "roles:userName",
cellFormatters: [emptyFormatter()],
},
{
name: "email",
displayKey: "roles:email",
cellFormatters: [emptyFormatter()],
},
{
name: "lastName",
displayKey: "roles:lastName",
cellFormatters: [emptyFormatter()],
},
{
name: "firstName",
displayKey: "roles:firstName",
cellFormatters: [boolFormatter(), emptyFormatter()],
},
]}
/>
2021-02-24 13:47:27 +00:00
</PageSection>
</>
);
};