Hotfix: Publish with decendants structure reload (#2486)

* ensure we always have the latest variant data

* use enum value

* Update document-tree-item.element.ts

* only dispatch event if there is no error

* reload structure after publish with descendants

* only request update if it succeeds

* rename private method
This commit is contained in:
Mads Rasmussen
2024-10-28 11:41:45 +01:00
committed by Niels Lyngsø
parent e96013ac29
commit a4e75f40d0
3 changed files with 56 additions and 24 deletions

View File

@@ -77,15 +77,17 @@ export class UmbUnpublishDocumentEntityAction extends UmbEntityActionBase<never>
if (variantIds.length) {
const publishingRepository = new UmbDocumentPublishingRepository(this._host);
await publishingRepository.unpublish(this.args.unique, variantIds);
const { error } = await publishingRepository.unpublish(this.args.unique, variantIds);
const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
const event = new UmbRequestReloadStructureForEntityEvent({
unique: this.args.unique,
entityType: this.args.entityType,
});
if (!error) {
const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
const event = new UmbRequestReloadStructureForEntityEvent({
unique: this.args.unique,
entityType: this.args.entityType,
});
actionEventContext.dispatchEvent(event);
actionEventContext.dispatchEvent(event);
}
}
}
}

View File

@@ -1,4 +1,5 @@
import type { UmbDocumentTreeItemModel, UmbDocumentTreeItemVariantModel } from '../types.js';
import { DocumentVariantStateModel } from '@umbraco-cms/backoffice/external/backend-api';
import { css, html, nothing, customElement, state, classMap } from '@umbraco-cms/backoffice/external/lit';
import type { UmbAppLanguageContext } from '@umbraco-cms/backoffice/language';
import { UMB_APP_LANGUAGE_CONTEXT } from '@umbraco-cms/backoffice/language';
@@ -31,7 +32,7 @@ export class UmbDocumentTreeItemElement extends UmbTreeItemElementBase<UmbDocume
#observeAppCulture() {
this.observe(this.#appLanguageContext!.appLanguageCulture, (value) => {
this._currentCulture = value;
this._variant = this.#getVariant(value);
this._variant = this.#findVariant(value);
});
}
@@ -41,7 +42,7 @@ export class UmbDocumentTreeItemElement extends UmbTreeItemElementBase<UmbDocume
});
}
#getVariant(culture: string | undefined) {
#findVariant(culture: string | undefined) {
return this.item?.variants.find((x) => x.culture === culture);
}
@@ -56,16 +57,22 @@ export class UmbDocumentTreeItemElement extends UmbTreeItemElementBase<UmbDocume
return this._item?.variants[0].name;
}
const fallbackName = this.#getVariant(this._defaultCulture)?.name ?? this._item?.variants[0].name ?? 'Unknown';
// ensure we always have the correct variant data
this._variant = this.#findVariant(this._currentCulture);
const fallbackName = this.#findVariant(this._defaultCulture)?.name ?? this._item?.variants[0].name ?? 'Unknown';
return this._variant?.name ?? `(${fallbackName})`;
}
#isDraft() {
if (this.#isInvariant()) {
return this._item?.variants[0].state === 'Draft';
return this._item?.variants[0].state === DocumentVariantStateModel.DRAFT;
}
return this._variant?.state === 'Draft';
// ensure we always have the correct variant data
this._variant = this.#findVariant(this._currentCulture);
return this._variant?.state === DocumentVariantStateModel.DRAFT;
}
override renderIconContainer() {

View File

@@ -716,18 +716,20 @@ export class UmbDocumentWorkspaceContext
await this.#performSaveOrCreate(variantIds, saveData);
await this.publishingRepository.publish(
const { error } = await this.publishingRepository.publish(
unique,
variantIds.map((variantId) => ({ variantId })),
);
const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
const event = new UmbRequestReloadStructureForEntityEvent({
unique: this.getUnique()!,
entityType: this.getEntityType(),
});
if (!error) {
const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
const event = new UmbRequestReloadStructureForEntityEvent({
unique: this.getUnique()!,
entityType: this.getEntityType(),
});
eventContext.dispatchEvent(event);
eventContext.dispatchEvent(event);
}
}
async #handleSave() {
@@ -832,6 +834,12 @@ export class UmbDocumentWorkspaceContext
}
public async publishWithDescendants() {
const unique = this.getUnique();
if (!unique) throw new Error('Unique is missing');
const entityType = this.getEntityType();
if (!entityType) throw new Error('Entity type is missing');
const { options, selected } = await this.#determineVariantOptions();
const modalManagerContext = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
@@ -853,15 +861,30 @@ export class UmbDocumentWorkspaceContext
if (!variantIds.length) return;
// TODO: Validate content & Save changes for the selected variants — This was how it worked in v.13 [NL]
const unique = this.getUnique();
if (!unique) throw new Error('Unique is missing');
await this.publishingRepository.publishWithDescendants(
const { error } = await this.publishingRepository.publishWithDescendants(
unique,
variantIds,
result.includeUnpublishedDescendants ?? false,
);
if (!error) {
const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
// request reload of this entity
const structureEvent = new UmbRequestReloadStructureForEntityEvent({
entityType,
unique,
});
// request reload of the children
const childrenEvent = new UmbRequestReloadChildrenOfEntityEvent({
entityType,
unique,
});
eventContext.dispatchEvent(structureEvent);
eventContext.dispatchEvent(childrenEvent);
}
}
async delete() {