Skip to content

Commit

Permalink
Merge pull request #280 from projectblacklight/no_chart_for_one_bucket
Browse files Browse the repository at this point in the history
Don't show chart or textual facets when only one facet bucket,
  • Loading branch information
seanaery authored Nov 14, 2024
2 parents 3550e22 + abd2392 commit 34b77e9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/assets/javascripts/blacklight-range-limit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,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")) {
this.extractBucketData();
// 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 @@ -117,13 +117,16 @@ export default class BlacklightRangeLimit {
then( response => response.ok ? response.text() : Promise.reject(response)).
then( responseBody => new DOMParser().parseFromString(responseBody, "text/html")).
then( responseDom => responseDom.querySelector(".facet-values")).
then( element => this.extractBucketData(element)).
then( element => this.placeFacetValuesListElement(element)).
then( _ => { conditonallySetupChart() }).
catch( error => {
console.error(error);
});
} else {
this.placeFacetValuesListElement(this.distributionElement.querySelector(".facet-values"));
const listElement = this.distributionElement.querySelector(".facet-values");
this.extractBucketData(listElement);
this.placeFacetValuesListElement(listElement);
conditonallySetupChart();
}
}
Expand Down Expand Up @@ -165,7 +168,7 @@ export default class BlacklightRangeLimit {
this.xTicks.push(this.rangeBuckets[this.rangeBuckets.length - 1].to + 1);
}

return undefined;
return facetListDom;
}

// Take HTML element with facet list values
Expand All @@ -181,7 +184,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 @@ -69,6 +69,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 34b77e9

Please sign in to comment.