Skip to content

Commit

Permalink
Add tab parameter to routerLink in event-notifications.component.html…
Browse files Browse the repository at this point in the history
… and machine-page.component.html
  • Loading branch information
akozma89 committed Jan 3, 2024
1 parent ce12ca3 commit 760f390
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
nz-row
class="notification"
[routerLink]="['/machines', data.machine_id]"
[queryParams]="{ tab: 'events' }"
>
<div nz-col nzSpan="6">
<div nz-row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h2>Machine Details</h2>
<nz-col nzSpan="18"></nz-col>
</nz-row>
<ng-template #desrciptionTemplate>
<p>ID: {{ machine.id }}</p>
<nz-tag [nzColor]="getStatusColor(machine.status)">
{{ machine.status }}
</nz-tag>
Expand All @@ -22,8 +23,7 @@ <h2>Machine Details</h2>
></nz-avatar>
</ng-template>
</nz-card>

<nz-tabset>
<nz-tabset [nzSelectedIndex]="currentTabIndex">
<nz-tab nzTitle="Overall">
<nz-list [nzBordered]="false">
<nz-list-item nzNoFlex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('MachinePageComponent', () => {
let fixture: ComponentFixture<MachinePageComponent>;
let activatedRouteStub: Partial<ActivatedRoute>;
let paramMapSpy: jasmine.Spy;
let queryParamMapSpy: jasmine.Spy;
let store: MockStore<any>;

beforeEach(() => {
Expand All @@ -37,6 +38,9 @@ describe('MachinePageComponent', () => {
paramMap: {
get: paramMapSpy,
},
queryParamMap: {
get: queryParamMapSpy,
},
});

TestBed.configureTestingModule({
Expand Down Expand Up @@ -71,6 +75,12 @@ describe('MachinePageComponent', () => {
get: () => 1,
})
);
queryParamMapSpy.and.returnValue(
of({
get: () => 'overall',
})
);

// WHEN
fixture.detectChanges();

Expand All @@ -89,6 +99,11 @@ describe('MachinePageComponent', () => {
get: () => id,
})
);
queryParamMapSpy.and.returnValue(
of({
get: () => 'events',
})
);

spyOn(store, 'select').and.returnValue(machine$Mock);
spyOn<any>(machineSelectors, 'selectMachineById');
Expand All @@ -98,6 +113,7 @@ describe('MachinePageComponent', () => {

// THEN
expect(component.machine$).toEqual(machine$Mock);
expect(component.currentTabIndex).toEqual(1);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MachineColorStatusMap } from '@interfaces/machine-events-options';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
import { AppStore } from '@interfaces/app-store';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, RouterLink } from '@angular/router';
import { Machine } from '@models/machine';
import { selectMachineById } from '@stores/machines/machines.selectors';
import { Observable, Subscription } from 'rxjs';
Expand All @@ -16,6 +16,12 @@ import { NzTagModule } from 'ng-zorro-antd/tag';
import { NzListModule } from 'ng-zorro-antd/list';
import { MapComponent } from '@components/map/map.component';

const tabMap: { [key: string]: number } = {
overall: 0,
events: 1,
map: 2,
};

@Component({
standalone: true,
selector: 'app-machine-page',
Expand All @@ -31,9 +37,11 @@ import { MapComponent } from '@components/map/map.component';
NzTagModule,
NzListModule,
MapComponent,
RouterLink,
],
})
export class MachinePageComponent implements OnInit, OnDestroy {
currentTabIndex: number = 0;
machine$!: Observable<Machine | undefined>;

private subscriptions = new Subscription();
Expand All @@ -44,13 +52,19 @@ export class MachinePageComponent implements OnInit, OnDestroy {
) {}

ngOnInit(): void {
this.currentTabIndex = 0;
this.subscriptions.add(
this.activatedRoute.paramMap.subscribe((params) => {
this.machine$ = this.store.select(
selectMachineById(params.get('id') || '')
);
})
);
this.subscriptions.add(
this.activatedRoute.queryParamMap.subscribe((params) => {
this.currentTabIndex = tabMap[params.get('tab') || 'overall'];
})
);
}

ngOnDestroy(): void {
Expand Down

0 comments on commit 760f390

Please sign in to comment.