import { t } from "@lingui/macro"; import { CSSResult, customElement, html, property, TemplateResult } from "lit-element"; import { AKResponse } from "../../../api/Client"; import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css"; import "../../../elements/forms/DeleteForm"; import "../../../elements/forms/ModalForm"; import "../../../elements/buttons/ModalButton"; import "../../../elements/buttons/Dropdown"; import "../../../elements/buttons/TokenCopyButton"; import { Table, TableColumn } from "../../../elements/table/Table"; import { PAGE_SIZE } from "../../../constants"; import { CoreApi, Token } from "authentik-api"; import { DEFAULT_CONFIG } from "../../../api/Config"; import "./UserTokenForm"; @customElement("ak-user-token-list") export class UserTokenList extends Table { searchEnabled(): boolean { return true; } expandable = true; @property() order = "expires"; apiEndpoint(page: number): Promise> { return new CoreApi(DEFAULT_CONFIG).coreTokensList({ ordering: this.order, page: page, pageSize: PAGE_SIZE, search: this.search || "", }); } columns(): TableColumn[] { return [ new TableColumn(t`Identifier`, t`identifier`), new TableColumn(""), ]; } static get styles(): CSSResult[] { return super.styles.concat(PFDescriptionList); } renderToolbar(): TemplateResult { return html` ${t`Create`} ${t`Create Token`} ${super.renderToolbar()} `; } renderExpanded(item: Token): TemplateResult { return html`
${t`User`}
${item.user?.username}
${t`Expiring`}
${item.expiring ? "Yes" : "No"}
${t`Expiring`}
${item.expiring ? item.expires?.toLocaleString() : "-"}
`; } row(item: Token): TemplateResult[] { return [ html`${item.identifier}`, html` ${t`Update`} ${t`Update Token`} { return new CoreApi(DEFAULT_CONFIG).coreTokensDelete({ identifier: item.identifier }); }}> ${t`Copy Key`} `, ]; } }