import React from 'react'; import history from 'utils/History'; import styles from './Tree.scss'; import classNames from 'classnames/bind'; const cx = classNames.bind(styles); class Node extends React.Component { displayName: 'UITreeNode'; renderCollapse = () => { const index = this.props.index; if (index.children && index.children.length) { const collapsed = index.node.collapsed; return ( ); } return null; }; renderChildren = () => { const index = this.props.index; const tree = this.props.tree; const dragging = this.props.dragging; if (index.children && index.children.length) { const childrenStyles = {}; if (!this.props.rootNode) { if (index.node.collapsed) childrenStyles.display = 'none'; childrenStyles.paddingLeft = `${this.props.paddingLeft}px`; } return (
{index.children.map(child => { const childIndex = tree.getIndex(child); return ( ); })}
); } return null; }; isModifying = () => { return this.props.allowUpdates && !this.props.rootNode; }; onClick = () => { const index = this.props.index; const node = index.node; if (!this.isModifying()) history.push(node.url); }; render() { const tree = this.props.tree; const index = this.props.index; const dragging = this.props.dragging; const node = index.node; const style = {}; return (
e.stopPropagation() : this.handleMouseDown } > {!this.props.rootNode && this.renderCollapse()} {node.title}
{this.renderChildren()}
); } handleCollapse = e => { e.stopPropagation(); const nodeId = this.props.index.id; if (this.props.onCollapse) this.props.onCollapse(nodeId); }; handleMouseDown = e => { const nodeId = this.props.index.id; const dom = this.refs.inner; if (this.props.onDragStart) { this.props.onDragStart(nodeId, dom, e); } }; } module.exports = Node;