Skip to content

Commit

Permalink
Merge pull request #193 from projectblacklight/missing
Browse files Browse the repository at this point in the history
Pass missing values through the overridden FilterField
  • Loading branch information
corylown authored Jul 6, 2022
2 parents 6780089 + 9944291 commit cbeb970
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 2 additions & 3 deletions app/presenters/blacklight_range_limit/filter_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,16 @@ def remove(item)
def values(except: [])
params = search_state.params
param_key = filters_key
return [] unless params.dig(param_key, config.key)

range = if params.dig(param_key, config.key).is_a? Range
params.dig(param_key, config.key)
else
elsif params.dig(param_key, config.key).is_a? Hash
begins = Array(params.dig(param_key, config.key, :begin)).map(&:presence)
ends = Array(params.dig(param_key, config.key, :end)).map(&:presence)
begins.zip(ends).map { |b_bound, e_bound| Range.new(b_bound&.to_i, e_bound&.to_i) if b_bound && e_bound }.compact
end

f = except.include?(:filters) ? [] : Array(range)

f_missing = [] if except.include?(:missing)
f_missing ||= [Blacklight::SearchState::FilterField::MISSING] if params.dig(filters_key, "-#{key}")&.any? { |v| v == Blacklight::Engine.config.blacklight.facet_missing_param }

Expand Down
13 changes: 12 additions & 1 deletion spec/presenters/filter_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
end
end

context 'with missing data' do
context 'with empty data' do
let(:param_values) { { range: { some_field: { begin: '', end: '' } } } }

describe '#values' do
Expand All @@ -67,6 +67,17 @@
end
end

context 'with missing data' do
let(:param_values) { { range: { '-some_field': ['[* TO *]']} } }

describe '#values' do
it 'uses the missing special value' do
expect(filter.values).to eq [Blacklight::SearchState::FilterField::MISSING]
end
end
end


context 'with array-mangled data' do
let(:param_values) { { range: { some_field: { begin: { '0' => '2013' }, end: { '0' => '2022' } } } } }

Expand Down

0 comments on commit cbeb970

Please sign in to comment.