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

Enable search functionality in the project SubMenu

Henriette Dargeeaaef34b86e6
diff --git a/app/components/open_project/common/submenu_component.html.erb b/app/components/open_project/common/submenu_component.html.erb
index 77fd2568680..659a2f60a49 100644
--- a/app/components/open_project/common/submenu_component.html.erb
+++ b/app/components/open_project/common/submenu_component.html.erb
@@ -8,10 +8,16 @@
classes: "op-sidebar--search-input",
data: {
action: "input->filter--filter-list#filterLists",
- "filter--filter-list-target": "filter"
- }) %>
+ "filter--filter-list-target": "filter",
+ "test-selector": "op-sidebar--search-input"
+ },) %>
- <%= render Primer::Beta::Text.new(display: :none, classes: "op-sidebar--search-no-results-container") do
+ <%= render Primer::Beta::Text.new(display: :none,
+ classes: "op-sidebar--search-no-results-container",
+ data: {
+ "test-selector": "op-sidebar--search-no-results",
+ "filter--filter-list-target": "noResultsText",
+ }) do
I18n.t("js.autocompleter.notFoundText")
end %>
</div>
diff --git a/app/views/projects/menus/show.html.erb b/app/views/projects/menus/show.html.erb
index 0b009bf17e1..05a9fa3d40d 100644
--- a/app/views/projects/menus/show.html.erb
+++ b/app/views/projects/menus/show.html.erb
@@ -1,3 +1,3 @@
<%= turbo_frame_tag "projects_sidemenu" do %>
- <%= render OpenProject::Common::SubmenuComponent.new(sidebar_menu_items: @sidebar_menu_items) %>
+ <%= render OpenProject::Common::SubmenuComponent.new(sidebar_menu_items: @sidebar_menu_items, searchable: true) %>
<% end %>
diff --git a/frontend/src/global_styles/content/_sidebar.sass b/frontend/src/global_styles/content/_sidebar.sass
index dd4efb75431..b59aec4d294 100644
--- a/frontend/src/global_styles/content/_sidebar.sass
+++ b/frontend/src/global_styles/content/_sidebar.sass
@@ -7,6 +7,9 @@
&--search
margin: 12px
color: var(--main-menu-font-color)
+ display: flex
+ flex-direction: column
+ row-gap: 16px
&--search-input
// Overriding the defult input styles, because of the default dark background of the sidebar
diff --git a/frontend/src/stimulus/controllers/dynamic/filter/filter-list.controller.ts b/frontend/src/stimulus/controllers/dynamic/filter/filter-list.controller.ts
index 4b992ce9135..3cbaec296e4 100644
--- a/frontend/src/stimulus/controllers/dynamic/filter/filter-list.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/filter/filter-list.controller.ts
@@ -34,6 +34,7 @@ export default class FilterListController extends Controller {
static targets = [
'filter',
'searchItem',
+ 'noResultsText',
];
static values = {
@@ -41,6 +42,7 @@ export default class FilterListController extends Controller {
};
declare readonly filterTarget:HTMLInputElement;
+ declare readonly noResultsTextTarget:HTMLInputElement;
declare readonly searchItemTargets:HTMLInputElement[];
declare readonly clearButtonIdValue:string;
@@ -58,16 +60,24 @@ export default class FilterListController extends Controller {
filterLists() {
const query = this.filterTarget.value.toLowerCase();
+ let showNoResultsText = true;
this.searchItemTargets.forEach((item) => {
const text = item.textContent?.toLowerCase();
if (text?.includes(query)) {
(item as HTMLElement).classList.remove('d-none');
+ showNoResultsText = false;
} else {
(item as HTMLElement).classList.add('d-none');
}
});
+
+ if (showNoResultsText) {
+ this.noResultsTextTarget?.classList.remove('d-none');
+ } else {
+ this.noResultsTextTarget?.classList.add('d-none');
+ }
}
resetFilterViaClearButton() {
diff --git a/modules/meeting/spec/support/pages/meetings/index.rb b/modules/meeting/spec/support/pages/meetings/index.rb
index abf2f2c317e..6c810b3797c 100644
--- a/modules/meeting/spec/support/pages/meetings/index.rb
+++ b/modules/meeting/spec/support/pages/meetings/index.rb
@@ -73,9 +73,7 @@ module Pages::Meetings
end
def set_sidebar_filter(filter_name)
- within "#main-menu" do
- click_on text: filter_name
- end
+ submenu.click_item(filter_name)
end
def expect_no_meetings_listed
@@ -175,5 +173,9 @@ module Pages::Meetings
def row_for(meeting)
find("td.title", text: meeting.title).ancestor("tr")
end
+
+ def submenu
+ Components::Submenu.new
+ end
end
end
diff --git a/spec/features/projects/persisted_lists_spec.rb b/spec/features/projects/persisted_lists_spec.rb
index b3cc973cf1d..8fe662bd1af 100644
--- a/spec/features/projects/persisted_lists_spec.rb
+++ b/spec/features/projects/persisted_lists_spec.rb
@@ -507,6 +507,32 @@ RSpec.describe "Persisted lists on projects index page",
expect(page)
.to have_text("You are not authorized to access this page.")
end
+
+ it "can search for a query in the sidebar" do
+ # Go to the persisted query
+ visit projects_path(query_id: my_projects_list.id)
+ projects_page.expect_sidebar_filter("My projects list", selected: true)
+
+ # In the sidebar, search for a substring
+ projects_page.search_for_sidebar_filter("My proj")
+
+ # Only matches are still shown and the selection state is kept
+ projects_page.expect_sidebar_filter("My projects list", selected: true, visible: true)
+ projects_page.expect_sidebar_filter("My projects", selected: false, visible: true)
+
+ projects_page.expect_sidebar_filter("Active projects", selected: false, visible: false)
+ projects_page.expect_sidebar_filter("Archived projects", selected: false, visible: false)
+
+ # In the sidebar, search for another substring
+ projects_page.search_for_sidebar_filter("DO NOT MATCH")
+
+ projects_page.expect_sidebar_filter("My projects list", selected: true, visible: false)
+ projects_page.expect_sidebar_filter("My projects", selected: false, visible: false)
+ projects_page.expect_sidebar_filter("Active projects", selected: false, visible: false)
+ projects_page.expect_sidebar_filter("Archived projects", selected: false, visible: false)
+
+ projects_page.expect_no_search_results_in_sidebar
+ end
end
describe "persisted query access on invalid query" do
diff --git a/spec/support/components/common/submenu.rb b/spec/support/components/common/submenu.rb
new file mode 100644
index 00000000000..77c59af075d
--- /dev/null
+++ b/spec/support/components/common/submenu.rb
@@ -0,0 +1,67 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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.
+#++
+
+module Components
+ class Submenu
+ include Capybara::DSL
+ include Capybara::RSpecMatchers
+ include RSpec::Matchers
+
+ def expect_item(name, selected: false, visible: true)
+ within "#main-menu" do
+ selected_specifier = selected ? ".selected" : ":not(.selected)"
+
+ expect(page).to have_css(".op-sidemenu--item-action#{selected_specifier}", text: name, visible:)
+ end
+ end
+
+ def expect_no_item(name)
+ within "#main-menu" do
+ expect(page).to have_no_css(".op-sidemenu--item-action", text: name)
+ end
+ end
+
+ def click_item(name)
+ within "#main-menu" do
+ click_on text: name
+ end
+ end
+
+ def search_for_item(name)
+ within "#main-menu" do
+ page.find_test_selector("op-sidebar--search-input").set(name)
+ end
+ end
+
+ def expect_no_results_text
+ within "#main-menu" do
+ expect(page).to have_test_selector("op-sidebar--search-no-results", text: "No items found")
+ end
+ end
+ end
+end
diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rb
index def088142aa..b63943e3170 100644
--- a/spec/support/pages/projects/index.rb
+++ b/spec/support/pages/projects/index.rb
@@ -75,18 +75,24 @@ module Pages
expect(page).to have_css('[data-test-selector="project-query-name"]', text: name)
end
- def expect_sidebar_filter(filter_name, selected: false)
- within "#main-menu" do
- selected_specifier = selected ? ".selected" : ":not(.selected)"
-
- expect(page).to have_css(".op-sidemenu--item-action#{selected_specifier}", text: filter_name)
- end
+ def expect_sidebar_filter(filter_name, selected: false, visible: true)
+ submenu.expect_item(filter_name, selected:, visible:)
end
def expect_no_sidebar_filter(filter_name)
- within "#main-menu" do
- expect(page).to have_no_css(".op-sidemenu--item-action", text: filter_name)
- end
+ submenu.expect_no_item(filter_name)
+ end
+
+ def search_for_sidebar_filter(filter_name)
+ submenu.search_for_item(filter_name)
+ end
+
+ def expect_no_search_results_in_sidebar
+ submenu.expect_no_results_text
+ end
+
+ def set_sidebar_filter(filter_name)
+ submenu.click_item(filter_name)
end
def expect_current_page_number(number)
@@ -102,12 +108,6 @@ module Pages
end
end
- def set_sidebar_filter(filter_name)
- within "#main-menu" do
- click_on text: filter_name
- end
- end
-
def expect_filters_container_toggled
expect(page).to have_css(".op-filters-form")
end
@@ -443,6 +443,10 @@ module Pages
def boolean_filter?(filter)
%w[active member_of favored public templated].include?(filter.to_s)
end
+
+ def submenu
+ Components::Submenu.new
+ end
end
end
end