-
Notifications
You must be signed in to change notification settings - Fork 365
/
Copy pathAlertHeader.jsx
284 lines (275 loc) · 8.49 KB
/
AlertHeader.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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import {
UncontrolledDropdown,
DropdownMenu,
DropdownItem,
DropdownToggle,
Container,
Row,
Col,
Button,
Input,
InputGroup,
} from 'reactstrap';
import { getJobsUrl, getPerfCompareBaseURL } from '../../helpers/url';
import { toMercurialShortDateStr } from '../../helpers/display';
import SimpleTooltip from '../../shared/SimpleTooltip';
import Assignee from './Assignee';
import TagsList from './TagsList';
import AlertHeaderTitle from './AlertHeaderTitle';
const AlertHeader = ({
frameworks,
alertSummary,
repoModel,
issueTrackers,
user,
updateAssignee,
changeRevision,
updateViewState,
}) => {
const [inEditMode, setInEditMode] = useState(false);
const [newRevision, setNewRevision] = useState(alertSummary.revision);
const handleEditMode = () => {
setNewRevision('');
setInEditMode(true);
};
const handleRevisionChange = (event) => {
setNewRevision(event.target.value);
};
const saveRevision = async () => {
const longHashMatch = /\b[a-f0-9]{40}\b/;
const trimmedRevision = newRevision.trim();
if (!longHashMatch.test(trimmedRevision)) {
updateViewState({
errorMessages: [
`Invalid Revision format, expected a 40 character hash.`,
],
});
return;
}
const response = await changeRevision(trimmedRevision);
if (!response.failureStatus) {
setInEditMode(false);
}
};
const cancelEditMode = () => {
setInEditMode(false);
};
const getIssueTrackerUrl = () => {
const { issue_tracker_url: issueTrackerUrl } = issueTrackers.find(
(tracker) => tracker.id === alertSummary.issue_tracker,
);
return issueTrackerUrl + alertSummary.bug_number;
};
const handleRevertRevision = async () => {
await changeRevision(alertSummary.original_revision);
};
const bugNumber = alertSummary.bug_number
? `Bug ${alertSummary.bug_number}`
: '';
const performanceTags = alertSummary.performance_tags || [];
const alertSummaryDatetime = new Date(alertSummary.push_timestamp * 1000);
const formattedSummaryRevision = alertSummary.revision.slice(0, 12);
const created = new Date(alertSummary.created.slice(0, 19));
return (
<Container>
<AlertHeaderTitle alertSummary={alertSummary} frameworks={frameworks} />
<Row className="font-weight-normal">
<Col className="p-0" xs="auto">
<Row className="m-0 px-0 py-0">
<SimpleTooltip
text={toMercurialShortDateStr(alertSummaryDatetime)}
tooltipText="Push date"
/>
</Row>
<Row className="m-0 px-0 py-0">
<SimpleTooltip
text={toMercurialShortDateStr(created)}
tooltipText="Alert Summary created"
/>
</Row>
<Row className="m-0 px-0 py-0">
<a
href={getPerfCompareBaseURL(
alertSummary.repository,
alertSummary.prev_push_revision,
alertSummary.repository,
alertSummary.revision,
alertSummary.framework,
)}
target="_blank"
rel="noopener noreferrer"
>
PerfCompare comparison
</a>
</Row>
</Col>
<Col className="p-0" xs="auto">
{inEditMode ? (
<InputGroup size="sm">
<Input
placeholder="Enter desired revision"
onChange={handleRevisionChange}
onKeyDown={(event) => {
if (event.key === 'Enter') {
event.preventDefault();
saveRevision();
}
if (event.key === 'Escape') cancelEditMode();
}}
autoFocus
/>
<Button
color="primary"
className="ml-1"
size="xs"
onClick={saveRevision}
>
Save
</Button>
<Button
color="secondary"
className="ml-1"
size="xs"
onClick={cancelEditMode}
>
Cancel
</Button>
</InputGroup>
) : (
<Button
className="ml-1"
color="darker-secondary"
size="xs"
onClick={handleEditMode}
title="Click to edit revision"
>
Edit Revision
</Button>
)}
</Col>
{user.isStaff &&
alertSummary.original_revision !== alertSummary.revision && (
<Col className="p-0" xs="auto">
<Button className="ml-1" size="xs" onClick={handleRevertRevision}>
Reset Revision
</Button>
</Col>
)}
<Col className="p-0" xs="auto">
<UncontrolledDropdown tag="span">
<DropdownToggle
className="btn-xs ml-1"
color="secondary"
caret
data-testid="push-dropdown"
>
{formattedSummaryRevision}
</DropdownToggle>
<DropdownMenu>
<DropdownItem
tag="a"
className="text-dark"
href={getJobsUrl({
repo: alertSummary.repository,
fromchange: alertSummary.prev_push_revision,
tochange: alertSummary.revision,
})}
target="_blank"
rel="noopener noreferrer"
>
Jobs
</DropdownItem>
<DropdownItem
tag="a"
className="text-dark"
href={repoModel.getPushLogRangeHref({
fromchange: alertSummary.prev_push_revision,
tochange: alertSummary.revision,
})}
target="_blank"
rel="noopener noreferrer"
>
Pushlog
</DropdownItem>
<DropdownItem
className="text-dark"
disabled
data-testid="prev-push-revision"
>
From: {`${alertSummary.prev_push_revision.slice(0, 12)}`}
</DropdownItem>
<DropdownItem
className="text-dark"
disabled
data-testid="to-push-revision"
>
To: {formattedSummaryRevision}
</DropdownItem>
</DropdownMenu>
</UncontrolledDropdown>
</Col>
{bugNumber && (
<Col className="p-0" xs="auto">
{alertSummary.issue_tracker && issueTrackers.length > 0 ? (
<a
className="btn btn-secondary btn-xs ml-1 text-white"
href={getIssueTrackerUrl(alertSummary)}
target="_blank"
rel="noopener noreferrer"
>
{bugNumber}
</a>
) : (
{ bugNumber }
)}
</Col>
)}
<Col className="p-0" xs="auto">
<Assignee
assigneeUsername={alertSummary.assignee_username}
updateAssignee={updateAssignee}
user={user}
/>
</Col>
</Row>
{alertSummary.duplicated_summaries_ids.length > 0 && (
<Row>
Duplicated summaries:
{alertSummary.duplicated_summaries_ids.map((id, index) => (
<Link
className="text-dark mr-1"
target="_blank"
to={`./alerts?id=${id}&hideDwnToInv=0`}
id={`duplicated alert summary ${id.toString()} `}
style={{ marginLeft: '5px' }}
>
Alert #{id}
{alertSummary.duplicated_summaries_ids.length - 1 !== index &&
', '}
</Link>
))}
</Row>
)}
<Row>
{performanceTags.length > 0 && (
<Col className="p-0" xs="auto">
<TagsList tags={alertSummary.performance_tags} />
</Col>
)}
</Row>
</Container>
);
};
AlertHeader.propTypes = {
alertSummary: PropTypes.shape({}).isRequired,
repoModel: PropTypes.shape({}).isRequired,
user: PropTypes.shape({}).isRequired,
issueTrackers: PropTypes.arrayOf(PropTypes.shape({})),
};
AlertHeader.defaultProps = {
issueTrackers: [],
};
export default AlertHeader;