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

[#52147] show the quick action menu for non-sortable columns

Tobias Dillmann7c0f8c4ec6c7
diff --git a/app/components/projects/table_component.html.erb b/app/components/projects/table_component.html.erb
index 5e16a55c21d..8386cc0afb6 100644
--- a/app/components/projects/table_component.html.erb
+++ b/app/components/projects/table_component.html.erb
@@ -54,8 +54,6 @@ See COPYRIGHT and LICENSE files for more details.
</div>
</div>
</th>
- <% elsif sortable_column?(column) %>
- <%= build_sort_header column.attribute, order_options(column, turbo: true) %>
<% elsif column.attribute == :favored %>
<th>
<div class="generic-table--header-outer">
@@ -67,15 +65,7 @@ See COPYRIGHT and LICENSE files for more details.
</div>
</th>
<% else %>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= column.caption %>
- </span>
- </div>
- </div>
- </th>
+ <%= quick_action_table_header column.attribute, order_options(column, turbo: true) %>
<% end %>
<% end %>
<th>
diff --git a/app/components/projects/table_component.rb b/app/components/projects/table_component.rb
index e8265938581..dfd0f4d3fba 100644
--- a/app/components/projects/table_component.rb
+++ b/app/components/projects/table_component.rb
@@ -63,7 +63,7 @@ module Projects
##
# The project sort by is handled differently
- def build_sort_header(column, options)
+ def quick_action_table_header(column, options)
helpers.projects_sort_header_tag(column, query.selects.map(&:attribute), **options, param: :json)
end
@@ -119,7 +119,10 @@ module Projects
end
def order_options(select, turbo: false)
- options = { caption: select.caption }
+ options = {
+ caption: select.caption,
+ sortable: sortable_column?(select)
+ }
if turbo
options[:data] = { "turbo-stream": true }
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index e508d83b4b9..c01a2c1bc15 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -31,10 +31,12 @@ module ProjectsHelper
PROJECTS_QUERY_PARAM_NAMES = %i[query_id filters columns sortBy per_page page].freeze
PROJECTS_FILTER_FOR_COLUMN_MAPPING = {
+ "description" => nil,
"identifier" => nil,
"name" => "id",
"project_status" => "project_status_code",
- "required_disk_space" => nil
+ "required_disk_space" => nil,
+ "status_explanation" => nil
}.freeze
# Just like sort_header tag but removes sorting by
diff --git a/app/helpers/sort_helper.rb b/app/helpers/sort_helper.rb
index fff342606e9..1d195b4c13d 100644
--- a/app/helpers/sort_helper.rb
+++ b/app/helpers/sort_helper.rb
@@ -349,7 +349,8 @@ module SortHelper
options[:title] = sort_header_title(column, caption, options)
within_sort_header_tag_hierarchy(options, sort_class(column)) do
- yield(column, caption, default_order, allowed_params:, param:, lang:, title: options[:title], data:)
+ yield(column, caption, default_order, allowed_params:, param:, lang:, title: options[:title],
+ sortable: options.fetch(:sortable, false), data:)
end
end
@@ -390,6 +391,7 @@ module SortHelper
caption ||= column.to_s.humanize
filter = find_filter_for_column(column, filter_column_mapping)
+ sortable = html_options.delete(:sortable)
# `param` is not needed in the `content_arguments`, but should remain in the `html_options`.
# It is important for keeping the current state in the GET parameters of each link used in
@@ -398,9 +400,9 @@ module SortHelper
render Primer::Alpha::ActionMenu.new(menu_id: "menu-#{column}") do |menu|
action_button(menu, caption)
- sort_actions(menu, column, default_order, content_args:, allowed_params:, **html_options)
- # Some columns do not offer a filter. Only show the option when filtering is possible.
+ # Some columns are not sortable or do not offer a suitable filter. Omit those actions for them.
+ sort_actions(menu, column, default_order, content_args:, allowed_params:, **html_options) if sortable
filter_action(menu, column, filter, content_args:) if filter
move_column_actions(menu, column, table_columns, content_args:, allowed_params:, **html_options)
@@ -439,10 +441,10 @@ module SortHelper
href: asc_sort_link)) do |item|
item.with_leading_visual_icon(icon: :"sort-asc")
end
+ menu.with_divider
end
def filter_action(menu, column, filter, content_args:)
- menu.with_divider
menu.with_item(**menu_options(label: t(:label_filter_by),
content_args: content_args.merge(
data: {
@@ -453,14 +455,13 @@ module SortHelper
))) do |item|
item.with_leading_visual_icon(icon: :filter)
end
+ menu.with_divider
end
def move_column_actions(menu, column, selected_columns, content_args:, allowed_params: nil, **html_options)
column_pos = selected_columns.index(column)
return unless column_pos
- menu.with_divider
-
# Add left shift action if possible (i.e. current column is not the leftmost one)
if column_pos > 0
add_shift_action(menu, column, selected_columns, content_args, allowed_params, html_options, direction: :left)
diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rb
index 742d23cca18..18179dd78f4 100644
--- a/spec/features/projects/projects_index_spec.rb
+++ b/spec/features/projects/projects_index_spec.rb
@@ -1537,6 +1537,16 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
end
end
+ describe "sorting a column",
+ with_settings: { enabled_projects_columns: %w[created_at name project_status description] } do
+ it "does not offer the sorting options for columns that are not sortable" do
+ projects_page.expect_columns_in_order("Created on", "Name", "Status", "Description")
+
+ projects_page.click_table_header_to_open_action_menu("Description")
+ projects_page.expect_no_sorting_option_in_action_menu("Description")
+ end
+ end
+
describe "removing a column" do
it "removes the column from the table view" do
projects_page.expect_columns_in_order("Created on", "Name", "Status")
diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rb
index 925a4beef8b..480bc3cbfdd 100644
--- a/spec/support/pages/projects/index.rb
+++ b/spec/support/pages/projects/index.rb
@@ -487,6 +487,11 @@ module Pages
find(".generic-table--sort-header a[data-test-selector='#{column_name.downcase}-sort-#{direction}']").click
end
+ def expect_no_sorting_option_in_action_menu(column_name)
+ expect(page).to have_no_css("[data-test-selector='#{column_name.downcase}-sort-asc']")
+ expect(page).to have_no_css("[data-test-selector='#{column_name.downcase}-sort-desc']")
+ end
+
def move_column_via_action_menu(column_name, direction:)
raise ArgumentError, "direction should be :left or :right" unless %i[left right].include?(direction)