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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
/*
* SonarQube
* Copyright (C) 2009-2018 SonarSource SA
* mailto:info 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 { stringify } from 'querystring';
import * as React from 'react';
import { Link } from 'react-router';
import * as PropTypes from 'prop-types';
import * as classNames from 'classnames';
import MeasuresOverlay from './components/MeasuresOverlay';
import { SourceViewerFile, BranchLike } from '../../app/types';
import QualifierIcon from '../shared/QualifierIcon';
import Dropdown from '../controls/Dropdown';
import FavoriteContainer from '../controls/FavoriteContainer';
import ListIcon from '../icons-components/ListIcon';
import { ButtonIcon } from '../ui/buttons';
import { WorkspaceContext } from '../workspace/context';
import {
getPathUrlAsString,
getBranchLikeUrl,
getComponentIssuesUrl,
getBaseUrl
} from '../../helpers/urls';
import { collapsedDirFromPath, fileFromPath } from '../../helpers/path';
import { translate } from '../../helpers/l10n';
import { getBranchLikeQuery, isMainBranch } from '../../helpers/branches';
import { formatMeasure } from '../../helpers/measures';
import { omitNil } from '../../helpers/request';
interface Props {
branchLike: BranchLike | undefined;
sourceViewerFile: SourceViewerFile;
}
interface State {
measuresOverlay: boolean;
}
export default class SourceViewerHeader extends React.PureComponent<Props, State> {
context!: { workspace: WorkspaceContext };
static contextTypes = {
workspace: PropTypes.object.isRequired
};
state: State = { measuresOverlay: false };
handleShowMeasuresClick = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
event.preventDefault();
this.setState({ measuresOverlay: true });
};
handleMeasuresOverlayClose = () => {
this.setState({ measuresOverlay: false });
};
openInWorkspace = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
event.preventDefault();
const { key } = this.props.sourceViewerFile;
this.context.workspace.openComponent({ branchLike: this.props.branchLike, key });
};
render() {
const {
key,
measures,
path,
project,
projectName,
q,
subProject,
subProjectName,
uuid
} = this.props.sourceViewerFile;
const isUnitTest = q === 'UTS';
const workspace = false;
const rawSourcesLink =
getBaseUrl() +
'/api/sources/raw?' +
stringify(omitNil({ key, ...getBranchLikeQuery(this.props.branchLike) }));
// TODO favorite
return (
<div className="source-viewer-header">
<div className="source-viewer-header-component">
<div className="component-name">
<div className="component-name-parent">
<a
className="link-with-icon"
href={getPathUrlAsString(getBranchLikeUrl(project, this.props.branchLike))}>
<QualifierIcon qualifier="TRK" /> <span>{projectName}</span>
</a>
</div>
{subProject != null && (
<div className="component-name-parent">
<a
className="link-with-icon"
href={getPathUrlAsString(getBranchLikeUrl(subProject, this.props.branchLike))}>
<QualifierIcon qualifier="BRC" /> <span>{subProjectName}</span>
</a>
</div>
)}
<div className="component-name-path">
<QualifierIcon qualifier={q} /> <span>{collapsedDirFromPath(path)}</span>
<span className="component-name-file">{fileFromPath(path)}</span>
{this.props.sourceViewerFile.canMarkAsFavorite &&
(!this.props.branchLike || isMainBranch(this.props.branchLike)) && (
<FavoriteContainer className="component-name-favorite" componentKey={key} />
)}
</div>
</div>
</div>
<Dropdown>
{({ onToggleClick, open }) => (
<div className={classNames('dropdown source-viewer-header-actions', { open })}>
<ButtonIcon
className="js-actions"
onClick={onToggleClick}
tooltip={translate('component_viewer.more_actions')}>
<ListIcon />
</ButtonIcon>
<ul className="dropdown-menu dropdown-menu-right">
<li>
<a className="js-measures" href="#" onClick={this.handleShowMeasuresClick}>
{translate('component_viewer.show_details')}
</a>
{this.state.measuresOverlay && (
<MeasuresOverlay
branchLike={this.props.branchLike}
onClose={this.handleMeasuresOverlayClose}
sourceViewerFile={this.props.sourceViewerFile}
/>
)}
</li>
<li>
<a
className="js-new-window"
href={getPathUrlAsString({
pathname: '/component',
query: { id: key, ...getBranchLikeQuery(this.props.branchLike) }
})}
target="_blank">
{translate('component_viewer.new_window')}
</a>
</li>
{!workspace && (
<li>
<a className="js-workspace" href="#" onClick={this.openInWorkspace}>
{translate('component_viewer.open_in_workspace')}
</a>
</li>
)}
<li>
<a className="js-raw-source" href={rawSourcesLink} target="_blank">
{translate('component_viewer.show_raw_source')}
</a>
</li>
</ul>
</div>
)}
</Dropdown>
<div className="source-viewer-header-measures">
{isUnitTest && (
<div className="source-viewer-header-measure">
<span className="source-viewer-header-measure-value">
{formatMeasure(measures.tests, 'SHORT_INT')}
</span>
<span className="source-viewer-header-measure-label">
{translate('metric.tests.name')}
</span>
</div>
)}
{!isUnitTest && (
<div className="source-viewer-header-measure">
<span className="source-viewer-header-measure-value">
{formatMeasure(measures.lines, 'SHORT_INT')}
</span>
<span className="source-viewer-header-measure-label">
{translate('metric.lines.name')}
</span>
</div>
)}
<div className="source-viewer-header-measure">
<span className="source-viewer-header-measure-value">
<Link
to={getComponentIssuesUrl(project, {
resolved: 'false',
fileUuids: uuid,
...getBranchLikeQuery(this.props.branchLike)
})}>
{measures.issues != null ? formatMeasure(measures.issues, 'SHORT_INT') : 0}
</Link>
</span>
<span className="source-viewer-header-measure-label">
{translate('metric.violations.name')}
</span>
</div>
{measures.coverage != null && (
<div className="source-viewer-header-measure">
<span className="source-viewer-header-measure-value">
{formatMeasure(measures.coverage, 'PERCENT')}
</span>
<span className="source-viewer-header-measure-label">
{translate('metric.coverage.name')}
</span>
</div>
)}
{measures.duplicationDensity != null && (
<div className="source-viewer-header-measure">
<span className="source-viewer-header-measure-value">
{formatMeasure(measures.duplicationDensity, 'PERCENT')}
</span>
<span className="source-viewer-header-measure-label">
{translate('duplications')}
</span>
</div>
)}
</div>
</div>
);
}
}
|