Skip to content

Commit 0909c37

Browse files
committed
don't hard code path checks
1 parent 72a6da8 commit 0909c37

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
4545
readonly parentUnique = this.#parent.asObservablePart((parent) => (parent ? parent.unique : undefined));
4646
readonly parentEntityType = this.#parent.asObservablePart((parent) => (parent ? parent.entityType : undefined));
4747

48+
#activePathSegment = '';
49+
4850
#initResolver?: () => void;
4951
#initialized = false;
5052

@@ -166,6 +168,14 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
166168
await this._detailRepository!.delete(unique);
167169
}
168170

171+
protected _setActivePathSegment(segment: string) {
172+
this.#activePathSegment = segment;
173+
}
174+
175+
protected _getActivePathSegment() {
176+
return this.#activePathSegment;
177+
}
178+
169179
/**
170180
* @description method to check if the workspace is about to navigate away.
171181
* @protected
@@ -174,8 +184,9 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
174184
* @memberof UmbEntityWorkspaceContextBase
175185
*/
176186
protected _checkWillNavigateAway(newUrl: string) {
177-
const workspacePathBase = UMB_WORKSPACE_PATH_PATTERN.generateLocal({ entityType: this.getEntityType() });
178-
return !newUrl.includes('/' + workspacePathBase);
187+
const workspaceBasePath = UMB_WORKSPACE_PATH_PATTERN.generateLocal({ entityType: this.getEntityType() });
188+
const currentWorkspacePathIdentifier = '/' + workspaceBasePath + '/' + this._getActivePathSegment();
189+
return !newUrl.includes(currentWorkspacePathIdentifier);
179190
}
180191

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

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export class UmbDataTypeWorkspaceContext
9090
path: 'create/parent/:entityType/:parentUnique',
9191
component: UmbDataTypeWorkspaceEditorElement,
9292
setup: (_component, info) => {
93+
this._setActivePathSegment(info.match.fragments.consumed);
9394
const parentEntityType = info.match.params.entityType;
9495
const parentUnique = info.match.params.parentUnique === 'null' ? null : info.match.params.parentUnique;
9596
this.create({ parent: { entityType: parentEntityType, unique: parentUnique } });
@@ -105,21 +106,14 @@ export class UmbDataTypeWorkspaceContext
105106
path: 'edit/:unique',
106107
component: UmbDataTypeWorkspaceEditorElement,
107108
setup: (_component, info) => {
109+
this._setActivePathSegment(info.match.fragments.consumed);
108110
const unique = info.match.params.unique;
109111
this.load(unique);
110112
},
111113
},
112114
]);
113115
}
114116

115-
protected override _checkWillNavigateAway(newUrl: string): boolean {
116-
if (this.getIsNew()) {
117-
return !newUrl.includes(`/create`) || super._checkWillNavigateAway(newUrl);
118-
} else {
119-
return !newUrl.includes(`/edit/${this.getUnique()}`) || super._checkWillNavigateAway(newUrl);
120-
}
121-
}
122-
123117
override async load(unique: string) {
124118
const response = await super.load(unique);
125119
this.observe(response.asObservable?.(), (entity) => this.#onStoreChange(entity), 'umbDataTypeStoreObserver');

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,14 @@ export class UmbUserWorkspaceContext
4848
path: 'edit/:id',
4949
component: UmbUserWorkspaceEditorElement,
5050
setup: (component, info) => {
51+
this._setActivePathSegment(info.match.fragments.consumed);
5152
const id = info.match.params.id;
5253
this.load(id);
5354
},
5455
},
5556
]);
5657
}
5758

58-
protected override _checkWillNavigateAway(newUrl: string): boolean {
59-
if (this.getIsNew()) {
60-
return !newUrl.includes(`/create`) || super._checkWillNavigateAway(newUrl);
61-
} else {
62-
return !newUrl.includes(`/edit/${this.getUnique()}`) || super._checkWillNavigateAway(newUrl);
63-
}
64-
}
65-
6659
override async load(unique: string) {
6760
const response = await super.load(unique);
6861

0 commit comments

Comments
 (0)