Commit 94e6d51e authored by Herminio Torres's avatar Herminio Torres

Fix the title of the toggle dropdown button

Before when you choose the way of `sort` instead it display the title correctly it was just apply the humanize helper in sort value.

E.g.

When you choose `Last updated` it should display the title `Last updated` instead of `Recently updated`. This fix makes this correctly displays the title.

Change the implementation of the `link_to` `filter_branches_path`

- Change the value of the `params[:sort]` in `link_to`. E.g. instead of using `'recently_updated'` is now using `sort_value_recently_updated`.

- Change the values of the case in the `branches_sorted_by` method for the values it receives in the `params[:sort]` that are: `nil`, `'name'`, `'updated_desc'`, `'updated_asc'`.
parent 680d361c
Please view this file on the master branch, on stable branches it's out of date.
v 8.11.0 (unreleased)
- Fix the title of the toggle dropdown button. !5515 (herminiotorres)
- Remove magic comments (`# encoding: UTF-8`) from Ruby files. !5456 (winniehell)
- Fix CI status icon link underline (ClemMakesApps)
- Fix of 'Commits being passed to custom hooks are already reachable when using the UI'
......
......@@ -6,6 +6,7 @@ class Projects::BranchesController < Projects::ApplicationController
before_action :authorize_push_code!, only: [:new, :create, :destroy]
def index
@sort = params[:sort].presence || 'name'
@branches = BranchesFinder.new(@repository, params).execute
@branches = Kaminari.paginate_array(@branches).page(params[:page])
......
......@@ -615,11 +615,11 @@ class Repository
case value
when 'name'
branches.sort_by(&:name)
when 'recently_updated'
when 'updated_desc'
branches.sort do |a, b|
commit(b.target).committed_date <=> commit(a.target).committed_date
end
when 'last_updated'
when 'updated_asc'
branches.sort do |a, b|
commit(a.target).committed_date <=> commit(b.target).committed_date
end
......
......@@ -14,18 +14,15 @@
.dropdown.inline
%button.dropdown-toggle.btn{type: 'button', 'data-toggle' => 'dropdown'}
%span.light
- if params[:sort].present?
= params[:sort].humanize
- else
Name
= projects_sort_options_hash[@sort]
%b.caret
%ul.dropdown-menu.dropdown-menu-align-right
%li
= link_to filter_branches_path(sort: nil) do
= link_to filter_branches_path(sort: sort_value_name) do
= sort_title_name
= link_to filter_branches_path(sort: 'recently_updated') do
= link_to filter_branches_path(sort: sort_value_recently_updated) do
= sort_title_recently_updated
= link_to filter_branches_path(sort: 'last_updated') do
= link_to filter_branches_path(sort: sort_value_oldest_updated) do
= sort_title_oldest_updated
- if can? current_user, :push_code, @project
......
......@@ -16,7 +16,7 @@ describe BranchesFinder do
end
it 'sorts by recently_updated' do
branches_finder = described_class.new(repository, { sort: 'recently_updated' })
branches_finder = described_class.new(repository, { sort: 'updated_desc' })
result = branches_finder.execute
......@@ -24,7 +24,7 @@ describe BranchesFinder do
end
it 'sorts by last_updated' do
branches_finder = described_class.new(repository, { sort: 'last_updated' })
branches_finder = described_class.new(repository, { sort: 'updated_asc' })
result = branches_finder.execute
......@@ -53,7 +53,7 @@ describe BranchesFinder do
context 'filter and sort' do
it 'filters branches by name and sorts by recently_updated' do
params = { sort: 'recently_updated', search: 'feature' }
params = { sort: 'updated_desc', search: 'feature' }
branches_finder = described_class.new(repository, params)
result = branches_finder.execute
......@@ -63,7 +63,7 @@ describe BranchesFinder do
end
it 'filters branches by name and sorts by last_updated' do
params = { sort: 'last_updated', search: 'feature' }
params = { sort: 'updated_asc', search: 'feature' }
branches_finder = described_class.new(repository, params)
result = branches_finder.execute
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment