Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
dd20f13
refactor: time range styles
Feb 8, 2022
a8523ab
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Bread…
Feb 9, 2022
4bfa6d6
feat: initial browser stored page time range
Feb 11, 2022
63a665e
fix: removed defaultTimeRange null check for throwing error
Feb 11, 2022
b81ae1a
refactor: time range logic to be query param centric
Feb 14, 2022
6e84fbe
refactor: update effected tests
Feb 14, 2022
ab466fe
Merge branch 'main' into BreadcrumbsTimeRange
Feb 14, 2022
3043f45
fix: replace arrow function for compiler
Feb 14, 2022
56c574b
fix: time range isCustom correction
Feb 15, 2022
c1be553
refactor: moved time range logic to sub component
Feb 16, 2022
8eb3a52
fix: adjusted time range style to match other header buttons
Feb 16, 2022
ffe3d6b
fix: linting
Feb 16, 2022
3f98a99
refactor: cleaned up nav params observable
Feb 16, 2022
f0d9ffe
fix: linting
Feb 16, 2022
e1bea69
refactor: feature flag added
Feb 17, 2022
b359fcd
test: tests for new time range
Feb 18, 2022
ab36992
test: linter
Feb 18, 2022
cd870bc
Merge branch 'main' into BreadcrumbsTimeRange
Feb 18, 2022
7a92d50
test: added new test for time range service
Feb 22, 2022
b241e0e
fix: pr changes
Feb 23, 2022
7e279e4
fix: linting
Feb 23, 2022
10e8225
Merge branch 'main' into BreadcrumbsTimeRange
Feb 23, 2022
1738b10
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Bread…
Feb 23, 2022
c44b03b
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Bread…
Feb 28, 2022
bd1cbbd
Merge branch 'BreadcrumbsTimeRange' of github.com:hypertrace/hypertra…
Feb 28, 2022
3adc661
fix: requested changes
Mar 1, 2022
6e78e54
fix: export feature enum
Mar 1, 2022
c225cf9
refactor: replaced time range icon with calendar
Mar 2, 2022
c2d0287
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Bread…
Mar 3, 2022
7bc71c7
fix: requested changes
Mar 3, 2022
b4b4722
fix: backwards compatability and depency issue changes
Mar 4, 2022
a528987
fix: requested changes
Mar 7, 2022
63c4bd0
fix: requested changes
Mar 8, 2022
8742a2b
fix: requested changes
Mar 9, 2022
b795d39
fix: linting
Mar 9, 2022
9ed2b22
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Bread…
Mar 9, 2022
67c8bfe
fix: moved tr selector back to components
Mar 9, 2022
0854000
fix: update test
Mar 9, 2022
62d1041
refactor: requested changes
Mar 9, 2022
5037200
refactor: requested changes
Christian862 Mar 10, 2022
11b0991
refactor: requested changes
Christian862 Mar 10, 2022
50153f9
refactor: requested changes
Christian862 Mar 10, 2022
12ab84d
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Bread…
Christian862 Mar 10, 2022
ea6357a
refactor: requested changes
Christian862 Mar 11, 2022
b558d41
fix: linting
Christian862 Mar 11, 2022
0989a6a
fix: requested changes - naming and TR service
Christian862 Mar 11, 2022
3845357
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Bread…
Christian862 Mar 14, 2022
a37a477
fix: requested changes
Christian862 Mar 14, 2022
00f785a
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Bread…
Christian862 Mar 14, 2022
82a9612
fix: requested changes - broken
Christian862 Mar 15, 2022
9714df8
fix: requested changes
Christian862 Mar 15, 2022
4b0b74e
test: testing support for new TR init
Christian862 Mar 15, 2022
44a67b6
refactor: requested changes
Christian862 Mar 15, 2022
bfcb9b8
refactor: requested changes, updated route data for new changes
Christian862 Mar 16, 2022
38c5e82
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Bread…
Christian862 Mar 16, 2022
efd4d15
refactor: requested changes
Christian862 Mar 18, 2022
5e5dcf5
refactor: requested changes
Christian862 Mar 18, 2022
7172091
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Bread…
Christian862 Mar 18, 2022
505d5d7
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Bread…
Christian862 Mar 18, 2022
748743e
refactor: requested changes
Christian862 Mar 18, 2022
09cf639
refactor: requested changes
Christian862 Mar 18, 2022
5c0cfe6
refactor: fix FF string
Christian862 Mar 18, 2022
541555f
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Bread…
Christian862 Mar 21, 2022
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
8 changes: 8 additions & 0 deletions projects/assets-library/assets/styles/_interaction.scss
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,11 @@
cursor: not-allowed;
}
}

@mixin time-range-button-background {
background-color: white;

&:hover {
background-color: $gray-1;
}
}
2 changes: 2 additions & 0 deletions projects/common/src/navigation/ht-route-data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Observable } from 'rxjs';
import { TimeRange } from '../time/time-range';
import { Breadcrumb } from './breadcrumb';

export interface HtRouteData {
breadcrumb?: Breadcrumb | Observable<Breadcrumb>;
features?: string[];
title?: string;
defaultTimeRange?: TimeRange;
}
1 change: 1 addition & 0 deletions projects/common/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export * from './time/time-range.service';
export * from './time/time-range.type';
export * from './time/time-unit.type';
export * from './time/time';
export * from './time/page-time-range.service';

// Validators
export * from './utilities/validators';
2 changes: 1 addition & 1 deletion projects/common/src/time/fixed-time-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export class FixedTimeRange implements TimeRange {

Copy link
Contributor Author

@Christian862 Christian862 Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with @anandtiwary, the values here and in RelativeTimeRange were a mistake and assigned incorrectly. Fixing them here because part of the PR depends on them. Other than this PR no other places use them

public isCustom(): boolean {
// Right now all RelativeTimeRanges are NOT custom; all FixedTimeRanges are
return false;
return true;
}
}
63 changes: 63 additions & 0 deletions projects/common/src/time/page-time-range-service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
FixedTimeRange,
NavigationService,
PageTimeRangeService,
RelativeTimeRange,
TimeDuration,
TimeRange,
TimeRangeService,
TimeUnit
} from '@hypertrace/common';
import { runFakeRxjs } from '@hypertrace/test-utils';
import { createServiceFactory, mockProvider } from '@ngneat/spectator/jest';

describe('Page time range service', () => {
const serviceFactory = createServiceFactory({
service: PageTimeRangeService,
providers: [mockProvider(NavigationService)]
});

test('Setting fixed time range emits corresponding time range from preferences', () => {
runFakeRxjs(({ expectObservable, cold }) => {
const timeRange: TimeRange = new FixedTimeRange(new Date(1573255100253), new Date(1573255111159));
const spectator = serviceFactory({
providers: [
mockProvider(TimeRangeService, {
timeRangeFromUrlString: jest.fn().mockReturnValue(timeRange)
})
]
});

cold('-a|', {
a: () => spectator.service.setPageTimeRange('foo', timeRange)
}).subscribe(update => update());

expectObservable(spectator.service.getPageTimeRange('foo')).toBe('da', {
d: undefined,
a: timeRange
});
});
});

test('Setting relative time range emits corresponding time range from preferences', () => {
runFakeRxjs(({ expectObservable, cold }) => {
const timeRange: TimeRange = new RelativeTimeRange(new TimeDuration(1, TimeUnit.Hour));
const spectator = serviceFactory({
providers: [
mockProvider(TimeRangeService, {
timeRangeFromUrlString: jest.fn().mockReturnValue(timeRange)
})
]
});

cold('-b|', {
b: () => spectator.service.setPageTimeRange('bar', timeRange)
}).subscribe(update => update());

expectObservable(spectator.service.getPageTimeRange('bar')).toBe('db', {
d: undefined,
b: timeRange
});
});
});
});
60 changes: 60 additions & 0 deletions projects/common/src/time/page-time-range.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Injectable, OnDestroy } from '@angular/core';
import { isNil } from 'lodash-es';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { distinctUntilChanged, map, share, takeUntil } from 'rxjs/operators';
import { PreferenceService, StorageType } from '../preference/preference.service';
import { TimeRange } from './time-range';
import { TimeRangeService } from './time-range.service';

@Injectable({ providedIn: 'root' })
export class PageTimeRangeService implements OnDestroy {
// TODO change to local ??
private static readonly STORAGE_TYPE: StorageType = StorageType.Session;
private static readonly TIME_RANGE_PREFERENCE_KEY: string = 'page-time-range';
private readonly destroyed$: Subject<void> = new Subject();

private readonly pageTimeRanges$: BehaviorSubject<PageTimeRangeMap> = new BehaviorSubject<PageTimeRangeMap>({});
private readonly storedTimeRanges$: Observable<PageTimeRangeMap> = this.preferenceService
.get<PageTimeRangeMap>(PageTimeRangeService.TIME_RANGE_PREFERENCE_KEY, {}, PageTimeRangeService.STORAGE_TYPE)
.pipe(takeUntil(this.destroyed$));

public constructor(
private readonly preferenceService: PreferenceService,
private readonly timeRangeService: TimeRangeService
) {
this.storedTimeRanges$.subscribe(values => {
this.pageTimeRanges$.next(values);
});
}

public getPageTimeRange(path: string): Observable<TimeRange | undefined> {
return this.storedTimeRanges$.pipe(
distinctUntilChanged((prev, curr) => prev[path] === curr[path]),
map(timeRanges =>
!isNil(timeRanges[path]) ? this.timeRangeService.timeRangeFromUrlString(timeRanges[path]) : undefined
),
share()
);
}

public setPageTimeRange(path: string, value: TimeRange): void {
const pageTimeMap: PageTimeRangeMap = this.pageTimeRanges$.getValue();

const newMap: PageTimeRangeMap = { ...pageTimeMap, [path]: value.toUrlString() };

this.preferenceService.set(
PageTimeRangeService.TIME_RANGE_PREFERENCE_KEY,
newMap,
PageTimeRangeService.STORAGE_TYPE
);
}

public ngOnDestroy(): void {
this.destroyed$.next();
this.destroyed$.complete();
}
}

interface PageTimeRangeMap {
[path: string]: string;
}
4 changes: 2 additions & 2 deletions projects/common/src/time/relative-time-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export class RelativeTimeRange implements TimeRange {
}

public isCustom(): boolean {
// Right now all RelativeTimeRanges are NOT custom; all FixedTimeRanges are
return true;
// Right now all RelativeTimeRanges ARE custom; all FixedTimeRanges are NOT
return false;
}

public toUrlString(): string {
Expand Down
8 changes: 5 additions & 3 deletions projects/common/src/time/time-range.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ActivatedRoute, convertToParamMap } from '@angular/router';
import { RelativeTimeRange, TimeDuration, TimeUnit } from '@hypertrace/common';
import { runFakeRxjs } from '@hypertrace/test-utils';
import { createServiceFactory, mockProvider } from '@ngneat/spectator/jest';
import { NEVER, Observable, of } from 'rxjs';
Expand All @@ -18,9 +19,10 @@ describe('Time range service', () => {
map(
initialTrString =>
// tslint:disable-next-line: no-object-literal-type-assertion
({
queryParamMap: of(convertToParamMap({ time: initialTrString }))
} as ActivatedRoute)
(({
queryParamMap: of(convertToParamMap({ time: initialTrString })),
snapshot: { data: { defaultTimeRange: new RelativeTimeRange(new TimeDuration(1, TimeUnit.Hour)) } }
} as unknown) as ActivatedRoute)
)
);
}
Expand Down
29 changes: 19 additions & 10 deletions projects/common/src/time/time-range.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { isEmpty } from 'lodash-es';
import { EMPTY, ReplaySubject } from 'rxjs';
import { catchError, defaultIfEmpty, filter, map, switchMap, take } from 'rxjs/operators';
import { combineLatest, EMPTY, ReplaySubject } from 'rxjs';
import { catchError, defaultIfEmpty, map, switchMap } from 'rxjs/operators';
import { NavigationService, QueryParamObject } from '../navigation/navigation.service';
import { ReplayObservable } from '../utilities/rxjs/rxjs-utils';
import { FixedTimeRange } from './fixed-time-range';
Expand Down Expand Up @@ -64,14 +64,23 @@ export class TimeRangeService {
}

private initializeTimeRange(): void {
this.navigationService.navigation$
combineLatest([
this.navigationService.navigation$,
this.navigationService.navigation$.pipe(switchMap(activatedRoute => activatedRoute.queryParamMap))
])
.pipe(
take(1), // Wait for first navigation
switchMap(activatedRoute => activatedRoute.queryParamMap), // Get the params from it
take(1), // Only the first set of params
map(paramMap => paramMap.get(TimeRangeService.TIME_RANGE_QUERY_PARAM)), // Extract the time range value from it
filter((timeRangeString): timeRangeString is string => !isEmpty(timeRangeString)), // Only valid time ranges
map(timeRangeString => this.timeRangeFromUrlString(timeRangeString)),
map(([activeRoute, paramMap]) => {
const defaultPageTimeRange = activeRoute.snapshot.data?.defaultTimeRange;
const timeRangeString = paramMap.get(TimeRangeService.TIME_RANGE_QUERY_PARAM);

if (typeof timeRangeString === 'string' && !isEmpty(timeRangeString)) {
return this.timeRangeFromUrlString(timeRangeString);
}
if (defaultPageTimeRange) {
return defaultPageTimeRange;
}
throw Error();
}),
catchError(() => EMPTY),
defaultIfEmpty(this.defaultTimeRange)
)
Expand All @@ -80,7 +89,7 @@ export class TimeRangeService {
});
}

private timeRangeFromUrlString(timeRangeFromUrl: string): TimeRange {
public timeRangeFromUrlString(timeRangeFromUrl: string): TimeRange {
const duration = this.timeDurationService.durationFromString(timeRangeFromUrl);
if (duration) {
return new RelativeTimeRange(duration);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Directive, TemplateRef } from '@angular/core';

@Directive({
selector: '[htHeaderContentPrimary]'
})
export class HeaderContentPrimaryDirective {
public constructor(public templateRef: TemplateRef<unknown>) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Directive, TemplateRef } from '@angular/core';

@Directive({
selector: '[htHeaderContentSecondary]'
})
export class HeaderContentSecondaryDirective {
public constructor(public templateRef: TemplateRef<unknown>) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { HeaderContentPrimaryDirective } from './header-content-primary.directive';
import { HeaderContentSecondaryDirective } from './header-content-secondary.directive';

@NgModule({
declarations: [HeaderContentPrimaryDirective, HeaderContentSecondaryDirective],
exports: [HeaderContentPrimaryDirective, HeaderContentSecondaryDirective],
imports: [CommonModule],
providers: []
})
export class HeaderContentModule {}
54 changes: 32 additions & 22 deletions projects/components/src/header/page/page-header.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,50 @@
.column-alignment {
display: flex;
flex-direction: column;
}

.row-alignment {
display: flex;
justify-content: space-between;
}
.primary-content {
display: flex;
justify-content: space-between;

&.bottom-border {
padding-bottom: 16px;
border-bottom: 1px solid $color-border;
}
.breadcrumb-container {
align-items: center;
margin-right: auto;

.breadcrumb-container {
align-items: center;
.breadcrumb-separator {
padding: 0 20px;
}

.breadcrumb-separator {
padding: 0 20px;
}
.title {
@include font-subtitle-medium($gray-7);
display: flex;
align-items: center;

.title {
@include font-subtitle-medium($gray-7);
display: flex;
align-items: center;
.icon {
padding-right: 12px;
}

.icon {
padding-right: 12px;
.beta {
margin-left: 12px;
}
}
}

.beta {
margin-left: 12px;
.time-range {
margin-left: 10px;
}
}
}

.row-alignment {
display: flex;
justify-content: space-between;
}

&.bottom-border {
padding-bottom: 16px;
border-bottom: 1px solid $color-border;
}

.tabs {
padding-top: 16px;
}
Expand Down
Loading