import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { Flow, FlowsApi } from "@goauthentik/api"; import { AKResponse } from "../../api/Client"; import { DEFAULT_CONFIG } from "../../api/Config"; import { uiConfig } from "../../common/config"; import "../../elements/buttons/SpinnerButton"; import "../../elements/forms/ConfirmationForm"; import "../../elements/forms/DeleteBulkForm"; import "../../elements/forms/ModalForm"; import { TableColumn } from "../../elements/table/Table"; import { TablePage } from "../../elements/table/TablePage"; import { groupBy } from "../../utils"; import "./FlowForm"; import "./FlowImportForm"; import { DesignationToLabel } from "./utils"; @customElement("ak-flow-list") export class FlowListPage extends TablePage { searchEnabled(): boolean { return true; } pageTitle(): string { return t`Flows`; } pageDescription(): string { return t`Flows describe a chain of Stages to authenticate, enroll or recover a user. Stages are chosen based on policies applied to them.`; } pageIcon(): string { return "pf-icon pf-icon-process-automation"; } checkbox = true; @property() order = "slug"; async apiEndpoint(page: number): Promise> { return new FlowsApi(DEFAULT_CONFIG).flowsInstancesList({ ordering: this.order, page: page, pageSize: (await uiConfig()).pagination.perPage, search: this.search || "", }); } groupBy(items: Flow[]): [string, Flow[]][] { return groupBy(items, (flow) => { if (!flow.designation) { return ""; } return DesignationToLabel(flow.designation); }); } columns(): TableColumn[] { return [ new TableColumn(t`Identifier`, "slug"), new TableColumn(t`Name`, "name"), new TableColumn(t`Stages`), new TableColumn(t`Policies`), new TableColumn(t`Actions`), ]; } renderToolbarSelected(): TemplateResult { const disabled = this.selectedElements.length < 1; return html` { return new FlowsApi(DEFAULT_CONFIG).flowsInstancesUsedByList({ slug: item.slug, }); }} .delete=${(item: Flow) => { return new FlowsApi(DEFAULT_CONFIG).flowsInstancesDestroy({ slug: item.slug, }); }} > `; } row(item: Flow): TemplateResult[] { return [ html` ${item.slug} `, html`${item.name}`, html`${Array.from(item.stages || []).length}`, html`${Array.from(item.policies || []).length}`, html` ${t`Update`} ${t`Update Flow`} `, ]; } renderToolbar(): TemplateResult { return html` ${t`Create`} ${t`Create Flow`} ${t`Import`} ${t`Import Flow`} ${super.renderToolbar()} { return new FlowsApi(DEFAULT_CONFIG).flowsInstancesCacheClearCreate(); }} > ${t`Clear Flow cache`}

${t`Are you sure you want to clear the flow cache? This will cause all flows to be re-evaluated on their next usage.`}

`; } }