-
Notifications
You must be signed in to change notification settings - Fork 898
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
Correct field names for reports #14905
Conversation
lib/miq_expression/field.rb
Outdated
@@ -18,6 +18,12 @@ def self.parse(field) | |||
parsed_params[:virtual_custom_column]) | |||
end | |||
|
|||
def self.get_col_name(field) | |||
return field.split('.').last.tr('-', '.') unless is_field?(field) |
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 curious as to why this is needed - could you add a test to demonstrate?
lib/miq_expression/field.rb
Outdated
def self.get_col_name(field) | ||
return field.split('.').last.tr('-', '.') unless is_field?(field) | ||
parsed_field = parse(field) | ||
parsed_field.associations.push(parsed_field.column).join('.') |
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.
Using .push
here I think will corrupt the associations
data on the field object. That's OK here because the object is short-lived but might lead to some confusion if this changes....the non-destructive + [other]
might be better?
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.
Maybe we could add an instance method that encapsulates this presentation form of the field with a possibly better name than get_col_name
(which I know is not yours 😉). Something like to_human
could be consistent with other parts of MiqExpression (i.e. "this is the form that we want to present in the UI"), WDYT?
@@ -77,6 +77,16 @@ | |||
end | |||
end | |||
|
|||
describe '#parse_report_field' do | |||
it 'returns the correct format for a non field' do | |||
expect(MiqExpression::Field.parse_report_field('Vm.managed-environment')).to eq('managed.environment') |
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.
Ah! This is because it's a tag? I think you want MiqExpression.parse_field_or_tag
for that 😁
lib/miq_expression/tag.rb
Outdated
@@ -19,6 +19,7 @@ def self.parse(field) | |||
|
|||
def initialize(model, associations, column, managed = true) | |||
super(model, associations, column) | |||
@managed = managed | |||
@namespace = "/#{managed ? MANAGED_NAMESPACE : USER_NAMESPACE}/#{column}" |
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 think namespace
is not quite right - it includes more than the namespace. Could this be changed so that you're encapsulating this knowledge (which namespace to use)? namespace
is its public API though, so I don't know how far reaching this would be
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.
@imtayadeway hmm not sure what you mean. Do you mean taking the namespace and translating it into the report_column?
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.
Sorry 😊 - I'd expect that namespace
would return simply MANAGED_NAMESPACE
or USER_NAMESPACE
as the names suggest - currently it's doing way more than that which means you can't reuse namespace
in your method below, and you have to grab the managed
value to do the same logic with it again. I'd suggest we either:
a) Change #namespace
to return the unmodified namespace, and give the thing it's currently doing a new name, or
b) Give the unmodified namespace a name (base_namespace, or similar) that both namespace
and your new method can delegate to
Given the choice, I'd prefer a over b even though it may be more work ( 😀 ) because I think having a thing called namespace
and things called MANAGED_NAMESPACE
and USER_NAMESPACE
being different concepts sort of introduces some cognitive dissonance for me. It seems like there's a missing concept that hasn't been named!
lib/miq_expression/tag.rb
Outdated
@@ -19,11 +20,12 @@ def self.parse(field) | |||
|
|||
def initialize(model, associations, column, managed = true) | |||
super(model, associations, column) | |||
@namespace = "/#{managed ? MANAGED_NAMESPACE : USER_NAMESPACE}/#{column}" | |||
@namespace = managed ? MANAGED_NAMESPACE : USER_NAMESPACE | |||
@path = "/#{namespace}/#{column}" |
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.
@imtayadeway what would be the proper name here? I chose path but...am not really sure (naming problems 😩 )
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 think looking at your other comments (b) might be more appropriate here, at least for now?
lib/miq_expression/tag.rb
Outdated
end | ||
|
||
def contains(value) | ||
ids = model.find_tagged_with(:any => value, :ns => namespace).pluck(:id) | ||
ids = model.find_tagged_with(:any => value, :ns => path).pluck(: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.
@imtayadeway want to get your thoughts here...I agree with the name change of namespace
, but there are many references to namespace
and even just ns
that should be changed to make all of them align / the name change make sense. I think that is getting out of the scope of this issue. Should we leave them for now and refactor later to make all of the changes in a separate PR, or just do this namespace name change in its entirety in a separate PR?
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 think as this is a bug I would do the simplest thing to get it to 💚 , perhaps let's look at naming in a follow up PR? :D
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.
@imtayadeway agreed! thanks for the 👀
@@ -77,6 +77,10 @@ def arel_attribute | |||
target.arel_attribute(column) | |||
end | |||
|
|||
def report_column |
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.
Although I like this name way better, I'm just thinking that these are used in other parts of the UI than reporting - anywhere there is an expression builder. I wonder if there could be a more generic name for this. @gtanzillo do you have any ideas?
This pull request is not mergeable. Please rebase and repush. |
Checked commits jntullo/manageiq@5fd2d55~...49905e5 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
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.
👍 LGTM
@miq-bot add_label fine/yes, euwe/yes |
Correct field names for reports (cherry picked from commit 8db3935) https://bugzilla.redhat.com/show_bug.cgi?id=1460761
Fine backport details:
|
@jntullo There are conflicts backporting to Euwe in all 4 files... would you mind creating a separate PR for Euwe branch? |
Backported to Euwe via #15498 |
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1402547
When creating a report, the field names were not being stored properly in
col_options
because of how the UI was parsing the field. For example, the fieldVm.miq_provision.miq_request-requester_name
was being parsed asmiq_request.v_approved_by
instead of the correctmiq_provision.miq_request.v_approved_by
, causing the MiqExpression to never evaluate to true and therefore not styling the report correctly.This PR adds in an instance method to
MiqExpression::Field
&MiqExpression::Tag
that the UI can leverage (ManageIQ/manageiq-ui-classic#1170) to properly retrieve the column/field name.@miq_bot add_label bug, reporting
@miq_bot assign @gtanzillo
cc: @imtayadeway