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

feat[Op#54749]: add client side text filter

Kabiru Mwenja2e013efc5c20
diff --git a/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.html.erb b/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.html.erb
index 097b38764a0..c92f886b908 100644
--- a/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.html.erb
+++ b/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.html.erb
@@ -27,7 +27,14 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<%= component_wrapper(tag: "tr", class: row_css_class, data: { turbo: true }) do %>
+<%
+ wrapper_data_attributes = {
+ turbo: true,
+ "projects--settings--available-project-mappings-filter-target": "searchItem"
+ }
+%>
+
+<%= component_wrapper(tag: "tr", class: row_css_class, data: wrapper_data_attributes) do %>
<% columns.each do |column| %>
<td class="<%= column_css_class(column) %>">
<%= column_value(column) %>
diff --git a/app/views/admin/settings/project_custom_fields/project_mappings.html.erb b/app/views/admin/settings/project_custom_fields/project_mappings.html.erb
index 7699c86ac2b..d97890b6652 100644
--- a/app/views/admin/settings/project_custom_fields/project_mappings.html.erb
+++ b/app/views/admin/settings/project_custom_fields/project_mappings.html.erb
@@ -27,6 +27,11 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
+<% content_controller 'projects--settings--available-project-mappings-filter',
+ dynamic: true
+%>
+
+
<%=
render(Settings::ProjectCustomFields::EditFormHeaderComponent.new(
custom_field: @custom_field,
@@ -36,6 +41,19 @@ See COPYRIGHT and LICENSE files for more details.
<%=
render(Primer::OpenProject::SubHeader.new) do |component|
+ component.with_filter_input(
+ name: "available-project-mappings-filter",
+ label: I18n.t("projects.settings.project_custom_fields.project_mapping_filter.label"),
+ visually_hide_label: true,
+ placeholder: I18n.t("projects.settings.project_custom_fields.project_mapping_filter.placeholder"),
+ show_clear_button: true,
+ clear_button_id: "available-project-mappings-filter-clear-button",
+ data: {
+ action: "input->projects--settings--available-project-mappings-filter#filterLists",
+ "projects--settings--available-project-mappings-filter-target": "filter"
+ }
+ )
+
component.with_action_component do
render(Settings::ProjectCustomFields::ProjectCustomFieldMapping::NewProjectMappingComponent.new(
project_mapping: @project_mapping,
diff --git a/config/locales/en.yml b/config/locales/en.yml
index dddcdd77298..2082d2a6b23 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -336,6 +336,9 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}
new_project_mapping_form:
add_projects: Add projects
include_sub_projects: Include sub-projects
+ project_mapping_filter:
+ label: Search project
+ placeholder: Filter by text
types:
no_results_title_text: There are currently no types available.
form:
diff --git a/frontend/src/stimulus/controllers/dynamic/projects/settings/available-project-mappings-filter.controller.ts b/frontend/src/stimulus/controllers/dynamic/projects/settings/available-project-mappings-filter.controller.ts
new file mode 100644
index 00000000000..3f568a37e7a
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/projects/settings/available-project-mappings-filter.controller.ts
@@ -0,0 +1,73 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) 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.
+ * ++
+ */
+
+import { Controller } from '@hotwired/stimulus';
+
+export default class AvailableProjectMappingsFilterController extends Controller {
+ static targets = [
+ 'filter',
+ 'searchItem',
+ ];
+
+ declare readonly filterTarget:HTMLInputElement;
+ declare readonly searchItemTargets:HTMLInputElement[];
+
+ connect():void {
+ this.element.querySelector('#available-project-mappings-filter-clear-button')?.addEventListener('click', () => {
+ this.resetFilterViaClearButton();
+ });
+ }
+
+ disconnect():void {
+ this.element.querySelector('#available-project-mappings-filter-clear-button')?.removeEventListener('click', () => {
+ this.resetFilterViaClearButton();
+ });
+ }
+
+ filterLists() {
+ const query = this.filterTarget.value.toLowerCase();
+
+ this.searchItemTargets.forEach((item) => {
+ const text = item.textContent?.toLowerCase();
+
+ if (text?.includes(query)) {
+ (item as HTMLElement).classList.remove('d-none');
+ } else {
+ (item as HTMLElement).classList.add('d-none');
+ }
+ });
+ }
+
+ resetFilterViaClearButton() {
+ this.searchItemTargets.forEach((item) => {
+ (item as HTMLElement).classList.remove('d-none');
+ });
+ }
+}