Skip to content

Bug 1609211 - Persist settings in URL#6656

Merged
camd merged 11 commits into
mozilla:masterfrom
SuyashSalampuria:persist-url-changes
Sep 2, 2020
Merged

Bug 1609211 - Persist settings in URL#6656
camd merged 11 commits into
mozilla:masterfrom
SuyashSalampuria:persist-url-changes

Conversation

@SuyashSalampuria
Copy link
Copy Markdown
Contributor

@SuyashSalampuria SuyashSalampuria commented Jul 26, 2020

Fixes #6226

  • Order By changes persist in the URL
  • Group By changes persist in the URL
  • Metrics changes persist in the URL

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jul 27, 2020

Codecov Report

Merging #6656 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #6656   +/-   ##
=======================================
  Coverage   88.32%   88.32%           
=======================================
  Files         280      280           
  Lines       12776    12776           
=======================================
  Hits        11284    11284           
  Misses       1492     1492           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52ba161...18ed3a3. Read the comment docs.

@SuyashSalampuria SuyashSalampuria marked this pull request as ready for review July 28, 2020 11:32
@SuyashSalampuria
Copy link
Copy Markdown
Contributor Author

@sarah-clements @camd Could you give your initial reviews if this is the expected way
I am trying to find the best way to persisit metrics too in the URL

Comment thread ui/push-health/TestMetric.jsx Outdated
regressionsGroupBy: 'path',
knownIssuesOrderBy: 'count',
knownIssuesGroupBy: 'path',
setRegressionsOrderBy: () => {},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a required prop.

Comment thread ui/push-health/Health.jsx
const queryString = createQueryParams(newParams);
updateQueryParams(queryString, history, location);
this.setState({ knownIssuesGroupBy });
};
Copy link
Copy Markdown
Contributor

@sarah-clements sarah-clements Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're on the right track here, but since all of this logic is the same you should create one generic function that accepts an argument for the state that should be updated (there is a way to do this without entering a specific state name/key). I suggest naming the generic function something like updateParamsAndState.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was facing the problem of updating the state variable from a generic function
I mean, how do I come to know which state variable regressionsGroupBy or knownIssuesOrderBy is to be changed
Other things will be surely much better to handle in a generic function

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a way to solve this problem, you just need to research it :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to find a DRY solution - here you are repeating the same code multiple times. So there are a few different approaches you can take that would be better.

Copy link
Copy Markdown
Contributor Author

@SuyashSalampuria SuyashSalampuria Jul 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unable to find a good solution to it.
The only way I find is to pass a string parameter from the classification group component to see which state variable has to be changed. Does this method work?Or a still better solution is needed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An easy solution is to pass an object parameter instead of a variable: this.setState(stateObj). Another one would be to call setState inline in the onClick and update the query parameters as a callback function.

Copy link
Copy Markdown
Contributor

@sarah-clements sarah-clements Jul 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could pass in a string, but then you'd need a value unless you were doing a boolean toogle, so: (stateName, value) => this.setState({ [stateName]: value }). This is possible by using computed property names.

@sarah-clements
Copy link
Copy Markdown
Contributor

sarah-clements commented Jul 28, 2020

@sarah-clements @camd Could you give your initial reviews if this is the expected way
I am trying to find the best way to persisit metrics too in the URL

I would look at what the minimum amount of data that is needed in order to call the push health API for the failure summary for a selected task. You'll also need a query string/param that will tell the task component to be open instead of collapsed.

@SuyashSalampuria SuyashSalampuria force-pushed the persist-url-changes branch 2 times, most recently from cadb2f3 to 7a60b86 Compare August 3, 2020 15:46
@SuyashSalampuria
Copy link
Copy Markdown
Contributor Author

@camd I have facing a problem in persist the exact task inside the exact group
I am currently using the task id to see which group should be expanded
But, the tasks are not unique and several group may have same task
Should I add the testName also to the URL so that we can see can make it unique.This would make the URL very long although
I have already added the 2 params

  1. defaultExpandedTab - whether possible regressions is expanded or known issues
  2. expandedDefaultMetric - This contains the task id to show the details panel

The things seem to be working fine except that many tests are expanded

@camd
Copy link
Copy Markdown
Collaborator

camd commented Aug 3, 2020

@camd I have facing a problem in persist the exact task inside the exact group
I am currently using the task id to see which group should be expanded
But, the tasks are not unique and several group may have same task
Should I add the testName also to the URL so that we can see can make it unique.This would make the URL very long although
I have already added the 2 params

1. defaultExpandedTab - whether possible regressions is expanded or known issues

2. expandedDefaultMetric - This contains the task id to show the details panel

The things seem to be working fine except that many tests are expanded

One way to do this would be to add the id of the test from the FailureLine table in this for loop:

for failure_line in new_failure_lines:

That way you could just use the id instead of the test name. The unit tests should ensure these things work.

When we move to using mozci as a back-end, some of these things will likely change. So the ids we get for this may be different after that change. But that's ok. There is not a wide use-base yet. And we can break backward compatibility at that time if we need to.

@SuyashSalampuria
Copy link
Copy Markdown
Contributor Author

@camd Please review this too .
I currently need 4 variables on the params to expand the correct task on the correct test
Please suggest if you can find a better solution too

Copy link
Copy Markdown
Collaborator

@camd camd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be working well. A bit more refinement is needed. But a great start!

Comment thread ui/push-health/PlatformConfig.jsx Outdated
if (selectedTask === task || !task) {
this.setState({ selectedTask: null, detailsShowing: false });
} else {
this.props.updateParamsAndState({ expandedDefaultMetric: task.id });
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A metric is different than a task. I think this state name should be selectedTask. Or you could use selectedTaskId for the querystring param name.

metricwould be either tests, builds or linting. And we should persist that, too.

The url params are seeming a bit verbose to me. I'm wondering about something closer to this:

selectedTask = task.id
test= test.id (rather than the full test text)
testgroup = one of pr(possible regressions), ki (known issues)
metric = one of tests, linting, or builds

It also seems worthwhile to add these settings to the URL as you expand each one. You may not want to necessarily share just a selected task, but an expanded list of tests in one area.

Those names might seem a bit generic for being part of state. Perhaps selectedTest, selectedTestGroup, etc would be fine.

Copy link
Copy Markdown
Contributor Author

@SuyashSalampuria SuyashSalampuria Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metricwould be either tests, builds or linting. And we should persist that, too.

I think we can have that without persisting it on the URL. If any of the params, that have been added in this PR is present, tests should be shown by default. The cost of this would be checking max 7 conditions on the React code

test= test.id (rather than the full test text)

The tests are actually grouped by path or platform. So under any tests object in the frontend(which can be expanded or collapse), there are several tests from different failure lines.
Screenshot from 2020-08-05 21-06-08
This is the screenshot of the props in the Test Component. the test object may have more than one tests from different failure lines, hence different failure.id. This was my understanding from the code. Please rectify me if I am wrong or we have to store the id which has the whole test name in the URL

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the screenshot of the props in the Test Component. the test object may have more than one tests from different failure lines, hence different failure.id. This was my understanding from the code. Please rectify me if I am wrong or we have to store the id which has the whole test name in the URL

Ahh yes. I see what you mean. That ID won't be consistent, especially if some of the back-end data changes and a task is moved to "known issues" because retriggers come back with more passing than failing.

OK, let's go with the text, then. I'll test this locally a bit today and see if I can find any issues. But this is looking good. :)

@SuyashSalampuria SuyashSalampuria force-pushed the persist-url-changes branch 2 times, most recently from 29ab083 to 5597a08 Compare August 10, 2020 17:47
@SuyashSalampuria
Copy link
Copy Markdown
Contributor Author

@camd I just wanted to confirm if we are adding test group to the URL or the current way is fine

@camd
Copy link
Copy Markdown
Collaborator

camd commented Aug 11, 2020

When I use this url: http://localhost:5000/pushhealth.html?repo=try&revision=7b971f5053efbca154a3e3232a85328eb8cd376f&selectedTaskId=312757448&selectedTest=linux1804-64debug&testGroup=pr&regressionsGroupBy=platform

It opens ALL of the tasks on that platform. So I think it needs to also persist the job_type_name in the url.

@camd
Copy link
Copy Markdown
Collaborator

camd commented Aug 11, 2020

Also, it should save when things are only partially expanded. Not only when a task has been selected. It if we are in this state, it should just open to here:

Screen Shot 2020-08-11 at 2 20 27 PM

@camd
Copy link
Copy Markdown
Collaborator

camd commented Aug 11, 2020

@camd I just wanted to confirm if we are adding test group to the URL or the current way is fine

It looks like you have added testGroup=pr to the url. I think this is good. Or were you asking about something else?

@SuyashSalampuria
Copy link
Copy Markdown
Contributor Author

It looks like you have added testGroup=pr to the url. I think this is good. Or were you asking about something else?
Hey @camd
We have some many groupings there. I was speaking of selectedTest=linux1804-64debug , here actually
I have made some changes
It would be great if you could review it once again

@SuyashSalampuria SuyashSalampuria requested a review from camd August 21, 2020 18:26
Copy link
Copy Markdown
Collaborator

@camd camd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is almost there. Just a few small nit-picky changes here and there. :)

Thanks!!!

Comment thread ui/push-health/Health.jsx Outdated
const newParams = {
...parseQueryParams(location.search),
};
Object.assign(newParams, stateObj);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of Object.assign, let's use spreading, like you did for newParams. So just add ...stateObj to the creation of newParams in the spread on line 105.

Comment thread ui/push-health/Health.jsx
Comment thread ui/push-health/PlatformConfig.jsx Outdated
jobs,
failure: { jobName, testName },
} = this.props;
if (selectedJobName === `${testName} ${jobName}`) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this section could be condensed into:

this.setState({
    detailsShowing: selectedJobName === `${testName} ${jobName}`,
    selectedTask: selectedTaskId ? jobs[jobName].filter(
      (job) => job.id === parseInt(selectedTaskId, 10),
    ).length > 0 : null,
});

Would you give that a shot and see if it works ok?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, please add a blank line before this.setState

Comment thread ui/push-health/Test.jsx
Comment thread ui/push-health/Test.jsx
Copy link
Copy Markdown
Collaborator

@camd camd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working great! I've been doing some testing with it, and it's a really nice addition. Thank you!!

@camd camd merged commit 030c67a into mozilla:master Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Persist settings in URL:

4 participants