import { EVENT_REFRESH } from "@goauthentik/web/constants"; import { setURLParams } from "@goauthentik/web/elements/router/RouteMatch"; import { t } from "@lingui/macro"; import { CSSResult, LitElement, TemplateResult, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import AKGlobal from "@goauthentik/web/authentik.css"; import PFTreeView from "@patternfly/patternfly/components/TreeView/tree-view.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; export interface TreeViewItem { id?: string; label: string; childItems: TreeViewItem[]; parent?: TreeViewItem; level: number; } @customElement("ak-treeview-node") export class TreeViewNode extends LitElement { @property({ attribute: false }) item?: TreeViewItem; @property({ type: Boolean }) open = false; @property({ attribute: false }) host?: TreeView; @property() activePath = ""; @property() separator = ""; get openable(): boolean { return (this.item?.childItems || []).length > 0; } get fullPath(): string { const pathItems = []; let item = this.item; while (item) { if (item.id) { pathItems.push(item.id); } item = item.parent; } return pathItems.reverse().join(this.separator); } protected createRenderRoot(): Element { return this; } firstUpdated(): void { const pathSegments = this.activePath.split(this.separator); const level = this.item?.level || 0; // Ignore the last item as that shouldn't be expanded pathSegments.pop(); if (pathSegments[level] == this.item?.id) { this.open = true; } if (this.activePath === this.fullPath && this.host !== undefined) { this.host.activeNode = this; } } render(): TemplateResult { const shouldRenderChildren = (this.item?.childItems || []).length > 0 && this.open; return html`