2020-09-03 19:25:05 +00:00
|
|
|
import React, { useState, useContext } from "react";
|
|
|
|
import { useHistory } from "react-router-dom";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2020-09-18 08:04:55 +00:00
|
|
|
import { Button, PageSection } from "@patternfly/react-core";
|
2020-09-03 19:25:05 +00:00
|
|
|
|
|
|
|
import { DataLoader } from "../components/data-loader/DataLoader";
|
|
|
|
import { TableToolbar } from "../components/table-toolbar/TableToolbar";
|
2020-09-10 18:04:03 +00:00
|
|
|
import { ClientList } from "./ClientList";
|
2020-09-03 19:25:05 +00:00
|
|
|
import { HttpClientContext } from "../http-service/HttpClientContext";
|
|
|
|
import { KeycloakContext } from "../auth/KeycloakContext";
|
2020-09-10 18:04:03 +00:00
|
|
|
import { ClientRepresentation } from "./models/client-model";
|
2020-09-17 11:37:30 +00:00
|
|
|
import { RealmContext } from "../components/realm-context/RealmContext";
|
2020-09-25 17:29:03 +00:00
|
|
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
2020-09-03 19:25:05 +00:00
|
|
|
|
2020-09-10 18:04:03 +00:00
|
|
|
export const ClientsSection = () => {
|
|
|
|
const { t } = useTranslation("clients");
|
2020-09-03 19:25:05 +00:00
|
|
|
const history = useHistory();
|
2020-09-17 11:37:30 +00:00
|
|
|
|
2020-09-03 19:25:05 +00:00
|
|
|
const [max, setMax] = useState(10);
|
|
|
|
const [first, setFirst] = useState(0);
|
|
|
|
const httpClient = useContext(HttpClientContext)!;
|
|
|
|
const keycloak = useContext(KeycloakContext);
|
2020-09-17 11:37:30 +00:00
|
|
|
const { realm } = useContext(RealmContext);
|
2020-09-03 19:25:05 +00:00
|
|
|
|
|
|
|
const loader = async () => {
|
|
|
|
return await httpClient
|
2020-09-17 11:37:30 +00:00
|
|
|
.doGet(`/admin/realms/${realm}/clients`, { params: { first, max } })
|
2020-09-03 19:25:05 +00:00
|
|
|
.then((r) => r.data as ClientRepresentation[]);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2020-09-25 17:29:03 +00:00
|
|
|
<>
|
|
|
|
<ViewHeader
|
|
|
|
titleKey="clients:clientList"
|
|
|
|
subKey="clients:clientsExplain"
|
|
|
|
/>
|
|
|
|
<PageSection variant="light">
|
|
|
|
<DataLoader loader={loader}>
|
|
|
|
{(clients) => (
|
|
|
|
<TableToolbar
|
|
|
|
count={clients!.length}
|
|
|
|
first={first}
|
|
|
|
max={max}
|
|
|
|
onNextClick={setFirst}
|
|
|
|
onPreviousClick={setFirst}
|
|
|
|
onPerPageSelect={(first, max) => {
|
|
|
|
setFirst(first);
|
|
|
|
setMax(max);
|
|
|
|
}}
|
|
|
|
toolbarItem={
|
|
|
|
<>
|
|
|
|
<Button onClick={() => history.push("/add-client")}>
|
|
|
|
{t("createClient")}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
onClick={() => history.push("/import-client")}
|
|
|
|
variant="link"
|
|
|
|
>
|
|
|
|
{t("importClient")}
|
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<ClientList
|
|
|
|
clients={clients}
|
|
|
|
baseUrl={keycloak!.authServerUrl()!}
|
|
|
|
/>
|
|
|
|
</TableToolbar>
|
|
|
|
)}
|
|
|
|
</DataLoader>
|
|
|
|
</PageSection>
|
|
|
|
</>
|
2020-09-03 19:25:05 +00:00
|
|
|
);
|
|
|
|
};
|