import {
	WeaOrgTree,
} from 'ecCom';

export default class OrgTree extends React.Component {
	constructor(props) {
		super(props);
		this.tree = null;
		this.setRef = element => {
			this.tree = element;
		}
	}

	componentWillReceiveProps(nextProps) {
		if (this.props.triggerRefresh !== nextProps.triggerRefresh) {
			this.init();
		}
	}

	componentDidMount() {
		this.init()
	}

	init = () => {
		if (this.tree) this.tree.reset(() => this.tree.fetchData());
	}

	render() {
		const {
			ORGTREE
		} = this.props;

		return (
			<div style={{height: '100%'}}>
		        <WeaOrgTree ecId={`${this && this.props && this.props.ecId || ''}_WeaOrgTree@gr8r61`} 
		        	{...ORGTREE}
		            ref={this.setRef}
		        />
        	</div>
		)
	}
}