@@ -6,10 +6,8 @@ import '../../../../ui/components/icon_button/icon_button.js';
66import './Table.js' ;
77
88import * as i18n from '../../../../core/i18n/i18n.js' ;
9- import type {
10- ImageDeliveryInsightModel , ImageOptimizationType , OptimizableImage } from
11- '../../../../models/trace/insights/ImageDelivery.js' ;
12- import * as Trace from '../../../../models/trace/trace.js' ;
9+ import type { ImageDeliveryInsightModel } from '../../../../models/trace/insights/ImageDelivery.js' ;
10+ import type * as Trace from '../../../../models/trace/trace.js' ;
1311import * as LitHtml from '../../../../ui/lit-html/lit-html.js' ;
1412import type * as Overlays from '../../overlays/overlays.js' ;
1513
@@ -20,10 +18,6 @@ import type {TableDataRow} from './Table.js';
2018const { html} = LitHtml ;
2119
2220const UIStrings = {
23- /**
24- * @description Column header for a table column containing network requests for images that are not sized correctly for how they are displayed on the page.
25- */
26- sizeAppropriately : 'Size appropriately' ,
2721 /**
2822 * @description Column header for a table column containing network requests for images which can improve their file size (e.g. use a different format, increase compression, etc).
2923 */
@@ -38,6 +32,8 @@ const UIStrings = {
3832const str_ = i18n . i18n . registerUIStrings ( 'panels/timeline/components/insights/ImageDelivery.ts' , UIStrings ) ;
3933const i18nString = i18n . i18n . getLocalizedString . bind ( undefined , str_ ) ;
4034
35+ const MAX_REQUESTS = 6 ;
36+
4137export class ImageDelivery extends BaseInsightComponent < ImageDeliveryInsightModel > {
4238 static override readonly litTagName = LitHtml . literal `devtools-performance-image-delivery` ;
4339 override internalName : string = 'image-delivery' ;
@@ -59,88 +55,48 @@ export class ImageDelivery extends BaseInsightComponent<ImageDeliveryInsightMode
5955 } ;
6056 }
6157
62- #getTopImagesAsRows(
63- optimizableImages : OptimizableImage [ ] , typeFilter : ( type : ImageOptimizationType ) => boolean ,
64- showDimensions ?: boolean ) : TableDataRow [ ] {
65- const MAX_REQUESTS = 3 ;
58+ override renderContent ( ) : LitHtml . LitTemplate {
59+ if ( ! this . model ) {
60+ return LitHtml . nothing ;
61+ }
62+
63+ const optimizableImages = this . model . optimizableImages ;
64+
6665 const topImages =
67- optimizableImages . filter ( image => image . optimizations . some ( o => typeFilter ( o . type ) ) )
68- . sort ( ( a , b ) => b . request . args . data . decodedBodyLength - a . request . args . data . decodedBodyLength ) ;
66+ optimizableImages . sort ( ( a , b ) => b . request . args . data . decodedBodyLength - a . request . args . data . decodedBodyLength ) ;
6967
7068 const remaining = topImages . splice ( MAX_REQUESTS ) ;
71-
7269 const rows : TableDataRow [ ] = topImages . map ( image => ( {
73- values : [
74- imageRef (
75- image . request ,
76- showDimensions ? image . largestImagePaint : undefined ,
77- ) ,
78- ] ,
70+ values : [ imageRef ( image . request ) ] ,
7971 overlays : [ this . #createOverlayForRequest( image . request ) ] ,
8072 } ) ) ;
8173
8274 if ( remaining . length > 0 ) {
83- const value = remaining . length > 1 ? i18nString ( UIStrings . others , { PH1 : remaining . length } ) :
84- imageRef (
85- remaining [ 0 ] . request ,
86- showDimensions ? remaining [ 0 ] . largestImagePaint : undefined ,
87- ) ;
75+ const value =
76+ remaining . length > 1 ? i18nString ( UIStrings . others , { PH1 : remaining . length } ) : imageRef ( remaining [ 0 ] . request ) ;
8877 rows . push ( {
8978 values : [ value ] ,
9079 overlays : remaining . map ( r => this . #createOverlayForRequest( r . request ) ) ,
9180 } ) ;
9281 }
9382
94- return rows ;
95- }
96-
97- override renderContent ( ) : LitHtml . LitTemplate {
98- if ( ! this . model ) {
83+ if ( ! rows . length ) {
9984 return LitHtml . nothing ;
10085 }
10186
102- const optimizableImages = this . model . optimizableImages ;
103-
104- const sections = [ ] ;
105-
106- const responsiveSizeRows = this . #getTopImagesAsRows(
107- optimizableImages , type => type === Trace . Insights . Models . ImageDelivery . ImageOptimizationType . RESPONSIVE_SIZE ,
108- true ) ;
109- if ( responsiveSizeRows . length ) {
110- // clang-format off
111- sections . push ( html `
112- < div class ="insight-section ">
113- < devtools-performance-table
114- .data =${ {
115- insight : this ,
116- headers : [ i18nString ( UIStrings . sizeAppropriately ) ] ,
117- rows : responsiveSizeRows ,
118- } } >
119- </ devtools-performance-table >
120- </ div >
121- ` ) ;
122- // clang-format on
123- }
124-
125- const optimizeFormatRows = this . #getTopImagesAsRows(
126- optimizableImages , type => type !== Trace . Insights . Models . ImageDelivery . ImageOptimizationType . RESPONSIVE_SIZE ) ;
127- if ( optimizeFormatRows . length ) {
128- // clang-format off
129- sections . push ( html `
130- < div class ="insight-section ">
131- < devtools-performance-table
132- .data =${ {
133- insight : this ,
134- headers : [ i18nString ( UIStrings . optimizeFile ) ] ,
135- rows : optimizeFormatRows ,
136- } } >
137- </ devtools-performance-table >
138- </ div >
139- ` ) ;
140- // clang-format on
141- }
142-
143- return html `${ sections } ` ;
87+ // clang-format off
88+ return html `
89+ < div class ="insight-section ">
90+ < devtools-performance-table
91+ .data =${ {
92+ insight : this ,
93+ headers : [ i18nString ( UIStrings . optimizeFile ) ] ,
94+ rows,
95+ } } >
96+ </ devtools-performance-table >
97+ </ div >
98+ ` ;
99+ // clang-format on
144100 }
145101}
146102
0 commit comments