Skip to content

Commit ec0ac73

Browse files
committed
[CST-6494] Update filter values when a workflow action is dispatched
1 parent 213f454 commit ec0ac73

27 files changed

Lines changed: 344 additions & 113 deletions

src/app/core/shared/search/search-filter.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
1+
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable } from 'rxjs';
22
import { distinctUntilChanged, map } from 'rxjs/operators';
33
import { Injectable, InjectionToken } from '@angular/core';
44
import {
@@ -26,6 +26,7 @@ const filterStateSelector = (state: SearchFiltersState) => state.searchFilter;
2626

2727
export const FILTER_CONFIG: InjectionToken<SearchFilterConfig> = new InjectionToken<SearchFilterConfig>('filterConfig');
2828
export const IN_PLACE_SEARCH: InjectionToken<boolean> = new InjectionToken<boolean>('inPlaceSearch');
29+
export const REFRESH_FILTER: InjectionToken<BehaviorSubject<any>> = new InjectionToken<boolean>('refreshFilters');
2930

3031
/**
3132
* Service that performs all actions that have to do with search filters and facets

src/app/core/shared/search/search.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,11 @@ export class SearchService implements OnDestroy {
408408
* @param {number} valuePage The page number of the filter values
409409
* @param {SearchOptions} searchOptions The search configuration for the current search
410410
* @param {string} filterQuery The optional query used to filter out filter values
411+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
412+
* no valid cached version. Defaults to true
411413
* @returns {Observable<RemoteData<PaginatedList<FacetValue>>>} Emits the given page of facet values
412414
*/
413-
getFacetValuesFor(filterConfig: SearchFilterConfig, valuePage: number, searchOptions?: SearchOptions, filterQuery?: string): Observable<RemoteData<FacetValues>> {
415+
getFacetValuesFor(filterConfig: SearchFilterConfig, valuePage: number, searchOptions?: SearchOptions, filterQuery?: string, useCachedVersionIfAvailable = true): Observable<RemoteData<FacetValues>> {
414416
let href;
415417
const args: string[] = [`page=${valuePage - 1}`, `size=${filterConfig.pageSize}`];
416418
if (hasValue(filterQuery)) {
@@ -428,7 +430,7 @@ export class SearchService implements OnDestroy {
428430
return FacetValueResponseParsingService;
429431
}
430432
});
431-
this.requestService.send(request, true);
433+
this.requestService.send(request, useCachedVersionIfAvailable);
432434

433435
return this.rdb.buildFromHref(href);
434436
}

src/app/shared/object-collection/object-collection.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
[importConfig]="importConfig"
2121
[customData]="customData"
2222
(importObject)="importObject.emit($event)"
23-
(contentChange)="contentChange.emit()"
23+
(contentChange)="contentChange.emit($event)"
2424
(customEvent)="customEvent.emit($event)"
2525
(prev)="goPrev()"
2626
(next)="goNext()"
@@ -51,6 +51,7 @@
5151
[context]="context"
5252
[hidePaginationDetail]="hidePaginationDetail"
5353
[showPaginator]="showPaginator"
54+
(contentChange)="contentChange.emit($event)"
5455
*ngIf="(currentMode$ | async) === viewModeEnum.DetailedListElement">
5556
</ds-object-detail>
5657

src/app/shared/object-collection/object-collection.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export class ObjectCollectionComponent implements OnInit {
5050
@Input() hideGear = false;
5151
@Input() selectable = false;
5252
@Input() selectionConfig: {repeatable: boolean, listId: string};
53+
54+
/**
55+
* Emit custom event for listable object custom actions.
56+
*/
57+
@Output() customEvent = new EventEmitter<any>();
5358
@Output() deselectObject: EventEmitter<ListableObject> = new EventEmitter<ListableObject>();
5459
@Output() selectObject: EventEmitter<ListableObject> = new EventEmitter<ListableObject>();
5560

@@ -132,11 +137,6 @@ export class ObjectCollectionComponent implements OnInit {
132137
*/
133138
@Output() sortFieldChange: EventEmitter<string> = new EventEmitter<string>();
134139

135-
/**
136-
* Emit custom event for listable object custom actions.
137-
*/
138-
@Output() customEvent = new EventEmitter<any>();
139-
140140
/**
141141
* If showPaginator is set to true, emit when the previous button is clicked
142142
*/

src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { ListableObject } from '../listable-object.model';
55
import { GenericConstructor } from '../../../../core/shared/generic-constructor';
66
import { Context } from '../../../../core/shared/context.model';
77
import { ViewMode } from '../../../../core/shared/view-mode.model';
8-
import { ItemListElementComponent } from '../../../object-list/item-list-element/item-types/item/item-list-element.component';
8+
import {
9+
ItemListElementComponent
10+
} from '../../../object-list/item-list-element/item-types/item/item-list-element.component';
911
import { ListableObjectDirective } from './listable-object.directive';
1012
import { TranslateModule } from '@ngx-translate/core';
1113
import { By } from '@angular/platform-browser';
@@ -146,7 +148,7 @@ describe('ListableObjectComponentLoaderComponent', () => {
146148
expect((comp as any).instantiateComponent).not.toHaveBeenCalled();
147149

148150
(listableComponent as any).reloadedObject.emit(reloadedObject);
149-
tick();
151+
tick(200);
150152

151153
expect((comp as any).instantiateComponent).toHaveBeenCalledWith(reloadedObject);
152154
}));
@@ -155,7 +157,7 @@ describe('ListableObjectComponentLoaderComponent', () => {
155157
expect((comp as any).contentChange.emit).not.toHaveBeenCalled();
156158

157159
(listableComponent as any).reloadedObject.emit(reloadedObject);
158-
tick();
160+
tick(200);
159161

160162
expect((comp as any).contentChange.emit).toHaveBeenCalledWith(reloadedObject);
161163
}));

src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ export class ListableObjectComponentLoaderComponent implements OnInit, OnChanges
197197
this.compRef.destroy();
198198
this.object = reloadedObject;
199199
this.instantiateComponent(reloadedObject);
200-
this.contentChange.emit(reloadedObject);
200+
// Add delay before emitting event to allow the new object is instantiated
201+
setTimeout(() => {
202+
this.contentChange.emit(reloadedObject);
203+
}, 100);
201204
}
202205
});
203206
}

src/app/shared/object-detail/object-detail.component.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
(sortFieldChange)="onSortFieldChange($event)"
1515
(paginationChange)="onPaginationChange($event)"
1616
(prev)="goPrev()"
17-
(next)="goNext()"
18-
>
17+
(next)="goNext()">
1918
<div class="row mt-2" *ngIf="objects?.hasSucceeded" @fadeIn>
2019
<div class="col"
2120
*ngFor="let object of objects?.payload?.page">
22-
<ds-listable-object-component-loader [object]="object" [viewMode]="viewMode" [context]="context"></ds-listable-object-component-loader>
21+
<ds-listable-object-component-loader [object]="object"
22+
[viewMode]="viewMode"
23+
[context]="context"
24+
(contentChange)="contentChange.emit($event)"></ds-listable-object-component-loader>
2325
</div>
2426
</div>
2527
<ds-error *ngIf="objects.hasFailed" message="{{'error.objects' | translate}}"></ds-error>

src/app/shared/object-detail/object-detail.component.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
ChangeDetectionStrategy,
3-
Component,
4-
EventEmitter,
5-
Input,
6-
Output,
7-
ViewEncapsulation
8-
} from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';
92

103
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
114
import { PaginatedList } from '../../core/data/paginated-list.model';
@@ -71,6 +64,11 @@ export class ObjectDetailComponent {
7164
*/
7265
@Input() showPaginator = true;
7366

67+
/**
68+
* Emit when one of the listed object has changed.
69+
*/
70+
@Output() contentChange = new EventEmitter<any>();
71+
7472
/**
7573
* If showPaginator is set to true, emit when the previous button is clicked
7674
*/

src/app/shared/object-list/object-list.component.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
(sortFieldChange)="onSortFieldChange($event)"
1515
(paginationChange)="onPaginationChange($event)"
1616
(prev)="goPrev()"
17-
(next)="goNext()"
18-
>
17+
(next)="goNext()">
1918
<ul *ngIf="objects?.hasSucceeded" class="list-unstyled" [ngClass]="{'ml-4': selectable}">
2019
<li *ngFor="let object of objects?.payload?.page; let i = index; let last = last" class="mt-4 mb-4 d-flex" [class.border-bottom]="hasBorder && !last" data-test="list-object">
2120
<ds-selectable-list-item-control *ngIf="selectable" [index]="i"
@@ -31,7 +30,7 @@
3130
[customData]="customData"
3231
(contentChange)="contentChange.emit()"
3332
(customEvent)="customEvent.emit($event)"
34-
></ds-listable-object-component-loader>
33+
(contentChange)="contentChange.emit($event)"></ds-listable-object-component-loader>
3534
</li>
3635
</ul>
3736
</ds-pagination>

src/app/shared/object-list/object-list.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class ObjectListComponent {
7979
/**
8080
* Config used for the import button
8181
*/
82-
@Input() importConfig: { importLabel: string };
82+
@Input() importConfig: { buttonLabel: string };
8383

8484
/**
8585
* Whether or not the pagination should be rendered as simple previous and next buttons instead of the normal pagination
@@ -231,4 +231,5 @@ export class ObjectListComponent {
231231
goNext() {
232232
this.next.emit(true);
233233
}
234+
234235
}

0 commit comments

Comments
 (0)