豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 09ac2b7

Browse files
finnurbrekiDevtools-frontend LUCI CQ
authored andcommitted
[GreenDev]: Polish the AnnotationRepository API.
Address Connor's comments on previous CL: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7201324 Bug: 461428483 Change-Id: Ic3f074312124afc80262d8b25aa01eb670b6cbeb Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7205831 Commit-Queue: Finnur Thorarinsson <finnur@chromium.org> Reviewed-by: Alina Varkki <alinavarkki@chromium.org>
1 parent 174bfd0 commit 09ac2b7

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

front_end/models/ai_assistance/agents/PerformanceAgent.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,7 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
11011101

11021102
// eslint-disable-next-line no-console
11031103
console.log(`AI AGENT EVENT: Performance Agent adding annotation for element ${elementId}: '${annotationMessage}'`);
1104-
Annotations.AnnotationRepository.instance().addAnnotationWithAnchor(
1105-
annotationMessage, elementId, Annotations.AnnotationType.ELEMENT_NODE);
1104+
Annotations.AnnotationRepository.instance().addElementsAnnotation(annotationMessage, elementId);
11061105
return {result: {success: true}};
11071106
}
11081107
}

front_end/ui/components/annotations/AnnotationRepository.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,36 @@ import * as Common from '../../../core/common/common.js';
66
import * as Root from '../../../core/root/root.js';
77
import type * as SDK from '../../../core/sdk/sdk.js';
88

9-
import type {AnnotationType} from './AnnotationType.js';
9+
import {AnnotationType} from './AnnotationType.js';
1010

11-
interface AnnotationData {
11+
interface BaseAnnotationData {
1212
id: number;
1313
type: AnnotationType;
1414
message: string;
1515
// Sometimes the anchor for an annotation is not known, but is provided using a
1616
// string id instead (which can be converted to an `anchor` later).
1717
lookupId: string;
18-
// What to anchor the annotation to.
19-
anchor?: SDK.DOMModel.DOMNode|SDK.NetworkRequest.NetworkRequest|null;
2018
// Sometimes we want annotations to anchor to a particular string on the page.
2119
anchorToString?: string;
2220
}
2321

22+
interface ElementsAnnotationData extends BaseAnnotationData {
23+
type: AnnotationType.ELEMENT_NODE;
24+
anchor?: SDK.DOMModel.DOMNode;
25+
}
26+
2427
export const enum Events {
2528
ANNOTATION_ADDED = 'AnnotationAdded',
2629
}
2730

2831
export interface EventTypes {
29-
[Events.ANNOTATION_ADDED]: AnnotationData;
32+
[Events.ANNOTATION_ADDED]: BaseAnnotationData;
3033
}
3134

3235
export class AnnotationRepository {
3336
static #instance: AnnotationRepository|null = null;
3437
#events = new Common.ObjectWrapper.ObjectWrapper<EventTypes>();
35-
#annotations: AnnotationData[] = [];
38+
#annotations: BaseAnnotationData[] = [];
3639
#nextId = 0;
3740

3841
static instance(): AnnotationRepository {
@@ -55,7 +58,7 @@ export class AnnotationRepository {
5558
return this.#events.addEventListener(eventType, listener, thisObject);
5659
}
5760

58-
getAnnotationsByType(type: AnnotationType): AnnotationData[] {
61+
getAnnotationsByType(type: AnnotationType): BaseAnnotationData[] {
5962
if (!AnnotationRepository.annotationsEnabled()) {
6063
console.warn('Received query for annotation types with annotations disabled');
6164
return [];
@@ -65,23 +68,23 @@ export class AnnotationRepository {
6568
return annotations;
6669
}
6770

68-
addAnnotationWithAnchor(
71+
addElementsAnnotation(
6972
label: string,
70-
anchor: SDK.DOMModel.DOMNode|SDK.NetworkRequest.NetworkRequest|string|null,
71-
type: AnnotationType,
72-
anchorToString = '',
73+
lookupId?: string,
74+
anchor?: SDK.DOMModel.DOMNode,
75+
anchorToString?: string,
7376
): void {
7477
if (!AnnotationRepository.annotationsEnabled()) {
7578
console.warn('Received annotation registration with annotations disabled');
7679
return;
7780
}
7881

79-
const annotationData = {
82+
const annotationData: ElementsAnnotationData = {
8083
id: this.#nextId++,
81-
type,
84+
type: AnnotationType.ELEMENT_NODE,
8285
message: label,
83-
lookupId: typeof anchor === 'string' ? anchor : 'None',
84-
anchor: typeof anchor === 'string' ? null : anchor,
86+
lookupId: lookupId || '',
87+
anchor,
8588
anchorToString
8689
};
8790
this.#annotations.push(annotationData);

0 commit comments

Comments
 (0)