Merge pull request #1691 from 4Science/CST-6056

fix for filter suggestion issue and bitstream description issue
This commit is contained in:
Tim Donohue
2022-06-22 10:46:05 -05:00
committed by GitHub
11 changed files with 58 additions and 36 deletions

View File

@@ -50,3 +50,7 @@
cursor: grabbing; cursor: grabbing;
} }
} }
:host ::ng-deep .larger-tooltip .tooltip-inner {
max-width: 500px;
}

View File

@@ -9,9 +9,10 @@
</div> </div>
<div class="{{columnSizes.columns[1].buildClasses()}} row-element d-flex align-items-center"> <div class="{{columnSizes.columns[1].buildClasses()}} row-element d-flex align-items-center">
<div class="w-100"> <div class="w-100">
<span class="text-truncate"> <div class="text-truncate" [tooltipClass]="'larger-tooltip'" placement="bottom"
[ngbTooltip]="bitstream?.firstMetadataValue('dc.description')">
{{ bitstream?.firstMetadataValue('dc.description') }} {{ bitstream?.firstMetadataValue('dc.description') }}
</span> </div>
</div> </div>
</div> </div>
<div class="{{columnSizes.columns[2].buildClasses()}} row-element d-flex align-items-center"> <div class="{{columnSizes.columns[2].buildClasses()}} row-element d-flex align-items-center">

View File

@@ -27,7 +27,7 @@
<div class="autocomplete dropdown-menu" [ngClass]="{'show': (show | async) && isNotEmpty(suggestions)}"> <div class="autocomplete dropdown-menu" [ngClass]="{'show': (show | async) && isNotEmpty(suggestions)}">
<div class="dropdown-list"> <div class="dropdown-list">
<div *ngFor="let suggestionOption of suggestions"> <div *ngFor="let suggestionOption of suggestions">
<a href="javascript:void(0);" class="d-block dropdown-item" (click)="onClickSuggestion(suggestionOption.value)" #suggestion> <a href="javascript:void(0);" class="d-block dropdown-item" (click)="onClickSuggestion(suggestionOption)" #suggestion>
<span [innerHTML]="suggestionOption.displayValue"></span> <span [innerHTML]="suggestionOption.displayValue"></span>
</a> </a>
</div> </div>

View File

@@ -51,7 +51,7 @@ describe('FilterInputSuggestionsComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should call onClickSuggestion() with the suggestion as a parameter', () => { it('should call onClickSuggestion() with the suggestion as a parameter', () => {
expect(comp.onClickSuggestion).toHaveBeenCalledWith(suggestions[clickedIndex].value); expect(comp.onClickSuggestion).toHaveBeenCalledWith(suggestions[clickedIndex]);
}); });
}); });
}); });

View File

@@ -32,8 +32,8 @@ export class FilterInputSuggestionsComponent extends InputSuggestionsComponent {
this.submitSuggestion.emit(data); this.submitSuggestion.emit(data);
} }
onClickSuggestion(data) { onClickSuggestion(data: InputSuggestion) {
this.value = data; this.value = data.value;
this.clickSuggestion.emit(data); this.clickSuggestion.emit(data);
this.close(); this.close();
this.blockReopen = true; this.blockReopen = true;

View File

@@ -7,6 +7,14 @@ export interface InputSuggestion {
*/ */
displayValue: string; displayValue: string;
/**
* The search query that can be used with filter suggestion.
* It contains the value within the operator :
* - value,equals
* - value,authority
*/
query?: string;
/** /**
* The actual value of the suggestion * The actual value of the suggestion
*/ */

View File

@@ -24,7 +24,7 @@
[name]="filterConfig.paramName" [name]="filterConfig.paramName"
[(ngModel)]="filter" [(ngModel)]="filter"
(submitSuggestion)="onSubmit($event)" (submitSuggestion)="onSubmit($event)"
(clickSuggestion)="onSubmit($event)" (clickSuggestion)="onClick($event)"
(findSuggestions)="findSuggestions($event)" (findSuggestions)="findSuggestions($event)"
ngDefaultControl></ds-filter-input-suggestions> ngDefaultControl></ds-filter-input-suggestions>
</div> </div>

View File

@@ -234,33 +234,16 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
* @param data The string from the input field * @param data The string from the input field
*/ */
onSubmit(data: any) { onSubmit(data: any) {
if (data.match(new RegExp(`^.+,(equals|query|authority)$`))) { this.applyFilterValue(data);
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([]);
}
);
}
} }
/** /**
* On click, set the input's value to the clicked data * Submits a selected filter value to the filter
* @param data The value of the option that was clicked * Take the query from the InputSuggestion object
* @param data The input suggestion selected
*/ */
onClick(data: any) { onClick(data: InputSuggestion) {
this.filter = data; this.applyFilterValue(data.query);
} }
/** /**
@@ -296,6 +279,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
return rd.payload.page.map((facet) => { return rd.payload.page.map((facet) => {
return { return {
displayValue: this.getDisplayValue(facet, data), displayValue: this.getDisplayValue(facet, data),
query: this.getFacetValue(facet),
value: stripOperatorFromFilterValue(this.getFacetValue(facet)) value: stripOperatorFromFilterValue(this.getFacetValue(facet))
}; };
}); });
@@ -308,6 +292,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 * Retrieve facet value
*/ */

View File

@@ -66,11 +66,11 @@ describe('Search Utils', () => {
describe('addOperatorToFilterValue', () => { describe('addOperatorToFilterValue', () => {
it('should add the operator to the value', () => { 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', () => { 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');
}); });
}); });

View File

@@ -49,7 +49,7 @@ export function stripOperatorFromFilterValue(value: string) {
* @param operator * @param operator
*/ */
export function addOperatorToFilterValue(value: string, operator: string) { export function addOperatorToFilterValue(value: string, operator: string) {
if (!value.endsWith(`,${operator}`)) { if (!value.match(new RegExp(`^.+,(equals|query|authority)$`))) {
return `${value},${operator}`; return `${value},${operator}`;
} }
return value; return value;