-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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 "Now" in DateTime parameter not working #3808
Conversation
@gabrieldutra I analyzed the code a little bit and I found the bug. |
Thanks @kravets-levko 😁
I'd thought so, however this was one of my tests (the values differ):
State seemed more the "React way", but |
@kravets-levko, updated to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice fix (even better than I did in my experiments 😅)! And, of course, it works (I tested on query and dashboard page).
What type of PR is this? (check all applicable)
Description
I did find the cause for this bug, but with DatePicker methods and our current needs the only way I could think as a fix was to create an "unnecessary" state. Leaving this as WIP so @ranbena and @kravets-levko can join here (also I have to extend the fix to
DateTimeRangeInput
as a guarantee).Antd's DatePicker provides the following callbacks:
onChange
: Triggered whenever you change the value on the dialogonOk
: Triggered only when you click "ok"onOpenChange
: Triggered when you open/close the dialogonOpenChange
seemed to be the most reliable event to trigger the update for the Query, so I used it by adding a state to track the value.The cause for the issue: when you click "Now" it invokes
onChange
->onOpenChange
fast enough that the component doesn't update.The workaround in this PR: Considering that React guarantees the order for
setState
I added a new state to use its callback to make surecurrentValue
would be updated.BTW,
onOk
may seem a good solution, but it's not triggered when you click on "Now".An alternative is to add the "Apply" button for this too, so the update event could be
onChange
with no problems. The con is that it's not the best to have both "Ok" and "Apply" to set the parameter.Edit:
useRef
instead.Related Tickets & Documents
Closes #3803
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
Dashboard
Query