mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-06 12:01:40 +08:00
This patch is part of the underscore migration that adds the private keyword to all properties that start with an underscore and removes the underscore. Bug:chromium:1207342 Change-Id: Ia25ac337cf7be99e2b18b95cf15f19eb559f22fe Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3077389 Commit-Queue: Jan Scheffler <janscheffler@chromium.org> Auto-Submit: Jan Scheffler <janscheffler@chromium.org> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
70 lines
2.6 KiB
TypeScript
70 lines
2.6 KiB
TypeScript
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import * as Common from '../../core/common/common.js';
|
|
import * as SDK from '../../core/sdk/sdk.js';
|
|
import type {Issue, IssueCategory} from './Issue.js';
|
|
import {IssuesManager} from './IssuesManager.js';
|
|
|
|
export type IssuesAssociatable = SDK.NetworkRequest.NetworkRequest|SDK.Cookie.Cookie|string;
|
|
|
|
function issuesAssociatedWithNetworkRequest(issues: Issue[], request: SDK.NetworkRequest.NetworkRequest): Issue[] {
|
|
return issues.filter(issue => {
|
|
for (const affectedRequest of issue.requests()) {
|
|
if (affectedRequest.requestId === request.requestId()) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
});
|
|
}
|
|
|
|
function issuesAssociatedWithCookie(issues: Issue[], domain: string, name: string, path: string): Issue[] {
|
|
return issues.filter(issue => {
|
|
for (const cookie of issue.cookies()) {
|
|
if (cookie.domain === domain && cookie.name === name && cookie.path === path) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @throws In case obj has an unsupported type (i.e. not part of the IssuesAssociatble union).
|
|
*/
|
|
export function issuesAssociatedWith(issues: Issue[], obj: IssuesAssociatable): Issue[] {
|
|
if (obj instanceof SDK.NetworkRequest.NetworkRequest) {
|
|
return issuesAssociatedWithNetworkRequest(issues, obj);
|
|
}
|
|
if (obj instanceof SDK.Cookie.Cookie) {
|
|
return issuesAssociatedWithCookie(issues, obj.domain(), obj.name(), obj.path());
|
|
}
|
|
throw new Error(`issues can not be associated with ${JSON.stringify(obj)}`);
|
|
}
|
|
|
|
export function hasIssues(obj: IssuesAssociatable): boolean {
|
|
const issues = Array.from(IssuesManager.instance().issues());
|
|
return issuesAssociatedWith(issues, obj).length > 0;
|
|
}
|
|
|
|
export function hasIssueOfCategory(obj: IssuesAssociatable, category: IssueCategory): boolean {
|
|
const issues = Array.from(IssuesManager.instance().issues());
|
|
return issuesAssociatedWith(issues, obj).some(issue => issue.getCategory() === category);
|
|
}
|
|
|
|
export async function reveal(obj: IssuesAssociatable, category?: IssueCategory): Promise<void|undefined> {
|
|
if (typeof obj === 'string') {
|
|
const issue = IssuesManager.instance().getIssueById(obj);
|
|
if (issue) {
|
|
return Common.Revealer.reveal(issue);
|
|
}
|
|
}
|
|
const issues = Array.from(IssuesManager.instance().issues());
|
|
const candidates = issuesAssociatedWith(issues, obj).filter(issue => !category || issue.getCategory() === category);
|
|
if (candidates.length > 0) {
|
|
return Common.Revealer.reveal(candidates[0]);
|
|
}
|
|
}
|