Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/app/services/data_service_v2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ xprof_ng_module(
":data_service_v2",
"//javascript/angular2/testing/catalyst/fake_async",
"//third_party/javascript/typings/jasmine",
"@npm//@angular/common",
"@npm//@angular/core_testing",
"@npm//@ngrx/store",
"@npm//rxjs",
"@org_xprof//frontend/app/common/angular:angular_common_http",
"@org_xprof//frontend/app/store",
Expand Down
38 changes: 23 additions & 15 deletions frontend/app/services/data_service_v2/data_service_v2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {PlatformLocation} from '@angular/common';
import {HttpClient, HttpErrorResponse, HttpParams} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {inject, Injectable} from '@angular/core';
import {Store} from '@ngrx/store';
import {
API_PREFIX,
Expand All @@ -27,6 +27,7 @@ import {
} from 'org_xprof/frontend/app/common/interfaces/capture_profile';
import {DataTable} from 'org_xprof/frontend/app/common/interfaces/data_table';
import {type Diagnostics} from 'org_xprof/frontend/app/common/interfaces/diagnostics';
import {GraphTypeObject} from 'org_xprof/frontend/app/common/interfaces/graph_viewer';
import {HostMetadata} from 'org_xprof/frontend/app/common/interfaces/hosts';
import {type SmartSuggestionReport} from 'org_xprof/frontend/app/common/interfaces/smart_suggestion.jsonpb_decls';
import * as utils from 'org_xprof/frontend/app/common/utils/utils';
Expand All @@ -40,17 +41,22 @@ import {Observable, of} from 'rxjs';
import {catchError} from 'rxjs/operators';
import {windowOpen} from 'safevalues/dom';

interface HttpGetOptions {
params?: HttpParams;
responseType?: string;
[key: string]: string | HttpParams | undefined;
}

/** The data service class that calls API and return response. */
@Injectable()
export class DataServiceV2 implements DataServiceV2Interface {
private readonly httpClient = inject(HttpClient);
private readonly store = inject(Store<{}>);
isLocalDevelopment = false;
pathPrefix = '';

constructor(
private readonly httpClient: HttpClient,
platformLocation: PlatformLocation,
private readonly store: Store<{}>,
) {
constructor() {
const platformLocation = inject(PlatformLocation);
// Clear previous searchParams from session storage
window.sessionStorage.removeItem('searchParams');

Expand All @@ -73,11 +79,10 @@ export class DataServiceV2 implements DataServiceV2Interface {

private get<T>(
url: string,
// tslint:disable-next-line:no-any
options: {[key: string]: any} = {},
options: HttpGetOptions = {},
notifyError = true,
): Observable<T | null> {
return this.httpClient.get<T>(url, options).pipe(
return this.httpClient.get<T>(url, options as {params?: HttpParams; responseType?: 'json'}).pipe(
catchError((error: HttpErrorResponse) => {
console.log(error);
let errorMessage = '';
Expand Down Expand Up @@ -274,7 +279,7 @@ export class DataServiceV2 implements DataServiceV2Interface {
moduleName: string,
opName: string,
programId = '',
) {
): string {
if (moduleName && opName) {
const linkParams = new URLSearchParams();
linkParams.set('tool', 'graph_viewer');
Expand Down Expand Up @@ -329,7 +334,7 @@ export class DataServiceV2 implements DataServiceV2Interface {
return `${window.parent.location.origin}?${linkParams.toString()}#profile`;
}

getGraphTypes(sessionId: string) {
getGraphTypes(sessionId: string): Observable<GraphTypeObject[]> {
const types = [
{
value: GRAPH_TYPE_DEFAULT,
Expand Down Expand Up @@ -377,7 +382,10 @@ export class DataServiceV2 implements DataServiceV2Interface {
return of('');
}

getMeGraphJson(sessionId: string, params: Map<string, string>) {
getMeGraphJson(
sessionId: string,
params: Map<string, string>,
): Observable<string> {
const queryParams = this.getHttpParamsWithPath()
.set('run', sessionId)
.set('tag', 'graph_viewer')
Expand Down Expand Up @@ -433,7 +441,7 @@ export class DataServiceV2 implements DataServiceV2Interface {
moduleName: string,
opName: string,
programId = '',
) {
): string {
if (moduleName && opName) {
const linkParams = new URLSearchParams();
linkParams.set('tag', 'graph_viewer');
Expand Down Expand Up @@ -461,7 +469,7 @@ export class DataServiceV2 implements DataServiceV2Interface {
moduleName: string,
opName: string,
programId = '',
) {
): string {
if (moduleName && opName) {
// TODO(xprof): Add program id support in 3p frontend.
return `${window.parent.location.origin}/${
Expand Down Expand Up @@ -557,7 +565,7 @@ export class DataServiceV2 implements DataServiceV2Interface {
host: string,
tqx = '',
additionalParams: Map<string, string> = new Map(),
) {
): void {
let params = this.getHttpParamsWithPath();
params = params
.set('run', sessionId)
Expand Down