-
Notifications
You must be signed in to change notification settings - Fork 11
fix: hide navigation header if there is nothing underneath #1024
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 all commits
8bf3da5
5599c6a
88d3bd4
cd18474
2aa1a9b
111e41d
58f01ef
f8726d6
d19e8a8
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { IconType } from '@hypertrace/assets-library'; | ||
import { NavigationService } from '@hypertrace/common'; | ||
import { Observable } from 'rxjs'; | ||
import { FeatureState, FeatureStateResolver, NavigationService } from '@hypertrace/common'; | ||
import { isEmpty } from 'lodash-es'; | ||
import { combineLatest, Observable, of } from 'rxjs'; | ||
import { map, startWith } from 'rxjs/operators'; | ||
import { IconSize } from '../icon/icon-size'; | ||
|
||
|
@@ -13,13 +14,15 @@ import { IconSize } from '../icon/icon-size'; | |
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"> | ||
<ng-container *ngFor="let item of this.navItems; let id = index"> | ||
<ng-container [ngSwitch]="item.type"> | ||
<div *ngIf="!this.collapsed"> | ||
<div *ngSwitchCase="'${NavItemType.Header}'" class="nav-header"> | ||
<div class="label">{{ item.label }}</div> | ||
<ht-beta-tag *ngIf="item.isBeta" class="beta"></ht-beta-tag> | ||
</div> | ||
<ng-container *ngSwitchCase="'${NavItemType.Header}'"> | ||
<div *ngIf="this.shouldShowHeader(id) | async" class="nav-header"> | ||
<div class="label">{{ item.label }}</div> | ||
<ht-beta-tag *ngIf="item.isBeta" class="beta"></ht-beta-tag> | ||
</div> | ||
</ng-container> | ||
</div> | ||
|
||
<hr *ngSwitchCase="'${NavItemType.Divider}'" class="nav-divider" /> | ||
|
@@ -68,7 +71,8 @@ export class NavigationListComponent { | |
|
||
public constructor( | ||
private readonly navigationService: NavigationService, | ||
private readonly activatedRoute: ActivatedRoute | ||
private readonly activatedRoute: ActivatedRoute, | ||
private readonly featureStateResolver: FeatureStateResolver | ||
) { | ||
this.activeItem$ = this.navigationService.navigation$.pipe( | ||
startWith(this.navigationService.getCurrentActivatedRoute()), | ||
|
@@ -87,6 +91,26 @@ export class NavigationListComponent { | |
return this.collapsed ? IconType.TriangleRight : IconType.TriangleLeft; | ||
} | ||
|
||
public shouldShowHeader(index: number): Observable<boolean> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use htMemoize |
||
const features = []; | ||
for (let i = index + 1; i < this.navItems.length; i++) { | ||
if (this.navItems[i].type !== NavItemType.Link) { | ||
break; | ||
} | ||
|
||
const navLinkItemFeatures = (this.navItems[i] as NavItemLinkConfig).features; | ||
features.push(isEmpty(navLinkItemFeatures) ? 'None' : navLinkItemFeatures); | ||
} | ||
|
||
return isEmpty(features.flat()) | ||
? of(false) | ||
: combineLatest( | ||
features | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't need to check feature flag state every time. One resolution per browser refresh is enough. Then we can just share the same result throughout (till another browser refresh) |
||
.flat() | ||
.map(f => (f === 'None' ? of(FeatureState.Enabled) : this.featureStateResolver.getFeatureState(f!))) | ||
).pipe(map(states => states.some(state => state === FeatureState.Enabled))); | ||
} | ||
|
||
private findActiveItem(navItems: NavItemConfig[]): NavItemLinkConfig | undefined { | ||
return navItems | ||
.filter((item): item is NavItemLinkConfig => item.type === NavItemType.Link) | ||
|
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.
Shouldn't this show up since there is not feature flag applied?