-
Notifications
You must be signed in to change notification settings - Fork 897
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
Lookup a category_id if a tag control passes it in #16965
Lookup a category_id if a tag control passes it in #16965
Conversation
@miq-bot assign @eclarizio @miq-bot add_label bug, services, gaprindashvili/yes cc - @d-m-u @gmcculloug |
cd5afca
to
f2e35d8
Compare
app/models/dialog_field_importer.rb
Outdated
if category_name | ||
category_id = dialog_field_attributes["options"][:category_id] | ||
if category_id | ||
dialog_field.category = dialog_field_attributes["options"][:category_id] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stupid nit, but doesn't it also need to set the description in this case?
ada950f
to
41f9449
Compare
app/models/dialog_field_importer.rb
Outdated
if category_name | ||
category_id = dialog_field_attributes["options"][:category_id] | ||
if category_id | ||
dialog_field.category = category_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno if this needs the description as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eclarizio - Does it need the description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, assigning the id is all that is needed
app/models/dialog_field_importer.rb
Outdated
@@ -32,12 +32,15 @@ def import_field(dialog_field_attributes) | |||
|
|||
def set_category_for_tag_control(dialog_field, dialog_field_attributes) | |||
category_name = dialog_field_attributes["options"][:category_name] | |||
if category_name | |||
category_id = dialog_field_attributes["options"][:category_id] | |||
if category_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see how this would work in an edit scenario where you expect the tag category to already exist but doesn't this method also get used when importing dialogs between completely different environments?
The category ID may exist in the new environment but it could point to a completely different tag category. Also, this is just checking that the ID exists in the field data, but there is no check that the category exists when importing into a different environment.
cc @eclarizio
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmcculloug You're right
@syncrou What I think you will need to do is if the category id exists, look up the category and then compare the name/description. The only problem is that in the edit scenario, the name/description that is getting passed in is incorrect as we determined when we were debugging and was the whole source of this issue. I think the best solution in this case would be to modify the ui-components here https://github.com/ManageIQ/ui-components/blob/master/src/dialog-editor/components/modal-field-template/tag-control.html#L26 and add an ng-change
method that ends up setting the id, name, and description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eclarizio - Thanks! - I'll get those changes in.
app/models/dialog_field_importer.rb
Outdated
if category_name | ||
category_id = dialog_field_attributes["options"][:category_id] | ||
if category_id | ||
dialog_field.category = category_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, assigning the id is all that is needed
app/models/dialog_field_importer.rb
Outdated
@@ -32,12 +32,15 @@ def import_field(dialog_field_attributes) | |||
|
|||
def set_category_for_tag_control(dialog_field, dialog_field_attributes) | |||
category_name = dialog_field_attributes["options"][:category_name] | |||
if category_name | |||
category_id = dialog_field_attributes["options"][:category_id] | |||
if category_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmcculloug You're right
@syncrou What I think you will need to do is if the category id exists, look up the category and then compare the name/description. The only problem is that in the edit scenario, the name/description that is getting passed in is incorrect as we determined when we were debugging and was the whole source of this issue. I think the best solution in this case would be to modify the ui-components here https://github.com/ManageIQ/ui-components/blob/master/src/dialog-editor/components/modal-field-template/tag-control.html#L26 and add an ng-change
method that ends up setting the id, name, and description.
@miq-bot add_label blocker |
39ef21c
to
54daa52
Compare
Rubocop complaint is due to this code where |
app/models/dialog_field_importer.rb
Outdated
def adjust_category(opts) | ||
return nil if opts[:category_description].nil? | ||
description = opts[:category_description] | ||
real_category = if opts[:category_id] && description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about the import operation and where these values come from the two variables description
and real_category
are not all that intuitive.
What do you think about: import_description
and import_category
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like import_category
.
My thought on description
was to use that name instead of category_description
, to differentiate that we need a description
as our control element. Without a description there is no category to adjust for. Though, if that logic were to follow through, then category
should suffice as opposed to import_category
and the circle of discussion continues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed further with @syncrou and agree that category
(instead of real_category
) is a better variable name here.
54daa52
to
4b66fbe
Compare
@eclarizio Please review after changes were pushed. Update your approval status if you are good with the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this will need the corresponding ui-components repo change that passes in the category_id
, category_description
, and category_name
, otherwise it won't work because currently all that is passed in is the category_id
, so the new line:
return nil if opts[:category_description].nil?
will always be hit and the category won't update properly, I think.
app/models/dialog_field_importer.rb
Outdated
Category.find(opts[:category_id]) | ||
elsif opts[:category_name] && description | ||
Category.find_by_name(opts[:category_name]) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to do && description
for the if
and elsif
conditions? We're already short circuiting on line 38 and that is ensuring that we have a description
, right?
When editing a tag control for service dialogs, we were always looking up by the name coming in from the dialog. For a new record this sufficed, for an edit it caused edits to fail. This changes the order of lookups to first check the category_id if it comes in, and to fallback to the name if there is no category_id https://bugzilla.redhat.com/show_bug.cgi?id=1542590
4b66fbe
to
571572e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thanks @eclarizio, you've helped bring the cognitive complexity of that method to 5 or less! 🎉 |
Checked commit syncrou@571572e with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 app/models/dialog_field_importer.rb
|
…ntrol Lookup a category_id if a tag control passes it in (cherry picked from commit 3153645) https://bugzilla.redhat.com/show_bug.cgi?id=1544849
Gaprindashvili backport details:
|
When editing a tag control for service dialogs, we were always looking up by the name
coming in from the dialog. For a new record this sufficed, for an edit it caused edits to fail.
This changes the order of lookups to first check the category_id if it comes in,
and to fallback to the name if there is no category_id
https://bugzilla.redhat.com/show_bug.cgi?id=1542590