2020-08-27 12:09:36 +00:00
|
|
|
import React, { useContext, useState } from "react";
|
|
|
|
import { ClientList } from "./clients/ClientList";
|
|
|
|
import { DataLoader } from "./components/data-loader/DataLoader";
|
|
|
|
import { HttpClientContext } from "./http-service/HttpClientContext";
|
2020-08-31 18:26:25 +00:00
|
|
|
import { ClientRepresentation } from "./model/client-model";
|
2020-08-27 12:09:36 +00:00
|
|
|
import { Page, PageSection, Button } from "@patternfly/react-core";
|
|
|
|
import { Header } from "./PageHeader";
|
|
|
|
import { PageNav } from "./PageNav";
|
|
|
|
import { KeycloakContext } from "./auth/KeycloakContext";
|
2020-08-31 18:26:25 +00:00
|
|
|
import { TableToolbar } from "./components/table-toolbar/TableToolbar";
|
2020-08-04 12:59:41 +00:00
|
|
|
|
2020-09-02 07:51:42 +00:00
|
|
|
import { Help } from "./components/help-enabler/HelpHeader";
|
2020-08-27 12:09:36 +00:00
|
|
|
import {
|
|
|
|
BrowserRouter as Router,
|
|
|
|
Route,
|
|
|
|
Switch,
|
2020-08-31 18:26:25 +00:00
|
|
|
useHistory,
|
2020-08-27 12:09:36 +00:00
|
|
|
} from "react-router-dom";
|
|
|
|
import { NewRealmForm } from "./forms/realm/NewRealmForm";
|
2020-08-31 18:26:25 +00:00
|
|
|
import { NewClientForm } from "./forms/client/NewClientForm";
|
2020-08-27 12:09:36 +00:00
|
|
|
|
2020-08-08 13:52:23 +00:00
|
|
|
export const App = () => {
|
2020-08-24 18:11:17 +00:00
|
|
|
const [max, setMax] = useState(10);
|
|
|
|
const [first, setFirst] = useState(0);
|
2020-08-04 12:59:41 +00:00
|
|
|
const httpClient = useContext(HttpClientContext);
|
2020-08-21 19:40:21 +00:00
|
|
|
const keycloak = useContext(KeycloakContext);
|
2020-08-04 12:59:41 +00:00
|
|
|
|
|
|
|
const loader = async () => {
|
|
|
|
return await httpClient
|
2020-08-31 18:26:25 +00:00
|
|
|
?.doGet("/admin/realms/master/clients", { params: { first, max } })
|
|
|
|
.then((r) => r.data as ClientRepresentation[]);
|
2020-08-04 12:59:41 +00:00
|
|
|
};
|
2020-08-27 12:09:36 +00:00
|
|
|
|
2020-08-31 18:26:25 +00:00
|
|
|
const Clients = () => {
|
|
|
|
const history = useHistory();
|
|
|
|
return (
|
|
|
|
<DataLoader loader={loader}>
|
|
|
|
{(clients) => (
|
|
|
|
<TableToolbar
|
|
|
|
count={clients!.length}
|
|
|
|
first={first}
|
|
|
|
max={max}
|
|
|
|
onNextClick={(f) => setFirst(f)}
|
|
|
|
onPreviousClick={(f) => setFirst(f)}
|
|
|
|
onPerPageSelect={(f, m) => {
|
|
|
|
setFirst(f);
|
|
|
|
setMax(m);
|
|
|
|
}}
|
|
|
|
toolbarItem={
|
|
|
|
<>
|
|
|
|
<Button onClick={() => history.push("/add-client")}>
|
|
|
|
Create client
|
|
|
|
</Button>
|
|
|
|
<Button variant="link">Import client</Button>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<ClientList
|
|
|
|
clients={clients}
|
|
|
|
baseUrl={keycloak!.authServerUrl()!}
|
|
|
|
/>
|
|
|
|
</TableToolbar>
|
|
|
|
)}
|
|
|
|
</DataLoader>
|
|
|
|
);
|
|
|
|
};
|
2020-08-04 12:59:41 +00:00
|
|
|
return (
|
2020-08-27 12:09:36 +00:00
|
|
|
<Router>
|
2020-09-02 07:51:42 +00:00
|
|
|
<Help>
|
|
|
|
<Page header={<Header />} isManagedSidebar sidebar={<PageNav />}>
|
|
|
|
<PageSection variant="light">
|
|
|
|
<Switch>
|
|
|
|
<Route exact path="/add-realm" component={NewRealmForm}></Route>
|
|
|
|
<Route exact path="/add-client" component={NewClientForm}></Route>
|
|
|
|
<Route exact path="/" component={Clients}></Route>
|
|
|
|
</Switch>
|
|
|
|
</PageSection>
|
|
|
|
</Page>
|
|
|
|
</Help>
|
2020-08-27 12:09:36 +00:00
|
|
|
</Router>
|
2020-08-04 12:59:41 +00:00
|
|
|
);
|
|
|
|
};
|