Clean quick search [SCI-10246]

This commit is contained in:
Andrej 2024-04-16 13:52:53 +02:00
parent a2a3c0ab28
commit c253d0ffcf
2 changed files with 5 additions and 7 deletions

View file

@ -225,14 +225,12 @@ class SearchController < ApplicationController
def quick
results = if params[:filter].present?
object_quick_search(params[:filter].singularize,
search_by_id: Constants::QUICK_SEARCH_SEARCHABLE_BY_NAME
.exclude?(params[:filter].singularize))
object_quick_search(params[:filter].singularize)
else
Constants::QUICK_SEARCH_SEARCHABLE_OBJECTS.filter_map do |object|
next if object == 'label_template' && !LabelTemplate.enabled?
object_quick_search(object, search_by_id: Constants::QUICK_SEARCH_SEARCHABLE_BY_NAME.exclude?(object))
object_quick_search(object)
end.flatten.sort_by(&:updated_at).reverse.take(Constants::QUICK_SEARCH_LIMIT)
end
@ -241,8 +239,9 @@ class SearchController < ApplicationController
private
def object_quick_search(class_name, search_by_id: true)
search_method = class_name.to_s.camelize.constantize.method(search_by_id ? :search_by_name_and_id : :search_by_name)
def object_quick_search(class_name)
search_model = class_name.to_s.camelize.constantize
search_method = search_model.method(search_model.respond_to?(:code) ? :search_by_name_and_id : :search_by_name)
search_method.call(current_user,
current_team,

View file

@ -447,7 +447,6 @@ class Constants
QUICK_SEARCH_LIMIT = 5
QUICK_SEARCH_SEARCHABLE_OBJECTS = %w(project experiment my_module protocol repository_row
report project_folder result label_template).freeze
QUICK_SEARCH_SEARCHABLE_BY_NAME = %w(project_folder result label_template).freeze
# ) \ / (
# /|\ )\_/( /|\