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

Fix issues related to adding, editing Chargeback Rates #3129

Merged

Conversation

hstastna
Copy link
Contributor

@hstastna hstastna commented Dec 21, 2017

fixing ManageIQ/manageiq#16699

Fix issues related to adding new or editing existing chargeback rates in Cloud Intel -> Chargeback
-> Rates
tab, caused by improper detail_index in the chargeback rate edit table.

Issues:

After:
rate_highlight
tier_add

Details:
Simple condition was added to haml, because it is accessed not only if editing chargeback rate, but also if adding a new one. We don't need editing detail_index if we just add a new rate.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1532368

@hstastna
Copy link
Contributor Author

@miq-bot add_label bug, gaprindashvili/yes

@hstastna hstastna changed the title Fix issues with adding, editing Chargeback Rates Fix issues related to adding, editing Chargeback Rates Dec 21, 2017
@hstastna hstastna force-pushed the Form_add_chargeback_rate_improper_ids branch from b727941 to c0e8ed8 Compare December 21, 2017 14:08
@hstastna hstastna force-pushed the Form_add_chargeback_rate_improper_ids branch from c0e8ed8 to a2adf5c Compare January 2, 2018 13:27
Copy link
Member

@romanblanco romanblanco left a comment

Choose a reason for hiding this comment

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

Fixes both issues described in ManageIQ/manageiq#16699. 👍

@romanblanco
Copy link
Member

Tests are passing locally.

@himdel himdel closed this Jan 5, 2018
@himdel himdel reopened this Jan 5, 2018
fixing ManageIQ/manageiq#16699

Fix issues with adding new or editing existing chargeback rates in Cloud Intel
-> Chargeback -> Rates tab, caused by improper detail_index in the chargeback
rate edit table.
@hstastna hstastna force-pushed the Form_add_chargeback_rate_improper_ids branch from a2adf5c to 97303e5 Compare January 9, 2018 13:34
@hstastna
Copy link
Contributor Author

hstastna commented Jan 9, 2018

@himdel @martinpovolny It looks like this could be merged. If any issues occur, please just let me know. Thanks!

@miq-bot
Copy link
Member

miq-bot commented Jan 9, 2018

Checked commit hstastna@97303e5 with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 1 offense detected

app/views/chargeback/_cb_rate_edit_table.html.haml

  • ⚠️ - Line 21 - Block has too many lines. [63/25]

@lpichler
Copy link
Contributor

@hstastna please reopen PR to restart travis.

@ZitaNemeckova is this PR fixing your BZ?

@ZitaNemeckova
Copy link
Contributor

@lpichler Yeah it is :)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1532368

@hstastna Can you please close and open this PR? Travis failures are not related to your changes and it should go green :)

@hstastna hstastna closed this Jan 10, 2018
@hstastna hstastna reopened this Jan 10, 2018
@ZitaNemeckova
Copy link
Contributor

This fixes blocker bz https://bugzilla.redhat.com/show_bug.cgi?id=1532368 so adding label :)
@miq-bot add_label blocker

@h-kataria
Copy link
Contributor

@ZitaNemeckova @hstastna please review changes that were made in 36163ea to make variable rate field non-editable.

- @cur_group = detail[:group] if @cur_group.nil?
- if @cur_group != detail[:group]
- @cur_group = detail[:group]
%tr
%td{:colspan => "10", :style => "background-color: #f5f5f5;"}  
- detail_index = @edit[:new][:tiers].index { |x| x.detect { |tier_hash| tier_hash['chargeback_rate_detail_id'] == detail[:id] }.present? }
- if params[:pressed] == "chargeback_rates_edit"
Copy link
Contributor

@himdel himdel Jan 10, 2018

Choose a reason for hiding this comment

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

This doesn't sound like the best place for this kind of condition.

Also, this means detail_index will be nil for all the other cases...

So.. all the code like {:id => "rate_detail_row_#{detail_index}_0"} has a bug now. (Well, unless nil is really expected there.)

Please make sure detail_index always has a reasonable value.
(And ideally, move the params[:pressed] condition to controller code.)

Copy link
Contributor Author

@hstastna hstastna Jan 10, 2018

Choose a reason for hiding this comment

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

detail_index will not be nil because of https://github.com/ManageIQ/manageiq-ui-classic/pull/3129/files#diff-9e228e37bdb4a0dfb3c30cffd92d3981R21
....each_with_index do |detail, detail_index|
I have tested that, it always will be set, and properly. detail_index is just changed if params[:pressed] == "chargeback_rates_edit"
Or am I missing something?
This change is made because in this haml... this haml is common for editing and displaying the rates. For just displaying, using detail_index just as it is, works perfectly. When editing, we need it just like this: https://github.com/ManageIQ/manageiq-ui-classic/pull/3129/files#diff-9e228e37bdb4a0dfb3c30cffd92d3981L27
To move the condition to controller? I am not sure, how I would change detail_index from controller if the rate is edited. Any idea how to make it properly? Thanks! :)

@ZitaNemeckova
Copy link
Contributor

@h-kataria Yeah but only for fixed ones.

@dclarizio
Copy link

@lpichler can you please review and let us know if this is good to go? Thx, Dan

@hstastna
Copy link
Contributor Author

@h-kataria I think that 36163ea is ok. I don't see how this could affect this PR. The commit change is already in the code and I was fixing the issue against the actual code.

Copy link
Contributor

@lpichler lpichler left a comment

Choose a reason for hiding this comment

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

@dclarizio tested and it is working as expected 👍

@himdel
detail_index is going from as an index from
.each_with_index do |detail, detail_index| as @hstastna is saying but for editing we need to recalculated index when the rate is edited.

This doesn't sound like the best place for this kind of condition

yes, it doesn't but there is more similar array operations in the haml a maybe all these should live somewhere else, maybe in the helper, maybe it would be solved by some cleanup's in the controller.

I am considering this solution as most safe what we can do now and I am suggesting to solve these technical debts in follow up PR. There is also probabilty that this section would be replaced by something 'new' in future.

@dclarizio dclarizio merged commit 5cd68c7 into ManageIQ:master Jan 11, 2018
@dclarizio dclarizio added this to the Sprint 77 Ending Jan 15, 2018 milestone Jan 11, 2018
simaishi pushed a commit that referenced this pull request Jan 12, 2018
…per_ids

Fix issues related to adding, editing Chargeback Rates
(cherry picked from commit 5cd68c7)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1533924
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit db13d23fd1e0384ce9d4527c47f41606a9185eab
Author: Dan Clarizio <dclarizi@redhat.com>
Date:   Thu Jan 11 08:38:48 2018 -0800

    Merge pull request #3129 from hstastna/Form_add_chargeback_rate_improper_ids
    
    Fix issues related to adding, editing Chargeback Rates
    (cherry picked from commit 5cd68c7eda217b5fa10fe1021f68122a3a68399c)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1533924

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.

None yet

9 participants