Refactored the dashboard code, which was allowing each node type to

define its own dashboardURL.

There was a typo, while calling the dashboard function of a Node type.
This commit is contained in:
Ashesh Vashi
2018-07-25 12:10:46 +05:30
parent f7e43d5e50
commit e12e00703f
4 changed files with 67 additions and 31 deletions

View File

@@ -0,0 +1,30 @@
import {isString, isFunction} from 'sources/utils';
import pgBrowser from 'pgadmin.browser';
export function url(itemData, item, treeHierarchy) {
let treeNode = pgBrowser.treeMenu.findNodeByDomElement(item);
let url = null;
let getDashboardURL = (node) => {
let nodeData = node.getData();
let browserNode = pgBrowser.Nodes[nodeData._type];
let dashboardURL = browserNode && browserNode.dashboard;
if (isFunction(dashboardURL)) {
dashboardURL = dashboardURL.apply(
browserNode, [node, nodeData, treeHierarchy]
);
}
url = isString(dashboardURL) ? dashboardURL : null;
return (url !== null);
};
if (treeNode) {
if (getDashboardURL(treeNode) === false)
treeNode.anyFamilyMember(getDashboardURL);
}
return url;
}

View File

@@ -7,6 +7,8 @@
//
//////////////////////////////////////////////////////////////////////////
import {isValidData} from 'sources/utils';
export class TreeNode {
constructor(id, data, domNode, parent) {
this.id = id;
@@ -217,6 +219,6 @@ function findInTree(rootNode, path) {
})(rootNode);
}
export function isValidTreeNodeData(treeNodeData) {
return !_.isUndefined(treeNodeData) && !_.isNull(treeNodeData);
}
let isValidTreeNodeData = isValidData;
export {isValidTreeNodeData};

View File

@@ -7,6 +7,8 @@
//
//////////////////////////////////////////////////////////////////////////
import _ from 'underscore';
export function parseShortcutValue(obj) {
var shortcut = '';
if (obj.alt) { shortcut += 'alt+'; }
@@ -36,3 +38,11 @@ export function findAndSetFocus(container) {
}
}, 200);
}
let isValidData = (data) => (!_.isUndefined(data) && !_.isNull(data));
let isFunction = (fn) => (_.isFunction(fn));
let isString = (str) => (_.isString(str));
export {
isValidData, isFunction, isString,
};