2020-12-11 14:48:39 +00:00
|
|
|
import {
|
2021-08-25 14:19:26 +00:00
|
|
|
ActionGroup,
|
2020-12-11 14:48:39 +00:00
|
|
|
Button,
|
2021-08-25 14:19:26 +00:00
|
|
|
Dropdown,
|
|
|
|
DropdownToggle,
|
|
|
|
Form,
|
|
|
|
FormGroup,
|
2020-12-11 14:48:39 +00:00
|
|
|
Modal,
|
|
|
|
ModalVariant,
|
2021-08-25 14:19:26 +00:00
|
|
|
Select,
|
|
|
|
SelectVariant,
|
|
|
|
TextInput,
|
2021-04-15 10:23:36 +00:00
|
|
|
Tooltip,
|
2021-08-26 09:15:59 +00:00
|
|
|
ToolbarItem,
|
2020-12-11 14:48:39 +00:00
|
|
|
} from "@patternfly/react-core";
|
|
|
|
import {
|
2021-04-15 10:23:36 +00:00
|
|
|
cellWidth,
|
2020-12-11 14:48:39 +00:00
|
|
|
Table,
|
|
|
|
TableBody,
|
|
|
|
TableHeader,
|
|
|
|
TableVariant,
|
|
|
|
} from "@patternfly/react-table";
|
2021-08-26 08:39:35 +00:00
|
|
|
import type AdminEventRepresentation from "@keycloak/keycloak-admin-client/lib/defs/adminEventRepresentation";
|
2021-07-21 09:30:18 +00:00
|
|
|
import moment from "moment";
|
2021-08-10 11:18:48 +00:00
|
|
|
import React, { FunctionComponent, useState } from "react";
|
2021-08-25 14:19:26 +00:00
|
|
|
import { useForm } from "react-hook-form";
|
2021-07-21 09:30:18 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { Link } from "react-router-dom";
|
2020-12-11 14:48:39 +00:00
|
|
|
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
|
2021-07-21 09:30:18 +00:00
|
|
|
import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable";
|
|
|
|
import { useAdminClient } from "../context/auth/AdminClient";
|
|
|
|
import { useRealm } from "../context/realm-context/RealmContext";
|
2021-08-25 14:19:26 +00:00
|
|
|
import "./events.css";
|
2020-12-11 14:48:39 +00:00
|
|
|
|
|
|
|
type DisplayDialogProps = {
|
|
|
|
titleKey: string;
|
|
|
|
onClose: () => void;
|
|
|
|
};
|
|
|
|
|
2021-08-25 14:19:26 +00:00
|
|
|
type AdminEventSearchForm = {
|
|
|
|
operationType: string[];
|
|
|
|
resourceType: string[];
|
|
|
|
resourcePath: string;
|
|
|
|
dateFrom: string;
|
|
|
|
dateTo: string;
|
|
|
|
client: string;
|
|
|
|
user: string;
|
|
|
|
realm: string[];
|
|
|
|
ipAddress: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultValues: AdminEventSearchForm = {
|
|
|
|
operationType: [],
|
|
|
|
resourceType: [],
|
|
|
|
resourcePath: "",
|
|
|
|
dateFrom: "",
|
|
|
|
dateTo: "",
|
|
|
|
client: "",
|
|
|
|
user: "",
|
|
|
|
realm: [],
|
|
|
|
ipAddress: "",
|
|
|
|
};
|
|
|
|
|
2021-08-10 11:18:48 +00:00
|
|
|
const DisplayDialog: FunctionComponent<DisplayDialogProps> = ({
|
|
|
|
titleKey,
|
|
|
|
onClose,
|
|
|
|
children,
|
|
|
|
}) => {
|
2020-12-11 14:48:39 +00:00
|
|
|
const { t } = useTranslation("events");
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
variant={ModalVariant.medium}
|
|
|
|
title={t(titleKey)}
|
|
|
|
isOpen={true}
|
|
|
|
onClose={onClose}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-04-15 10:23:36 +00:00
|
|
|
const MAX_TEXT_LENGTH = 38;
|
|
|
|
const Truncate = ({
|
|
|
|
text,
|
|
|
|
children,
|
|
|
|
}: {
|
|
|
|
text?: string;
|
|
|
|
children: (text: string) => any;
|
|
|
|
}) => {
|
|
|
|
const definedText = text || "";
|
|
|
|
const needsTruncation = definedText.length > MAX_TEXT_LENGTH;
|
|
|
|
const truncatedText = definedText.substr(0, MAX_TEXT_LENGTH);
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{needsTruncation && (
|
|
|
|
<Tooltip content={text}>{children(truncatedText + "...")}</Tooltip>
|
|
|
|
)}
|
|
|
|
{!needsTruncation && <>{children(definedText)}</>}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-12-11 14:48:39 +00:00
|
|
|
export const AdminEvents = () => {
|
|
|
|
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-15 10:23:36 +00:00
|
|
|
const [key, setKey] = useState(0);
|
2021-08-25 14:19:26 +00:00
|
|
|
const [searchDropdownOpen, setSearchDropdownOpen] = useState(false);
|
|
|
|
const [selectOpen, setSelectOpen] = useState(false);
|
2021-04-15 10:23:36 +00:00
|
|
|
const refresh = () => setKey(new Date().getTime());
|
2020-12-11 14:48:39 +00:00
|
|
|
|
|
|
|
const [authEvent, setAuthEvent] = useState<AdminEventRepresentation>();
|
2021-07-05 11:24:10 +00:00
|
|
|
const [representationEvent, setRepresentationEvent] =
|
|
|
|
useState<AdminEventRepresentation>();
|
2020-12-11 14:48:39 +00:00
|
|
|
|
2021-08-25 14:19:26 +00:00
|
|
|
const {
|
|
|
|
register,
|
|
|
|
formState: { isDirty },
|
|
|
|
} = useForm<AdminEventSearchForm>({
|
|
|
|
shouldUnregister: false,
|
|
|
|
mode: "onChange",
|
|
|
|
defaultValues,
|
|
|
|
});
|
|
|
|
|
2020-12-11 14:48:39 +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.findAdminEvents({ ...params });
|
|
|
|
};
|
|
|
|
|
2021-04-15 10:23:36 +00:00
|
|
|
const LinkResource = (row: AdminEventRepresentation) => (
|
|
|
|
<>
|
|
|
|
<Truncate text={row.resourcePath}>
|
|
|
|
{(text) => (
|
|
|
|
<>
|
|
|
|
{row.resourceType !== "COMPONENT" && (
|
|
|
|
<Link
|
|
|
|
to={`/${realm}/${row.resourcePath}${
|
|
|
|
row.resourceType !== "GROUP" ? "/settings" : ""
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{text}
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
{row.resourceType === "COMPONENT" && <span>{text}</span>}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Truncate>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2021-08-25 14:19:26 +00:00
|
|
|
const adminEventSearchFormDisplay = () => {
|
|
|
|
return (
|
|
|
|
<>
|
2021-08-26 09:15:59 +00:00
|
|
|
<ToolbarItem>
|
|
|
|
<Dropdown
|
|
|
|
id="admin-events-search-select"
|
|
|
|
data-testid="AdminEventsSearchSelector"
|
|
|
|
className="pf-u-ml-md"
|
|
|
|
toggle={
|
|
|
|
<DropdownToggle
|
|
|
|
data-testid="adminEventsSearchSelectorToggle"
|
|
|
|
onToggle={(isOpen) => setSearchDropdownOpen(isOpen)}
|
|
|
|
className="keycloak__events_search_selector_dropdown__toggle"
|
|
|
|
>
|
|
|
|
{t("searchForAdminEvent")}
|
|
|
|
</DropdownToggle>
|
|
|
|
}
|
|
|
|
isOpen={searchDropdownOpen}
|
|
|
|
>
|
|
|
|
<Form
|
|
|
|
isHorizontal
|
|
|
|
className="keycloak__admin_events_search__form"
|
|
|
|
data-testid="searchForm"
|
2021-08-25 14:19:26 +00:00
|
|
|
>
|
2021-08-26 09:15:59 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("resourceType")}
|
|
|
|
fieldId="kc-resourceType"
|
|
|
|
className="keycloak__events_search__form_multiline_label"
|
2021-08-25 14:19:26 +00:00
|
|
|
>
|
2021-08-26 09:15:59 +00:00
|
|
|
<Select
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
onToggle={(isOpen) => setSelectOpen(isOpen)}
|
|
|
|
isOpen={selectOpen}
|
|
|
|
></Select>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("operationType")}
|
|
|
|
fieldId="kc-operationType"
|
|
|
|
className="keycloak__events_search__form_multiline_label"
|
|
|
|
>
|
|
|
|
<Select
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
onToggle={(isOpen) => setSelectOpen(isOpen)}
|
|
|
|
isOpen={selectOpen}
|
|
|
|
></Select>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("user")}
|
|
|
|
fieldId="kc-user"
|
|
|
|
className="keycloak__events_search__form_label"
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
ref={register()}
|
|
|
|
type="text"
|
|
|
|
id="kc-user"
|
|
|
|
name="user"
|
|
|
|
data-testid="user-searchField"
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("realm")}
|
|
|
|
fieldId="kc-realm"
|
|
|
|
className="keycloak__events_search__form_label"
|
|
|
|
>
|
|
|
|
<Select
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
onToggle={(isOpen) => setSelectOpen(isOpen)}
|
|
|
|
isOpen={selectOpen}
|
|
|
|
></Select>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("ipAddress")}
|
|
|
|
fieldId="kc-ipAddress"
|
|
|
|
className="keycloak__events_search__form_label"
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
ref={register()}
|
|
|
|
type="text"
|
|
|
|
id="kc-ipAddress"
|
|
|
|
name="ipAddress"
|
|
|
|
data-testid="ipAddress-searchField"
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("dateFrom")}
|
|
|
|
fieldId="kc-dateFrom"
|
|
|
|
className="keycloak__events_search__form_label"
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
ref={register()}
|
|
|
|
type="text"
|
|
|
|
id="kc-dateFrom"
|
|
|
|
name="dateFrom"
|
|
|
|
className="pf-c-form-control pf-m-icon pf-m-calendar"
|
|
|
|
placeholder="yyyy-MM-dd"
|
|
|
|
data-testid="dateFrom-searchField"
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("dateTo")}
|
|
|
|
fieldId="kc-dateTo"
|
|
|
|
className="keycloak__events_search__form_label"
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
ref={register()}
|
|
|
|
type="text"
|
|
|
|
id="kc-dateTo"
|
|
|
|
name="dateTo"
|
|
|
|
className="pf-c-form-control pf-m-icon pf-m-calendar"
|
|
|
|
placeholder="yyyy-MM-dd"
|
|
|
|
data-testid="dateTo-searchField"
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<ActionGroup>
|
|
|
|
<Button
|
|
|
|
className="keycloak__admin_events_search__form_btn"
|
|
|
|
variant={"primary"}
|
|
|
|
data-testid="search-events-btn"
|
|
|
|
isDisabled={!isDirty}
|
2021-08-25 14:19:26 +00:00
|
|
|
>
|
2021-08-26 09:15:59 +00:00
|
|
|
{t("searchAdminEventsBtn")}
|
|
|
|
</Button>
|
|
|
|
</ActionGroup>
|
|
|
|
</Form>
|
|
|
|
</Dropdown>
|
|
|
|
<Button
|
|
|
|
className="pf-u-ml-md"
|
|
|
|
onClick={refresh}
|
|
|
|
data-testid="refresh-btn"
|
|
|
|
>
|
|
|
|
{t("refresh")}
|
|
|
|
</Button>
|
|
|
|
</ToolbarItem>
|
2021-08-25 14:19:26 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-12-11 14:48:39 +00:00
|
|
|
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>
|
|
|
|
)}
|
2020-12-14 08:57:05 +00:00
|
|
|
<KeycloakDataTable
|
2020-12-11 14:48:39 +00:00
|
|
|
key={key}
|
|
|
|
loader={loader}
|
|
|
|
isPaginated
|
2020-12-11 17:25:54 +00:00
|
|
|
ariaLabelKey="events:adminEvents"
|
2021-08-25 14:19:26 +00:00
|
|
|
toolbarItem={adminEventSearchFormDisplay()}
|
2020-12-11 14:48:39 +00:00
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
title: t("auth"),
|
|
|
|
onRowClick: (event) => setAuthEvent(event),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: t("representation"),
|
|
|
|
onRowClick: (event) => setRepresentationEvent(event),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
columns={[
|
|
|
|
{
|
|
|
|
name: "time",
|
|
|
|
displayKey: "events:time",
|
2021-04-20 12:28:21 +00:00
|
|
|
cellRenderer: (row) => moment(row.time).format("LLL"),
|
2020-12-11 14:48:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "resourcePath",
|
|
|
|
displayKey: "events:resourcePath",
|
2021-04-15 10:23:36 +00:00
|
|
|
cellRenderer: LinkResource,
|
2020-12-11 14:48:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "resourceType",
|
|
|
|
displayKey: "events:resourceType",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "operationType",
|
|
|
|
displayKey: "events:operationType",
|
2021-04-15 10:23:36 +00:00
|
|
|
transforms: [cellWidth(10)],
|
2020-12-11 14:48:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "",
|
|
|
|
displayKey: "events:user",
|
|
|
|
cellRenderer: (event) => event.authDetails?.userId,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
emptyState={
|
|
|
|
<ListEmptyState
|
|
|
|
message={t("emptyEvents")}
|
|
|
|
instructions={t("emptyEventsInstructions")}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|