Skip to content

Commit 8baf2b9

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored andcommitted
RPP: add default to InsightModel generic
We had some cases where we passed `any`, others where we passed `{}`. If we set the default explicitly, we can not pass anything and be consistent. Bug: none Change-Id: I4bc500cb55587abf2c5892af8438f4994935c063 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6316669 Commit-Queue: Jack Franklin <[email protected]> Auto-Submit: Jack Franklin <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]> Reviewed-by: Nikolay Vitkov <[email protected]>
1 parent 8ea49e2 commit 8baf2b9

File tree

11 files changed

+40
-42
lines changed

11 files changed

+40
-42
lines changed

front_end/models/trace/insights/LCPPhases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ interface LCPPhases {
9090
renderDelay: Types.Timing.Milli;
9191
}
9292

93-
export function isLCPPhases(model: InsightModel<{}, {}>): model is LCPPhasesInsightModel {
93+
export function isLCPPhases(model: InsightModel): model is LCPPhasesInsightModel {
9494
return model.insightKey === 'LCPPhases';
9595
}
9696
export type LCPPhasesInsightModel = InsightModel<typeof UIStrings, {

front_end/models/trace/insights/types.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,25 @@ export type RelatedEventsMap = Map<Types.Events.Event, string[]>;
7979

8080
export type Checklist<Keys extends string> = Record<Keys, {label: Common.UIString.LocalizedString, value: boolean}>;
8181

82-
export type InsightModel<UIStrings extends Record<string, string>, R extends Record<string, unknown>> = R&{
83-
/** Used internally to identify the type of a model, not shown visibly to users **/
84-
insightKey: keyof InsightModelsType,
85-
/** Not used within DevTools - this is for external consumers (like Lighthouse). */
86-
strings: UIStrings,
87-
title: Common.UIString.LocalizedString,
88-
description: Common.UIString.LocalizedString,
89-
category: InsightCategory,
90-
state: 'pass' | 'fail' | 'informative',
91-
relatedEvents?: RelatedEventsMap | Types.Events.Event[],
92-
warnings?: InsightWarning[],
93-
metricSavings?: MetricSavings,
94-
/**
95-
* If this insight is attached to a navigation, this stores its ID.
96-
*/
97-
navigationId?: string,
98-
};
82+
export type InsightModel<UIStrings extends Record<string, string> = Record<string, string>,
83+
ExtraDetail extends Record<string, unknown> = Record<string, unknown>> =
84+
ExtraDetail&{
85+
/** Used internally to identify the type of a model, not shown visibly to users **/
86+
insightKey: keyof InsightModelsType,
87+
/** Not used within DevTools - this is for external consumers (like Lighthouse). */
88+
strings: UIStrings,
89+
title: Common.UIString.LocalizedString,
90+
description: Common.UIString.LocalizedString,
91+
category: InsightCategory,
92+
state: 'pass' | 'fail' | 'informative',
93+
relatedEvents?: RelatedEventsMap | Types.Events.Event[],
94+
warnings?: InsightWarning[],
95+
metricSavings?: MetricSavings,
96+
/**
97+
* If this insight is attached to a navigation, this stores its ID.
98+
*/
99+
navigationId?: string,
100+
};
99101

100102
export type PartialInsightModel<T> =
101103
Omit<T, 'strings'|'title'|'description'|'category'|'state'|'insightKey'|'navigationId'>;

front_end/panels/ai_assistance/data_formatters/PerformanceInsightFormatter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ function formatMicro(x: number|undefined): string {
2323
}
2424

2525
export class PerformanceInsightFormatter {
26-
#insight: Trace.Insights.Types.InsightModel<{}, {}>;
27-
constructor(insight: Trace.Insights.Types.InsightModel<{}, {}>) {
26+
#insight: Trace.Insights.Types.InsightModel;
27+
constructor(insight: Trace.Insights.Types.InsightModel) {
2828
this.#insight = insight;
2929
}
3030

front_end/panels/timeline/components/Sidebar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {SidebarAnnotationsTab} from './SidebarAnnotationsTab.js';
1010
import {SidebarInsightsTab} from './SidebarInsightsTab.js';
1111

1212
export interface ActiveInsight {
13-
model: Trace.Insights.Types.InsightModel<{}, {}>;
13+
model: Trace.Insights.Types.InsightModel;
1414
insightSetKey: string;
1515
}
1616

front_end/panels/timeline/components/SidebarSingleInsightSet.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as Components from './components.js';
1313
import type * as InsightComponents from './insights/insights.js';
1414

1515
type BaseInsightComponent =
16-
InsightComponents.BaseInsightComponent.BaseInsightComponent<Trace.Insights.Types.InsightModel<{}, {}>>;
16+
InsightComponents.BaseInsightComponent.BaseInsightComponent<Trace.Insights.Types.InsightModel>;
1717

1818
function getUserVisibleInsights(component: Components.SidebarSingleInsightSet.SidebarSingleInsightSet):
1919
BaseInsightComponent[] {

front_end/panels/timeline/components/SidebarSingleInsightSet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ export interface SidebarSingleInsightSetData {
9292
const EXPERIMENTAL_INSIGHTS: ReadonlySet<string> = new Set([
9393
]);
9494

95-
type InsightNameToComponentMapping = Record<
96-
string, typeof Insights.BaseInsightComponent.BaseInsightComponent<Trace.Insights.Types.InsightModel<{}, {}>>>;
95+
type InsightNameToComponentMapping =
96+
Record<string, typeof Insights.BaseInsightComponent.BaseInsightComponent<Trace.Insights.Types.InsightModel>>;
9797

9898
/**
9999
* Every insight (INCLUDING experimental ones).

front_end/panels/timeline/components/insights/BaseInsightComponent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const {html} = Lit;
1818

1919
describeWithEnvironment('BaseInsightComponent', () => {
2020
const {BaseInsightComponent} = Insights.BaseInsightComponent;
21-
class TestInsightComponent extends BaseInsightComponent<Trace.Insights.Types.InsightModel<{}, {}>> {
21+
class TestInsightComponent extends BaseInsightComponent<Trace.Insights.Types.InsightModel> {
2222
override internalName = 'test-insight';
2323
override createOverlays(): TimelineOverlay[] {
2424
return [];

front_end/panels/timeline/components/insights/BaseInsightComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export interface BaseInsightData {
5858
insightSetKey: string|null;
5959
}
6060

61-
export abstract class BaseInsightComponent<T extends InsightModel<{}, {}>> extends HTMLElement {
61+
export abstract class BaseInsightComponent<T extends InsightModel> extends HTMLElement {
6262
abstract internalName: string;
6363
// So we can use the TypeScript BaseInsight class without getting warnings
6464
// about litTagName. Every child should overrwrite this.

front_end/panels/timeline/components/insights/SidebarInsight.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface InsightDetails {
1818
export class InsightActivated extends Event {
1919
static readonly eventName = 'insightactivated';
2020

21-
constructor(public model: InsightModel<{}, {}>, public insightSetKey: string) {
21+
constructor(public model: InsightModel, public insightSetKey: string) {
2222
super(InsightActivated.eventName, {bubbles: true, composed: true});
2323
}
2424
}

front_end/panels/timeline/components/insights/Table.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tableStyles.replaceSync(tableStylesRaw.cssContent);
1818

1919
const {html} = Lit;
2020

21-
type BaseInsightComponent = BaseInsightComponent.BaseInsightComponent<Trace.Insights.Types.InsightModel<{}, {}>>;
21+
type BaseInsightComponent = BaseInsightComponent.BaseInsightComponent<Trace.Insights.Types.InsightModel>;
2222

2323
/**
2424
* @fileoverview An interactive table component.
@@ -53,7 +53,6 @@ export interface TableDataRow {
5353
}
5454

5555
export class Table extends HTMLElement {
56-
5756
readonly #shadow = this.attachShadow({mode: 'open'});
5857
readonly #boundRender = this.#render.bind(this);
5958
#insight?: BaseInsightComponent;

0 commit comments

Comments
 (0)