From 4ee67f485dd1a349567172367bb9a430e81c028d Mon Sep 17 00:00:00 2001 From: Thomas Han Date: Wed, 12 Mar 2025 22:03:47 +1300 Subject: [PATCH 1/3] - fix issue with updates to tree node properties not triggering reordering of tree - fix spelling error in comment --- web/pgadmin/static/js/components/PgTree/FileTreeX/index.tsx | 3 +++ web/pgadmin/static/js/tree/ObjectExplorer.jsx | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/web/pgadmin/static/js/components/PgTree/FileTreeX/index.tsx b/web/pgadmin/static/js/components/PgTree/FileTreeX/index.tsx index 1599d0529c3..ea4126febd6 100644 --- a/web/pgadmin/static/js/components/PgTree/FileTreeX/index.tsx +++ b/web/pgadmin/static/js/components/PgTree/FileTreeX/index.tsx @@ -294,6 +294,9 @@ export class FileTreeX extends React.Component { private readonly update = async (item, itemData): Promise => { item._metadata.data = itemData; await this.props.update(item.path, itemData); + await this.changeResolvePath(item); + await this.remove(item); + await this.create(item.parent, itemData); this.events.dispatch(FileTreeXEvent.onTreeEvents, window.event, 'updated', item); }; diff --git a/web/pgadmin/static/js/tree/ObjectExplorer.jsx b/web/pgadmin/static/js/tree/ObjectExplorer.jsx index 7a1526b1ab0..cc93a18a865 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) { From d54854cbfc544359f493af112870134979057e22 Mon Sep 17 00:00:00 2001 From: Thomas Han Date: Wed, 14 May 2025 01:29:47 +1200 Subject: [PATCH 2/3] Fix issue with server groups not getting reordered on label update: - set RECREATE operation for server group updates - call remove -> create => and update tree methods on the updated server group node to force resort on server group siblings --- web/pgadmin/browser/static/js/browser.js | 18 +++++++++++++++++- .../js/components/PgTree/FileTreeX/index.tsx | 3 --- .../static/js/components/PgTree/types.ts | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) 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/FileTreeX/index.tsx b/web/pgadmin/static/js/components/PgTree/FileTreeX/index.tsx index ea4126febd6..1599d0529c3 100644 --- a/web/pgadmin/static/js/components/PgTree/FileTreeX/index.tsx +++ b/web/pgadmin/static/js/components/PgTree/FileTreeX/index.tsx @@ -294,9 +294,6 @@ export class FileTreeX extends React.Component { private readonly update = async (item, itemData): Promise => { item._metadata.data = itemData; await this.props.update(item.path, itemData); - await this.changeResolvePath(item); - await this.remove(item); - await this.create(item.parent, itemData); this.events.dispatch(FileTreeXEvent.onTreeEvents, window.event, 'updated', item); }; 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 From 853ebb7755b7507546daf61a855159a53d46398c Mon Sep 17 00:00:00 2001 From: Thomas Han Date: Wed, 14 May 2025 01:30:33 +1200 Subject: [PATCH 3/3] Fix issue with - fix issue with item.metadata.data not getting set if item.metadata was undefined - fix issue with incorrect check on node.type (if it is a file, it should return no children, but if it is a directory it should return the node children) --- web/pgadmin/static/js/tree/tree_nodes.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 []; }