mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
AAE-26155 Added feature for refreshing filter (#10266)
* [AAE-26155] added feature for refreshing filter * [AAE-26155] updated input property description * [AAE-26155] updated services to allow refreshing filters
This commit is contained in:
parent
d5a530ba23
commit
1d21c3ef80
@ -33,7 +33,8 @@ import { MatListModule } from '@angular/material/list';
|
||||
|
||||
const ProcessFilterCloudServiceMock = {
|
||||
getProcessFilters: () => of(mockProcessFilters),
|
||||
getProcessNotificationSubscription: () => of([])
|
||||
getProcessNotificationSubscription: () => of([]),
|
||||
filterKeyToBeRefreshed$: of(mockProcessFilters[0].key)
|
||||
};
|
||||
|
||||
describe('ProcessFiltersCloudComponent', () => {
|
||||
@ -295,6 +296,17 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
expect(component.getCurrentFilter()).toBe(filter);
|
||||
});
|
||||
|
||||
it('should remove key from set of updated filters when received refreshed filter key', async () => {
|
||||
const filterKeyTest = 'filter-key-test';
|
||||
component.updatedFiltersSet.add(filterKeyTest);
|
||||
|
||||
expect(component.updatedFiltersSet.size).toBe(1);
|
||||
processFilterService.filterKeyToBeRefreshed$ = of(filterKeyTest);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.updatedFiltersSet.size).toBe(0);
|
||||
});
|
||||
|
||||
describe('Highlight Selected Filter', () => {
|
||||
const allProcessesFilterKey = mockProcessFilters[0].key;
|
||||
const runningProcessesFilterKey = mockProcessFilters[1].key;
|
||||
|
@ -84,6 +84,7 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges, OnDestro
|
||||
this.getFilters(this.appName);
|
||||
}
|
||||
this.initProcessNotification();
|
||||
this.getFilterKeysAfterExternalRefreshing();
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
@ -250,9 +251,7 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges, OnDestro
|
||||
|
||||
updateFilterCounters(): void {
|
||||
this.filters.forEach((filter: ProcessFilterCloudModel) => {
|
||||
if (filter?.status) {
|
||||
this.updateFilterCounter(filter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -279,4 +278,14 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges, OnDestro
|
||||
isFilterUpdated(filterName: string): boolean {
|
||||
return this.updatedFiltersSet.has(filterName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filer key when filter was refreshed by external action
|
||||
*
|
||||
*/
|
||||
getFilterKeysAfterExternalRefreshing(): void {
|
||||
this.processFilterCloudService.filterKeyToBeRefreshed$.pipe(takeUntil(this.onDestroy$)).subscribe((filterKey: string) => {
|
||||
this.updatedFiltersSet.delete(filterKey);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable, of, BehaviorSubject } from 'rxjs';
|
||||
import { Observable, of, BehaviorSubject, Subject } from 'rxjs';
|
||||
import { ProcessFilterCloudModel } from '../models/process-filter-cloud.model';
|
||||
import { switchMap, map } from 'rxjs/operators';
|
||||
import { PROCESS_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service';
|
||||
@ -47,6 +47,8 @@ const PROCESS_EVENT_SUBSCRIPTION_QUERY = `
|
||||
export class ProcessFilterCloudService {
|
||||
private filtersSubject: BehaviorSubject<ProcessFilterCloudModel[]>;
|
||||
filters$: Observable<ProcessFilterCloudModel[]>;
|
||||
private filterKeyToBeRefreshedSource = new Subject<string>();
|
||||
filterKeyToBeRefreshed$: Observable<string> = this.filterKeyToBeRefreshedSource.asObservable();
|
||||
|
||||
private readonly preferenceService = inject<PreferenceCloudServiceInterface>(PROCESS_FILTERS_SERVICE_TOKEN);
|
||||
private readonly identityUserService = inject(IdentityUserService);
|
||||
@ -403,4 +405,13 @@ export class ProcessFilterCloudService {
|
||||
.makeGQLQuery(appName, PROCESS_EVENT_SUBSCRIPTION_QUERY)
|
||||
.pipe(map((events: any) => events?.data?.engineEvents));
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh filter key
|
||||
*
|
||||
* @param filterKey Key of the filter
|
||||
*/
|
||||
refreshFilter(filterKey: string): void {
|
||||
this.filterKeyToBeRefreshedSource.next(filterKey);
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ export abstract class BaseTaskFiltersCloudComponent implements OnDestroy {
|
||||
error: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
counters$: { [key: string]: Observable<number> } = {};
|
||||
updatedCounters: string[] = [];
|
||||
updatedCountersSet = new Set<string>();
|
||||
|
||||
protected onDestroy$ = new Subject<boolean>();
|
||||
|
||||
@ -56,19 +56,14 @@ export abstract class BaseTaskFiltersCloudComponent implements OnDestroy {
|
||||
}
|
||||
|
||||
wasFilterUpdated(filterKey: string): boolean {
|
||||
return this.updatedCounters.includes(filterKey);
|
||||
return this.updatedCountersSet.has(filterKey);
|
||||
}
|
||||
|
||||
addToUpdatedCounters(filterKey: string) {
|
||||
if (!this.updatedCounters.includes(filterKey)) {
|
||||
this.updatedCounters.push(filterKey);
|
||||
}
|
||||
this.updatedCountersSet.add(filterKey);
|
||||
}
|
||||
|
||||
resetFilterCounter(filterKey: string) {
|
||||
const filterIndex = this.updatedCounters.indexOf(filterKey);
|
||||
if (filterIndex > -1) {
|
||||
this.updatedCounters.splice(filterIndex, 1);
|
||||
}
|
||||
this.updatedCountersSet.delete(filterKey);
|
||||
}
|
||||
}
|
||||
|
@ -15,18 +15,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AppConfigService } from '@alfresco/adf-core';
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
|
||||
import { AppConfigService } from '@alfresco/adf-core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { first, of, throwError } from 'rxjs';
|
||||
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service';
|
||||
import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service';
|
||||
import { TaskFilterCloudService } from '../services/task-filter-cloud.service';
|
||||
import { TaskFiltersCloudComponent } from './task-filters-cloud.component';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
|
||||
import { defaultTaskFiltersMock, fakeGlobalFilter, taskNotifications } from '../mock/task-filters-cloud.mock';
|
||||
import { TaskFilterCloudService } from '../services/task-filter-cloud.service';
|
||||
import { TaskFiltersCloudModule } from '../task-filters-cloud.module';
|
||||
import { fakeGlobalFilter, defaultTaskFiltersMock, taskNotifications } from '../mock/task-filters-cloud.mock';
|
||||
import { TaskFiltersCloudComponent } from './task-filters-cloud.component';
|
||||
|
||||
describe('TaskFiltersCloudComponent', () => {
|
||||
let taskFilterService: TaskFilterCloudService;
|
||||
@ -386,6 +386,42 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should remove key from set of updated filters when received refreshed filter key', async () => {
|
||||
const filterKeyTest = 'filter-key-test';
|
||||
component.updatedCountersSet.add(filterKeyTest);
|
||||
|
||||
expect(component.updatedCountersSet.size).toBe(1);
|
||||
|
||||
taskFilterService.filterKeyToBeRefreshed$ = of(filterKeyTest);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.updatedCountersSet.size).toBe(0);
|
||||
});
|
||||
|
||||
it('should remove key from set of updated filters when clicked on filter', async () => {
|
||||
const filter = defaultTaskFiltersMock[1];
|
||||
component.updatedCountersSet.add(filter.key);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.updatedCountersSet.size).toBe(1);
|
||||
|
||||
component.onFilterClick(filter);
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.updatedCountersSet.size).toBe(0);
|
||||
});
|
||||
|
||||
it('should add key to set of updated filters when value has changed', () => {
|
||||
component.updatedCountersSet = new Set();
|
||||
const fakeFilterKey = 'testKey';
|
||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 20);
|
||||
|
||||
expect(component.updatedCountersSet.size).toBe(1);
|
||||
expect(component.updatedCountersSet.has(fakeFilterKey)).toBe(true);
|
||||
});
|
||||
|
||||
describe('Highlight Selected Filter', () => {
|
||||
const assignedTasksFilterKey = defaultTaskFiltersMock[1].key;
|
||||
const queuedTasksFilterKey = defaultTaskFiltersMock[0].key;
|
||||
|
@ -62,6 +62,7 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
|
||||
this.enableNotifications = this.appConfigService.get('notifications', true);
|
||||
this.getFilters(this.appName);
|
||||
this.initFilterCounterNotifications();
|
||||
this.getFilterKeysAfterExternalRefreshing();
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
@ -182,6 +183,7 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
|
||||
this.selectFilter(filter);
|
||||
this.updateFilterCounter(this.currentFilter);
|
||||
this.filterClicked.emit(this.currentFilter);
|
||||
this.updatedCountersSet.delete(filter.key);
|
||||
} else {
|
||||
this.currentFilter = undefined;
|
||||
}
|
||||
@ -221,6 +223,17 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
|
||||
if (this.currentFiltersValues[filterKey] !== filterValue) {
|
||||
this.currentFiltersValues[filterKey] = filterValue;
|
||||
this.updatedFilter.emit(filterKey);
|
||||
this.updatedCountersSet.add(filterKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filer key when filter was refreshed by external action
|
||||
*
|
||||
*/
|
||||
getFilterKeysAfterExternalRefreshing(): void {
|
||||
this.taskFilterCloudService.filterKeyToBeRefreshed$.pipe(takeUntil(this.onDestroy$)).subscribe((filterKey: string) => {
|
||||
this.updatedCountersSet.delete(filterKey);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Injectable, Inject } from '@angular/core';
|
||||
import { Observable, of, BehaviorSubject, throwError } from 'rxjs';
|
||||
import { Observable, of, BehaviorSubject, throwError, Subject } from 'rxjs';
|
||||
import { TaskFilterCloudModel } from '../models/filter-cloud.model';
|
||||
import { switchMap, map } from 'rxjs/operators';
|
||||
import { BaseCloudService } from '../../../services/base-cloud.service';
|
||||
@ -50,6 +50,8 @@ const TASK_EVENT_SUBSCRIPTION_QUERY = `
|
||||
export class TaskFilterCloudService extends BaseCloudService {
|
||||
private filtersSubject = new BehaviorSubject<TaskFilterCloudModel[]>([]);
|
||||
filters$ = this.filtersSubject.asObservable();
|
||||
private filterKeyToBeRefreshedSource = new Subject<string>();
|
||||
filterKeyToBeRefreshed$ = this.filterKeyToBeRefreshedSource.asObservable();
|
||||
|
||||
constructor(
|
||||
private identityUserService: IdentityUserService,
|
||||
@ -368,4 +370,13 @@ export class TaskFilterCloudService extends BaseCloudService {
|
||||
.makeGQLQuery(appName, TASK_EVENT_SUBSCRIPTION_QUERY)
|
||||
.pipe(map((events: any) => events.data.engineEvents));
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh filter key
|
||||
*
|
||||
* @param filterKey Key of the filter
|
||||
*/
|
||||
refreshFilter(filterKey: string): void {
|
||||
this.filterKeyToBeRefreshedSource.next(filterKey);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user