Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help text toggle #751

Merged
merged 5 commits into from
Oct 6, 2016
Merged

Help text toggle #751

merged 5 commits into from
Oct 6, 2016

Conversation

ebidel
Copy link
Contributor

@ebidel ebidel commented Oct 6, 2016

R: @paullewis @paulirish @brendankenny

  • Hides helpText by default when the audit rating is "good". Shows it otherwise.
  • Adds a ? button to toggle help text
  • Note: the HTTPs audit here does not have helpText, which is why nothing is showing for that failed audit :)

screen shot 2016-10-05 at 8 10 18 pm

@@ -34,6 +34,23 @@ class ReportGenerator {
return Math.round(totalScore * 100);
};

const getItemRating = (value, aggregatorScored) => {
if (typeof value === 'boolean') {
return value ? 'good' : 'poor';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit extract good / poor / average to a file live "enum" like map const

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


// Limit the rating to average if this is a rating for Best Practices.
let rating = aggregatorScored ? 'average' : 'poor';
if (value > 0.33) {
Copy link
Contributor

Choose a reason for hiding this comment

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

extract magic numbers to a private file level const map

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not going to touch other people's stuff as part of this cl

Copy link
Member

Choose a reason for hiding this comment

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

I agree with sam here. If you can improve code immediately involved with what you're changing anyways, you should. Pulling these out would be helpful.

Copy link
Contributor Author

@ebidel ebidel Oct 6, 2016

Choose a reason for hiding this comment

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

If every PR is a refactor, PRs take way longer to get in and introduce errors unrelated to the PR. I'm happy to do this one because it's small.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, and there's always a limit so we can actually make progress, PRs aren't weighted down by the past, etc. But small simplifications along the way are also a good way to help pay down technical debt. People usually need to get new stuff done so pure refactor PRs don't come along that often.

@@ -47,9 +49,19 @@ LighthouseReport.prototype = {
}
},

toggleHelpText: function(e) {
if (e.target.classList.contains('report-section__item-help-toggle')) {
const el = e.currentTarget.parentNode.querySelector('.report-section__item-helptext');
Copy link
Contributor

Choose a reason for hiding this comment

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

depending directly on the parentNode structure feels like smell, and potentially brittle code that could break with a trivial dom change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the handlers up a level to each item in the report (.report-section__item). That should "guarantee" the help text falls within the currentTarget

addEventListeners: function() {
this.printButton.addEventListener('click', this.onPrint);
this.checkboxToggleView.addEventListener('change', this.updateView);
Array.from(this.itemDetails).forEach(node => {
Copy link
Contributor

Choose a reason for hiding this comment

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

[...this.itemDetails].forEach

should be fine, since itemDetails is an iterable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

any advantage?

@ebidel
Copy link
Contributor Author

ebidel commented Oct 6, 2016

PTAL

@brendankenny
Copy link
Member

"1 resources were not served over h2"??

@ebidel
Copy link
Contributor Author

ebidel commented Oct 6, 2016

bugs me too :)

@@ -34,6 +40,23 @@ class ReportGenerator {
return Math.round(totalScore * 100);
};

const getItemRating = (value, aggregatorScored) => {
Copy link
Member

@brendankenny brendankenny Oct 6, 2016

Choose a reason for hiding this comment

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

make this a method on the class?

Copy link
Member

Choose a reason for hiding this comment

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

aggregatorScored appears to never be used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's an arg to the helper, but I don't see it used in the report.

Copy link
Member

Choose a reason for hiding this comment

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

what about moving this to a private method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ebidel
Copy link
Contributor Author

ebidel commented Oct 6, 2016

PTAL

@brendankenny
Copy link
Member

travis is apparently busy taking a nap

@paulirish
Copy link
Member

This PR is the bee's knees. 👍

@brendankenny brendankenny merged commit 5259f1e into master Oct 6, 2016
@brendankenny brendankenny deleted the helptext branch October 6, 2016 21:26
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.

4 participants