|
1
|
|
|
var React = require("react"); |
|
2
|
|
|
|
|
3
|
|
|
var SummaryTable = React.createClass({ |
|
4
|
|
|
|
|
5
|
|
|
propTypes: { |
|
6
|
|
|
changes: React.PropTypes.objectOf(React.PropTypes.shape( |
|
7
|
|
|
React.PropTypes.objectOf(React.PropTypes.shape({ |
|
8
|
|
|
from: React.PropTypes.string, |
|
9
|
|
|
to: React.PropTypes.string |
|
10
|
|
|
})).isRequired |
|
11
|
|
|
)).isRequired |
|
12
|
|
|
}, |
|
13
|
|
|
|
|
14
|
|
|
render: function() { |
|
15
|
|
|
var changes = this.props.changes; |
|
16
|
|
|
|
|
17
|
|
|
var idx = 0; |
|
18
|
|
|
var summaryLines = Object.keys(changes).map(function(key) { |
|
19
|
|
|
idx++; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
var compareUrl = null; |
|
22
|
|
|
if (typeof changes[key].compareUrl !== 'undefined') { |
|
23
|
|
|
compareUrl = changes[key].compareUrl; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
if (typeof changes[key].description !== 'undefined') { |
|
27
|
|
|
|
|
28
|
|
|
if (changes[key].description !== "") { |
|
29
|
|
|
return ( |
|
30
|
|
|
<DescriptionOnlySummaryLine |
|
31
|
|
|
key={idx} |
|
32
|
|
|
name={key} |
|
33
|
|
|
description={changes[key].description} |
|
34
|
|
|
compareUrl={compareUrl} |
|
35
|
|
|
/> |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
return ( |
|
39
|
|
|
<UnchangedSummaryLine |
|
40
|
|
|
key={idx} |
|
41
|
|
|
name={key} |
|
42
|
|
|
value="" |
|
43
|
|
|
/> |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
} else if (changes[key].from !== changes[key].to) { |
|
47
|
|
|
return ( |
|
48
|
|
|
<SummaryLine |
|
49
|
|
|
key={idx} |
|
50
|
|
|
name={key} |
|
51
|
|
|
from={changes[key].from} |
|
52
|
|
|
to={changes[key].to} |
|
53
|
|
|
compareUrl={compareUrl} |
|
54
|
|
|
/> |
|
55
|
|
|
); |
|
56
|
|
|
} else if (typeof changes[key].from !== 'undefined') { |
|
57
|
|
|
return ( |
|
58
|
|
|
<UnchangedSummaryLine |
|
59
|
|
|
key={idx} |
|
60
|
|
|
name={key} |
|
61
|
|
|
value={changes[key].from} |
|
62
|
|
|
/> |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
return null; |
|
66
|
|
|
}); |
|
67
|
|
|
|
|
68
|
|
|
return ( |
|
69
|
|
|
<table className="table table-striped table-hover"> |
|
70
|
|
|
<tbody> |
|
71
|
|
|
{summaryLines} |
|
72
|
|
|
</tbody> |
|
73
|
|
|
</table> |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
}); |
|
77
|
|
|
|
|
78
|
|
|
function SummaryLine(props) { |
|
79
|
|
|
var from = props.from; |
|
80
|
|
|
var to = props.to; |
|
81
|
|
|
|
|
82
|
|
|
// naive git sha detection |
|
83
|
|
|
if (from !== null && from.length === 40) { |
|
84
|
|
|
from = from.substring(0, 7); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
// naive git sha detection |
|
88
|
|
|
if (to !== null && to.length === 40) { |
|
89
|
|
|
to = to.substring(0, 7); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
var compareUrl = null; |
|
93
|
|
|
if (props.compareUrl !== null) { |
|
94
|
|
|
compareUrl = ( |
|
95
|
|
|
<a href={props.compareUrl}> |
|
96
|
|
|
View diff<i className="fa fa-external-link-square superscript"></i> |
|
97
|
|
|
</a> |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return ( |
|
102
|
|
|
<tr> |
|
103
|
|
|
<th scope="row">{props.name}</th> |
|
104
|
|
|
<td>{from}</td> |
|
105
|
|
|
<td><span className="glyphicon glyphicon-arrow-right" /></td> |
|
106
|
|
|
<td>{to}</td> |
|
107
|
|
|
<td className="changeAction">{compareUrl}</td> |
|
108
|
|
|
</tr> |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
function UnchangedSummaryLine(props) { |
|
113
|
|
|
var from = props.value; |
|
114
|
|
|
// naive git sha detection |
|
115
|
|
|
if (from !== null && from.length === 40) { |
|
116
|
|
|
from = from.substring(0, 7); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return ( |
|
120
|
|
|
<tr> |
|
121
|
|
|
<th scope="row">{props.name}</th> |
|
122
|
|
|
<td>{from}</td> |
|
123
|
|
|
<td> </td> |
|
124
|
|
|
<td><span className="label label-success">Unchanged</span></td> |
|
125
|
|
|
<td> </td> |
|
126
|
|
|
</tr> |
|
127
|
|
|
); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
function DescriptionOnlySummaryLine(props) { |
|
131
|
|
|
var compareColumn = null; |
|
132
|
|
|
var colSpan = "4"; |
|
133
|
|
|
if (props.compareUrl !== null) { |
|
134
|
|
|
compareColumn = ( |
|
135
|
|
|
<td className="changeAction"> |
|
136
|
|
|
<a href={props.compareUrl}> |
|
137
|
|
|
View diff<i className="fa fa-external-link-square superscript"></i> |
|
138
|
|
|
</a> |
|
139
|
|
|
</td> |
|
140
|
|
|
); |
|
141
|
|
|
colSpan = "3"; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
return ( |
|
145
|
|
|
<tr> |
|
146
|
|
|
<th scope="row">{props.name}</th> |
|
147
|
|
|
<td |
|
148
|
|
|
colSpan={colSpan} |
|
149
|
|
|
dangerouslySetInnerHTML={{__html: props.description}} |
|
150
|
|
|
/> |
|
151
|
|
|
{compareColumn} |
|
152
|
|
|
</tr> |
|
153
|
|
|
); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
module.exports = SummaryTable; |
|
157
|
|
|
|