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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/views/chargeback/_cb_rate_edit_table.html.haml
Expand Up @@ -18,13 +18,14 @@
%th= _("Fixed")
%th= _("Variable")
%tbody
- @edit[:new][:details].sort_by { |rd| [rd[:group], rd[:description], rd[:sub_metric].to_s] }.each do |detail|
- @edit[:new][:details].sort_by { |rd| [rd[:group], rd[:description], rd[:sub_metric].to_s] }.each_with_index do |detail, detail_index|
- @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! :)

- detail_index = @edit[:new][:tiers].index { |x| x.detect { |tier_hash| tier_hash['chargeback_rate_detail_id'] == detail[:id] }.present? }
- num_tiers = @edit[:new][:tiers][detail_index].blank? ? "1" : @edit[:new][:tiers][detail_index].length.to_s

%tr.rdetail{:id => "rate_detail_row_#{detail_index}_0"}
Expand Down