Skip to content

Commit ad03dfa

Browse files
authored
Optimistically update the UI when user selects db/list (#2063)
1 parent 682a1e1 commit ad03dfa

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

extensions/ql-vscode/src/databases/ui/db-panel.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ export class DbPanel extends DisposableObject {
254254
"Not a selectable database item. Please select a valid item.",
255255
);
256256
}
257+
258+
// Optimistically update the UI to select the item that the user
259+
// selected to avoid delay in the UI.
260+
this.dataProvider.updateSelectedItem(treeViewItem);
261+
257262
await this.dbManager.setSelectedDbItem(treeViewItem.dbItem);
258263
}
259264

extensions/ql-vscode/src/databases/ui/db-tree-data-provider.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ export class DbTreeDataProvider
4848
});
4949
}
5050

51+
/**
52+
* Updates the selected item and re-renders the tree.
53+
* @param selectedItem The item to select.
54+
*/
55+
public updateSelectedItem(selectedItem: DbTreeViewItem): void {
56+
// Unselect all items
57+
for (const item of this.dbTreeItems) {
58+
item.setAsUnselected();
59+
}
60+
61+
// Select the new item
62+
selectedItem.setAsSelected();
63+
64+
// Re-render the tree
65+
this._onDidChangeTreeData.fire(undefined);
66+
}
67+
5168
/**
5269
* Called when expanding a node (including the root node).
5370
* @param node The node to expand.

extensions/ql-vscode/src/databases/ui/db-tree-view-item.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,19 @@ export class DbTreeViewItem extends vscode.TreeItem {
3636
if (dbItem) {
3737
this.contextValue = getContextValue(dbItem);
3838
if (isSelectableDbItem(dbItem) && dbItem.selected) {
39-
// Define the resource id to drive the UI to render this item as selected.
40-
this.resourceUri = vscode.Uri.parse(SELECTED_DB_ITEM_RESOURCE_URI);
39+
this.setAsSelected();
4140
}
4241
}
4342
}
43+
44+
public setAsSelected(): void {
45+
// Define the resource id to drive the UI to render this item as selected.
46+
this.resourceUri = vscode.Uri.parse(SELECTED_DB_ITEM_RESOURCE_URI);
47+
}
48+
49+
public setAsUnselected(): void {
50+
this.resourceUri = undefined;
51+
}
4452
}
4553

4654
function getContextValue(dbItem: DbItem): string | undefined {

0 commit comments

Comments
 (0)