OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#38738] Global search missing results when searching for a work package ID
Dombi Attila6b04d612a4da
diff --git a/frontend/src/app/core/global_search/global-search-work-packages.component.ts b/frontend/src/app/core/global_search/global-search-work-packages.component.tsindex 379696eea59..6ca86b18bae 100644--- a/frontend/src/app/core/global_search/global-search-work-packages.component.ts+++ b/frontend/src/app/core/global_search/global-search-work-packages.component.ts@@ -27,7 +27,7 @@//++import {- AfterViewInit, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, Renderer2,+ AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, Renderer2,} from '@angular/core';import { FocusHelperService } from 'core-app/shared/directives/focus/focus-helper';import { I18nService } from 'core-app/core/i18n/i18n.service';@@ -46,6 +46,7 @@ export const globalSearchWorkPackagesSelector = 'global-search-work-packages';@Component({selector: globalSearchWorkPackagesSelector,+ changeDetection: ChangeDetectionStrategy.OnPush,template: `<wp-embedded-table *ngIf="!resultsHidden"[queryProps]="queryProps"@@ -69,7 +70,8 @@ export class GlobalSearchWorkPackagesComponent extends UntilDestroyedMixin implefilterButtonText: this.I18n.t('js.button_advanced_filter'),};- constructor(readonly FocusHelper:FocusHelperService,+ constructor(+ readonly FocusHelper:FocusHelperService,readonly elementRef:ElementRef,readonly renderer:Renderer2,readonly I18n:I18nService,@@ -79,7 +81,8 @@ export class GlobalSearchWorkPackagesComponent extends UntilDestroyedMixin implereadonly querySpace:IsolatedQuerySpace,readonly wpFilters:WorkPackageFiltersService,readonly cdRef:ChangeDetectorRef,- private UrlParamsHelper:UrlParamsHelperService) {+ private UrlParamsHelper:UrlParamsHelperService,+ ) {super();}@@ -115,7 +118,14 @@ export class GlobalSearchWorkPackagesComponent extends UntilDestroyedMixin impleconst filters:any[] = [];let columns = ['id', 'project', 'subject', 'type', 'status', 'updatedAt'];- if (this.globalSearchService.searchTerm.length > 0) {+ if (this.globalSearchService.searchTermIsId) {+ filters.push({+ id: {+ operator: '=',+ values: [this.globalSearchService.searchTermWithoutHash],+ },+ });+ } else if (this.globalSearchService.searchTerm.length > 0) {filters.push({search: {operator: '**',diff --git a/frontend/src/app/core/global_search/input/global-search-input.component.ts b/frontend/src/app/core/global_search/input/global-search-input.component.tsindex 844b2196ad8..ec8e345b212 100644--- a/frontend/src/app/core/global_search/input/global-search-input.component.ts+++ b/frontend/src/app/core/global_search/input/global-search-input.component.ts@@ -38,8 +38,8 @@ import {ViewChild,ViewEncapsulation,} from '@angular/core';-import { Observable, of } from 'rxjs';-import { map, tap } from 'rxjs/operators';+import { BehaviorSubject, Observable, of } from 'rxjs';+import { first, map, tap } from 'rxjs/operators';import { GlobalSearchService } from 'core-app/core/global_search/services/global-search.service';import { isClickedWithModifier } from 'core-app/shared/helpers/link-handling/link-handling';import { Highlighting } from 'core-app/features/work-packages/components/wp-fast-table/builders/highlighting/highlighting.functions';@@ -58,11 +58,6 @@ import { ApiV3WorkPackageCachedSubresource } from 'core-app/core/apiv3/endpointsexport const globalSearchSelector = 'global-search-input';-interface SearchResultItems {- items:SearchResultItem[]|SearchOptionItem[];- term:string;-}-interface SearchResultItem {id:string;subject:string;@@ -78,6 +73,11 @@ interface SearchOptionItem {text:string;}+interface SearchResultItems {+ items:SearchResultItem[]|SearchOptionItem[];+ term:string;+}+@Component({selector: globalSearchSelector,changeDetection: ChangeDetectionStrategy.OnPush,@@ -97,7 +97,9 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {public expanded = false;- public markable = false;+ private _markable = new BehaviorSubject<boolean>(false);++ public markable$ = this._markable.asObservable();getAutocompleterData = (query:string):Observable<unknown[]> => this.autocompleteWorkPackages(query);@@ -129,7 +131,8 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {close_search: this.I18n.t('js.global_search.close_search'),};- constructor(readonly elementRef:ElementRef,+ constructor(+ readonly elementRef:ElementRef,readonly I18n:I18nService,readonly apiV3Service:ApiV3Service,readonly pathHelperService:PathHelperService,@@ -139,7 +142,8 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {readonly deviceService:DeviceService,readonly cdRef:ChangeDetectorRef,readonly halNotification:HalResourceNotificationService,- readonly ngZone:NgZone) {+ readonly ngZone:NgZone,+ ) {}ngAfterViewInit():void {@@ -161,13 +165,21 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {return this.ngSelectComponent.ngSelectInstance.searchTerm;}+ public set markable(value:boolean) {+ this._markable.next(value);+ }++ public get markable():boolean {+ return this._markable.value;+ }+// detect if click is outside or inside the element@HostListener('click', ['$event'])public handleClick(event:JQuery.TriggeredEvent):void {event.preventDefault();// handle click on search button- if (insideOrSelf(this.btn.nativeElement, event.target)) {+ if (insideOrSelf(this.btn.nativeElement as HTMLElement, event.target as HTMLElement)) {if (this.deviceService.isMobile) {this.toggleMobileSearch();// open ng-select menu on default@@ -247,11 +259,15 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {// in and then decide what to do. If a direct hit is present, follow that. Otherwise,// go to the search in the current scope.public onEnterBeforeResultsLoaded():void {- if (this.selectedItem) {- this.followSelectedItem();- } else {- this.searchInScope(this.currentScope);- }+ this.markable$.pipe(+ first((v) => v),+ ).subscribe(() => {+ if (this.selectedItem) {+ this.followSelectedItem();+ } else {+ this.searchInScope(this.currentScope);+ }+ });}public statusHighlighting(statusId:string):string {@@ -416,9 +432,11 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {&& this.globalSearchService.isAfterSearch()&& this.globalSearchService.currentTab === 'work_packages') {window.history- .replaceState({},+ .replaceState(+ {},`${I18n.t('global_search.search')}: ${this.searchTerm}`,- this.globalSearchService.searchPath());+ this.globalSearchService.searchPath(),+ );return;}diff --git a/frontend/src/app/core/global_search/services/global-search.service.ts b/frontend/src/app/core/global_search/services/global-search.service.tsindex abc058d8360..c8c192d9ebc 100644--- a/frontend/src/app/core/global_search/services/global-search.service.ts+++ b/frontend/src/app/core/global_search/services/global-search.service.ts@@ -58,10 +58,12 @@ export class GlobalSearchService {public resultsHidden$ = this._resultsHidden.asObservable();- constructor(protected I18n:I18nService,+ constructor(+ protected I18n:I18nService,protected injector:Injector,protected PathHelper:PathHelperService,- protected currentProjectService:CurrentProjectService) {+ protected currentProjectService:CurrentProjectService,+ ) {this.initialize();}@@ -118,6 +120,17 @@ export class GlobalSearchService {return this._searchTerm.value;}+ public get searchTermIsId():boolean {+ return this.searchTermWithoutHash !== this.searchTerm;+ }++ public get searchTermWithoutHash():string {+ if (/^#(\d+)/.exec(this.searchTerm)) {+ return this.searchTerm.substr(1);+ }+ return this.searchTerm;+ }+public get tabs():string {return this._tabs.value;}diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rbindex 7a0cf1577a3..ec8d596b3ef 100644--- a/spec/features/search_spec.rb+++ b/spec/features/search_spec.rb@@ -213,6 +213,30 @@ describe 'Search', js: true, with_mail: false, with_settings: { per_page_optionstable.expect_work_package_subject(work_packages[1].subject)endend++ describe 'by #id' do+ let(:work_package) { work_packages.last }++ it 'loads the WP results table with the correct WP' do+ select_autocomplete(page.find('.top-menu-search--input'),+ query: "##{work_package.id}",+ select_text: "In all projects ↵",+ wait_dropdown_open: false)+ table = Pages::EmbeddedWorkPackagesTable.new(find('.work-packages-embedded-view--container'))+ table.ensure_work_package_not_listed!(*work_packages[0...-1])+ table.expect_work_package_subject(work_package.subject)+ end++ context 'when submitting without autocomplete' do+ it 'loads the WP in full view' do+ global_search.search "##{work_package.id}"+ global_search.submit_with_enter++ wp_page = Pages::FullWorkPackage.new(work_package)+ wp_page.expect_subject+ end+ end+ endendcontext 'for project search' do