Files
authentik/web/src/components/events/ObjectChangelog.ts
Jens L. 3fa6ce2e34 enterprise/web/admin: OSM for events (#9287)
* web: fix esbuild issue with style sheets

Getting ESBuild, Lit, and Storybook to all agree on how to read and parse stylesheets is a serious
pain. This fix better identifies the value types (instances) being passed from various sources in
the repo to the three *different* kinds of style processors we're using (the native one, the
polyfill one, and whatever the heck Storybook does internally).

Falling back to using older CSS instantiating techniques one era at a time seems to do the trick.
It's ugly, but in the face of the aggressive styling we use to avoid Flashes of Unstyled Content
(FLoUC), it's the logic with which we're left.

In standard mode, the following warning appears on the console when running a Flow:

```
Autofocus processing was blocked because a document already has a focused element.
```

In compatibility mode, the following **error** appears on the console when running a Flow:

```
crawler-inject.js:1106 Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.
    at initDomMutationObservers (crawler-inject.js:1106:18)
    at crawler-inject.js:1114:24
    at Array.forEach (<anonymous>)
    at initDomMutationObservers (crawler-inject.js:1114:10)
    at crawler-inject.js:1549:1
initDomMutationObservers @ crawler-inject.js:1106
(anonymous) @ crawler-inject.js:1114
initDomMutationObservers @ crawler-inject.js:1114
(anonymous) @ crawler-inject.js:1549
```

Despite this error, nothing seems to be broken and flows work as anticipated.

* initial OSM for events

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* remove card title

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* split with volume

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* add pin

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* basic map selection

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* update pin

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* rewrite map points to be more imperative

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* zoom to fit

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: Ken Sternberg <ken@goauthentik.io>
2025-06-18 13:36:40 +02:00

109 lines
3.6 KiB
TypeScript

import { EventGeo, EventUser } from "@goauthentik/admin/events/utils";
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
import { EventWithContext } from "@goauthentik/common/events";
import { actionToLabel } from "@goauthentik/common/labels";
import { formatElapsedTime } from "@goauthentik/common/temporal";
import "@goauthentik/components/ak-event-info";
import "@goauthentik/elements/Tabs";
import "@goauthentik/elements/buttons/Dropdown";
import "@goauthentik/elements/buttons/ModalButton";
import "@goauthentik/elements/buttons/SpinnerButton";
import { PaginatedResponse } from "@goauthentik/elements/table/Table";
import { Table, TableColumn } from "@goauthentik/elements/table/Table";
import { SlottedTemplateResult } from "@goauthentik/elements/types";
import { msg } from "@lit/localize";
import { PropertyValues, TemplateResult, html } from "lit";
import { customElement, property } from "lit/decorators.js";
import { Event, EventsApi } from "@goauthentik/api";
@customElement("ak-object-changelog")
export class ObjectChangelog extends Table<Event> {
expandable = true;
@property()
order = "-created";
@property()
targetModelPk!: string | number;
@property()
targetModelApp?: string;
@property()
targetModelName = "";
async apiEndpoint(): Promise<PaginatedResponse<Event>> {
let modelName = this.targetModelName;
let appName = this.targetModelApp;
if (this.targetModelName.indexOf(".") !== -1) {
const parts = this.targetModelName.split(".", 1);
appName = parts[0];
modelName = parts[1];
}
if (this.targetModelName === "") {
return Promise.reject();
}
return new EventsApi(DEFAULT_CONFIG).eventsEventsList({
...(await this.defaultEndpointConfig()),
action: "model_",
contextModelApp: appName,
contextModelName: modelName,
contextModelPk: this.targetModelPk.toString(),
});
}
columns(): TableColumn[] {
return [
new TableColumn(msg("Action"), "action"),
new TableColumn(msg("User"), "enabled"),
new TableColumn(msg("Creation Date"), "created"),
new TableColumn(msg("Client IP"), "client_ip"),
];
}
willUpdate(changedProperties: PropertyValues<this>) {
if (changedProperties.has("targetModelName") && this.targetModelName) {
this.fetch();
}
}
row(item: EventWithContext): SlottedTemplateResult[] {
return [
html`${actionToLabel(item.action)}`,
EventUser(item),
html`<div>${formatElapsedTime(item.created)}</div>
<small>${item.created.toLocaleString()}</small>`,
html`<div>${item.clientIp || msg("-")}</div>
<small>${EventGeo(item)}</small>`,
];
}
renderExpanded(item: Event): TemplateResult {
return html` <td role="cell" colspan="4">
<div class="pf-c-table__expandable-row-content">
<ak-event-info .event=${item as EventWithContext}></ak-event-info>
</div>
</td>
<td></td>
<td></td>
<td></td>`;
}
renderEmpty(): TemplateResult {
return super.renderEmpty(
html`<ak-empty-state
><span slot="header">${msg("No Events found.")}</span>
<div slot="body">${msg("No matching events could be found.")}</div>
</ak-empty-state>`,
);
}
}
declare global {
interface HTMLElementTagNameMap {
"ak-object-changelog": ObjectChangelog;
}
}