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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
* SonarQube :: Web
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import classNames from 'classnames';
import React from 'react';
import ReactDOM from 'react-dom';
import { connect } from 'react-redux';
import ComponentName from './ComponentName';
import ComponentMeasure from './ComponentMeasure';
import ComponentQualityGate from './ComponentQualityGate';
import ComponentDetach from './ComponentDetach';
import ComponentPin from './ComponentPin';
const TOP_OFFSET = 200;
const BOTTOM_OFFSET = 10;
class Component extends React.Component {
componentDidMount () {
this.handleUpdate();
}
componentDidUpdate () {
this.handleUpdate();
}
handleUpdate () {
const { selected } = this.props;
if (selected) {
setTimeout(() => {
this.handleScroll();
}, 0);
}
}
handleScroll () {
const node = ReactDOM.findDOMNode(this);
const position = node.getBoundingClientRect();
const { top, bottom } = position;
if (bottom > window.innerHeight - BOTTOM_OFFSET) {
window.scrollTo(0, bottom - window.innerHeight + window.scrollY + BOTTOM_OFFSET);
} else if (top < TOP_OFFSET) {
window.scrollTo(0, top + window.scrollY - TOP_OFFSET);
}
}
render () {
const { component, selected, previous, coverageMetric, onBrowse, isView } = this.props;
let componentAction = null;
switch (component.qualifier) {
case 'FIL':
case 'UTS':
componentAction = <ComponentPin component={component}/>;
break;
default:
componentAction = <ComponentDetach component={component}/>;
}
return (
<tr className={classNames({ 'selected': selected })}>
<td className="thin nowrap">
<span className="spacer-right">
{componentAction}
</span>
</td>
<td className="code-name-cell">
{isView && (
<ComponentQualityGate
component={component}/>
)}
<ComponentName
component={component}
previous={previous}
onBrowse={onBrowse}/>
</td>
<td className="thin nowrap text-right">
<div className="code-components-cell">
<ComponentMeasure
component={component}
metricKey="ncloc"
metricType="SHORT_INT"/>
</div>
</td>
<td className="thin nowrap text-right">
<div className="code-components-cell">
<ComponentMeasure
component={component}
metricKey="sqale_index"
metricType="SHORT_WORK_DUR"/>
</div>
</td>
<td className="thin nowrap text-right">
<div className="code-components-cell">
<ComponentMeasure
component={component}
metricKey="violations"
metricType="SHORT_INT"/>
</div>
</td>
<td className="thin nowrap text-right">
<div className="code-components-cell">
<ComponentMeasure
component={component}
metricKey={coverageMetric}
metricType="PERCENT"/>
</div>
</td>
<td className="thin nowrap text-right">
<div className="code-components-cell">
<ComponentMeasure
component={component}
metricKey="duplicated_lines_density"
metricType="PERCENT"/>
</div>
</td>
</tr>
);
}
}
function mapStateToProps (state, ownProps) {
return {
selected: state.current.searchSelectedItem === ownProps.component,
isView: state.current.isView
};
}
export default connect(mapStateToProps)(Component);
|