Skip to content

Commit

Permalink
AAE-28286 Show process variables columns in datatable fix (#10383)
Browse files Browse the repository at this point in the history
* AAE-28286 Show process variables columns in datatable fix

* fix lint
  • Loading branch information
BSekula authored Nov 12, 2024
1 parent 278a5ee commit 3111008
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 62 deletions.
7 changes: 4 additions & 3 deletions lib/core/src/lib/datatable/data/data-table.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { ContentChild, Input, Directive } from '@angular/core';
import { ReplaySubject } from 'rxjs';
import { BehaviorSubject } from 'rxjs';
import { AppConfigService } from '../../app-config/app-config.service';
import { DataColumnListComponent } from '../data-column/data-column-list.component';
import { DataColumn } from './data-column.model';
Expand All @@ -42,18 +42,19 @@ export abstract class DataTableSchema<T = unknown> {

private layoutPresets = {};

private columnsSchemaSubject$ = new ReplaySubject<boolean>();
protected columnsSchemaSubject$ = new BehaviorSubject<boolean>(false);
isColumnSchemaCreated$ = this.columnsSchemaSubject$.asObservable();

constructor(private appConfigService: AppConfigService, protected presetKey: string, protected presetsModel: any) {}

public createDatatableSchema(): void {
this.loadLayoutPresets();

if (!this.columns || this.columns.length === 0) {
this.createColumns();
this.columnsSchemaSubject$.next(true);
} else {
this.columnsSchemaSubject$.next(false);
this.columnsSchemaSubject$.next(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ describe('ProcessListCloudComponent', () => {
done();
});
component.appName = appName.currentValue;
component.ngAfterContentInit();
component.ngOnChanges({ appName });
fixture.detectChanges();
});
Expand Down Expand Up @@ -480,7 +479,6 @@ describe('ProcessListCloudComponent', () => {
done();
});
component.appName = appName.currentValue;
component.ngAfterContentInit();
component.ngOnChanges({ appName });
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
DataColumn
} from '@alfresco/adf-core';
import { ProcessListCloudService } from '../services/process-list-cloud.service';
import { BehaviorSubject, Subject } from 'rxjs';
import { BehaviorSubject, combineLatest, Subject } from 'rxjs';
import { processCloudPresetsDefaultModel } from '../models/process-cloud-preset.model';
import { ProcessListRequestModel, ProcessQueryCloudRequestModel } from '../models/process-cloud-query-request.model';
import { ProcessListCloudSortingModel } from '../models/process-list-sorting.model';
Expand All @@ -66,11 +66,9 @@ const PRESET_KEY = 'adf-cloud-process-list.presets';
styleUrls: ['./process-list-cloud.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class ProcessListCloudComponent
extends DataTableSchema<ProcessListDataColumnCustomData>
implements OnChanges, AfterContentInit, PaginatedComponent, OnDestroy {
@ViewChild(DataTableComponent)
dataTable: DataTableComponent;
export class ProcessListCloudComponent extends DataTableSchema<ProcessListDataColumnCustomData> implements OnChanges, AfterContentInit, PaginatedComponent, OnDestroy {

@ViewChild(DataTableComponent) dataTable: DataTableComponent;

@ContentChild(CustomEmptyContentTemplateDirective)
emptyCustomContent: CustomEmptyContentTemplateDirective;
Expand Down Expand Up @@ -274,6 +272,8 @@ implements OnChanges, AfterContentInit, PaginatedComponent, OnDestroy {

private defaultSorting = { key: 'startDate', direction: 'desc' };

private fetchProcessesTrigger$ = new Subject<void>();

constructor(
@Inject(PROCESS_SEARCH_API_METHOD_TOKEN) @Optional() private searchMethod: 'GET' | 'POST',
private processListCloudService: ProcessListCloudService,
Expand All @@ -292,6 +292,44 @@ implements OnChanges, AfterContentInit, PaginatedComponent, OnDestroy {
skipCount: 0,
totalItems: 0
});

this.isLoading = true;

combineLatest([
this.isColumnSchemaCreated$,
this.fetchProcessesTrigger$
]).pipe(
filter(([isColumnSchemaCreated]) => {
return isColumnSchemaCreated;
}),
switchMap(() => {
console.count('load');
if (this.searchMethod === 'POST') {
const requestNode = this.createProcessListRequestNode();
this.processListRequestNode = requestNode;
return this.processListCloudService.fetchProcessList(requestNode).pipe(take(1));
} else {
const requestNode = this.createRequestNode();
this.requestNode = requestNode;
return this.processListCloudService.getProcessByRequest(requestNode).pipe(take(1));
}
}),
takeUntil(this.onDestroy$)
).subscribe({
next: (processes) => {
this.rows = this.variableMapperService.mapVariablesByColumnTitle(processes.list.entries, this.columns);

this.dataAdapter = new ProcessListDatatableAdapter(this.rows, this.columns);

this.success.emit(processes);
this.isLoading = false;
this.pagination.next(processes.list.pagination);
},
error: (error) => {
this.error.emit(error);
this.isLoading = false;
}
});
}

ngAfterContentInit() {
Expand Down Expand Up @@ -340,6 +378,7 @@ implements OnChanges, AfterContentInit, PaginatedComponent, OnDestroy {
if (this.isPropertyChanged(changes, 'sorting')) {
this.formatSorting(changes['sorting'].currentValue);
}

if (this.isAnyPropertyChanged(changes)) {
this.reload();
}
Expand All @@ -351,48 +390,12 @@ implements OnChanges, AfterContentInit, PaginatedComponent, OnDestroy {

reload() {
if (this.appName || this.appName === '') {
this.load();
this.fetchProcessesTrigger$.next();
} else {
this.rows = [];
}
}

private load() {
this.isLoading = true;

this.isColumnSchemaCreated$
.pipe(
filter((isColumnSchemaCreated) => !!isColumnSchemaCreated),
take(1),
switchMap(() => {
if (this.searchMethod === 'POST') {
const requestNode = this.createProcessListRequestNode();
this.processListRequestNode = requestNode;
return this.processListCloudService.fetchProcessList(requestNode).pipe(take(1));
} else {
const requestNode = this.createRequestNode();
this.requestNode = requestNode;
return this.processListCloudService.getProcessByRequest(requestNode).pipe(take(1));
}
}),
takeUntil(this.onDestroy$)
)
.subscribe({
next: (processes) => {
this.rows = this.variableMapperService.mapVariablesByColumnTitle(processes.list.entries, this.columns);

this.dataAdapter = new ProcessListDatatableAdapter(this.rows, this.columns);

this.success.emit(processes);
this.isLoading = false;
this.pagination.next(processes.list.pagination);
},
error: (error) => {
this.error.emit(error);
this.isLoading = false;
}
});
}

private isAnyPropertyChanged(changes: SimpleChanges): boolean {
for (const property in changes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ describe('TaskListCloudComponent', () => {
spyOn(taskListCloudService, 'getTaskByRequest').and.returnValue(of(fakeGlobalTasks));
const appName = new SimpleChange(null, 'FAKE-APP-NAME', true);

fixture.detectChanges();
component.ngOnChanges({ appName });
fixture.detectChanges();

Expand Down Expand Up @@ -214,7 +213,6 @@ describe('TaskListCloudComponent', () => {
});

component.reload();
fixture.detectChanges();
});

it('should call endpoint when a column visibility gets changed', () => {
Expand Down Expand Up @@ -244,16 +242,19 @@ describe('TaskListCloudComponent', () => {
component.status = 'mock-status';
component.lastModifiedFrom = 'mock-lastmodified-date';
component.owner = 'mock-owner-name';

const priorityChange = new SimpleChange(undefined, 1, true);
const statusChange = new SimpleChange(undefined, 'mock-status', true);
const lastModifiedFromChange = new SimpleChange(undefined, 'mock-lastmodified-date', true);
const ownerChange = new SimpleChange(undefined, 'mock-owner-name', true);

component.ngOnChanges({
priority: priorityChange,
status: statusChange,
lastModifiedFrom: lastModifiedFromChange,
owner: ownerChange
});

fixture.detectChanges();
expect(component.isListEmpty()).toBeFalsy();
expect(getTaskByRequestSpy).toHaveBeenCalled();
Expand Down Expand Up @@ -357,7 +358,6 @@ describe('TaskListCloudComponent', () => {
});

component.reload();
fixture.detectChanges();
});

it('should call endpoint when a column visibility gets changed', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent<ProcessLi
map(([isLoadingPreferences, isReloading]) => isLoadingPreferences || isReloading)
);

private fetchProcessesTrigger$ = new Subject<void>();

constructor(
@Inject(TASK_SEARCH_API_METHOD_TOKEN) @Optional() private searchMethod: 'GET' | 'POST',
@Inject(TASK_LIST_CLOUD_TOKEN) public taskListCloudService: TaskListCloudServiceInterface,
Expand All @@ -207,20 +209,10 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent<ProcessLi
private viewModelCreator: VariableMapperService
) {
super(appConfigService, taskCloudService, userPreferences, PRESET_KEY, cloudPreferenceService);
}

ngOnDestroy() {
this.onDestroyTaskList$.next(true);
this.onDestroyTaskList$.complete();
}

reload() {
this.isReloadingSubject$.next(true);

this.isColumnSchemaCreated$
combineLatest([this.isColumnSchemaCreated$, this.fetchProcessesTrigger$])
.pipe(
filter((isColumnSchemaCreated) => !!isColumnSchemaCreated),
take(1),
switchMap(() => {
if (this.searchMethod === 'POST') {
const requestNode = this.createTaskListRequestNode();
Expand Down Expand Up @@ -255,6 +247,16 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent<ProcessLi
});
}

ngOnDestroy() {
this.onDestroyTaskList$.next(true);
this.onDestroyTaskList$.complete();
}

reload() {
this.isReloadingSubject$.next(true);
this.fetchProcessesTrigger$.next();
}

private createTaskListRequestNode(): TaskListRequestModel {
const requestNode: TaskListRequestModel = {
appName: this.appName,
Expand Down

0 comments on commit 3111008

Please sign in to comment.