2020-08-04 12:59:41 +00:00
|
|
|
import React, { useContext } from 'react';
|
2020-08-07 13:44:34 +00:00
|
|
|
import {
|
|
|
|
Page,
|
|
|
|
PageSection,
|
|
|
|
Button,
|
|
|
|
AlertVariant,
|
|
|
|
} from '@patternfly/react-core';
|
2020-08-04 12:59:41 +00:00
|
|
|
|
|
|
|
import { ClientList } from './clients/ClientList';
|
|
|
|
import { DataLoader } from './components/data-loader/DataLoader';
|
|
|
|
import { HttpClientContext } from './http-service/HttpClientContext';
|
|
|
|
import { Client } from './clients/client-model';
|
|
|
|
import { Header } from './PageHeader';
|
|
|
|
import { PageNav } from './PageNav';
|
2020-08-07 13:44:34 +00:00
|
|
|
import { AlertPanel } from './components/alert/AlertPanel';
|
|
|
|
import { useAlerts, withAlerts } from './components/alert/Alerts';
|
2020-08-04 12:59:41 +00:00
|
|
|
|
2020-08-07 13:44:34 +00:00
|
|
|
const AppComponent = () => {
|
|
|
|
const [alerts, add, hide] = useAlerts();
|
2020-08-04 12:59:41 +00:00
|
|
|
const httpClient = useContext(HttpClientContext);
|
|
|
|
|
|
|
|
const loader = async () => {
|
|
|
|
return await httpClient
|
|
|
|
?.doGet('/realms/master/clients?first=0&max=20&search=true')
|
|
|
|
.then((r) => r.data as Client[]);
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<Page header={<Header />} sidebar={<PageNav />}>
|
2020-08-06 09:43:33 +00:00
|
|
|
<PageSection>
|
2020-08-07 13:44:34 +00:00
|
|
|
<AlertPanel alerts={alerts} onCloseAlert={hide} />
|
2020-08-06 09:43:33 +00:00
|
|
|
<DataLoader loader={loader}>
|
|
|
|
{(clients) => <ClientList clients={clients} />}
|
|
|
|
</DataLoader>
|
2020-08-07 13:44:34 +00:00
|
|
|
<Button
|
|
|
|
onClick={() => add('Crazy stuff happened', AlertVariant.danger)}
|
|
|
|
>
|
|
|
|
Click
|
|
|
|
</Button>
|
2020-08-06 09:43:33 +00:00
|
|
|
</PageSection>
|
2020-08-04 12:59:41 +00:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
};
|
2020-08-07 13:44:34 +00:00
|
|
|
|
|
|
|
export const App = withAlerts(AppComponent);
|