mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Initial version of the new tree implementation.
This is the first version of our Tree implementation. At this point is a very simple tree without no abstractions and with code that eventually is not very performant, but this is only the first iteration and we are trying to follow the 'Last Responsible Moment Principle' [1]. Implemention details: - Creation of PGBrowser.treeMenu - Initial version of the Tree Adaptor 'pgadmin/static/js/tree/tree.js' - TreeFake test double that can replace the Tree for testing purposes - Tests, As an interesting asside because Fake’s need to behave like the real object you will noticed that there are tests for this type of double and they the same as of the real object. [1] https://medium.com/@aidanjcasey/guiding-principles-for-an-evolutionary-software-architecture-b6dc2cb24680 Patched by: Victoria && Joao Reviewed by: Khushboo & Ashesh
This commit is contained in:
committed by
Ashesh Vashi
parent
a34b3f27d4
commit
bc4d16eb83
69
web/regression/javascript/tree/tree_fake.js
Normal file
69
web/regression/javascript/tree/tree_fake.js
Normal file
@@ -0,0 +1,69 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import {Tree} from '../../../pgadmin/static/js/tree/tree';
|
||||
|
||||
export class TreeFake extends Tree {
|
||||
constructor() {
|
||||
super();
|
||||
this.aciTreeToOurTreeTranslator = {};
|
||||
this.aciTreeApi = jasmine.createSpyObj(
|
||||
['ACITreeApi'], ['setInode', 'unload', 'deselect', 'select']);
|
||||
}
|
||||
|
||||
addNewNode(id, data, domNode, path) {
|
||||
this.aciTreeToOurTreeTranslator[id] = [id];
|
||||
if (path !== null && path !== undefined) {
|
||||
this.aciTreeToOurTreeTranslator[id] = path.concat(id);
|
||||
}
|
||||
return super.addNewNode(id, data, domNode, path);
|
||||
}
|
||||
|
||||
addChild(parent, child) {
|
||||
child.setParent(parent);
|
||||
this.aciTreeToOurTreeTranslator[child.id] = this.aciTreeToOurTreeTranslator[parent.id].concat(child.id);
|
||||
parent.children.push(child);
|
||||
}
|
||||
|
||||
hasParent(aciTreeNode) {
|
||||
return this.translateTreeNodeIdFromACITree(aciTreeNode).length > 1;
|
||||
}
|
||||
|
||||
parent(aciTreeNode) {
|
||||
if (this.hasParent(aciTreeNode)) {
|
||||
let path = this.translateTreeNodeIdFromACITree(aciTreeNode);
|
||||
return [{id: this.findNode(path).parent().id}];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
translateTreeNodeIdFromACITree(aciTreeNode) {
|
||||
if(aciTreeNode === undefined || aciTreeNode[0] === undefined) {
|
||||
return null;
|
||||
}
|
||||
return this.aciTreeToOurTreeTranslator[aciTreeNode[0].id];
|
||||
}
|
||||
|
||||
itemData(aciTreeNode) {
|
||||
let node = this.findNodeByDomElement(aciTreeNode);
|
||||
if (node === undefined || node === null) {
|
||||
return undefined;
|
||||
}
|
||||
return node.getData();
|
||||
}
|
||||
|
||||
selected() {
|
||||
return this.selectedNode;
|
||||
}
|
||||
|
||||
selectNode(selectedNode) {
|
||||
this.selectedNode = selectedNode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user