Events search fixes (#1056)

* events: uncommented test for searching user events

* events: added refresh btn and tidied up css

* events: increased search form width

* events: removed unwanted Divider

* events: fixed grey line issue when no events logged, fixed test

* events: renamed css classes to make them reusable for admin search

* events: added admin events search ui

* events: fixed refresh btn on user events tab

Co-authored-by: Agnieszka Gancarczyk <agancarc@redhat.com>
This commit is contained in:
agagancarczyk 2021-08-25 15:19:26 +01:00 committed by GitHub
parent 170b4b0e43
commit 0fbd196380
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 405 additions and 221 deletions

View file

@ -60,15 +60,14 @@ export default class EventsPage {
cy.get("table").should("not.have.text", "LOGIN_ERROR"); cy.get("table").should("not.have.text", "LOGIN_ERROR");
cy.get("table").should("not.have.text", "LOGOUT"); cy.get("table").should("not.have.text", "LOGOUT");
// cy.get('[id^=remove_pf]').click(); cy.get("[id^=remove_pf]").click();
// cy.get("table").contains("LOGIN");
// cy.get(this.searchEventDrpDwnBtn).click(); cy.get(this.searchEventDrpDwnBtn).click();
// cy.getId(this.userIdInputFld).type("11111"); cy.getId(this.userIdInputFld).type("11111");
// cy.get(this.eventsPageTitle).contains("No events logged"); cy.getId(this.searchEventsBtn).click();
// cy.getId(this.searchEventsBtn).click(); cy.get(this.eventsPageTitle).contains("No events logged");
// cy.get('[id^=remove_group]').click(); cy.get("[id^=remove_group]").click();
// cy.get("table").contains("LOGIN"); cy.get("table").contains("LOGIN");
} }
shouldDoNoResultsSearch() { shouldDoNoResultsSearch() {

View file

@ -1,8 +1,17 @@
import { import {
ActionGroup,
Button, Button,
Dropdown,
DropdownToggle,
Flex,
FlexItem,
Form,
FormGroup,
Modal, Modal,
ModalVariant, ModalVariant,
ToolbarItem, Select,
SelectVariant,
TextInput,
Tooltip, Tooltip,
} from "@patternfly/react-core"; } from "@patternfly/react-core";
import { import {
@ -15,18 +24,44 @@ import {
import type AdminEventRepresentation from "keycloak-admin/lib/defs/adminEventRepresentation"; import type AdminEventRepresentation from "keycloak-admin/lib/defs/adminEventRepresentation";
import moment from "moment"; import moment from "moment";
import React, { FunctionComponent, useState } from "react"; import React, { FunctionComponent, useState } from "react";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable";
import { useAdminClient } from "../context/auth/AdminClient"; import { useAdminClient } from "../context/auth/AdminClient";
import { useRealm } from "../context/realm-context/RealmContext"; import { useRealm } from "../context/realm-context/RealmContext";
import "./events.css";
type DisplayDialogProps = { type DisplayDialogProps = {
titleKey: string; titleKey: string;
onClose: () => void; onClose: () => void;
}; };
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: "",
};
const DisplayDialog: FunctionComponent<DisplayDialogProps> = ({ const DisplayDialog: FunctionComponent<DisplayDialogProps> = ({
titleKey, titleKey,
onClose, onClose,
@ -72,12 +107,23 @@ export const AdminEvents = () => {
const { realm } = useRealm(); const { realm } = useRealm();
const [key, setKey] = useState(0); const [key, setKey] = useState(0);
const [searchDropdownOpen, setSearchDropdownOpen] = useState(false);
const [selectOpen, setSelectOpen] = useState(false);
const refresh = () => setKey(new Date().getTime()); const refresh = () => setKey(new Date().getTime());
const [authEvent, setAuthEvent] = useState<AdminEventRepresentation>(); const [authEvent, setAuthEvent] = useState<AdminEventRepresentation>();
const [representationEvent, setRepresentationEvent] = const [representationEvent, setRepresentationEvent] =
useState<AdminEventRepresentation>(); useState<AdminEventRepresentation>();
const {
register,
formState: { isDirty },
} = useForm<AdminEventSearchForm>({
shouldUnregister: false,
mode: "onChange",
defaultValues,
});
const loader = async (first?: number, max?: number, search?: string) => { const loader = async (first?: number, max?: number, search?: string) => {
const params = { const params = {
first: first!, first: first!,
@ -111,6 +157,145 @@ export const AdminEvents = () => {
</> </>
); );
const adminEventSearchFormDisplay = () => {
return (
<>
<Flex direction={{ default: "column" }}>
<FlexItem>
<Dropdown
id="admin-events-search-select"
data-testid="AdminEventsSearchSelector"
className="pf-u-mt-md pf-u-ml-md pf-u-mb-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__events_search__form"
data-testid="searchForm"
>
<FormGroup
label={t("resourceType")}
fieldId="kc-resourceType"
className="keycloak__events_search__form_label"
>
<Select
variant={SelectVariant.single}
onToggle={(isOpen) => setSelectOpen(isOpen)}
isOpen={selectOpen}
></Select>
</FormGroup>
<FormGroup
label={t("operationType")}
fieldId="kc-operationType"
className="keycloak__events_search__form_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}
>
{t("searchAdminEventsBtn")}
</Button>
</ActionGroup>
</Form>
</Dropdown>
<Button
className="pf-u-ml-md"
onClick={refresh}
data-testid="refresh-btn"
>
{t("refresh")}
</Button>
</FlexItem>
</Flex>
</>
);
};
return ( return (
<> <>
{authEvent && ( {authEvent && (
@ -139,14 +324,7 @@ export const AdminEvents = () => {
loader={loader} loader={loader}
isPaginated isPaginated
ariaLabelKey="events:adminEvents" ariaLabelKey="events:adminEvents"
searchPlaceholderKey="events:searchForEvent" toolbarItem={adminEventSearchFormDisplay()}
toolbarItem={
<>
<ToolbarItem>
<Button onClick={refresh}>{t("refresh")}</Button>
</ToolbarItem>
</>
}
actions={[ actions={[
{ {
title: t("auth"), title: t("auth"),

View file

@ -7,7 +7,6 @@ import {
DescriptionListDescription, DescriptionListDescription,
DescriptionListGroup, DescriptionListGroup,
DescriptionListTerm, DescriptionListTerm,
Divider,
Dropdown, Dropdown,
DropdownToggle, DropdownToggle,
Flex, Flex,
@ -43,7 +42,7 @@ import { useRealm } from "../context/realm-context/RealmContext";
import { toRealmSettings } from "../realm-settings/routes/RealmSettings"; import { toRealmSettings } from "../realm-settings/routes/RealmSettings";
import { toUser } from "../user/routes/User"; import { toUser } from "../user/routes/User";
import { AdminEvents } from "./AdminEvents"; import { AdminEvents } from "./AdminEvents";
import "./events-section.css"; import "./events.css";
type UserEventSearchForm = { type UserEventSearchForm = {
client: string; client: string;
@ -170,6 +169,10 @@ export const EventsSection = () => {
setKey(key + 1); setKey(key + 1);
} }
function refresh() {
commitFilters();
}
const UserDetailLink = (event: EventRepresentation) => ( const UserDetailLink = (event: EventRepresentation) => (
<Link <Link
key={`link-${event.time}-${event.type}`} key={`link-${event.time}-${event.type}`}
@ -179,54 +182,35 @@ export const EventsSection = () => {
</Link> </Link>
); );
const userEventSearchFormDisplay = () => {
return ( return (
<> <>
<ViewHeader <Flex direction={{ default: "column" }}>
titleKey="events:title"
subKey={
<Trans i18nKey="events:eventExplain">
If you want to configure user events, Admin events or Event
listeners, please enter
<Link to={toRealmSettings({ realm, tab: "events" })}>
{t("eventConfig")}
</Link>
page realm settings to configure.
</Trans>
}
divider={false}
/>
<PageSection variant="light" className="pf-u-p-0">
<KeycloakTabs isBox>
<Tab
eventKey="userEvents"
title={<TabTitleText>{t("userEvents")}</TabTitleText>}
>
<Flex>
<FlexItem> <FlexItem>
<Dropdown <Dropdown
id="user-events-search-select" id="user-events-search-select"
data-testid="UserEventsSearchSelector" data-testid="UserEventsSearchSelector"
className="pf-u-mt-md pf-u-ml-md pf-u-mb-md" className="pf-u-mt-md pf-u-ml-md"
toggle={ toggle={
<DropdownToggle <DropdownToggle
data-testid="userEventsSearchSelectorToggle" data-testid="userEventsSearchSelectorToggle"
onToggle={(isOpen) => setSearchDropdownOpen(isOpen)} onToggle={(isOpen) => setSearchDropdownOpen(isOpen)}
className="keycloak__user_events_search_selector_dropdown__toggle" className="keycloak__events_search_selector_dropdown__toggle"
> >
{t("searchForEvent")} {t("searchForUserEvent")}
</DropdownToggle> </DropdownToggle>
} }
isOpen={searchDropdownOpen} isOpen={searchDropdownOpen}
> >
<Form <Form
isHorizontal isHorizontal
className="keycloak__user_events_search__form" className="keycloak__events_search__form"
data-testid="searchForm" data-testid="searchForm"
> >
<FormGroup <FormGroup
label={t("userId")} label={t("userId")}
fieldId="kc-userId" fieldId="kc-userId"
className="keycloak__user_events_search__form_label" className="keycloak__events_search__form_label"
> >
<TextInput <TextInput
ref={register()} ref={register()}
@ -239,7 +223,7 @@ export const EventsSection = () => {
<FormGroup <FormGroup
label={t("eventType")} label={t("eventType")}
fieldId="kc-eventType" fieldId="kc-eventType"
className="keycloak__user_events_search__form_label" className="keycloak__events_search__form_label"
> >
<Controller <Controller
name="type" name="type"
@ -252,7 +236,7 @@ export const EventsSection = () => {
value: EventType[]; value: EventType[];
}) => ( }) => (
<Select <Select
className="keycloak__user_events_search__event_type_select" className="keycloak__events_search__event_type_select"
name="eventType" name="eventType"
data-testid="event-type-searchField" data-testid="event-type-searchField"
chipGroupProps={{ chipGroupProps={{
@ -265,8 +249,7 @@ export const EventsSection = () => {
onToggle={(isOpen) => setSelectOpen(isOpen)} onToggle={(isOpen) => setSelectOpen(isOpen)}
selections={value} selections={value}
onSelect={(_, selectedValue) => { onSelect={(_, selectedValue) => {
const option = const option = selectedValue.toString() as EventType;
selectedValue.toString() as EventType;
const changedValue = value.includes(option) const changedValue = value.includes(option)
? value.filter((item) => item !== option) ? value.filter((item) => item !== option)
: [...value, option]; : [...value, option];
@ -286,10 +269,7 @@ export const EventsSection = () => {
key={chip} key={chip}
onClick={(event) => { onClick={(event) => {
event.stopPropagation(); event.stopPropagation();
onChange(value.filter((val) => val !== chip));
onChange(
value.filter((val) => val !== chip)
);
}} }}
> >
{chip} {chip}
@ -308,7 +288,7 @@ export const EventsSection = () => {
<FormGroup <FormGroup
label={t("client")} label={t("client")}
fieldId="kc-client" fieldId="kc-client"
className="keycloak__user_events_search__form_label" className="keycloak__events_search__form_label"
> >
<TextInput <TextInput
ref={register()} ref={register()}
@ -321,7 +301,7 @@ export const EventsSection = () => {
<FormGroup <FormGroup
label={t("dateFrom")} label={t("dateFrom")}
fieldId="kc-dateFrom" fieldId="kc-dateFrom"
className="keycloak__user_events_search__form_label" className="keycloak__events_search__form_label"
> >
<TextInput <TextInput
ref={register()} ref={register()}
@ -336,7 +316,7 @@ export const EventsSection = () => {
<FormGroup <FormGroup
label={t("dateTo")} label={t("dateTo")}
fieldId="kc-dateTo" fieldId="kc-dateTo"
className="keycloak__user_events_search__form_label" className="keycloak__events_search__form_label"
> >
<TextInput <TextInput
ref={register()} ref={register()}
@ -356,13 +336,20 @@ export const EventsSection = () => {
data-testid="search-events-btn" data-testid="search-events-btn"
isDisabled={!isDirty} isDisabled={!isDirty}
> >
{t("searchBtn")} {t("searchUserEventsBtn")}
</Button> </Button>
</ActionGroup> </ActionGroup>
</Form> </Form>
</Dropdown> </Dropdown>
<Button
className="pf-u-ml-md"
onClick={refresh}
data-testid="refresh-btn"
>
{t("refresh")}
</Button>
</FlexItem> </FlexItem>
</Flex> <FlexItem>
{Object.entries(activeFilters).length > 0 && ( {Object.entries(activeFilters).length > 0 && (
<div className="keycloak__searchChips pf-u-ml-md"> <div className="keycloak__searchChips pf-u-ml-md">
{Object.entries(activeFilters).map((filter) => { {Object.entries(activeFilters).map((filter) => {
@ -396,6 +383,34 @@ export const EventsSection = () => {
})} })}
</div> </div>
)} )}
</FlexItem>
</Flex>
</>
);
};
return (
<>
<ViewHeader
titleKey="events:title"
subKey={
<Trans i18nKey="events:eventExplain">
If you want to configure user events, Admin events or Event
listeners, please enter
<Link to={toRealmSettings({ realm, tab: "events" })}>
{t("eventConfig")}
</Link>
page realm settings to configure.
</Trans>
}
divider={false}
/>
<PageSection variant="light" className="pf-u-p-0">
<KeycloakTabs isBox>
<Tab
eventKey="userEvents"
title={<TabTitleText>{t("userEvents")}</TabTitleText>}
>
<div className="keycloak__events_table"> <div className="keycloak__events_table">
<KeycloakDataTable <KeycloakDataTable
key={key} key={key}
@ -409,6 +424,7 @@ export const EventsSection = () => {
]} ]}
isPaginated isPaginated
ariaLabelKey="events:title" ariaLabelKey="events:title"
toolbarItem={userEventSearchFormDisplay()}
columns={[ columns={[
{ {
name: "time", name: "time",
@ -438,7 +454,6 @@ export const EventsSection = () => {
]} ]}
emptyState={ emptyState={
<div className="pf-u-mt-md"> <div className="pf-u-mt-md">
<Divider className="keycloak__events_empty_state_divider" />
<ListEmptyState <ListEmptyState
message={t("emptyEvents")} message={t("emptyEvents")}
instructions={t("emptyEventsInstructions")} instructions={t("emptyEventsInstructions")}

View file

@ -2,41 +2,30 @@
--pf-c-description-list--m-horizontal__term--width: 15ch; --pf-c-description-list--m-horizontal__term--width: 15ch;
} }
.keycloak__user_events_search_selector_dropdown__toggle { .keycloak__events_search_selector_dropdown__toggle {
--pf-c-dropdown__toggle--MinWidth: 21rem; --pf-c-dropdown__toggle--MinWidth: 21rem;
}
.keycloak__refresh_btn,
.keycloak__searchChips,
.keycloak__user_events_search_selector_dropdown__toggle {
position: relative; position: relative;
z-index: 1; z-index: 1;
} }
.keycloak__user_events_search__form { .keycloak__events_search__form {
margin: 0 0 var(--pf-global--spacer--lg) var(--pf-global--spacer--lg); margin: 0 var(--pf-global--spacer--lg) var(--pf-global--spacer--lg) var(--pf-global--spacer--lg);
--pf-c-form__group--m-action--MarginTop: 0rem; --pf-c-form__group--m-action--MarginTop: 0rem;
--pf-c-form--m-horizontal__group-control--md--GridColumnWidth: 12rem; --pf-c-form--m-horizontal__group-control--md--GridColumnWidth: 24rem;
--pf-c-form--m-horizontal__group-label--md--GridColumnWidth: 5rem; --pf-c-form--m-horizontal__group-label--md--GridColumnWidth: 5rem;
} }
.keycloak__user_events_search__form_label { .keycloak__events_search__form_label {
--pf-c-form--m-horizontal__group-label--md--GridColumnWidth: 5rem; --pf-c-form--m-horizontal__group-label--md--GridColumnWidth: 5rem;
} }
.keycloak__user_events_search__event_type_select .pf-c-select__menu { .keycloak__events_search__event_type_select .pf-c-select__menu {
max-height: 200px; max-height: 200px;
overflow: auto; overflow: auto;
} }
.pf-c-toolbar { .pf-c-toolbar {
background-color: transparent; background-color: transparent;
} --pf-c-toolbar--PaddingTop: 0;
--pf-c-toolbar--PaddingBottom: 0;
.keycloak__events_table {
margin-top: -4.25rem;
}
.keycloak__events_empty_state_divider {
margin-top: 4.25rem;
} }

View file

@ -6,7 +6,8 @@ export default {
eventConfigs: "Event configs", eventConfigs: "Event configs",
userEvents: "User events", userEvents: "User events",
adminEvents: "Admin events", adminEvents: "Admin events",
searchForEvent: "Search user event", searchForUserEvent: "Search user event",
searchForAdminEvent: "Search admin event",
refresh: "Refresh", refresh: "Refresh",
emptyEvents: "No events logged", emptyEvents: "No events logged",
emptyEventsInstructions: "Configure event logging in the realm settings", emptyEventsInstructions: "Configure event logging in the realm settings",
@ -20,7 +21,9 @@ export default {
client: "Client", client: "Client",
dateFrom: "Date(from)", dateFrom: "Date(from)",
dateTo: "Date(to)", dateTo: "Date(to)",
searchBtn: "Search events", searchUserEventsBtn: "Search events",
searchAdminEventsBtn: "Search admin events",
realm: "Realm",
resourcePath: "Resource path", resourcePath: "Resource path",
resourceType: "Resource type", resourceType: "Resource type",
operationType: "Operation type", operationType: "Operation type",