Skip to content

Commit 8bbe053

Browse files
authored
Close active modal if its begin unregistered (#18285)
1 parent 5379fec commit 8bbe053

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

src/Umbraco.Web.UI.Client/src/libs/observable-api/utils/partial-update-frozen-array.function.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/**
22
* @function partialUpdateFrozenArray
33
* @param {Observable<T>} source - RxJS Subject to use for this Observable.
4-
* @param data
5-
* @param partialEntry
6-
* @param findMethod
4+
* @param {T} data - Initial data for this Observable.
5+
* @param {Partial<T>} partialEntry - New data to be added in this Observable.
6+
* @param {(entry: T) => boolean} findMethod - Method to find the data to be updated.
77
* @param {(mappable: T) => R} mappingFunction - Method to return the part for this Observable to return.
88
* @param {(previousResult: R, currentResult: R) => boolean} [memoizationFunction] - Method to Compare if the data has changed. Should return true when data is different.
9+
* @returns {T[]} - New data set with the updated entry.
910
* @description - Creates a RxJS Observable from RxJS Subject.
1011
* @example <caption>Example append new entry for a ArrayState or a part of UmbDeepState/UmbObjectState it which is an array. Where the key is unique and the item will be updated if matched with existing.</caption>
1112
* const partialEntry = {value: 'myValue'};
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UmbContentTypeModel, UmbPropertyTypeContainerModel } from '../types.js';
1+
import type { UmbContentTypeModel } from '../types.js';
22
import type { UmbContentTypeStructureManager } from './content-type-structure-manager.class.js';
33
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
44
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
@@ -10,38 +10,37 @@ const MoveRootContainersIntoFirstTabHelperControllerAlias = Symbol('moveRootCont
1010
*/
1111
export class UmbContentTypeMoveRootGroupsIntoFirstTabHelper<T extends UmbContentTypeModel> extends UmbControllerBase {
1212
#structure?: UmbContentTypeStructureManager<T>;
13-
#tabContainers?: Array<UmbPropertyTypeContainerModel>;
1413

1514
constructor(host: UmbControllerHost, structure: UmbContentTypeStructureManager<T>) {
1615
super(host, MoveRootContainersIntoFirstTabHelperControllerAlias);
1716
this.#structure = structure;
1817
this.#observeContainers();
1918
}
2019

21-
#observeContainers() {
20+
async #observeContainers() {
2221
if (!this.#structure) return;
2322

24-
this.observe(
23+
await this.observe(
2524
this.#structure.ownerContainersOf('Tab', null),
2625
(tabContainers) => {
27-
const old = this.#tabContainers;
28-
this.#tabContainers = tabContainers;
29-
// If the amount of containers was 0 before and now becomes 1, we should move all root containers into this tab:
30-
if (old?.length === 0 && tabContainers?.length === 1) {
26+
// If the amount of containers now became 1, we should move all root containers into this tab:
27+
if (tabContainers?.length === 1) {
3128
const firstTabId = tabContainers[0].id;
3229
const rootContainers = this.#structure?.getOwnerContainers('Group', null);
3330
rootContainers?.forEach((groupContainer) => {
3431
this.#structure?.updateContainer(null, groupContainer.id, { parent: { id: firstTabId } });
3532
});
33+
this.destroy();
3634
}
3735
},
3836
'_observeMainContainer',
39-
);
37+
).asPromise();
38+
39+
this.destroy();
4040
}
4141

4242
override destroy() {
4343
super.destroy();
4444
this.#structure = undefined;
45-
this.#tabContainers = undefined;
4645
}
4746
}

src/Umbraco.Web.UI.Client/src/packages/core/content-type/structure/content-type-structure-manager.class.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ export class UmbContentTypeStructureManager<
317317
if (!contentType) {
318318
throw new Error('Could not find the Content Type to ensure containers for');
319319
}
320-
const containers = contentType?.containers;
321-
const container = containers?.find((x) => x.id === containerId);
320+
const container = contentType?.containers?.find((x) => x.id === containerId);
322321
if (!container) {
323322
return this.cloneContainerTo(containerId, contentTypeUnique);
324323
}
@@ -346,6 +345,7 @@ export class UmbContentTypeStructureManager<
346345
...container,
347346
id: UmbId.new(),
348347
};
348+
349349
if (container.parent) {
350350
// Investigate parent container. (See if we have one that matches if not, then clone it.)
351351
const parentContainer = await this.ensureContainerOf(container.parent.id, toContentTypeUnique);
@@ -361,6 +361,7 @@ export class UmbContentTypeStructureManager<
361361
const containers = [
362362
...(this.#contentTypes.getValue().find((x) => x.unique === toContentTypeUnique)?.containers ?? []),
363363
];
364+
364365
//.filter((x) => x.name !== clonedContainer.name && x.type === clonedContainer.type);
365366
containers.push(clonedContainer);
366367

@@ -541,7 +542,9 @@ export class UmbContentTypeStructureManager<
541542

542543
// If we have a container, we need to ensure it exists, and then update the container with the new parent id. [NL]
543544
if (property.container) {
545+
this.#contentTypes.mute();
544546
const container = await this.ensureContainerOf(property.container.id, contentTypeUnique);
547+
this.#contentTypes.unmute();
545548
if (!container) {
546549
throw new Error('Container for inserting property could not be found or created');
547550
}

src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-design-editor.element.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ export class UmbContentTypeDesignEditorElement extends UmbLitElement implements
140140
this.consumeContext(UMB_CONTENT_TYPE_WORKSPACE_CONTEXT, (workspaceContext) => {
141141
this.#workspaceContext = workspaceContext;
142142
this.#tabsStructureHelper.setStructureManager(workspaceContext.structure);
143-
new UmbContentTypeMoveRootGroupsIntoFirstTabHelper(this, workspaceContext.structure);
144143

145144
this.#observeRootGroups();
146145
});
@@ -281,11 +280,19 @@ export class UmbContentTypeDesignEditorElement extends UmbLitElement implements
281280
return;
282281
}
283282

283+
if (!this.#workspaceContext) {
284+
throw new Error('Workspace context has not been found');
285+
}
286+
284287
if (!this._tabs) return;
285288

286289
const len = this._tabs.length;
287290
const sortOrder = len === 0 ? 0 : this._tabs[len - 1].sortOrder + 1;
288-
const tab = await this.#workspaceContext?.structure.createContainer(null, null, 'Tab', sortOrder);
291+
const tab = await this.#workspaceContext.structure.createContainer(null, null, 'Tab', sortOrder);
292+
// If length was 0 before, then we need to move the root groups into the first tab: [NL]
293+
if (len === 0) {
294+
new UmbContentTypeMoveRootGroupsIntoFirstTabHelper(this, this.#workspaceContext.structure);
295+
}
289296
if (tab) {
290297
const path = this._routerPath + '/tab/' + encodeFolderName(tab.name && tab.name !== '' ? tab.name : '-');
291298
window.history.replaceState(null, '', path);

src/Umbraco.Web.UI.Client/src/packages/core/router/components/router-slot/route.context.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ export class UmbRouteContext extends UmbContextBase<UmbRouteContext> {
9191
const routesToRemove = this.#modalRoutes.filter(
9292
(route) => !this.#modalRegistrations.find((x) => x.key === route.__modalKey),
9393
);
94+
// If one the of the removed modals are active we should close it.
95+
routesToRemove.some((route) => {
96+
if (route.path === this.#activeModalPath) {
97+
this.#modalContext?.close(route.__modalKey);
98+
return true;
99+
}
100+
return false;
101+
});
94102

95103
const cleanedRoutes = this.#modalRoutes.filter((route) => !routesToRemove.includes(route));
96104

0 commit comments

Comments
 (0)