Skip to content

Commit 60e362b

Browse files
authored
Merge pull request #1851 from umbraco/bugfix/request-reload-after-entity-publish
Bugfix: request reload of entity after publish
2 parents 7bad7fe + 5c3df1e commit 60e362b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/packages/documents/documents/entity-actions/publish.action.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { UmbDocumentDetailRepository, UmbDocumentPublishingRepository } from '..
33
import type { UmbDocumentVariantOptionModel } from '../types.js';
44
import { UMB_APP_LANGUAGE_CONTEXT, UmbLanguageCollectionRepository } from '@umbraco-cms/backoffice/language';
55
import type { UmbEntityActionArgs } from '@umbraco-cms/backoffice/entity-action';
6-
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action';
6+
import { UmbEntityActionBase, UmbRequestReloadStructureForEntityEvent } from '@umbraco-cms/backoffice/entity-action';
77
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
88
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
99
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
10+
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
1011

1112
export class UmbPublishDocumentEntityAction extends UmbEntityActionBase<never> {
1213
constructor(host: UmbControllerHost, args: UmbEntityActionArgs<never>) {
@@ -44,11 +45,18 @@ export class UmbPublishDocumentEntityAction extends UmbEntityActionBase<never> {
4445
}),
4546
);
4647

48+
const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
49+
const event = new UmbRequestReloadStructureForEntityEvent({
50+
unique: this.args.unique,
51+
entityType: this.args.entityType,
52+
});
53+
4754
// If the document has only one variant, we can skip the modal and publish directly:
4855
if (options.length === 1) {
4956
const variantId = UmbVariantId.Create(documentData.variants[0]);
5057
const publishingRepository = new UmbDocumentPublishingRepository(this._host);
5158
await publishingRepository.publish(this.args.unique, [{ variantId }]);
59+
actionEventContext.dispatchEvent(event);
5260
return;
5361
}
5462

@@ -84,6 +92,7 @@ export class UmbPublishDocumentEntityAction extends UmbEntityActionBase<never> {
8492
this.args.unique,
8593
variantIds.map((variantId) => ({ variantId })),
8694
);
95+
actionEventContext.dispatchEvent(event);
8796
}
8897
}
8998
}

src/packages/documents/documents/entity-bulk-actions/publish/publish.action.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@ import { UMB_APP_LANGUAGE_CONTEXT, UmbLanguageCollectionRepository } from '@umbr
88
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
99
import { UMB_CONFIRM_MODAL, UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
1010
import { UmbLocalizationController } from '@umbraco-cms/backoffice/localization-api';
11+
import { UMB_ENTITY_CONTEXT } from '@umbraco-cms/backoffice/entity';
12+
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
13+
import { UmbRequestReloadChildrenOfEntityEvent } from '@umbraco-cms/backoffice/entity-action';
1114

1215
export class UmbDocumentPublishEntityBulkAction extends UmbEntityBulkActionBase<object> {
1316
async execute() {
17+
const entityContext = await this.getContext(UMB_ENTITY_CONTEXT);
18+
const entityType = entityContext.getEntityType();
19+
const unique = entityContext.getUnique();
20+
21+
if (!entityType) throw new Error('Entity type not found');
22+
if (unique === undefined) throw new Error('Entity unique not found');
23+
1424
// If there is only one selection, we can refer to the regular publish entity action:
1525
if (this.selection.length === 1) {
1626
const action = new UmbPublishDocumentEntityAction(this._host, {
@@ -43,6 +53,12 @@ export class UmbDocumentPublishEntityBulkAction extends UmbEntityBulkActionBase<
4353

4454
const modalManagerContext = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
4555

56+
const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
57+
const event = new UmbRequestReloadChildrenOfEntityEvent({
58+
entityType,
59+
unique,
60+
});
61+
4662
// If there is only one language available, we can skip the modal and publish directly:
4763
if (options.length === 1) {
4864
const localizationController = new UmbLocalizationController(this._host);
@@ -62,6 +78,7 @@ export class UmbDocumentPublishEntityBulkAction extends UmbEntityBulkActionBase<
6278
const variantId = new UmbVariantId(options[0].language.unique, null);
6379
const publishingRepository = new UmbDocumentPublishingRepository(this._host);
6480
await publishingRepository.unpublish(this.selection[0], [variantId]);
81+
eventContext.dispatchEvent(event);
6582
}
6683
return;
6784
}
@@ -98,6 +115,7 @@ export class UmbDocumentPublishEntityBulkAction extends UmbEntityBulkActionBase<
98115
unique,
99116
variantIds.map((variantId) => ({ variantId })),
100117
);
118+
eventContext.dispatchEvent(event);
101119
}
102120
}
103121
}

0 commit comments

Comments
 (0)