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

Update the configuration to use the component for bookmarks #2879

Merged
merged 1 commit into from
Dec 15, 2022
Merged
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
2 changes: 1 addition & 1 deletion app/components/blacklight/document/actions_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Blacklight
module Document
# Render a bookmark widget to bookmark / unbookmark a document
# Render a the set of actions for a document. One of the default actions is the bookmark control.
class ActionsComponent < Blacklight::Component
renders_many :actions, (lambda do |action:, component: nil, **kwargs|
component ||= action.component || Blacklight::Document::ActionComponent
Expand Down
5 changes: 3 additions & 2 deletions app/components/blacklight/document/bookmark_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
module Blacklight
module Document
# Render a bookmark widget to bookmark / unbookmark a document
class BookmarkComponent < Blacklight::Component
class BookmarkComponent < Blacklight::Document::ActionComponent
# @param [Blacklight::Document] document
# @param [Boolean] checked
# @param [Object] bookmark_path the rails route to use for bookmarks
def initialize(document:, checked: nil, bookmark_path: nil)
def initialize(document:, action: nil, checked: nil, bookmark_path: nil, **kwargs)
@document = document
@checked = checked
@bookmark_path = bookmark_path
super(document: document, action: action, **kwargs)
end

def bookmarked?
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_bookmark_control.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= render Blacklight::Document::BookmarkComponent.new(document: document) %>
<%= render Blacklight::Document::BookmarkComponent.new(document: document, action: document_action_config) %>
4 changes: 2 additions & 2 deletions lib/generators/blacklight/templates/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ class <%= controller_name.classify %>Controller < ApplicationController
# config.index.search_bar_component = MyApp::SearchBarComponent
# config.index.document_actions.delete(:bookmark)

config.add_results_document_tool(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?)
config.add_results_document_tool(:bookmark, component: Blacklight::Document::BookmarkComponent, if: :render_bookmarks_control?)

config.add_results_collection_tool(:sort_widget)
config.add_results_collection_tool(:per_page_widget)
config.add_results_collection_tool(:view_type_group)

config.add_show_tools_partial(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?)
config.add_show_tools_partial(:bookmark, component: Blacklight::Document::BookmarkComponent, if: :render_bookmarks_control?)
config.add_show_tools_partial(:email, callback: :email_action, validator: :validate_email_params)
config.add_show_tools_partial(:sms, if: :render_sms_action?, callback: :sms_action, validator: :validate_sms_params)
config.add_show_tools_partial(:citation)
Expand Down