84367: SearchForm/SearchComponent: add option to hide scope selection dropdown

This commit is contained in:
Yura
2021-10-20 11:27:55 +02:00
parent 9fc7b57157
commit 14b1fd463d
6 changed files with 29 additions and 2 deletions

View File

@@ -47,6 +47,12 @@ export class ConfigurationSearchPageComponent extends SearchComponent implements
*/ */
@Input() fixedFilterQuery: string; @Input() fixedFilterQuery: string;
/**
* Whether to show the scope selection dropdown
*/
@Input() scopeSelectable = true;
constructor(protected service: SearchService, constructor(protected service: SearchService,
protected sidebarService: SidebarService, protected sidebarService: SidebarService,
protected windowService: HostWindowService, protected windowService: HostWindowService,

View File

@@ -45,6 +45,7 @@
<ng-template #searchForm> <ng-template #searchForm>
<ds-search-form *ngIf="searchEnabled" id="search-form" <ds-search-form *ngIf="searchEnabled" id="search-form"
[query]="(searchOptions$ | async)?.query" [query]="(searchOptions$ | async)?.query"
[scopeSelectable]="scopeSelectable"
[scope]="(searchOptions$ | async)?.scope" [scope]="(searchOptions$ | async)?.scope"
[currentUrl]="searchLink" [currentUrl]="searchLink"
[scopes]="(scopeListRD$ | async)" [scopes]="(scopeListRD$ | async)"

View File

@@ -99,6 +99,11 @@ export class SearchComponent implements OnInit {
@Input() @Input()
context: Context; context: Context;
/**
* Whether to show the scope selection dropdown
*/
@Input() scopeSelectable = true;
/** /**
* Link to the search page * Link to the search page
*/ */

View File

@@ -1,11 +1,11 @@
<form #form="ngForm" (ngSubmit)="onSubmit(form.value)" class="row" action="/search"> <form #form="ngForm" (ngSubmit)="onSubmit(form.value)" class="row" action="/search">
<div *ngIf="isNotEmpty(scopes)" class="col-12 col-sm-3"> <div *ngIf="scopeSelectable && isNotEmpty(scopes)" class="col-12 col-sm-3">
<select [(ngModel)]="scope" name="scope" class="form-control" aria-label="Search scope" (change)="onScopeChange($event.target.value)" tabindex="0"> <select [(ngModel)]="scope" name="scope" class="form-control" aria-label="Search scope" (change)="onScopeChange($event.target.value)" tabindex="0">
<option value>{{'search.form.search_dspace' | translate}}</option> <option value>{{'search.form.search_dspace' | translate}}</option>
<option *ngFor="let scopeOption of scopes" [value]="scopeOption.id">{{scopeOption?.name ? scopeOption.name : 'search.form.search_dspace' | translate}}</option> <option *ngFor="let scopeOption of scopes" [value]="scopeOption.id">{{scopeOption?.name ? scopeOption.name : 'search.form.search_dspace' | translate}}</option>
</select> </select>
</div> </div>
<div [ngClass]="{'col-sm-9': isNotEmpty(scopes)}" class="col-12"> <div [ngClass]="{'col-sm-9': (scopeSelectable && isNotEmpty(scopes))}" class="col-12">
<div class="form-group input-group"> <div class="form-group input-group">
<input type="text" [(ngModel)]="query" name="query" class="form-control" attr.aria-label="{{ searchPlaceholder }}" <input type="text" [(ngModel)]="query" name="query" class="form-control" attr.aria-label="{{ searchPlaceholder }}"
[placeholder]="searchPlaceholder"> [placeholder]="searchPlaceholder">

View File

@@ -72,6 +72,16 @@ describe('SearchFormComponent', () => {
expect(select).toBeNull(); expect(select).toBeNull();
}); });
it('should not display scopes when scopeSelectable is false', () => {
comp.scopeSelectable = false;
comp.scopes = objects;
comp.scope = objects[1].id;
fixture.detectChanges();
const select = de.query(By.css('select'));
expect(select).toBeNull();
});
it('should display set query value in input field', fakeAsync(() => { it('should display set query value in input field', fakeAsync(() => {
const testString = 'This is a test query'; const testString = 'This is a test query';
comp.query = testString; comp.query = testString;

View File

@@ -66,6 +66,11 @@ export class SearchFormComponent {
*/ */
@Output() submitSearch = new EventEmitter<any>(); @Output() submitSearch = new EventEmitter<any>();
/**
* Whether to show the scope selection dropdown
*/
@Input() scopeSelectable = true;
constructor(private router: Router, private searchService: SearchService, constructor(private router: Router, private searchService: SearchService,
private paginationService: PaginationService, private paginationService: PaginationService,
private searchConfig: SearchConfigurationService private searchConfig: SearchConfigurationService