diff --git a/public/app/features/scopes/selector/ScopesSelectorService.ts b/public/app/features/scopes/selector/ScopesSelectorService.ts index 9dea729ff88..ede86a50135 100644 --- a/public/app/features/scopes/selector/ScopesSelectorService.ts +++ b/public/app/features/scopes/selector/ScopesSelectorService.ts @@ -46,7 +46,7 @@ export interface ScopesSelectorServiceState { // Simple tree structure for the scopes categories. Each node in a tree has a scopeNodeId which keys the nodes cache // map. - tree: TreeNode | undefined; + tree: TreeNode; } export class ScopesSelectorService extends ScopesServiceBase { @@ -116,9 +116,6 @@ export class ScopesSelectorService extends ScopesServiceBase => { - if (!tree) { - throw new Error('Tree is required'); - } const nodePath = await this.getNodePath(scopeNodeId); const newTree = insertPathNodesIntoTree(tree, nodePath); @@ -133,7 +130,7 @@ export class ScopesSelectorService extends ScopesServiceBase { + const newTree = modifyTreeNodeAtPath(this.state.tree, path, (treeNode) => { treeNode.expanded = !nodeToToggle.expanded; treeNode.query = ''; }); @@ -152,7 +149,7 @@ export class ScopesSelectorService extends ScopesServiceBase { + const newTree = modifyTreeNodeAtPath(this.state.tree, path, (treeNode) => { treeNode.expanded = true; treeNode.query = query; }); @@ -209,7 +206,7 @@ export class ScopesSelectorService extends ScopesServiceBase { + const newTree = modifyTreeNodeAtPath(this.state.tree, path, (treeNode) => { // Set parent query only when filtering within existing children treeNode.children = {}; for (const node of childNodes) { @@ -455,12 +452,12 @@ export class ScopesSelectorService extends ScopesServiceBase { - if (!this.state.tree?.children || Object.keys(this.state.tree?.children).length === 0) { + if (!this.state.tree.children || Object.keys(this.state.tree.children).length === 0) { await this.filterNode('', ''); } // First close all nodes - let newTree = closeNodes(this.state.tree!); + let newTree = closeNodes(this.state.tree); if (this.state.selectedScopes.length && this.state.selectedScopes[0].parentNodeId) { let path = getPathOfNode(this.state.selectedScopes[0].parentNodeId, this.state.nodes);