reload workspace on entity detail updated event
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import type { UmbEntityActionEventArgs } from './entity-action.event.js';
|
||||
import { UmbEntityActionEvent } from './entity-action.event.js';
|
||||
|
||||
export class UmbEntityDetailUpdatedEvent extends UmbEntityActionEvent {
|
||||
static readonly TYPE = 'entity-detail-updated';
|
||||
|
||||
constructor(args: UmbEntityActionEventArgs) {
|
||||
super(UmbEntityDetailUpdatedEvent.TYPE, args);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ export * from './constants.js';
|
||||
export * from './entity-action-base.js';
|
||||
export * from './entity-action-list.element.js';
|
||||
export * from './entity-action.event.js';
|
||||
export * from './entity-detail-updated.event.js';
|
||||
export type * from './types.js';
|
||||
|
||||
export { UmbRequestReloadStructureForEntityEvent } from './request-reload-structure-for-entity.event.js';
|
||||
|
||||
@@ -15,6 +15,11 @@ import { UMB_ENTITY_CONTEXT } from '@umbraco-cms/backoffice/entity';
|
||||
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
|
||||
|
||||
import '../../modals/shared/document-variant-language-picker.element.js';
|
||||
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
|
||||
import {
|
||||
UmbEntityDetailUpdatedEvent,
|
||||
UmbRequestReloadStructureForEntityEvent,
|
||||
} from '@umbraco-cms/backoffice/entity-action';
|
||||
|
||||
type DocumentVersion = {
|
||||
id: string;
|
||||
@@ -187,12 +192,28 @@ export class UmbRollbackModalElement extends UmbModalBaseElement<UmbRollbackModa
|
||||
await this.#setDiffs();
|
||||
}
|
||||
|
||||
#onRollback() {
|
||||
async #onRollback() {
|
||||
if (!this._selectedVersion) return;
|
||||
|
||||
const id = this._selectedVersion.id;
|
||||
const culture = this._selectedCulture ?? undefined;
|
||||
this.#rollbackRepository.rollback(id, culture);
|
||||
|
||||
const { error } = await this.#rollbackRepository.rollback(id, culture);
|
||||
if (error) return;
|
||||
|
||||
const unique = this.#currentDocument?.unique;
|
||||
const entityType = this.#currentDocument?.entityType;
|
||||
|
||||
if (!unique || !entityType) {
|
||||
throw new Error('Document unique or entity type is not set');
|
||||
}
|
||||
|
||||
const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
|
||||
const reloadStructureEvent = new UmbRequestReloadStructureForEntityEvent({ unique, entityType });
|
||||
actionEventContext.dispatchEvent(reloadStructureEvent);
|
||||
|
||||
const entityDetailUpdatedEvent = new UmbEntityDetailUpdatedEvent({ unique, entityType });
|
||||
actionEventContext.dispatchEvent(entityDetailUpdatedEvent);
|
||||
|
||||
this.modalContext?.reject();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ import type { UmbDocumentTypeDetailModel } from '@umbraco-cms/backoffice/documen
|
||||
import { UmbIsTrashedEntityContext } from '@umbraco-cms/backoffice/recycle-bin';
|
||||
import { UMB_APP_CONTEXT } from '@umbraco-cms/backoffice/app';
|
||||
import { UmbDeprecation } from '@umbraco-cms/backoffice/utils';
|
||||
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
|
||||
import { UmbEntityDetailUpdatedEvent } from '@umbraco-cms/backoffice/entity-action';
|
||||
|
||||
type ContentModel = UmbDocumentDetailModel;
|
||||
type ContentTypeModel = UmbDocumentTypeDetailModel;
|
||||
@@ -66,6 +68,7 @@ export class UmbDocumentWorkspaceContext
|
||||
|
||||
#isTrashedContext = new UmbIsTrashedEntityContext(this);
|
||||
#publishingContext?: typeof UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT.TYPE;
|
||||
#eventContext?: typeof UMB_ACTION_EVENT_CONTEXT.TYPE;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host, {
|
||||
@@ -135,6 +138,20 @@ export class UmbDocumentWorkspaceContext
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
this.consumeContext(UMB_ACTION_EVENT_CONTEXT, (context) => {
|
||||
this.#eventContext = context;
|
||||
|
||||
this.#eventContext.removeEventListener(
|
||||
UmbEntityDetailUpdatedEvent.TYPE,
|
||||
this.#onEntityDetailUpdatedEvent as unknown as EventListener,
|
||||
);
|
||||
|
||||
this.#eventContext.addEventListener(
|
||||
UmbEntityDetailUpdatedEvent.TYPE,
|
||||
this.#onEntityDetailUpdatedEvent as unknown as EventListener,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
override async load(unique: string) {
|
||||
@@ -326,6 +343,18 @@ export class UmbDocumentWorkspaceContext
|
||||
): UmbDocumentPropertyDatasetContext {
|
||||
return new UmbDocumentPropertyDatasetContext(host, this, variantId);
|
||||
}
|
||||
|
||||
// TODO: This is currently only a local implementation. Looks into a solution for all detail workspaces
|
||||
#onEntityDetailUpdatedEvent = (event: UmbEntityDetailUpdatedEvent) => {
|
||||
const eventUnique = event.getUnique();
|
||||
const eventEntityType = event.getEntityType();
|
||||
|
||||
// Ignore events for other entities
|
||||
if (eventEntityType !== this.getEntityType()) return;
|
||||
if (eventUnique !== this.getUnique()) return;
|
||||
|
||||
this.load(this.getUnique()!);
|
||||
};
|
||||
}
|
||||
|
||||
export default UmbDocumentWorkspaceContext;
|
||||
|
||||
Reference in New Issue
Block a user