Skip to content
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

Scoped repository searching #1530

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 7 additions & 1 deletion app/components/arclight/search_bar_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
<label class="input-group-text" for="within_collection">
<%= t('arclight.within_collection_dropdown.label_html') %>
</label>
<%= select_tag ('f[collection][]' if collection_name.present?), within_collection_options, id: 'within_collection', class: 'form-select search-field rounded-end' %>
<% if collection_name.present? %>
<%= select_tag 'f[collection][]', within_collection_options, id: 'within_collection', class: 'form-select search-field rounded-end' %>
<% elsif repository_name.present? %>
<%= select_tag 'f[repository][]', within_collection_options, id: 'within_collection', class: 'form-select search-field rounded-end' %>
<% else %>
<%= select_tag ('f[collection][]' if collection_name.present?), within_collection_options, id: 'within_collection', class: 'form-select search-field rounded-end' %>
<% end %>
</div>
<% end %>

Expand Down
28 changes: 22 additions & 6 deletions app/components/arclight/search_bar_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ def initialize(**kwargs)
end

def within_collection_options
value = collection_name || 'none-selected'
all_collections_option = [t('arclight.within_collection_dropdown.all_collections'), '']
this_collection_option = [t('arclight.within_collection_dropdown.this_collection'), collection_name || 'none-selected']
this_repository_option = [t('arclight.within_collection_dropdown.this_repository'), repository_name].compact

options = [all_collections_option]
options << this_collection_option if collection_name.present?
options << this_repository_option if repository_name.present?

options_for_select(
[
[t('arclight.within_collection_dropdown.all_collections'), ''],
[t('arclight.within_collection_dropdown.this_collection'), value]
],
selected: collection_name,
options,
selected: selected_option(options),
disabled: 'none-selected'
)
end
Expand All @@ -28,5 +32,17 @@ def collection_name
@collection_name ||= Array(@params.dig(:f, :collection)).reject(&:empty?).first ||
helpers.current_context_document&.collection_name
end

def repository_name
if controller.controller_name == "repositories" && controller.action_name == "show"
@repository_name ||= Repository.find_by!(slug: params[:id]).name
else
@repository_name ||= Array(@params.dig(:f, :repository)).reject(&:empty?).first
end
end

def selected_option(options)
options.detect { |option| option.last.present? }&.last || ''
end
end
end
1 change: 1 addition & 0 deletions config/locales/arclight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ en:
all_collections: all collections
label_html: Search<span class="sr-only visually-hidden"> within</span>
this_collection: this collection
this_repository: this repository
blacklight:
entry_name:
grouped:
Expand Down
Loading