Skip to content

Commit 71c991a

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Move insight "shouldShow" logic from component to model
CLSCulprits is still doing this in the component, left out here since it is a non-trivial refactor. Bug: 371615739 Change-Id: I96a3c1d7de35d8e84f125a4ee8113a64d3a8752b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6040099 Reviewed-by: Paul Irish <[email protected]> Commit-Queue: Connor Clark <[email protected]>
1 parent 052d1c7 commit 71c991a

27 files changed

+97
-60
lines changed

front_end/models/trace/insights/CLSCulprits.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,14 @@ function getFontRootCauses(
420420
return rootCausesByShift;
421421
}
422422

423-
function finalize(partialModel: Omit<CLSCulpritsInsightModel, 'title'|'description'|'category'>):
423+
function finalize(partialModel: Omit<CLSCulpritsInsightModel, 'title'|'description'|'category'|'shouldShow'>):
424424
CLSCulpritsInsightModel {
425425
return {
426426
title: i18nString(UIStrings.title),
427427
description: i18nString(UIStrings.description),
428428
category: InsightCategory.CLS,
429+
// TODO: getTopCulprits in component needs to move to model so this can be set here.
430+
shouldShow: true,
429431
...partialModel,
430432
};
431433
}

front_end/models/trace/insights/DocumentLatency.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,19 @@ function getCompressionSavings(request: Types.Events.SyntheticNetworkRequest): n
119119
return estimatedSavings < IGNORE_THRESHOLD_IN_BYTES ? 0 : estimatedSavings;
120120
}
121121

122-
function finalize(partialModel: Omit<DocumentLatencyInsightModel, 'title'|'description'|'category'>):
122+
function finalize(partialModel: Omit<DocumentLatencyInsightModel, 'title'|'description'|'category'|'shouldShow'>):
123123
DocumentLatencyInsightModel {
124+
let hasFailure = false;
125+
if (partialModel.data) {
126+
hasFailure = partialModel.data.redirectDuration > 0 || partialModel.data.serverResponseTooSlow ||
127+
partialModel.data.uncompressedResponseBytes > 0;
128+
}
129+
124130
return {
125131
title: i18nString(UIStrings.title),
126132
description: i18nString(UIStrings.description),
127133
category: InsightCategory.ALL,
134+
shouldShow: hasFailure,
128135
...partialModel,
129136
};
130137
}

front_end/models/trace/insights/FontDisplay.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ export type FontDisplayInsightModel = InsightModel<{
3434
}>,
3535
}>;
3636

37-
function finalize(partialModel: Omit<FontDisplayInsightModel, 'title'|'description'|'category'>):
37+
function finalize(partialModel: Omit<FontDisplayInsightModel, 'title'|'description'|'category'|'shouldShow'>):
3838
FontDisplayInsightModel {
3939
return {
4040
title: i18nString(UIStrings.title),
4141
description: i18nString(UIStrings.description),
4242
category: InsightCategory.INP,
43+
shouldShow: Boolean(partialModel.fonts.find(font => font.wastedTime > 0)),
4344
...partialModel,
4445
};
4546
}

front_end/models/trace/insights/ImageDelivery.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ export type ImageDeliveryInsightModel = InsightModel<{
7575
optimizableImages: OptimizableImage[],
7676
}>;
7777

78-
function finalize(partialModel: Omit<ImageDeliveryInsightModel, 'title'|'description'|'category'>):
78+
function finalize(partialModel: Omit<ImageDeliveryInsightModel, 'title'|'description'|'category'|'shouldShow'>):
7979
ImageDeliveryInsightModel {
8080
return {
8181
title: i18nString(UIStrings.title),
8282
description: i18nString(UIStrings.description),
8383
category: InsightCategory.LCP,
84+
shouldShow: partialModel.optimizableImages.length > 0,
8485
...partialModel,
8586
relatedEvents: partialModel.optimizableImages.map(image => image.request),
8687
};

front_end/models/trace/insights/InteractionToNextPaint.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ export type INPInsightModel = InsightModel<{
3232
highPercentileInteractionEvent?: SyntheticInteractionPair,
3333
}>;
3434

35-
function finalize(partialModel: Omit<INPInsightModel, 'title'|'description'|'category'>): INPInsightModel {
35+
function finalize(partialModel: Omit<INPInsightModel, 'title'|'description'|'category'|'shouldShow'>): INPInsightModel {
3636
return {
3737
title: i18nString(UIStrings.title),
3838
description: i18nString(UIStrings.description),
3939
category: InsightCategory.INP,
40+
shouldShow: Boolean(partialModel.longestInteractionEvent),
4041
...partialModel,
4142
};
4243
}

front_end/models/trace/insights/LCPDiscovery.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type LCPDiscoveryInsightModel = InsightModel<{
4444
earliestDiscoveryTimeTs?: Types.Timing.MicroSeconds,
4545
}>;
4646

47-
function finalize(partialModel: Omit<LCPDiscoveryInsightModel, 'title'|'description'|'category'>):
47+
function finalize(partialModel: Omit<LCPDiscoveryInsightModel, 'title'|'description'|'category'|'shouldShow'>):
4848
LCPDiscoveryInsightModel {
4949
const relatedEvents = partialModel.lcpEvent && partialModel.lcpRequest ?
5050
// TODO: add entire request initiator chain?
@@ -54,6 +54,10 @@ function finalize(partialModel: Omit<LCPDiscoveryInsightModel, 'title'|'descript
5454
title: i18nString(UIStrings.title),
5555
description: i18nString(UIStrings.description),
5656
category: InsightCategory.LCP,
57+
shouldShow: Boolean(
58+
partialModel.lcpRequest &&
59+
(partialModel.shouldIncreasePriorityHint || partialModel.shouldPreloadImage ||
60+
partialModel.shouldRemoveLazyLoading)),
5761
...partialModel,
5862
relatedEvents,
5963
};

front_end/models/trace/insights/LCPPhases.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ function breakdownPhases(
116116
};
117117
}
118118

119-
function finalize(partialModel: Omit<LCPPhasesInsightModel, 'title'|'description'|'category'>): LCPPhasesInsightModel {
119+
function finalize(partialModel: Omit<LCPPhasesInsightModel, 'title'|'description'|'category'|'shouldShow'>):
120+
LCPPhasesInsightModel {
120121
const relatedEvents = [];
121122
if (partialModel.lcpEvent) {
122123
relatedEvents.push(partialModel.lcpEvent);
@@ -128,6 +129,8 @@ function finalize(partialModel: Omit<LCPPhasesInsightModel, 'title'|'description
128129
title: i18nString(UIStrings.title),
129130
description: i18nString(UIStrings.description),
130131
category: InsightCategory.LCP,
132+
// TODO: should move the component's "getPhaseData" to model.
133+
shouldShow: Boolean(partialModel.phases) && (partialModel.lcpMs ?? 0) > 0,
131134
...partialModel,
132135
relatedEvents,
133136
};

front_end/models/trace/insights/RenderBlocking.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,13 @@ function computeSavings(
151151
return {metricSavings, requestIdToWastedMs};
152152
}
153153

154-
function finalize(partialModel: Omit<RenderBlockingInsightModel, 'title'|'description'|'category'>):
154+
function finalize(partialModel: Omit<RenderBlockingInsightModel, 'title'|'description'|'category'|'shouldShow'>):
155155
RenderBlockingInsightModel {
156156
return {
157157
title: i18nString(UIStrings.title),
158158
description: i18nString(UIStrings.description),
159159
category: InsightCategory.LCP,
160+
shouldShow: partialModel.renderBlockingRequests.length > 0,
160161
...partialModel,
161162
};
162163
}

front_end/models/trace/insights/SlowCSSSelector.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ function aggregateSelectorStats(
6868
return [...selectorMap.values()];
6969
}
7070

71-
function finalize(partialModel: Omit<SlowCSSSelectorInsightModel, 'title'|'description'|'category'>):
71+
function finalize(partialModel: Omit<SlowCSSSelectorInsightModel, 'title'|'description'|'category'|'shouldShow'>):
7272
SlowCSSSelectorInsightModel {
7373
return {
7474
title: i18nString(UIStrings.title),
7575
description: i18nString(UIStrings.description),
7676
category: InsightCategory.ALL,
77+
shouldShow: partialModel.topElapsedMs.length !== 0 && partialModel.topMatchAttempts.length !== 0,
7778
...partialModel,
7879
};
7980
}

front_end/models/trace/insights/ThirdParties.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ function getRelatedEvents(
5252
return events;
5353
}
5454

55-
function finalize(partialModel: Omit<ThirdPartiesInsightModel, 'title'|'description'|'category'>):
55+
function finalize(partialModel: Omit<ThirdPartiesInsightModel, 'title'|'description'|'category'|'shouldShow'>):
5656
ThirdPartiesInsightModel {
5757
return {
5858
title: i18nString(UIStrings.title),
5959
description: i18nString(UIStrings.description),
6060
category: InsightCategory.ALL,
61+
shouldShow:
62+
Boolean([...partialModel.summaryByEntity.entries()].find(kv => kv[0] !== partialModel.firstPartyEntity)),
6163
...partialModel,
6264
};
6365
}

0 commit comments

Comments
 (0)