|
1 | 1 | import { Inject, Injectable } from '@angular/core'; |
2 | | -import { ActivatedRouteSnapshot, Resolve } from '@angular/router'; |
| 2 | +import { ActivatedRouteSnapshot } from '@angular/router'; |
3 | 3 | import { Breadcrumb, NavigationService, TimeRangeService } from '@hypertrace/common'; |
4 | 4 | import { BreadcrumbsService } from '@hypertrace/components'; |
5 | | -import { GraphQlRequestCacheability, GraphQlRequestService } from '@hypertrace/graphql-client'; |
| 5 | +import { GraphQlRequestService } from '@hypertrace/graphql-client'; |
| 6 | +import { entityIdKey } from '@hypertrace/observability'; |
6 | 7 | import { Observable } from 'rxjs'; |
7 | | -import { map, switchMap, take } from 'rxjs/operators'; |
| 8 | +import { map, switchMap } from 'rxjs/operators'; |
8 | 9 | import { EntityMetadata, EntityMetadataMap, ENTITY_METADATA } from '../../../shared/constants/entity-metadata'; |
9 | | -import { Entity, ObservabilityEntityType } from '../../../shared/graphql/model/schema/entity'; |
10 | | -import { GraphQlTimeRange } from '../../../shared/graphql/model/schema/timerange/graphql-time-range'; |
11 | | -import { SpecificationBuilder } from '../../../shared/graphql/request/builders/specification/specification-builder'; |
| 10 | +import { Entity, entityTypeKey, ObservabilityEntityType } from '../../../shared/graphql/model/schema/entity'; |
12 | 11 | import { |
13 | | - EntityGraphQlQueryHandlerService, |
14 | | - ENTITY_GQL_REQUEST |
15 | | -} from '../../../shared/graphql/request/handlers/entities/query/entity/entity-graphql-query-handler.service'; |
| 12 | + EntityBreadcrumb, |
| 13 | + EntityBreadcrumbResolver |
| 14 | +} from '../../../shared/services/entity-breadcrumb/entity-breadcrumb.resolver'; |
| 15 | +import { EntityIconLookupService } from './../../../shared/services/entity/entity-icon-lookup.service'; |
16 | 16 |
|
17 | 17 | @Injectable({ providedIn: 'root' }) |
18 | | -export class ApiDetailBreadcrumbResolver implements Resolve<Observable<Breadcrumb>> { |
19 | | - private readonly specificationBuilder: SpecificationBuilder = new SpecificationBuilder(); |
| 18 | +export class ApiDetailBreadcrumbResolver<T extends EntityBreadcrumb> extends EntityBreadcrumbResolver<T> { |
20 | 19 | protected readonly apiEntityMetadata: EntityMetadata | undefined; |
21 | 20 |
|
22 | 21 | public constructor( |
| 22 | + timeRangeService: TimeRangeService, |
| 23 | + graphQlQueryService: GraphQlRequestService, |
| 24 | + iconLookupService: EntityIconLookupService, |
23 | 25 | private readonly navigationService: NavigationService, |
24 | | - private readonly timeRangeService: TimeRangeService, |
25 | | - private readonly graphQlQueryService: GraphQlRequestService, |
26 | 26 | protected readonly breadcrumbService: BreadcrumbsService, |
27 | 27 | @Inject(ENTITY_METADATA) private readonly entityMetadataMap: EntityMetadataMap |
28 | 28 | ) { |
| 29 | + super(timeRangeService, graphQlQueryService, iconLookupService); |
29 | 30 | this.apiEntityMetadata = this.entityMetadataMap.get(ObservabilityEntityType.Api); |
30 | 31 | } |
31 | 32 |
|
32 | 33 | public async resolve(activatedRouteSnapshot: ActivatedRouteSnapshot): Promise<Observable<Breadcrumb>> { |
33 | 34 | const id = activatedRouteSnapshot.paramMap.get('id') as string; |
34 | | - const parentType = this.resolveParentType(); |
| 35 | + const parentEntityMetadata = this.resolveParentType(); |
35 | 36 |
|
36 | 37 | return Promise.resolve( |
37 | | - this.fetchEntity(id, parentType).pipe( |
38 | | - take(1), |
| 38 | + this.fetchEntity(id, ObservabilityEntityType.Api).pipe( |
| 39 | + map(apiEntity => ({ |
| 40 | + ...apiEntity, |
| 41 | + ...this.getParentPartial(apiEntity, parentEntityMetadata) |
| 42 | + })), |
39 | 43 | switchMap(api => [ |
40 | | - ...this.getParentBreadcrumbs(api, parentType), |
| 44 | + ...this.getParentBreadcrumbs(api, parentEntityMetadata), |
41 | 45 | this.createBreadcrumbForEntity(api, activatedRouteSnapshot) |
42 | 46 | ]) |
43 | 47 | ) |
44 | 48 | ); |
45 | 49 | } |
46 | 50 |
|
47 | | - protected createBreadcrumbForEntity( |
48 | | - api: ApiBreadcrumbDetails, |
49 | | - activatedRouteSnapshot: ActivatedRouteSnapshot |
50 | | - ): Breadcrumb { |
| 51 | + protected createBreadcrumbForEntity(api: Entity, activatedRouteSnapshot: ActivatedRouteSnapshot): EntityBreadcrumb { |
51 | 52 | return { |
52 | | - label: api.name, |
| 53 | + ...api, |
| 54 | + label: api.name as string, |
53 | 55 | icon: this.apiEntityMetadata?.icon, |
54 | 56 | url: this.breadcrumbService.getPath(activatedRouteSnapshot) |
55 | 57 | }; |
56 | 58 | } |
57 | 59 |
|
58 | | - protected getParentBreadcrumbs(api: ApiBreadcrumbDetails, parentEntityMetadata?: EntityMetadata): Breadcrumb[] { |
| 60 | + protected getParentBreadcrumbs( |
| 61 | + api: EntityBreadcrumb, |
| 62 | + parentEntityMetadata?: EntityMetadata |
| 63 | + ): (EntityBreadcrumb | Breadcrumb)[] { |
59 | 64 | return parentEntityMetadata !== undefined |
60 | 65 | ? [ |
61 | 66 | { |
62 | | - label: api.parentName, |
| 67 | + [entityIdKey]: api.parentId as string, |
| 68 | + [entityTypeKey]: parentEntityMetadata.entityType, |
| 69 | + label: api.parentName as string, |
63 | 70 | icon: parentEntityMetadata?.icon, |
64 | | - url: parentEntityMetadata?.detailPath(api.parentId) |
| 71 | + url: parentEntityMetadata?.detailPath(api.parentId as string) |
65 | 72 | }, |
66 | 73 | { |
67 | 74 | label: 'Endpoints', |
68 | 75 | icon: this.apiEntityMetadata?.icon, |
69 | | - url: parentEntityMetadata?.apisListPath?.(api.parentId) |
| 76 | + url: parentEntityMetadata?.apisListPath?.(api.parentId as string) |
70 | 77 | } |
71 | 78 | ] |
72 | 79 | : []; |
73 | 80 | } |
74 | 81 |
|
75 | | - private fetchEntity(id: string, parentEntityMetadata?: EntityMetadata): Observable<ApiBreadcrumbDetails> { |
76 | | - return this.timeRangeService.getTimeRangeAndChanges().pipe( |
77 | | - switchMap(timeRange => |
78 | | - this.graphQlQueryService.query<EntityGraphQlQueryHandlerService, ApiBreadcrumbDetails>( |
79 | | - { |
80 | | - requestType: ENTITY_GQL_REQUEST, |
81 | | - entityType: ObservabilityEntityType.Api, |
82 | | - id: id, |
83 | | - properties: this.getAttributeKeys(parentEntityMetadata).map(attributeKey => |
84 | | - this.specificationBuilder.attributeSpecificationForKey(attributeKey) |
85 | | - ), |
86 | | - timeRange: new GraphQlTimeRange(timeRange.startTime, timeRange.endTime) |
87 | | - }, |
88 | | - { cacheability: GraphQlRequestCacheability.NotCacheable } |
89 | | - ) |
90 | | - ), |
91 | | - map(apiEntity => ({ |
92 | | - ...apiEntity, |
93 | | - ...this.getParentPartial(apiEntity, parentEntityMetadata) |
94 | | - })) |
95 | | - ); |
96 | | - } |
97 | | - |
98 | | - private getAttributeKeys(parentTypeMetadata?: EntityMetadata): string[] { |
| 82 | + protected getAttributeKeys(): string[] { |
| 83 | + const parentTypeMetadata = this.resolveParentType(); |
99 | 84 | const parentAttributes = parentTypeMetadata |
100 | 85 | ? [this.getParentNameAttribute(parentTypeMetadata), this.getParentIdAttribute(parentTypeMetadata)] |
101 | 86 | : []; |
@@ -142,7 +127,7 @@ export class ApiDetailBreadcrumbResolver implements Resolve<Observable<Breadcrum |
142 | 127 | } |
143 | 128 | } |
144 | 129 |
|
145 | | -export interface ApiBreadcrumbDetails extends Entity<ObservabilityEntityType.Api> { |
| 130 | +export interface ApiBreadcrumbDetails extends EntityBreadcrumb { |
146 | 131 | name: string; |
147 | 132 | parentName: string; |
148 | 133 | parentId: string; |
|
0 commit comments