2020-12-11 13:05:41 +00:00
|
|
|
import {
|
|
|
|
Button,
|
2021-04-20 12:28:21 +00:00
|
|
|
DescriptionList,
|
|
|
|
DescriptionListDescription,
|
|
|
|
DescriptionListGroup,
|
|
|
|
DescriptionListTerm,
|
2020-12-11 13:05:41 +00:00
|
|
|
PageSection,
|
2020-12-11 14:48:39 +00:00
|
|
|
Tab,
|
|
|
|
TabTitleText,
|
2020-12-11 13:05:41 +00:00
|
|
|
ToolbarItem,
|
2021-04-20 12:28:21 +00:00
|
|
|
Tooltip,
|
2020-12-11 13:05:41 +00:00
|
|
|
} from "@patternfly/react-core";
|
2021-04-20 12:28:21 +00:00
|
|
|
import { CheckCircleIcon, WarningTriangleIcon } from "@patternfly/react-icons";
|
2021-07-21 09:30:18 +00:00
|
|
|
import { cellWidth, expandable } from "@patternfly/react-table";
|
2021-05-04 17:58:18 +00:00
|
|
|
import type EventRepresentation from "keycloak-admin/lib/defs/eventRepresentation";
|
2021-07-21 09:30:18 +00:00
|
|
|
import moment from "moment";
|
|
|
|
import React, { useState } from "react";
|
|
|
|
import { Trans, useTranslation } from "react-i18next";
|
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
import { KeycloakTabs } from "../components/keycloak-tabs/KeycloakTabs";
|
|
|
|
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
|
2020-12-14 08:57:05 +00:00
|
|
|
import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable";
|
2021-07-21 09:30:18 +00:00
|
|
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
|
|
|
import { useAdminClient } from "../context/auth/AdminClient";
|
|
|
|
import { useRealm } from "../context/realm-context/RealmContext";
|
2020-12-11 14:48:39 +00:00
|
|
|
import { AdminEvents } from "./AdminEvents";
|
2021-04-20 12:28:21 +00:00
|
|
|
import "./events-section.css";
|
|
|
|
|
2020-09-10 18:04:03 +00:00
|
|
|
export const EventsSection = () => {
|
2020-12-11 13:05:41 +00:00
|
|
|
const { t } = useTranslation("events");
|
|
|
|
const adminClient = useAdminClient();
|
2021-07-21 09:30:18 +00:00
|
|
|
const { realm } = useRealm();
|
2020-12-11 14:48:39 +00:00
|
|
|
|
2021-04-20 12:28:21 +00:00
|
|
|
const [key, setKey] = useState(0);
|
|
|
|
const refresh = () => setKey(new Date().getTime());
|
2020-12-11 13:05:41 +00:00
|
|
|
|
|
|
|
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 });
|
|
|
|
};
|
|
|
|
|
2021-04-20 12:28:21 +00:00
|
|
|
const StatusRow = (event: EventRepresentation) => (
|
|
|
|
<>
|
|
|
|
{!event.error && (
|
|
|
|
<span key={`status-${event.time}-${event.type}`}>
|
|
|
|
<CheckCircleIcon
|
|
|
|
color="green"
|
|
|
|
key={`circle-${event.time}-${event.type}`}
|
|
|
|
/>{" "}
|
2020-12-11 13:05:41 +00:00
|
|
|
{event.type}
|
2021-04-20 12:28:21 +00:00
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{event.error && (
|
|
|
|
<Tooltip
|
|
|
|
content={event.error}
|
|
|
|
key={`tooltip-${event.time}-${event.type}`}
|
|
|
|
>
|
|
|
|
<span key={`label-${event.time}-${event.type}`}>
|
|
|
|
<WarningTriangleIcon
|
|
|
|
color="orange"
|
|
|
|
key={`triangle-${event.time}-${event.type}`}
|
|
|
|
/>{" "}
|
|
|
|
{event.type}
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const UserDetailLink = (event: EventRepresentation) => (
|
|
|
|
<>
|
|
|
|
<Link
|
|
|
|
key={`link-${event.time}-${event.type}`}
|
|
|
|
to={`/${realm}/users/${event.userId}/details`}
|
|
|
|
>
|
|
|
|
{event.userId}
|
|
|
|
</Link>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const DetailCell = (event: EventRepresentation) => (
|
|
|
|
<>
|
|
|
|
<DescriptionList isHorizontal className="keycloak_eventsection_details">
|
|
|
|
{Object.keys(event.details!).map((k) => (
|
|
|
|
<DescriptionListGroup key={`detail-${event.time}-${event.type}`}>
|
|
|
|
<DescriptionListTerm>{k}</DescriptionListTerm>
|
|
|
|
<DescriptionListDescription>
|
|
|
|
{event.details![k]}
|
|
|
|
</DescriptionListDescription>
|
|
|
|
</DescriptionListGroup>
|
|
|
|
))}
|
|
|
|
</DescriptionList>
|
|
|
|
</>
|
|
|
|
);
|
2020-12-11 13:05:41 +00:00
|
|
|
|
2020-09-18 08:04:55 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-03-31 13:16:58 +00:00
|
|
|
<ViewHeader
|
|
|
|
titleKey="events:title"
|
2021-04-20 12:28:21 +00:00
|
|
|
subKey={
|
|
|
|
<Trans i18nKey="events:eventExplain">
|
|
|
|
If you want to configure user events, Admin events or Event
|
|
|
|
listeners, please enter
|
2021-06-08 05:29:56 +00:00
|
|
|
<Link to={`/${realm}/realm-settings/events`}>
|
|
|
|
{t("eventConfig")}
|
|
|
|
</Link>
|
2021-04-20 12:28:21 +00:00
|
|
|
page realm settings to configure.
|
|
|
|
</Trans>
|
|
|
|
}
|
2021-03-31 13:16:58 +00:00
|
|
|
divider={false}
|
|
|
|
/>
|
|
|
|
<PageSection variant="light" className="pf-u-p-0">
|
2021-01-13 20:47:40 +00:00
|
|
|
<KeycloakTabs isBox>
|
2020-12-11 14:48:39 +00:00
|
|
|
<Tab
|
2021-01-13 20:47:40 +00:00
|
|
|
eventKey="userEvents"
|
2020-12-11 14:48:39 +00:00
|
|
|
title={<TabTitleText>{t("userEvents")}</TabTitleText>}
|
|
|
|
>
|
2020-12-14 08:57:05 +00:00
|
|
|
<KeycloakDataTable
|
2020-12-11 14:48:39 +00:00
|
|
|
key={key}
|
|
|
|
loader={loader}
|
2021-04-20 12:28:21 +00:00
|
|
|
detailColumns={[
|
|
|
|
{
|
|
|
|
name: "details",
|
|
|
|
enabled: (event) => event.details !== undefined,
|
|
|
|
cellRenderer: DetailCell,
|
|
|
|
},
|
|
|
|
]}
|
2020-12-11 14:48:39 +00:00
|
|
|
isPaginated
|
|
|
|
ariaLabelKey="events:title"
|
|
|
|
searchPlaceholderKey="events:searchForEvent"
|
|
|
|
toolbarItem={
|
|
|
|
<>
|
|
|
|
<ToolbarItem>
|
|
|
|
<Button onClick={refresh}>{t("refresh")}</Button>
|
|
|
|
</ToolbarItem>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
columns={[
|
|
|
|
{
|
|
|
|
name: "time",
|
|
|
|
displayKey: "events:time",
|
2021-04-20 12:28:21 +00:00
|
|
|
cellRenderer: (row) => moment(row.time).format("LLL"),
|
|
|
|
cellFormatters: [expandable],
|
2020-12-11 14:48:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "userId",
|
|
|
|
displayKey: "events:user",
|
2021-04-20 12:28:21 +00:00
|
|
|
cellRenderer: UserDetailLink,
|
2020-12-11 14:48:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "type",
|
|
|
|
displayKey: "events:eventType",
|
|
|
|
cellRenderer: StatusRow,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ipAddress",
|
|
|
|
displayKey: "events:ipAddress",
|
2021-04-20 12:28:21 +00:00
|
|
|
transforms: [cellWidth(10)],
|
2020-12-11 14:48:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "clientId",
|
|
|
|
displayKey: "events:client",
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
emptyState={
|
|
|
|
<ListEmptyState
|
|
|
|
message={t("emptyEvents")}
|
|
|
|
instructions={t("emptyEventsInstructions")}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
2021-01-13 20:47:40 +00:00
|
|
|
eventKey="adminEvents"
|
2020-12-11 14:48:39 +00:00
|
|
|
title={<TabTitleText>{t("adminEvents")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<AdminEvents />
|
|
|
|
</Tab>
|
2021-01-13 20:47:40 +00:00
|
|
|
</KeycloakTabs>
|
2020-12-11 13:05:41 +00:00
|
|
|
</PageSection>
|
2020-09-18 08:04:55 +00:00
|
|
|
</>
|
|
|
|
);
|
2020-09-09 09:07:17 +00:00
|
|
|
};
|