Skip to content

Replace Chosen.js with TomSelect for member lookup#2562

Merged
mroderick merged 3 commits intocodebar:masterfrom
mroderick:feature/tom-select-member-search
Apr 11, 2026
Merged

Replace Chosen.js with TomSelect for member lookup#2562
mroderick merged 3 commits intocodebar:masterfrom
mroderick:feature/tom-select-member-search

Conversation

@mroderick
Copy link
Copy Markdown
Collaborator

@mroderick mroderick commented Apr 11, 2026

Why

The member lookup on /admin/members currently loads all members into a dropdown using Chosen.js. This approach has two problems:

  1. Chosen.js is unmaintained - The repository has been archived and hasn't received updates since 2017. It has known issues with modern browsers and accessibility.

  2. Scaling problem - The database has ~28,000 members. Loading all of them into a dropdown on every page load is slow and will only get worse as membership grows.

What

Replace Chosen.js with TomSelect for the member lookup field, using remote data loading:

  • TomSelect fetches members on-demand via a new /admin/members/search JSON endpoint
  • Minimum 3 characters before search triggers
  • 300ms debounce on requests
  • Searches both name and email fields
  • Results limited to 50 matches

Changes

Backend:

  • Add GET /admin/members/search JSON endpoint
  • Search by name or email with ILIKE query
  • Return id, name, surname, email, full_name

Frontend:

  • Load TomSelect from CDN (CSS + JS) only on /admin/members
  • Initialize TomSelect on #member_lookup_id
  • Exclude from Chosen.js initialization

How to Verify Locally

1. Make yourself an admin

Open a Rails console:

bundle exec rails console

Find your member record and add the admin role:

member = Member.find_by(email: "your-email@example.com")
member.add_role(:admin)

2. Start the server

bundle exec rails server

3. Test the member search

  1. Navigate to http://localhost:3000/admin/members
  2. The dropdown should show "Type to search members..." placeholder
  3. Type 2 characters - no search should trigger
  4. Type 3+ characters - search triggers with 300ms debounce
  5. Results show member name and email
  6. Select a member - "View Profile" link updates
  7. Click "View Profile" - navigates to member page

4. Run the tests

bundle exec rspec spec/controllers/admin/members_controller_spec.rb spec/features/admin/tom_select_member_lookup_spec.rb

All 8 tests should pass.

Suggested Searches (from local dev database)

Try these searches to verify the functionality:

Search Term Matches
Sal Salvador Tremblay (cory_okon@blick.example)
Salvador Salvador Tremblay (cory_okon@blick.example)
blick Salvador Tremblay (cory_okon@blick.example)
Emm Emmie Robel (wiley_simonis@smith-smith.example)
Emmie Emmie Robel (wiley_simonis@smith-smith.example)
Kenn Kennith Dietrich (leandro@bins.example)
Gon Gonzalo Orn (jana_homenick@treutel-wehner.test)
g@ All members with 'g' in their email

Note: Search requires 3+ characters to trigger. Results show both name and email in the dropdown.

Commits

Each commit is independently green (all tests pass):

  1. feat: add search route for admin members - Adds the route
  2. feat(admin): add member search endpoint - Controller tests + implementation
  3. feat: integrate TomSelect for member lookup - Frontend + feature tests

Copy link
Copy Markdown
Contributor

@KimberleyCook KimberleyCook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@mroderick mroderick force-pushed the feature/tom-select-member-search branch from 45154c0 to 9332651 Compare April 11, 2026 06:51
@mroderick
Copy link
Copy Markdown
Collaborator Author

Replacing with clean PR that only contains implementation commits.

@mroderick mroderick closed this Apr 11, 2026
- Add search action to Admin::MembersController
- Search by name or email with ILIKE query
- Return JSON with id, name, surname, email, full_name
- Limit results to 50
- Require minimum 3 characters for search
- Remove @members = Member.all from index (loaded dynamically)
- Add TomSelect to admin members index page (loaded from CDN)
- Search triggers after 3+ characters with 300ms debounce
- Display member name and email in dropdown options
- Update 'View Profile' link on member selection
- Initialize TomSelect before Chosen to avoid conflicts
- Exclude member_lookup_id from Chosen initialization
@mroderick mroderick reopened this Apr 11, 2026
@mroderick mroderick force-pushed the feature/tom-select-member-search branch from 9332651 to ea3e71f Compare April 11, 2026 06:55
@mroderick mroderick merged commit 10bf440 into codebar:master Apr 11, 2026
15 checks passed
@mroderick mroderick deleted the feature/tom-select-member-search branch April 11, 2026 08:28
mroderick added a commit to mroderick/codebar-planner that referenced this pull request Apr 11, 2026
- Replace Chosen.js dropdown with TomSelect for member lookup
- Load members dynamically via /admin/members/search endpoint
- Add select_from_tom_select helper for Capybara tests
- Update tests for remote data loading
- Exclude #meeting_invitations_member from Chosen.js initialization

Reuses /admin/members/search endpoint from PR codebar#2562.
Fixes performance issue loading 28k+ members on every page render.
mroderick added a commit to mroderick/codebar-planner that referenced this pull request Apr 11, 2026
- Add organisers field to TomSelect initialization with remove_button plugin
- Pre-populate existing organisers on edit form using options_for_select
- Add remove_from_tom_select test helper for multi-select interaction
- Update tests for TomSelect interaction (add/remove organisers)
- Exclude meeting_organisers from Chosen.js initialization

Reuses /admin/members/search endpoint from PR codebar#2562.
Fixes performance issue loading 28k+ members on every page load.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants