Skip to content

Commit

Permalink
Merge pull request #16944 from opf/feature/52147-quick-action-table-h…
Browse files Browse the repository at this point in the history
…eaders

[#52147] quick action table headers
  • Loading branch information
EinLama authored Oct 18, 2024
2 parents 450d1f0 + 80f6dc9 commit f27bd0a
Show file tree
Hide file tree
Showing 15 changed files with 709 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def columns
def sortable?
false
end

def use_quick_action_table_headers?
false
end
end
end
end
Expand Down
28 changes: 10 additions & 18 deletions app/components/projects/table_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<%= component_wrapper(tag: 'turbo-frame') do %>
<div class="project-list-page--table">
<div class="project-list-page--table" data-controller="table-action-menu" data-application-target="dynamic">
<div class="generic-table--flex-container">
<div class="generic-table--container <%= container_class %>">
<div class="generic-table--results-container">
Expand All @@ -54,28 +54,20 @@ 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">
<div class="generic-table--header generic-table--header_centered generic-table--header_no-min-width">
<span>
<%= render(Primer::Beta::Octicon.new(icon: "star-fill", color: :subtle, "aria-label": I18n.t(:label_favorite))) %>
</span>
</div>
</div>
</th>
<% else %>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<% if use_quick_action_table_headers? %>
<%= quick_action_table_header column.attribute, order_options(column, turbo: true) %>
<% else %>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<span>
<%= column.caption %>
</span>
</div>
</div>
</div>
</th>
</th>
<% end %>
<% end %>
<% end %>
<th>
Expand Down
13 changes: 10 additions & 3 deletions app/components/projects/table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def container_class

##
# The project sort by is handled differently
def build_sort_header(column, options)
helpers.projects_sort_header_tag(column, **options, param: :json)
def quick_action_table_header(column, options)
helpers.projects_sort_header_tag(column, query.selects.map(&:attribute), **options, param: :json)
end

# We don't return the project row
Expand Down Expand Up @@ -119,7 +119,10 @@ def href_only_when_not_sort_lft
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 }
Expand All @@ -132,6 +135,10 @@ def sortable_column?(select)
sortable? && query.known_order?(select.attribute)
end

def use_quick_action_table_headers?
true
end

def columns
@columns ||= begin
columns = query.selects.reject { |select| select.is_a?(::Queries::Selects::NotExistingSelect) }
Expand Down
13 changes: 11 additions & 2 deletions app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,25 @@ module ProjectsHelper
include WorkPackagesFilterHelper

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,
"status_explanation" => nil
}.freeze

# Just like sort_header tag but removes sorting by
# lft from the sort criteria as lft is mutually exclusive with
# the other criteria.
def projects_sort_header_tag(column, **)
def projects_sort_header_tag(column, all_column_attributes, **)
former_criteria = @sort_criteria.criteria.dup

@sort_criteria.criteria.reject! { |a, _| a == "lft" }

sort_header_tag(column, **, allowed_params: projects_query_param_names_for_sort)
sort_header_with_action_menu(column, all_column_attributes, PROJECTS_FILTER_FOR_COLUMN_MAPPING, **,
allowed_params: projects_query_param_names_for_sort)
ensure
@sort_criteria.criteria = former_criteria
end
Expand Down
Loading

0 comments on commit f27bd0a

Please sign in to comment.