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

report(redesign): add toggle control to show metric descriptions #8661

Merged
merged 23 commits into from
May 1, 2019

Conversation

connorjclark
Copy link
Collaborator

</div>
<div class=""></div>
</div>
</summary>
</details>
</template>

<!-- Lighthouse metrics toggle -->
<template id="tmpl-lh-metrics-toggle">
<div class="lh-metrics-toggle">
Copy link
Member

Choose a reason for hiding this comment

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

i'd like to use a <input type=checkbox> here (as the underlying control).

we shouldn't need JS for this guy (except for this.metricAuditGroup.classList.toggle('lh-audit-group--metrics__show-descriptions'))

this guide seems to be solid on implementation.. also including their resources at the bottom. https://webdesign.tutsplus.com/tutorials/how-to-make-custom-accessible-checkboxes-and-radio-buttons--cms-32074

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done, hows that?

<defs>
<path id="a" d="M0 0h24v24H0V0z" />
</defs>
<clipPath id="b">
Copy link
Member

Choose a reason for hiding this comment

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

afaik this clippath isn't being used. i guess its just an artifact from sketch exports.

<div class="lh-metrics-toggle-more">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path class="lh-metrics-toggle-lines" d="M3 18h12v-2H3v2zM3 6v2h18V6H3zm0 7h18v-2H3v2z" />
<path fill="none" d="M0 0h24v24H0V0z" />
Copy link
Member

Choose a reason for hiding this comment

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

ditto with this unused path

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

thx! this is def looking in the right direction.

apologies i'm finding so much in this one.

this.metricAuditGroup = this._dom.find('.lh-audit-group--metrics', this._document);
}

_setupMetricDescriptionToggleListeners() {
Copy link
Member

Choose a reason for hiding this comment

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

i definitely didnt expect this..

click on the newly expanded descriptions to make them go away?

this UX doesn't make sense to me

Copy link
Member

Choose a reason for hiding this comment

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

IMO this would only make sense if the toggle is scoped to just the metric title.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

silly that u cant link to doc comments

Copy link
Member

@paulirish paulirish Apr 29, 2019

Choose a reason for hiding this comment

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

aiight. i'm not feeling this UX at all, so I raised a concern there: https://docs.google.com/a/google.com/document/d/15L5iaWo4ieouegpSlaqGGWpA13JnTv73xnpxuVhzkBg/edit?disco=AAAAC6njMnI


silly that u cant link to doc comments

image

_setupMetricDescriptionToggleListeners() {
const toggle = () => this.metricDescriptionToggleEl.click();
this.metricDescriptionToggleEl.addEventListener('input', this._toggleMetricDescription);
for (const el of this._dom.findAll('.lh-metric', this._document)) {
Copy link
Member

Choose a reason for hiding this comment

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

event delegation will be cleaner here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hm?

Copy link
Member

Choose a reason for hiding this comment

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

we really only need one click listener, then just make sure the target was an .lh-metric (though it might as well be on the entire section considering how much of it lh-metrics take up...I think I agree with @paulirish about the clicking thing)

Copy link
Member

Choose a reason for hiding this comment

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

here's event delegation. and also only using the metric titles as click targets.

    this.metricAuditGroup.addEventListener('click', e => {
      if (e.target.closest('.lh-metric__title')) this.metricDescriptionToggleEl.click()
    });

@@ -81,6 +88,8 @@ class ReportUIFeatures {
this._document.addEventListener('copy', this.onCopy);
this._document.addEventListener('scroll', this._updateStickyHeaderOnScroll);
window.addEventListener('resize', this._updateStickyHeaderOnScroll);
this._setupMetricDescriptionToggleElements();
this._setupMetricDescriptionToggleListeners();
Copy link
Member

Choose a reason for hiding this comment

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

let's just merge these two

@@ -102,6 +103,7 @@
--env-item-bg: var(--color-black-100);
--env-name-min-width: 220px;
--env-tem-padding: 10px 0px;
--expandable-padding: 0 0 2px 28px;
Copy link
Member

Choose a reason for hiding this comment

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

magic number here... :/

    --score-shape-margin: 7px 12px 0 4px;
    --score-shape-size: 12px;

afaik the 28 is 12 + 4 + 12.

I wonder if we can redefine score-shape with some base variable so these remain synchronized?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done-ish. shoot, that icon width varies based on the state ...

fill: #7F7F7F;
}
.lh-metrics-toggle input:not(:checked) + label .lh-metrics-toggle-less .lh-metrics-toggle-lines,
.lh-metrics-toggle input:checked + label .lh-metrics-toggle-more .lh-metrics-toggle-lines {
Copy link
Member

Choose a reason for hiding this comment

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

instead of this, you could override a css var up in the conditional L595 rule ...

  --color-lines: var(--color-white);

.lh-metrics-toggle input:checked + label .lh-metrics-toggle-more .lh-metrics-toggle-lines {
fill: white;
}
.lh-metrics-toggle label div.lh-metrics-toggle-less {
Copy link
Member

Choose a reason for hiding this comment

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

you could afford to be more BEM-y here

.lh-metrics-toggle__icon
.lh-metrics-toggle__icon--expand

border-radius: 20px;
overflow: hidden;
}
.lh-metrics-toggle label div {
Copy link
Member

Choose a reason for hiding this comment

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

this should be defined closer to the L605 rules. and BEMy would be .lh-metrics-toggle__icon

opacity: 0;
position: absolute;
top: 0;
width: 74px;
Copy link
Member

Choose a reason for hiding this comment

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

instead of these magic numbers you could just do bottom:0; right: 0; and now its 100% 100%. ;)

also not putting left & top together in a rule? what kind of sadist are you? 😭

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

needs some tests 🎉 🎉

@@ -200,6 +200,11 @@ class CategoryRenderer {
descriptionEl.classList.add('lh-audit-group__description');
auditGroupHeader.appendChild(descriptionEl);
}
if (group.title === 'Metrics') {
Copy link
Member

Choose a reason for hiding this comment

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

should move this over to performance-category-renderer.js. It'll have to do an extra step to re-find the header, but it would be good to keep specialized knowledge of the perf category encapsulated in that file if we can

@@ -157,6 +165,24 @@ class ReportUIFeatures {
this._copyAttempt = false;
}

_setupMetricDescriptionToggleElements() {
this.metricDescriptionToggleEl =
/** @type {HTMLInputElement} */ (this._dom.find('.lh-metrics-toggle input', this._document));
Copy link
Member

Choose a reason for hiding this comment

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

will need to guard against when there's no perf category

@@ -60,6 +64,9 @@ class ReportUIFeatures {
this.expandAllDetails = this.expandAllDetails.bind(this);
this._toggleDarkTheme = this._toggleDarkTheme.bind(this);
this._updateStickyHeaderOnScroll = this._updateStickyHeaderOnScroll.bind(this);
this._toggleMetricDescription = this._toggleMetricDescription.bind(this);
this._setupMetricDescriptionToggleElements =
Copy link
Member

Choose a reason for hiding this comment

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

doesn't look like it need to be bound?

@vercel vercel bot temporarily deployed to staging April 30, 2019 05:06 Inactive
@connorjclark
Copy link
Collaborator Author

connorjclark commented Apr 30, 2019

@brendankenny added tests. Also tried a tests refactor (render fn) but not sure if better

/**
* @param {LH.JSON} lhr
*/
function render(lhr) {
Copy link
Member

Choose a reason for hiding this comment

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

render function looks 👍

main issue is that it can be pretty slow, so we want to share rendered reports between tests as much as possible, but that's what you do here, so looks good to me


assert.equal(reportUIFeatures.json, undefined);
reportUIFeatures.initFeatures(sampleResults);
assert.ok(reportUIFeatures.json);
Copy link
Member

Choose a reason for hiding this comment

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

testing json was being used as a proxy test for the reportUIFeatures being initialized, otherwise this is just testing the report renderer.

We could definitely do something much better if you want to come up with something to test :) or just restore and we'll think about it another day

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about just removing it? Doesn't seem useful now that we have all these other tests checking individual behaviors.

Copy link
Member

Choose a reason for hiding this comment

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

How about just removing it?

seems fine now, yeah

@@ -795,6 +855,14 @@
font-weight: bold;
}

/* Pushes the metric description toggle button to the right. */
Copy link
Member

Choose a reason for hiding this comment

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

not sure if it's really better down here or up with the toggle stuff

_setupMetricDescriptionToggleListeners() {
const toggle = () => this.metricDescriptionToggleEl.click();
this.metricDescriptionToggleEl.addEventListener('input', this._toggleMetricDescription);
for (const el of this._dom.findAll('.lh-metric', this._document)) {
Copy link
Member

Choose a reason for hiding this comment

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

we really only need one click listener, then just make sure the target was an .lh-metric (though it might as well be on the entire section considering how much of it lh-metrics take up...I think I agree with @paulirish about the clicking thing)

}
.lh-metrics-toggle__input:not(:checked) + label .lh-metrics-toggle__icon--less .lh-metrics-toggle__lines,
.lh-metrics-toggle__input:checked + label .lh-metrics-toggle__icon--more .lh-metrics-toggle__lines {
--color-metric-toggle-lines: var(--color-white);
Copy link
Member

Choose a reason for hiding this comment

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

now you can move this prop into the L601 rule and delete this L608 rule

.lh-metrics-toggle__input:checked + label .lh-metrics-toggle__icon--more .lh-metrics-toggle__lines {
--color-metric-toggle-lines: var(--color-white);
}
.lh-metrics-toggle label .lh-metrics-toggle__icon--less {
Copy link
Member

Choose a reason for hiding this comment

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

the base .lh-metrics-toggle__icon rule could assume the --less case so this rule isnt necessary

regardless you can move width/height into the base lh-metrics-toggle__icon rule

<defs>
<path id="a" d="M0 0h24v24H0V0z" />
</defs>
<path class="lh-metrics-toggle__lines" d="M4 9h16v2H4zm0 4h10v2H4z" clip-path="url(#b)" />
Copy link
Member

Choose a reason for hiding this comment

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

i think you can just delete clip-path attribute and the <defs> above. it seems to be ignored.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@connorjclark
Copy link
Collaborator Author

connorjclark commented Apr 30, 2019

not crazy about how the tab control is styled, thoughts?

@brendankenny
Copy link
Member

up to @paulirish on if he likes this :)

@paulirish paulirish changed the title report(redesign): toggle metric descriptions report(redesign): add toggle control to show metric descriptions May 1, 2019
@paulirish paulirish merged commit e613ba4 into master May 1, 2019
@paulirish paulirish deleted the report-ui-metric-desc branch May 1, 2019 02:04
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