request reload of entity after publish

This commit is contained in:
Mads Rasmussen
2024-05-21 20:24:02 +02:00
parent 392c65fdd7
commit 58a96597cf
2 changed files with 28 additions and 1 deletions

View File

@@ -3,10 +3,11 @@ import { UmbDocumentDetailRepository, UmbDocumentPublishingRepository } from '..
import type { UmbDocumentVariantOptionModel } from '../types.js';
import { UMB_APP_LANGUAGE_CONTEXT, UmbLanguageCollectionRepository } from '@umbraco-cms/backoffice/language';
import type { UmbEntityActionArgs } from '@umbraco-cms/backoffice/entity-action';
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action';
import { UmbEntityActionBase, UmbRequestReloadStructureForEntityEvent } from '@umbraco-cms/backoffice/entity-action';
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
export class UmbPublishDocumentEntityAction extends UmbEntityActionBase<never> {
constructor(host: UmbControllerHost, args: UmbEntityActionArgs<never>) {
@@ -44,11 +45,18 @@ export class UmbPublishDocumentEntityAction extends UmbEntityActionBase<never> {
}),
);
const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
const event = new UmbRequestReloadStructureForEntityEvent({
unique: this.args.unique,
entityType: this.args.entityType,
});
// If the document has only one variant, we can skip the modal and publish directly:
if (options.length === 1) {
const variantId = UmbVariantId.Create(documentData.variants[0]);
const publishingRepository = new UmbDocumentPublishingRepository(this._host);
await publishingRepository.publish(this.args.unique, [{ variantId }]);
actionEventContext.dispatchEvent(event);
return;
}
@@ -84,6 +92,7 @@ export class UmbPublishDocumentEntityAction extends UmbEntityActionBase<never> {
this.args.unique,
variantIds.map((variantId) => ({ variantId })),
);
actionEventContext.dispatchEvent(event);
}
}
}

View File

@@ -8,9 +8,19 @@ import { UMB_APP_LANGUAGE_CONTEXT, UmbLanguageCollectionRepository } from '@umbr
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
import { UMB_CONFIRM_MODAL, UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
import { UmbLocalizationController } from '@umbraco-cms/backoffice/localization-api';
import { UMB_ENTITY_CONTEXT } from '@umbraco-cms/backoffice/entity';
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
import { UmbRequestReloadChildrenOfEntityEvent } from '@umbraco-cms/backoffice/entity-action';
export class UmbDocumentPublishEntityBulkAction extends UmbEntityBulkActionBase<object> {
async execute() {
const entityContext = await this.getContext(UMB_ENTITY_CONTEXT);
const entityType = entityContext.getEntityType();
const unique = entityContext.getUnique();
if (!entityType) throw new Error('Entity type not found');
if (unique === undefined) throw new Error('Entity unique not found');
// If there is only one selection, we can refer to the regular publish entity action:
if (this.selection.length === 1) {
const action = new UmbPublishDocumentEntityAction(this._host, {
@@ -43,6 +53,12 @@ export class UmbDocumentPublishEntityBulkAction extends UmbEntityBulkActionBase<
const modalManagerContext = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
const event = new UmbRequestReloadChildrenOfEntityEvent({
entityType,
unique,
});
// If there is only one language available, we can skip the modal and publish directly:
if (options.length === 1) {
const localizationController = new UmbLocalizationController(this._host);
@@ -62,6 +78,7 @@ export class UmbDocumentPublishEntityBulkAction extends UmbEntityBulkActionBase<
const variantId = new UmbVariantId(options[0].language.unique, null);
const publishingRepository = new UmbDocumentPublishingRepository(this._host);
await publishingRepository.unpublish(this.selection[0], [variantId]);
eventContext.dispatchEvent(event);
}
return;
}
@@ -98,6 +115,7 @@ export class UmbDocumentPublishEntityBulkAction extends UmbEntityBulkActionBase<
unique,
variantIds.map((variantId) => ({ variantId })),
);
eventContext.dispatchEvent(event);
}
}
}