-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
core(lhr): rename perf-hint, perf-info, etc #5102
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
08eab5d
core(lhr): rename perf-hint, etc.
paulirish cc2ae7c
final varname renames within the JS
paulirish c249d14
fix merge
paulirish cae32d6
feedback.
paulirish 13e3dc4
lint
paulirish eb02a7f
Merge branch 'master' into perfhint-renames
paulirish c99fe08
it fits.
paulirish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,24 +13,24 @@ class PerformanceCategoryRenderer extends CategoryRenderer { | |
* @return {!Element} | ||
*/ | ||
_renderMetric(audit) { | ||
const tmpl = this.dom.cloneTemplate('#tmpl-lh-perf-metric', this.templateContext); | ||
const element = this.dom.find('.lh-perf-metric', tmpl); | ||
const tmpl = this.dom.cloneTemplate('#tmpl-lh-metric', this.templateContext); | ||
const element = this.dom.find('.lh-metric', tmpl); | ||
element.id = audit.result.name; | ||
// FIXME(paulirish): currently this sets a 'lh-perf-metric--fail' class on error'd audits | ||
element.classList.add(`lh-perf-metric--${Util.calculateRating(audit.result.score)}`); | ||
// FIXME(paulirish): currently this sets a 'lh-metric--fail' class on error'd audits | ||
element.classList.add(`lh-metric--${Util.calculateRating(audit.result.score)}`); | ||
|
||
const titleEl = this.dom.find('.lh-perf-metric__title', tmpl); | ||
const titleEl = this.dom.find('.lh-metric__title', tmpl); | ||
titleEl.textContent = audit.result.description; | ||
|
||
const valueEl = this.dom.find('.lh-perf-metric__value', tmpl); | ||
const valueEl = this.dom.find('.lh-metric__value', tmpl); | ||
valueEl.textContent = audit.result.displayValue; | ||
|
||
const descriptionEl = this.dom.find('.lh-perf-metric__description', tmpl); | ||
const descriptionEl = this.dom.find('.lh-metric__description', tmpl); | ||
descriptionEl.appendChild(this.dom.convertMarkdownLinkSnippets(audit.result.helpText)); | ||
|
||
if (audit.result.error) { | ||
element.classList.remove(`lh-perf-metric--fail`); | ||
element.classList.add(`lh-perf-metric--error`); | ||
element.classList.remove(`lh-metric--fail`); | ||
element.classList.add(`lh-metric--error`); | ||
descriptionEl.textContent = ''; | ||
valueEl.textContent = 'Error!'; | ||
const tooltip = this.dom.createChildOf(descriptionEl, 'span', 'lh-error-tooltip-content'); | ||
|
@@ -45,19 +45,17 @@ class PerformanceCategoryRenderer extends CategoryRenderer { | |
* @param {number} scale | ||
* @return {!Element} | ||
*/ | ||
_renderPerfHintAudit(audit, scale) { | ||
const tooltipAttrs = {title: audit.result.displayValue}; | ||
|
||
_renderOpportunity(audit, scale) { | ||
const element = this.dom.createElement('details', [ | ||
'lh-perf-hint', | ||
`lh-perf-hint--${Util.calculateRating(audit.result.score)}`, | ||
'lh-load-opportunity', | ||
`lh-load-opportunity--${Util.calculateRating(audit.result.score)}`, | ||
'lh-expandable-details', | ||
].join(' ')); | ||
element.id = audit.result.name; | ||
|
||
const summary = this.dom.createChildOf(element, 'summary', 'lh-perf-hint__summary ' + | ||
'lh-expandable-details__summary'); | ||
const titleEl = this.dom.createChildOf(summary, 'div', 'lh-perf-hint__title'); | ||
const summary = this.dom.createChildOf(element, 'summary', 'lh-load-opportunity__summary ' + | ||
'lh-expandable-details__summary'); | ||
const titleEl = this.dom.createChildOf(summary, 'div', 'lh-load-opportunity__title'); | ||
titleEl.textContent = audit.result.description; | ||
|
||
this.dom.createChildOf(summary, 'div', 'lh-toggle-arrow', {title: 'See resources'}); | ||
|
@@ -70,32 +68,35 @@ class PerformanceCategoryRenderer extends CategoryRenderer { | |
|
||
const details = audit.result.details; | ||
const summaryInfo = /** @type {!DetailsRenderer.OpportunitySummary} | ||
*/ (details && details.summary); | ||
*/ (details && details.summary); | ||
// eslint-disable-next-line no-console | ||
console.assert(summaryInfo, 'Missing `summary` for perf-hint audit'); | ||
console.assert(summaryInfo, 'Missing `summary` for load-opportunities audit'); | ||
// eslint-disable-next-line no-console | ||
console.assert(typeof summaryInfo.wastedMs === 'number', | ||
'Missing numeric `summary.wastedMs` for perf-hint audit'); | ||
'Missing numeric `summary.wastedMs` for load-opportunities audit'); | ||
if (!summaryInfo || !summaryInfo.wastedMs) { | ||
return element; | ||
} | ||
|
||
const sparklineContainerEl = this.dom.createChildOf(summary, 'div', 'lh-perf-hint__sparkline', | ||
tooltipAttrs); | ||
const elemAttrs = {title: audit.result.displayValue}; | ||
const sparklineContainerEl = this.dom.createChildOf(summary, 'div', | ||
'lh-load-opportunity__sparkline', elemAttrs); | ||
const sparklineEl = this.dom.createChildOf(sparklineContainerEl, 'div', 'lh-sparkline'); | ||
const sparklineBarEl = this.dom.createChildOf(sparklineEl, 'div', 'lh-sparkline__bar'); | ||
sparklineBarEl.style.width = summaryInfo.wastedMs / scale * 100 + '%'; | ||
|
||
const statsEl = this.dom.createChildOf(summary, 'div', 'lh-perf-hint__stats', tooltipAttrs); | ||
const statsMsEl = this.dom.createChildOf(statsEl, 'div', 'lh-perf-hint__primary-stat'); | ||
const statsEl = this.dom.createChildOf(summary, 'div', 'lh-load-opportunity__stats', elemAttrs); | ||
const statsMsEl = this.dom.createChildOf(statsEl, 'div', 'lh-load-opportunity__primary-stat'); | ||
statsMsEl.textContent = Util.formatMilliseconds(summaryInfo.wastedMs); | ||
|
||
if (summaryInfo.wastedBytes) { | ||
const statsKbEl = this.dom.createChildOf(statsEl, 'div', 'lh-perf-hint__secondary-stat'); | ||
const statsKbEl = this.dom.createChildOf(statsEl, 'div', | ||
'lh-load-opportunity__secondary-stat'); | ||
statsKbEl.textContent = Util.formatBytesToKB(summaryInfo.wastedBytes); | ||
} | ||
|
||
const descriptionEl = this.dom.createChildOf(element, 'div', 'lh-perf-hint__description'); | ||
const descriptionEl = this.dom.createChildOf(element, 'div', | ||
'lh-load-opportunity__description'); | ||
descriptionEl.appendChild(this.dom.convertMarkdownLinkSnippets(audit.result.helpText)); | ||
|
||
if (audit.result.debugString) { | ||
|
@@ -119,16 +120,16 @@ class PerformanceCategoryRenderer extends CategoryRenderer { | |
this.createPermalinkSpan(element, category.id); | ||
element.appendChild(this.renderCategoryScore(category)); | ||
|
||
const metricAudits = category.audits.filter(audit => audit.group === 'perf-metric'); | ||
const metricAuditsEl = this.renderAuditGroup(groups['perf-metric'], {expandable: false}); | ||
const metricAudits = category.audits.filter(audit => audit.group === 'metrics'); | ||
const metricAuditsEl = this.renderAuditGroup(groups['metrics'], {expandable: false}); | ||
|
||
// Metrics | ||
const keyMetrics = metricAudits.filter(a => a.weight >= 3); | ||
const otherMetrics = metricAudits.filter(a => a.weight < 3); | ||
|
||
const metricsBoxesEl = this.dom.createChildOf(metricAuditsEl, 'div', 'lh-metrics-container'); | ||
const metricsColumn1El = this.dom.createChildOf(metricsBoxesEl, 'div', 'lh-metrics-column'); | ||
const metricsColumn2El = this.dom.createChildOf(metricsBoxesEl, 'div', 'lh-metrics-column'); | ||
const metricsBoxesEl = this.dom.createChildOf(metricAuditsEl, 'div', 'lh-metric-container'); | ||
const metricsColumn1El = this.dom.createChildOf(metricsBoxesEl, 'div', 'lh-metric-column'); | ||
const metricsColumn2El = this.dom.createChildOf(metricsBoxesEl, 'div', 'lh-metric-column'); | ||
|
||
keyMetrics.forEach(item => { | ||
metricsColumn1El.appendChild(this._renderMetric(item)); | ||
|
@@ -153,30 +154,30 @@ class PerformanceCategoryRenderer extends CategoryRenderer { | |
element.appendChild(metricAuditsEl); | ||
|
||
// Opportunities | ||
const hintAudits = category.audits | ||
.filter(audit => audit.group === 'perf-hint' && audit.result.score < 1) | ||
const oppAudits = category.audits | ||
.filter(audit => audit.group === 'load-opportunities' && audit.result.score < 1) | ||
.sort((auditA, auditB) => auditB.result.rawValue - auditA.result.rawValue); | ||
if (hintAudits.length) { | ||
const maxWaste = Math.max(...hintAudits.map(audit => audit.result.rawValue)); | ||
if (oppAudits.length) { | ||
const maxWaste = Math.max(...oppAudits.map(audit => audit.result.rawValue)); | ||
const scale = Math.ceil(maxWaste / 1000) * 1000; | ||
const hintAuditsEl = this.renderAuditGroup(groups['perf-hint'], {expandable: false}); | ||
hintAudits.forEach(item => hintAuditsEl.appendChild(this._renderPerfHintAudit(item, scale))); | ||
hintAuditsEl.open = true; | ||
element.appendChild(hintAuditsEl); | ||
const groupEl = this.renderAuditGroup(groups['load-opportunities'], {expandable: false}); | ||
oppAudits.forEach(item => groupEl.appendChild(this._renderOpportunity(item, scale))); | ||
groupEl.open = true; | ||
element.appendChild(groupEl); | ||
} | ||
|
||
// Diagnostics | ||
const infoAudits = category.audits | ||
.filter(audit => audit.group === 'perf-info' && audit.result.score < 1); | ||
if (infoAudits.length) { | ||
const infoAuditsEl = this.renderAuditGroup(groups['perf-info'], {expandable: false}); | ||
infoAudits.forEach(item => infoAuditsEl.appendChild(this.renderAudit(item))); | ||
infoAuditsEl.open = true; | ||
element.appendChild(infoAuditsEl); | ||
const diagnosticAudits = category.audits | ||
.filter(audit => audit.group === 'diagnostics' && audit.result.score < 1); | ||
if (diagnosticAudits.length) { | ||
const diagsEl = this.renderAuditGroup(groups['diagnostics'], {expandable: false}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant groupEl here too :) |
||
diagnosticAudits.forEach(item => diagsEl.appendChild(this.renderAudit(item))); | ||
diagsEl.open = true; | ||
element.appendChild(diagsEl); | ||
} | ||
|
||
const passedElements = category.audits | ||
.filter(audit => (audit.group === 'perf-hint' || audit.group === 'perf-info') && | ||
.filter(audit => (audit.group === 'load-opportunities' || audit.group === 'diagnostics') && | ||
audit.result.score === 1) | ||
.map(audit => this.renderAudit(audit)); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
does
opportunityAudits
not fit? :D