-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Closes #2394 - Allow relative from and to #10990
Conversation
Looks like there are some tests for the timepicker that need to change as well |
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.
Currently, the "quick" and "absolute" pickers don't allow you to select a "to" date before the "from" date. It'd be nice if the "relative" behavior followed this same pattern.
Also, I think it'd be nice to add the "set to now" buttons here like we have in the absolute picker, because there isn't a real easy way to get back to "now" other than manually setting the value inside the text input to 0. Thoughts?
Yeah... I was thinking about adding the "Set To Now", I figured just typing zero was pretty easy but people might not know to do that. Good point on the checks, I will add them. |
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.
Looks like there's a bug here. The date that shows up in the "To" field doesn't actually match what gets selected as the date when you use "Round to the nearest." For example, here I've got "6 months ago, rounded to the nearest month" selected as both "From" and "To".
In the timepicker, I think we assume that "rounding to the nearest" means rounding down for "From" and rounding up for "To".
If you wanted to add a test to make sure the text shows the correct date in this case, that'd be awesome.
<span ng-show="relative.preview">{{relative.preview}}</span> | ||
<span ng-hide="relative.preview"><i>Invalid Expression</i></span> | ||
<span ng-show="relative.from.preview">{{relative.from.preview}}</span> | ||
<a class="label label-default" ng-click="setRelativeToNow('from')">Set To Now</a> |
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.
As it currently stands, it doesn't make much sense to add the "Set to Now" button in the "From" field, because there's no way to have a "To" that's in the future (as far as the relative picker is concerned). However, since we just added it to the absolute timepicker, and since there's an open issue to add future relative dates, I'm fine with it.
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.
So remove it?
It looks like I forgot to add the flag for rounding up for the "to" |
I'm going to remove the "review" tag from this and also work on closing #6732 |
Sounds good! Thanks for taking these on. |
@cjcenizal Curious if you could provide your feedback about the error message when the "from" value is after the "to" value (see the screenshot in this comment). |
@lukasolson I would highlight both fields in red by setting them as invalid, and put the error message in red beneath the "Round the nearest minute" checkbox in the "From" panel. This way people see that there's an error, it's specific to their input, and they read the error message in the same context as the error's cause. |
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.
When I select one of the options in the drop-down for the future, the "round to the" label doesn't seem to adjust properly:
Also, I know I had mentioned removing the "set to now" button for the "from" field, but now that you've added support for future dates, and seeing as how the "set to now" button is in the absolute "from" as well, I think it makes sense to add it back.
@lukasolson Fixed the "round to the" label. The new value for the future units was messing up the lookup. |
@lukasolson All the things |
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.
Sorry, found another thing. 😬 If I have "0 days" selected as the "to", then check "round to the day", it still says "now". Shouldn't that actually be the end of today? (If I go into the url and change the "to" value to "now-0d/d", it's a different date than simply "now".)
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.
WOOT LGTM!
@tsullivan any concerns about these changes for monitoring, and @stacey-gammon any concerns about these changes for dashboard?
The behavior for the back and forward buttons is a bit odd. I'd expect the relative time to keep the difference between from and to but it seems to shift randomly. To automatically reverts to 0 seconds and from seems to work as expected when traversing backwards but if you move forward in time the dropdown changes to seconds with an incorrect number. Another minor thing I found. I noticed that if I set the from or to values to 0 [anything], the dropdown reverts back to seconds / now regardless of the selection I made. I'd expect the dropdown to persist the value I chose while still loading "now". If I use the "round to" option, it will persist the selection in the drop down. Granted, the date value also changes here. From a monitoring perspective (@bohyun-e @tsullivan) there is now a "from now" option (hours from now, months from now, etc.). It's its current state, this would make it that much easier to view future dates where there is no monitoring data. |
I'm not sure what I did to cause this, but I am getting an error when trying to click the
|
@stacey-gammon Changing the relative then going to absolute doesn't retain the new date (from relative) in master. This mimics the same behavior. I did fix the bug you found though with the exception above. @alexfrancoeur I fixed the code so that when you have a 4 hour range (now-2h-now+2h) then start scrolling absolute will retain the range between. So if you go to the left once then it will change to (now-6h-now-2h). As for retaining the I think we should merge this PR and then file a new issue to change the |
@simianhacker ++ sounds good to me. Retaining the unit is a minor issue in my opinion. |
Sorry @simianhacker I came in late to the PR, thought this had something to do with the previous/next buttons. You are right about the current functionality in master. LGTM! 👍 |
Not following.. could you clarify? |
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.
I noticed when weeks is selected as the unit it gets turned into days in the timepicker. Not really an issue, but a little odd since the other units don't seem to get converted. Don't think it's anything to block on, but thought I'd mention it.
This second thing is just sort of a pet peeve of mine, but I hate when forms freak out on me during normal usage. When I delete the current input in order to type something else in, everything goes red for a second before I start typing which is jarring. Would it be worthwhile to make the error handling a bit smarter so it doesn't make everything red when a single input is empty?
let results = {}; | ||
const matches = _.isString(part) && part.match(/now(([\-\+])([0-9]+)([smhdwMy])(\/[smhdwMy])?)?/); | ||
|
||
if (matches && !matches[1]) { |
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.
Just a suggestion, but some destructuring on this matches array would really make this code more understandable. For instance I couldn't really figure out what that last capture group was for until I read the tests, a variable name for it might have helped.
if (Math.abs(as) > 1) { | ||
results.count = Math.round(Math.abs(as)); | ||
results.unit = units[i] + unitOp; | ||
results.round = false; |
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.
Should round
really always be false here? It looks like the old code set it based on a conditional:
if ($scope.from.toString().split('/')[1]) $scope.relative.round = true;
But from what I can tell, maybe that was incorrect?
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.
Yes... Once the execution is to this point it's already NOT a relative timestamp, so we can't determine if it should be rounded or not. Default is "do not round".
@@ -0,0 +1,105 @@ | |||
import { parseRelativeString, parseRelativeParts } from '../parse_relative_parts'; | |||
import { expect } from 'chai'; |
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.
Have we decided to move to Chai? Afaik it's just used in Timelion. I don't wanna be a killjoy but... it gets confusing if we start mixing assertion libraries within a given plugin.
@Bargs For the first thing you pointed out there is weirdness in the relative date code that has an edge case where when something is on the cusp of a whole week it returns days. If that's important we should create a separate issue and PR to fix it since it's outside the scope of this change. I believe the rest of your concerns have been addressed. |
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.
Had one tiny question about a variable name, otherwise LGTM!
let results = {}; | ||
const matches = _.isString(part) && part.match(/now(([\-\+])([0-9]+)([smhdwMy])(\/[smhdwMy])?)?/); | ||
|
||
const isNotNow = matches && !matches[1]; |
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.
Shouldn't this be isNow
?
@Bargs Yeah... I'm not sure what I was thinking... fixed |
* Closes elastic#2394 - Allow relative from and to * Closes elastic#6732 - Adding support future realtive for time picker
Closes #2394.
Closes #6732.
This PR allows you to define a relative "to" string.
Before:
After: