-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathevents-table-virtualized.js
More file actions
76 lines (67 loc) · 1.97 KB
/
events-table-virtualized.js
File metadata and controls
76 lines (67 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { InfiniteLoader, Table, Column } from 'react-virtualized'
import {
fetchLazyEvents,
selectEvent,
loadMoreEvents,
eventListSelector,
loadedSelector,
loadingSelector
} from '../../ducks/events'
import Loader from '../common/loader'
import 'react-virtualized/styles.css'
export class EventsTableVirtualized extends Component {
static propTypes = {}
componentDidMount() {
this.props.fetchLazyEvents()
}
get isFirstLoading() {
const { events, loading } = this.props
return loading && events.length === 0
}
render() {
const { events } = this.props
if (this.isFirstLoading) return <Loader />
return (
<InfiniteLoader
isRowLoaded={this.isRowLoaded}
loadMoreRows={this.loadMoreRows}
rowCount={Number.MAX_SAFE_INTEGER}
>
{({ onRowsRendered, registerChild }) => (
<Table
rowCount={events.length}
width={500}
height={300}
rowHeight={40}
rowGetter={this.rowGetter}
headerHeight={50}
onRowClick={this.handleSelect}
overscanRowCount={1}
onRowsRendered={onRowsRendered}
ref={registerChild}
>
<Column dataKey="title" width={200} label="name" />
<Column dataKey="where" width={300} label="place" />
<Column dataKey="url" width={300} label="url" />
</Table>
)}
</InfiniteLoader>
)
}
rowGetter = ({ index }) => this.props.events[index]
handleSelect = ({ rowData }) => this.props.selectEvent(rowData.uid)
isRowLoaded = ({ index }) => !!this.props.events[index]
loadMoreRows = () => {
this.props.fetchLazyEvents()
}
}
export default connect(
(state) => ({
events: eventListSelector(state),
loading: loadingSelector(state),
loaded: loadedSelector(state)
}),
{ fetchLazyEvents, selectEvent }
)(EventsTableVirtualized)