Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: Publish with decendants structure reload #2486

Merged
merged 7 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
});
}

Expand All @@ -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);
}

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,18 +712,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() {
Expand Down Expand Up @@ -826,6 +828,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);
Expand All @@ -847,13 +855,30 @@ export class UmbDocumentWorkspaceContext

if (!variantIds.length) return;

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() {
Expand Down
Loading