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

Dialog field - set load_values_on_init to true where show_refresh_button was not enabled #357

Merged
merged 5 commits into from
Apr 1, 2019

Conversation

himdel
Copy link
Contributor

@himdel himdel commented Mar 27, 2019

Replaces code that was previously hardcoded in the model..

    def load_values_on_init?
      return true unless show_refresh_button
      load_values_on_init
    end

Needed to make it posssible to set both these fields to false,
without breaking all the old fields where the value of load_values_on_init previously didn't matter.

https://bugzilla.redhat.com/show_bug.cgi?id=1684575
https://bugzilla.redhat.com/show_bug.cgi?id=1684567

(Depended on by:

@himdel
Copy link
Contributor Author

himdel commented Mar 27, 2019

Cc @gmcculloug @eclarizio
(this is the last one of the three :))

Copy link
Member

@eclarizio eclarizio left a comment

Choose a reason for hiding this comment

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

I think my only concern about all of this is that we should probably now be defaulting load_values_on_init to be true, right? Previously, as you said, this was handled by the code, and this migration fixes any existing fields, but going forward new ones will be created with both show_refresh_button and load_values_on_init to be false. It might be weird for people used to the system that don't change those switches at all and now suddenly their newly created fields don't work.

Other than that I think this fix is straightforward

@himdel
Copy link
Contributor Author

himdel commented Mar 27, 2019

Agreed @eclarizio , will add that to the ui-components PR (assuming that's what sets the initial value), thanks :)

@eclarizio
Copy link
Member

Actually, should it be added here? For people that use the API to create fields? (Is that even a thing people do?)

@gmcculloug Maybe you have some insight on this.

@himdel
Copy link
Contributor Author

himdel commented Mar 27, 2019

Well, not in schema (or I don't know how), but possibly default_value_for in the model?

@eclarizio
Copy link
Member

Yeah, that's probably fine

himdel added 2 commits March 28, 2019 15:06
…ton was not enabled

Replaces code that was previously hardcoded in the model..

    def load_values_on_init?
      return true unless show_refresh_button
      load_values_on_init
    end

Needed to make it posssible to set both these fields to false,
without breaking all the old fields where the value of `load_values_on_init` previously didn't matter.

https://bugzilla.redhat.com/show_bug.cgi?id=1684567
https://bugzilla.redhat.com/show_bug.cgi?id=1684575
… set to true unless show_refresh_button was set
@JPrause
Copy link
Member

JPrause commented Mar 28, 2019

@himdel if this will be able to be backported, can you add the hammer/yes label.

@himdel
Copy link
Contributor Author

himdel commented Mar 29, 2019

(EDIT: wrong place for the comment, moved to ManageIQ/manageiq#18600 (comment))

@himdel himdel closed this Mar 29, 2019
@himdel himdel reopened this Mar 29, 2019
@carbonin
Copy link
Member

@JPrause We typically don't backport schema PRs. Is there a compelling reason for this one to be backported?

Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

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

What is the actual relationship between these columns? Should they really be just one column with some logic around it?

migration_context :up do
before do
[true, false, nil].each do |show|
[true, false, nil].each do |load|
Copy link
Member

Choose a reason for hiding this comment

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

Using keywords as variable names makes me nervous ... maybe load_value here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed 👍

end

it "updates load_values_on_init" do
expect(dialog_field_stub.pluck(:load_values_on_init)).to eq([true, false, nil, true, true, true, true, true, true])
Copy link
Member

Choose a reason for hiding this comment

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

Can you add an explicit sort here so we don't get bit by locale or OS default sorting rules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was hoping we can reliably get them in order they were created.

Is there any nice way of doing that?
(But I can live with sort too...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a sort_by(:id) since we probably can rely on the ids being ascending, right?

And split into 3 lines to better show the relation.

@himdel
Copy link
Contributor Author

himdel commented Mar 29, 2019

@himdel if this will be able to be backported, can you add the hammer/yes label.
@JPrause We typically don't backport schema PRs. Is there a compelling reason for this one to be backported?

Explicitly leaving the backport/no backport decision on @gmcculloug & @Loicavenel.

It looks like there is a need for fields that will only refresh because other fields change in hammer, and this is the only (sane) way of achieving that.

@himdel
Copy link
Contributor Author

himdel commented Mar 29, 2019

What is the actual relationship between these columns? Should they really be just one column with some logic around it?

@carbonin it's described in this PR's description ;)

Before, load_on_init was completely ignored (and assumed to be true) when show_refresh_button was not set to true, and only read if show_refresh_button was true.

Now, load_on_init and show_refresh_button will be completely independent.

But we still need to make sure that all those "assumed to be true" load_on_init values get explicitly set to true for this to not break old fields.

@carbonin
Copy link
Member

Okay, that makes sense @himdel

As far as the backport decision, it actually seems to me that this cannot be backported because we wouldn't be able to rely on this logic for people who have already upgraded to hammer (and by extension will not run this migration).

expect(dialog_field_stub.sort_by(:id).pluck(:load_values_on_init)).to eq([
true, false, nil, # show_button was true
true, true, true,
true, true, true,
Copy link
Member

Choose a reason for hiding this comment

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

I think I would just prefer individual specs for each case. For example:

it "doesnt update load_values_on_init when show_refresh_button is true" do
...
end

it "updates load_values_on_init when show_refresh_button is not true" do
...
end

Then we don't have to play this ordering game at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, maybe better with less magic, fixing :)

@himdel
Copy link
Contributor Author

himdel commented Mar 29, 2019

As far as the backport decision, it actually seems to me that this cannot be backported because we wouldn't be able to rely on this logic for people who have already upgraded to hammer (and by extension will not run this migration).

Agreed that the whole feature can absolutely not work without the migration backported too, if that's what you mean, yes.

(But if we did, it would, right?)

@carbonin
Copy link
Member

carbonin commented Mar 29, 2019

Agreed that the whole feature can absolutely not work without the migration backported too, if that's what you mean, yes.

(But if we did, it would, right?)

No, because people who have already upgraded to hammer will not run this migration. Users are only expected to run migrations on major releases. This is why we don't backport migrations.

@himdel
Copy link
Contributor Author

himdel commented Mar 29, 2019

Ah, well, in that case..

@miq-bot add_label hammer/no

That pretty much settles it I think, unless we want to wrap it in a product feature switch or something like that.

Thanks! :)

let(:dialog_field_stub) { migration_stub(:DialogField) }

migration_context :up do
let (:show_button) { nil }
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is needed.

Copy link
Contributor Author

@himdel himdel Apr 1, 2019

Choose a reason for hiding this comment

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

It was, undefined local variable or method 'show_button' for #<RSpec::ExampleGroups::DialogFieldLoadValuesOnInit::Up:0x0000000009226718> otherwise.

end

context "when show_refresh_button is true" do
let (:show_button) { true }
Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure there shouldn't be a space between the let and ( here. And that's why you're getting the rubocop issues.

Copy link
Member

Choose a reason for hiding this comment

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

Same with the other let(:show_button) calls.

@himdel
Copy link
Contributor Author

himdel commented Apr 1, 2019

Thanks @carbonin , those should be resolved now..

@miq-bot
Copy link
Member

miq-bot commented Apr 1, 2019

Checked commits https://github.com/himdel/manageiq-schema/compare/e8c1faa5dbbf46ae3d4c2ac2ac462da64dd988c2~...8252f75d908b68c5db84bf7cf6cb48b0d18ef731 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 1 offense detected

db/migrate/20190327132620_dialog_field_load_values_on_init.rb

@carbonin carbonin self-assigned this Apr 1, 2019
@carbonin carbonin merged commit 445eac4 into ManageIQ:master Apr 1, 2019
@carbonin carbonin added this to the Sprint 108 Ending Apr 1, 2019 milestone Apr 1, 2019
@himdel himdel deleted the bz1684575 branch April 1, 2019 14:10
thearifismail pushed a commit to thearifismail/manageiq that referenced this pull request Jun 3, 2019
thearifismail pushed a commit to thearifismail/manageiq that referenced this pull request Jun 3, 2019
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.

5 participants