From 1cf32958b3ce82aacd280dad42ceac3d3b8846f8 Mon Sep 17 00:00:00 2001 From: Tobias Dillmann Date: Mon, 9 Dec 2024 13:38:09 +0100 Subject: [PATCH] [#58160] show icons in life cycle list headers --- .../projects/table_component.html.erb | 2 +- app/helpers/sort_helper.rb | 26 +++++++++++-------- .../projects/selects/life_cycle_step.rb | 8 ++++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/components/projects/table_component.html.erb b/app/components/projects/table_component.html.erb index a114faeff841..9f33feb4aeea 100644 --- a/app/components/projects/table_component.html.erb +++ b/app/components/projects/table_component.html.erb @@ -56,7 +56,7 @@ See COPYRIGHT and LICENSE files for more details. <% else %> <% if use_quick_action_table_headers? %> - <%= quick_action_table_header column.attribute, order_options(column, turbo: true) %> + <%= quick_action_table_header column, order_options(column, turbo: true) %> <% else %>
diff --git a/app/helpers/sort_helper.rb b/app/helpers/sort_helper.rb index e0a557d56b15..daf2c395ae0f 100644 --- a/app/helpers/sort_helper.rb +++ b/app/helpers/sort_helper.rb @@ -331,8 +331,8 @@ def sort_header_tag(column, allowed_params: nil, **options) # This is a more specific version of #sort_header_tag. # For "filter by" to work properly, you must pass a Hash for `filter_column_mapping`. def sort_header_with_action_menu(column, all_columns, filter_column_mapping = {}, allowed_params: nil, **options) - with_sort_header_options(column, allowed_params:, **options) do |col, cap, default_order, **opts| - action_menu(col, all_columns, cap, default_order, filter_column_mapping, **opts) + with_sort_header_options(column.attribute, allowed_params:, **options) do |_col, cap, default_order, **opts| + action_menu(column, all_columns, cap, default_order, filter_column_mapping, **opts) end end @@ -392,9 +392,11 @@ def find_filter_for_column(column, filter_mapping) # Some of the method arguments are only needed for specific actions. def action_menu(column, table_columns, caption, default_order, filter_column_mapping = {}, allowed_params: nil, **html_options) - caption ||= column.to_s.humanize - filter = find_filter_for_column(column, filter_column_mapping) + attribute = column.attribute + caption ||= attribute.to_s.humanize + + filter = find_filter_for_column(attribute, filter_column_mapping) sortable = html_options.delete(:sortable) # `param` is not needed in the `content_arguments`, but should remain in the `html_options`. @@ -402,25 +404,27 @@ def action_menu(column, table_columns, caption, default_order, filter_column_map # the action menu. content_args = html_options.merge(rel: :nofollow, param: nil) - render Primer::Alpha::ActionMenu.new(menu_id: "menu-#{column}") do |menu| - action_button(menu, caption, favorite: column == :favored) + render Primer::Alpha::ActionMenu.new(menu_id: "menu-#{attribute}") do |menu| + action_button(menu, column, caption, favorite: column == :favored) # 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 + sort_actions(menu, attribute, default_order, content_args:, allowed_params:, **html_options) if sortable + filter_action(menu, attribute, filter, content_args:) if filter - move_column_actions(menu, column, table_columns, content_args:, allowed_params:, **html_options) - add_and_remove_column_actions(menu, column, table_columns, content_args:, allowed_params:, **html_options) + move_column_actions(menu, attribute, table_columns, content_args:, allowed_params:, **html_options) + add_and_remove_column_actions(menu, attribute, table_columns, content_args:, allowed_params:, **html_options) end end - def action_button(menu, caption, favorite: false) + def action_button(menu, column, caption, favorite: false) menu.with_show_button(scheme: :link, color: :default, text_transform: :uppercase, underline: false, display: :inline_flex, classes: "generic-table--action-menu-button") do |button| if favorite # This column only shows an icon, no text. render Primer::Beta::Octicon.new(icon: "star-fill", color: :subtle, "aria-label": I18n.t(:label_favorite)) + elsif column.respond_to?(:action_menu_header) + column.action_menu_header(button) else button.with_trailing_action_icon(icon: :"triangle-down") diff --git a/app/models/queries/projects/selects/life_cycle_step.rb b/app/models/queries/projects/selects/life_cycle_step.rb index 55725c053452..6143283809bd 100644 --- a/app/models/queries/projects/selects/life_cycle_step.rb +++ b/app/models/queries/projects/selects/life_cycle_step.rb @@ -57,4 +57,12 @@ def life_cycle_step def available? life_cycle_step.present? end + + def action_menu_header(button) + icon = life_cycle_step.is_a?(Project::StageDefinition) ? :"git-commit" : :diamond + button.with_leading_visual_icon(icon:) + button.with_trailing_action_icon(icon: :"triangle-down") + + caption.to_s + end end