Merge pull request #7083 from opf/fix/global-search--enter-before-results-loaded

Fix: Submit global search on enter before results are loaded
pull/7090/head
Wieland Lindenthal 6 years ago committed by GitHub
commit 05d67435c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      frontend/src/app/modules/global_search/global-search-input.component.html
  2. 17
      frontend/src/app/modules/global_search/global-search-input.component.ts
  3. 2
      spec/features/search_spec.rb

@ -31,7 +31,8 @@
(open)="openCloseMenu(currentValue)" (open)="openCloseMenu(currentValue)"
(close)="select.filterValue = currentValue" (close)="select.filterValue = currentValue"
(change)="onChange($event)" (change)="onChange($event)"
(clear)="clearSearch()"> (clear)="clearSearch()"
(keydown.enter)="onEnterBeforeResultsLoaded()">
<ng-template ng-option-tmp let-item="item" let-index="index" let-search="searchTerm"> <ng-template ng-option-tmp let-item="item" let-index="index" let-search="searchTerm">
<div *ngIf="!item.id; else workPackageItemTemplate"> <div *ngIf="!item.id; else workPackageItemTemplate">
<div tabindex="-1" class="global-search--option"> <div tabindex="-1" class="global-search--option">

@ -64,6 +64,7 @@ export class GlobalSearchInputComponent implements OnInit, OnDestroy {
public currentValue:string = ''; public currentValue:string = '';
public expanded:boolean = false; public expanded:boolean = false;
public noResults:boolean = true;
public results:any[]; public results:any[];
public suggestions:any[]; public suggestions:any[];
@ -190,6 +191,13 @@ export class GlobalSearchInputComponent implements OnInit, OnDestroy {
this.openCloseMenu(this.currentValue); this.openCloseMenu(this.currentValue);
} }
// If Enter key is pressed before result list is loaded submit search in current scope
public onEnterBeforeResultsLoaded() {
if (this.noResults) {
this.searchInScope(this.currentScope);
}
}
// get work packages result list and append it to suggestions // get work packages result list and append it to suggestions
private getSearchResult(term:string) { private getSearchResult(term:string) {
this.autocompleteWorkPackages(term).then((values) => { this.autocompleteWorkPackages(term).then((values) => {
@ -214,6 +222,7 @@ export class GlobalSearchInputComponent implements OnInit, OnDestroy {
this.dynamicCssService.requireHighlighting(); this.dynamicCssService.requireHighlighting();
this.$element.find('.ui-autocomplete--loading').show(); this.$element.find('.ui-autocomplete--loading').show();
this.noResults = true;
let idOnly:boolean = false; let idOnly:boolean = false;
@ -306,7 +315,13 @@ export class GlobalSearchInputComponent implements OnInit, OnDestroy {
} }
private hideSpinner():void { private hideSpinner():void {
this.$element.find('.ui-autocomplete--loading').hide(); this.$element.find('.ui-autocomplete--loading').hide()
this.noResults = false;
}
private get currentScope():string {
let serviceScope = this.globalSearchService.projectScope;
return (serviceScope === '') ? 'current_project_and_all_descendants' : serviceScope;
} }
private unregister() { private unregister() {

@ -167,7 +167,6 @@ describe 'Search', type: :feature, js: true do
# Expect that a fresh global search will reset the advanced filters, i.e. that they are closed # Expect that a fresh global search will reset the advanced filters, i.e. that they are closed
global_search_field.set(work_packages[10].subject) global_search_field.set(work_packages[10].subject)
sleep(1)
global_search_field.send_keys(:enter) global_search_field.send_keys(:enter)
table.expect_work_package_not_listed(work_packages[9], wait: 20) table.expect_work_package_not_listed(work_packages[9], wait: 20)
table.expect_work_package_subject(work_packages[10].subject) table.expect_work_package_subject(work_packages[10].subject)
@ -179,7 +178,6 @@ describe 'Search', type: :feature, js: true do
# Expect that changing the search term without using the autocompleter will leave the project scope unchanged # Expect that changing the search term without using the autocompleter will leave the project scope unchanged
# at current_project. # at current_project.
global_search_field.set(other_work_package.subject) global_search_field.set(other_work_package.subject)
sleep(1)
global_search_field.send_keys(:enter) global_search_field.send_keys(:enter)
expect(current_url).to match(/\/#{project.identifier}\/search\?q=Other%20work%20package&work_packages=1&scope=current_project$/) expect(current_url).to match(/\/#{project.identifier}\/search\?q=Other%20work%20package&work_packages=1&scope=current_project$/)

Loading…
Cancel
Save