Skip to content

Commit 42bf033

Browse files
committed
revert changes in doc workspace
1 parent 195966e commit 42bf033

File tree

1 file changed

+2
-60
lines changed

1 file changed

+2
-60
lines changed

src/packages/documents/documents/workspace/document-workspace.context.ts

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { UmbDocumentTypeDetailRepository } from '../../document-types/repository/detail/document-type-detail.repository.js';
22
import { UmbDocumentPropertyDatasetContext } from '../property-dataset-context/document-property-dataset-context.js';
3-
import { UMB_DOCUMENT_ENTITY_TYPE, type UmbDocumentEntityTypeUnion } from '../entity.js';
3+
import { UMB_DOCUMENT_ENTITY_TYPE } from '../entity.js';
44
import { UmbDocumentDetailRepository } from '../repository/index.js';
55
import type {
66
UmbDocumentVariantPublishModel,
@@ -52,7 +52,7 @@ import {
5252
UmbRequestReloadChildrenOfEntityEvent,
5353
UmbRequestReloadStructureForEntityEvent,
5454
} from '@umbraco-cms/backoffice/entity-action';
55-
import { UMB_DISCARD_CHANGES_MODAL, UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
55+
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
5656
import {
5757
UMB_VALIDATION_CONTEXT,
5858
UMB_VALIDATION_EMPTY_LOCALIZATION_KEY,
@@ -171,7 +171,6 @@ export class UmbDocumentWorkspaceContext
171171
constructor(host: UmbControllerHost) {
172172
super(host, UMB_DOCUMENT_WORKSPACE_ALIAS);
173173

174-
window.addEventListener('willchangestate', this.#onWillNavigate);
175174
this.addValidationContext(new UmbValidationContext(this));
176175

177176
new UmbVariantValuesValidationPathTranslator(this);
@@ -924,68 +923,11 @@ export class UmbDocumentWorkspaceContext
924923
return new UmbDocumentPropertyDatasetContext(host, this, variantId);
925924
}
926925

927-
#hasUnpersistedChanges() {
928-
const persisted = this.#persistedData.getValue();
929-
const current = this.#currentData.getValue();
930-
return jsonStringComparison(persisted, current) === false;
931-
}
932-
933-
#resetCurrentData() {
934-
this.#currentData.setValue(this.#persistedData.getValue());
935-
}
936-
937-
#willNavigateAway(newUrl: string) {
938-
let willNavigateAway = false;
939-
940-
if (this.getIsNew()) {
941-
const parent = this.#parent.getValue()!;
942-
const documentTypeUnique = this.#currentData.getValue()!.documentType.unique;
943-
944-
const createPath = UMB_CREATE_DOCUMENT_WORKSPACE_PATH_PATTERN.generateLocal({
945-
parentEntityType: parent.entityType as UmbDocumentEntityTypeUnion,
946-
parentUnique: parent.unique,
947-
documentTypeUnique,
948-
});
949-
willNavigateAway = !newUrl.includes(createPath);
950-
} else {
951-
const editPath = UMB_EDIT_DOCUMENT_WORKSPACE_PATH_PATTERN.generateLocal({
952-
unique: this.getUnique()!,
953-
});
954-
willNavigateAway = !newUrl.includes(editPath);
955-
}
956-
957-
return willNavigateAway;
958-
}
959-
960-
#onWillNavigate = async (e: CustomEvent) => {
961-
const newUrl = e.detail.url;
962-
963-
if (this.#willNavigateAway(newUrl) && this.#hasUnpersistedChanges()) {
964-
e.preventDefault();
965-
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
966-
const modal = modalManager.open(this, UMB_DISCARD_CHANGES_MODAL);
967-
968-
try {
969-
// navigate to the new url when discarding changes
970-
await modal.onSubmit();
971-
// Reset the current data so we don't end in a endless loop of asking to discard changes.
972-
this.#resetCurrentData();
973-
history.pushState({}, '', e.detail.url);
974-
return true;
975-
} catch {
976-
return false;
977-
}
978-
}
979-
980-
return true;
981-
};
982-
983926
public override destroy(): void {
984927
this.#persistedData.destroy();
985928
this.#currentData.destroy();
986929
this.structure.destroy();
987930
this.#languageRepository.destroy();
988-
window.removeEventListener('willchangestate', this.#onWillNavigate);
989931
super.destroy();
990932
}
991933
}

0 commit comments

Comments
 (0)