import React, { useContext, useState } from "react"; import { Link } from "react-router-dom"; import { Trans, useTranslation } from "react-i18next"; import moment from "moment"; import { Button, DescriptionList, DescriptionListDescription, DescriptionListGroup, DescriptionListTerm, PageSection, Tab, TabTitleText, ToolbarItem, Tooltip, } from "@patternfly/react-core"; import { cellWidth, expandable } from "@patternfly/react-table"; import { CheckCircleIcon, WarningTriangleIcon } from "@patternfly/react-icons"; import EventRepresentation from "keycloak-admin/lib/defs/eventRepresentation"; import { useAdminClient } from "../context/auth/AdminClient"; import { ViewHeader } from "../components/view-header/ViewHeader"; import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; import { RealmContext } from "../context/realm-context/RealmContext"; import { AdminEvents } from "./AdminEvents"; import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; import { KeycloakTabs } from "../components/keycloak-tabs/KeycloakTabs"; import "./events-section.css"; export const EventsSection = () => { const { t } = useTranslation("events"); const adminClient = useAdminClient(); const { realm } = useContext(RealmContext); const [key, setKey] = useState(0); const refresh = () => setKey(new Date().getTime()); 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.findEvents({ ...params }); }; const StatusRow = (event: EventRepresentation) => ( <> {!event.error && ( {" "} {event.type} )} {event.error && ( {" "} {event.type} )} ); const UserDetailLink = (event: EventRepresentation) => ( <> {event.userId} ); const DetailCell = (event: EventRepresentation) => ( <> {Object.keys(event.details!).map((k) => ( {k} {event.details![k]} ))} ); return ( <> If you want to configure user events, Admin events or Event listeners, please enter {t("eventConfig")} page realm settings to configure. } divider={false} /> {t("userEvents")}} > event.details !== undefined, cellRenderer: DetailCell, }, ]} isPaginated ariaLabelKey="events:title" searchPlaceholderKey="events:searchForEvent" toolbarItem={ <> } columns={[ { name: "time", displayKey: "events:time", cellRenderer: (row) => moment(row.time).format("LLL"), cellFormatters: [expandable], }, { name: "userId", displayKey: "events:user", cellRenderer: UserDetailLink, }, { name: "type", displayKey: "events:eventType", cellRenderer: StatusRow, }, { name: "ipAddress", displayKey: "events:ipAddress", transforms: [cellWidth(10)], }, { name: "clientId", displayKey: "events:client", }, ]} emptyState={ } /> {t("adminEvents")}} > ); };