-
Notifications
You must be signed in to change notification settings - Fork 11
refactor: breadcrumb to support additional specifications #1254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
a710c40
39e81b6
d837182
f054311
d7307b4
305e1f1
f3e855d
e6895e8
ca25f5c
9c61b3d
8a0bdef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { ActivatedRouteSnapshot, Resolve } from '@angular/router'; | ||
| import { Breadcrumb, TimeRangeService } from '@hypertrace/common'; | ||
| import { GraphQlRequestCacheability, GraphQlRequestService } from '@hypertrace/graphql-client'; | ||
| import { Observable } from 'rxjs'; | ||
| import { map, switchMap, take } from 'rxjs/operators'; | ||
| import { Entity } from '../../graphql/model/schema/entity'; | ||
| import { GraphQlTimeRange } from '../../graphql/model/schema/timerange/graphql-time-range'; | ||
| import { SpecificationBuilder } from '../../graphql/request/builders/specification/specification-builder'; | ||
| import { EntityGraphQlQueryHandlerService } from '../../graphql/request/handlers/entities/query/entity/entity-graphql-query-handler.service'; | ||
| import { EntityIconLookupService } from '../entity/entity-icon-lookup.service'; | ||
| import { Specification } from './../../graphql/model/schema/specifier/specification'; | ||
| import { ENTITY_GQL_REQUEST } from './../../graphql/request/handlers/entities/query/entity/entity-graphql-query-handler.service'; | ||
|
|
||
| export abstract class EntityBreadcrumbResolver<T extends Entity> implements Resolve<Observable<Breadcrumb>> { | ||
| private readonly specificationBuilder: SpecificationBuilder = new SpecificationBuilder(); | ||
|
|
||
| public constructor( | ||
| protected readonly timeRangeService: TimeRangeService, | ||
| protected readonly graphQlQueryService: GraphQlRequestService, | ||
| protected readonly iconLookupService: EntityIconLookupService | ||
| ) {} | ||
|
|
||
| public abstract resolve(route: ActivatedRouteSnapshot): Promise<Observable<Breadcrumb>>; | ||
|
|
||
| protected abstract getAttributeKeys(): string[]; | ||
|
|
||
| protected getAdditionalSpecifications(): Specification[] { | ||
| return []; | ||
| } | ||
|
|
||
| protected fetchEntity(id: string, entityType: string): Observable<T & Breadcrumb> { | ||
| return this.timeRangeService.getTimeRangeAndChanges().pipe( | ||
| switchMap(timeRange => | ||
| this.graphQlQueryService.query<EntityGraphQlQueryHandlerService, T>( | ||
| { | ||
| requestType: ENTITY_GQL_REQUEST, | ||
| entityType: entityType, | ||
| id: id, | ||
| properties: [...this.getAttributeSpecification(), ...this.getAdditionalSpecifications()], | ||
| timeRange: new GraphQlTimeRange(timeRange.startTime, timeRange.endTime) | ||
| }, | ||
| { cacheability: GraphQlRequestCacheability.NotCacheable } | ||
|
||
| ) | ||
| ), | ||
| map(entity => ({ | ||
| ...entity, | ||
| label: entity.name as string, | ||
| icon: this.iconLookupService.forEntity(entity) | ||
| })), | ||
| take(1) | ||
| ); | ||
| } | ||
|
|
||
| private getAttributeSpecification(): Specification[] { | ||
| return this.getAttributeKeys().map(attributeKey => | ||
| this.specificationBuilder.attributeSpecificationForKey(attributeKey) | ||
| ); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
types are wrong here, shouldn't need to cast
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ts is not able to detect the types in the pipe -> map operator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the type on line 42? Are we sure we're not just dropping it on 59? That map should produce a
T & Partial<Pick<ApiBreadcrumbDetails, 'parentName' | 'parentId'>>since we're spreading them together (that partial could use a type alias!).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit btw)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I am not able to make it work. IMO,
getParentPartialis making the parentName and parentId optional and then we are required fields inApiBreadcrumbDetails.We wouldn't have to cast if we can ensure that following code returns an
ApiBreadcrumbDetailsobjectThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that by assigning '' instead of undefined but i don't know if it would create any run time issue. So, I am ignoring it for this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could just make those two fields optional on
ApiBreadcrumbDetailsI think? They are optional, they're omitted if we can't resolve them, hence the check on line 60 before we access them.