Skip to content

Commit

Permalink
clear states if a new document is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
madsrasmussen committed Dec 18, 2024
1 parent 567816a commit 1770f80
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,11 @@ export class UmbDocumentPublishedPendingChangesManager extends UmbControllerBase
// @ts-expect-error
delete variant.updateDate;
};

/**
* Clear all states/values,
*/
clear() {
this.#variantsWithChanges.setValue([]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
import { firstValueFrom } from '@umbraco-cms/backoffice/external/rxjs';
import { observeMultiple } from '@umbraco-cms/backoffice/observable-api';
import { DocumentVariantStateModel } from '@umbraco-cms/backoffice/external/backend-api';
import type { UmbEntityUnique } from '@umbraco-cms/backoffice/entity';

export class UmbDocumentPublishingWorkspaceContext extends UmbContextBase<UmbDocumentPublishingWorkspaceContext> {
/**
Expand All @@ -37,6 +38,7 @@ export class UmbDocumentPublishingWorkspaceContext extends UmbContextBase<UmbDoc
#eventContext?: typeof UMB_ACTION_EVENT_CONTEXT.TYPE;
#publishingRepository = new UmbDocumentPublishingRepository(this);
#publishedDocumentData?: UmbDocumentDetailModel;
#currentUnique?: UmbEntityUnique;

constructor(host: UmbControllerHost) {
super(host, UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT);
Expand Down Expand Up @@ -331,6 +333,13 @@ export class UmbDocumentPublishingWorkspaceContext extends UmbContextBase<UmbDoc
this.observe(
observeMultiple([this.#documentWorkspaceContext.unique, this.#documentWorkspaceContext.isNew]),
([unique, isNew]) => {
// We have loaded in a new document, so we need to clear the states
if (unique !== this.#currentUnique) {
this.#clear();
}

this.#currentUnique = unique;

if (isNew === false && unique) {
this.#loadAndProcessLastPublished();
}
Expand Down Expand Up @@ -383,6 +392,11 @@ export class UmbDocumentPublishingWorkspaceContext extends UmbContextBase<UmbDoc

this.publishedPendingChanges.process({ persistedData, publishedData });
}

#clear() {
this.#publishedDocumentData = undefined;
this.publishedPendingChanges.clear();
}
}

export { UmbDocumentPublishingWorkspaceContext as api };

0 comments on commit 1770f80

Please sign in to comment.