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: show disabled checkbox when all/no urls are third-party #9299

Merged
merged 2 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lighthouse-core/report/html/renderer/report-ui-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,11 @@ class ReportUIFeatures {
tablesWithUrls.forEach((tableEl, index) => {
const urlItems = this._getUrlItems(tableEl);
const thirdPartyRows = this._getThirdPartyRows(tableEl, urlItems, this.json.finalUrl);
// If all or none of the rows are 3rd party, no checkbox!
if (thirdPartyRows.size === urlItems.length || !thirdPartyRows.size) return;

// create input box
const filterTemplate = this._dom.cloneTemplate('#tmpl-lh-3p-filter', this._templateContext);
const filterInput = this._dom.find('input', filterTemplate);
const filterInput =
/** @type {HTMLInputElement} */ (this._dom.find('input', filterTemplate));
Copy link
Collaborator

Choose a reason for hiding this comment

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

man it'd really be nice to type this for some basic HTMLXElement inference

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but how often do we even select on just the tagname?

Copy link
Collaborator

Choose a reason for hiding this comment

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

not enough to make me want to put in the effort to do it for real :)

image

const id = `lh-3p-filter-label--${index}`;

filterInput.id = id;
Expand All @@ -265,6 +264,12 @@ class ReportUIFeatures {
this._dom.find('.lh-3p-ui-string', filterTemplate).textContent =
Util.UIStrings.thirdPartyResourcesLabel;

// If all or none of the rows are 3rd party, disable the checkbox.
if (thirdPartyRows.size === urlItems.length || !thirdPartyRows.size) {
filterInput.disabled = true;
filterInput.checked = thirdPartyRows.size === urlItems.length;
}

// Finally, add checkbox to the DOM.
if (!tableEl.parentNode) return; // Keep tsc happy.
tableEl.parentNode.insertBefore(filterTemplate, tableEl);
Expand Down
4 changes: 3 additions & 1 deletion lighthouse-core/report/html/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,12 @@
padding: 6px;
}
.lh-3p-filter-label, .lh-3p-filter-input {
cursor: pointer;
vertical-align: middle;
user-select: none;
}
.lh-3p-filter-input:disabled + .lh-3p-ui-string {
text-decoration: line-through;
}
</style>
<div class="lh-3p-filter">
<label class="lh-3p-filter-label">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,17 @@ describe('ReportUIFeatures', () => {
.toThrowError('query #uses-rel-preconnect .lh-3p-filter-input not found');
});

it('adds no filter for audits with tables containing only third party resources', () => {
const checkboxClassName = 'lh-3p-filter-input';

expect(() => dom.find(`#render-blocking-resources .${checkboxClassName}`, container))
.toThrowError('query #render-blocking-resources .lh-3p-filter-input not found');
it('filter is disabled and checked for when just third party resources', () => {
const filterCheckbox =
dom.find('#render-blocking-resources .lh-3p-filter-input', container);
expect(filterCheckbox.disabled).toEqual(true);
expect(filterCheckbox.checked).toEqual(true);
});

it('adds no filter for audits with tables containing only first party resources', () => {
const checkboxClassName = 'lh-3p-filter-input';

expect(() => dom.find(`#uses-text-compression .${checkboxClassName}`, container))
.toThrowError('query #uses-text-compression .lh-3p-filter-input not found');
it('filter is disabled and not checked for just first party resources', () => {
const filterCheckbox = dom.find('#uses-text-compression .lh-3p-filter-input', container);
expect(filterCheckbox.disabled).toEqual(true);
expect(filterCheckbox.checked).toEqual(false);
});
});
});
Expand Down