MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / ManageTreeNodes

Class ManageTreeNodes

web/pgadmin/static/js/tree/tree_nodes.ts:20–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18import getApiInstance, { parseApiError } from '../api_instance';
19
20export class ManageTreeNodes {
21 constructor() {
22 this.tree = {};
23 this.tempTree = new TreeNode(undefined, {});
24 }
25
26 public init = (_root: string) => new Promise((res) => {
27 const node = {parent: null, children: [], data: null};
28 this.tree = {};
29 this.tree[_root] = {name: 'root', type: FileType.Directory, metadata: node};
30 res();
31 });
32
33 public updateNode = (_path, _data) => new Promise((res) => {
34 const item = this.findNode(_path);
35 if (item) {
36 item.data = {...item.data, ..._data};
37 item.name = _data.label;
38 item.metadata.data = _data;
39 }
40 res(true);
41 });
42
43 public removeNode = async (_path) => {
44 const item = this.findNode(_path);
45
46 if (item?.parentNode) {
47 item.children = [];
48 item.parentNode.children.splice(item.parentNode.children.indexOf(item), 1);
49 }
50 return true;
51 };
52
53 findNode(path) {
54 if (path === null || path === undefined || path.length === 0 || path == '/browser') {
55 return this.tempTree;
56 }
57 return findInTree(this.tempTree, path);
58 }
59
60 public addNode = (_parent: string, _path: string, _data: []) => new Promise((res) => {
61 _data.type = _data.inode ? FileType.Directory : FileType.File;
62 _data._label = _data.label;
63
64 _data.info_label = pgAdmin.Browser.Nodes[_data._type]?.getNodeInfoLabel(_data);
65
66 _data.label = _.escape(_data.label);
67
68 _data.is_collection = isCollectionNode(_data._type);
69 const nodeData = {parent: _parent, children: [], data: _data};
70
71 const tmpParentNode = this.findNode(_parent);
72 const treeNode = new TreeNode(_data.id, _data, {}, tmpParentNode, nodeData, _data.type);
73
74 if (tmpParentNode !== null && tmpParentNode !== undefined) tmpParentNode.children.push(treeNode);
75
76 res(treeNode);
77 });

Callers

nothing calls this directly

Calls 15

findNodeMethod · 0.95
parseApiErrorFunction · 0.90
isCollectionNodeFunction · 0.85
getApiInstanceFunction · 0.85
gettextFunction · 0.85
escapeMethod · 0.80
errorMethod · 0.80
generate_urlMethod · 0.80
addIconMethod · 0.80
confirmMethod · 0.80
toggleMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected