From 3740b45e1a7c5a783f0115825bb46368164bdfb6 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 13 Feb 2023 11:14:40 +0100 Subject: [PATCH] web/admin: refactor event geo display Signed-off-by: Jens Langhammer --- web/src/admin/Routes.ts | 4 ++-- web/src/admin/events/EventListPage.ts | 10 +++------- .../{EventInfoPage.ts => EventViewPage.ts} | 17 ++++------------- web/src/admin/events/utils.ts | 17 +++++++++++++++++ 4 files changed, 26 insertions(+), 22 deletions(-) rename web/src/admin/events/{EventInfoPage.ts => EventViewPage.ts} (92%) diff --git a/web/src/admin/Routes.ts b/web/src/admin/Routes.ts index 434dd327f..bb695cfa5 100644 --- a/web/src/admin/Routes.ts +++ b/web/src/admin/Routes.ts @@ -105,8 +105,8 @@ export const ROUTES: Route[] = [ return html``; }), new Route(new RegExp(`^/events/log/(?${UUID_REGEX})$`), async (args) => { - await import("@goauthentik/admin/events/EventInfoPage"); - return html``; + await import("@goauthentik/admin/events/EventViewPage"); + return html``; }), new Route(new RegExp("^/events/transports$"), async () => { await import("@goauthentik/admin/events/TransportListPage"); diff --git a/web/src/admin/events/EventListPage.ts b/web/src/admin/events/EventListPage.ts index 5bf0e311f..dd1d432f9 100644 --- a/web/src/admin/events/EventListPage.ts +++ b/web/src/admin/events/EventListPage.ts @@ -1,9 +1,8 @@ import "@goauthentik/admin/events/EventInfo"; -import { ActionToLabel } from "@goauthentik/admin/events/utils"; +import { ActionToLabel, EventGeo } from "@goauthentik/admin/events/utils"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EventWithContext } from "@goauthentik/common/events"; import { uiConfig } from "@goauthentik/common/ui/config"; -import { KeyUnknown } from "@goauthentik/elements/forms/Form"; import { PaginatedResponse } from "@goauthentik/elements/table/Table"; import { TableColumn } from "@goauthentik/elements/table/Table"; import { TablePage } from "@goauthentik/elements/table/TablePage"; @@ -56,10 +55,6 @@ export class EventListPage extends TablePage { } row(item: EventWithContext): TemplateResult[] { - let geo: KeyUnknown | undefined = undefined; - if (Object.hasOwn(item.context, "geo")) { - geo = item.context.geo as KeyUnknown; - } return [ html`
${ActionToLabel(item.action)}
${item.app}`, @@ -77,7 +72,8 @@ export class EventListPage extends TablePage { : html`-`, html`${item.created?.toLocaleString()}`, html`
${item.clientIp || t`-`}
- ${geo ? html`${[geo.city, geo.country].join(", ")}` : html``}`, + + ${EventGeo(item)}`, html`${item.tenant?.name || t`-`}`, html` diff --git a/web/src/admin/events/EventInfoPage.ts b/web/src/admin/events/EventViewPage.ts similarity index 92% rename from web/src/admin/events/EventInfoPage.ts rename to web/src/admin/events/EventViewPage.ts index d294e0721..117ae2273 100644 --- a/web/src/admin/events/EventInfoPage.ts +++ b/web/src/admin/events/EventViewPage.ts @@ -1,10 +1,9 @@ import "@goauthentik/admin/events/EventInfo"; -import { ActionToLabel } from "@goauthentik/admin/events/utils"; +import { ActionToLabel, EventGeo } from "@goauthentik/admin/events/utils"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EventWithContext } from "@goauthentik/common/events"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/PageHeader"; -import { KeyUnknown } from "@goauthentik/elements/forms/Form"; import { t } from "@lingui/macro"; @@ -21,8 +20,8 @@ import PFBase from "@patternfly/patternfly/patternfly-base.css"; import { EventsApi } from "@goauthentik/api"; -@customElement("ak-event-info-page") -export class EventInfoPage extends AKElement { +@customElement("ak-event-view") +export class EventViewPage extends AKElement { @property() set eventID(value: string) { new EventsApi(DEFAULT_CONFIG) @@ -46,10 +45,6 @@ export class EventInfoPage extends AKElement { return html` `; } - let geo: KeyUnknown | undefined = undefined; - if (Object.hasOwn(this.event.context, "geo")) { - geo = this.event.context.geo as KeyUnknown; - } return html`
${this.event.clientIp || t`-`}
- ${geo - ? html`${[geo.city, geo.country].join(", ")}` - : html``} + ${EventGeo(this.event)}
diff --git a/web/src/admin/events/utils.ts b/web/src/admin/events/utils.ts index 7810b94d1..27e3f921e 100644 --- a/web/src/admin/events/utils.ts +++ b/web/src/admin/events/utils.ts @@ -1,7 +1,24 @@ +import { EventWithContext } from "@goauthentik/common/events"; +import { KeyUnknown } from "@goauthentik/elements/forms/Form"; + import { t } from "@lingui/macro"; +import { TemplateResult, html } from "lit"; + import { EventActions } from "@goauthentik/api"; +export function EventGeo(event: EventWithContext): TemplateResult { + let geo: KeyUnknown | undefined = undefined; + if (Object.hasOwn(event.context, "geo")) { + geo = event.context.geo as KeyUnknown; + const parts = [geo.city, geo.country, geo.continent].filter( + (v) => v !== "" && v !== undefined, + ); + return html`${parts.join(", ")}`; + } + return html``; +} + export function ActionToLabel(action?: EventActions): string { if (!action) return ""; switch (action) {