2021-03-02 16:11:08 +00:00
|
|
|
import React, { useContext } 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-03-02 16:11:08 +00:00
|
|
|
import { HelpContext } from "../components/help-enabler/HelpHeader";
|
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();
|
|
|
|
|
2021-03-02 15:27:33 +00:00
|
|
|
const loader = async (first?: number, max?: number) => {
|
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!,
|
2021-03-02 15:27:33 +00:00
|
|
|
first: first!,
|
|
|
|
max: max!,
|
|
|
|
} as any);
|
2021-02-24 20:05:19 +00:00
|
|
|
return usersWithRole;
|
2021-02-24 13:47:27 +00:00
|
|
|
};
|
|
|
|
|
2021-03-02 16:11:08 +00:00
|
|
|
const { enabled } = useContext(HelpContext);
|
|
|
|
|
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
|
2021-03-02 15:27:33 +00:00
|
|
|
isPaginated
|
2021-03-01 15:30:16 +00:00
|
|
|
loader={loader}
|
|
|
|
ariaLabelKey="roles:roleList"
|
|
|
|
searchPlaceholderKey=""
|
2021-03-01 17:20:58 +00:00
|
|
|
toolbarItem={
|
2021-03-02 16:11:08 +00:00
|
|
|
enabled && (
|
|
|
|
<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")}
|
2021-03-01 17:20:58 +00:00
|
|
|
>
|
2021-03-02 16:11:08 +00:00
|
|
|
<Button
|
|
|
|
variant="link"
|
|
|
|
className="kc-who-will-appear-button"
|
|
|
|
key="who-will-appear-button"
|
|
|
|
icon={<QuestionCircleIcon />}
|
|
|
|
>
|
|
|
|
{t("roles:whoWillAppearLinkText")}
|
|
|
|
</Button>
|
|
|
|
</Popover>
|
|
|
|
)
|
2021-03-01 17:20:58 +00:00
|
|
|
}
|
2021-03-01 15:30:16 +00:00
|
|
|
emptyState={
|
|
|
|
<ListEmptyState
|
|
|
|
hasIcon={true}
|
|
|
|
message={t("noDirectUsers")}
|
2021-03-01 19:20:26 +00:00
|
|
|
instructions={
|
|
|
|
<div>
|
|
|
|
{t("noUsersEmptyStateDescription")}
|
|
|
|
<Button
|
|
|
|
className="kc-groups-link-empty-state"
|
|
|
|
variant="link"
|
|
|
|
onClick={() => history.push(`/${realm}/groups`)}
|
|
|
|
>
|
|
|
|
{t("groups")}
|
|
|
|
</Button>
|
|
|
|
{t("or")}
|
|
|
|
<Button
|
|
|
|
className="kc-users-link-empty-state"
|
|
|
|
variant="link"
|
|
|
|
onClick={() => history.push(`/${realm}/users`)}
|
|
|
|
>
|
|
|
|
{t("users")}
|
|
|
|
</Button>
|
|
|
|
{t("noUsersEmptyStateDescriptionContinued")}
|
|
|
|
</div>
|
|
|
|
}
|
2021-03-01 15:30:16 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
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>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|