Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions projects/common/src/constants/application-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ import { InjectionToken } from '@angular/core';
export const GLOBAL_HEADER_HEIGHT = new InjectionToken<string>('Global Header Height');

export const enum ApplicationFeature {
PageTimeRange = 'ui.page-time-range',
NavigationRedesign = 'ui.navigation-version-2'
PageTimeRange = 'ui.page-time-range'
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
FeatureState,
FeatureStateResolver,
FixedTimeRange,
NavigationService,
RelativeTimeRange,
Expand All @@ -9,6 +11,7 @@ import {
} from '@hypertrace/common';
import { runFakeRxjs } from '@hypertrace/test-utils';
import { createServiceFactory, mockProvider } from '@ngneat/spectator/jest';
import { of } from 'rxjs';
import { PageTimeRangePreferenceService } from './page-time-range-preference.service';

describe('Page time range preference service', () => {
Expand All @@ -18,6 +21,9 @@ describe('Page time range preference service', () => {
providers: [
mockProvider(NavigationService, {
getRouteConfig: jest.fn().mockReturnValue({ data: { defaultTimeRange: defaultPageTimeRange } })
}),
mockProvider(FeatureStateResolver, {
getFeatureState: jest.fn().mockReturnValue(of(FeatureState.Enabled))
})
]
});
Expand Down
32 changes: 17 additions & 15 deletions projects/common/src/time/page-time-range-preference.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { isNil } from 'lodash-es';
import { combineLatest, Observable } from 'rxjs';
import { map, shareReplay, take } from 'rxjs/operators';
Expand All @@ -18,8 +19,6 @@ export class PageTimeRangePreferenceService {
private static readonly STORAGE_TYPE: StorageType = StorageType.Local;
private static readonly TIME_RANGE_PREFERENCE_KEY: string = 'page-time-range';

private readonly globalDefaultTimeRange: TimeRange = new RelativeTimeRange(new TimeDuration(30, TimeUnit.Minute));

private readonly pageTimeRangeStringDictionary$: Observable<PageTimeRangeStringDictionary>;

public constructor(
Expand All @@ -31,26 +30,22 @@ export class PageTimeRangePreferenceService {
this.pageTimeRangeStringDictionary$ = this.buildPageTimeRangeObservable();
}

public getTimeRangePreferenceForPage(rootLevelPath: string): Observable<TimeRange> {
public getTimeRangePreferenceForPage(rootLevelPath: string): Observable<TimeRangeCallback> {
return combineLatest([
this.pageTimeRangeStringDictionary$,
this.featureStateResolver.getCombinedFeatureState([
ApplicationFeature.PageTimeRange,
ApplicationFeature.NavigationRedesign
])
this.featureStateResolver.getFeatureState(ApplicationFeature.PageTimeRange)
]).pipe(
map(([pageTimeRangeStringDictionary, featureState]) => {
if (featureState === FeatureState.Enabled) {
if (isNil(pageTimeRangeStringDictionary[rootLevelPath])) {
// Right side for when FFs are enabled but page path doesn't have 'defaultTimeRange' set on AR data
return this.getDefaultPageTimeRange() ?? this.globalDefaultTimeRange;
return this.getDefaultTimeRangeForCurrentRoute;
}

return this.timeRangeService.timeRangeFromUrlString(pageTimeRangeStringDictionary[rootLevelPath]);
return () => this.timeRangeService.timeRangeFromUrlString(pageTimeRangeStringDictionary[rootLevelPath]);
}

// When FFs are disabled
return this.globalDefaultTimeRange;
// When FF is disabled
return this.getGlobalDefaultTimeRange;
})
);
}
Expand Down Expand Up @@ -83,11 +78,18 @@ export class PageTimeRangePreferenceService {
.pipe(shareReplay(1));
}

private getDefaultPageTimeRange(): TimeRange | undefined {
return this.navigationService.getCurrentActivatedRoute().snapshot.data?.defaultTimeRange;
}
public getDefaultTimeRangeForCurrentRoute = (): TimeRange => {
const currentRoute: ActivatedRoute = this.navigationService.getCurrentActivatedRoute();
// Right side for when FF is enabled but 'defaultTimeRange' is not set on AR data
return currentRoute.snapshot.data?.defaultTimeRange ?? this.getGlobalDefaultTimeRange();
};

public getGlobalDefaultTimeRange = (): TimeRange => {
return new RelativeTimeRange(new TimeDuration(1, TimeUnit.Hour));
};
}

interface PageTimeRangeStringDictionary {
[path: string]: string;
}
export type TimeRangeCallback = () => TimeRange;
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
ApplicationFeature,
FeatureState,
FeatureStateResolver,
NavigationService,
Expand All @@ -12,7 +11,6 @@ import { of } from 'rxjs';
import { BreadcrumbsService } from '../../breadcrumbs/breadcrumbs.service';
import { FeatureConfigCheckModule } from '../../feature-check/feature-config-check.module';
import { PageTimeRangeComponent } from '../../page-time-range/page-time-range.component';
import { TimeRangeComponent } from '../../time-range/time-range.component';
import { PageHeaderComponent } from './page-header.component';

describe('Page Header Component', () => {
Expand All @@ -21,7 +19,7 @@ describe('Page Header Component', () => {
const createHost = createHostFactory({
component: PageHeaderComponent,
imports: [FeatureConfigCheckModule],
declarations: [MockComponent(PageTimeRangeComponent), MockComponent(TimeRangeComponent)],
declarations: [MockComponent(PageTimeRangeComponent)],
shallow: true,
providers: [
mockProvider(NavigationService),
Expand Down Expand Up @@ -50,7 +48,7 @@ describe('Page Header Component', () => {
expect(spectator.query('.beta')).not.toExist();
});

test('should display page time range component when feature flags are enabled', () => {
test('should display page time range component when feature flag is enabled', () => {
spectator = createHost('<ht-page-header></ht-page-header>', {
providers: [
mockProvider(FeatureStateResolver, {
Expand All @@ -60,26 +58,6 @@ describe('Page Header Component', () => {
});

expect(spectator.query(PageTimeRangeComponent)).toExist();
expect(spectator.query(TimeRangeComponent)).not.toExist();
});

test('should display time-range component when navigation feature flag is disabled and page time range is enabled', () => {
spectator = createHost('<ht-page-header></ht-page-header>', {
providers: [
mockProvider(FeatureStateResolver, {
getCombinedFeatureState: jest.fn().mockImplementation(([feature]) => {
if (feature === ApplicationFeature.NavigationRedesign) {
return of(FeatureState.Disabled);
}

return of(FeatureState.Enabled);
})
})
]
});

expect(spectator.query(PageTimeRangeComponent)).not.toExist();
expect(spectator.query(TimeRangeComponent)).toExist();
});

test('should not display any time range if FF is disabled', () => {
Expand All @@ -92,6 +70,5 @@ describe('Page Header Component', () => {
});

expect(spectator.query(PageTimeRangeComponent)).not.toExist();
expect(spectator.query(TimeRangeComponent)).not.toExist();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@ import { NavigableTab } from '../../tabs/navigable/navigable-tab';
<ng-container *ngIf="this.contentAlignment === '${PageHeaderContentAlignment.Row}'">
<ng-container *ngTemplateOutlet="this.projectedContentTemplate"></ng-container>
</ng-container>
<ht-page-time-range
class="time-range"
*htIfFeature="'${ApplicationFeature.NavigationRedesign}' | htFeature; else globalTimeRangeTemplate"
></ht-page-time-range>

<ng-template #globalTimeRangeTemplate>
<ht-time-range></ht-time-range>
</ng-template>
<ht-page-time-range class="time-range"></ht-page-time-range>
</div>
<ng-container *ngIf="this.contentAlignment === '${PageHeaderContentAlignment.Column}'">
<ng-container *ngTemplateOutlet="this.projectedContentTemplate"></ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe('Navigation List Component Service', () => {
service: NavigationListComponentService,
providers: [
mockProvider(FeatureStateResolver, {
getCombinedFeatureState: jest.fn().mockReturnValue(of(FeatureState.Enabled))
getCombinedFeatureState: jest.fn().mockReturnValue(of(FeatureState.Enabled)),
getFeatureState: jest.fn().mockReturnValue(of(FeatureState.Enabled))
}),
mockProvider(PageTimeRangePreferenceService, {
getTimeRangePreferenceForPage: jest.fn().mockReturnValue(of(mockTimeRange))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Injectable } from '@angular/core';
import { FeatureState, FeatureStateResolver, PageTimeRangePreferenceService } from '@hypertrace/common';
import {
ApplicationFeature,
FeatureState,
FeatureStateResolver,
PageTimeRangePreferenceService
} from '@hypertrace/common';
import { isEmpty } from 'lodash-es';
import { combineLatest, Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { map, switchMap } from 'rxjs/operators';
import { NavItemConfig, NavItemHeaderConfig, NavItemLinkConfig, NavItemType } from './navigation.config';

@Injectable({ providedIn: 'root' })
Expand All @@ -29,11 +34,10 @@ export class NavigationListComponentService {
return updatedItems;
}

public resolveNavItemConfigTimeRanges(
navItems: NavItemConfig[],
pageLevelTimeRangeFeatureState: FeatureState
): Observable<NavItemConfig[]> {
return combineLatest(this.getTimeRangesForNavItems(navItems, pageLevelTimeRangeFeatureState));
public resolveNavItemConfigTimeRanges(navItems: NavItemConfig[]): Observable<NavItemConfig[]> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Called by NavigationListComponent to decorate each navItem with it's time range. It retrieves the time range for each navItem with it's respective path from getUserSpecifiedTimeRangeForPage, then adds it to the navItem, and returns them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we combine this into the one existing resolve call? we shouldn't have to call resolve multiple times for each piece of data we want to resolve. Easy bug to miss.

Copy link
Contributor

Choose a reason for hiding this comment

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

Kept these apart for readability and FF backwards compatibility

Not sure that we helped in either respect (I would consider the FF evaluation part of the resolution logic, and thus the responsibility of the resolver), but this is really just a style preference, so your call.

return this.featureStateResolver
.getFeatureState(ApplicationFeature.PageTimeRange)
.pipe(switchMap(featureState => combineLatest(this.getTimeRangesForNavItems(navItems, featureState))));
Copy link
Contributor

Choose a reason for hiding this comment

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

So any time a time range is saved, you would get a whole new set of nav items?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, is there a better operator for this ?

Copy link
Contributor

@aaron-steinfeld aaron-steinfeld Mar 18, 2022

Choose a reason for hiding this comment

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

This gets back to the suggestion to do the resolution on click rather than up front, but we can revisit later as discussed. Just need to make sure with this approach that a new set of items doesn't cause issues (e.g. losing the active item, flickering due to re-render etc.)

}

private getTimeRangesForNavItems(
Expand All @@ -43,9 +47,9 @@ export class NavigationListComponentService {
return navItems.map(navItem => {
if (navItem.type === NavItemType.Link) {
return this.pageTimeRangePreferenceService.getTimeRangePreferenceForPage(navItem.matchPaths[0]).pipe(
map(timeRange => ({
map(resolveTimeRange => ({
...navItem,
timeRange: timeRange,
resolveTimeRange: resolveTimeRange,
pageLevelTimeRangeIsEnabled: pageLevelTimeRangeFeatureState === FeatureState.Enabled
}))
);
Expand Down
68 changes: 16 additions & 52 deletions projects/components/src/navigation/navigation-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { IconType } from '@hypertrace/assets-library';
import {
ApplicationFeature,
FeatureStateResolver,
FixedTimeRange,
NavigationService,
RelativeTimeRange,
TimeRangeService,
TypedSimpleChanges
} from '@hypertrace/common';
import { isNil } from 'lodash-es';
import { combineLatest, Observable } from 'rxjs';
import { map, shareReplay, startWith, switchMap } from 'rxjs/operators';
import { NavigationService, TimeRangeService, TypedSimpleChanges } from '@hypertrace/common';
import { Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
import { IconSize } from '../icon/icon-size';
import { NavigationListComponentService } from './navigation-list-component.service';
import { FooterItemConfig, NavItemConfig, NavItemLinkConfig, NavItemType } from './navigation.config';
Expand All @@ -24,7 +15,7 @@ import { FooterItemConfig, NavItemConfig, NavItemLinkConfig, NavItemType } from
template: `
<nav class="navigation-list" [ngClass]="{ expanded: !this.collapsed }">
<div class="content" *htLetAsync="this.activeItem$ as activeItem" [htLayoutChangeTrigger]="this.collapsed">
<ng-container *ngFor="let item of this.navItems$ | async; let id = index">
<ng-container *ngFor="let item of this.navItems; let id = index">
<ng-container [ngSwitch]="item.type">
<div *ngIf="!this.collapsed">
<ng-container *ngSwitchCase="'${NavItemType.Header}'">
Expand All @@ -39,7 +30,7 @@ import { FooterItemConfig, NavItemConfig, NavItemLinkConfig, NavItemType } from

<ng-container *ngSwitchCase="'${NavItemType.Link}'">
<ht-nav-item
(click)="this.setPageTimeRangeForSelectedNavItem(item)"
(click)="this.navItemSelected.emit(item)"
[config]="item"
[active]="item === activeItem"
[collapsed]="this.collapsed"
Expand Down Expand Up @@ -82,46 +73,31 @@ export class NavigationListComponent implements OnChanges {
@Output()
public readonly collapsedChange: EventEmitter<boolean> = new EventEmitter();

public activeItem$?: Observable<NavItemLinkConfig | undefined>;
@Output()
public readonly navItemSelected: EventEmitter<NavItemLinkConfig> = new EventEmitter();

public navItems$?: Observable<NavItemConfig[]>;
public activeItem$?: Observable<NavItemLinkConfig | undefined>;

public constructor(
private readonly navigationService: NavigationService,
private readonly activatedRoute: ActivatedRoute,
private readonly navListComponentService: NavigationListComponentService,
private readonly timeRangeService: TimeRangeService,
private readonly featureStateResolver: FeatureStateResolver
private readonly timeRangeService: TimeRangeService
) {}

public ngOnChanges(changes: TypedSimpleChanges<this>): void {
if (changes.navItems) {
this.navItems = this.navListComponentService.resolveFeaturesAndUpdateVisibilityForNavItems(this.navItems);

// Decorate the nav items with the corresponding time ranges, depending on the FF state.
// The time ranges in nav items are streams that get the most recent value from page time range preference service
this.navItems$ = this.featureStateResolver
.getCombinedFeatureState([ApplicationFeature.PageTimeRange, ApplicationFeature.NavigationRedesign])
.pipe(
switchMap(pageLevelTimeRangeFeature =>
this.navListComponentService.resolveNavItemConfigTimeRanges(this.navItems, pageLevelTimeRangeFeature)
),
shareReplay()
);

// For each nav item, find the (possibly new) active nav item
// Time range is set on component load, when it isn't already
// Initialize the time range service
// Depending on FF status, the TR will be either global or page level for the init
this.activeItem$ = combineLatest([
this.navItems$,
this.navigationService.navigation$.pipe(startWith(this.navigationService.getCurrentActivatedRoute()))
]).pipe(
map(([navItems]) => {
const activeItem = this.findActiveItem(navItems);
if (!this.timeRangeService.isInitialized() && activeItem) {
this.timeRangeService.setDefaultTimeRange(activeItem.timeRange!);
this.activeItem$ = this.navigationService.navigation$.pipe(
startWith(this.navigationService.getCurrentActivatedRoute()),
map(() => {
const activeItem = this.findActiveItem(this.navItems);
if (!this.timeRangeService.isInitialized() && activeItem?.resolveTimeRange) {
this.timeRangeService.setDefaultTimeRange(activeItem.resolveTimeRange());
Copy link
Contributor

Choose a reason for hiding this comment

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

unclear why we're setting this here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put the logic for calling setDefault in the activeItem$ pipe because it needs the TR value that is decorated on the navItem, and the knowledge of what nav item is currently active, and this captures both, and also this is a shared component.

Copy link
Contributor

Choose a reason for hiding this comment

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

also this is a shared component.

This is my main concern - it's a shared component, and the whole component is used in contexts where we would not want this behavior - I'm guessing that resolveTimeRange is trying to address those cases. I would ideally prefer putting this in the parent left nav instead, unless there's a reason that's not feasible.

}

return activeItem;
})
);
Expand All @@ -139,18 +115,6 @@ export class NavigationListComponent implements OnChanges {
return this.collapsed ? IconType.TriangleRight : IconType.TriangleLeft;
}

public setPageTimeRangeForSelectedNavItem(navItemLink: NavItemLinkConfig): void {
if (!isNil(navItemLink.timeRange) && navItemLink.pageLevelTimeRangeIsEnabled) {
if (navItemLink.timeRange instanceof FixedTimeRange) {
const timeRange: FixedTimeRange = navItemLink.timeRange;
this.timeRangeService.setFixedRange(timeRange.startTime, timeRange.endTime);
} else if (navItemLink.timeRange instanceof RelativeTimeRange) {
const timeRange: RelativeTimeRange = navItemLink.timeRange;
this.timeRangeService.setRelativeRange(timeRange.duration.value, timeRange.duration.unit);
}
}
}

private findActiveItem(navItems: NavItemConfig[]): NavItemLinkConfig | undefined {
return navItems
.filter((item): item is NavItemLinkConfig => item.type === NavItemType.Link)
Expand Down
4 changes: 2 additions & 2 deletions projects/components/src/navigation/navigation.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Color, FeatureState, TimeRange } from '@hypertrace/common';
import { Color, FeatureState, TimeRangeCallback } from '@hypertrace/common';
import { Observable } from 'rxjs';
import { IconSize } from '../icon/icon-size';

Expand All @@ -16,7 +16,7 @@ export interface NavItemLinkConfig {
trailingIcon?: string;
trailingIconTooltip?: string;
trailingIconColor?: Color;
timeRange?: TimeRange;
resolveTimeRange?: TimeRangeCallback;
pageLevelTimeRangeIsEnabled?: boolean;
featureState$?: Observable<FeatureState>;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ActivatedRoute, UrlSegment } from '@angular/router';
import { UrlSegment } from '@angular/router';
import { LoggerService, NavigationService, PageTimeRangePreferenceService, TimeRange } from '@hypertrace/common';
import { isNil } from 'lodash-es';

Expand All @@ -19,13 +19,15 @@ export class PageTimeRangeComponent {
const activatedRoute = this.navigationService.getCurrentActivatedRoute();
const urlSegments: UrlSegment[] = activatedRoute.pathFromRoot.flatMap(activeRoute => activeRoute.snapshot.url);

if (this.shouldSavePageTimeRange(activatedRoute)) {
if (this.shouldSavePageTimeRange()) {
this.savePageTimeRange(selectedTimeRange, urlSegments[0]);
}
}

public shouldSavePageTimeRange(route: ActivatedRoute): boolean {
return !isNil(route.snapshot.data?.defaultTimeRange);
public shouldSavePageTimeRange(): boolean {
const currentRoute = this.navigationService.getCurrentActivatedRoute();

return !isNil(currentRoute.snapshot.data?.defaultTimeRange);
}

public savePageTimeRange(selectedTimeRange: TimeRange, segment: UrlSegment): void {
Expand Down