use new extension point for bulk action + remove old

This commit is contained in:
Mads Rasmussen
2023-02-08 09:48:57 +01:00
parent a4eeb726a1
commit a2ae2d3e0d
9 changed files with 71 additions and 120 deletions

View File

@@ -1,11 +0,0 @@
import type { ManifestElement } from './models';
export interface ManifestCollectionBulkAction extends ManifestElement {
type: 'collectionBulkAction';
meta: MetaCollectionBulkAction;
}
export interface MetaCollectionBulkAction {
label: string;
entityType: string;
}

View File

@@ -1,4 +1,3 @@
import type { ManifestCollectionBulkAction } from './collection-bulk-action.models';
import type { ManifestCollectionView } from './collection-view.models';
import type { ManifestDashboard } from './dashboard.models';
import type { ManifestDashboardCollection } from './dashboard-collection.models';
@@ -24,7 +23,6 @@ import type { ManifestWorkspaceViewCollection } from './workspace-view-collectio
import type { ManifestRepository } from './repository.models';
import type { ClassConstructor } from '@umbraco-cms/models';
export * from './collection-bulk-action.models';
export * from './collection-view.models';
export * from './dashboard-collection.models';
export * from './dashboard.models';
@@ -50,7 +48,6 @@ export * from './repository.models';
export * from './workspace.models';
export type ManifestTypes =
| ManifestCollectionBulkAction
| ManifestCollectionView
| ManifestCustom
| ManifestDashboard

View File

@@ -220,8 +220,9 @@ export class UmbDocumentRepository implements UmbTreeRepository, UmbDetailReposi
// Listing all currently known methods we need to implement:
// these currently only covers posting data
// TODO: find a good way to split these
async trash() {
alert('trash');
async trash(keys: Array<string>) {
console.log('document trash: ' + keys);
alert('implement trash');
}
async saveAndPublish() {

View File

@@ -1,5 +1,6 @@
import { UmbMediaMoveEntityBulkAction } from './move/move.action';
import { UmbMediaCopyEntityBulkAction } from './copy/copy.action';
import { UmbMediaTrashEntityBulkAction } from './trash/trash.action';
import { ManifestEntityBulkAction } from '@umbraco-cms/extensions-registry';
const entityType = 'media';
@@ -30,6 +31,18 @@ const entityActions: Array<ManifestEntityBulkAction> = [
api: UmbMediaCopyEntityBulkAction,
},
},
{
type: 'entityBulkAction',
alias: 'Umb.EntityBulkAction.Media.Trash',
name: 'Trash Media Entity Bulk Action',
weight: 80,
meta: {
entityType,
label: 'Trash',
repositoryAlias,
api: UmbMediaTrashEntityBulkAction,
},
},
];
export const manifests = [...entityActions];

View File

@@ -0,0 +1,52 @@
import type { UmbMediaRepository } from '../../repository/media.repository';
import { UmbActionBase } from '../../../../shared/action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
import { UmbContextConsumerController } from '@umbraco-cms/context-api';
import { UmbModalService, UMB_MODAL_SERVICE_CONTEXT_TOKEN } from '@umbraco-cms/modal';
import { html } from 'lit-html';
export class UmbMediaTrashEntityBulkAction extends UmbActionBase<UmbMediaRepository> {
#selection: Array<string>;
#modalService?: UmbModalService;
constructor(host: UmbControllerHostInterface, repositoryAlias: string, selection: Array<string>) {
super(host, repositoryAlias);
this.#selection = selection;
new UmbContextConsumerController(host, UMB_MODAL_SERVICE_CONTEXT_TOKEN, (instance) => {
this.#modalService = instance;
});
}
setSelection(selection: Array<string>) {
this.#selection = selection;
}
async execute() {
// TODO: show error
if (!this.#modalService || !this.repository) return;
// TODO: should we subscribe in cases like this?
const { data } = await this.repository.requestTreeItems(this.#selection);
if (data) {
// TODO: use correct markup
const modalHandler = this.#modalService?.confirm({
headline: `Deleting ${this.#selection.length} items`,
content: html`
This will delete the following files:
<ul style="list-style-type: none; padding: 0; margin: 0; margin-top: var(--uui-size-space-2);">
${data.map((item) => html`<li>${item.name}</li>`)}
</ul>
`,
color: 'danger',
confirmLabel: 'Delete',
});
const { confirmed } = await modalHandler.onClose();
if (confirmed) {
await this.repository?.trash(this.#selection);
}
}
}
}

View File

@@ -213,8 +213,9 @@ export class UmbMediaRepository implements UmbTreeRepository, UmbDetailRepositor
return { error };
}
async trash() {
alert('trash');
async trash(keys: Array<string>) {
console.log('media trash: ' + keys);
alert('implement trash');
}
async move(keys: Array<string>, destination: string) {

View File

@@ -1,84 +0,0 @@
import { UUITextStyles } from '@umbraco-ui/uui-css';
import { css, html } from 'lit';
import { customElement } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { map } from 'rxjs';
import { repeat } from 'lit-html/directives/repeat.js';
import { UmbCollectionContext, UMB_COLLECTION_CONTEXT_TOKEN } from '../collection.context';
import { UmbModalService, UMB_MODAL_SERVICE_CONTEXT_TOKEN } from '../../../../core/modal';
import { UmbLitElement } from '@umbraco-cms/element';
import type { ManifestCollectionBulkAction, MediaDetails } from '@umbraco-cms/models';
@customElement('umb-collection-bulk-action-media-delete')
export class UmbCollectionBulkActionDeleteElement extends UmbLitElement {
static styles = [UUITextStyles, css``];
// TODO: make a UmbCollectionContextMedia:
#collectionContext?: UmbCollectionContext<any, any>;
public manifest?: ManifestCollectionBulkAction;
#modalService?: UmbModalService;
constructor() {
super();
this.consumeContext(UMB_COLLECTION_CONTEXT_TOKEN, (context) => {
this.#collectionContext = context;
});
this.consumeContext(UMB_MODAL_SERVICE_CONTEXT_TOKEN, (instance) => {
this.#modalService = instance;
});
}
#handleClick(event: Event) {
// TODO: Revisit this subscription nightmare, can we make this simpler, avoid subscribing to the selection?
const selectionSubscription = this.#collectionContext?.selection.subscribe((selection) => {
const dataSubscription = this.#collectionContext?.data
.pipe(map((items) => items.filter((item) => item.key && selection.includes(item.key))))
.subscribe((items: Array<any>) => {
const modalHandler = this.#modalService?.confirm({
headline: `Deleting ${selection.length} items`,
content: html`
This will delete the following files:
<ul style="list-style-type: none; padding: 0; margin: 0; margin-top: var(--uui-size-space-2);">
${repeat(
items,
(item) => item.key,
(item) => html`<li style="font-weight: bold;">${item.name}</li>`
)}
</ul>
`,
color: 'danger',
confirmLabel: 'Delete',
});
modalHandler?.onClose().then(({ confirmed }) => {
selectionSubscription?.unsubscribe();
dataSubscription?.unsubscribe();
if (confirmed) {
this.#collectionContext?.trash(selection);
this.#collectionContext?.clearSelection();
}
});
});
});
}
render() {
// TODO: make a UmbCollectionContextMedia and use a deleteSelection method.
return html`<uui-button
@click=${this.#handleClick}
label=${ifDefined(this.manifest?.meta.label)}
color="default"
look="secondary"></uui-button>`;
}
}
declare global {
interface HTMLElementTagNameMap {
'umb-collection-bulk-action-media-delete': UmbCollectionBulkActionDeleteElement;
}
}

View File

@@ -1,16 +0,0 @@
import type { ManifestCollectionBulkAction } from '@umbraco-cms/models';
export const manifests: Array<ManifestCollectionBulkAction> = [
{
type: 'collectionBulkAction',
alias: 'Umb.CollectionBulkAction.Delete',
name: 'Delete',
elementName: 'umb-collection-bulk-action-media-delete',
loader: () => import('./collection-bulk-action-media-delete.element'),
weight: 200,
meta: {
label: 'Delete',
entityType: 'media',
},
},
];

View File

@@ -3,7 +3,6 @@ import './components';
import { manifests as propertyActionManifests } from './property-actions/manifests';
import { manifests as propertyEditorModelManifests } from './property-editors/models/manifests';
import { manifests as propertyEditorUIManifests } from './property-editors/uis/manifests';
import { manifests as collectionBulkActionManifests } from './collection/bulk-actions/manifests';
import { manifests as collectionViewManifests } from './collection/views/manifests';
import { umbExtensionsRegistry } from '@umbraco-cms/extensions-api';
@@ -20,6 +19,5 @@ registerExtensions([
...propertyActionManifests,
...propertyEditorModelManifests,
...propertyEditorUIManifests,
...collectionBulkActionManifests,
...collectionViewManifests,
]);