-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
clients(psi): render treemap button #12570
Changes from 5 commits
30f8cf6
7b13b4a
4e0de5f
d2e0275
5abdfe6
02d21df
5c67661
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,7 @@ | |
*/ | ||
'use strict'; | ||
|
||
/* globals self DOM PerformanceCategoryRenderer Util I18n DetailsRenderer ElementScreenshotRenderer */ | ||
|
||
/* globals self DOM PerformanceCategoryRenderer Util I18n DetailsRenderer ElementScreenshotRenderer ReportUIFeatures */ | ||
|
||
/** | ||
* Returns all the elements that PSI needs to render the report | ||
|
@@ -81,6 +80,9 @@ function prepareLabData(LHResult, document) { | |
const clonedScoreTemplate = dom.cloneTemplate('#tmpl-lh-scorescale', dom.document()); | ||
const scoreScaleEl = dom.find('.lh-scorescale', clonedScoreTemplate); | ||
|
||
const reportUIFeatures = new ReportUIFeatures(dom); | ||
reportUIFeatures.json = lhResult; | ||
|
||
/** @param {HTMLElement} reportEl */ | ||
const installFeatures = (reportEl) => { | ||
if (fullPageScreenshot) { | ||
|
@@ -109,6 +111,17 @@ function prepareLabData(LHResult, document) { | |
ElementScreenshotRenderer.installFullPageScreenshot( | ||
screenshotEl, fullPageScreenshot.screenshot); | ||
} | ||
|
||
const showTreemapApp = | ||
lhResult.audits['script-treemap-data'] && lhResult.audits['script-treemap-data'].details; | ||
if (showTreemapApp) { | ||
reportUIFeatures.addButton({ | ||
container: reportEl.querySelector('.lh-audit-group--metrics'), | ||
text: Util.i18n.strings.viewTreemapLabel, | ||
icon: 'treemap', | ||
onClick: () => ReportUIFeatures.openTreemap(lhResult, 'url'), | ||
}); | ||
} | ||
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. more copy/paste for now. |
||
}; | ||
|
||
return {scoreGaugeEl, perfCategoryEl, finalScreenshotDataUri, scoreScaleEl, installFeatures}; | ||
|
@@ -126,6 +139,13 @@ function _getFinalScreenshot(perfCategory) { | |
return details.data; | ||
} | ||
|
||
// Defined by lib/file-namer.js, but that file does not exist in PSI. PSI doesn't use it, but | ||
// needs some basic definition so closure compiler accepts report-ui-features.js | ||
// @ts-expect-error | ||
connorjclark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// eslint-disable-next-line no-unused-vars | ||
function getFilenamePrefix(lhr) { | ||
} | ||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = prepareLabData; | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,14 +181,14 @@ class ReportUIFeatures { | |
} | ||
|
||
/** | ||
* @param {{text: string, icon?: string, onClick: () => void}} opts | ||
* @param {{container?: Element, text: string, icon?: string, onClick: () => void}} opts | ||
*/ | ||
addButton(opts) { | ||
const metricsEl = this._document.querySelector('.lh-audit-group--metrics'); | ||
connorjclark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Not supported without metrics group. | ||
const containerEl = opts.container || metricsEl; | ||
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. report-ui-features doesn't have a reference to the root report 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. this would make a great comment on the (I stared at the container |
||
if (!metricsEl) return; | ||
|
||
let buttonsEl = metricsEl.querySelector('.lh-buttons'); | ||
let buttonsEl = containerEl.querySelector('.lh-buttons'); | ||
if (!buttonsEl) buttonsEl = this._dom.createChildOf(metricsEl, 'div', 'lh-buttons'); | ||
|
||
const classes = [ | ||
|
@@ -551,7 +551,6 @@ class ReportUIFeatures { | |
* Opens a new tab to the treemap app and sends the JSON results using postMessage. | ||
* @param {LH.Result} json | ||
* @param {'postMessage'|'url'} method | ||
* @protected | ||
*/ | ||
static openTreemap(json, method = 'postMessage') { | ||
const treemapData = json.audits['script-treemap-data'].details; | ||
|
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.
this class's scope is starting to get scary now 😆
my trail of verification that this doesn't do anything we don't want it to
addButton
I wonder why it's not static.initFeatures
does the heavy lifting.reportUIFeatures.json =
needed then? AFAICT it isn'tThere 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.
yes, definitely :) it needs a refactor (e.g.
addButton
could just be ondom
itself or inperformanceCategoryRenderer
if we really want it scoped just toaddMetricsSectionButton
), but since I was the one who suggested not doing #12327 before the 8.0 release I figured this was fair and we can fix it up afterwards :)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.
this seems right
And we could make
addButton
static now and passdom
in (initFeatures
would just pass it along too), but that might take concurrent DevTools changes?