Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ GEM
safely_block (>= 1)
bootsnap (1.22.0)
msgpack (~> 1.2)
brakeman (8.1.0)
brakeman (8.1.1)
racc
builder (3.3.0)
bullet (8.1.0)
Expand Down Expand Up @@ -869,7 +869,7 @@ CHECKSUMS
binding_of_caller (2.0.0) sha256=e53eebf8428a85587aede7b43a83e7419eb85b8b690938a96aa330d03052d517
blazer (3.5.0) sha256=734b883b843fbd6d5c9db7a09ec267a068f504908f2d01b94fce151bd00ad4e2
bootsnap (1.22.0) sha256=5820c9d42c2efef095bee6565484bdc511f1223bf950140449c9385ae775793e
brakeman (8.1.0) sha256=cfa9e5214e4925842f4bc849a64f8a7e6c5d0425fe98eac8d7b7bc60fdc17e07
brakeman (8.1.1) sha256=a038d25ef911be910171222d2355e11ff5b5048cc4e2f08e7a4c11eccd4f418a
builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f
bullet (8.1.0) sha256=604b7e2636ec2137dcab3ba61a56248c39a0004a0c9405d58bad0686d23b98ff
bundler-audit (0.9.3) sha256=81c8766c71e47d0d28a0f98c7eed028539f21a6ea3cd8f685eb6f42333c9b4e9
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/bookmarks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class BookmarksController < ApplicationController
VALID_SORTS = %w[created_at title popularity].freeze
# Label => value for the personal bookmarks "Sort by" strip (shared/_sort_strip)
SORT_OPTIONS = { "Newest" => "created_at", "Title" => "title", "Most bookmarked" => "popularity" }.freeze

def index
authorize!
Expand Down
1 change: 1 addition & 0 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def set_index_variables
def populations_served
authorize! @organization
@sort = params[:sort].presence_in(Organization::BREAKDOWN_SORTS) || Organization::BREAKDOWN_SORTS.first
@sort_direction = params[:direction].presence_in(%w[asc desc]) || Organization.breakdown_default_direction(@sort)
end

# The org's workshop logs on their own page: the date rows of the one group a
Expand Down
2 changes: 2 additions & 0 deletions app/frontend/stylesheets/application.tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@
@source inline("{hover:,}border-{indigo,purple,teal,violet,orange,rose,blue,sky,emerald,slate,lime,stone,amber,green,yellow,gray,cyan,fuchsia,pink,brand-navy,brand-yellow,brand-green,brand-magenta,brand-orange,brand-purple,brand-teal,brand-coral,brand-olive,brand-pink,brand-amber,brand-cyan,brand-emerald}-{200,300}");
@source inline("ring-{indigo,purple,teal,violet,orange,rose,blue,sky,emerald,slate,lime,stone,amber,green,yellow,gray,cyan,fuchsia,pink,brand-navy,brand-yellow,brand-green,brand-magenta,brand-orange,brand-purple,brand-teal,brand-coral,brand-olive,brand-pink,brand-amber,brand-cyan,brand-emerald}-{200,300,400,500}");
@source inline("{hover:,}text-{indigo,purple,teal,violet,orange,rose,blue,sky,emerald,slate,lime,stone,amber,green,yellow,gray,cyan,fuchsia,pink,brand-navy,brand-yellow,brand-green,brand-magenta,brand-orange,brand-purple,brand-teal,brand-coral,brand-olive,brand-pink,brand-amber,brand-cyan,brand-emerald}-{50,{100..900..100},950}");
/* Active segment of shared/_sort_strip (radio mode) */
@source inline("has-checked:bg-{indigo,purple,teal,violet,orange,rose,blue,sky,emerald,slate,lime,stone,amber,green,yellow,gray,cyan,fuchsia,pink,brand-navy,brand-yellow,brand-green,brand-magenta,brand-orange,brand-purple,brand-teal,brand-coral,brand-olive,brand-pink,brand-amber,brand-cyan,brand-emerald}-700");

/* Per-field form layout widths (generated from FormField::WIDTH_GRID_SPANS, which
lives in a model file Tailwind does not scan) */
Expand Down
28 changes: 17 additions & 11 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,33 +404,37 @@ def active_facilitator_age_groups
.sort_by { |group, count| [ -count, group.position || 0, group.name.to_s ] }.map(&:first)
end

BREAKDOWN_SORT_OPTIONS = [ [ "Primary first", "primary" ], [ "Total", "total" ], [ "A–Z", "name" ] ].freeze
BREAKDOWN_SORT_OPTIONS = [ [ "Primary", "primary" ], [ "Total", "total" ], [ "Name", "name" ] ].freeze
BREAKDOWN_SORTS = BREAKDOWN_SORT_OPTIONS.map(&:last).freeze

def self.breakdown_default_direction(sort) = sort == "name" ? "asc" : "desc"

TagBreakdown = Data.define(:tag, :primary_count, :additional_count) do
def total = primary_count + additional_count

def sort_key(sort)
# Counts flip with the direction; ties stay A–Z.
def sort_key(sort, direction)
name = tag.name.to_s.downcase
sign = direction == "asc" ? 1 : -1
case sort
when "total" then [ -total, -primary_count, name ]
when "total" then [ sign * total, sign * primary_count, name ]
when "name" then [ name ]
else [ -primary_count, -additional_count, name ]
else [ sign * primary_count, sign * additional_count, name ]
end
end
end

# Every sector active facilitators hold, primary or additional, for the full breakdown page.
def active_facilitator_sector_breakdown(sort: nil)
def active_facilitator_sector_breakdown(sort: nil, direction: nil)
tag_breakdown(active_facilitators.flat_map { |person|
person.sectorable_items.filter_map { |item| [ item.sector, item.is_primary? ] if item.sector && item.sector.name != Sector::OTHER_SECTOR_NAME }
}, sort)
}, sort, direction)
end

def active_facilitator_age_group_breakdown(sort: nil)
def active_facilitator_age_group_breakdown(sort: nil, direction: nil)
tag_breakdown(active_facilitators.flat_map { |person|
person.primary_age_groups.map { |group| [ group, true ] } + person.additional_age_groups.map { |group| [ group, false ] }
}, sort)
}, sort, direction)
end

# Reads preloaded affiliations, so a list page that nests PEOPLE_TAGGINGS under
Expand Down Expand Up @@ -482,10 +486,12 @@ def website_link_url

private

def tag_breakdown(tag_and_primary_pairs, sort)
tag_and_primary_pairs.group_by(&:first)
def tag_breakdown(tag_and_primary_pairs, sort, direction)
direction ||= Organization.breakdown_default_direction(sort)
rows = tag_and_primary_pairs.group_by(&:first)
.map { |tag, pairs| TagBreakdown.new(tag:, primary_count: pairs.count(&:last), additional_count: pairs.count { |pair| !pair.last }) }
.sort_by { |row| row.sort_key(sort) }
.sort_by { |row| row.sort_key(sort, direction) }
sort == "name" && direction == "desc" ? rows.reverse : rows
end

def affiliation_dates_locked
Expand Down
8 changes: 8 additions & 0 deletions app/services/workshop_search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ class WorkshopSearchService

TITLE_SORT_SQL = "LOWER(TRIM(#{Workshop.strip_punctuation_sql_spaced('workshops.title')})) ASC".freeze

# Label => value for the index "Sort by" strip (shared/_sort_strip)
SORT_OPTIONS = {
"Newest" => "created",
"Title" => "title",
"Most bookmarked" => "popularity",
"Author" => "author"
}.freeze

attr_reader :params, :user, :admin
attr_accessor :workshops, :sort

Expand Down
23 changes: 6 additions & 17 deletions app/views/bookmarks/_personal_bookmarks_results.html.erb
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
<%= turbo_stream.replace("bookmarks_count", partial: "bookmarks_count") %>
<%
sort_base = params.permit(:keyword, :bookmarkable_type, :windows_type, :user_id, :number_of_items_per_page).to_h.symbolize_keys
sort_icon = ->(column) {
if @sort == column
@sort_direction == "asc" ? "fa-arrow-up" : "fa-arrow-down"
else
"fa-sort"
end
# Clicking the active segment flips its direction; the arrow shows which way it runs.
sort_href = ->(col) {
personal_bookmarks_path(sort_base.merge(sort: col, direction: (@sort == col && @sort_direction == "desc") ? "asc" : "desc", page: nil))
}
%>
<div class="<%= 'animate-fade blur-on-submit' if @bookmarks.any? %>">
<!-- Sort bar -->
<div class="mb-6 flex flex-wrap items-center gap-4">
<span class="font-semibold">Sort by:</span>
<% [ [ "created_at", "Newest" ], [ "title", "Title" ], [ "popularity", "Most Bookmarked" ] ].each do |col, label| %>
<%= link_to personal_bookmarks_path(sort_base.merge(sort: col, direction: (@sort == col && @sort_direction == "desc") ? "asc" : "desc", page: nil)),
data: { turbo_frame: "personal_bookmarks_results" },
class: "inline-flex items-center gap-1 text-sm font-medium #{@sort == col ? 'text-blue-700' : 'text-gray-600'} hover:text-gray-900" do %>
<%= label %>
<i class="fa-solid <%= sort_icon.call(col) %> text-xs opacity-70"></i>
<% end %>
<% end %>
<div class="mb-6 flex justify-end">
<%= render "shared/sort_strip", options: BookmarksController::SORT_OPTIONS, selected: @sort, domain: :bookmarks,
href: sort_href, active_icon: (@sort_direction == "asc" ? "fa-arrow-up" : "fa-arrow-down"), link_data: { turbo_frame: "personal_bookmarks_results" } %>
</div>

<div class="my-6 border-b border-gray-300"></div>
Expand Down
22 changes: 10 additions & 12 deletions app/views/organizations/populations_served.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@
The organization's profile and list show only primary tags.
</p>
<% if show_sectors || show_age_groups %>
<div class="flex shrink-0 items-center gap-2 text-sm">
<span class="text-gray-600">Sort by</span>
<div class="inline-flex rounded-lg border border-gray-200 bg-white p-0.5 shadow-sm">
<% Organization::BREAKDOWN_SORT_OPTIONS.each do |label, value| %>
<% active = value == @sort %>
<%= link_to label, populations_served_organization_path(@organization, sort: value, return_to: params[:return_to].presence_in(%w[organization_edit])),
aria: { current: (active ? "true" : nil) },
class: "rounded-md px-3 py-1 font-medium #{active ? "#{DomainTheme.bg_class_for(:organizations, intensity: 700)} text-white" : "text-gray-600 hover:bg-gray-100"}" %>
<% end %>
</div>
<div class="shrink-0">
<%# Clicking the active option flips its direction; other options open in their default direction %>
<%= render "shared/sort_strip", options: Organization::BREAKDOWN_SORT_OPTIONS, selected: @sort, domain: :organizations,
active_icon: (@sort_direction == "asc" ? "fa-arrow-up" : "fa-arrow-down"),
href: ->(value) {
flipped = (@sort_direction == "asc" ? "desc" : "asc") if value == @sort
populations_served_organization_path(@organization, sort: value, direction: flipped, return_to: params[:return_to].presence_in(%w[organization_edit]))
} %>
</div>
<% end %>
</div>
Expand All @@ -40,11 +38,11 @@
<div class="grid grid-cols-1 gap-6 p-4 sm:p-8 <%= "md:grid-cols-2" if show_sectors && show_age_groups %>">
<% if show_sectors %>
<%= render "organizations/tag_breakdown", title: "Sectors", domain: :sectors, facilitator_count: facilitator_count,
rows: @organization.active_facilitator_sector_breakdown(sort: @sort), link_param: :sector_names_all %>
rows: @organization.active_facilitator_sector_breakdown(sort: @sort, direction: @sort_direction), link_param: :sector_names_all %>
<% end %>
<% if show_age_groups %>
<%= render "organizations/tag_breakdown", title: "Age groups served", domain: :categories, facilitator_count: facilitator_count,
rows: @organization.active_facilitator_age_group_breakdown(sort: @sort), link_param: :category_names_all %>
rows: @organization.active_facilitator_age_group_breakdown(sort: @sort, direction: @sort_direction), link_param: :category_names_all %>
<% end %>
<% unless show_sectors || show_age_groups %>
<p class="text-gray-500 italic">This organization doesn't show sectors or age groups on its profile.</p>
Expand Down
17 changes: 3 additions & 14 deletions app/views/resources/_resources_count.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,9 @@
<h3 class="text-sm font-semibold tracking-wide text-gray-500 uppercase">Resources (<%= @count_display %>)</h3>
<%= render "shared/copy_url" %>

<%# Radios inside the search form, so a change auto-submits via the collection
controller. The default option submits blank, so the server re-derives the
default (Title once kinds are picked) until someone picks a sort. %>
<div class="ml-auto flex items-center gap-2 text-sm">
<span class="text-gray-600">Sort by</span>
<div class="inline-flex rounded-lg border border-gray-200 bg-white p-0.5 shadow-sm">
<% Resource::SORT_OPTIONS.each do |label, value| %>
<label class="has-checked:bg-brand-purple-700 cursor-pointer rounded-md px-3 py-1 font-medium text-gray-600 hover:bg-gray-100 has-checked:text-white has-focus-visible:ring-2 has-focus-visible:ring-indigo-300">
<%= radio_button_tag :sort, (value == @default_sort ? "" : value), value == @sort,
id: "sort_#{value}", class: "sr-only" %>
<%= label %>
</label>
<% end %>
</div>
<%# Blank submits for the default, so the server re-derives it (Title once kinds are picked) %>
<div class="ml-auto">
<%= render "shared/sort_strip", options: Resource::SORT_OPTIONS, selected: @sort, domain: :resources, default: @default_sort %>
</div>
</div>
</div>
43 changes: 43 additions & 0 deletions app/views/shared/_sort_strip.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<%# The one "Sort by" control for card/list indexes (tables sort by column header instead).
Segments fill with the domain's 700 color when active.

Two modes:
- Radios (no `href`): put it inside the search form so the collection controller
auto-submits; the checked segment is styled with `has-checked` (no JS).
`default` names the value that submits blank, so the server re-derives it.
- Links (`href` given): the server marks the active segment.

locals:
options - { label => value }
selected - the active value
domain - DomainTheme key for the active fill
href - optional ->(value) { path } (link mode)
link_data - optional data attributes for each link (e.g. turbo_frame)
active_icon - optional Font Awesome class shown after the active link (e.g. a direction arrow)
default - optional radio value that submits blank %>
<%
href = local_assigns[:href]
active_icon = local_assigns[:active_icon]
active_bg = DomainTheme.bg_class_for(domain, intensity: 700)
segment = "inline-flex items-center gap-1 rounded-md px-3 py-1 font-medium"
%>
<div class="flex flex-wrap items-center gap-2 text-sm">
<span class="whitespace-nowrap text-gray-600">Sort by</span>
<div class="inline-flex flex-wrap rounded-lg border border-gray-200 bg-white p-0.5 shadow-sm">
<% options.each do |label, value| %>
<% if href %>
<% active = value == selected %>
<%# Built inline (not a block) so the link text is exactly the label %>
<% text = active && active_icon ? safe_join([ label, tag.i(class: "fa-solid #{active_icon} text-xs") ]) : label %>
<%= link_to text, href.call(value), data: local_assigns[:link_data], aria: { current: (active ? "true" : nil) },
class: "#{segment} #{active ? "#{active_bg} text-white" : "text-gray-600 hover:bg-gray-100"}" %>
<% else %>
<label class="<%= segment %> has-checked:<%= active_bg %> cursor-pointer text-gray-600 hover:bg-gray-100 has-checked:text-white has-focus-visible:ring-2 has-focus-visible:ring-indigo-300">
<%= radio_button_tag :sort, (value == local_assigns[:default] ? "" : value), value == selected,
id: "sort_#{value}", class: "sr-only" %>
<%= label %>
</label>
<% end %>
<% end %>
</div>
</div>
10 changes: 5 additions & 5 deletions app/views/users/users_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<% if @users.any? %>
<!-- Small screens: one card per user -->
<div class="rounded border border-gray-200 bg-white lg:hidden">
<div class="flex flex-wrap items-center gap-x-4 gap-y-2 border-b border-gray-200 bg-gray-100 px-4 py-2 text-sm font-semibold">
<span class="text-gray-500">Sort by</span>
<% [ %w[email Email], %w[person Person], %w[confirmed Confirmed], %w[access Access], %w[admin Admin] ].each do |column, label| %>
<%= sort_link.call(column, label) %>
<% end %>
<div class="border-b border-gray-200 bg-gray-100 px-4 py-2">
<%= render "shared/sort_strip", options: { "Email" => "email", "Person" => "person", "Confirmed" => "confirmed", "Access" => "access", "Admin" => "admin" },
selected: @sort, domain: :admin_only, link_data: { turbo_frame: "users_results" },
href: ->(column) { users_path(sort_base.merge(sort: column, direction: (@sort == column && @sort_direction == "desc") ? "asc" : "desc", page: nil)) },
active_icon: (@sort_direction == "asc" ? "fa-arrow-up" : "fa-arrow-down") %>
</div>

<ul class="divide-y divide-gray-200">
Expand Down
51 changes: 0 additions & 51 deletions app/views/workshops/_sort_by_options.html.erb

This file was deleted.

7 changes: 6 additions & 1 deletion app/views/workshops/_workshops_count.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<div id="workshops_count">
<hr class="my-6 border-gray-300">
<div class="filters-applied flex w-full items-center gap-3">
<div class="filters-applied flex w-full flex-wrap items-center gap-3">
<h3 class="text-sm font-semibold tracking-wide text-gray-500 uppercase">
Workshops (<%= number_with_delimiter(@workshops&.total_entries) %>)
</h3>
<%= render "shared/copy_url" %>

<%# Radios inside the search form, so a change auto-submits via the collection controller %>
<div class="ml-auto">
<%= render "shared/sort_strip", options: WorkshopSearchService::SORT_OPTIONS, selected: @sort, domain: :workshops %>
</div>
</div>
</div>
11 changes: 0 additions & 11 deletions app/views/workshops/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@

<div class="mt-6"><%= render "filters_applied" %></div>

<div><hr class="my-6 border-gray-300"></div>

<!-- Sort Options -->
<div class="flex flex-wrap items-center gap-x-4 gap-y-2 font-medium">
<h3 class="text-sm font-semibold tracking-wide text-gray-500 uppercase">
Sort by
</h3>

<%= render "sort_by_options" %>
</div>

<%= render "workshops_count" %>
<% end %>

Expand Down
12 changes: 12 additions & 0 deletions db/seeds/features/2026-11-20-one-sort-by-control.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: "One Sort by control on workshops, bookmarks, and users"
area: content
display_status: admin_facing
released_on: 2026-11-20
pr_number: 2981
action_path: "/workshops"
summary: >-
Workshops, My Bookmarks, and the users list on small screens now sort with the
same Sort by button strip as the resource library and an organization's
sectors and age groups page.
pro_tips:
- "On My Bookmarks and the users list, click the highlighted option again to flip between ascending and descending; the arrow shows which way it runs."
Loading