Skip to content

Replace story author dropdown with a search box#1553

Draft
maebeale wants to merge 1 commit into
mainfrom
maebeale/story-author-search
Draft

Replace story author dropdown with a search box#1553
maebeale wants to merge 1 commit into
mainfrom
maebeale/story-author-search

Conversation

@maebeale
Copy link
Copy Markdown
Collaborator

@maebeale maebeale commented Jun 5, 2026

Closes #1516

What is the goal of this PR and why is this important?

  • The story author field rendered a <select> containing every accessible user as an <option>
  • As the facilitator/user list grows this dropdown becomes unwieldy to scan and bloats the HTML on every story new/edit page
  • Replaces it with a type-to-search input so an author can be found quickly

How did you approach the change?

  • Reused the existing remote-select Stimulus controller (TomSelect) that already powers the workshop and organization fields on this same form
  • The author created_by_id field now loads matches on demand from the existing User remote-search endpoint (/search/user) instead of pre-rendering all users
  • For a persisted story, the currently-selected author is seeded as the single initial option (same pattern as workshop/organization) so the existing value displays
  • Removed the now-unused @users query from StoriesController#set_form_variables — it previously loaded and ordered every accessible user just to populate the dropdown
  • No backend/authorization changes needed: User already implements remote_search/remote_search_label, SearchController already whitelists user, and story new/edit/create are admin-only (matching the search endpoint's admin? rule)

UI Testing Checklist

  • On a new story, the "Story author" field shows a "Type to search authors…" search box; typing returns matching users
  • On an existing story, the current author is pre-selected/displayed and can be changed via search
  • Saving a story persists the selected author (created_by_id)

Anything else to add?

  • Existing story form view specs (spec/views/stories/new and edit) still pass — the server-rendered element remains a <select> (TomSelect enhances it client-side)
  • The sibling "spotlighted facilitator" field still uses a full dropdown; out of scope for this issue but a candidate for the same treatment in a follow-up

The author dropdown rendered every accessible user as a <select> option,
which grows unwieldy as the facilitator list expands and bloats every
story new/edit page. Reuse the existing remote-select typeahead (already
used for workshops and organizations) so authors can be found by typing,
loading matches on demand via the User remote-search endpoint instead of
preloading all users into the form.

Fixes #1516

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 5, 2026 00:46
collection: @users.map { |u| [ u.full_name_with_email, u.id ] },
prompt: "Select an author",
collection: f.object.created_by.present? ? [[ f.object.created_by.remote_search_label[:label], f.object.created_by.id ]] : [],
selected: f.object.created_by_id,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Seeds only the currently-selected author as the initial <option> (same pattern as the workshop/organization fields above). The full result set is fetched on demand from /search/user as the user types, so the form no longer renders every user.

@@ -131,7 +131,6 @@ def set_form_variables
.references(:users)
.order(:created_at)
@people = Person.order(Arel.sql("LOWER(first_name), LOWER(last_name)"))
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed the @users query that loaded and ordered every accessible user purely to populate the author dropdown. The remote-select field now fetches matches on demand, so this preload is no longer needed (other views that use @users set it themselves).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Story form to avoid rendering a huge “author” <select> by switching it to the existing TomSelect-powered remote-select behavior, querying authors on demand via the existing /search/user endpoint. This keeps the story new/edit pages responsive as the user list grows and removes an unnecessary controller query.

Changes:

  • Replace the story created_by_id dropdown collection with an initially-seeded, remote-search-enabled select (TomSelect via remote-select Stimulus).
  • Seed the current author as the only initial option for persisted stories so the existing value displays immediately.
  • Remove the now-unused @users preload query from StoriesController#set_form_variables.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
app/views/stories/_form.html.erb Switches “Story author” to a remote-select (TomSelect) field with on-demand search and initial seeding for persisted records.
app/controllers/stories_controller.rb Removes the full-user-list query previously used only to populate the author dropdown.

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.

New story: replace story author dropdown with a search box

2 participants