Skip to content

Commit 0ebf78c

Browse files
authored
Fixed an issue in the Search Objects tool where selecting a node occasionally selected an incorrect node. #8675
1 parent 60c8e5f commit 0ebf78c

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

web/pgadmin/browser/static/js/node.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,19 @@ define('pgadmin.browser.node', [
729729
_item.clear_cache.apply(_item);
730730
}, 0);
731731
}
732-
pgBrowser.Events.trigger('pgadmin:browser:tree:expand-from-previous-tree-state',
733-
item);
734732
pgBrowser.Node.callbacks.change_server_background(item, data);
733+
// Suppress added tree event being called during object search operations
734+
// where tree.select clashes due to previous tree state restore
735+
const suppressPath = pgBrowser.tree.suppressEventsForPath;
736+
if (suppressPath) {
737+
if (item.path === suppressPath) {
738+
pgBrowser.tree.suppressEventsForPath = null;
739+
} else {
740+
return;
741+
}
742+
}
743+
744+
pgBrowser.Events.trigger('pgadmin:browser:tree:expand-from-previous-tree-state', item);
735745
},
736746
// Callback called - when a node is selected in browser tree.
737747
selected: function(item, data) {
@@ -777,6 +787,16 @@ define('pgadmin.browser.node', [
777787
opened: function(item) {
778788
let tree = pgBrowser.tree,
779789
auto_expand = usePreferences.getState().getPreferences('browser', 'auto_expand_sole_children');
790+
// Suppress opened tree event being called during object search operations
791+
// where tree.select clashes due to only child of parent opens automatically.
792+
const suppressPath = pgBrowser.tree.suppressEventsForPath;
793+
if (suppressPath) {
794+
if (item.path === suppressPath) {
795+
pgBrowser.tree.suppressEventsForPath = null;
796+
} else {
797+
return;
798+
}
799+
}
780800

781801
if (auto_expand?.value && tree.children(item).length == 1) {
782802
// Automatically expand the child node, if a treeview node has only a single child.

web/pgadmin/static/js/components/PgTree/FileTreeItem/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,10 @@ export class FileTreeItem extends React.Component<IItemRendererXProps & IItemRen
130130
if (this.props.decorations) {
131131
this.props.decorations.addChangeListener(this.forceUpdate);
132132
}
133-
this.setActiveFile(this.props.item);
133+
this.setFileLoaded(this.props.item);
134134
}
135135

136-
private readonly setActiveFile = async (FileOrDir): Promise<void> => {
137-
136+
private readonly setFileLoaded = async (FileOrDir): Promise<void> => {
138137
this.props.changeDirectoryCount(FileOrDir.parent);
139138
if(FileOrDir._loaded !== true) {
140139
this.events.dispatch(FileTreeXEvent.onTreeEvents, window.event, 'added', FileOrDir);

web/pgadmin/static/js/tree/tree.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ export class Tree {
8484
this.rootNode = manageTree.tempTree;
8585
this.Nodes = pgBrowser ? pgBrowser.Nodes : pgAdmin.Browser.Nodes;
8686

87+
// Flag to suppress added and opened tree event being called during object search operations,
88+
// tree.select of search object clashes with other tree.select.
89+
this.suppressEventsForPath = null;
8790
this.draggableTypes = {};
8891
}
8992

web/pgadmin/tools/search_objects/static/js/SearchObjects.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ export default function SearchObjects({nodeData}) {
313313

314314
return false;
315315
}
316+
tree.suppressEventsForPath = '/browser/' + rowData.id_path.join('/');
316317
setLoaderText(gettext('Locating...'));
317318
tree.findNodeWithToggle(rowData.id_path)
318319
.then((treeItem)=>{

0 commit comments

Comments
 (0)