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

Correct field names for reports #14905

Merged
merged 3 commits into from
Jun 6, 2017
Merged

Correct field names for reports #14905

merged 3 commits into from
Jun 6, 2017

Conversation

jntullo
Copy link

@jntullo jntullo commented Apr 26, 2017

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 field Vm.miq_provision.miq_request-requester_name was being parsed as miq_request.v_approved_by instead of the correct miq_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

@@ -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)
Copy link
Contributor

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?

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('.')
Copy link
Contributor

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?

Copy link
Contributor

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')
Copy link
Contributor

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 😁

@@ -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}"
Copy link
Contributor

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

Copy link
Author

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?

Copy link
Contributor

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!

@@ -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}"
Copy link
Author

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 😩 )

Copy link
Contributor

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?

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)
Copy link
Author

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?

Copy link
Contributor

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

Copy link
Author

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
Copy link
Contributor

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?

@miq-bot
Copy link
Member

miq-bot commented May 22, 2017

This pull request is not mergeable. Please rebase and repush.

@miq-bot
Copy link
Member

miq-bot commented May 22, 2017

Checked commits jntullo/manageiq@5fd2d55~...49905e5 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 0 offenses detected
Everything looks fine. 🏆

@chessbyte
Copy link
Member

@jntullo @gtanzillo @imtayadeway bump

Copy link
Member

@gtanzillo gtanzillo left a comment

Choose a reason for hiding this comment

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

👍 LGTM

@gtanzillo gtanzillo added this to the Sprint 62 Ending Jun 5, 2017 milestone Jun 6, 2017
@gtanzillo gtanzillo merged commit 8db3935 into ManageIQ:master Jun 6, 2017
@jntullo
Copy link
Author

jntullo commented Jun 7, 2017

@miq-bot add_label fine/yes, euwe/yes

simaishi pushed a commit that referenced this pull request Jun 12, 2017
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 623ae1f1897c43fb5a5162657c0d905d718b6491
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Mon Jun 5 23:03:00 2017 -0400

    Merge pull request #14905 from jntullo/bz/report_styles
    
    Correct field names for reports
    (cherry picked from commit 8db3935e68455a29943f89db1f40506b1e7269e9)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1460761

@simaishi
Copy link
Contributor

@jntullo There are conflicts backporting to Euwe in all 4 files... would you mind creating a separate PR for Euwe branch?

@simaishi
Copy link
Contributor

simaishi commented Jul 7, 2017

Backported to Euwe via #15498

@jntullo jntullo deleted the bz/report_styles branch November 28, 2017 19:42
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.

6 participants