| 39 | }) |
| 40 | |
| 41 | class DraggableTable extends React.PureComponent { |
| 42 | state = { |
| 43 | data: this.props.data, |
| 44 | } |
| 45 | |
| 46 | table = React.createRef() |
| 47 | |
| 48 | getContainer = () => { |
| 49 | return this.table.current.getDOMNode().querySelector('.BaseTable__body') |
| 50 | } |
| 51 | |
| 52 | getHelperContainer = () => { |
| 53 | return this.table.current.getDOMNode().querySelector('.BaseTable__table') |
| 54 | } |
| 55 | |
| 56 | rowProps = args => { |
| 57 | // don't forget to passing the incoming rowProps |
| 58 | const extraProps = callOrReturn(this.props.rowProps) |
| 59 | return { |
| 60 | ...extraProps, |
| 61 | tagName: Row, |
| 62 | index: args.rowIndex, |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | handleSortEnd = ({ oldIndex, newIndex }) => { |
| 67 | const data = [...this.state.data] |
| 68 | const [removed] = data.splice(oldIndex, 1) |
| 69 | data.splice(newIndex, 0, removed) |
| 70 | this.setState({ data }) |
| 71 | } |
| 72 | |
| 73 | render() { |
| 74 | return ( |
| 75 | <DraggableContainer |
| 76 | useDragHandle |
| 77 | getContainer={this.getContainer} |
| 78 | helperContainer={this.getHelperContainer} |
| 79 | onSortEnd={this.handleSortEnd} |
| 80 | > |
| 81 | <Table |
| 82 | {...this.props} |
| 83 | ref={this.table} |
| 84 | data={this.state.data} |
| 85 | fixed={false} |
| 86 | rowProps={this.rowProps} |
| 87 | /> |
| 88 | </DraggableContainer> |
| 89 | ) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | const Hint = styled.div` |
| 94 | font-size: 16px; |
nothing calls this directly
no test coverage detected