-
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(details-renderer): snippet details renderer type #6999
Changes from 19 commits
12d56af
281791d
3eb8c65
68eb06a
60fbb1f
e2eab1d
8aa311d
7de63a0
557f7dc
6585304
983cd38
e0648de
0948b4f
e200a53
f64c552
092725a
fcbd748
193a6d8
9529f91
721f15d
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,7 +16,7 @@ | |
*/ | ||
'use strict'; | ||
|
||
/* globals self CriticalRequestChainRenderer Util URL */ | ||
/* globals self CriticalRequestChainRenderer SnippetRenderer Util URL */ | ||
|
||
/** @typedef {import('./dom.js')} DOM */ | ||
/** @typedef {LH.Audit.Details.Opportunity} OpportunityDetails */ | ||
|
@@ -43,7 +43,7 @@ class DetailsRenderer { | |
} | ||
|
||
/** | ||
* @param {DetailsJSON|OpportunityDetails} details | ||
* @param {DetailsJSON|OpportunityDetails|LH.Audit.Details.Snippet} details | ||
* @return {Element|null} | ||
*/ | ||
render(details) { | ||
|
@@ -68,6 +68,15 @@ class DetailsRenderer { | |
case 'table': | ||
// @ts-ignore - TODO(bckenny): Fix type hierarchy | ||
return this._renderTable(/** @type {TableDetailsJSON} */ (details)); | ||
case 'list': | ||
return this._renderList( | ||
// @ts-ignore - TODO(bckenny): Fix type hierarchy | ||
/** @type {LH.Audit.Details.List} */ (details) | ||
); | ||
case 'snippet': | ||
return SnippetRenderer.render(this._dom, this._templateContext, | ||
// @ts-ignore | ||
/** @type {LH.Audit.Details.Snippet} */ (details), this); | ||
case 'code': | ||
return this._renderCode(/** @type {DetailsJSON} */ (details)); | ||
case 'node': | ||
|
@@ -210,6 +219,21 @@ class DetailsRenderer { | |
return element; | ||
} | ||
|
||
/** | ||
* @param {LH.Audit.Details.List} details | ||
* @returns {Element} | ||
*/ | ||
_renderList(details) { | ||
const listContainer = this._dom.createElement('div', 'lh-list'); | ||
|
||
details.items.forEach(item => { | ||
// @ts-ignore TODO(bckenny): this can never be null | ||
listContainer.appendChild(this.render(item)); | ||
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. rather than call |
||
}); | ||
|
||
return listContainer; | ||
} | ||
|
||
/** | ||
* @param {TableDetailsJSON} details | ||
* @return {Element} | ||
|
@@ -455,6 +479,12 @@ if (typeof module !== 'undefined' && module.exports) { | |
}} TableDetailsJSON | ||
*/ | ||
|
||
/** @typedef {{ | ||
type: string, | ||
items: Array<DetailsJSON> | ||
}} ListDetailsJSON | ||
*/ | ||
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 think this can be deleted? 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. Yup! |
||
|
||
/** @typedef {{ | ||
type: string, | ||
value: string, | ||
|
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.
let's not add
snippet
here (it's just going to be immediately removed anyways)