-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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: add PWA category badge gauge #6526
Conversation
margin: 0 4px; | ||
} | ||
|
||
.lh-scores-header .lh-gauge--pwa__wrapper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice if this could be .lh-gauge__wrapper:last-of-type
, but it doesn't work on classes. Open to other ways to do this that don't rely on the pwa wrapper being where it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we really care if it's an .lh-gauge?
couldn't we just do .lh-scores-header > :last-child
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't we just do .lh-scores-header > :last-child ?
we can't because when you don't run the PWA category you don't want a vertical line before the next last-child
in line once the PWA gauge is gone :)
Maybe we should make an explicit divider line class, but this seems fine for now (if/when we ever get another special score gauge we can reevaluate)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course :) forgot about running without pwa.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flushing the two comments I had before I had to run out the door, will be back later but screenshots look nice! :D
*/ | ||
renderScoreGauge(category) { | ||
// Defer to parent-gauge style if category error. | ||
if (category.score === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't decide if I like the explicit documentation that score === null
when it fails or would prefer to play it safe with Number.isFinite
, any insight you used to share with me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any insight you used to share with me?
I used it just because that's what categoryRenderer.renderScoreGauge
uses :)
Looking more into it now, null
is what ReportScoring.arithmeticMean
returns in case of error, and combined with the fact that we haven't seen any issues with it for plain old categoryRenderer
...seems fine?
|
||
const passingGroupIds = this._getPassingGroupIds(category.auditRefs); | ||
let className = 'lh-badged-na'; | ||
if (passingGroupIds.has('pwa-fast-reliable')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to clarify the laughing was on this whole nesting business we need to do, not just this line :)
FWIW, I'd probably find something like
const isReliable = passingGroupIds.has()
const isInstallable = ...
const isOptimized = ...
if (isReliable && isInstallable && isOptimized) className = 'lh-badged-all'
else if (isReliable && isInstallable) className = 'lh-badged-reliable-installable'
...
a bit easier to read, but no biggie
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha, that is significantly easier to read. I was very tired when I wrote all that is my only excuse :)
While you were writing this I was just working on a more css-centric version. What do you think of this instead?
The looooong class names are the only downside. Maybe we can short circuit the BEMness to pick short names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
didn't realize most of the lines were SVG and I was mostly done already sorry! :)
|
||
const passingGroupIds = this._getPassingGroupIds(category.auditRefs); | ||
let className = 'lh-badged-na'; | ||
if (passingGroupIds.has('pwa-fast-reliable')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to clarify the laughing was on this whole nesting business we need to do, not just this line :)
FWIW, I'd probably find something like
const isReliable = passingGroupIds.has()
const isInstallable = ...
const isOptimized = ...
if (isReliable && isInstallable && isOptimized) className = 'lh-badged-all'
else if (isReliable && isInstallable) className = 'lh-badged-reliable-installable'
...
a bit easier to read, but no biggie
<template id="tmpl-lh-gauge--pwa"> | ||
<style> | ||
.lh-gauge--pwa { | ||
width: calc(3 * var(--header-font-size)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there significance to this 3
or just feels about right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there significance to this 3 or just feels about right?
I copied this over from .lh-gauge
since lh-gauge
(and its modifiers) had a bunch of svg-score-gauge-specific properties. Basically it just means 60px
:)
This is one of the properties that make it seem we need a more general "this is a round-ish thing representing the overall category score" name that includes both the gauge we've had and the badge container (though we could just stick with lh-gauge
and move the current gauge stuff down inside).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lh-gauge defines --circle-size: calc(3 * var(--header-font-size));
in its wrapper.
seems good to either do that here too or to move the circle-size
into the .lh-vars
block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems good to either do that here too or to move the
circle-size
into the.lh-vars
block.
after discussion, moved into .lh-vars
block. It makes sense that the gauges should stay the same size and it turns out we were using the same number in a few other places that could benefit from a single definition
display: none; | ||
} | ||
|
||
.lh-badged-na .lh-gauge--pwa--na { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are all just lining up the lh-badged-*
with lh-gauge--pwa--*
right? since the intention is all identical and we would ideally replace something simpler maybe it does make sense to combine them?
💖 Thanks @brendankenny! I think we can use a few more pixels above the sub group title (to make the total pixel 24px). 💖 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm % diff handling of the circle-size custom prop
const categoryGauge = renderer.renderScoreGauge(category); | ||
|
||
// Group gauges that aren't default at the end of the header | ||
if (renderer.renderScoreGauge === categoryRenderer.renderScoreGauge) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm! how does equality on a function work? seems fine though i'm curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does equality on a function work?
it's (shared) on the root prototype, so if a renderer descends from CategoryRenderer
but doesn't override renderScoreGauge
it'll just be the same function object.
I was originally going to do something more complicated with verifying which prototype the function that will be called was defined on, but it doesn't buy anything extra, and considering this is the only special gauge for now, anything much more complicated than a specialized check directly for the pwa renderer would be compounding the silliness.
<template id="tmpl-lh-gauge--pwa"> | ||
<style> | ||
.lh-gauge--pwa { | ||
width: calc(3 * var(--header-font-size)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lh-gauge defines --circle-size: calc(3 * var(--header-font-size));
in its wrapper.
seems good to either do that here too or to move the circle-size
into the .lh-vars
block.
const tmpl = this.dom.cloneTemplate('#tmpl-lh-gauge--pwa', this.templateContext); | ||
const wrapper = /** @type {HTMLAnchorElement} */ (this.dom.find('.lh-gauge--pwa__wrapper', | ||
tmpl)); | ||
wrapper.href = `#${category.id}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it feels like it should have a tooltip. I'll add it to the list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative idea:
Fast and reliable: 3/3, Installable: 3/3, PWA Optimized: 4/6
Part of #6395
A bit hacked together, but it works. Work in earlier PRs keeps the hackiness fairly well contained, though, and it should be easy to revise what's in this initial draft.Currently