Skip to content

Commit

Permalink
Merge pull request #3499 from ita-social-projects/bugfix/#7829-update…
Browse files Browse the repository at this point in the history
…-employee-table

[Bugfix] #7829 update employee table
  • Loading branch information
hnativlyubomyr authored Dec 23, 2024
2 parents 0ce968a + 5911f9a commit 99b9cf4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
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

0 comments on commit 99b9cf4

Please sign in to comment.