Skip to content
Merged
Changes from 3 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import {
QueryList
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Color, FeatureState, NavigationParams, NavigationParamsType, NavigationService } from '@hypertrace/common';
import {
Color,
FeatureState,
NavigationParams,
NavigationParamsType,
NavigationService,
queryListAndChanges$
} from '@hypertrace/common';
import { merge, Observable } from 'rxjs';
import { distinctUntilChanged, map, startWith, tap } from 'rxjs/operators';
import { NavigableTabComponent } from './navigable-tab.component';
Expand All @@ -20,7 +27,7 @@ import { NavigableTabComponent } from './navigable-tab.component';
template: `
<div class="tab-group">
<nav mat-tab-nav-bar *htLetAsync="this.activeTab$ as activeTab" disableRipple>
<ng-container *ngFor="let tab of this.tabs">
<ng-container *ngFor="let tab of this.tabs$ | async">
<ng-container *ngIf="!tab.hidden">
<div class="tab-button" *htIfFeature="tab.featureFlags | htFeature as featureState">
<ht-link
Expand Down Expand Up @@ -49,23 +56,28 @@ import { NavigableTabComponent } from './navigable-tab.component';
</nav>
<div class="divider"></div>
</div>

<!-- When tabs input changes, change detection will be triggered automatically -->
<ng-container *ngIf="tabs.changes | async"></ng-container>
`
})
export class NavigableTabGroupComponent implements AfterContentInit {
@ContentChildren(NavigableTabComponent)
public tabs!: QueryList<NavigableTabComponent>;
private readonly tabs!: QueryList<NavigableTabComponent>;

@Output()
public readonly tabChange: EventEmitter<string | undefined> = new EventEmitter<string | undefined>();

public activeTab$?: Observable<NavigableTabComponent | undefined>;
public tabs$!: Observable<NavigableTabComponent[]>;

public constructor(
public readonly navigationService: NavigationService,
private readonly activatedRoute: ActivatedRoute
) {}

public ngAfterContentInit(): void {
this.tabs$ = queryListAndChanges$(this.tabs).pipe(map(list => list.toArray()));
this.activeTab$ = merge(this.navigationService.navigation$, this.tabs.changes).pipe(
startWith(undefined),
map(() => this.findActiveTab()),
Expand Down