-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Anna Headley <hackartisan@users.noreply.github.com> Co-authored-by: Carolyn Cole <carolyncole@users.noreply.github.com> Co-authored-by: James R. Griffin III <jrgriffiniii@users.noreply.github.com> Co-authored-by: Trey Pendragon <tpendragon@users.noreply.github.com> Implementing the Orangelight::DropdownHelpTextComponent to support help text markup within the algorithm selection dropdown UI component Co-authored-by: Anna Headley <hackartisan@users.noreply.github.com> Co-authored-by: Eliot Jordan <eliotjordan@users.noreply.github.com>
- Loading branch information
1 parent
dedb0d0
commit 15554a8
Showing
9 changed files
with
93 additions
and
1 deletion.
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
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,5 @@ | ||
.dropdown-help-text { | ||
margin-left: 10px; | ||
font-size: 0.8em; | ||
font-style: italic; | ||
} |
21 changes: 21 additions & 0 deletions
21
app/components/orangelight/dropdown_help_text_component.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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class Orangelight::DropdownHelpTextComponent < Blacklight::System::DropdownComponent | ||
# options are { label:, value:, helptext: } hashes | ||
def option_text_and_value(option) | ||
[option[:label], option[:value]] | ||
end | ||
|
||
# Override to allow adding and styling a helptext for each option | ||
def before_render | ||
with_button(classes: 'btn btn-outline-secondary dropdown-toggle', label: button_label) unless button | ||
|
||
return if options.any? | ||
|
||
with_options(@choices.map do |option| | ||
text = "<div>#{option[:label]}</div><div id='#{option[:value]}' class='dropdown-help-text'>#{option[:helptext]}</div>".html_safe | ||
value = option[:value] | ||
{ text:, url: helpers.url_for(@search_state.params_for_search(@param => value)), selected: @selected == value } | ||
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
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,14 @@ | ||
<% if Flipflop.multi_algorithm? %> | ||
<%= render(Orangelight::DropdownHelpTextComponent.new( | ||
param: :search_algorithm, | ||
choices: [ | ||
{ label: "default", value: "default", helptext: "documents with highest term frequency are first"}, | ||
{ label: "engineering", value: "engineering", helptext: "move documents about engineering to the top" } | ||
], | ||
id: 'search-algorithm-dropdown', | ||
search_state: search_state, | ||
default: 'default', | ||
interpolation: :algorithm, | ||
selected: search_algorithm_value)) | ||
%> | ||
<% 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
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,39 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe 'Selecting search algorithms for results', type: :system, js: false do | ||
before do | ||
stub_holding_locations | ||
end | ||
|
||
context 'with the search algorithms feature enabled' do | ||
before do | ||
allow(Flipflop).to receive(:multi_algorithm?).and_return(true) | ||
end | ||
|
||
it 'renders a select widget used to select the ordering algorithm' do | ||
visit '/catalog?search_field=all_fields&q=roman' | ||
expect(page).to have_text('1. Огонек : роман') | ||
|
||
click_button('Rank by default') | ||
within('#engineering.dropdown-help-text') do | ||
expect(page).to have_text("move documents about engineering to the top") | ||
end | ||
click_link('engineering') | ||
expect(page).to have_button('Rank by engineering') | ||
expect(page).to have_text('1. Reconstructing the Vitruvian Scorpio: An Engineering Analysis') | ||
end | ||
end | ||
|
||
context 'with the search algorithms feature disabled' do | ||
before do | ||
allow(Flipflop).to receive(:multi_algorithm?).and_return(false) | ||
end | ||
|
||
it 'does not render a select widget' do | ||
visit '/catalog?search_field=all_fields&q=roman' | ||
expect(page).not_to have_button('Rank by default') | ||
end | ||
end | ||
end |