Skip to content

Commit 030c67a

Browse files
Bug 1609211 - Persist settings in URL (#6656)
* persist group and order by changes in the URL * Modify tests for modifying the way of changing orderBy or groupBy * add a generic function to update state and params * Persist changes in the metric in the URL * persist the jobName in the URL
1 parent 5e6bc09 commit 030c67a

9 files changed

Lines changed: 214 additions & 37 deletions

File tree

tests/ui/push-health/ClassificationGroup_test.jsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { render, waitFor, fireEvent } from '@testing-library/react';
2+
import { render, waitFor } from '@testing-library/react';
33

44
import pushHealth from '../mock/push_health';
55
import ClassificationGroup from '../../../ui/push-health/ClassificationGroup';
@@ -9,7 +9,7 @@ const tests = metrics.tests.details.needInvestigation;
99
const repoName = 'autoland';
1010

1111
describe('ClassificationGroup', () => {
12-
const testClassificationGroup = (group) => (
12+
const testClassificationGroup = (group, groupedBy) => (
1313
<ClassificationGroup
1414
jobs={jobs}
1515
tests={group}
@@ -20,26 +20,22 @@ describe('ClassificationGroup', () => {
2020
unfilteredLength={5}
2121
hasRetriggerAll
2222
notify={() => {}}
23+
groupedBy={groupedBy}
2324
/>
2425
);
2526

2627
test('should group by test path', async () => {
27-
const { getAllByTestId } = render(testClassificationGroup(tests));
28+
const { getAllByTestId } = render(testClassificationGroup(tests, 'path'));
2829

2930
expect(await waitFor(() => getAllByTestId('test-grouping'))).toHaveLength(
3031
3,
3132
);
3233
});
3334

3435
test('should group by platform', async () => {
35-
const { getAllByTestId, findByTestId, findByText } = render(
36-
testClassificationGroup(tests),
36+
const { getAllByTestId } = render(
37+
testClassificationGroup(tests, 'platform'),
3738
);
38-
const groupBy = await findByTestId('groupTestsDropdown');
39-
40-
fireEvent.click(groupBy);
41-
const path = await findByText('Platform');
42-
fireEvent.click(path);
4339

4440
expect(await waitFor(() => getAllByTestId('test-grouping'))).toHaveLength(
4541
12,

tests/ui/push-health/PlatformConfig_test.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ describe('PlatformConfig', () => {
6060
currentRepo={{ name: repoName, tc_root_url: 'http://foo.com' }}
6161
groupedBy="platform"
6262
notify={() => {}}
63+
updateParamsAndState={() => {}}
6364
/>
6465
);
6566

tests/ui/push-health/TestMetric_test.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('TestMetric', () => {
2020
currentRepo={{ name: repoName, tc_root_url: 'http://foo.com' }}
2121
notify={() => {}}
2222
searchStr=""
23+
updateParamsAndState={() => {}}
2324
showParentMatches={false}
2425
/>
2526
);

ui/push-health/Action.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class Action extends PureComponent {
3939
currentRepo,
4040
notify,
4141
jobs,
42+
testGroup,
43+
selectedJobName,
44+
selectedTest,
45+
selectedTaskId,
46+
updateParamsAndState,
4247
} = this.props;
4348
const groupedTests = this.getTestGroups(tests);
4449

@@ -54,6 +59,11 @@ class Action extends PureComponent {
5459
currentRepo={currentRepo}
5560
notify={notify}
5661
jobs={jobs}
62+
selectedJobName={selectedJobName}
63+
selectedTest={selectedTest}
64+
testGroup={testGroup}
65+
selectedTaskId={selectedTaskId}
66+
updateParamsAndState={updateParamsAndState}
5767
/>
5868
</div>
5969
))}

ui/push-health/ClassificationGroup.jsx

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ class ClassificationGroup extends React.PureComponent {
3333
this.state = {
3434
detailsShowing: props.expanded,
3535
retriggerDropdownOpen: false,
36-
groupedBy: 'path',
37-
orderedBy: 'count',
3836
};
3937
}
4038

4139
toggleDetails = () => {
40+
const { updateParamsAndState, name } = this.props;
41+
42+
updateParamsAndState({
43+
testGroup: name === 'Possible Regressions' ? 'pr' : 'ki',
44+
});
4245
this.setState((prevState) => ({
4346
detailsShowing: !prevState.detailsShowing,
4447
}));
@@ -65,14 +68,6 @@ class ClassificationGroup extends React.PureComponent {
6568
JobModel.retrigger(uniqueJobs, currentRepo, notify, times);
6669
};
6770

68-
setGroupedBy = (groupedBy) => {
69-
this.setState({ groupedBy });
70-
};
71-
72-
setOrderedBy = (orderedBy) => {
73-
this.setState({ orderedBy });
74-
};
75-
7671
getTestsByAction = (tests) => {
7772
const { log, crash, test } = groupBy(tests, 'action');
7873

@@ -83,12 +78,7 @@ class ClassificationGroup extends React.PureComponent {
8378
};
8479

8580
render() {
86-
const {
87-
detailsShowing,
88-
retriggerDropdownOpen,
89-
groupedBy,
90-
orderedBy,
91-
} = this.state;
81+
const { detailsShowing, retriggerDropdownOpen } = this.state;
9282
const {
9383
jobs,
9484
tests,
@@ -100,6 +90,15 @@ class ClassificationGroup extends React.PureComponent {
10090
currentRepo,
10191
icon,
10292
iconColor,
93+
groupedBy,
94+
orderedBy,
95+
testGroup,
96+
selectedTest,
97+
selectedJobName,
98+
selectedTaskId,
99+
setGroupedBy,
100+
setOrderedBy,
101+
updateParamsAndState,
103102
} = this.props;
104103
const expandIcon = detailsShowing ? faCaretDown : faCaretRight;
105104
const expandTitle = detailsShowing
@@ -187,21 +186,23 @@ class ClassificationGroup extends React.PureComponent {
187186
<DropdownItem
188187
className="pointable"
189188
tag="a"
190-
onClick={() => this.setGroupedBy('none')}
189+
onClick={() => setGroupedBy('none')}
191190
>
192191
None
193192
</DropdownItem>
194193
<DropdownItem
195194
className="pointable"
196195
tag="a"
197-
onClick={() => this.setGroupedBy('path')}
196+
onClick={() => {
197+
setGroupedBy('path');
198+
}}
198199
>
199200
Path
200201
</DropdownItem>
201202
<DropdownItem
202203
className="pointable"
203204
tag="a"
204-
onClick={() => this.setGroupedBy('platform')}
205+
onClick={() => setGroupedBy('platform')}
205206
>
206207
Platform
207208
</DropdownItem>
@@ -222,14 +223,18 @@ class ClassificationGroup extends React.PureComponent {
222223
<DropdownItem
223224
className="pointable"
224225
tag="a"
225-
onClick={() => this.setOrderedBy('count')}
226+
onClick={() => {
227+
setOrderedBy('count');
228+
}}
226229
>
227230
Count
228231
</DropdownItem>
229232
<DropdownItem
230233
className="pointable"
231234
tag="a"
232-
onClick={() => this.setOrderedBy('text')}
235+
onClick={() => {
236+
setOrderedBy('text');
237+
}}
233238
>
234239
Text
235240
</DropdownItem>
@@ -251,6 +256,11 @@ class ClassificationGroup extends React.PureComponent {
251256
notify={notify}
252257
key={key}
253258
jobs={jobs}
259+
testGroup={testGroup}
260+
selectedTest={selectedTest}
261+
selectedJobName={selectedJobName}
262+
selectedTaskId={selectedTaskId}
263+
updateParamsAndState={updateParamsAndState}
254264
/>
255265
))}
256266
</Collapse>
@@ -269,13 +279,21 @@ ClassificationGroup.propTypes = {
269279
expanded: PropTypes.bool,
270280
className: PropTypes.string,
271281
iconColor: PropTypes.string,
282+
orderedBy: PropTypes.string,
283+
groupedBy: PropTypes.string,
284+
setOrderedBy: PropTypes.func,
285+
setGroupedBy: PropTypes.func,
272286
};
273287

274288
ClassificationGroup.defaultProps = {
275289
expanded: true,
276290
className: '',
277291
iconColor: 'darker-info',
278292
hasRetriggerAll: false,
293+
orderedBy: 'count',
294+
groupedBy: 'path',
295+
setOrderedBy: () => {},
296+
setGroupedBy: () => {},
279297
};
280298

281299
export default ClassificationGroup;

ui/push-health/Health.jsx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,29 @@ export default class Health extends React.PureComponent {
5454
notifications: [],
5555
defaultTabIndex: 0,
5656
showParentMatches: false,
57+
testGroup: params.get('testGroup') || '',
58+
selectedTest: params.get('selectedTest') || '',
59+
selectedTaskId: params.get('selectedTaskId') || '',
60+
selectedJobName: params.get('selectedJobName') || '',
5761
searchStr: params.get('searchStr') || '',
62+
regressionsOrderBy: params.get('regressionsOrderBy') || 'count',
63+
regressionsGroupBy: params.get('regressionsGroupBy') || 'path',
64+
knownIssuesOrderBy: params.get('knownIssuesOrderBy') || 'count',
65+
knownIssuesGroupBy: params.get('knownIssuesGroupBy') || 'path',
5866
};
5967
}
6068

6169
async componentDidMount() {
62-
const { repo } = this.state;
70+
const { repo, testGroup } = this.state;
6371
const {
6472
metrics: { linting, builds, tests },
6573
} = await this.updatePushHealth();
66-
const defaultTabIndex = [linting, builds, tests].findIndex(
74+
let defaultTabIndex = [linting, builds, tests].findIndex(
6775
(metric) => metric.result === 'fail',
6876
);
77+
if (testGroup) {
78+
defaultTabIndex = 2;
79+
}
6980
const repos = await RepositoryModel.getList();
7081
const currentRepo = repos.find((repoObj) => repoObj.name === repo);
7182

@@ -88,6 +99,18 @@ export default class Health extends React.PureComponent {
8899
this.setState({ user });
89100
};
90101

102+
updateParamsAndState = (stateObj) => {
103+
const { location, history } = this.props;
104+
const newParams = {
105+
...parseQueryParams(location.search),
106+
...stateObj,
107+
};
108+
const queryString = createQueryParams(newParams);
109+
110+
updateQueryParams(queryString, history, location);
111+
this.setState(stateObj);
112+
};
113+
91114
updatePushHealth = async () => {
92115
const { repo, revision } = this.state;
93116
const { data, failureStatus } = await PushModel.getHealth(repo, revision);
@@ -174,7 +197,15 @@ export default class Health extends React.PureComponent {
174197
searchStr,
175198
currentRepo,
176199
showParentMatches,
200+
testGroup,
201+
selectedTest,
177202
defaultTabIndex,
203+
selectedTaskId,
204+
selectedJobName,
205+
regressionsOrderBy,
206+
regressionsGroupBy,
207+
knownIssuesOrderBy,
208+
knownIssuesGroupBy,
178209
} = this.state;
179210
const { tests, commitHistory, linting, builds } = metrics;
180211
const needInvestigationCount = tests
@@ -305,7 +336,16 @@ export default class Health extends React.PureComponent {
305336
notify={this.notify}
306337
setExpanded={this.setExpanded}
307338
searchStr={searchStr}
339+
testGroup={testGroup}
340+
selectedTest={selectedTest}
308341
showParentMatches={showParentMatches}
342+
regressionsOrderBy={regressionsOrderBy}
343+
regressionsGroupBy={regressionsGroupBy}
344+
knownIssuesOrderBy={knownIssuesOrderBy}
345+
knownIssuesGroupBy={knownIssuesGroupBy}
346+
selectedTaskId={selectedTaskId}
347+
selectedJobName={selectedJobName}
348+
updateParamsAndState={this.updateParamsAndState}
309349
/>
310350
</TabPanel>
311351
</div>

ui/push-health/PlatformConfig.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,39 @@ class PlatformConfig extends React.PureComponent {
2222
};
2323
}
2424

25+
componentDidMount() {
26+
const {
27+
selectedJobName,
28+
selectedTaskId,
29+
jobs,
30+
failure: { jobName, testName },
31+
} = this.props;
32+
33+
this.setState({
34+
detailsShowing: selectedJobName === `${testName} ${jobName}`,
35+
selectedTask: selectedTaskId
36+
? jobs[jobName].filter((job) => job.id === parseInt(selectedTaskId, 10))
37+
.length > 0 &&
38+
jobs[jobName].filter(
39+
(job) => job.id === parseInt(selectedTaskId, 10),
40+
)[0]
41+
: null,
42+
});
43+
}
44+
2545
setSelectedTask = (task) => {
2646
const { selectedTask } = this.state;
47+
const {
48+
failure: { jobName, testName },
49+
} = this.props;
2750

2851
if (selectedTask === task || !task) {
2952
this.setState({ selectedTask: null, detailsShowing: false });
3053
} else {
54+
this.props.updateParamsAndState({
55+
selectedTaskId: task.id,
56+
selectedJobName: `${testName} ${jobName}`,
57+
});
3158
this.setState({ selectedTask: task, detailsShowing: true });
3259
}
3360
};
@@ -140,6 +167,7 @@ PlatformConfig.propTypes = {
140167
currentRepo: PropTypes.shape({}).isRequired,
141168
notify: PropTypes.func.isRequired,
142169
groupedBy: PropTypes.string.isRequired,
170+
updateParamsAndState: PropTypes.func.isRequired,
143171
};
144172

145173
export default PlatformConfig;

0 commit comments

Comments
 (0)