Skip to content

Commit

Permalink
[#58160] show icons in life cycle list headers
Browse files Browse the repository at this point in the history
  • Loading branch information
EinLama committed Dec 9, 2024
1 parent 118a89f commit 1cf3295
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/components/projects/table_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ See COPYRIGHT and LICENSE files for more details.
</th>
<% 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 %>
<th>
<div class="generic-table--sort-header-outer">
Expand Down
26 changes: 15 additions & 11 deletions app/helpers/sort_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -392,35 +392,39 @@ 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`.
# It is important for keeping the current state in the GET parameters of each link used in
# 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")

Expand Down
8 changes: 8 additions & 0 deletions app/models/queries/projects/selects/life_cycle_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1cf3295

Please sign in to comment.