-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
4241 change agency type to enum #4931
base: main
Are you sure you want to change the base?
4241 change agency type to enum #4931
Conversation
Just a note about
Honestly? We can just delete that migration from the codebase. It's already run on production and staging, and people's local databases shouldn't be affected. |
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.
Overall looks good! Some requests/comments.
app/models/partners/profile.rb
Outdated
@@ -95,6 +95,17 @@ class Profile < Base | |||
accepts_nested_attributes_for :served_areas, allow_destroy: true | |||
|
|||
has_many_attached :documents | |||
enum :agency_type, other: "OTHER", career: "CAREER", abuse: "ABUSE", bnb: "BNB", |
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.
Can this be reformatted so each value is on a single line?
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.
Made this change in the recent commits.
app/models/partner.rb
Outdated
@agency_info = { | ||
address: [profile.address1, profile.address2].select(&:present?).join(', '), | ||
city: profile.city, | ||
state: profile.state, | ||
zip_code: profile.zip_code, | ||
website: profile.website, | ||
agency_type: (profile.agency_type == AGENCY_TYPES["OTHER"]) ? "#{AGENCY_TYPES["OTHER"]}: #{profile.other_agency_type}" : profile.agency_type | ||
agency_type: (symbolic_agency_type == :other) ? "#{Partners::Profile.agency_types[:other]}: #{profile.other_agency_type}" : profile.agency_type |
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.
I'm assuming the values here are for display? Then I'd suggest
agency_type: (symbolic_agency_type == :other) ? "Other: #{profile.other_agency_type}" : profile.agency_type
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.
Actually - would we want to do i18n.translate
for these values? As far as I can tell this is only used in the CSV export, so we should have readable strings here.
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.
I had originally left profile.agency_type
because @cielf had a recollection that the type codes were used in the CSV and some of the full descriptive strings seemed quite long for a CSV column..
Below are some screenshots of the CSV under different conditions. Which looks best?
<%= profile_form.input :agency_type, | ||
# Symbolize keys, because simple_form will only do a I18n lookup for | ||
# symbols | ||
collection: Partners::Profile.agency_types.symbolize_keys.keys, |
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.
Probably a bit more performant to do Partners::Profile.agency_types.keys.map(&:symbolize)
, but I may be nitpicking here.
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.
Made this change in the recent commits. For my own edification, why was my implementation less performant?
profiles = Partners::Profile.all() | ||
profiles.each do |profile| |
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.
profiles = Partners::Profile.all() | |
profiles.each do |profile| | |
Partners::Profile.all.each do |profile| |
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.
Made this change in the recent commits.
puts profile.id | ||
puts current_agency_type |
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.
Please remove these puts
statements.
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.
Made this change in the recent commits.
current_agency_type = profile.read_attribute_before_type_cast(:agency_type) | ||
puts profile.id | ||
puts current_agency_type | ||
if !current_agency_type.nil? |
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.
if !current_agency_type.nil? | |
if current_agency_type.present? |
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.
Made this change in the recent commits.
if !current_agency_type.nil? | ||
# If a profile has a descriptive string (ignoring case) as an agency type | ||
# update it to the associated value code. | ||
if( string_to_value_mapping.key?( current_agency_type.downcase ) ) |
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.
if( string_to_value_mapping.key?( current_agency_type.downcase ) ) | |
if string_to_value_mapping.key?(current_agency_type.downcase) |
(similarly below - not sure why lint didn't pick this up)
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.
Hmm, for some reason the linter missed this file entirely. It only made corrections when I specified this file explicitly. Regardless, ran this through the inter in the recent commits.
spec/models/partner_spec.rb
Outdated
@@ -294,7 +294,7 @@ | |||
let(:agency_state) { "ND" } | |||
let(:agency_zipcode) { "09980-7010" } | |||
let(:agency_website) { "bosco.example" } | |||
let(:agency_type) { Partner::AGENCY_TYPES["OTHER"] } | |||
let(:agency_type) { Partners::Profile.agency_types[:other] } |
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.
let(:agency_type) { Partners::Profile.agency_types[:other] } | |
let(:agency_type) { :other } |
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.
Made this change, and also fixed the test improperly expecting the enum value (OTHER
). Might need to update this again depending on what we choose for the CSV export.
We'll need me to do some light manual testing when those are all addressed, methinks. |
…handled by 20241122201255_cleanup_partner_agency_types
Alright, in the most recent commits I removed |
Alright, a bunch of checks are failing post merge. Working on resolving them. |
Alright, resolved the issues that were causing checks to fail. Now just waiting on @cielf and/or @dorner to make a decisions regarding how we want to style the agency types when exported to csv. After that, I can do another round of manual testing. |
Sorry I missed that-- this should be as seamless a change as possible for the users, so keep putting out the full text, please. |
Resolves #4241
Description
This PR modifies the attribute
Partners::Profile.agency_type
to be a Rails enum that stores a code-string in the database. Thepartners_profile.en.yml
localization file was also created so I18n may be used to convert from the code-string to a full, descriptive string. These translations were added to existing views.The existing map of code-strings to descriptive strings,
Partners::AGENCY_TYPES
, was left as is because it is a dependency of the migration20241122201255_cleanup_partner_agency_types.rb
and removing it would necessitate modifying this old migration, which would cause even worse problems. A warning comment was added to steer people away from usingAGENCY_TYPES
in the future and other parts of the code which referencedAGENCY_TYPES
where updated to reference the new enum.Lastly, a migration was created to convert existing values of
agency_type
to the specific values of the enum in cases where the existing value directly maps to one of the enum's values.Type of change
How Has This Been Tested?
Existing tests which referenced
agency_type
were updated to refer to the enum. No new tests were added.I manually verified the translations worked in the pages for viewing and updating a partner's profile.