-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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: Expand by default passed audit groups containing warnings #6279
report: Expand by default passed audit groups containing warnings #6279
Conversation
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 nice changes 🎉
const isExpanded = passedAuditGroupEl.hasAttribute('open'); | ||
assert.ok(isExpanded, 'Passed audit group with warning should be expanded by default'); | ||
|
||
category.auditRefs = prevAuditRefs; |
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.
What is this line doing? Cleaning up auditRefs? Can this make a deepCopy of category instead so it doesn't modify it for each test (like 'doesnt create a passed section if there were 0 passed'
)? e.g.
const origCategory = sampleResults.reportCategories.find(c => c.id === 'pwa');
const category = JSON.parse(JSON.stringify(origCategory));
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 followed a pattern I saw in the handles markdown in category descriptions a category
test case. Since sampleResults
is being modified, and is initialized once and used in all the tests, I needed to restore the state of the auditRefs
property for the given category.
I see it is also done in the way you suggested here: doesnt create a passed section if there were 0 passed
. So there's two different methods for avoiding unwanted state change. If one is preferred, I can change the other instance to match.
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.
Nice job @hoten! Ace first contribution!
* @return {Element} | ||
*/ | ||
renderPassedAuditsSection(elements) { | ||
renderPassedAuditsSection(elements, expandByDefault) { |
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.
We've learned over time that every boolean
we add to a function method, we regret eventually :)
let's do an object instead const {expandByDefault} = displayOptions
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.
Ah, ok, thanks for the insight.
@@ -316,8 +327,10 @@ class CategoryRenderer { | |||
const manualAudits = auditRefs.filter(audit => audit.result.scoreDisplayMode === 'manual'); | |||
const nonManualAudits = auditRefs.filter(audit => !manualAudits.includes(audit)); | |||
|
|||
/** @type {Object<string, {passed: Array<LH.ReportResult.AuditRef>, failed: Array<LH.ReportResult.AuditRef>, notApplicable: Array<LH.ReportResult.AuditRef>}>} */ | |||
/** @type {Object<string, AuditsByState>} */ | |||
const auditsGroupedByGroup = {}; |
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.
ByState
is very nice, let's rename this much less nice variable name I think I'm responsible for to auditsKeyedByState
too :D
9299422
to
647ae56
Compare
@paulirish is this good to go? |
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.
can you share a screenshot? This looks like it opens up the whole passed group, while the intention of the issue seems to have just been to make the warnings pop up to the top level? @paulirish since he wrote the issue :)
Util.showAsPassed(audit.result)) | ||
.map((audit, i) => this.renderAudit(audit, i)); | ||
Util.showAsPassed(audit.result)); | ||
const passedElements = passedAudits.map((audit, i) => this.renderAudit(audit, i)); |
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.
👍
/** @type {Object<string, {passed: Array<LH.ReportResult.AuditRef>, failed: Array<LH.ReportResult.AuditRef>, notApplicable: Array<LH.ReportResult.AuditRef>}>} */ | ||
const auditsGroupedByGroup = {}; | ||
/** @type {Object<string, AuditsByState>} */ | ||
const auditsKeyedByState = {}; |
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.
we do lose a little bit of info by the rename (and it sounds like the keys will be states, when really it's the keys of the values of the object). Maybe passStatesByGroupId
? scoreStatesByGroupId
? Or something better
* @return {boolean} | ||
*/ | ||
_auditsHaveWarnings(audits) { | ||
return audits.some(group => Boolean(group.result.warnings && group.result.warnings.length)); |
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.
s/group
/audit
?
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. Wonder how my brain did that.
@@ -372,6 +387,7 @@ class CategoryRenderer { | |||
groups.passed.forEach((item, i) => auditGroupElem.appendChild(this.renderAudit(item, i))); | |||
auditGroupElem.classList.add('lh-audit-group--unadorned'); | |||
passedElements.push(auditGroupElem); | |||
if (!expandPassedAudits) expandPassedAudits = this._auditsHaveWarnings(groups.passed); |
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, why is this dependent on previous states of expandPassedAudits
? That's not immediately clear
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.
oh I see, because we collect passed elements, not passed audits. Some other ideas (take or leave them):
- Maybe a comment (
// track if any group has passed audits with warnings
or whatever) andexpandPassedAudits = expandPassedAudits || this._auditsHaveWarnings(groups.passed);
to make it more explicit? - is it worth pulling out the check to just a loop over the passed audits? Or do it up in the
nonManualAudits.forEach
instead? - OR
renderPassedAuditsSection
could handle this, looking for the warning DOM element on any of the passed in elements and opening up the group if found
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.
iterating on point 1 - 2:
// check if any group has passed audits with warnings
let expandPassedAudits = false;
for (const group of [auditsUngrouped, ...Object.values(passStatesByGroupId)]) {
if (expandPassedAudits = this._auditsHaveWarnings(group.passed)) {
break;
}
}
I don't like the last option, b/c it's querying the DOM elements for state that is more readily available elsewhere.
Initial view when there is a warning: @brendankenny Right ... seems the intention as laid out in the ticket differs from what I understood as the task. @paulirish is the above what you expected? |
Admittedly this is different than what the ticket described, but I kind of like this approach. The other UX had some awkwardness about it (repeated audit title, so many bullets). @hwikyounglee any feelings on this? I'd be fine going with what we have here, but I'm cool if you'd prefer a separate block as #5327 described. |
|
I like this approach. |
Let's do that. #6279 (comment) |
Abandoning for #6974. |
Summary
Expands by default passed audit groups, if it contains a warning.
Related Issues/PRs
Fixes #5327