Skip to content

Commit

Permalink
AAE-27327 New process search API
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaRobert committed Nov 4, 2024
1 parent f07636e commit 7573740
Show file tree
Hide file tree
Showing 15 changed files with 1,541 additions and 801 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ when the process list is empty:
| stickyHeader | `boolean` | false | Toggles the sticky header mode. |
| suspendedFrom | `string` | "" | Filter the processes. Display only process with suspendedFrom equal to the supplied date. |
| suspendedTo | `string` | "" | Filter the processes. Display only process with suspendedTo equal to the supplied date. |
| names | `string[]` | [] | Filter the processes. Display only processes with names matching any of the supplied strings. This input will be used only if `PROCESS_SEARCH_API_METHOD_TOKEN` is provided with `POST` value. |
initiators | `string[]` | [] | Filter the processes. Display only processes started by any of the users whose usernames are present in the array. This input will be used only if `PROCESS_SEARCH_API_METHOD_TOKEN` is provided with `POST` value. |
| appVersions | `string[]` | [] | Filter the processes. Display only processes present in any of the specified app versions. This input will be used only if `PROCESS_SEARCH_API_METHOD_TOKEN` is provided with `POST` value. |
| statuses | `string[]` | [] | Filter the processes. Display only processes with provided statuses. This input will be used only if `PROCESS_SEARCH_API_METHOD_TOKEN` is provided with `POST` value. |

### Events

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { AppConfigService, TranslationService } from '@alfresco/adf-core';
import { FilterParamsModel } from '../../../task/task-filters/models/filter-cloud.model';
import { debounceTime, takeUntil, tap } from 'rxjs/operators';
import { ProcessListCloudService } from '../../../process/process-list/services/process-list-cloud.service';
import { PROCESS_SEARCH_API_METHOD_TOKEN } from '../../../services/cloud-token.service';
import { ProcessFilterCloudAdapter } from '../../process-list/models/process-cloud-query-request.model';

@Component({
selector: 'adf-cloud-process-filters',
Expand Down Expand Up @@ -77,6 +79,7 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges, OnDestro
private readonly translationService = inject(TranslationService);
private readonly appConfigService = inject(AppConfigService);
private readonly processListCloudService = inject(ProcessListCloudService);
private readonly searchMethod = inject<'GET' | 'POST'>(PROCESS_SEARCH_API_METHOD_TOKEN, { optional: true });

ngOnInit() {
this.enableNotifications = this.appConfigService.get('notifications', true);
Expand Down Expand Up @@ -272,8 +275,7 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges, OnDestro
* @param filter filter
*/
updateFilterCounter(filter: ProcessFilterCloudModel): void {
this.processListCloudService
.getProcessCounter(filter.appName, filter.status)
this.fetchProcessFilterCounter(filter)
.pipe(
tap((filterCounter) => {
this.checkIfFilterValuesHasBeenUpdated(filter.key, filterCounter);
Expand Down Expand Up @@ -312,4 +314,10 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges, OnDestro
this.updatedFiltersSet.delete(filterKey);
});
}

private fetchProcessFilterCounter(filter: ProcessFilterCloudModel): Observable<number> {
return this.searchMethod === 'POST'
? this.processListCloudService.getProcessListCounter(new ProcessFilterCloudAdapter(filter))
: this.processListCloudService.getProcessCounter(filter.appName, filter.status)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,23 @@ export const fakeProcessCloudFilters = [

export const mockProcessFilters: any[] = [
{
appName: 'mock-app-name',
name: 'FakeAllProcesses',
key: 'FakeAllProcesses',
icon: 'adjust',
id: '10',
status: ''
},
{
appName: 'mock-app-name',
name: 'FakeRunningProcesses',
key: 'FakeRunningProcesses',
icon: 'inbox',
id: '11',
status: 'RUNNING'
},
{
appName: 'mock-app-name',
name: 'FakeCompletedProcesses',
key: 'completed-processes',
icon: 'done',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export class ProcessFilterCloudModel {
completedDate: Date;
environmentId?: string;

processDefinitionNames: string[] | null;
initiators: string[] | null;
appVersions: string[] | null;
statuses: string[] | null;

private dateRangeFilterService = new DateRangeFilterService();
private _completedFrom: string;
private _completedTo: string;
Expand Down Expand Up @@ -94,6 +99,11 @@ export class ProcessFilterCloudModel {
this.completedDate = obj.completedDate || null;
this._suspendedFrom = obj._suspendedFrom || null;
this._suspendedTo = obj._suspendedTo || null;

this.processDefinitionNames = obj.processDefinitionNames || null;
this.initiators = obj.initiators || null;
this.appVersions = obj.appVersions || null;
this.statuses = obj.statuses || null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,19 @@ describe('ProcessFilterCloudService', () => {
expect(res[0].id).toBe('1');
expect(res[0].name).toBe('MOCK_PROCESS_NAME_1');
expect(res[0].status).toBe('MOCK_ALL');
expect(res[0].statuses).toContain('MOCK_ALL');

expect(res[1].appName).toBe('mock-appName');
expect(res[1].id).toBe('2');
expect(res[1].name).toBe('MOCK_PROCESS_NAME_2');
expect(res[1].status).toBe('MOCK-RUNNING');
expect(res[1].statuses).toContain('MOCK-RUNNING');

expect(res[2].appName).toBe('mock-appName');
expect(res[2].id).toBe('3');
expect(res[2].name).toBe('MOCK_PROCESS_NAME_3');
expect(res[2].status).toBe('MOCK-COMPLETED');
expect(res[2].statuses).toContain('MOCK-COMPLETED');

expect(createPreferenceSpy).toHaveBeenCalled();
done();
Expand All @@ -112,16 +115,19 @@ describe('ProcessFilterCloudService', () => {
expect(res[0].id).toBe('1');
expect(res[0].name).toBe('MOCK_PROCESS_NAME_1');
expect(res[0].status).toBe('MOCK_ALL');
expect(res[0].statuses).toContain('MOCK_ALL');

expect(res[1].appName).toBe('mock-appName');
expect(res[1].id).toBe('2');
expect(res[1].name).toBe('MOCK_PROCESS_NAME_2');
expect(res[1].status).toBe('MOCK-RUNNING');
expect(res[1].statuses).toContain('MOCK-RUNNING');

expect(res[2].appName).toBe('mock-appName');
expect(res[2].id).toBe('3');
expect(res[2].name).toBe('MOCK_PROCESS_NAME_3');
expect(res[2].status).toBe('MOCK-COMPLETED');
expect(res[2].statuses).toContain('MOCK-COMPLETED');

expect(getPreferencesSpy).toHaveBeenCalled();
done();
Expand All @@ -140,16 +146,19 @@ describe('ProcessFilterCloudService', () => {
expect(res[0].id).toBe('1');
expect(res[0].name).toBe('MOCK_PROCESS_NAME_1');
expect(res[0].status).toBe('MOCK_ALL');
expect(res[0].statuses).toContain('MOCK_ALL');

expect(res[1].appName).toBe('mock-appName');
expect(res[1].id).toBe('2');
expect(res[1].name).toBe('MOCK_PROCESS_NAME_2');
expect(res[1].status).toBe('MOCK-RUNNING');
expect(res[1].statuses).toContain('MOCK-RUNNING');

expect(res[2].appName).toBe('mock-appName');
expect(res[2].id).toBe('3');
expect(res[2].name).toBe('MOCK_PROCESS_NAME_3');
expect(res[2].status).toBe('MOCK-COMPLETED');
expect(res[2].statuses).toContain('MOCK-COMPLETED');

expect(getPreferencesSpy).toHaveBeenCalled();
expect(createPreferenceSpy).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export class ProcessFilterCloudService {
} else {
return of(this.findFiltersByKeyInPreferences(preferences, key));
}
})
}),
switchMap((filters) => this.handleCreateFilterBackwardsCompatibility(appName, key, filters))
)
.subscribe((filters) => {
this.addFiltersToStream(filters);
Expand Down Expand Up @@ -414,4 +415,39 @@ export class ProcessFilterCloudService {
refreshFilter(filterKey: string): void {
this.filterKeyToBeRefreshedSource.next(filterKey);
}

/**
* This method is run after retrieving the filter array from preferences.
* It handles the backwards compatibility with the new API by looking for the new properties and their counterparts in each passed filter.
* If the new property is not found, it is created and assigned the value constructed from the old property.
* The filters are then updated in the preferences and returned.
* Old properties are left untouched for purposes like feature toggling.
*
* @param appName Name of the target app.
* @param key Key of the process filters.
* @param filters Array of process filters to be checked for backward compatibility.
* @returns Observable of process filters with updated properties.
*/
private handleCreateFilterBackwardsCompatibility(
appName: string,
key: string,
filters: ProcessFilterCloudModel[]
): Observable<ProcessFilterCloudModel[]> {
filters.forEach((filter) => {
if (filter.processDefinitionName && !filter.processDefinitionNames) {
filter.processDefinitionNames = [filter.processDefinitionName];
}
if (filter.initiator && !filter.initiators) {
filter.initiators = [filter.initiator];
}
if (filter.appVersion && !filter.appVersions) {
filter.appVersions = [filter.appVersion.toString()];
}
if (filter.status && !filter.statuses) {
filter.statuses = [filter.status];
}
});

return this.updateProcessFilters(appName, key, filters);
}
}
Loading

0 comments on commit 7573740

Please sign in to comment.