Skip to content

Commit

Permalink
Don't show chart or textual facets when only one facet bucket, not us…
Browse files Browse the repository at this point in the history
…eful
  • Loading branch information
jrochkind committed Nov 13, 2024
1 parent 1494534 commit abd2392
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/assets/javascripts/blacklight-range-limit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ export default class BlacklightRangeLimit {
// What we'll do to put the chart on page whether or not we need to load --
// when query has range limits, we don't need to load, it's already there.
let conditonallySetupChart = () => {
if (this.distributionElement.classList.contains("chart_js")) {
// No need to draw chart for only one or none buckets, not useful
if (this.distributionElement.classList.contains("chart_js") && this.rangeBuckets.length > 1) {
this.chartCanvasElement = this.setupDomForChart();
this.drawChart(this.chartCanvasElement);
}
Expand All @@ -122,8 +123,9 @@ export default class BlacklightRangeLimit {
console.error(error);
});
} else {
this.placeFacetValuesListElement(this.distributionElement.querySelector(".facet-values"));
this.extractBucketData();
const listElement = this.distributionElement.querySelector(".facet-values");
this.extractBucketData(listElement);
this.placeFacetValuesListElement(listElement);
conditonallySetupChart();
}
}
Expand Down Expand Up @@ -181,7 +183,8 @@ export default class BlacklightRangeLimit {

listElement.classList.add("mt-3");

if (! this.textualFacets) {
// No need to show if only 1 or none categories, not useful
if (!this.textualFacets || this.rangeBuckets.length <= 1) {
listElement.style["display"] = "none"
} else if (this.textualFacetsCollapsible) {
const detailsEl = this.container.ownerDocument.createElement("details");
Expand Down
22 changes: 22 additions & 0 deletions spec/features/run_through_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@
end
end

context "for single dates" do
it "does not show chart or facet list" do
visit search_catalog_path

click_button 'Publication Date Sort'
last_date = nil
within ".facet-limit.blacklight-pub_date_si" do
last_date = find("input#range_pub_date_si_begin").value

find("input#range_pub_date_si_begin").set(last_date)
find("input#range_pub_date_si_end").set(last_date)
click_button "Apply limit"
end

expect(page).to have_css(".applied-filter", text: /Publication Date Sort.*#{last_date}/)
within ".facet-limit.blacklight-pub_date_si" do
expect(page).not_to have_css 'canvas'
expect(page).not_to have_css 'details'
end
end
end

context 'when assumed boundaries configured' do
before do
CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = {
Expand Down

0 comments on commit abd2392

Please sign in to comment.