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: Expand by default passed audit groups containing warnings #6279

Closed

Conversation

connorjclark
Copy link
Collaborator

Summary
Expands by default passed audit groups, if it contains a warning.

Related Issues/PRs
Fixes #5327

Copy link
Member

@exterkamp exterkamp left a 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;
Copy link
Member

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));

Copy link
Collaborator Author

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.

Copy link
Collaborator

@patrickhulce patrickhulce left a 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) {
Copy link
Collaborator

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

Copy link
Collaborator Author

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 = {};
Copy link
Collaborator

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

@connorjclark connorjclark force-pushed the issue-5327-expand-passed-audits-group-with-warnings branch from 9299422 to 647ae56 Compare October 15, 2018 21:13
@connorjclark
Copy link
Collaborator Author

@paulirish is this good to go?

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.

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));
Copy link
Member

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 = {};
Copy link
Member

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));
Copy link
Member

Choose a reason for hiding this comment

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

s/group/audit?

Copy link
Collaborator Author

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);
Copy link
Member

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

Copy link
Member

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) and expandPassedAudits = 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

Copy link
Collaborator Author

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.

@connorjclark
Copy link
Collaborator Author

connorjclark commented Oct 23, 2018

Initial view when there is a warning:
image

@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?

@paulirish
Copy link
Member

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.

@hwikyounglee
Copy link

  • I like the aspect of attaching warnings to each audit.
  • What's bugging me at the moment are 1) 'expanding the passed audits (could be a long list)' when there's a warning, 2) the row shows the green checkmark (passing) but it has a warning (is it truly passing or not)
  • For audits with warnings, would it make sense to group them in a separate bucket (e.g. "Audits with warning") rather than listing them under 'Passed audits'?

@connorjclark
Copy link
Collaborator Author

  • For audits with warnings, would it make sense to group them in a separate bucket (e.g. "Audits with warning") rather than listing them under 'Passed audits'?

I like this approach.

@paulirish
Copy link
Member

Let's do that. #6279 (comment)

@connorjclark
Copy link
Collaborator Author

Abandoning for #6974.

@connorjclark connorjclark deleted the issue-5327-expand-passed-audits-group-with-warnings branch July 11, 2019 23:12
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.

None yet

6 participants