Skip to content

Commit

Permalink
Fix issue with bookmarked records not staying checked (#1465)
Browse files Browse the repository at this point in the history
* Fix issue with bookmarked records not staying checked
* Add test that checking/unchecking bookmarks succeeds.
lfarrell authored Dec 13, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e866e15 commit aebab31
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/components/arclight/bookmark_component.html.erb
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
}) do %>
<div class="checkbox toggle-bookmark">
<label class="toggle-bookmark" data-checkboxsubmit-target="label">
<input type="checkbox" class="toggle-bookmark" data-checkboxsubmit-target="checkbox">
<input type="checkbox" class="toggle-bookmark" data-checkboxsubmit-target="checkbox" <%= 'checked="checked"' if bookmarked? %>>
<span data-checkboxsubmit-target="span"><%= bookmarked? ? "#{blacklight_icon(:bookmark).html_safe}<span class=\"sr-only visually-hidden\">#{t('blacklight.search.bookmarks.present')}</span>".html_safe : "#{blacklight_icon(:bookmark).html_safe}<span class=\"sr-only visually-hidden\">#{t('blacklight.search.bookmarks.absent')}</span>".html_safe %></span>
</label>
</div>
11 changes: 11 additions & 0 deletions app/helpers/arclight_helper.rb
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
module ArclightHelper
include Arclight::EadFormatHelpers
include Arclight::FieldConfigHelpers
include Blacklight::DocumentHelperBehavior
include Blacklight::LayoutHelperBehavior

def repository_collections_path(repository)
@@ -91,6 +92,16 @@ def document_or_parent_icon(document)
end
end

##
# Override of BL core https://github.com/projectblacklight/blacklight/blob/v8.1.0/app/helpers/blacklight/document_helper_behavior.rb#L55
# Remove document_type check. It isn't a method on arclight documents
# Check if the document is in the user's bookmarks
# @param [Blacklight::Document] document
# @return [Boolean]
def bookmarked?(document)
current_bookmarks.any? { |x| x.document_id == document.id }
end

def current_context_document
@document
end
15 changes: 15 additions & 0 deletions spec/features/bookmarks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Bookmarks' do
it 'shows bookmarks as checkboxes', js: true do
visit solr_document_path('aoa271aspace_a951375d104030369a993ff943f61a77')
check 'Bookmark'
click_link 'Bookmarks'

visit solr_document_path('aoa271aspace_a951375d104030369a993ff943f61a77')
expect(page).to have_css('input[type="checkbox"][checked]')
uncheck 'In Bookmarks'
end
end

0 comments on commit aebab31

Please sign in to comment.