-
-
Notifications
You must be signed in to change notification settings - Fork 204
Replace Chosen with native datalist for sponsor chapter filter #2820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mroderick
merged 5 commits into
master
from
feature/replace-chosen-sponsors-filter-clean
Aug 31, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1f718e2
feat(sponsors_search): lookup chapters by name for filtering
mroderick 26997e4
feat(components): add ChapterPickerComponent
mroderick 2bcb89f
feat(admin/sponsors): use ChapterPickerComponent for chapter filter
mroderick 3788be9
feat(admin/workshops): use ChapterPickerComponent for chapter selection
mroderick a40b8f7
Merge branch 'master' into feature/replace-chosen-sponsors-filter-clean
mroderick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,11 @@ | ||
| <%= text_field_tag @name, @selected, | ||
| list: datalist_id, | ||
| placeholder: @placeholder, | ||
| class: 'form-control', | ||
| autocomplete: 'off' %> | ||
|
|
||
| <%= tag.datalist id: datalist_id do %> | ||
| <% @chapters.each do |chapter| %> | ||
| <%= tag.option chapter.name, value: chapter.name %> | ||
| <% end %> | ||
| <% end %> |
This file contains hidden or 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 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class ChapterPickerComponent < ViewComponent::Base | ||
| def initialize(name:, chapters:, selected: nil, placeholder: 'Select a chapter') | ||
| super() | ||
| @name = name | ||
| @chapters = chapters | ||
| @selected = selected | ||
| @placeholder = placeholder | ||
| end | ||
|
|
||
| def datalist_id | ||
| "#{@name.parameterize}-options" | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,40 @@ | ||
| require 'rails_helper' | ||
| require 'view_component/test_helpers' | ||
|
|
||
| RSpec.describe ChapterPickerComponent do | ||
| include ViewComponent::TestHelpers | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: we should make it so that each spec/components/ test get these by dint of having derived RSpec Metadata about their "type". Or, check whether that's already true, and these helpers are already included. |
||
|
|
||
| let(:chapters) { Fabricate.times(3, :chapter) } | ||
|
|
||
| it 'renders a text input with datalist attributes' do | ||
| render_inline described_class.new(name: 'sponsors_search[chapter]', chapters: chapters, placeholder: 'Filter by chapter') | ||
|
|
||
| expect(page).to have_field('sponsors_search[chapter]') | ||
| input = page.find('input') | ||
| expect(input['placeholder']).to eq('Filter by chapter') | ||
| expect(input['autocomplete']).to eq('off') | ||
| expect(input['class']).to include('form-control') | ||
| end | ||
|
|
||
| it 'renders a datalist with chapter names' do | ||
| render_inline described_class.new(name: 'sponsors_search[chapter]', chapters: chapters) | ||
|
|
||
| expect(page).to have_css('datalist#sponsors_search-chapter-options') | ||
| chapters.each do |chapter| | ||
| expect(page).to have_css("option[value='#{chapter.name}']") | ||
| end | ||
| end | ||
|
|
||
| it 'sanitises bracket characters in the datalist id' do | ||
| render_inline described_class.new(name: 'workshop[chapter_id]', chapters: chapters) | ||
|
|
||
| expect(page).to have_css('datalist#workshop-chapter_id-options') | ||
| end | ||
|
|
||
| it 'pre-fills the input when selected value is provided' do | ||
| render_inline described_class.new(name: 'sponsors_search[chapter]', chapters: chapters, selected: 'London') | ||
|
|
||
| input = page.find('input') | ||
| expect(input['value']).to eq('London') | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: We should have an ApplicationComponent base class, I think, for an easier control point. It won't change anything right now, but it's neat to have prepared.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm new to using ViewComponents, so this might be a silly question. What would this ApplicationComponent give us?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like ApplicationController or ApplicationRecord, a single base class, where you can do shared things like "ah, always use this custom layout", to take an example from ApplicationController.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, let's install that thing whenever we need to.