Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -119,6 +119,14 @@ export class UmbBlockElementManager<LayoutDataType extends UmbBlockLayoutBaseMod
return this.#data.getCurrent();
}

/**
* Check if there are unpersisted changes.
* @returns { boolean } true if there are unpersisted changes.
*/
public getHasUnpersistedChanges(): boolean {
return this.#data.getHasUnpersistedChanges();
}

getUnique() {
return this.getData()?.key;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UmbBlockDataModel, UmbBlockLayoutBaseModel } from '../types.js';

Check notice on line 1 in src/Umbraco.Web.UI.Client/src/packages/block/block/workspace/block-workspace.context.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v15/dev)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 5.10 to 4.95, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
import { UmbBlockWorkspaceEditorElement } from './block-workspace-editor.element.js';
import { UmbBlockElementManager } from './block-element-manager.js';
import {
Expand Down Expand Up @@ -424,6 +424,14 @@
return 'block name content element type here...';
}

/**
* Check if there are unpersisted changes.
* @returns { boolean } true if there are unpersisted changes.
*/
public getHasUnpersistedChanges(): boolean {
return this.content.getHasUnpersistedChanges() || this.settings.getHasUnpersistedChanges();
}

/**
* @function propertyValueByAlias
* @param {string} propertyAlias - The alias of the property to get the value of.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { UmbExtensionApiInitializer } from '@umbraco-cms/backoffice/extension-api';
import { umbExtensionsRegistry, type ManifestRepository } from '@umbraco-cms/backoffice/extension-registry';
import type { UmbDetailRepository } from '@umbraco-cms/backoffice/repository';
import { UmbStateManager } from '@umbraco-cms/backoffice/utils';
import { UmbDeprecation, UmbStateManager } from '@umbraco-cms/backoffice/utils';
import { UmbValidationContext } from '@umbraco-cms/backoffice/validation';
import { UmbId } from '@umbraco-cms/backoffice/id';

Expand Down Expand Up @@ -366,7 +366,7 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
return true;
}

if (this._checkWillNavigateAway(newUrl) && this._getHasUnpersistedChanges()) {
if (this._checkWillNavigateAway(newUrl) && this.getHasUnpersistedChanges()) {
/* 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.
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.
This push will make the "willchangestate" event happen again and due to this somewhat "backward" behavior,
Expand All @@ -393,9 +393,18 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
* Check if there are unpersisted changes.
* @returns { boolean } true if there are unpersisted changes.
*/
protected _getHasUnpersistedChanges(): boolean {
public getHasUnpersistedChanges(): boolean {
return this._data.getHasUnpersistedChanges();
}
// @deprecated use getHasUnpersistedChanges instead, will be removed in v17.0
protected _getHasUnpersistedChanges(): boolean {
new UmbDeprecation({
removeInVersion: '17',
deprecated: '_getHasUnpersistedChanges',
solution: 'use public getHasUnpersistedChanges instead.',
}).warn();
return this.getHasUnpersistedChanges();
}

override resetState() {
super.resetState();
Expand Down