Skip to content

Commit 65efd09

Browse files
committed
fix(search): add default filters
Default filters are added only if there is no search. * Closes rero/rero-ils#3617. Co-Authored-by: Bertrand Zuchuat <[email protected]>
1 parent 9e8d497 commit 65efd09

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

projects/rero/ng-core/src/lib/record/search/record-search.component.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,6 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
404404
}
405405
)
406406
);
407-
// Add default filters on aggregations filters if not exist.
408-
if (this._config && this._config.defaultSearchInputFilters) {
409-
this._config.defaultSearchInputFilters.map((filter: {key: string, values: string[]}) => {
410-
if (!this.aggregationsFilters.some((e: any) => e.key === filter.key)) {
411-
this.aggregationsFilters.push(filter);
412-
}
413-
});
414-
}
415407
}
416408

417409
/**
@@ -871,6 +863,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
871863
* @param type Type of resource
872864
*/
873865
private _loadConfigurationForType(type: string) {
866+
const q = this._buildQueryString();
874867
this._config = this.recordUiService.getResourceConfig(type);
875868
this.recordUiService.canAddRecord$(type).subscribe((result: ActionStatus) => {
876869
this.addStatus = result;
@@ -899,8 +892,8 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
899892
// load export options
900893
this.exportOptions = this._exportFormats();
901894

902-
// Update filters with default search filters
903-
if (this._config.defaultSearchInputFilters) {
895+
// Update filters with default search filters only if the q parameter is empty
896+
if ((q === null || q.trim().length === 0) && this._config.defaultSearchInputFilters) {
904897
this._config.defaultSearchInputFilters.forEach((filter: { key: string, values: any[]}) => {
905898
this.recordSearchService.updateAggregationFilter(filter.key, filter.values);
906899
});

0 commit comments

Comments
 (0)