-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.js
More file actions
66 lines (59 loc) · 2.04 KB
/
index.js
File metadata and controls
66 lines (59 loc) · 2.04 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
import React from 'react'
import Table from 'react-virtualized/dist/commonjs/Table/Table'
import Column from 'react-virtualized/dist/commonjs/Table/Column'
import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer'
import getScrollBarWidth from 'get-scrollbar-width'
require('react-virtualized/styles.css')
const rowHeight = 30
class TableView extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.filteredFeatures !== this.props.filteredFeatures
}
componentWillMount () {
this.scrollbarWidth = getScrollBarWidth()
}
getColumns () {
const { filteredFeatures } = this.props
const featureWithProperties = filteredFeatures.find(d => d.hasOwnProperty('properties'))
if (!featureWithProperties) { return [] }
return Object.keys(featureWithProperties.properties)
}
render () {
const { filteredFeatures } = this.props
const rowGetter = ({ index }) => filteredFeatures[index].properties
const rowLength = filteredFeatures.length
const columns = this.getColumns()
return (
<div style={{width: '100%', height: '100%', position: 'absolute'}}>
<AutoSizer>
{({ width, height }) => {
const totalHeight = rowHeight * rowLength
const overflow = totalHeight > height
const columnWidth = overflow ? (width - this.scrollbarWidth) / columns.length
: width / columns.length
return <Table
disableHeader={false}
ref='table'
headerHeight={rowHeight}
height={height}
rowCount={filteredFeatures.length}
rowGetter={rowGetter}
rowHeight={rowHeight}
width={width}
>
{columns.map(column => (
<Column
label={column}
key={column}
dataKey={column}
width={columnWidth}
/>
))}
</Table>
}}
</AutoSizer>
</div>
)
}
}
export default TableView