Add nice formatting for subtypes on account list #2138
Reference in New Issue
Block a user
Delete Branch "format-subtypes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
On the sidebar for accounts the subtype is currently shown with the
humanizeformatting. This doesn't work super well for some subtypes because it only capitalizes the first letter, and standard formatting for some subtypes are all caps (e.g. IRA).This PR introduces a new helper that:
titleizeto have title formatting (for cases like "Mutual Fund" instead of "Mutual fund")Before and after:

I agree with the formatting changes here, but I think we should try and keep these labels in one spot in the codebase. We're already defining them in each accountable class, such as for investment:
a7dfafc907/app/models/investment.rb (L4-L17)Long term, I think there's likely a better solution than this, but to leverage these existing definitions + labels, we can define a little helper in the accountable concern and define a singleton method within our "Account Group" struct:
Then over in
balance_sheet.rb, we'd just pass it in:Then the view simply becomes:
It's far from a perfect solution given we're mixing a little bit of model / view logic together, but I'd really like to keep the
value / labelpairs defined in a single spot for consistency and so when we make changes to the labels it only has to be changed once.@zachgoll I love this idea. I kind of started going down that path but wasn't really sure the best place to put that mapping. I made those changes! Appreciate the help 👍
The one note here is that some of them have changed a bit, like
HSAis nowHealth Savings Account. I don't think this is a bad thing - it now matches 1:1 to the dropdown menu where people can select a subtype. Maybe this is a bit overly verbose, but at least for now it's an improvement. Some day if there's a 'short name' or something we want to add it would be possible.@ahatzz11 it would be a slight bit more work, but I think it would be reasonable to define a short/long version of each:
There are likely a few views throughout the codebase we'd have to alter for select options, but I don't think too many:
Totally up to you. I'm good with how it is now too!
@zachgoll Since I started this I might as well keep it going!
I now have a short/long string for each type that has a subtype (for consistency across all subtypes), and to support the new label on the
/accountspage.For the dropdown menus when creating the subtype and the
/accountspage I use:long. For the balance sheet I use the:shortsince that sidebar is a bit shorter.Balance sheet sidebar looks the same as I previously implemented (although an improvement here is now properties/depository subtypes also get the same treatment!):

Here are some screenshots validating there aren't any regressions in the dropdown selectors:

And here's a view of the

/accountspage with the subtypes (I matched the styling from the balance sheet sidebar):Nice! Labels look good. Just added a few potential simplifications.
@@ -158,0 +163,4 @@# Get long version of the subtype labeldef long_subtype_labelaccountable_class.long_subtype_label_for(subtype) || accountable_class.display_nameendSmall nit, but
accountable_classshould automatically be available on each Account instance, so these could be simplified to:@@ -59,6 +59,7 @@ class BalanceSheetaccount.define_singleton_method(:weight) doIf I'm not mistaken, now that you've got both of these defined on
account.rbdirectly, we can remove these singleton overrides here and things will work fine in the sidebar.@@ -17,6 +17,9 @@</p>@zachgoll thanks for the comments! I changed those things and cursor also decided to add a little test case. Let me know what you think!
Looks great! Once tests pass I'll get it merged.
Whoops - cursor wasn't very good about where that field on the model was, I did look for a
bin/testbut didn't realize that was just viabin/rails, good to know!