/
EditableHitPolicyCell.js
75 lines (58 loc) · 1.51 KB
/
EditableHitPolicyCell.js
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
import { Component } from 'inferno';
import {
inject
} from 'table-js/lib/components';
export default class EditableHitPolicyCell extends Component {
constructor(props, context) {
super(props, context);
inject(this);
}
onClick = (event) => {
this.eventBus.fire('hitPolicy.edit', {
event
});
}
onElementsChanged = () => {
this.forceUpdate();
}
getRoot() {
return this.sheet.getRoot();
}
componentWillMount() {
this.changeSupport.onElementsChanged(this.getRoot().id, this.onElementsChanged);
}
componentWillUnmount() {
this.changeSupport.offElementsChanged(this.getRoot().id, this.onElementsChanged);
}
render() {
const root = this.getRoot(),
businessObject = root.businessObject,
hitPolicy = businessObject.hitPolicy,
hitPolicyLabel = hitPolicy.charAt(0),
aggregation = businessObject.aggregation;
const aggregationLabel = getAggregationLabel(aggregation);
return (
<th
data-hit-policy="true"
title={ 'Hit Policy = ' + hitPolicy }
onClick={ this.onClick }
className="hit-policy header"
rowspan="3">{ hitPolicyLabel }{ aggregationLabel }</th>
);
}
}
EditableHitPolicyCell.$inject = [
'changeSupport',
'sheet',
'eventBus'
];
// helpers //////////////////////
function getAggregationLabel(aggregation) {
switch (aggregation) {
case 'SUM': return '+';
case 'MIN': return '<';
case 'MAX': return '>';
case 'COUNT': return '#';
default: return '';
}
}