From 7d8fe0bac90eec666c84f77a334c0f2e583bd8c5 Mon Sep 17 00:00:00 2001 From: Stepan Kiryakov Date: Mon, 30 Dec 2024 21:19:51 +0400 Subject: [PATCH] fix Signed-off-by: Stepan Kiryakov --- .../components/label-config.ts | 8 ++++++ .../components/nav-item.ts | 25 +++++++++++++++++++ .../policy-label-configuration.component.html | 13 +++++++--- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/modules/statistics/policy-labels/policy-label-configuration/components/label-config.ts b/frontend/src/app/modules/statistics/policy-labels/policy-label-configuration/components/label-config.ts index 2633dc54e0..084003ffde 100644 --- a/frontend/src/app/modules/statistics/policy-labels/policy-label-configuration/components/label-config.ts +++ b/frontend/src/app/modules/statistics/policy-labels/policy-label-configuration/components/label-config.ts @@ -50,6 +50,7 @@ export class LabelConfig { this.menu = NavMenu.from(item); this.navigationTree = NavTree.from(item); this.navigationTree.update(); + this.updateSelected(); } public setPolicy(relationships: any) { @@ -119,6 +120,13 @@ export class LabelConfig { this.selectedNavItem = node; } + public updateSelected() { + if (this.selectedNavItem) { + const key = this.selectedNavItem.key; + this.selectedNavItem = this.navigationTree.getItem(key); + } + } + public ifNavSelected(node: NavItem) { if (this.selectedNavItem) { return this.selectedNavItem.key === node.key; diff --git a/frontend/src/app/modules/statistics/policy-labels/policy-label-configuration/components/nav-item.ts b/frontend/src/app/modules/statistics/policy-labels/policy-label-configuration/components/nav-item.ts index 843d6df7fb..8f77c6c25b 100644 --- a/frontend/src/app/modules/statistics/policy-labels/policy-label-configuration/components/nav-item.ts +++ b/frontend/src/app/modules/statistics/policy-labels/policy-label-configuration/components/nav-item.ts @@ -303,6 +303,21 @@ export class NavItem implements TreeNode { } return null; } + + public getItem(key: string): NavItem | null { + if (this.key === key) { + return this; + } + if (Array.isArray(this.children)) { + for (const node of this.children) { + const result = node.getItem(key); + if (result) { + return result; + } + } + } + return null; + } } export class NavTree { @@ -323,6 +338,16 @@ export class NavTree { this._deleteNode(this.data, node); } + public getItem(key: string): NavItem | null { + for (const node of this.data) { + const result = node.getItem(key); + if (result) { + return result; + } + } + return null; + } + private _deleteNode(nodes: NavItem[] | undefined, node: NavItem): void { if (!Array.isArray(nodes)) { return; diff --git a/frontend/src/app/modules/statistics/policy-labels/policy-label-configuration/policy-label-configuration.component.html b/frontend/src/app/modules/statistics/policy-labels/policy-label-configuration/policy-label-configuration.component.html index bdccbe2d49..b3a20a92b0 100644 --- a/frontend/src/app/modules/statistics/policy-labels/policy-label-configuration/policy-label-configuration.component.html +++ b/frontend/src/app/modules/statistics/policy-labels/policy-label-configuration/policy-label-configuration.component.html @@ -229,7 +229,8 @@