-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to filter facets in the facets "more" modal (#3367)
* Facet typeahead: back end This creates a new endpoint at /catalog/facet/<facet_name>/<query_fragment> Co-authored-by: Isha Sinha <[email protected]> * Facet typeahead: front end Co-authored-by: Christina Chortaria <[email protected]> * bundle exec i18n-tasks add-missing * Incorporate feedback from review Rather than two very similar controller actions for facets vs. facet_suggest, this commit combines them into a single controller action. --------- Co-authored-by: Isha Sinha <[email protected]> Co-authored-by: Christina Chortaria <[email protected]>
- Loading branch information
1 parent
6ddb0ec
commit 46452d2
Showing
31 changed files
with
277 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/components/blacklight/search/facet_suggest_input.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<label for="facet-suggest-<%= facet.key %>"> | ||
<%= I18n.t('blacklight.search.facets.suggest.label', field_label: presenter&.label) %> | ||
</label> | ||
<input class="facet-suggest form-control" | ||
id="facet-suggest-<%= facet.key %>" | ||
data-facet-field="<%= facet.key %>" | ||
name="facet_suggest_<%= facet.key %>" | ||
placeholder="<%= I18n.t('blacklight.search.form.search.placeholder') %>"> | ||
</input> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module Search | ||
class FacetSuggestInput < Blacklight::Component | ||
def initialize(facet:, presenter:) | ||
@facet = facet | ||
@presenter = presenter | ||
end | ||
|
||
private | ||
|
||
attr_accessor :facet, :presenter | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Usage: | ||
// ``` | ||
// const basicFunction = (entry) => console.log(entry) | ||
// const debounced = debounce(basicFunction("I should only be called once")); | ||
// | ||
// debounced // does NOT print to the screen becase it is invoked again less than 200 milliseconds later | ||
// debounced // does print to the screen | ||
// ``` | ||
export default function debounce(func, timeout = 200) { | ||
let timer; | ||
return (...args) => { | ||
clearTimeout(timer); | ||
timer = setTimeout(() => { func.apply(this, args); }, timeout); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import debounce from "blacklight/debounce"; | ||
|
||
const FacetSuggest = async (e) => { | ||
if (e.target.matches('.facet-suggest')) { | ||
const queryFragment = e.target.value?.trim(); | ||
const facetField = e.target.dataset.facetField; | ||
if (!facetField) { return; } | ||
|
||
const urlToFetch = `/catalog/facet_suggest/${facetField}/${queryFragment}` | ||
const response = await fetch(urlToFetch); | ||
if (response.ok) { | ||
const blob = await response.blob() | ||
const text = await blob.text() | ||
|
||
const facetArea = document.querySelector('.facet-extended-list'); | ||
|
||
if (text && facetArea) { | ||
facetArea.innerHTML = text | ||
} | ||
} | ||
} | ||
}; | ||
|
||
document.addEventListener('input', debounce(FacetSuggest)); | ||
|
||
export default FacetSuggest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= render Blacklight::FacetComponent.new(display_facet: @display_facet, | ||
blacklight_config: blacklight_config, | ||
layout: false) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
spec/components/blacklight/search/facet_suggest_input_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Blacklight::Search::FacetSuggestInput, type: :component do | ||
let(:facet) { Blacklight::Configuration::FacetField.new key: 'language_facet' } | ||
let(:presenter) { instance_double(Blacklight::FacetFieldPresenter) } | ||
|
||
before do | ||
allow(presenter).to receive(:label).and_return 'Language' | ||
end | ||
|
||
it 'has an input with the facet-suggest class, which the javascript needs to find it' do | ||
rendered = render_inline(described_class.new(facet: facet, presenter: presenter)) | ||
expect(rendered.css("input.facet-suggest").count).to eq 1 | ||
end | ||
|
||
it 'has an input with the data-facet-field attribute, which the javascript needs to determine the correct query' do | ||
rendered = render_inline(described_class.new(facet: facet, presenter: presenter)) | ||
expect(rendered.css('input[data-facet-field="language_facet"]').count).to eq 1 | ||
end | ||
|
||
it 'has a visible label that is associated with the input' do | ||
rendered = render_inline(described_class.new(facet: facet, presenter: presenter)) | ||
label = rendered.css('label').first | ||
expect(label.text.strip).to eq 'Filter Language' | ||
|
||
id_in_label_for = label.attribute('for').text | ||
expect(id_in_label_for).to eq('facet-suggest-language_facet') | ||
|
||
expect(rendered.css('input').first.attribute('id').text).to eq id_in_label_for | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.