From 441f2eaf35fadbd87cc1a3232eee7593ad97ac8e Mon Sep 17 00:00:00 2001 From: Cheena Malhotra <13396919+cheenamalhotra@users.noreply.github.com> Date: Mon, 31 Jul 2023 20:07:21 -0700 Subject: [PATCH] Add null checks for server tree view (#24038) (#24039) --- .../browser/asyncServerTreeRenderer.ts | 61 ++++++++++++------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/src/sql/workbench/services/objectExplorer/browser/asyncServerTreeRenderer.ts b/src/sql/workbench/services/objectExplorer/browser/asyncServerTreeRenderer.ts index 5b7c321643..6dae311def 100644 --- a/src/sql/workbench/services/objectExplorer/browser/asyncServerTreeRenderer.ts +++ b/src/sql/workbench/services/objectExplorer/browser/asyncServerTreeRenderer.ts @@ -70,12 +70,17 @@ class ConnectionProfileGroupTemplate extends Disposable { matches: createMatches(filterData) }); - const actionProvider = this._objectExplorerService.getServerTreeView().treeActionProvider; - const tree = this._objectExplorerService.getServerTreeView().tree; - const actions = actionProvider.getActions(tree, element, true); - this._actionBar.context = this._objectExplorerService.getServerTreeView().getActionContext(element); - this._actionBar.clear(); - this._actionBar.pushAction(actions, { icon: true, label: false }); + let serverTreeView = this._objectExplorerService.getServerTreeView(); + if (serverTreeView) { + const actionProvider = serverTreeView.treeActionProvider; + const tree = serverTreeView.tree; + const actions = actionProvider.getActions(tree, element, true); + this._actionBar.context = serverTreeView.getActionContext(element); + this._actionBar.clear(); + this._actionBar.pushAction(actions, { icon: true, label: false }); + } else { + console.log('Server Tree view not loaded, action bar will not be populated.'); + } } } @@ -150,18 +155,23 @@ class ConnectionProfileTemplate extends Disposable { matches: createMatches(filterData) }); this._root.title = treeNode?.filters?.length > 0 ? getLabelWithFilteredSuffix(element.serverInfo) : element.serverInfo; - const actionProvider = this._objectExplorerService.getServerTreeView().treeActionProvider; - if (!this._isCompact) { - const tree = this._objectExplorerService.getServerTreeView().tree; - const actions = actionProvider.getActions(tree, element, true); - this._actionBar.context = this._objectExplorerService.getServerTreeView().getActionContext(element); - this._actionBar.clear(); - this._actionBar.pushAction(actions, { icon: true, label: false }); + let serverTreeView = this._objectExplorerService.getServerTreeView(); + if (serverTreeView) { + const actionProvider = serverTreeView.treeActionProvider; + if (!this._isCompact) { + const tree = serverTreeView.tree; + const actions = actionProvider.getActions(tree, element, true); + this._actionBar.context = serverTreeView.getActionContext(element); + this._actionBar.clear(); + this._actionBar.pushAction(actions, { icon: true, label: false }); + } else { + const actions = actionProvider.getRecentConnectionActions(element); + this._actionBar.context = undefined; + this._actionBar.clear(); + this._actionBar.pushAction(actions, { icon: true, label: false }); + } } else { - const actions = actionProvider.getRecentConnectionActions(element); - this._actionBar.context = undefined; - this._actionBar.clear(); - this._actionBar.pushAction(actions, { icon: true, label: false }); + console.log('Server Tree view not loaded, action bar will not be populated.'); } } } @@ -247,12 +257,17 @@ class TreeNodeTemplate extends Disposable { matches: createMatches(filterData) }); this._root.title = labelText; - const tree = this._objectExplorerService.getServerTreeView().tree; - const actionProvider = this._objectExplorerService.getServerTreeView().treeActionProvider; - const actions = actionProvider.getActions(tree, element, true); - this._actionBar.context = this._objectExplorerService.getServerTreeView().getActionContext(element); - this._actionBar.clear(); - this._actionBar.pushAction(actions, { icon: true, label: false }); + let serverTreeView = this._objectExplorerService.getServerTreeView(); + if (serverTreeView) { + const tree = serverTreeView.tree; + const actionProvider = serverTreeView.treeActionProvider; + const actions = actionProvider.getActions(tree, element, true); + this._actionBar.context = serverTreeView.getActionContext(element); + this._actionBar.clear(); + this._actionBar.pushAction(actions, { icon: true, label: false }); + } else { + console.log('Server Tree view not loaded, action bar will not be populated.'); + } } }