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

Use turbo stream when sorting columns

Klaus Zanders5a8925c33732
diff --git a/app/components/projects/table_component.html.erb b/app/components/projects/table_component.html.erb
index aba75fdcdeb..b2f2f2046bd 100644
--- a/app/components/projects/table_component.html.erb
+++ b/app/components/projects/table_component.html.erb
@@ -50,13 +50,13 @@ See COPYRIGHT and LICENSE files for more details.
helpers.op_icon("icon-hierarchy"),
href: href_only_when_not_sort_lft,
class: "spot-link #{deactivate_class_on_lft_sort}",
+ data: { "turbo-stream": true },
title: t(:label_sort_by, value: %("#{t(:label_project_hierarchy)}")) %>
</div>
</div>
</th>
<% elsif sortable_column?(column) %>
- <%= build_sort_header column.attribute,
- order_options(column) %>
+ <%= build_sort_header column.attribute, order_options(column, turbo: true) %>
<% elsif column.attribute == :favored %>
<th>
<div class="generic-table--header-outer">
diff --git a/app/components/projects/table_component.rb b/app/components/projects/table_component.rb
index 76d9ef5dea0..0873cb7ad70 100644
--- a/app/components/projects/table_component.rb
+++ b/app/components/projects/table_component.rb
@@ -115,10 +115,14 @@ module Projects
end
end
- def order_options(select)
- {
- caption: select.caption
- }
+ def order_options(select, turbo: false)
+ options = { caption: select.caption }
+
+ if turbo
+ options[:data] = { "turbo-stream": true }
+ end
+
+ options
end
def sortable_column?(select)
diff --git a/spec/helpers/sort_helper_spec.rb b/spec/helpers/sort_helper_spec.rb
index 96ec6b1048b..3de566be89c 100644
--- a/spec/helpers/sort_helper_spec.rb
+++ b/spec/helpers/sort_helper_spec.rb
@@ -250,7 +250,17 @@ RSpec.describe SortHelper do
it "includes the passed data parm in the link" do
expect(output).to be_html_eql(<<~HTML)
- <th title="Sort by &quot;Id&quot;"><div class="generic-table--sort-header-outer"><div class="generic-table--sort-header"><span><a title="Sort by &quot;Id&quot;" data-turbo-stream="true" href="/work_packages?sort=sort_criteria_params">Id</a></span></div></div></th>
+ <th title="Sort by &quot;Id&quot;">
+ <div class="generic-table--sort-header-outer">
+ <div class="generic-table--sort-header">
+ <span>
+ <a title="Sort by &quot;Id&quot;" data-turbo-stream="true" href="/work_packages?sort=sort_criteria_params">
+ Id
+ </a>
+ </span>
+ </div>
+ </div>
+ </th>
HTML
end
end