Skip to content

Commit 195966e

Browse files
committed
add local path checks
1 parent 88eca04 commit 195966e

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

src/packages/core/workspace/entity-detail/entity-detail-workspace-base.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,8 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
174174
* @memberof UmbEntityWorkspaceContextBase
175175
*/
176176
protected _checkWillNavigateAway(newUrl: string) {
177-
let willNavigateAway = false;
178-
179177
const workspacePathBase = UMB_WORKSPACE_PATH_PATTERN.generateLocal({ entityType: this.getEntityType() });
180-
181-
if (this.getIsNew()) {
182-
willNavigateAway = !newUrl.includes(`${workspacePathBase}/create`);
183-
} else {
184-
willNavigateAway = !newUrl.includes(`${workspacePathBase}/edit/${this.getUnique()}`);
185-
}
186-
187-
return willNavigateAway;
178+
return !newUrl.includes('/' + workspacePathBase);
188179
}
189180

190181
#onWillNavigate = async (e: CustomEvent) => {

src/packages/data-type/workspace/data-type-workspace.context.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
UmbInvariantWorkspacePropertyDatasetContext,
1313
UmbWorkspaceIsNewRedirectController,
1414
UmbEntityDetailWorkspaceContextBase,
15+
UMB_WORKSPACE_PATH_PATTERN,
1516
} from '@umbraco-cms/backoffice/workspace';
1617
import { appendToFrozenArray, UmbArrayState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
1718
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
@@ -92,7 +93,7 @@ export class UmbDataTypeWorkspaceContext
9293
setup: (_component, info) => {
9394
const parentEntityType = info.match.params.entityType;
9495
const parentUnique = info.match.params.parentUnique === 'null' ? null : info.match.params.parentUnique;
95-
this.create({ entityType: parentEntityType, unique: parentUnique });
96+
this.create({ parent: { entityType: parentEntityType, unique: parentUnique } });
9697

9798
new UmbWorkspaceIsNewRedirectController(
9899
this,
@@ -112,11 +113,21 @@ export class UmbDataTypeWorkspaceContext
112113
]);
113114
}
114115

116+
protected override _checkWillNavigateAway(newUrl: string): boolean {
117+
super._checkWillNavigateAway(newUrl);
118+
119+
const workspacePathBase = UMB_WORKSPACE_PATH_PATTERN.generateLocal({ entityType: this.getEntityType() });
120+
121+
if (this.getIsNew()) {
122+
return !newUrl.includes(`${workspacePathBase}/create`);
123+
} else {
124+
return !newUrl.includes(`${workspacePathBase}/edit/${this.getUnique()}`);
125+
}
126+
}
127+
115128
override async load(unique: string) {
116129
const response = await super.load(unique);
117-
118130
this.observe(response.asObservable?.(), (entity) => this.#onStoreChange(entity), 'umbDataTypeStoreObserver');
119-
120131
return response;
121132
}
122133

src/packages/language/workspace/language/language-workspace.context.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
UmbWorkspaceIsNewRedirectController,
99
type UmbRoutableWorkspaceContext,
1010
UmbEntityDetailWorkspaceContextBase,
11+
UMB_WORKSPACE_PATH_PATTERN,
1112
} from '@umbraco-cms/backoffice/workspace';
1213
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
1314

@@ -54,6 +55,18 @@ export class UmbLanguageWorkspaceContext
5455
]);
5556
}
5657

58+
protected override _checkWillNavigateAway(newUrl: string): boolean {
59+
super._checkWillNavigateAway(newUrl);
60+
61+
const workspacePathBase = UMB_WORKSPACE_PATH_PATTERN.generateLocal({ entityType: this.getEntityType() });
62+
63+
if (this.getIsNew()) {
64+
return !newUrl.includes(`${workspacePathBase}/create`);
65+
} else {
66+
return !newUrl.includes(`${workspacePathBase}/edit/${this.getUnique()}`);
67+
}
68+
}
69+
5770
setName(name: string) {
5871
this._data.updateCurrentData({ name });
5972
}

src/packages/user/user/workspace/user/user-workspace.context.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { UmbUserConfigRepository } from '../../repository/config/index.js';
77
import { UMB_USER_WORKSPACE_ALIAS } from './constants.js';
88
import { UmbUserWorkspaceEditorElement } from './user-workspace-editor.element.js';
99
import type { UmbSubmittableWorkspaceContext } from '@umbraco-cms/backoffice/workspace';
10-
import { UmbEntityDetailWorkspaceContextBase } from '@umbraco-cms/backoffice/workspace';
10+
import { UMB_WORKSPACE_PATH_PATTERN, UmbEntityDetailWorkspaceContextBase } from '@umbraco-cms/backoffice/workspace';
1111
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
1212
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
1313

@@ -52,6 +52,18 @@ export class UmbUserWorkspaceContext
5252
]);
5353
}
5454

55+
protected override _checkWillNavigateAway(newUrl: string): boolean {
56+
super._checkWillNavigateAway(newUrl);
57+
58+
const workspacePathBase = UMB_WORKSPACE_PATH_PATTERN.generateLocal({ entityType: this.getEntityType() });
59+
60+
if (this.getIsNew()) {
61+
return !newUrl.includes(`${workspacePathBase}/create`);
62+
} else {
63+
return !newUrl.includes(`${workspacePathBase}/edit/${this.getUnique()}`);
64+
}
65+
}
66+
5567
override async load(unique: string) {
5668
const response = await super.load(unique);
5769

0 commit comments

Comments
 (0)