22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ import * as i18n from '../../core/i18n/i18n.js' ;
6+ import type * as Platform from '../../core/platform/platform.js' ;
57import * as SDK from '../../core/sdk/sdk.js' ;
68import type * as Protocol from '../../generated/protocol.js' ;
79import * as UI from '../../ui/legacy/legacy.js' ;
@@ -10,9 +12,33 @@ import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
1012import type * as ApplicationComponents from './components/components.js' ;
1113import { ReportingApiReportsView } from './ReportingApiReportsView.js' ;
1214
15+ const UIStrings = {
16+ /**
17+ *@description Placeholder text that shows if no report or endpoint was detected.
18+ * A report contains information on issues or events that were encountered by a web browser.
19+ * An endpoint is a URL where the report is sent to.
20+ * (https://developer.chrome.com/docs/capabilities/web-apis/reporting-api)
21+ */
22+ noReportOrEndpoint : 'No report or endpoint' ,
23+ /**
24+ *@description Placeholder text that shows if no report or endpoint was detected.
25+ * A report contains information on issues or events that were encountered by a web browser.
26+ * An endpoint is a URL where the report is sent to.
27+ * (https://developer.chrome.com/docs/capabilities/web-apis/reporting-api)
28+ */
29+ reportingApiDescription : 'On this page you will be able to inspect `Reporting API` reports and endpoints.' ,
30+ } as const ;
31+ const str_ = i18n . i18n . registerUIStrings ( 'panels/application/ReportingApiView.ts' , UIStrings ) ;
32+ export const i18nString = i18n . i18n . getLocalizedString . bind ( undefined , str_ ) ;
33+
34+ const REPORTING_API_EXPLANATION_URL =
35+ 'https://developer.chrome.com/docs/capabilities/web-apis/reporting-api' as Platform . DevToolsPath . UrlString ;
36+
1337export class ReportingApiView extends UI . SplitWidget . SplitWidget {
1438 private readonly endpointsGrid : ApplicationComponents . EndpointsGrid . EndpointsGrid ;
1539 private endpoints : Map < string , Protocol . Network . ReportingApiEndpoint [ ] > ;
40+ #emptyWidget?: UI . EmptyWidget . EmptyWidget ;
41+ #reportingApiReports?: ReportingApiReportsView ;
1642
1743 constructor ( endpointsGrid : ApplicationComponents . EndpointsGrid . EndpointsGrid ) {
1844 super ( /* isVertical: */ false , /* secondIsSidebar: */ true ) ;
@@ -21,22 +47,44 @@ export class ReportingApiView extends UI.SplitWidget.SplitWidget {
2147 this . endpoints = new Map ( ) ;
2248 const mainTarget = SDK . TargetManager . TargetManager . instance ( ) . primaryPageTarget ( ) ;
2349 const networkManager = mainTarget ?. model ( SDK . NetworkManager . NetworkManager ) ;
50+ this . #emptyWidget = new UI . EmptyWidget . EmptyWidget (
51+ i18nString ( UIStrings . noReportOrEndpoint ) , i18nString ( UIStrings . reportingApiDescription ) ) ;
52+ this . #emptyWidget. appendLink ( REPORTING_API_EXPLANATION_URL ) ;
53+ this . setMainWidget ( this . #emptyWidget) ;
2454 if ( networkManager ) {
2555 networkManager . addEventListener (
2656 SDK . NetworkManager . Events . ReportingApiEndpointsChangedForOrigin ,
2757 event => this . onEndpointsChangedForOrigin ( event . data ) , this ) ;
2858
29- const reportingApiReportsView = new ReportingApiReportsView ( networkManager ) ;
59+ networkManager . addEventListener (
60+ SDK . NetworkManager . Events . ReportingApiReportAdded , this . #showReportsAndEndpoints, this ) ;
61+
62+ this . #reportingApiReports = new ReportingApiReportsView ( networkManager ) ;
3063 const reportingApiEndpointsView = new UI . Widget . VBox ( ) ;
3164 reportingApiEndpointsView . setMinimumSize ( 0 , 40 ) ;
3265 reportingApiEndpointsView . contentElement . appendChild ( this . endpointsGrid ) ;
33- this . setMainWidget ( reportingApiReportsView ) ;
66+
3467 this . setSidebarWidget ( reportingApiEndpointsView ) ;
3568 void networkManager . enableReportingApi ( ) ;
69+ this . hideSidebar ( ) ;
3670 }
3771 }
3872
73+ #showReportsAndEndpoints( ) : void {
74+ // Either we don't have reports and endpoints to show (first case), or we have already
75+ // replaced the empty widget with a different main view (second case).
76+ if ( this . #reportingApiReports === undefined || this . mainWidget ( ) !== this . #emptyWidget) {
77+ return ;
78+ }
79+
80+ this . #emptyWidget?. detach ( ) ;
81+ this . #emptyWidget = undefined ;
82+ this . setMainWidget ( this . #reportingApiReports) ;
83+ this . showBoth ( ) ;
84+ }
85+
3986 private onEndpointsChangedForOrigin ( data : Protocol . Network . ReportingApiEndpointsChangedForOriginEvent ) : void {
87+ this . #showReportsAndEndpoints( ) ;
4088 this . endpoints . set ( data . origin , data . endpoints ) ;
4189 this . endpointsGrid . data = { endpoints : this . endpoints } ;
4290 }
0 commit comments