Skip to content

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

Hide recent work packages header when empty

Christophe Bliard0fb10394ee2b
diff --git a/frontend/src/app/core/global_search/input/global-search-input.component.html b/frontend/src/app/core/global_search/input/global-search-input.component.html
index 11784e322b8..4747c055c06 100644
--- a/frontend/src/app/core/global_search/input/global-search-input.component.html
+++ b/frontend/src/app/core/global_search/input/global-search-input.component.html
@@ -36,8 +36,8 @@
[searchKey]="autocompleterOptions.searchKey"
[getOptionsFn]="autocompleterOptions.getOptionsFn"
>
- <ng-template op-autocompleter-header-tmp let-search="searchTerm">
- <div *ngIf="!searchTerm">{{text.recently_viewed}}</div>
+ <ng-template op-autocompleter-header-tmp>
+ <div *ngIf="!searchTerm && (hasRecentItems$ | async)">{{text.recently_viewed}}</div>
</ng-template>
<ng-template op-autocompleter-option-tmp let-item let-index="index" let-search="searchTerm">
<div *ngIf="!item.id; else workPackageItemTemplate">
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.ts
index 7e51292f098..a9d9b75d4d0 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
@@ -104,6 +104,10 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {
public markable$ = this._markable.asObservable();
+ public hasRecentItems$ = this.recentItemsService.recentItems$.pipe(
+ map((items) => (items.length > 0)),
+ );
+
getAutocompleterData = ():Observable<unknown[]> => this.autocompleteWorkPackages();
public autocompleterOptions = {
diff --git a/spec/features/search/recently_viewed_work_packages_spec.rb b/spec/features/search/recently_viewed_work_packages_spec.rb
new file mode 100644
index 00000000000..eb1e8fcb105
--- /dev/null
+++ b/spec/features/search/recently_viewed_work_packages_spec.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require 'spec_helper'
+
+RSpec.describe 'Recently viewed work packages', js: true, with_mail: false do
+ include Components::Autocompleter::NgSelectAutocompleteHelpers
+
+ shared_let(:admin) { create(:admin) }
+ let(:project) { create(:project) }
+ let(:global_search) { Components::GlobalSearch.new }
+
+ def recently_viewed_header_text
+ I18n.t('js.global_search.recently_viewed', raise: true).upcase
+ end
+
+ current_user { admin }
+
+ context 'when no work packages have been viewed' do
+ it 'displays nothing after clicking in the global search bar' do
+ visit project_path(project)
+
+ global_search.click_input
+ expect(global_search.dropdown).to be_visible
+ expect(global_search.dropdown).not_to have_text(recently_viewed_header_text)
+ end
+ end
+end
diff --git a/spec/features/search_spec.rb b/spec/features/search/search_spec.rb
similarity index 100%
rename from spec/features/search_spec.rb
rename to spec/features/search/search_spec.rb
diff --git a/spec/support/components/global_search.rb b/spec/support/components/global_search.rb
index 9a989cd2f52..60c90993fdc 100644
--- a/spec/support/components/global_search.rb
+++ b/spec/support/components/global_search.rb
@@ -16,11 +16,19 @@ module Components
container.find 'input'
end
+ def dropdown
+ container.find('.ng-dropdown-panel')
+ end
+
+ def click_input
+ input.hover
+ input.click
+ end
+
def search(query, submit: false)
SeleniumHubWaiter.wait
input.set ''
- input.hover
- input.click
+ click_input
input.set query
if submit