From 0c0512c2ca31a38d7685f1a517592a5b1d3c0cfa Mon Sep 17 00:00:00 2001 From: yuliia_karas Date: Wed, 27 Nov 2024 19:41:49 +0200 Subject: [PATCH 1/2] fix updating table --- .../ubs-admin-employee-table.component.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/app/ubs/ubs-admin/components/ubs-admin-employee/ubs-admin-employee-table/ubs-admin-employee-table.component.ts b/src/app/ubs/ubs-admin/components/ubs-admin-employee/ubs-admin-employee-table/ubs-admin-employee-table.component.ts index 519541ee1c..46d8f02742 100644 --- a/src/app/ubs/ubs-admin/components/ubs-admin-employee/ubs-admin-employee-table/ubs-admin-employee-table.component.ts +++ b/src/app/ubs/ubs-admin/components/ubs-admin-employee/ubs-admin-employee-table/ubs-admin-employee-table.component.ts @@ -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'; @@ -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', @@ -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 = new Subject(); isTooltipOpened: boolean; isStatusActive = EmployeeStatus.active; isStatusInactive = EmployeeStatus.inactive; @@ -74,9 +75,10 @@ export class UbsAdminEmployeeTableComponent implements OnInit { }; constructor( - private ubsAdminEmployeeService: UbsAdminEmployeeService, - private dialog: MatDialog, - private store: Store, + private readonly ubsAdminEmployeeService: UbsAdminEmployeeService, + private readonly dialog: MatDialog, + private readonly store: Store, + private readonly actions$: Actions, public fb: FormBuilder ) {} @@ -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 { @@ -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) { From 5911f9a86be2892cd5d5de07b4bb511a01262cea Mon Sep 17 00:00:00 2001 From: yuliia_karas Date: Mon, 16 Dec 2024 14:13:17 +0200 Subject: [PATCH 2/2] fix tests --- .../ubs-admin-employee-table.component.spec.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/ubs/ubs-admin/components/ubs-admin-employee/ubs-admin-employee-table/ubs-admin-employee-table.component.spec.ts b/src/app/ubs/ubs-admin/components/ubs-admin-employee/ubs-admin-employee-table/ubs-admin-employee-table.component.spec.ts index 9317dff8f4..16a8811ccd 100644 --- a/src/app/ubs/ubs-admin/components/ubs-admin-employee/ubs-admin-employee-table/ubs-admin-employee-table.component.spec.ts +++ b/src/app/ubs/ubs-admin/components/ubs-admin-employee/ubs-admin-employee-table/ubs-admin-employee-table.component.spec.ts @@ -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'; @@ -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; @@ -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();