-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
chore: Migrate the AddressComponent to using ViewComponent #2638
Changes from all commits
b6853b0
dca4951
9b10173
184f9b8
0628f6d
9a530b1
f3b5f50
84cdf5d
2f0e74e
9cfc8e9
12a8cd1
808d460
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,4 +131,4 @@ Lint/SelfAssignment: | |
Enabled: false | ||
Lint/RedundantCopDisableDirective: | ||
Enabled: false | ||
|
||
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<p class="place_info__address" property="address" typeof="PostalAddress"> | ||
<%= formatted_address %> | ||
<%= sanitize formatted_address %> | ||
</p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddressComponent < ViewComponent::Base | ||
def initialize(address:, raw_location: nil) | ||
lenikadali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
super | ||
@address = address | ||
@raw_location = raw_location | ||
end | ||
|
||
def formatted_address | ||
if @address.present? | ||
address_lines = @address.all_address_lines.map(&:strip) | ||
return address_lines.join(", #{tag.br}") | ||
end | ||
|
||
uri = URI.parse(@raw_location) | ||
"<a href='#{uri}'>#{uri.hostname}</a>" | ||
|
||
rescue URI::InvalidURIError | ||
@raw_location | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,9 +46,8 @@ | |
<% if @partner.has_service_areas? %> | ||
<p>We operate in <%= partner_service_area_text(@partner) %>.</p> | ||
<% end %> | ||
<%= render_component "address", | ||
address: @partner.address | ||
%> | ||
|
||
<%= render AddressComponent.new(address: @partner.address) %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lenikadali i found one more address just fyi! otherwise happy to merge if you are? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hahaha beat me to it 😄 Yes please merge 🙌 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh no theres an test fail now are you ok to fix the test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why that is. Locally it doesn't fail though. Let me see 🤞 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Realized I was mixing the integration and controller tests 😅 Can't figure out why it is failing right now. Will look at it tomorrow with a fresher head. |
||
|
||
<% unless @partner.accessibility_info_html.blank? %> | ||
<details id='accessibility-info'> | ||
|
@@ -97,9 +96,7 @@ | |
<div class="gi gi__1-2"> | ||
<h3 class="udl udl--fw allcaps h4">Address</h3> | ||
<div class="small"> | ||
<%= render_component "address", | ||
address: place.address | ||
%> | ||
<%= render AddressComponent.new(address: place.address) %> | ||
</div> | ||
<h3 class="udl udl--fw allcaps h4">Contact</h3> | ||
<div class="small"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
require 'view_component/test_case' | ||
|
||
class AddressComponentTest < ViewComponent::TestCase | ||
setup do | ||
# TODO: once we can make the event factory use a local calendar | ||
# instead of one that makes outgoing HTTP calls, switch to using | ||
# the event factory here. Or remove this TODO once | ||
# we have an integration test | ||
@address = create(:address) | ||
@raw_location = 'Unformatted Address, Ungeolocated Lane, Manchester' | ||
end | ||
|
||
def test_component_renders_address | ||
render_inline(AddressComponent.new(address: @address, raw_location: @raw_location)) | ||
assert_text '123 Moss Ln E, Manchester, Manchester, M15 5DD' | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cant work out how to get rid of this but i think more faff than its worth to remove from the commit now lol