-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.jsx
84 lines (82 loc) · 1.92 KB
/
report.jsx
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
77
78
79
80
81
82
83
84
var React = require('react')
var ReactPivot = require('react-pivot')
var Emitter = require('wildemitter')
var createReactClass = require('create-react-class')
var rows = require('./data.json')
var showRate = (val) => {
return isFinite(val) ? `${(val * 100).toFixed(1)}%` : 0
}
module.exports = createReactClass({
dimensions: [
{value: 'date', title: 'Date'},
{value: 'host', title: 'Host'}
],
calculations: [
{
title: 'Impressions',
value: 'impression',
className: 'alignRight'
},
{
title: 'Loads',
value: 'load',
className: 'alignRight'
},
{
title: 'Displays',
value: 'display',
className: 'alignRight'
},
{
title: 'Load Rate',
value: memo => memo.load / memo.impression,
template: showRate,
className: 'alignRight'
},
{
title: 'Display Rate',
value: memo => memo.display / memo.impression,
template: showRate,
className: 'alignRight'
}
],
reduce: (row, memo) => {
memo[row.type] = (memo[row.type] || 0) + 1
return memo
},
bus: new Emitter(),
getInitialState () {
return JSON.parse(window.localStorage.PivotState || '{}')
},
componentWillMount () {
this.bus.on('*', (event, data) => {
this.setState({[event]: data})
window.localStorage.PivotState = JSON.stringify(this.state)
})
},
render () {
const {
activeDimensions,
sortBy,
sortDir,
solo,
hiddenColumns
} = this.state
return (
<div>
<div>Report</div>
<ReactPivot rows={rows}
dimensions={this.dimensions}
reduce={this.reduce}
calculations={this.calculations}
activeDimensions={activeDimensions || ['Transaction Type']}
sortBy={sortBy}
sortDir={sortDir}
solo={solo}
hiddenColumns={hiddenColumns}
eventBus={this.bus}
/>
</div>
)
}
})