correct name of existing empty containers + do not collide with the container of interrest
This commit is contained in:
@@ -295,9 +295,18 @@ export class UmbContentTypeStructureManager<
|
||||
sortOrder: sortOrder ?? 0,
|
||||
};
|
||||
|
||||
const containers = [
|
||||
...(this.#contentTypes.getValue().find((x) => x.unique === contentTypeUnique)?.containers ?? []),
|
||||
];
|
||||
this.getOwnerContainers(type, parentId)?.forEach((container) => {
|
||||
if (container.name === '') {
|
||||
const newName = 'unnamed';
|
||||
this.updateContainer(contentTypeUnique, container.id, {
|
||||
name: this.makeContainerNameUniqueForOwnerContentType(container.id, newName, type, parentId) ?? newName,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const contentTypes = this.#contentTypes.getValue();
|
||||
const containers = [...(contentTypes.find((x) => x.unique === contentTypeUnique)?.containers ?? [])];
|
||||
containers.push(container);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
@@ -333,21 +342,22 @@ export class UmbContentTypeStructureManager<
|
||||
}*/
|
||||
|
||||
makeContainerNameUniqueForOwnerContentType(
|
||||
containerId: string,
|
||||
newName: string,
|
||||
containerType: UmbPropertyContainerTypes = 'Tab',
|
||||
containerType: UmbPropertyContainerTypes,
|
||||
parentId: string | null = null,
|
||||
) {
|
||||
const ownerRootContainers = this.getOwnerContainers(containerType, parentId); //getRootContainers() can't differentiates between compositions and locals
|
||||
if (!ownerRootContainers) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let changedName = newName;
|
||||
if (ownerRootContainers) {
|
||||
while (ownerRootContainers.find((tab) => tab.name === changedName && tab.id !== parentId)) {
|
||||
changedName = incrementString(changedName);
|
||||
}
|
||||
|
||||
return changedName === newName ? null : changedName;
|
||||
while (ownerRootContainers.find((con) => con.name === changedName && con.id !== containerId)) {
|
||||
changedName = incrementString(changedName);
|
||||
}
|
||||
return null;
|
||||
|
||||
return changedName === newName ? null : changedName;
|
||||
}
|
||||
|
||||
async updateContainer(
|
||||
|
||||
@@ -92,11 +92,12 @@ export class UmbContentTypeWorkspaceViewEditGroupElement extends UmbLitElement {
|
||||
let newName = (e.target as HTMLInputElement).value;
|
||||
const changedName = this.groupStructureHelper
|
||||
.getStructureManager()!
|
||||
.makeContainerNameUniqueForOwnerContentType(newName, 'Group', this._group.parent?.id ?? null);
|
||||
.makeContainerNameUniqueForOwnerContentType(this._group.id, newName, 'Group', this._group.parent?.id ?? null);
|
||||
if (changedName) {
|
||||
newName = changedName;
|
||||
}
|
||||
this._singleValueUpdate('name', newName);
|
||||
(e.target as HTMLInputElement).value = newName;
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -118,7 +119,7 @@ export class UmbContentTypeWorkspaceViewEditGroupElement extends UmbLitElement {
|
||||
<uui-input
|
||||
label=${this.localize.term('contentTypeEditor_group')}
|
||||
placeholder=${this.localize.term('placeholders_entername')}
|
||||
.value=${this.group!.name}
|
||||
.value=${this._group.name}
|
||||
?disabled=${!this._hasOwnerContainer}
|
||||
@change=${this.#renameGroup}></uui-input>
|
||||
</div>
|
||||
|
||||
@@ -292,9 +292,9 @@ export class UmbContentTypeDesignEditorElement extends UmbLitElement implements
|
||||
let newName = (event.target as HTMLInputElement).value;
|
||||
|
||||
const changedName = this.#workspaceContext?.structure.makeContainerNameUniqueForOwnerContentType(
|
||||
tab.id,
|
||||
newName,
|
||||
'Tab',
|
||||
tab.id,
|
||||
);
|
||||
|
||||
// Check if it collides with another tab name of this same content-type, if so adjust name:
|
||||
|
||||
Reference in New Issue
Block a user