-
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a710c40
refactor: breadcrumb to support additional specifications
anandtiwary 39e81b6
refactor: fixing lint
anandtiwary d837182
Merge branch 'main' into breadcrumb-refactor
anandtiwary f054311
refactor: fix test
anandtiwary d7307b4
Merge branch 'breadcrumb-refactor' of github.com:hypertrace/hypertrac…
anandtiwary 305e1f1
refactor: addressing review comments
anandtiwary f3e855d
refactor: fixing test
anandtiwary e6895e8
refactor: fixing lint
anandtiwary ca25f5c
refactor: addressing review comments
anandtiwary 9c61b3d
refactor: fixing test
anandtiwary 8a0bdef
refactor: update breadcrumb and fix tests
anandtiwary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 16 additions & 47 deletions
63
projects/observability/src/pages/apis/service-detail/service-detail-breadcrumb.resolver.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
projects/observability/src/shared/services/entity-breadcrumb/entity-breadcrumb.resolver.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { ActivatedRouteSnapshot, Resolve } from '@angular/router'; | ||
| import { Breadcrumb, TimeRangeService } from '@hypertrace/common'; | ||
| import { GraphQlRequestCacheability, GraphQlRequestOptions, 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 EntityBreadcrumb = EntityBreadcrumb> | ||
| implements Resolve<Observable<EntityBreadcrumb>> { | ||
| 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<EntityBreadcrumb>>; | ||
|
|
||
| protected abstract getAttributeKeys(): string[]; | ||
|
|
||
| protected getAdditionalSpecifications(): Specification[] { | ||
| return []; | ||
| } | ||
|
|
||
| protected getRequestOptions(): GraphQlRequestOptions | undefined { | ||
| return { cacheability: GraphQlRequestCacheability.Cacheable }; | ||
| } | ||
|
|
||
| protected fetchEntity(id: string, entityType: string): Observable<T> { | ||
| 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) | ||
| }, | ||
| this.getRequestOptions() | ||
| ) | ||
| ), | ||
| 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) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export interface EntityBreadcrumb extends Breadcrumb, Entity {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.