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

Refactor toolbar builder #12025

Merged

Conversation

romanblanco
Copy link
Member

@romanblanco romanblanco commented Oct 18, 2016

We need to chane control flow, so we don't need to evaluate procs of toolbars for buttons that are going to be skipped, and avoid situations like this

/cc @PanSpagetka @martinpovolny @jzigmund @vecerek

@romanblanco romanblanco force-pushed the toolbar_builder_refactoring branch 5 times, most recently from a0b8a9f to f70406b Compare October 19, 2016 14:25
@romanblanco romanblanco force-pushed the toolbar_builder_refactoring branch 4 times, most recently from eeffc44 to 5bed11a Compare October 25, 2016 16:55
@romanblanco romanblanco force-pushed the toolbar_builder_refactoring branch 3 times, most recently from fb15c81 to 3b919e6 Compare October 31, 2016 14:15
@romanblanco romanblanco changed the title [WIP] Refactor toolbar builder Refactor toolbar builder Oct 31, 2016
@miq-bot miq-bot removed the wip label Oct 31, 2016
A lot of methods still has prefix  from time, when these methods were in application controller. In this commit I'm changing method names to be more specific and also trying to provide at least basic description of what does the methods do
Don't call methods for setting buttons properties in '#skipped?' method,
where we check if the button should be rendered.
Call '#skipped?' method that determines if the buttons should be rendered earlier in the code
@@ -58,8 +58,7 @@ def all_instance_variables_set
def skipped?
return true unless role_allows_feature?
return true unless all_instance_variables_set
calculate_properties
!visible?
return !visible?
Copy link
Member

Choose a reason for hiding this comment

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

extra return

nil
else
apply_common_props(button, inputs)
end
Copy link
Member

@martinpovolny martinpovolny Nov 1, 2016

Choose a reason for hiding this comment

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

button.skipped? ? nil : apply_common_props(button, inputs)

or early return:

return nil if button.skipped?
apply_common_props(button, inputs)

any of the 2 is more readable than the above imho

Copy link
Member Author

Choose a reason for hiding this comment

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

@martinpovolny updated, thanks!

@martinpovolny
Copy link
Member

Looks good.

My only concern:

are you sure that none of the visible? implementation relies on calculate_properties already having been run?

@martinpovolny
Copy link
Member

@PanSpagetka @jzigmund @vecerek: can you check the visible? methods?

@romanblanco
Copy link
Member Author

romanblanco commented Nov 1, 2016

@martinpovolny I've checked all current visible? methods (grep -rI 'visible?' -A 10), and don't see any situation, where this problem could occure. @PanSpagetka, @vecerek, how about you?

@miq-bot
Copy link
Member

miq-bot commented Nov 1, 2016

Checked commits romanblanco/manageiq@db53fee~...410399c with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
3 files checked, 23 offenses detected

app/helpers/application_helper/button/basic.rb

app/helpers/application_helper/toolbar_builder.rb

Copy link

@vecerek vecerek left a comment

Choose a reason for hiding this comment

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

@martinpovolny we checked the visible methods with @romanblanco and the changes seem to be fine. No problem encountered.

@martinpovolny martinpovolny merged commit 2c3e787 into ManageIQ:master Nov 2, 2016
@martinpovolny martinpovolny added this to the Sprint 49 Ending Nov 14, 2016 milestone Nov 2, 2016
@romanblanco romanblanco deleted the toolbar_builder_refactoring branch November 2, 2016 16:02
end
end

context "build_toolbar" do
context "loolbar_class" do
Copy link

Choose a reason for hiding this comment

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

@romanblanco here you have a typo

Copy link
Member Author

@romanblanco romanblanco Nov 2, 2016

Choose a reason for hiding this comment

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

@vecerek lool 😄 nice catch! 👍 I'll fix it in another PR, thanks

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.

4 participants