-
Notifications
You must be signed in to change notification settings - Fork 352
/
MainView.jsx
174 lines (162 loc) · 3.94 KB
/
MainView.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
import React from 'react';
import { Row, Col } from 'reactstrap';
import PropTypes from 'prop-types';
import moment from 'moment';
import ReactTable from 'react-table';
import { bugsEndpoint } from '../helpers/url';
import BugColumn from './BugColumn';
import {
calculateMetrics,
prettyDate,
ISODate,
tableRowStyling,
} from './helpers';
import withView from './View';
import Layout from './Layout';
import DateRangePicker from './DateRangePicker';
const MainView = props => {
const {
graphData,
tableData,
initialParamsSet,
startday,
endday,
updateState,
tree,
location,
updateAppState,
} = props;
const textFilter = (filter, row) => {
const text = row[filter.id];
const regex = RegExp(filter.value, 'i');
if (regex.test(text)) {
return row;
}
};
const columns = [
{
Header: 'Bug',
accessor: 'id',
headerClassName: 'bug-column-header',
className: 'bug-column',
maxWidth: 150,
Cell: _props => (
<BugColumn
data={_props.original}
tree={tree}
startday={startday}
endday={endday}
location={location}
graphData={graphData}
tableData={tableData}
updateAppState={updateAppState}
/>
),
},
{
Header: 'Count',
accessor: 'count',
maxWidth: 100,
filterable: false,
},
{
Header: 'Summary',
accessor: 'summary',
minWidth: 250,
filterMethod: (filter, row) => textFilter(filter, row),
},
{
Header: 'Whiteboard',
accessor: 'whiteboard',
minWidth: 150,
filterMethod: (filter, row) => textFilter(filter, row),
},
];
let graphOneData = null;
let graphTwoData = null;
let totalFailures = 0;
let totalRuns = 0;
if (graphData.length) {
({
graphOneData,
graphTwoData,
totalFailures,
totalRuns,
} = calculateMetrics(graphData));
}
return (
<Layout
{...props}
graphOneData={graphOneData}
graphTwoData={graphTwoData}
header={
initialParamsSet && (
<React.Fragment>
<Row>
<Col xs="12" className="mx-auto pt-3">
<h1>Intermittent Test Failures</h1>
</Col>
</Row>
<Row>
<Col xs="12" className="mx-auto">
<p className="subheader">{`${prettyDate(
startday,
)} to ${prettyDate(endday)} UTC`}</p>
</Col>
</Row>
<Row>
<Col xs="12" className="mx-auto">
<p className="text-secondary">
{totalFailures} bugs in {totalRuns} pushes
</p>
</Col>
</Row>
</React.Fragment>
)
}
table={
initialParamsSet && (
<ReactTable
data={tableData}
showPageSizeOptions
columns={columns}
className="-striped"
getTrProps={tableRowStyling}
showPaginationTop
defaultPageSize={50}
filterable
/>
)
}
datePicker={<DateRangePicker updateState={updateState} />}
/>
);
};
MainView.propTypes = {
location: PropTypes.shape({}).isRequired,
tree: PropTypes.string.isRequired,
updateAppState: PropTypes.func,
updateState: PropTypes.func.isRequired,
startday: PropTypes.string.isRequired,
endday: PropTypes.string.isRequired,
tableData: PropTypes.arrayOf(PropTypes.shape({})),
graphData: PropTypes.arrayOf(PropTypes.shape({})),
initialParamsSet: PropTypes.bool.isRequired,
};
MainView.defaultProps = {
graphData: [],
tableData: [],
updateAppState: null,
};
const defaultState = {
tree: 'trunk',
startday: ISODate(
moment()
.utc()
.subtract(7, 'days'),
),
endday: ISODate(moment().utc()),
route: '/main',
endpoint: bugsEndpoint,
};
export default withView(defaultState)(MainView);