added admin events tab
This commit is contained in:
parent
7d20fc01a7
commit
6b962577ba
3 changed files with 227 additions and 39 deletions
147
src/events/AdminEvents.tsx
Normal file
147
src/events/AdminEvents.tsx
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
import React, { ReactNode, useContext, useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Modal,
|
||||||
|
ModalVariant,
|
||||||
|
ToolbarItem,
|
||||||
|
} from "@patternfly/react-core";
|
||||||
|
import moment from "moment";
|
||||||
|
|
||||||
|
import { useAdminClient } from "../context/auth/AdminClient";
|
||||||
|
import { DataList } from "../components/table-toolbar/DataList";
|
||||||
|
import { RealmContext } from "../context/realm-context/RealmContext";
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableHeader,
|
||||||
|
TableVariant,
|
||||||
|
} from "@patternfly/react-table";
|
||||||
|
import AdminEventRepresentation from "keycloak-admin/lib/defs/adminEventRepresentation";
|
||||||
|
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
|
||||||
|
|
||||||
|
type DisplayDialogProps = {
|
||||||
|
titleKey: string;
|
||||||
|
onClose: () => void;
|
||||||
|
children: ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
const DisplayDialog = ({ titleKey, onClose, children }: DisplayDialogProps) => {
|
||||||
|
const { t } = useTranslation("events");
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
variant={ModalVariant.medium}
|
||||||
|
title={t(titleKey)}
|
||||||
|
isOpen={true}
|
||||||
|
onClose={onClose}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const AdminEvents = () => {
|
||||||
|
const { t } = useTranslation("events");
|
||||||
|
const adminClient = useAdminClient();
|
||||||
|
const { realm } = useContext(RealmContext);
|
||||||
|
|
||||||
|
const [key, setKey] = useState("");
|
||||||
|
const refresh = () => setKey(`${new Date().getTime()}`);
|
||||||
|
|
||||||
|
const [authEvent, setAuthEvent] = useState<AdminEventRepresentation>();
|
||||||
|
const [representationEvent, setRepresentationEvent] = useState<
|
||||||
|
AdminEventRepresentation
|
||||||
|
>();
|
||||||
|
|
||||||
|
const loader = async (first?: number, max?: number, search?: string) => {
|
||||||
|
const params = {
|
||||||
|
first: first!,
|
||||||
|
max: max!,
|
||||||
|
realm,
|
||||||
|
};
|
||||||
|
if (search) {
|
||||||
|
console.log("how to search?", search);
|
||||||
|
}
|
||||||
|
return await adminClient.realms.findAdminEvents({ ...params });
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{authEvent && (
|
||||||
|
<DisplayDialog titleKey="auth" onClose={() => setAuthEvent(undefined)}>
|
||||||
|
<Table
|
||||||
|
aria-label="authData"
|
||||||
|
variant={TableVariant.compact}
|
||||||
|
cells={[t("attribute"), t("value")]}
|
||||||
|
rows={Object.entries(authEvent.authDetails!)}
|
||||||
|
>
|
||||||
|
<TableHeader />
|
||||||
|
<TableBody />
|
||||||
|
</Table>
|
||||||
|
</DisplayDialog>
|
||||||
|
)}
|
||||||
|
{representationEvent && (
|
||||||
|
<DisplayDialog
|
||||||
|
titleKey="representation"
|
||||||
|
onClose={() => setRepresentationEvent(undefined)}
|
||||||
|
>
|
||||||
|
some json from the changed values
|
||||||
|
</DisplayDialog>
|
||||||
|
)}
|
||||||
|
<DataList
|
||||||
|
key={key}
|
||||||
|
loader={loader}
|
||||||
|
isPaginated
|
||||||
|
ariaLabelKey="events:title"
|
||||||
|
searchPlaceholderKey="events:searchForEvent"
|
||||||
|
toolbarItem={
|
||||||
|
<>
|
||||||
|
<ToolbarItem>
|
||||||
|
<Button onClick={refresh}>{t("refresh")}</Button>
|
||||||
|
</ToolbarItem>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
actions={[
|
||||||
|
{
|
||||||
|
title: t("auth"),
|
||||||
|
onRowClick: (event) => setAuthEvent(event),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("representation"),
|
||||||
|
onRowClick: (event) => setRepresentationEvent(event),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
name: "time",
|
||||||
|
displayKey: "events:time",
|
||||||
|
cellRenderer: (row) => moment(row.time).fromNow(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "resourcePath",
|
||||||
|
displayKey: "events:resourcePath",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "resourceType",
|
||||||
|
displayKey: "events:resourceType",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "operationType",
|
||||||
|
displayKey: "events:operationType",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "",
|
||||||
|
displayKey: "events:user",
|
||||||
|
cellRenderer: (event) => event.authDetails?.userId,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
emptyState={
|
||||||
|
<ListEmptyState
|
||||||
|
message={t("emptyEvents")}
|
||||||
|
instructions={t("emptyEventsInstructions")}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -4,6 +4,9 @@ import {
|
||||||
Button,
|
Button,
|
||||||
Label,
|
Label,
|
||||||
PageSection,
|
PageSection,
|
||||||
|
Tab,
|
||||||
|
Tabs,
|
||||||
|
TabTitleText,
|
||||||
ToolbarItem,
|
ToolbarItem,
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
@ -14,11 +17,15 @@ import { ViewHeader } from "../components/view-header/ViewHeader";
|
||||||
import { DataList } from "../components/table-toolbar/DataList";
|
import { DataList } from "../components/table-toolbar/DataList";
|
||||||
import { RealmContext } from "../context/realm-context/RealmContext";
|
import { RealmContext } from "../context/realm-context/RealmContext";
|
||||||
import { InfoCircleIcon } from "@patternfly/react-icons";
|
import { InfoCircleIcon } from "@patternfly/react-icons";
|
||||||
|
import { AdminEvents } from "./AdminEvents";
|
||||||
|
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
|
||||||
|
|
||||||
export const EventsSection = () => {
|
export const EventsSection = () => {
|
||||||
const { t } = useTranslation("events");
|
const { t } = useTranslation("events");
|
||||||
const adminClient = useAdminClient();
|
const adminClient = useAdminClient();
|
||||||
const { realm } = useContext(RealmContext);
|
const { realm } = useContext(RealmContext);
|
||||||
|
|
||||||
|
const [activeTab, setActiveTab] = useState(0);
|
||||||
const [key, setKey] = useState("");
|
const [key, setKey] = useState("");
|
||||||
const refresh = () => setKey(`${new Date().getTime()}`);
|
const refresh = () => setKey(`${new Date().getTime()}`);
|
||||||
|
|
||||||
|
@ -48,6 +55,15 @@ export const EventsSection = () => {
|
||||||
<>
|
<>
|
||||||
<ViewHeader titleKey="events:title" subKey="events:eventExplain" />
|
<ViewHeader titleKey="events:title" subKey="events:eventExplain" />
|
||||||
<PageSection variant="light">
|
<PageSection variant="light">
|
||||||
|
<Tabs
|
||||||
|
activeKey={activeTab}
|
||||||
|
onSelect={(_, key) => setActiveTab(key as number)}
|
||||||
|
isBox
|
||||||
|
>
|
||||||
|
<Tab
|
||||||
|
eventKey={0}
|
||||||
|
title={<TabTitleText>{t("userEvents")}</TabTitleText>}
|
||||||
|
>
|
||||||
<DataList
|
<DataList
|
||||||
key={key}
|
key={key}
|
||||||
loader={loader}
|
loader={loader}
|
||||||
|
@ -85,7 +101,21 @@ export const EventsSection = () => {
|
||||||
displayKey: "events:client",
|
displayKey: "events:client",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
emptyState={
|
||||||
|
<ListEmptyState
|
||||||
|
message={t("emptyEvents")}
|
||||||
|
instructions={t("emptyEventsInstructions")}
|
||||||
/>
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Tab>
|
||||||
|
<Tab
|
||||||
|
eventKey={1}
|
||||||
|
title={<TabTitleText>{t("adminEvents")}</TabTitleText>}
|
||||||
|
>
|
||||||
|
<AdminEvents />
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,12 +2,23 @@
|
||||||
"events": {
|
"events": {
|
||||||
"title": "Events",
|
"title": "Events",
|
||||||
"eventExplain": "If you want to configure user events, Admin events or Event listeners, please enter Event configs page realm settings to configure.",
|
"eventExplain": "If you want to configure user events, Admin events or Event listeners, please enter Event configs page realm settings to configure.",
|
||||||
|
"userEvents": "User events",
|
||||||
|
"adminEvents": "Admin events",
|
||||||
"searchForEvent": "Search user event",
|
"searchForEvent": "Search user event",
|
||||||
"refresh": "Refresh",
|
"refresh": "Refresh",
|
||||||
|
"emptyEvents": "No events logged",
|
||||||
|
"emptyEventsInstructions": "Configure event logging in the realm settings",
|
||||||
"time": "Time",
|
"time": "Time",
|
||||||
"user": "User",
|
"user": "User",
|
||||||
"eventType": "Event type",
|
"eventType": "Event type",
|
||||||
"ipAddress": "IP address",
|
"ipAddress": "IP address",
|
||||||
"client": "Client"
|
"client": "Client",
|
||||||
|
"resourcePath": "Resource path",
|
||||||
|
"resourceType": "Resource type",
|
||||||
|
"operationType": "Operation type",
|
||||||
|
"auth": "Auth",
|
||||||
|
"attribute": "Attribute",
|
||||||
|
"value": "Value",
|
||||||
|
"representation": "Representation"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue