import React, {Component, PropTypes} from 'react';
import {Button, ButtonGroup} from 'react-bootstrap';
import update from 'react-addons-update';
import {VerticalLayout, HorizontalLayout,DataGrid,DynamicDataGrid,Icon,ResizableModal,AutoResizeComponent,DepartmentDropdown,FlexPanel,FixedPanel,DraggableCell} from 'ssc-cdt3';
import {connectCdtDataComponent} from 'ssc-cdt3';
import React, {Component, PropTypes} from 'react'; import {Button, ButtonGroup} from 'react-bootstrap'; import update from 'react-addons-update'; import {VerticalLayout, HorizontalLayout,DataGrid,DynamicDataGrid,Icon,ResizableModal,AutoResizeComponent,DepartmentDropdown,FlexPanel,FixedPanel,DraggableCell} from 'ssc-cdt3'; import {connectCdtDataComponent} from 'ssc-cdt3';
const leftColConfig = [ { dataKey: 'CLIENT_NAME', label: 'Client Name', width: 200, dataType: 'string' } ];
const rightColConfig = [ { dataKey: 'CLIENT_NAME', label: 'Visible Columns', width: '*', dataType: 'string', sort: false, menu: false, cell: DraggableCell } ];
export default class ClientSelector extends Component {
static propTypes = { gridState: PropTypes.object.isRequired, onChange: PropTypes.func.isRequired,
};
constructor(props) { super(props); this.leftSelected = []; this.rightSelected = []; this.state = this.getState(); this.state = { showModal: false};
}
getState(props) { const {gridState} = this.props; // const {columns} = gridState; const locked = leftColConfig.filter(col => !col.hidden && !col.locked); const visible = leftColConfig.filter(col => !col.hidden && !col.locked); const hidden = leftColConfig.filter(col => col.hidden && !col.locked); return {visible, hidden, locked}; }
componentWillReceiveProps(props) { this.setState((this.getState(props)));
}
moveRight = () => { let {visible, hidden} = this.state; hidden = hidden.filter(item => this.leftSelected.indexOf(item) === -1); visible = visible.concat(this.leftSelected); this.setState({hidden, visible}, this.getColumnsForGrid); }
moveLeft = () => { let {visible, hidden} = this.state; visible = visible.filter(item => this.rightSelected.indexOf(item) === -1); hidden = hidden.concat(this.rightSelected); this.setState({hidden, visible}, this.getColumnsForGrid); }
leftSelectionChange = (colArray) => { this.leftSelected = colArray; }
rightSelectionChange = (colArray) => { this.rightSelected = colArray; }
getColumnsForGrid = () => { //const {onChange} = this.props; let {visible, hidden} = this.state; const {locked} = this.state; const columns = hidden.map(x => {return {...x, hidden: true, index: -1};}).concat(locked).concat(visible.map((col, index) => { return {...col, hidden: false, index}; })); onChange=({...this.props, columns});
}
open = () => { this.setState({ showModal: true }); }
render() { const {visible, hidden} = this.state;
} }