Skip to content

Commit bf74636

Browse files
authored
make getHasUnpersistedChanges public (#18929)
1 parent 1aff4c6 commit bf74636

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/Umbraco.Web.UI.Client/src/packages/block/block/workspace/block-element-manager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ export class UmbBlockElementManager<LayoutDataType extends UmbBlockLayoutBaseMod
119119
return this.#data.getCurrent();
120120
}
121121

122+
/**
123+
* Check if there are unpersisted changes.
124+
* @returns { boolean } true if there are unpersisted changes.
125+
*/
126+
public getHasUnpersistedChanges(): boolean {
127+
return this.#data.getHasUnpersistedChanges();
128+
}
129+
122130
getUnique() {
123131
return this.getData()?.key;
124132
}

src/Umbraco.Web.UI.Client/src/packages/block/block/workspace/block-workspace.context.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,14 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
424424
return 'block name content element type here...';
425425
}
426426

427+
/**
428+
* Check if there are unpersisted changes.
429+
* @returns { boolean } true if there are unpersisted changes.
430+
*/
431+
public getHasUnpersistedChanges(): boolean {
432+
return this.content.getHasUnpersistedChanges() || this.settings.getHasUnpersistedChanges();
433+
}
434+
427435
/**
428436
* @function propertyValueByAlias
429437
* @param {string} propertyAlias - The alias of the property to get the value of.

src/Umbraco.Web.UI.Client/src/packages/core/workspace/entity-detail/entity-detail-workspace-base.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { UmbExtensionApiInitializer } from '@umbraco-cms/backoffice/extension-api';
1515
import { umbExtensionsRegistry, type ManifestRepository } from '@umbraco-cms/backoffice/extension-registry';
1616
import type { UmbDetailRepository } from '@umbraco-cms/backoffice/repository';
17-
import { UmbStateManager } from '@umbraco-cms/backoffice/utils';
17+
import { UmbDeprecation, UmbStateManager } from '@umbraco-cms/backoffice/utils';
1818
import { UmbValidationContext } from '@umbraco-cms/backoffice/validation';
1919
import { UmbId } from '@umbraco-cms/backoffice/id';
2020

@@ -359,7 +359,7 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
359359
return true;
360360
}
361361

362-
if (this._checkWillNavigateAway(newUrl) && this._getHasUnpersistedChanges()) {
362+
if (this._checkWillNavigateAway(newUrl) && this.getHasUnpersistedChanges()) {
363363
/* Since ours modals are async while events are synchronous, we need to prevent the default behavior of the event, even if the modal hasn’t been resolved yet.
364364
Once the modal is resolved (the user accepted to discard the changes and navigate away from the route), we will push a new history state.
365365
This push will make the "willchangestate" event happen again and due to this somewhat "backward" behavior,
@@ -386,9 +386,18 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
386386
* Check if there are unpersisted changes.
387387
* @returns { boolean } true if there are unpersisted changes.
388388
*/
389-
protected _getHasUnpersistedChanges(): boolean {
389+
public getHasUnpersistedChanges(): boolean {
390390
return this._data.getHasUnpersistedChanges();
391391
}
392+
// @deprecated use getHasUnpersistedChanges instead, will be removed in v17.0
393+
protected _getHasUnpersistedChanges(): boolean {
394+
new UmbDeprecation({
395+
removeInVersion: '17',
396+
deprecated: '_getHasUnpersistedChanges',
397+
solution: 'use public getHasUnpersistedChanges instead.',
398+
}).warn();
399+
return this.getHasUnpersistedChanges();
400+
}
392401

393402
override resetState() {
394403
super.resetState();

0 commit comments

Comments
 (0)