Skip to content
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

[Bugfix] #7829 update employee table #3499

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -4,7 +4,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { BehaviorSubject, of, Subject } from 'rxjs';
import { ReactiveFormsModule } from '@angular/forms';
import { MatDialog, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { Store } from '@ngrx/store';
import { ScannedActionsSubject, Store } from '@ngrx/store';
import { MatTableModule } from '@angular/material/table';
import { TranslateModule } from '@ngx-translate/core';
import { InfiniteScrollModule } from 'ngx-infinite-scroll';
Expand All @@ -15,6 +15,7 @@ import { LanguageService } from 'src/app/main/i18n/language.service';
import { UbsAdminEmployeeTableComponent } from './ubs-admin-employee-table.component';
import { UbsAdminEmployeeEditFormComponent } from '../ubs-admin-employee-edit-form/ubs-admin-employee-edit-form.component';
import { DialogPopUpComponent } from 'src/app/shared/dialog-pop-up/dialog-pop-up.component';
import { Actions } from '@ngrx/effects';

describe('UbsAdminEmployeeTableComponent', () => {
let component: UbsAdminEmployeeTableComponent;
Expand Down Expand Up @@ -158,7 +159,9 @@ describe('UbsAdminEmployeeTableComponent', () => {
{ provide: MatDialog, useValue: matDialogMock },
{ provide: Store, useValue: storeMock },
{ provide: UbsAdminEmployeeService, useValue: ubsAdminEmployeeServiceMock },
{ provide: LanguageService, useValue: languageServiceMock }
{ provide: LanguageService, useValue: languageServiceMock },
{ provide: Actions, useValue: of() },
{ provide: ScannedActionsSubject, useValue: of() }
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { Store } from '@ngrx/store';
import { BehaviorSubject } from 'rxjs';
import { debounceTime, distinctUntilChanged, take } from 'rxjs/operators';
import { BehaviorSubject, Subject } from 'rxjs';
import { debounceTime, distinctUntilChanged, take, takeUntil } from 'rxjs/operators';

import { ActivateEmployee, DeleteEmployee, GetEmployees } from 'src/app/store/actions/employee.actions';
import { ActivateEmployee, DeleteEmployee, GetEmployees, AddEmployeeSuccess } from 'src/app/store/actions/employee.actions';
import { modifiedEmployee } from 'src/app/store/selectors/employee';
import { IAppState } from 'src/app/store/state/app.state';
import { Employees, Page } from 'src/app/ubs/ubs-admin/models/ubs-admin.interface';
Expand All @@ -15,6 +15,7 @@ import { FilterData } from 'src/app/ubs/ubs-admin/models/tariffs.interface';
import { UbsAdminEmployeeEditFormComponent } from '../ubs-admin-employee-edit-form/ubs-admin-employee-edit-form.component';
import { UbsAdminEmployeePermissionsFormComponent } from '../ubs-admin-employee-permissions-form/ubs-admin-employee-permissions-form.component';
import { EmployeeStatus, PopUpsStyles } from './employee-models.enum';
import { Actions, ofType } from '@ngrx/effects';

@Component({
selector: 'app-ubs-admin-employee-table',
Expand All @@ -35,12 +36,12 @@ export class UbsAdminEmployeeTableComponent implements OnInit {
totalPagesForTable: number;
tableData: Page[];
employees: Page[];
filteredTableData: Page[] = [];
firstPageLoad = true;
reset = true;
filterDatas: FilterData = { positions: [], regions: [], locations: [], couriers: [], employeeStatus: 'ACTIVE' };
employees$ = this.store.select((state: IAppState): Employees => state.employees.employees);
employeesData$ = this.store.select(modifiedEmployee);
private readonly destroy$: Subject<void> = new Subject();
isTooltipOpened: boolean;
isStatusActive = EmployeeStatus.active;
isStatusInactive = EmployeeStatus.inactive;
Expand Down Expand Up @@ -74,9 +75,10 @@ export class UbsAdminEmployeeTableComponent implements OnInit {
};

constructor(
private ubsAdminEmployeeService: UbsAdminEmployeeService,
private dialog: MatDialog,
private store: Store<IAppState>,
private readonly ubsAdminEmployeeService: UbsAdminEmployeeService,
private readonly dialog: MatDialog,
private readonly store: Store<IAppState>,
private readonly actions$: Actions,
public fb: FormBuilder
) {}

Expand All @@ -86,6 +88,8 @@ export class UbsAdminEmployeeTableComponent implements OnInit {
this.initSearch();
});
this.initSearch();

this.actions$.pipe(ofType(AddEmployeeSuccess), takeUntil(this.destroy$)).subscribe(() => this.updateTable());
}

initSearch(): void {
Expand All @@ -102,7 +106,7 @@ export class UbsAdminEmployeeTableComponent implements OnInit {
this.isLoading = true;
this.getEmployeesPages();

this.employees$.subscribe((item: Employees) => {
this.employees$.pipe(takeUntil(this.destroy$)).subscribe((item: Employees) => {
if (item) {
this.totalPagesForTable = item[`totalPages`];
if (this.firstPageLoad) {
Expand Down
Loading