Skip to content

Extract FacetFiltersComponent so it's display can be customized #3609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
6 changes: 0 additions & 6 deletions app/assets/builds/blacklight.css
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,6 @@ main {
background: transparent url('data:image/svg+xml,%3csvg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-dash-square" viewBox="0 0 16 16"%3e%3cpath d="M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h12zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2z" /%3e%3cpath d="M4 8a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7A.5.5 0 0 1 4 8z" /%3e%3c/svg%3e') center/1em auto no-repeat;
}

/* Facet browse pages & modals
-------------------------------------------------- */
.facet-filters:not(:has(*)) {
display: none;
}

/* Search History */
.search-history {
--bl-history-filter-name-color: var(--bs-secondary-color);
Expand Down
6 changes: 0 additions & 6 deletions app/assets/stylesheets/blacklight/_facets.scss
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,3 @@ $facet-toggle-height: $facet-toggle-width !default;
$facet-toggle-width auto no-repeat;
}
}

/* Facet browse pages & modals
-------------------------------------------------- */
.facet-filters:not(:has(*)) {
display: none;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="<%= classes %>">
<%= render Blacklight::Search::FacetSuggestInput.new(facet: facet, presenter: presenter) %>
<%= render 'facet_index_navigation' if render_index_navigation? %>
</div>
27 changes: 27 additions & 0 deletions app/components/blacklight/search/facet_filters_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Blacklight::Search
class FacetFiltersComponent < Blacklight::Component
# @param [Blacklight::FacetFieldPresenter] presenter
def initialize(presenter:, classes: 'facet-filters card card-body bg-light p-3 mb-3 border-0')
@presenter = presenter
@classes = classes
end

def facet
@presenter.facet_field
end

attr_reader :classes, :presenter

delegate :display_facet, to: :presenter

def render?
facet.suggest != false || render_index_navigation?
end

def render_index_navigation?
facet.index_range && display_facet.index?
end
end
end
5 changes: 1 addition & 4 deletions app/views/catalog/facet.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<%= render Blacklight::System::ModalComponent.new do |component| %>
<% component.with_title { facet_field_label(@facet.key) } %>

<div class="facet-filters card card-body bg-light p-3 mb-3 border-0">
<%= render Blacklight::Search::FacetSuggestInput.new(facet: @facet, presenter: @presenter) %>
<%= render partial: 'facet_index_navigation' if @facet.index_range && @display_facet.index? %>
</div>
<%= render Blacklight::Search::FacetFiltersComponent.new(presenter: @presenter) %>

<div class="facet-pagination top d-flex flex-wrap w-100 justify-content-between border-bottom pb-3 mb-3">
<%= render :partial=>'facet_pagination' %>
Expand Down
10 changes: 6 additions & 4 deletions spec/views/catalog/facet.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
let(:blacklight_config) { Blacklight::Configuration.new }
let(:component) { instance_double(Blacklight::FacetComponent) }
let(:facet_suggest_input) { instance_double(Blacklight::Search::FacetSuggestInput) }
let(:facet_filters) { instance_double(Blacklight::Search::FacetFiltersComponent) }

before do
allow(Blacklight::FacetComponent).to receive(:new).and_return(component)
allow(Blacklight::Search::FacetSuggestInput).to receive(:new).and_return(facet_suggest_input)
allow(Blacklight::Search::FacetFiltersComponent).to receive(:new).and_return(facet_filters)

allow(view).to receive(:render).and_call_original
allow(view).to receive(:render).with(component)
allow(view).to receive(:render).with(facet_suggest_input)
allow(view).to receive(:render).with(facet_filters)

blacklight_config.add_facet_field 'xyz', label: "Facet title"
allow(view).to receive(:blacklight_config).and_return(blacklight_config)
Expand All @@ -25,9 +27,9 @@
expect(rendered).to have_css 'h1', text: "Facet title"
end

it "renders the facet suggest input" do
it "renders the facet filters" do
render
expect(view).to have_received(:render).with(facet_suggest_input)
expect(view).to have_received(:render).with(facet_filters)
end

it "renders facet pagination" do
Expand Down