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

4241 change agency type to enum #4931

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

Benjamin-Couey
Copy link
Contributor

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. The partners_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 migration 20241122201255_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 using AGENCY_TYPES in the future and other parts of the code which referenced AGENCY_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

  • New feature (non-breaking change which adds functionality)

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.

@cielf cielf requested a review from dorner January 17, 2025 18:58
@dorner
Copy link
Collaborator

dorner commented Jan 17, 2025

Just a note about

The existing map of code-strings to descriptive strings, Partners::AGENCY_TYPES, was left as is because it is a dependency of the migration 20241122201255_cleanup_partner_agency_types.rb

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.

Copy link
Collaborator

@dorner dorner left a 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.

@@ -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",
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@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
Copy link
Collaborator

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

Copy link
Collaborator

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.

Copy link
Contributor Author

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?

CSV with full descriptive strings

PartnerCSVExportFullStrings

CSV with full descriptive strings (agency type column fully expanded)

PartnerCSVExportFullStringsWideColumn

CSV with untranslated type codes

PartnerCSVExportCodes

CSV with untranslated type codes, including `other_agency_type` for `:other`

PartnerCSVExportCodesOtherType

<%= 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,
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Comment on lines 53 to 54
profiles = Partners::Profile.all()
profiles.each do |profile|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
profiles = Partners::Profile.all()
profiles.each do |profile|
Partners::Profile.all.each do |profile|

Copy link
Contributor Author

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.

Comment on lines 58 to 59
puts profile.id
puts current_agency_type
Copy link
Collaborator

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.

Copy link
Contributor Author

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?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !current_agency_type.nil?
if current_agency_type.present?

Copy link
Contributor Author

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 ) )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Copy link
Contributor Author

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.

@@ -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] }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let(:agency_type) { Partners::Profile.agency_types[:other] }
let(:agency_type) { :other }

Copy link
Contributor Author

@Benjamin-Couey Benjamin-Couey Jan 21, 2025

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.

@cielf
Copy link
Collaborator

cielf commented Jan 18, 2025

We'll need me to do some light manual testing when those are all addressed, methinks.

@Benjamin-Couey
Copy link
Contributor Author

Just a note about

The existing map of code-strings to descriptive strings, Partners::AGENCY_TYPES, was left as is because it is a dependency of the migration 20241122201255_cleanup_partner_agency_types.rb

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.

Alright, in the most recent commits I removed 20241122201255_cleanup_partner_agency_types.rb and Partners::AGENCY_TYPES. I also copied the mappings from 20241122201255_cleanup_partner_agency_types.rb to the migration added by this PR to preserve the relations and just in case someone hadn't run the now deleted migration.

@Benjamin-Couey
Copy link
Contributor Author

Alright, a bunch of checks are failing post merge. Working on resolving them.

@Benjamin-Couey
Copy link
Contributor Author

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.

@cielf
Copy link
Collaborator

cielf commented Jan 22, 2025

Sorry I missed that-- this should be as seamless a change as possible for the users, so keep putting out the full text, please.

@Benjamin-Couey
Copy link
Contributor Author

Alright, finished the last round of manual testing. I checked the bank and partner facing view and edit pages, as well as the exported CSV and everything looked good.

Bank facing view page

BankFacingProfile

Partner facing view page

PartnerFacingProfile

Bank facing edit page

BankFacingEditPage

Partner facing edit page with dropdown open

PartnerFacingEditPageDropdown

Exported CSV

PartnerCSVExport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change agency_type to a Rails enum
3 participants