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

Admin::ReportsController reusable search params #2012

Merged
merged 1 commit into from
Jun 20, 2017

Conversation

oeN
Copy link

@oeN oeN commented Jun 9, 2017

I'm adding a new report to my project, and I want to reuse the same filter as the sales_total.
I think that would be great if we can have the search params logic in an another method like search_params

@oeN oeN force-pushed the reports-reusable-params branch 2 times, most recently from 4c2d31c to eb63e38 Compare June 13, 2017 13:42
Time.current.beginning_of_month
end

def adjust_end_date string_date

Choose a reason for hiding this comment

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

Use def with parentheses when there are parameters.

end
end

def adjust_start_date string_date = nil

Choose a reason for hiding this comment

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

Use def with parentheses when there are parameters.

@oeN oeN force-pushed the reports-reusable-params branch 2 times, most recently from 126746e to c8eb27c Compare June 13, 2017 13:44
Copy link
Contributor

@jhawthorn jhawthorn left a comment

Choose a reason for hiding this comment

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

This looks great, but I have a few suggestions.

def adjust_start_date(string_date = nil)
return Time.current.beginning_of_month unless string_date
Time.zone.parse(string_date).beginning_of_day
rescue
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this rescue something more specific? It's easy for bugs to sneak in with the catchall rescue.


def adjust_end_date(string_date)
Time.zone.parse(string_date).end_of_day
rescue
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto here.

end

def adjust_start_date(string_date = nil)
return Time.current.beginning_of_month unless string_date
Copy link
Contributor

Choose a reason for hiding this comment

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

The previous code checked the equivalent of string_date.blank?, should we still be doing that (I suspect yes since we may get an empty string from the user)?

@oeN oeN force-pushed the reports-reusable-params branch from c8eb27c to dfcc720 Compare June 14, 2017 08:06
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Thanks! Everything looks nicer now!

I just have one comment: when the date param is passed in an "unparsable" format Time.zone.parse will return nil raising a NoMethodError, eg:

> Time.zone.parse('asd').beginning_of_day
NoMethodError: undefined method `beginning_of_day' for nil:NilClass

I'm not sure it's the scope of this PR since this issue was already there. Also since that input is controlled by some JS code (datepicker) maybe we can avoid this check? What do you think @oeN ?

@kennyadsl
Copy link
Member

@oeN also, I think that if you rebase against master the test suite failure will disappear, thanks!

@oeN oeN force-pushed the reports-reusable-params branch from dfcc720 to 2b7cd2a Compare June 15, 2017 09:21
@oeN
Copy link
Author

oeN commented Jun 15, 2017

@kennyadsl Thanks for the comments! About the "unparsable" format, I think that we can avoid this check, for now, for two reasons:

  • the inputs are managed by JS code
  • adding this check feels like a kind of defensive programming

Copy link
Contributor

@jhawthorn jhawthorn left a comment

Choose a reason for hiding this comment

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

👍 Thank you

@jhawthorn jhawthorn merged commit 040210e into solidusio:master Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants