fix(enum-utils): return nil if option name is blank #447
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
In #442 we added support for automatic enum translation for Rails built-in enums
Changes
This PR fixes an issue that would show the whole enum hash as the translation for an empty value when using
tag_column
ortag_row
. Thanks to @stadia for reporting this issue.The fix returns nil as the translation for a blank value. Returning nil instead of an empty string keeps the same behavior as before the translation changes, which uses activeadmin's default translation for unset value
Before translation changes
![image](https://user-images.githubusercontent.com/12057523/223147326-49121c12-ca01-4c6c-bcfe-c39a6aa9d983.png)
After translation changes, before fix
![image](https://user-images.githubusercontent.com/12057523/223147115-ebbff61c-9d98-43d4-8beb-4b7a8d491474.png)
After fix
![image](https://user-images.githubusercontent.com/12057523/223146884-f4806825-f05d-4efb-be8b-0f3922baf0f6.png)
I'm not adding this to the changelog, as it fixes something that is still unreleased.
I also added a test case for enum utils for when
translate_enum_option
is used with not nil value that is not present in enum, to account for all three cases.