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: refactor rendering of top-level failed/passing/etc sections #6460

Merged
merged 3 commits into from
Nov 4, 2018

Conversation

brendankenny
Copy link
Member

@brendankenny brendankenny commented Nov 2, 2018

This makes the process of grouping under failed/passing/manual/notApplicable and then again under audit groups a lot easier to understand. It also sets the stage for making a new pwa-category-renderer.js (where they aren't split into failed/passing/etc) much easier.

Before the renderer was mixing up levels of failed/passing/notApplicable and audit groups, putting those states inside groups, then ending up rendering the opposite way (groups inside failed/passing/notApplicable). Manual audits were handled separately, even though it's just another of these states.

Instead, this new code sorts by state, then renders groups in each of them. The code is just a little shorter (longer with new tests), but it's hopefully easier to follow.

Importantly, this makes for an easy interface for renderTopLevelSection (which performance-category-renderer now uses) and renderUnexpandableTopLevelSection (which the pwa one will use).

It also lets us get rid of _getTotalAuditsLength and allows easy numbering across groups now.

The numbering is the only thing that has changed from master (so no changed tests, only new ones). edit: also (collapsed) passed audits in the performance section are now grouped like they are in other categories

@brendankenny
Copy link
Member Author

also, we can pick a different name than "top-level section". I couldn't think of one (and overloading "group" seems like a mistake in retrospect :)

.querySelector('.lh-audit-group--manual .lh-audit-group__description').textContent;
// may need to be adjusted if description includes a link at the beginning
assert.ok(description.startsWith(pwaCategory.manualDescription.substring(0, 20)),
'no manual description');
Copy link
Member Author

@brendankenny brendankenny Nov 2, 2018

Choose a reason for hiding this comment

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

we weren't asserting that there was a manual description in the report before

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.

This is so great. way cleaner.

*/
_getTotalAuditsLength(elements) {
Copy link
Member

Choose a reason for hiding this comment

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

so happy you managed to nuke this. 🙌

auditGroupElem.appendChild(this.renderAudit(audit, i));
});
return auditGroupElem;
renderTopLevelSection(sectionId, auditRefs, groupDefinitions, description) {
Copy link
Member

Choose a reason for hiding this comment

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

renderCategorySection ?

Copy link
Member

Choose a reason for hiding this comment

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

clump?

Copy link
Member

Choose a reason for hiding this comment

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

and maybe a little ascii diagram of what accessibility section looks like wrt groups & clumps.

Copy link
Member Author

Choose a reason for hiding this comment

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

done and done

element.appendChild(manualEl);
}
// Render each section.
for (const [sectionIdStr, sectionRefs] of Object.entries(sections)) {
Copy link
Member

Choose a reason for hiding this comment

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

We're relying on order of Object.entries(), right? is that safe?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're relying on order of Object.entries(), right? is that safe?

well, there's safe and then there's safe :)

switched to a Map

const expandable = true;
const elements = this._renderGroupedAudits(auditRefs, groupDefinitions, {expandable});

const sectionInfo = {
Copy link
Member

Choose a reason for hiding this comment

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

move this outside?

Copy link
Member Author

Choose a reason for hiding this comment

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

move this outside?

done

/**
* Display info per top-level clump. Define on class to avoid race with Util init.
*/
get _clumpInfo() {
Copy link
Member Author

Choose a reason for hiding this comment

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

kind of annoyingly this has to be defined on the class so that Util is available (not a problem in regular use, but Util isn't globally defined yet when this file is required in tests)

Copy link
Collaborator

Choose a reason for hiding this comment

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

this feels like a name that a certain someone would complain conveys no information 😉

_clumpDisplayClasses
_clumpDisplayAttributes
_clumpDisplayInfo at least?

Copy link
Member Author

Choose a reason for hiding this comment

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

this feels like a name that a certain someone would complain conveys no information

lulz I'm always in favor of more descriptive names. Switching to _clumpDisplayInfo though I can switch it more :)

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.

so great. love it.

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.

looks great!

are we really going to go with "clump" though? 😆 #smooshgatev2

/**
* Display info per top-level clump. Define on class to avoid race with Util init.
*/
get _clumpInfo() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this feels like a name that a certain someone would complain conveys no information 😉

_clumpDisplayClasses
_clumpDisplayAttributes
_clumpDisplayInfo at least?

const grouped = new Map();

// Add audits without a group first so they will appear first.
const notAGroup = 'NotAGroup';
Copy link
Collaborator

Choose a reason for hiding this comment

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

😆

* @param {LH.ReportResult.AuditRef} auditRef
* @return {TopLevelClumpId}
*/
_getClumpIdForAuditRef(auditRef) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

love this fn!

auditGroupElem.appendChild(this.renderAudit(audit, i));
});
return auditGroupElem;
renderClump(clumpId, auditRefs, groupDefinitions, description) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this feels a bit many arguments to remember what all the args are for in order, time for an object?

Copy link
Member Author

Choose a reason for hiding this comment

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

time for an object?

done

@brendankenny
Copy link
Member Author

are we really going to go with "clump" though?

haha, well, @paulirish really didn't like my suggestions, and we couldn't keep calling them groups because that was confusing with the other (config) groups... So we looked at a thesaurus and that one was sufficiently funny.

Maybe a name will more naturally come out later.

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.

3 participants