Skip to content

Commit

Permalink
🐛 Favor overriding CollectionsController
Browse files Browse the repository at this point in the history
This commit will allow us to override the CollectionsController instead
of the Blacklight::ConfigurationHelperBehavior.  A bug was noticed when
switching the sort fields that the field selected wouldn't stick in the
UI even though the fields were actually sorting correctly.  Overriding
the CollectionsController will be a better pattern since we override the
WorksController in the same way.  The reason why we didn't do that in
the first place was because it caused the show page to have the same
sort fields as the index page.  In this commit, we are also modifying
the show page to reconfigure the sort fields to address the issue.

Ref:
  - #748
  • Loading branch information
kirkkwang committed Nov 1, 2023
1 parent e603797 commit f4f6417
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 56 deletions.
9 changes: 9 additions & 0 deletions app/controllers/hyrax/dashboard/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def new
end

def show
configure_show_sort_fields

# unused assignment to be removed in 4.0.0
@banner_file = presenter.banner_file if collection_type.brandable?

Expand Down Expand Up @@ -732,6 +734,13 @@ def process_file_location(f)
end
end
## END OVERRIDE

def configure_show_sort_fields
# In the CollectionsControllerDecorator, we clear the sort fields and add our own to have
# the ability to sort the index with custom fields. However, this also affects the show page.
# Here we set the sort fields back to the defaults for the show page.
blacklight_config.sort_fields = CatalogController.blacklight_config.sort_fields
end
end
end
end
28 changes: 28 additions & 0 deletions app/controllers/hyrax/my/collections_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Hyrax
module My
module CollectionsControllerDecorator
def configure_facets
configure_blacklight do |config|
# clear facets copied from the CatalogController
config.sort_fields.clear
# Collections don't seem to have a date_uploaded_dtsi nor date_modified_dtsi
# we can at least use the system_modified_dtsi instead of date_modified_dtsi
# but we will omit date_uploaded_dtsi
config.add_sort_field "system_modified_dtsi desc", label: "date modified \u25BC"
config.add_sort_field "system_modified_dtsi asc", label: "date modified \u25B2"
config.add_sort_field "system_create_dtsi desc", label: "date created \u25BC"
config.add_sort_field "system_create_dtsi asc", label: "date created \u25B2"
config.add_sort_field "depositor_ssi asc, title_ssi asc", label: "depositor (A-Z)"
config.add_sort_field "depositor_ssi desc, title_ssi desc", label: "depositor (Z-A)"
config.add_sort_field "creator_ssi asc, title_ssi asc", label: "creator (A-Z)"
config.add_sort_field "creator_ssi desc, title_ssi desc", label: "creator (Z-A)"
end
end
end
end
end

Hyrax::My::CollectionsController.singleton_class.send(:prepend, Hyrax::My::CollectionsControllerDecorator)
Hyrax::My::CollectionsController.configure_facets
6 changes: 2 additions & 4 deletions app/controllers/hyrax/my/works_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ module My
module WorksControllerDecorator
def configure_facets
configure_blacklight do |config|
config.sort_fields.each_key do |key|
config.sort_fields.delete(key)
end

# clear facets copied from the CatalogController
config.sort_fields.clear
config.add_sort_field "date_uploaded_dtsi desc", label: "date uploaded \u25BC"
config.add_sort_field "date_uploaded_dtsi asc", label: "date uploaded \u25B2"
config.add_sort_field "date_modified_dtsi desc", label: "date modified \u25BC"
Expand Down
52 changes: 0 additions & 52 deletions app/helpers/blacklight/configuration_helper_behavior_decorator.rb

This file was deleted.

24 changes: 24 additions & 0 deletions spec/controllers/hyrax/my/collections_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

RSpec.describe Hyrax::My::CollectionsController, type: :controller do
describe "#configure_facets" do
subject { controller.blacklight_config.sort_fields.keys }

let(:expected_sort_fields) do
[
"system_modified_dtsi desc",
"system_modified_dtsi asc",
"system_create_dtsi desc",
"system_create_dtsi asc",
"depositor_ssi asc, title_ssi asc",
"depositor_ssi desc, title_ssi desc",
"creator_ssi asc, title_ssi asc",
"creator_ssi desc, title_ssi desc"
]
end

it "configures the custom sort fields" do
expect(subject).to match_array(expected_sort_fields)
end
end
end

0 comments on commit f4f6417

Please sign in to comment.