diff --git a/web/pgadmin/browser/static/js/browser.js b/web/pgadmin/browser/static/js/browser.js index f6f1d662620..c42caa0255f 100644 --- a/web/pgadmin/browser/static/js/browser.js +++ b/web/pgadmin/browser/static/js/browser.js @@ -783,8 +783,20 @@ define('pgadmin.browser', [ ) { let _parent = this.t.parent(this.i) || null; + // if the node is a server group + if (_item_parent.path === '/browser') { + let that = this; + // first remove the node from the tree + this.t.remove(this.i).then(() => { + // then add in the updated node with updated item data + this.t.tree.create(_parent, that.new).then((new_item) => { + // then we need to call update so that item.metadata is populated + this.t.update(new_item, that.new); + }); + }); + } // If there is no parent then just update the node - if(this.t.isRootNode(_parent) || + else if(this.t.isRootNode(_parent) || (_parent && _parent.length == 0 && ctx.op == 'UPDATE')) { //Update node if browser has single child node. if(this.t.children().length === 1) { @@ -1189,6 +1201,10 @@ define('pgadmin.browser', [ ) { ctx.op = 'RECREATE'; traversePath(); + // call RECREATE operation for server_groups so that the hierarchy is reordered on server group name update + } else if (_old._type == 'server_group' && _new._type == 'server_group') { + ctx.op = 'RECREATE'; + traversePath(); } else { ctx.op = 'UPDATE'; traversePath(); diff --git a/web/pgadmin/static/js/components/PgTree/types.ts b/web/pgadmin/static/js/components/PgTree/types.ts index 2ab494c9e3e..1e21fb9a04f 100644 --- a/web/pgadmin/static/js/components/PgTree/types.ts +++ b/web/pgadmin/static/js/components/PgTree/types.ts @@ -81,6 +81,7 @@ export interface IFileTreeXProps { * Amalgam of unix's `mkdir` and `touch` command */ create: (path: string, type: FileType) => IFileEntryItem | Promise + update: (path: string, data: {}) => IFileEntryItem | Promise onReady?: (handle: IFileTreeXHandle) => void onEvent?: (event: IFileTreeXTriggerEvents) => void onContextMenu?: (ev: React.MouseEvent, item?: FileOrDir) => void diff --git a/web/pgadmin/static/js/tree/ObjectExplorer.jsx b/web/pgadmin/static/js/tree/ObjectExplorer.jsx index a860fead1af..c640bb1ddef 100644 --- a/web/pgadmin/static/js/tree/ObjectExplorer.jsx +++ b/web/pgadmin/static/js/tree/ObjectExplorer.jsx @@ -118,7 +118,7 @@ export default function ObjectExplorer() { return mtree.readNode(path); }, sortComparator: (a, b) => { - // No nee to sort columns + // No need to sort columns if (a._metadata && a._metadata.data._type == 'column') return 0; // Sort alphabetically if (a.constructor === b.constructor) { diff --git a/web/pgadmin/static/js/tree/tree_nodes.ts b/web/pgadmin/static/js/tree/tree_nodes.ts index 7f12f0fac9d..96ba6f78c4b 100644 --- a/web/pgadmin/static/js/tree/tree_nodes.ts +++ b/web/pgadmin/static/js/tree/tree_nodes.ts @@ -36,7 +36,7 @@ export class ManageTreeNodes { if (item) { item.data = {...item.data, ..._data}; item.name = _data.label; - item.metadata.data = _data; + item.metadata = { data: _data, ...item.metadata }; } res(true); }); @@ -81,7 +81,7 @@ export class ManageTreeNodes { const api = getApiInstance(); if (node && node.children.length > 0) { - if (node.type !== FileType.File) { + if (node.type === FileType.File) { console.error(node, 'It\'s a leaf node'); return []; }