Skip to content

Commit

Permalink
[BUGFIX] TreeNode creation and cleanup
Browse files Browse the repository at this point in the history
Correctly extend and show the children of the
parentnode when a node is added. Clean up
the parent node status when a node is removed
and no longer contains child nodes.

Resolves: #103226
Releases: main
Change-Id: I269380c322cad06902e87406732d8f708c8f9614
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83158
Tested-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: core-ci <typo3@b13.com>
  • Loading branch information
benjaminkott authored and bmack committed Feb 28, 2024
1 parent 3ecaa2a commit 8eab4ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions Build/Sources/TypeScript/backend/tree/tree.ts
Expand Up @@ -322,13 +322,13 @@ export class Tree extends LitElement {
}]).pop();

if (parentNode) {
if (target.hasChildren && !target.expanded) {
await this.showChildren(target);
if (parentNode.hasChildren && !parentNode.expanded) {
await this.showChildren(parentNode);
}

if (!target.hasChildren) {
target.hasChildren = true;
target.expanded = true;
if (!parentNode.hasChildren) {
parentNode.hasChildren = true;
parentNode.expanded = true;
}
}

Expand All @@ -342,9 +342,17 @@ export class Tree extends LitElement {

public async removeNode(node: TreeNodeInterface) {
const index = this.nodes.indexOf(node);
const parentNode = this.getParentNode(node);
if (index > -1) {
this.nodes.splice(index, 1);
}
this.requestUpdate();
this.updateComplete.then(() => {
if (parentNode.expanded && parentNode.hasChildren && this.getNodeChildren(parentNode).length === 0) {
parentNode.hasChildren = false;
parentNode.expanded = false;
}
});
}

public filter(searchTerm?: string|null): void {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8eab4ba

Please sign in to comment.