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

Improvements for non-zero index subtotals #6

Merged

Conversation

aharpervc
Copy link
Contributor

@aharpervc aharpervc commented Oct 24, 2018

@ronnietaylor I guess you were the last person to touch this, so GitHub said you could review it 😀

- the `collection` is empty and you set `collection[1] = {}`, then `collection[0]` will be `nil` and that'll cause things to blow up
- eg, when the subtotal index is 1, you'll have an index_1 row, but you don't want an empty index_0 row
@BrianBorge
Copy link
Contributor

BrianBorge commented Oct 30, 2018

Taking a look at this PR as I have several client requests that will benefit from this being merged in.

Related Client Requests

Copy link
Contributor

@BrianBorge BrianBorge left a comment

Choose a reason for hiding this comment

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

Looks good to me. One thing I noticed was that nonzero starting subtotals do not get the border top styling, see image below. I don't think that was intentional and if it wasn't I can add a to the PR here.

Only important if you're using the default styling but not important if you already override the css property (.index_0 td) in your code...I think.

screen shot 2018-10-30 at 3 05 55 pm

Compared to a subtotal indexed at 0 below

screen shot 2018-10-30 at 3 09 04 pm

@@ -72,6 +72,48 @@
expect(data_table.subtotal_calculations).to eq({["Star Wars"]=>[{:power_level=>{:sum=>145.0}}], ["Middle Earth"]=>[{:power_level=>{:sum=>9081.0}}]})
end

it "should do sub-totaling starting with indexes > 0" do
data_table.group_by :world, level: 0
Copy link
Contributor

Choose a reason for hiding this comment

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

{level: 0} is the default value for the level param in the group by definition so it can be removed.

Suggested change
data_table.group_by :world, level: 0
data_table.group_by :world

Choose a reason for hiding this comment

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

I think it should have the border top by default in that case. Let's go ahead and add that.

@BrianBorge
Copy link
Contributor

BrianBorge commented Oct 30, 2018

Here's my proposed changed for the problem mentioned above regarding the borders: #7

Thoughts on the implementation?

Edit - closed pr since I need to look into it more.

@ronnietaylor
Copy link

I think that using a css pseudo class here is a decent way to avoid the brittleness of relying on the indexes values generated by data-tables.

Let's test using last-child instead to fix the css issue.

if that works then I'm ok with merging this change.

@@ -339,7 +339,9 @@ def calculate_subtotals!
@collection.each_pair_with_parents(@groupings.count) do |group_name, group_data, parents|
path = parents + [group_name]
result = calculate(group_data, subtotal[0], subtotal[1], path)
@subtotal_calculations[path][index] ||= {}
(0..index).each do |index|

Choose a reason for hiding this comment

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

@aharpervc What the reasoning for iterating over the range here? (0..index)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same logic as https://github.com/veracross/data-table/pull/6/files#diff-6d5c93afbede304616a4170b9f9dacadR443, which is that you need to fill in any prior array indexes with empty objects to avoid nil reference exceptions.

x = []
x[1] = {}
puts x.inspect # [nil, {}]`

Copy link

@ronnietaylor ronnietaylor Oct 30, 2018

Choose a reason for hiding this comment

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

Were nil references the original problem that triggered this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, see https://support.veracross.com/a/tickets/17520 for the original test case, now followed by all of brian's examples, plus https://github.com/axiom-dev/planning/issues/1274

@BrianBorge
Copy link
Contributor

Alright, I created this PR(#8) which keeps the top borders for nonzero subtotals and totals when they are the first rendered row.

@BrianBorge
Copy link
Contributor

@aharpervc - Same question, different PR. This PR is ready to be merged into master. Do you have any objections?

What needs to happen once this is merged to get it into production?

@aharpervc
Copy link
Contributor Author

Do you have any objections?

The code seems fine in and of itself. The next question is integration with consumers & confirmation that it resolves the problem statement.

Confirming that & getting to production are a similar path... get a dev env of an app you want to test with, change the gemfile to point at this branch, try to pull up the pages that formerly failed & are now expected to succeed (don't forget to confirm they fail on master branch first).

Assuming that all works out, the production update steps are: follow the release steps for this gem (release notes, version bump, push to rubygems), then follow the release steps for any app that needs this update.

@BrianBorge
Copy link
Contributor

Awesome, thanks. I'll work on testing inside a development environment.

@BrianBorge
Copy link
Contributor

BrianBorge commented Nov 12, 2018

  • Confirm failure on master branch first
  • Confirm failed published queries in Portals work with this branch

Now to go through the production steps.

@BrianBorge BrianBorge merged commit 2b66395 into master Nov 12, 2018
@aharpervc aharpervc deleted the fix-unhandled-exception-for-nonzero-starting-subtotals branch November 13, 2018 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants