Fix an issue where object explorer tree crashes occasionally. #5306

This commit is contained in:
Aditya Toshniwal 2023-06-21 11:05:58 +05:30 committed by GitHub
parent 878c14dec0
commit 466e969776
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 95 deletions

View File

@ -122,17 +122,11 @@ define('pgadmin.node.compound_trigger', [
t.removeIcon(i);
data.icon = 'icon-compound_trigger';
t.addIcon(i, {icon: data.icon});
t.unload(i);
t.setInode(false);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
t.updateAndReselectNode(i, data);
}
}).catch(function(error) {
Notify.pgRespErrorNotify(error);
t.unload(i);
t.refresh(i);
});
},
/* Disable compound trigger */
@ -156,17 +150,11 @@ define('pgadmin.node.compound_trigger', [
t.removeIcon(i);
data.icon = 'icon-compound_trigger-bad';
t.addIcon(i, {icon: data.icon});
t.unload(i);
t.setInode(false);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
t.updateAndReselectNode(i, data);
}
}).catch(function(error) {
Notify.pgRespErrorNotify(error);
t.unload(i);
t.refresh(i);
});
},
},

View File

@ -133,13 +133,7 @@ function(
t.removeIcon(i);
data.icon = 'icon-partition';
t.addIcon(i, {icon: data.icon});
t.unload(i);
t.setInode(i);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
t.updateAndReselectNode(i, data);
}
},
canDrop: SchemaChildTreeNode.isTreeItemOfChildOfSchema,
@ -171,17 +165,12 @@ function(
.then(({data: res})=>{
if (res.success == 1) {
Notify.success(res.info);
t.unload(i);
t.setInode(i);
t.deselect(i);
setTimeout(function() {
t.select(i);
}, 10);
t.updateAndReselectNode(i, d);
}
})
.catch((error)=>{
Notify.pgRespErrorNotify(error);
t.unload(i);
t.refresh(i);
});
},
/* Truncate table */

View File

@ -141,16 +141,11 @@ define('pgadmin.node.rule', [
t.removeIcon(i);
data.icon = 'icon-rule';
t.addIcon(i, {icon: data.icon});
t.unload(i);
t.setInode(false);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
t.updateAndReselectNode(i, data);
})
.catch((error)=>{
Notify.pgRespErrorNotify(error);
t.refresh(i);
});
},
/* Disable rule */
@ -171,16 +166,11 @@ define('pgadmin.node.rule', [
t.removeIcon(i);
data.icon = 'icon-rule-bad';
t.addIcon(i, {icon: data.icon});
t.unload(i);
t.setInode(false);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
t.updateAndReselectNode(i, data);
})
.catch((error)=>{
Notify.pgRespErrorNotify(error);
t.refresh(i);
});
},
},

View File

@ -195,13 +195,7 @@ define('pgadmin.node.table', [
t.removeIcon(i);
data.icon = data.is_partitioned ? 'icon-partition': 'icon-table';
t.addIcon(i, {icon: data.icon});
t.unload(i);
t.setInode(i);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
t.updateAndReselectNode(i, data);
}
if (res.success == 2) {
Notify.error(res.info);
@ -209,7 +203,7 @@ define('pgadmin.node.table', [
})
.catch((error)=>{
Notify.pgRespErrorNotify(error);
t.unload(i);
t.refresh(i);
});
}, function() {/*This is intentional (SonarQube)*/}
);
@ -236,18 +230,12 @@ define('pgadmin.node.table', [
t.removeIcon(i);
data.icon = data.is_partitioned ? 'icon-partition': 'icon-table';
t.addIcon(i, {icon: data.icon});
t.unload(i);
t.setInode(i);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
t.updateAndReselectNode(i, d);
}
})
.catch((error)=>{
Notify.pgRespErrorNotify(error);
t.unload(i);
t.refresh(i);
});
},
function() {/*This is intentional (SonarQube)*/}
@ -271,16 +259,11 @@ define('pgadmin.node.table', [
.then(({data: res})=>{
Notify.success(res.info, null);
d.rows_cnt = res.data.total_rows;
t.unload(i);
t.setInode(i);
t.deselect(i);
setTimeout(function() {
t.select(i);
}, 10);
t.updateAndReselectNode(i, d);
})
.catch((error)=>{
Notify.pgRespErrorNotify(error);
t.unload(i);
t.refresh(i);
});
},
/* Generate the ERD */

View File

@ -115,20 +115,14 @@ define('pgadmin.node.trigger', [
Notify.success(res.info);
t.removeIcon(i);
data.icon = 'icon-trigger';
data.has_enable_triggers = res.data.has_enable_triggers;
t.addIcon(i, {icon: data.icon});
t.unload(i);
t.setInode(false);
t.deselect(i);
i.parent.parent._metadata.data.has_enable_triggers = res.data.has_enable_triggers;
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
t.updateAndReselectNode(i, data);
}
})
.catch((error)=>{
Notify.pgRespErrorNotify(error);
t.unload(i);
t.refresh(i);
});
},
/* Disable trigger */
@ -149,20 +143,14 @@ define('pgadmin.node.trigger', [
Notify.success(res.info);
t.removeIcon(i);
data.icon = 'icon-trigger-bad';
data.has_enable_triggers = res.data.has_enable_triggers;
t.addIcon(i, {icon: data.icon});
t.unload(i);
t.setInode(false);
t.deselect(i);
i.parent.parent._metadata.data.has_enable_triggers = res.data.has_enable_triggers;
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
t.updateAndReselectNode(i, data);
}
})
.catch((error)=>{
Notify.pgRespErrorNotify(error);
t.unload(i);
t.refresh(i);
});
},
},

View File

@ -197,10 +197,9 @@ define('pgadmin.node.database', [
},
function() {
d.is_connecting = false;
t.unload(i);
t.setInode(i);
let dbIcon = d.isTemplate ? 'icon-database-template-not-connected':'icon-database-not-connected';
t.addIcon(i, {icon: dbIcon});
t.updateAndReselectNode(i, d);
pgBrowser.Events.trigger(
'pgadmin:database:connect:cancelled', i, d, self
);
@ -473,11 +472,10 @@ define('pgadmin.node.database', [
onCancel = function(_tree, _item, _data) {
_data.is_connecting = false;
let server = _tree.parent(_item);
_tree.unload(_item);
_tree.setInode(_item);
_tree.removeIcon(_item);
let dbIcon = data.isTemplate ? 'icon-database-template-not-connected':'icon-database-not-connected';
_tree.addIcon(_item, {icon: dbIcon});
_tree.updateAndReselectNode(_item, _data);
obj.trigger('connect:cancelled', obj, _item, _data);
pgBrowser.Events.trigger(
'pgadmin:database:connect:cancelled', _item, _data, obj

View File

@ -551,7 +551,6 @@ define('pgadmin.node.server', [
function() {
d.is_connecting = false;
t.unload(i);
t.setInode(i);
t.addIcon(i, {icon: 'icon-database-not-connected'});
pgBrowser.Events.trigger(
'pgadmin:server:connect:cancelled', i, d, self
@ -588,13 +587,11 @@ define('pgadmin.node.server', [
);
data.is_connecting = false;
tree.unload(item);
tree.setInode(item);
tree.addIcon(item, {icon: 'icon-shared-server-not-connected'});
Notify.info('Please enter the server details to connect to the server. This server is a shared server.');
} else {
data.is_connecting = false;
tree.unload(item);
tree.setInode(item);
tree.addIcon(item, {icon: 'icon-shared-server-not-connected'});
}
}
@ -707,7 +704,6 @@ define('pgadmin.node.server', [
let onCancel = function(_tree, _item, _data, _status) {
_data.is_connecting = false;
_tree.unload(_item);
_tree.setInode(_item);
_tree.removeIcon(_item);
if (_data.shared && pgAdmin.server_mode == 'True'){
_tree.addIcon(_item, {icon: 'icon-shared-server-not-connected'});

View File

@ -223,8 +223,8 @@ export class Tree {
}
}
deselect(item) {
this.tree.deSelectActiveFile(item);
async deselect(item) {
await this.tree.deSelectActiveFile(item);
}
wasInit() {
@ -455,6 +455,12 @@ export class Tree {
return node;
}
async updateAndReselectNode(item, data) {
await this.update(item, data);
await this.deselect(item);
await this.select(item);
}
translateTreeNodeIdFromReactTree(treeNode) {
let currentTreeNode = treeNode;
let path = [];