2020-10-07 15:47:03 +00:00
|
|
|
import React, { useContext } from "react";
|
2020-09-18 08:04:55 +00:00
|
|
|
import { useHistory } from "react-router-dom";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2020-10-07 15:47:03 +00:00
|
|
|
import { Button, PageSection } from "@patternfly/react-core";
|
2020-09-18 08:04:55 +00:00
|
|
|
|
|
|
|
import { DataLoader } from "../components/data-loader/DataLoader";
|
|
|
|
import { TableToolbar } from "../components/table-toolbar/TableToolbar";
|
2020-10-06 08:25:38 +00:00
|
|
|
import { HttpClientContext } from "../context/http-service/HttpClientContext";
|
2020-09-18 08:04:55 +00:00
|
|
|
import { RoleRepresentation } from "../model/role-model";
|
|
|
|
import { RolesList } from "./RoleList";
|
2020-10-06 08:25:38 +00:00
|
|
|
import { RealmContext } from "../context/realm-context/RealmContext";
|
2020-10-07 15:47:03 +00:00
|
|
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
2020-09-09 09:07:17 +00:00
|
|
|
|
2020-09-10 18:04:03 +00:00
|
|
|
export const RealmRolesSection = () => {
|
2020-09-18 08:04:55 +00:00
|
|
|
const { t } = useTranslation("roles");
|
|
|
|
const history = useHistory();
|
|
|
|
const httpClient = useContext(HttpClientContext)!;
|
|
|
|
const { realm } = useContext(RealmContext);
|
|
|
|
|
|
|
|
const loader = async () => {
|
2020-10-07 15:47:03 +00:00
|
|
|
const result = await httpClient.doGet<RoleRepresentation[]>(
|
|
|
|
`/admin/realms/${realm}/roles`
|
|
|
|
);
|
|
|
|
return result.data;
|
2020-09-18 08:04:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2020-10-07 15:47:03 +00:00
|
|
|
<>
|
|
|
|
<ViewHeader titleKey="roles:title" subKey="roles:roleExplain" />
|
|
|
|
<PageSection padding={{ default: "noPadding" }}>
|
|
|
|
<TableToolbar
|
|
|
|
toolbarItem={
|
|
|
|
<>
|
|
|
|
<Button onClick={() => history.push("/add-role")}>
|
|
|
|
{t("createRole")}
|
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<DataLoader loader={loader}>
|
|
|
|
{(roles) => <RolesList roles={roles.data} />}
|
|
|
|
</DataLoader>
|
|
|
|
</TableToolbar>
|
|
|
|
</PageSection>
|
|
|
|
</>
|
2020-09-18 08:04:55 +00:00
|
|
|
);
|
2020-09-09 09:07:17 +00:00
|
|
|
};
|