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

fix[Op#57989]: Specify action in non-index turbo stream requests storage projects list

Kabiru Mwenjabdb67efe80d3
diff --git a/app/components/admin/custom_fields/custom_field_projects/table_component.rb b/app/components/admin/custom_fields/custom_field_projects/table_component.rb
index 1e9f55a9d92..5eb0f19a4cd 100644
--- a/app/components/admin/custom_fields/custom_field_projects/table_component.rb
+++ b/app/components/admin/custom_fields/custom_field_projects/table_component.rb
@@ -30,6 +30,8 @@ module Admin
module CustomFields
module CustomFieldProjects
class TableComponent < Projects::TableComponent
+ include ::Projects::Concerns::TableComponent::StreamablePaginationLinksConstraints
+
def columns
@columns ||= query.selects.reject { |select| select.is_a?(Queries::Selects::NotExistingSelect) }
end
@@ -37,24 +39,6 @@ module Admin
def sortable?
false
end
-
- # @override optional_pagination_options are passed to the pagination_options
- # which are passed to #pagination_links_full in pagination_helper.rb
- #
- # In Turbo streamable components, we need to be able to specify the url_for(action:) so that links are
- # generated in the context of the component index action, instead of any turbo stream actions performing
- # partial updates on the page.
- #
- # params[:url_for_action] is passed to the pagination_options making it's way down to any pagination links
- # that are generated via link_to which calls url_for which uses the params[:url_for_action] to specify
- # the controller action that link_to should use.
- #
- def optional_pagination_options
- super.tap do |options|
- options[:params] = { action: params[:url_for_action] } if params[:url_for_action]
- options[:turbo_action] = "advance"
- end
- end
end
end
end
diff --git a/app/components/projects/concerns/table_component/streamable_pagination_links_constraints.rb b/app/components/projects/concerns/table_component/streamable_pagination_links_constraints.rb
new file mode 100644
index 00000000000..ddaedeaa11a
--- /dev/null
+++ b/app/components/projects/concerns/table_component/streamable_pagination_links_constraints.rb
@@ -0,0 +1,55 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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 Projects
+ module Concerns
+ module TableComponent
+ module StreamablePaginationLinksConstraints
+ # @override optional_pagination_options are passed to the pagination_options
+ # which are passed to #pagination_links_full in pagination_helper.rb
+ #
+ # In Turbo streamable components, we need to be able to specify the url_for(action:) so that links are
+ # generated in the context of the component index action, instead of any turbo stream actions performing
+ # partial updates on the page.
+ #
+ # params[:url_for_action] is passed to the pagination_options making it's way down to any pagination links
+ # that are generated via link_to which calls url_for which uses the params[:url_for_action] to specify
+ # the controller action that link_to should use.
+ #
+ # data-turbo-action="advance" is added to the pagination links ensure links pushState to the browser
+ #
+ def optional_pagination_options
+ super.tap do |options|
+ options[:params] = { action: params[:url_for_action] } if params[:url_for_action]
+ options[:turbo_action] = "advance"
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/modules/storages/app/components/storages/project_storages/projects/table_component.rb b/modules/storages/app/components/storages/project_storages/projects/table_component.rb
index 0ccf7c9497b..ea1db72e051 100644
--- a/modules/storages/app/components/storages/project_storages/projects/table_component.rb
+++ b/modules/storages/app/components/storages/project_storages/projects/table_component.rb
@@ -32,6 +32,8 @@
# for every "column" defined below.
module Storages::ProjectStorages::Projects
class TableComponent < Projects::TableComponent
+ include ::Projects::Concerns::TableComponent::StreamablePaginationLinksConstraints
+
options :storage
def columns
diff --git a/modules/storages/spec/features/storages/admin/project_storages_spec.rb b/modules/storages/spec/features/storages/admin/project_storages_spec.rb
index f4ae5ee03f8..fa0d54eaacc 100644
--- a/modules/storages/spec/features/storages/admin/project_storages_spec.rb
+++ b/modules/storages/spec/features/storages/admin/project_storages_spec.rb
@@ -228,6 +228,10 @@ RSpec.describe "Admin lists project mappings for a storage",
expect(page).to have_text(project.name)
expect(page).to have_text(subproject.name)
+
+ aggregate_failures "pagination links maintain the correct url" do
+ project_storages_index_page.expect_correct_pagination_links(model: storage)
+ end
end
context "when the user does not select a folder" do
@@ -297,6 +301,10 @@ RSpec.describe "Admin lists project mappings for a storage",
project_storages_index_page.within_the_table_row_containing(project.name) do
expect(page).to have_text("No specific folder")
end
+
+ aggregate_failures "pagination links maintain the correct url" do
+ project_storages_index_page.expect_correct_pagination_links(model: storage)
+ end
end
context "when oauth access has not been granted and manual selection" do
@@ -388,6 +396,10 @@ RSpec.describe "Admin lists project mappings for a storage",
expect(page).to have_no_selector("dialog")
expect(page).to have_text("Successful deletion.")
expect(page).to have_no_text(project.name)
+
+ aggregate_failures "pagination links maintain the correct url" do
+ project_storages_index_page.expect_correct_pagination_links(model: storage)
+ end
end
end
end