2020-09-18 08:04:55 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
|
|
import React, { useState, useContext, useEffect } from "react";
|
|
|
|
import { useHistory } from "react-router-dom";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Divider,
|
|
|
|
Page,
|
|
|
|
PageSection,
|
|
|
|
PageSectionVariants,
|
|
|
|
Text,
|
|
|
|
TextContent,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
|
|
|
|
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-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 [max, setMax] = useState(10);
|
|
|
|
const [, setRoles] = useState([] as RoleRepresentation[]);
|
|
|
|
const [first, setFirst] = useState(0);
|
|
|
|
const httpClient = useContext(HttpClientContext)!;
|
|
|
|
const { realm } = useContext(RealmContext);
|
|
|
|
|
|
|
|
const loader = async () => {
|
|
|
|
return await httpClient
|
|
|
|
.doGet(`/admin/realms/${realm}/roles`)
|
|
|
|
.then((r) => r.data as RoleRepresentation[]);
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
loader().then((result) => setRoles(result || []));
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DataLoader loader={loader}>
|
|
|
|
{(roles) => (
|
|
|
|
<>
|
|
|
|
<PageSection variant="light">
|
|
|
|
<TextContent>
|
|
|
|
<Text component="h1">Realm roles</Text>
|
|
|
|
<Text component="p">{t("roleExplain")}</Text>
|
|
|
|
</TextContent>
|
|
|
|
</PageSection>
|
|
|
|
<Divider component="li" key={1} />
|
|
|
|
<PageSection padding={{ default: "noPadding" }}>
|
|
|
|
<TableToolbar
|
2020-10-06 11:56:06 +00:00
|
|
|
count={roles.data.length}
|
2020-09-18 08:04:55 +00:00
|
|
|
first={first}
|
|
|
|
max={max}
|
|
|
|
onNextClick={setFirst}
|
|
|
|
onPreviousClick={setFirst}
|
|
|
|
onPerPageSelect={(f, m) => {
|
|
|
|
setFirst(f);
|
|
|
|
setMax(m);
|
|
|
|
}}
|
|
|
|
toolbarItem={
|
|
|
|
<>
|
|
|
|
<Button onClick={() => history.push("/add-role")}>
|
|
|
|
{t("createRole")}
|
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
>
|
2020-10-06 11:56:06 +00:00
|
|
|
<RolesList roles={roles.data} />
|
2020-09-18 08:04:55 +00:00
|
|
|
</TableToolbar>
|
|
|
|
</PageSection>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</DataLoader>
|
|
|
|
);
|
2020-09-09 09:07:17 +00:00
|
|
|
};
|