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

Use type names directly from GenericObjectDefinition object #232

Merged

Conversation

mzazrivec
Copy link
Contributor

This change is to make sure API uses pretty (i.e. human readable) type names directly from the GenericObjectDefinition object, rather than from the locale/en.yml file.

This PR depends on ManageIQ/manageiq#16563

@mzazrivec
Copy link
Contributor Author

The core PR has been merged, this one is ready for review.

@@ -104,8 +104,8 @@ def self.allowed_association_types
end

def self.allowed_types
GenericObjectDefinition::TYPE_MAP.keys.collect do |type|
[Dictionary.gettext(type.to_s, :type => :data_type, :notfound => :titleize, :plural => false), type.to_s]
GenericObjectDefinition::TYPE_NAMES.each.collect do |key, value|
Copy link
Contributor

Choose a reason for hiding this comment

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

Does GenericObjectDefinition::TYPE_NAMES.stringify_keys.invert.to_a.sort suffice here?

Was this constant extracted for this use only? These transformations seem to suggest that its data structure is a poor fit 😉

Copy link
Contributor Author

@mzazrivec mzazrivec Dec 4, 2017

Choose a reason for hiding this comment

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

Yes, right now this is the only place where GenericObjectDefinition::TYPE_NAMES is being used.

What you're suggesting definitely looks better.

@mzazrivec mzazrivec force-pushed the use_type_names_from_god_object branch from 0589af8 to 050d107 Compare December 4, 2017 19:32
@miq-bot
Copy link
Member

miq-bot commented Dec 4, 2017

Checked commit mzazrivec@050d107 with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. ⭐

Copy link
Contributor

@imtayadeway imtayadeway left a comment

Choose a reason for hiding this comment

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

This LGTM. Perhaps we can look into making this constant something more like:

TYPE_NAMES = [
    [N_('Boolean'), "boolean"],
    [N_('Date/Time'), "datetime"],
    [N_('Float'), "float"],
    [N_('Integer'), "integer"],
    [N_('String'), "string"],
    [N_('Time'), "time"]
  ].freeze

in the future, which would simplify this to:

GenericObjectDefinition::TYPE_NAMES.sort

@abellotti abellotti added this to the Sprint 75 Ending Dec 11, 2017 milestone Dec 5, 2017
@abellotti
Copy link
Member

LGTM!! Thanks @mzazrivec for the enhancement.

@abellotti abellotti merged commit 2b07344 into ManageIQ:master Dec 5, 2017
@abellotti abellotti self-assigned this Dec 5, 2017
@mzazrivec
Copy link
Contributor Author

@imtayadeway Actually, I'd rather keep the model structures as they are. I think the hash used there is just fine. Yes, in the API there's this data transformation being done, which is not exactly pretty.

But if you look at the UI end consuming this data, the author of the code, for reasons I don't quite comprehend, decided to do the same transformation backwards: invert the fields + back to hash.

So I think the true fix is to avoid this data transformation back and forth, just send the hash over API, consume the same hash on the javascript end and that's the end of it. I'd like to do that in separate PRs though.

@mzazrivec mzazrivec deleted the use_type_names_from_god_object branch December 6, 2017 10:26
@mzazrivec
Copy link
Contributor Author

@imtayadeway #238

@AparnaKarve
Copy link
Contributor

the author of the code, for reasons I don't quite comprehend, decided to do the same transformation backwards: invert the fields + back to hash.

Could it be that the author of the code initially intended to have an array across the board (API + UI), and later had to change it to a hash in the UI due to some reason?

@mzazrivec
Copy link
Contributor Author

@AparnaKarve Are you telling it as a matter of fact, or are you just guessing?

@AparnaKarve
Copy link
Contributor

@mzazrivec I was alluding to the fact that I could have answered whatever questions you had and you didn't have to speculate what the author of the code was trying to do.

In retrospect, and after a second look at the JS code, I think the hash conversion PR #238 wasn't really necessary - a few adjustments in the JS was what was required.

Hashes/Arrays - they both are fine, so I think we are good.

@mzazrivec
Copy link
Contributor Author

I wasn't really speculating. I simply stated that I don't understand the reasons for doing things this way.

You're welcome to explain your point on #238 in that PR.

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

Successfully merging this pull request may close these issues.

5 participants