Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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).

@users = User.has_access.includes(:person).left_joins(:person).order(Arel.sql("people.first_name IS NULL, LOWER(people.first_name), LOWER(people.last_name), LOWER(users.email)"))
@windows_types = WindowsType.all
@workshops = authorized_scope(Workshop.all).includes(:windows_type).order(:title)
@categories_grouped =
Expand Down
16 changes: 10 additions & 6 deletions app/views/stories/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,22 @@
<div class="flex flex-col md:flex-row md:space-x-4">
<div class="flex-1 mb-4 md:mb-0">
<%= f.input :created_by_id,
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.

include_blank: true,
label: (f.object.created_by&.person ? (
link_to "Story author",
person_path(f.object.created_by.person),
class: "hover:underline") : "Story author").html_safe,
label_html: { class: "block font-medium mb-1 text-gray-700" },
input_html: {
class: select_caret_class(blank: f.object.created_by_id.blank?),
style: custom_caret_style,
onchange: select_caret_onchange
} %>
class: "w-full px-3 py-2 border border-gray-300 rounded-lg",
data: {
controller: "remote-select",
remote_select_model_value: "user"
}
},
prompt: "Type to search authors…" %>
</div>

<div class="flex-1 mb-4 md:mb-0">
Expand Down