mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[CST-6056] optimize fix to issue with filter suggestion
This commit is contained in:
@@ -29,7 +29,7 @@ import { InputSuggestion } from '../../../../input-suggestions/input-suggestions
|
||||
import { SearchOptions } from '../../../models/search-options.model';
|
||||
import { SEARCH_CONFIG_SERVICE } from '../../../../../my-dspace-page/my-dspace-page.component';
|
||||
import { currentPath } from '../../../../utils/route.utils';
|
||||
import { getFacetValueForType, stripOperatorFromFilterValue } from '../../../search.utils';
|
||||
import { addOperatorToFilterValue, getFacetValueForType, stripOperatorFromFilterValue } from '../../../search.utils';
|
||||
import { createPendingRemoteDataObject } from '../../../../remote-data.utils';
|
||||
|
||||
@Component({
|
||||
@@ -234,32 +234,16 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
|
||||
* @param data The string from the input field
|
||||
*/
|
||||
onSubmit(data: any) {
|
||||
if (data.match(new RegExp(`^.+,(equals|query|authority)$`))) {
|
||||
this.selectedValues$.pipe(take(1)).subscribe((selectedValues) => {
|
||||
if (isNotEmpty(data)) {
|
||||
this.router.navigate(this.getSearchLinkParts(), {
|
||||
queryParams:
|
||||
{
|
||||
[this.filterConfig.paramName]: [
|
||||
...selectedValues.map((facet) => this.getFacetValue(facet)),
|
||||
data
|
||||
]
|
||||
},
|
||||
queryParamsHandling: 'merge'
|
||||
});
|
||||
this.filter = '';
|
||||
}
|
||||
this.filterSearchResults = observableOf([]);
|
||||
});
|
||||
}
|
||||
this.applyFilterValue(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* On click, set the input's value to the clicked data
|
||||
* @param data The value of the option that was clicked
|
||||
* Submits a selected filter value to the filter
|
||||
* Adds the "equals" operator to the received data before passing it on
|
||||
* @param data The string selected from input suggestions
|
||||
*/
|
||||
onClick(data: any) {
|
||||
this.filter = data;
|
||||
this.applyFilterValue(addOperatorToFilterValue(data, 'equals'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,6 +291,31 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the filter query using the value given and apply to the search.
|
||||
* @param data The string from the input field
|
||||
*/
|
||||
protected applyFilterValue(data) {
|
||||
if (data.match(new RegExp(`^.+,(equals|query|authority)$`))) {
|
||||
this.selectedValues$.pipe(take(1)).subscribe((selectedValues) => {
|
||||
if (isNotEmpty(data)) {
|
||||
this.router.navigate(this.getSearchLinkParts(), {
|
||||
queryParams:
|
||||
{
|
||||
[this.filterConfig.paramName]: [
|
||||
...selectedValues.map((facet) => this.getFacetValue(facet)),
|
||||
data
|
||||
]
|
||||
},
|
||||
queryParamsHandling: 'merge'
|
||||
});
|
||||
this.filter = '';
|
||||
}
|
||||
this.filterSearchResults = observableOf([]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve facet value
|
||||
*/
|
||||
|
@@ -24,7 +24,7 @@
|
||||
[name]="filterConfig.paramName"
|
||||
[(ngModel)]="filter"
|
||||
(submitSuggestion)="onSubmit($event)"
|
||||
(clickSuggestion)="onSubmit($event)"
|
||||
(clickSuggestion)="onClick($event)"
|
||||
(findSuggestions)="findSuggestions($event)"
|
||||
ngDefaultControl
|
||||
></ds-filter-input-suggestions>
|
||||
|
@@ -3,7 +3,6 @@ import { FilterType } from '../../../models/filter-type.model';
|
||||
import { renderFacetFor } from '../search-filter-type-decorator';
|
||||
import { facetLoad, SearchFacetFilterComponent } from '../search-facet-filter/search-facet-filter.component';
|
||||
import { addOperatorToFilterValue } from '../../../search.utils';
|
||||
import { InputSuggestion } from '../../../../input-suggestions/input-suggestions.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-search-hierarchy-filter',
|
||||
@@ -23,8 +22,6 @@ export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent i
|
||||
* @param data The string from the input field
|
||||
*/
|
||||
onSubmit(data: any) {
|
||||
this.filterSearchResults.subscribe((filterSearchResults: InputSuggestion[]) => {
|
||||
super.onSubmit(addOperatorToFilterValue(data, filterSearchResults.length ? 'equals' : 'query'));
|
||||
});
|
||||
super.onSubmit(addOperatorToFilterValue(data, 'query'));
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@
|
||||
[name]="filterConfig.paramName"
|
||||
[(ngModel)]="filter"
|
||||
(submitSuggestion)="onSubmit($event)"
|
||||
(clickSuggestion)="onSubmit($event)"
|
||||
(clickSuggestion)="onClick($event)"
|
||||
(findSuggestions)="findSuggestions($event)"
|
||||
ngDefaultControl></ds-filter-input-suggestions>
|
||||
</div>
|
||||
|
@@ -3,7 +3,6 @@ import { FilterType } from '../../../models/filter-type.model';
|
||||
import { facetLoad, SearchFacetFilterComponent } from '../search-facet-filter/search-facet-filter.component';
|
||||
import { renderFacetFor } from '../search-filter-type-decorator';
|
||||
import { addOperatorToFilterValue, } from '../../../search.utils';
|
||||
import { InputSuggestion } from '../../../../input-suggestions/input-suggestions.model';
|
||||
|
||||
/**
|
||||
* This component renders a simple item page.
|
||||
@@ -29,8 +28,6 @@ export class SearchTextFilterComponent extends SearchFacetFilterComponent implem
|
||||
* @param data The string from the input field
|
||||
*/
|
||||
onSubmit(data: any) {
|
||||
this.filterSearchResults.subscribe((filterSearchResults: InputSuggestion[]) => {
|
||||
super.onSubmit(addOperatorToFilterValue(data, filterSearchResults.length ? 'equals' : 'query'));
|
||||
});
|
||||
super.onSubmit(addOperatorToFilterValue(data, 'query'));
|
||||
}
|
||||
}
|
||||
|
@@ -66,11 +66,11 @@ describe('Search Utils', () => {
|
||||
|
||||
describe('addOperatorToFilterValue', () => {
|
||||
it('should add the operator to the value', () => {
|
||||
expect(addOperatorToFilterValue('value', 'operator')).toEqual('value,operator');
|
||||
expect(addOperatorToFilterValue('value', 'equals')).toEqual('value,equals');
|
||||
});
|
||||
|
||||
it('shouldn\'t add the operator to the value if it already contains the operator', () => {
|
||||
expect(addOperatorToFilterValue('value,operator', 'operator')).toEqual('value,operator');
|
||||
expect(addOperatorToFilterValue('value,equals', 'equals')).toEqual('value,equals');
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -49,7 +49,7 @@ export function stripOperatorFromFilterValue(value: string) {
|
||||
* @param operator
|
||||
*/
|
||||
export function addOperatorToFilterValue(value: string, operator: string) {
|
||||
if (!value.endsWith(`,${operator}`)) {
|
||||
if (!value.match(new RegExp(`^.+,(equals|query|authority)$`))) {
|
||||
return `${value},${operator}`;
|
||||
}
|
||||
return value;
|
||||
|
Reference in New Issue
Block a user