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

Sort correctly in Bulk Order Managment #10451

Conversation

cyrillefr
Copy link
Contributor

What? Why?

Inaccurate sorting @ /admin/orders/bulk_management
Even though so some numeric representation of a Date could be used at first thought, the advantage here is also to get a utc date first then to format it to an ISO8601. No locale in a numeric representation.

Avdi Grimm has a post on it: https://avdi.codes/iso8601-dates-in-ruby/

What should we test?

The same procedure as stated in #9661

  • Go to /admin/orders/bulk_management
  • Select date range covering three or more months
  • Sort by date (click on 'completed at' in the table header)

I would personally use July, September and August

Copy link
Contributor

@jibees jibees left a comment

Choose a reason for hiding this comment

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

Great documentation, clean PR, thanks!

Wondering if this worth a spec. @filipefurtad0 what to you think?

@filipefurtad0
Copy link
Contributor

Wondering if this worth a spec.

Agree @jibees , wondering as well - something like we already to for the orders page.

I'd suggest we'd make this check on the file spec/system/admin/bulk_order_management_spec.rb, within the block describe "sorting of line items" do.

Would you be available to add a test to this PR @cyrillefr?

@cyrillefr
Copy link
Contributor Author

Hello @filipefurtad0.
Just added the spec.

Copy link
Contributor

@filipefurtad0 filipefurtad0 left a comment

Choose a reason for hiding this comment

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

LGTM, in what the spec concerns. Thanks @cyrillefr !

Seems like a minor code change - should we move it to test ready @jibees ?

@jibees
Copy link
Contributor

jibees commented Feb 17, 2023

Yes!

@filipefurtad0 filipefurtad0 self-assigned this Feb 20, 2023
@filipefurtad0 filipefurtad0 added pr-staged-uk staging.openfoodnetwork.org.uk and removed pr-staged-uk staging.openfoodnetwork.org.uk labels Feb 20, 2023
@filipefurtad0
Copy link
Contributor

Hey @cyrillefr ,

I've staged the PR and repeated the automated test, on the server with "real" data.

Before the PR:

image

After this PR - with the data for this enterprise, I somehow cannot observer the correct ordering:

After clicking once on "Completed at", I get:

image

After clicking a second time:

image

This seems to work in some cases, but not always. Could there be another factor interfering in the ordering, on this page?

@cyrillefr
Copy link
Contributor Author

cyrillefr commented Feb 20, 2023

This seems to work in some cases, but not always. Could there be another factor interfering in the ordering, on this page?

Hello @filipefurtad0.
I need to check. The thing that surprises me a bit also is it seems to me there is no lexicographical order either ...

@cyrillefr cyrillefr force-pushed the Sort-properly-date-chronologically-and-not-lexicographically branch from c7e546a to 2bd87b4 Compare February 20, 2023 18:17
    Converting date to utc + iso8601 format is
    sufficient to ensure proper sorting.
@cyrillefr cyrillefr force-pushed the Sort-properly-date-chronologically-and-not-lexicographically branch from 2bd87b4 to e4845f4 Compare February 20, 2023 20:43
@cyrillefr
Copy link
Contributor Author

@filipefurtad0 , it should work now.
I had forgotten to put the serializer ....
Strangely, my combination of months names worked ...
So I have taken the same months as your example both in local and and test, and it is ok after(ko before this change)

@sigmundpetersen
Copy link
Contributor

Thanks @cyrillefr .
We should get a short review of the latest changes before moving back to testing 👍

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Great work!

@drummer83 drummer83 added the pr-staged-uk staging.openfoodnetwork.org.uk label Feb 22, 2023
@drummer83 drummer83 self-assigned this Feb 22, 2023
@drummer83
Copy link
Contributor

Hi @cyrillefr,
Thanks for following up on this. I have tested your updated PR and it looks good now.

Before your PR - clicking 'Completed at' ONCE
Sorted alphabetically, ascending:
image

Before your PR - clicking 'Completed at' TWICE
Sorted alphabetically, descending:
image

After your PR - clicking 'Completed at' ONCE
Sorted chronologically, ascending:
image

After your PR - clicking 'Completed at' TWICE
Sorted chronologically, descending:
image

Conclusion

This is great improvement, thanks a lot! It's ready to be merged! 🚀

Note

I find it strange that the columns are sorted per page only (and not all results of the query). So on other pages there may be older or newer line items, even if the table is sorted by date. On page /orders the behavior is different and more intuitive, I think. But we can see that each sorting process requires a new database query there - maybe there was a technical reason to implement the BOM page like this. I will do some digging and see if we want to improve this even more. Also the little indicator arrow for ascending and descending might be helpful sometimes.
All of this is clearly out of scope of this issue and your PR. Just noting my observation.
Thanks again! 💪

@drummer83 drummer83 merged commit 8b89c8d into openfoodfoundation:master Feb 22, 2023
@drummer83 drummer83 removed the pr-staged-uk staging.openfoodnetwork.org.uk label Feb 22, 2023
@cyrillefr cyrillefr deleted the Sort-properly-date-chronologically-and-not-lexicographically branch February 26, 2024 08:31
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.

[Bulk Order Management] Incorrect sorting by date: months sorted alphabetically instead of chronologically
6 participants