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

Override where clause functions and added helpers dir #178

Conversation

Oferlis
Copy link

@Oferlis Oferlis commented Sep 12, 2022

In order to filter events by the selected storage system, overriding the where_clause functions was needed.
Since both models share most of the query structuring code, I added a new 'helpers' directory and a helper function that both models use.

This PR is related to another in UI repo:
ManageIQ/manageiq-ui-classic#8424

Other helpers should be added to this directory

@Fryguy
Copy link
Member

Fryguy commented Sep 12, 2022

Not sure why the bot is not triggering here, but the use of and should be && instead.

@@ -0,0 +1,14 @@
module ManipulationHelper
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this should be a top-level helper, because then it's global to the whole app...it should probably namespaced to the plugin.

if storage_systems.instance_of? Array and storage_systems.length >=1
rec_cond = ""
storage_systems.each do |i|
rec_cond = rec_cond + "#{events_table_name(assoc)}.physical_storage_id = #{i}"
Copy link
Member

Choose a reason for hiding this comment

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

Prefer << over + (same below)

@Fryguy
Copy link
Member

Fryguy commented Sep 12, 2022

Please address the rubocop issues found by the bot.

@@ -0,0 +1,14 @@
module ManipulationHelper
def manipulate_storage_systems(assoc, storage_systems = nil)
if storage_systems.instance_of?(Array) && storage_systems.length >= 1
Copy link
Member

@Fryguy Fryguy Sep 13, 2022

Choose a reason for hiding this comment

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

What is the storage_systems.instance_of?(Array) check actually checking for? Are you really just checking for nil?

Copy link
Author

Choose a reason for hiding this comment

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

The purpose is to make sure storage_systems is an instance of Array so length property won't cause an error

Copy link
Member

Choose a reason for hiding this comment

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

Right, but there are other ways of doing that like checking respond_to?(:length). But what are you seeing coming in aside from the nil? or is it only the nil?

@@ -114,6 +114,14 @@ def count_resources(component = nil)
end
end

def event_where_clause(assoc = :ems_events, storage_systems = nil)
if storage_systems && storage_systems != ['']
Copy link
Member

Choose a reason for hiding this comment

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

What would cause [''] to be an incoming value? If you can prevent this from the calling side and accept an empty array instead, then this line can be simplified to the following since .present? handle both nil and []

   if storage_systems.present?

@miq-bot
Copy link
Member

miq-bot commented Sep 14, 2022

Checked commits Autosde/manageiq-providers-autosde@3732a27~...e5f95ee with ruby 2.6.10, rubocop 1.28.2, haml-lint 0.35.0, and yamllint
3 files checked, 1 offense detected

app/helpers/manipulation_helper.rb

@Fryguy Fryguy added the enhancement New feature or request label Sep 14, 2022
@miq-bot
Copy link
Member

miq-bot commented Feb 9, 2023

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

@miq-bot
Copy link
Member

miq-bot commented May 15, 2023

This pull request has been automatically closed because it has not been updated for at least 3 months.

Feel free to reopen this pull request if these changes are still valid.

Thank you for all your contributions! More information about the ManageIQ triage process can be found in the triage process documentation.

@Fryguy Fryguy removed the stale label Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request unmergeable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants