-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract a DestinationSelectorComponent
- Loading branch information
Showing
13 changed files
with
105 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div data-scheduler-lookup-url='<%= paging_schedule_path(origin: form.object.paging_origin_library) %>'> | ||
<% if pickup_destinations.one? %> | ||
<div class='form-group'> | ||
<div class='<%= helpers.label_column_class %> control-label'> | ||
Will be delivered to | ||
</div> | ||
<div class='<%= helpers.content_column_class %> input-like-text'> | ||
<%= destination_label(pickup_destinations.first) %> | ||
</div> | ||
<%= form.hidden_field :destination, value: pickup_destinations.first %> | ||
</div> | ||
<% elsif pickup_destinations.many? %> | ||
<%= form.label :destination, 'Deliver to' %> | ||
<%= form.select :destination, | ||
pickup_destinations_array(pickup_destinations), | ||
{ | ||
selected: request.destination || request.default_pickup_destination | ||
}, | ||
aria: { controls: 'scheduler-text' }, | ||
data: { 'paging-schedule-updater' => 'true', 'text-selector' => "[data-text-object='#{request.object_id}']" } | ||
%> | ||
<% end %> | ||
<%= render 'requests/scheduler_text', f: form, current_request: form.object %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
# Draws the select a destionation widget | ||
class DestinationSelectorComponent < ViewComponent::Base | ||
def initialize(form:) | ||
@form = form | ||
end | ||
|
||
attr_reader :form | ||
|
||
def request | ||
form.object | ||
end | ||
|
||
delegate :pickup_destinations, to: :request | ||
|
||
# Get the label, if it exists, for the pickup destination | ||
def destination_label(pickup_destination) | ||
Settings.ils.pickup_destination_class.constantize.new(pickup_destination).display_label || pickup_destination | ||
end | ||
|
||
# Return the array of destinations for the dropdown | ||
def pickup_destinations_array(pickup_destinations) | ||
pickup_destinations.map do |k| | ||
[destination_label(k), k] | ||
end.sort | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<div class="alert alert-warning destination-note-callout"> | ||
<%= render partial: 'destination_selector', locals: { f: f } %> | ||
<%= render DestinationSelectorComponent.new(form: f) %> | ||
|
||
<%= render partial: 'needed_date', locals: { f: f } %> | ||
</div> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe DestinationSelectorComponent, type: :component do | ||
let(:component) { described_class.new(form:) } | ||
let(:rendered) { render_inline(component) } | ||
let(:form) { ActionView::Helpers::FormBuilder.new(nil, request, vc_test_controller.view_context, {}) } | ||
|
||
describe 'single library' do | ||
let(:request) { build(:request, origin: 'SAL3', origin_location: 'PAGE-EN', bib_data:) } | ||
let(:item) do | ||
build(:item, | ||
barcode: '3610512345678', | ||
callnumber: 'ABC 123', | ||
effective_location: build(:page_en_location)) | ||
end | ||
|
||
let(:bib_data) { double(:bib_data, title: 'Test title', request_holdings: [item]) } | ||
|
||
it 'returns library text and a hidden input w/ the destination library' do | ||
expect(rendered).to have_css('.form-group .control-label', text: 'Will be delivered to') | ||
expect(rendered).to have_css('.form-group .input-like-text', text: 'Engineering Library (Terman)') | ||
expect(rendered).to have_css('input[type="hidden"][value="ENG"]', visible: :hidden) | ||
end | ||
end | ||
|
||
describe 'multiple libraries' do | ||
let(:request) { create(:request, origin: 'SAL3', origin_location: 'PAGE-HP') } | ||
|
||
it 'creates a select list' do | ||
expect(rendered).to have_select 'Deliver to' | ||
end | ||
|
||
context 'with a destination' do | ||
let(:request) { create(:request, origin: 'SAL3', destination: 'ART', origin_location: 'PAGE-HP') } | ||
|
||
before do | ||
allow(request).to receive(:pickup_destinations).and_return(['GREEN', 'HOPKINS', 'ART']) | ||
end | ||
|
||
it 'defaults to the destination library' do | ||
expect(rendered).to have_select 'Deliver to', selected: 'Art & Architecture Library (Bowes)' | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters