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

Method findNodeWithToggle

web/pgadmin/static/js/tree/tree.js:349–394  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

347 }
348
349 findNodeWithToggle(path) {
350 let tree = this;
351
352 if (path == null || !Array.isArray(path)) {
353 return Promise.reject(new Error(null));
354 }
355 const basepath = '/browser/' + path.slice(0, path.length-1).join('/') + '/';
356 path = '/browser/' + path.join('/');
357
358 let onCorrectPath = function (matchPath) {
359 return (matchPath !== undefined && path !== undefined
360 && (basepath.startsWith(`${matchPath}/`) || path === matchPath));
361 };
362
363 return (function findInNode(currentNode) {
364 return new Promise((resolve, reject) => {
365 if (path === null || path === undefined || path.length === 0) {
366 resolve(null);
367 }
368 /* No point in checking the children if
369 * the path for currentNode itself is not matching
370 */
371 if (currentNode.path !== undefined && !onCorrectPath(currentNode.path)) {
372 reject(new Error(null));
373 } else if (currentNode.path === path) {
374 resolve(currentNode);
375 } else {
376 tree.open(currentNode)
377 .then(() => {
378 let children = currentNode.children;
379 for (let i = 0, length = children.length; i < length; i++) {
380 let childNode = children[i];
381 if (onCorrectPath(childNode.path)) {
382 resolve(findInNode(childNode));
383 return;
384 }
385 }
386 reject(new Error(null));
387 })
388 .catch(() => {
389 reject(new Error(null));
390 });
391 }
392 });
393 })(tree.tree.getModel().root);
394 }
395
396 getNodeDisplayPath(item, separator='/', skip_coll=false) {
397 let retStack = [];

Callers 1

SearchObjectsFunction · 0.80

Calls 3

joinMethod · 0.80
getModelMethod · 0.65
openMethod · 0.45

Tested by

no test coverage detected