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 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2566e16
Update agency_type to be an enum
Benjamin-Couey Jan 10, 2025
4e156a2
Created new I18n config file to translate agency_type codes to descri…
Benjamin-Couey Jan 16, 2025
b8a4d61
Applied translation of agency_type code to descriptive strings in views
Benjamin-Couey Jan 16, 2025
7c9d8a8
Applied translation of agency_type code in partner info report
Benjamin-Couey Jan 16, 2025
9521d48
Updated existing tests to refer to enum
Benjamin-Couey Jan 16, 2025
f840bb0
Updated Partner.agency_info to refer to new enum instead of AGENCY_TY…
Benjamin-Couey Jan 16, 2025
de2d69f
Removed unecessary brackets
Benjamin-Couey Jan 16, 2025
c5e260d
Added comment warning people away from using AGENCY_TYPES
Benjamin-Couey Jan 16, 2025
6c1625c
Created migration to update existing agency_type values to enum values
Benjamin-Couey Jan 17, 2025
c62835c
Changes made by linter
Benjamin-Couey Jan 17, 2025
93feb8f
Merge branch 'main' into 4241-change-agency-type-to-enum
Benjamin-Couey Jan 17, 2025
ec45472
Cleaned up formatting, removed puts statements, ran through linter
Benjamin-Couey Jan 18, 2025
21a8cd3
Reformatted :agency_type so each entry is on one line
Benjamin-Couey Jan 21, 2025
f32237d
Fixed test using and expecting enum values
Benjamin-Couey Jan 21, 2025
74073cb
Changed calculation of agency_type symbols to more performant impleme…
Benjamin-Couey Jan 21, 2025
a516804
Changes made by linter
Benjamin-Couey Jan 21, 2025
1f4bd43
Removed old cleanup of partner agency types and associated mapping fr…
Benjamin-Couey Jan 21, 2025
596e79c
Updated mapping in migration to handle agency_type values previously …
Benjamin-Couey Jan 21, 2025
2987a2a
Merge branch 'main' into 4241-change-agency-type-to-enum
Benjamin-Couey Jan 21, 2025
b5606af
Fixed using wrong function to symbolize strings
Benjamin-Couey Jan 22, 2025
2e5a0a1
Updated agency_info to translate agency_types for now
Benjamin-Couey Jan 22, 2025
9fc8950
Fixed views not comparing agency_type to enum keys
Benjamin-Couey Jan 23, 2025
723d43d
Merge branch 'main' into 4241-change-agency-type-to-enum
Benjamin-Couey Jan 23, 2025
761195b
Merge branch 'main' into 4241-change-agency-type-to-enum
Benjamin-Couey Jan 31, 2025
4ac097d
Added agency_types_for_selection function to provide sorted agency ty…
Benjamin-Couey Feb 3, 2025
01a9ebf
Merge branch 'main' into 4241-change-agency-type-to-enum
Benjamin-Couey Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 2 additions & 45 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,50 +71,6 @@ class Partner < ApplicationRecord
where(status: status.to_sym)
}

AGENCY_TYPES = {
"CAREER" => "Career technical training",
"ABUSE" => "Child abuse resource center",
"BNB" => "Basic Needs Bank",
"CHURCH" => "Church outreach ministry",
"COLLEGE" => "College and Universities",
"CDC" => "Community development corporation",
"HEALTH" => "Community health program or clinic",
"OUTREACH" => "Community outreach services",
"LEGAL" => "Correctional Facilities / Jail / Prison / Legal System",
"CRISIS" => "Crisis/Disaster services",
"DISAB" => "Developmental disabilities program",
"DISTRICT" => "School District",
"DOMV" => "Domestic violence shelter",
"ECE" => "Early Childhood Education/Childcare",
"CHILD" => "Early childhood services",
"EDU" => "Education program",
"FAMILY" => "Family resource center",
"FOOD" => "Food bank/pantry",
"FOSTER" => "Foster Program",
"GOVT" => "Government Agency/Affiliate",
"HEADSTART" => "Head Start/Early Head Start",
"HOMEVISIT" => "Home visits",
"HOMELESS" => "Homeless resource center",
"HOSP" => "Hospital",
"INFPAN" => "Infant/Child Pantry/Closet",
"LIB" => "Library",
"MHEALTH" => "Mental Health",
"MILITARY" => "Military Bases/Veteran Services",
"POLICE" => "Police Station",
"PREG" => "Pregnancy resource center",
"PRESCH" => "Preschool",
"REF" => "Refugee resource center",
"ES" => "School - Elementary School",
"HS" => "School - High School",
"MS" => "School - Middle School",
"SENIOR" => "Senior Center",
"TRIBAL" => "Tribal/Native-Based Organization",
"TREAT" => "Treatment clinic",
"2YCOLLEGE" => "Two-Year College",
"WIC" => "Women, Infants and Children",
"OTHER" => "Other"
}.freeze

ALL_PARTIALS = %w[
media_information
agency_stability
Expand Down Expand Up @@ -241,13 +197,14 @@ def agency_info

return {} if profile.blank?

symbolic_agency_type = profile.agency_type&.to_sym
@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) ? "#{I18n.t symbolic_agency_type, scope: :partners_profile}: #{profile.other_agency_type}" : (I18n.t symbolic_agency_type, scope: :partners_profile)
}
end

Expand Down
48 changes: 48 additions & 0 deletions app/models/partners/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,49 @@ 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",
church: "CHURCH",
college: "COLLEGE",
cdc: "CDC",
health: "HEALTH",
outreach: "OUTREACH",
legal: "LEGAL",
crisis: "CRISIS",
disab: "DISAB",
district: "DISTRICT",
domv: "DOMV",
ece: "ECE",
child: "CHILD",
edu: "EDU",
family: "FAMILY",
food: "FOOD",
foster: "FOSTER",
govt: "GOVT",
headstart: "HEADSTART",
homevisit: "HOMEVISIT",
homeless: "HOMELESS",
hosp: "HOSP",
infpan: "INFPAN",
lib: "LIB",
mhealth: "MHEALTH",
military: "MILITARY",
police: "POLICE",
preg: "PREG",
presch: "PRESCH",
ref: "REF",
es: "ES",
hs: "HS",
ms: "MS",
senior: "SENIOR",
tribal: "TRIBAL",
treat: "TREAT",
twoycollege: "2YCOLLEGE",
wic: "WIC"

validate :check_social_media, on: :edit

validate :client_share_is_0_or_100
Expand Down Expand Up @@ -131,6 +174,11 @@ def county_list_by_region
counties.order(%w(lower(region) lower(name))).pluck(:name).join("; ")
end

def self.agency_types_for_selection
# alphabetize based on the translated version, as that is the text users will actually read
agency_types.keys.map(&:to_sym).sort_by { |sym| I18n.t(sym, scope: :partners_profile) }.partition { |v| v != :other }.flatten
end

private

def check_social_media
Expand Down
2 changes: 1 addition & 1 deletion app/services/reports/partner_info_report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def report

entries = { 'Number of Partner Agencies' => partner_agencies }
partner_agency_counts.each do |agency, count|
entries["Agency Type: #{agency || 'Unknown'}"] = count
entries["Agency Type: #{(I18n.t agency, scope: [:partners_profile]) || 'Unknown'}"] = count
end
entries['Zip Codes Served'] = partner_zipcodes_serviced
@report = { name: 'Partner Agencies and Service Area', entries: entries }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
</div>
<div class="card-body">
<%= form.input :name, label: "Agency Name", class: "form-control", wrapper: :input_group %>
<%= profile_form.input :agency_type, collection: Partner::AGENCY_TYPES.values, label: "Agency Type", class: "form-control", wrapper: :input_group %>
<%= profile_form.input :agency_type,
# Symbolize keys, because simple_form will only do a I18n lookup for
# symbols
collection: Partners::Profile.agency_types_for_selection,
label: "Agency Type",
class: "form-control",
wrapper: :input_group %>
<%= profile_form.input :other_agency_type, label: "Other Agency Type", class: "form-control", wrapper: :input_group %>

<%= render "shared/custom_file_input",
Expand Down
5 changes: 2 additions & 3 deletions app/views/partners/profiles/show/_agency_information.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
<dd><%= profile.partner.name %></dd>

<dt>Agency Type</dt>
<dd><%= profile.agency_type %></dd>

<% if profile.agency_type == "Other" %>
<dd><%= t profile.agency_type, scope: :partners_profile %></dd>
<% if profile.agency_type&.to_sym == :other %>
<dt>Other Agency Type</dt>
<dd><%= profile.other_agency_type %></dd>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

<%= f.fields_for :profile, profile do |pf| %>
<div class="form-group">
<%= pf.input :agency_type, collection: Partner::AGENCY_TYPES.values, label: "Agency Type", class: "form-control", wrapper: :input_group %>
<%= pf.input :agency_type,
# Symbolize keys, because simple_form will only do a I18n lookup for
# symbols
collection: Partners::Profile.agency_types_for_selection,
label: "Agency Type",
class: "form-control",
wrapper: :input_group %>
</div>

<div class="form-group">
Expand Down
4 changes: 2 additions & 2 deletions app/views/profiles/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<%# The field for inputting the name registers it as partner.name, %>
<%# not partner_profile.name, so this pulls from partner.name %>
<p>Name: <%= @partner.name %></p>
<p>Agency Type: <%= partner_profile.agency_type %>
<% if partner_profile.agency_type == "Other" && partner_profile.other_agency_type %>
<p>Agency Type: <%= t partner_profile.agency_type, scope: :partners_profile %>
<% if partner_profile.agency_type&.to_sym == :other && partner_profile.other_agency_type %>
(<%= partner_profile.other_agency_type %>)
<% end %>
</p>
Expand Down
52 changes: 52 additions & 0 deletions config/locales/partners_profile.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
agency_type_map: &agency_type_map
Copy link
Collaborator

Choose a reason for hiding this comment

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

Functional issue: "Other" is appearing at the top of the list of types when selecting. It should be at the bottom. Everything else should be in alphabetical order (by the full text) (though I note it isn't in staging --so the alpha thing could be a separate issue)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cielf alright this should be addressed in the most recent commit. Below is a screenshot demonstrating the new behavior.

Partner facing edit page with dropdown open

PartnerFacingEditPageDropdownAlphabetized

other: "Other"
career: "Career technical training"
abuse: "Child abuse resource center"
bnb: "Basic Needs Bank"
church: "Church outreach ministry"
college: "College and Universities"
cdc: "Community development corporation"
health: "Community health program or clinic"
outreach: "Community outreach services"
legal: "Correctional Facilities / Jail / Prison / Legal System"
crisis: "Crisis/Disaster services"
disab: "Developmental disabilities program"
district: "School District"
domv: "Domestic violence shelter"
ece: "Early Childhood Education/Childcare"
child: "Early childhood services"
edu: "Education program"
family: "Family resource center"
food: "Food bank/pantry"
foster: "Foster Program"
govt: "Government Agency/Affiliate"
headstart: "Head Start/Early Head Start"
homevisit: "Home visits"
homeless: "Homeless resource center"
hosp: "Hospital"
infpan: "Infant/Child Pantry/Closet"
lib: "Library"
mhealth: "Mental Health"
military: "Military Bases/Veteran Services"
police: "Police Station"
preg: "Pregnancy resource center"
presch: "Preschool"
ref: "Refugee resource center"
es: "School - Elementary School"
hs: "School - High School"
ms: "School - Middle School"
senior: "Senior Center"
tribal: "Tribal/Native-Based Organization"
treat: "Treatment clinic"
twoycollege: "Two-Year College"
wic: "Women, Infants and Children"

en:
partners_profile:
*agency_type_map

simple_form:
options:
profile:
agency_type:
*agency_type_map
109 changes: 0 additions & 109 deletions db/migrate/20241122201255_cleanup_partner_agency_types.rb

This file was deleted.

Loading