From d1403f6f7d7c31b3517f600e79e7b524cdb38cdc Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 12 Aug 2021 22:03:13 +0200 Subject: [PATCH] web: implement bulk-delete form Signed-off-by: Jens Langhammer --- web/src/elements/events/ObjectChangelog.ts | 1 - web/src/elements/events/UserEvents.ts | 1 - web/src/elements/forms/DeleteBulkForm.ts | 137 ++++++++++-------- web/src/elements/oauth/UserCodeList.ts | 17 +-- web/src/elements/oauth/UserRefreshList.ts | 19 ++- web/src/elements/user/SessionList.ts | 19 ++- web/src/elements/user/UserConsentList.ts | 19 ++- web/src/locales/en.po | 60 ++++---- web/src/locales/pseudo-LOCALE.po | 60 ++++---- .../pages/applications/ApplicationListPage.ts | 17 +-- .../crypto/CertificateKeyPairListPage.ts | 23 +-- web/src/pages/events/RuleListPage.ts | 17 +-- web/src/pages/events/TransportListPage.ts | 17 +-- web/src/pages/flows/BoundStagesList.ts | 19 ++- web/src/pages/flows/FlowListPage.ts | 17 +-- web/src/pages/groups/GroupListPage.ts | 17 +-- web/src/pages/outposts/OutpostListPage.ts | 17 +-- .../outposts/ServiceConnectionListPage.ts | 17 +-- web/src/pages/policies/BoundPoliciesList.ts | 19 ++- web/src/pages/policies/PolicyListPage.ts | 24 ++- .../reputation/IPReputationListPage.ts | 15 +- .../reputation/UserReputationListPage.ts | 15 +- .../PropertyMappingListPage.ts | 17 +-- web/src/pages/providers/ProviderListPage.ts | 17 +-- web/src/pages/sources/SourcesListPage.ts | 17 +-- web/src/pages/stages/StageListPage.ts | 17 +-- .../stages/invitation/InvitationListPage.ts | 17 +-- web/src/pages/stages/prompt/PromptListPage.ts | 17 +-- web/src/pages/tenants/TenantListPage.ts | 17 +-- web/src/pages/tokens/TokenListPage.ts | 17 +-- .../user-settings/tokens/UserTokenList.ts | 15 +- web/src/pages/users/UserListPage.ts | 14 +- 32 files changed, 365 insertions(+), 367 deletions(-) diff --git a/web/src/elements/events/ObjectChangelog.ts b/web/src/elements/events/ObjectChangelog.ts index 915133c84..5d22ce77e 100644 --- a/web/src/elements/events/ObjectChangelog.ts +++ b/web/src/elements/events/ObjectChangelog.ts @@ -4,7 +4,6 @@ import { AKResponse } from "../../api/Client"; import { Table, TableColumn } from "../table/Table"; import { Event, EventsApi } from "authentik-api"; -import "../forms/DeleteForm"; import "../Tabs"; import "../buttons/ModalButton"; import "../buttons/SpinnerButton"; diff --git a/web/src/elements/events/UserEvents.ts b/web/src/elements/events/UserEvents.ts index de52de8cf..eb2947f01 100644 --- a/web/src/elements/events/UserEvents.ts +++ b/web/src/elements/events/UserEvents.ts @@ -4,7 +4,6 @@ import { AKResponse } from "../../api/Client"; import { Table, TableColumn } from "../table/Table"; import { Event, EventsApi } from "authentik-api"; -import "../forms/DeleteForm"; import "../Tabs"; import "../buttons/ModalButton"; import "../buttons/SpinnerButton"; diff --git a/web/src/elements/forms/DeleteBulkForm.ts b/web/src/elements/forms/DeleteBulkForm.ts index 12b441999..88c8c3e1d 100644 --- a/web/src/elements/forms/DeleteBulkForm.ts +++ b/web/src/elements/forms/DeleteBulkForm.ts @@ -12,29 +12,28 @@ import { Table, TableColumn } from "../table/Table"; import { AKResponse } from "../../api/Client"; import { PFSize } from "../Spinner"; -export interface AKObject { - pk: T; - slug?: string; - name?: string; - [key: string]: unknown; -} +type BulkDeleteMetadata = { key: string; value: string }[]; @customElement("ak-delete-objects-table") -export class DeleteObjectsTable extends Table> { +export class DeleteObjectsTable extends Table { expandable = true; paginated = false; @property({ attribute: false }) - objects: AKObject[] = []; + objects: T[] = []; @property({ attribute: false }) - usedBy?: (item: AKObject) => Promise; + metadata!: (item: T) => BulkDeleteMetadata; + + @property({ attribute: false }) + usedBy?: (item: T) => Promise; static get styles(): CSSResult[] { return super.styles.concat(PFList); } - apiEndpoint(page: number): Promise>> { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + apiEndpoint(page: number): Promise> { return Promise.resolve({ pagination: { count: this.objects.length, @@ -48,77 +47,93 @@ export class DeleteObjectsTable extends Table { + return new TableColumn(element.key); + }); } - row(item: AKObject): TemplateResult[] { - return [html`${item.name}`, html`${item.pk}`]; + row(item: T): TemplateResult[] { + return this.metadata(item).map((element) => { + return html`${element.value}`; + }); } renderToolbarContainer(): TemplateResult { return html``; } - renderExpanded(item: AKObject): TemplateResult { - return html`${this.usedBy - ? until( - this.usedBy(item).then((usedBy) => { - return this.renderUsedBy(item, usedBy); - }), - html``, - ) - : html``}`; - } - - renderUsedBy(item: AKObject, usedBy: UsedBy[]): TemplateResult { - if (usedBy.length < 1) { - return html` -
- ${t`Not used by any other object.`} -
- `; - } + renderExpanded(item: T): TemplateResult { return html`
-

${t`The following objects use ${item.name}:`}

-
    - ${usedBy.map((ub) => { - let consequence = ""; - switch (ub.action) { - case UsedByActionEnum.Cascade: - consequence = t`object will be DELETED`; - break; - case UsedByActionEnum.CascadeMany: - consequence = t`connection will be deleted`; - break; - case UsedByActionEnum.SetDefault: - consequence = t`reference will be reset to default value`; - break; - case UsedByActionEnum.SetNull: - consequence = t`reference will be set to an empty value`; - break; - } - return html`
  • ${t`${ub.name} (${consequence})`}
  • `; - })} -
+ ${this.usedBy + ? until( + this.usedBy(item).then((usedBy) => { + return this.renderUsedBy(usedBy); + }), + html``, + ) + : html``}
- `; + `; + } + + renderUsedBy(usedBy: UsedBy[]): TemplateResult { + if (usedBy.length < 1) { + return html` ${t`Not used by any other object.`}`; + } + return html`
    + ${usedBy.map((ub) => { + let consequence = ""; + switch (ub.action) { + case UsedByActionEnum.Cascade: + consequence = t`object will be DELETED`; + break; + case UsedByActionEnum.CascadeMany: + consequence = t`connection will be deleted`; + break; + case UsedByActionEnum.SetDefault: + consequence = t`reference will be reset to default value`; + break; + case UsedByActionEnum.SetNull: + consequence = t`reference will be set to an empty value`; + break; + } + return html`
  • ${t`${ub.name} (${consequence})`}
  • `; + })} +
`; } } @customElement("ak-forms-delete-bulk") -export class DeleteBulkForm extends ModalButton { +export class DeleteBulkForm extends ModalButton { @property({ attribute: false }) - objects: AKObject[] = []; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + objects: any[] = []; @property() objectLabel?: string; @property({ attribute: false }) - usedBy?: (itemPk: AKObject) => Promise; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + metadata: (item: any) => BulkDeleteMetadata = (item: any) => { + const rec = item as Record; + const meta = []; + if (Object.prototype.hasOwnProperty.call(rec, "name")) { + meta.push({ key: t`Name`, value: rec.name as string }); + } + if (Object.prototype.hasOwnProperty.call(rec, "pk")) { + meta.push({ key: t`ID`, value: rec.pk as string }); + } + return meta; + }; @property({ attribute: false }) - delete!: (itemPk: AKObject) => Promise; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + usedBy?: (item: any) => Promise; + + @property({ attribute: false }) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + delete!: (item: any) => Promise; confirm(): Promise { return Promise.all( @@ -170,7 +185,11 @@ export class DeleteBulkForm extends ModalButton
- +