diff --git a/components/core/DataView.js b/components/core/DataView.js index 24dfc669..15d24651 100644 --- a/components/core/DataView.js +++ b/components/core/DataView.js @@ -198,10 +198,11 @@ export default class DataView extends React.Component { viewLimit: 40, scrollDebounce: false, imageSize: 100, - isShiftDown: false, - lastSelectedItemIndex: null, }; + isShiftDown = false; + lastSelectedItemIndex = null; + gridWrapperEl = React.createRef(); async componentDidMount() { @@ -263,65 +264,34 @@ export default class DataView extends React.Component { _handleCheckScroll = Window.debounce(this._handleScroll, 200); - _handleTableCheckBox = (e) => { - let checked = this.state.checked; - - let i = e.target.name; - if (this.state.isShiftDown && this.state.lastSelectedItemIndex !== i) { - return this._handleShiftClick({ - currentSelectedItemIndex: i, - lastSelectedItemIndex: this.state.lastSelectedItemIndex, - checked, - }); - } - - if (e.target.value === false) { - delete checked[e.target.name]; - this.setState({ checked, lastSelectedItemIndex: i }); - return; - } - - this.setState({ - checked: { ...this.state.checked, [e.target.name]: true }, - lastSelectedItemIndex: i, - }); - - if (checked[i]) { - delete checked[i]; - } else { - checked[i] = true; - } - this.setState({ checked, lastSelectedItemIndex: i }); - }; - - /* (NOTE):daniel This disable text selection while pressing shift key */ + /* NOTE(daniel): This disable text selection while pressing shift key */ _handleSelectStart = (e) => { - if (this.state.isShiftDown) { + if (this.isShiftDown) { e.preventDefault(); } }; _handleKeyUp = (e) => { - if (e.shiftKey && this.state.isShiftDown) { - this.setState({ isShiftDown: false }); + if (e.keyCode === 16 && this.isShiftDown) { + this.isShiftDown = false; } }; _handleKeyDown = (e) => { - if (e.shiftKey && !this.state.isShiftDown) { - this.setState({ isShiftDown: true }); + if (e.keyCode === 16 && !this.isShiftDown) { + this.isShiftDown = true; } }; - _handleGridCheckBox = (e, i) => { + _handleCheckBox = (e, i) => { e.stopPropagation(); e.preventDefault(); let checked = this.state.checked; - if (this.state.isShiftDown && this.state.lastSelectedItemIndex !== i) { + if (this.isShiftDown && this.lastSelectedItemIndex !== i) { return this._handleShiftClick({ currentSelectedItemIndex: i, - lastSelectedItemIndex: this.state.lastSelectedItemIndex, + lastSelectedItemIndex: this.lastSelectedItemIndex, checked, }); } @@ -331,7 +301,8 @@ export default class DataView extends React.Component { } else { checked[i] = true; } - this.setState({ checked, lastSelectedItemIndex: i }); + this.setState({ checked }); + this.lastSelectedItemIndex = i; }; _handleShiftClick = ({ currentSelectedItemIndex, lastSelectedItemIndex, checked }) => { @@ -349,7 +320,8 @@ export default class DataView extends React.Component { } let newSelection = Object.assign({}, checked, rangeSelected); - this.setState({ checked: newSelection, lastSelectedItemIndex: currentSelectedItemIndex }); + this.setState({ checked: newSelection }); + this.lastSelectedItemIndex = currentSelectedItemIndex; return; }; @@ -432,7 +404,8 @@ export default class DataView extends React.Component { }; _handleUncheckAll = () => { - this.setState({ checked: {}, lastSelectedItemIndex: null }); + this.setState({ checked: {} }); + this.lastSelectedItemIndex = null; }; render() { @@ -500,7 +473,10 @@ export default class DataView extends React.Component {