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

Force start date before end date with range mode flatpickr #12094

Conversation

cyrillefr
Copy link
Contributor

@cyrillefr cyrillefr commented Jan 27, 2024

  • modify view to get a flatpickr component in range mode
  • modify spec to take into account range mode

What? Why?

By using the flatpickr component(node module + stimulus), to execute in range mode, we force the user to use consecutive dates. That is: a start date, then an end date.
This mode is already in use in the orders part of the admin.
The change is also effective to every reports since the datepickr is shared between all report views.

What should we test?

  • Visit any report page, and see the datepicker is now only one input and pop-up component that compels to chose a range of date in proper order.
  • also, the automated spec orders_and_fulfillment_spec.rb simulate the picking of dates in this new mode.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Nice one ! 👍

@drummer83 drummer83 self-assigned this Jan 31, 2024
@drummer83 drummer83 added the pr-staged-au staging.openfoodnetwork.org.au label Jan 31, 2024
@drummer83
Copy link
Contributor

drummer83 commented Jan 31, 2024

Hi @cyrillefr,
Thanks for yet another one! 🔥

I love using the date range selector. It's much more comfortable! 👍
As far as I can tell it is working great on all the reports - not all of them have been tested yet.

Two things come to my mind which need clarification, though:

  1. We are losing the option to set start and end TIME. I could imagine that this can be useful if an order cycle ends at noon and the next one starts in the same moment. You might want to set the report filters accordingly.
  2. I'm not sure if this is something we can change, but: If you select just one day (click on it twice in the range selector), I would expect to get results from time >= 00:00 until time < 00:00 next day. However the results are always empty. It seems like the query is looking from 00:00 until 00:00, which is (almost) always empty. Can we change this?
    UPDATE: Ah, even worse... If you select 17th and 18th January in the date range it will show results from 17th Jan 00:00:00 until 18th Jan 00:00:00. So the 18th is actually ignored.

I think we should hear the opinion of @openfoodfoundation/train-drivers-product-owners on how to continue with this one. But maybe you can already comment what's possible and what's not, Cyrille! Thanks!

Anyway, thanks a lot for your work already!

@drummer83 drummer83 added feedback-needed and removed pr-staged-au staging.openfoodnetwork.org.au labels Jan 31, 2024
@drummer83 drummer83 removed their assignment Jan 31, 2024
@mkllnk
Copy link
Member

mkllnk commented Jan 31, 2024

Those are clear regressions that need to be solved.

  • Include time.
  • Adjust boundaries.

Maybe it makes more sense to query the range inclusive the borders, not exclusive (<= instead of <) and then we could go from the start date at 00:00 midnight to the end date at 23:59 by default.

This is just an idea, I don't know which implementation is easiest.

@cyrillefr
Copy link
Contributor Author

Hello @drummer83, @mkllnk sorry I did miss the issue on time ...
I assume the range mode would be ok since it is used in the orders part.

I will look at those time issues and tell what can be done to solve listed regressions.

@cyrillefr
Copy link
Contributor Author

Hello @drummer83, @mkllnk ,

I can add time with a simple config add to configuration.
Time starts by default at 12:00, but I can change to 00:00, therefore, it is easier to get 00:00 to 23:59 reports or 00:00 to 00:00 ones.
Also, by adding time, I think there should be no need to set up some other default, since user is free to chose exactly time.

What do you think, should I do that ?

@drummer83
Copy link
Contributor

Please, go ahead and add the time config.

I don't quite follow your proposal regarding the default time. Could you try to explain again? 🙃

@cyrillefr
Copy link
Contributor Author

Hello @drummer83 , regarding the default time at 00:00

Since (I think), most of the reports will be for complete days and since time is displayed: by setting default time at 00:00, there will be less time juggling and clicking than with the previous default of 12:00(which forces to click till 00 or to enter 00).
So if you want a report for one day, you will only have in the second part of the range to click upwards from 00:00 to 23:59 to get a range of a complete day. With one click.

@drummer83
Copy link
Contributor

Ok, so it's not possible to have 00:00 as default for the start day and 23:59 as default for the end day?
I think if that's not possible, then 00:00 for both is maybe best, just like you said. And instead of clicking to 23:59 I would simply select the next day and use 00:00 on that day - which is really convenient.
Thanks for thinking this through, @cyrillefr!

@cyrillefr
Copy link
Contributor Author

Hello @drummer83 , Yes you can only chose one default hour and not an array like default dates. (I have tried and it is not working).

@drummer83
Copy link
Contributor

Cool, @cyrillefr!
In case you have time for something interesting to read: #9989
The corresponding discussion in the PR is interesting as well. 😉

Long story short: 00:00 is the way to go! 💪🏻

@cyrillefr cyrillefr closed this Feb 26, 2024
@cyrillefr cyrillefr deleted the Reports-500Error-if-date-range-end-is-before-date-range-start-in-Enterprise-Fee-Summary branch February 26, 2024 08:30
@cyrillefr cyrillefr restored the Reports-500Error-if-date-range-end-is-before-date-range-start-in-Enterprise-Fee-Summary branch March 14, 2024 12:39
@cyrillefr cyrillefr reopened this Mar 14, 2024
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.

The code is looking good but I have one concern over an issue we had before. If you select a date range, like for Monday to Friday then the times are set to 00:00 on both days, right? So the effective search is from beginning of Monday to beginning of Friday which is also end of Thursday. The user expects Friday to be included but it's not unless you adjust the time.

Is this what happens? Is there any callback we can hook into to adjust the time after date selection? Is the time reset every time you change a date or is the time preserved? For example, if I select Wednesday 10:00 am and then select Thursday, does it reset to 00:00 or keep 10:00?

@cyrillefr
Copy link
Contributor Author

Hello @mkllnk ,

If you select Mon 00:00 to Fri 00:00, you will have a span search that includes all of the Thursday and the first minute of Friday.
Either you select Thu 23:59 or Fri 23:59. Its offers more flexibility but users must be aware of what they do a bit more.
Note that after selecting the first date, the time is highlighted to show you can modify it.
When selecting a second date, the time set off for the first one is kept: if you choose Mon 11:40, it will keep the 11:40 for the second date (that you can modify of course).

If you click a third time, you re init both dates & times.

Regarding hooks, there are some:
https://flatpickr.js.org/events/

I guess you would be interested on setting 23:59 for the 2nd date.
From the link @drummer83 mentioned above, what have been implemented on the 2 parts picker, was a 00:00 default time for both start & end dates.

@mkllnk
Copy link
Member

mkllnk commented Mar 18, 2024

I guess you would be interested on setting 23:59 for the 2nd date.

I think that would be ideal. I'm happy for @drummer83 to have the last say here.

@sigmundpetersen
Copy link
Contributor

As @abdellani says in #9989 (comment), if you set 23:59 you will miss records created between 23:59:00 and 23:59:59.

His solution was

In start date:
    date: Today
    time: 00:00
In end date:
    date: Tomorrow
    time: 00:00

@drummer83
Copy link
Contributor

Hi @cyrillefr,
Sorry for my late reply. I've been thinking about this again and again, started writing down scenarios, but in the end this PR is about removing the error 500 - not about improving or changing the usability.
Therefore I came to the following conclusion: Let's go for 00:00 for start and end date.
Why? Because this is the exact behaviour we have right now - just with two separate date pickers instead of one.
I hope we can move this forward now.
Apologies again!

@cyrillefr
Copy link
Contributor Author

Hello @drummer83 ,

no problemo :)

@RachL
Copy link
Contributor

RachL commented May 17, 2024

hello @cyrillefr do you still plan to work on this one?

@cyrillefr
Copy link
Contributor Author

Hello @RachL ,

I need to refresh a bit with this one, but I am pretty sure the solution that was picked in the end was what I have coded in the first place.
I will have a look and make some tests.

@cyrillefr
Copy link
Contributor Author

Yes, the few remarks at the end to talk about the end time of the date picker.
In the end, everybody is ok with the chosen end time.
To me, there is nothing to add.

@@ -141,7 +142,8 @@
# 2 rows for order1 + 1 summary row

# setting a time interval to include both orders
pick_datetime "#q_completed_at_gt", datetime_start2
find("input.datepicker").click
select_dates_from_daterangepicker datetime_start2, Time.zone.now
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am wondering why we don't need to close flatpickr here ? Anyway the tests are green, so it's not really important.

Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Nice one, thanks @cyrillefr !

@rioug rioug added the user facing changes Thes pull requests affect the user experience label May 20, 2024
@filipefurtad0 filipefurtad0 self-assigned this May 22, 2024
@filipefurtad0 filipefurtad0 added the pr-staged-fr staging.coopcircuits.fr label May 22, 2024
@filipefurtad0
Copy link
Contributor

filipefurtad0 commented May 22, 2024

Hey @cyrillefr ,

This is quite awesome 💪

image

I could not find a way to select an invalid time range on the reports date-time selector.

Just as a recap, we go from the scenario in which we had to separate date/time selectors:

image

to having just one. The only minor usability issue introduced is that the selected date is not really fitting the placeholder, which means it is not readable:

image

I think it can be easily checked in a visual way, by clicking the selector, so I don't think this is a blocker.

I've checked other report types, and the new selector is implemented everywhere, and functional.

From the testing side, I'd say this is good to merge. I'm wondering how does @openfoodfoundation/train-drivers-product-owners feel about the too short placeholder?

Adding the feedback needed label.

Edit - more of a note to self: looking at the code, I'm surprised only one report spec needed updating. I think it's a good idea to implement this test in other reports as well. I'll open an issue and assign myself to it.

@filipefurtad0 filipefurtad0 added feedback-needed and removed pr-staged-fr staging.coopcircuits.fr labels May 22, 2024
@cyrillefr
Copy link
Contributor Author

Hello @filipefurtad0 ,

I can definitively make the size for the placeholder bigger.
I will do it tomorrow ( I am UTC + 2:00)

@sigmundpetersen sigmundpetersen force-pushed the Reports-500Error-if-date-range-end-is-before-date-range-start-in-Enterprise-Fee-Summary branch from 71743f7 to 3451be4 Compare May 23, 2024 07:13
@filipefurtad0 filipefurtad0 added the pr-staged-fr staging.coopcircuits.fr label Jun 5, 2024
@filipefurtad0
Copy link
Contributor

Hey @cyrillefr ,

This looks great now:

image

I had a quick look through other reports, all good. Merging! Thanks again!

@filipefurtad0 filipefurtad0 merged commit e4c0523 into openfoodfoundation:master Jun 5, 2024
52 checks passed
@filipefurtad0 filipefurtad0 removed the pr-staged-fr staging.coopcircuits.fr label Jun 5, 2024
@cyrillefr cyrillefr deleted the Reports-500Error-if-date-range-end-is-before-date-range-start-in-Enterprise-Fee-Summary branch June 11, 2024 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user facing changes Thes pull requests affect the user experience
Projects
Status: Done
7 participants