-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[APM] Enabling yesterday option when 24 hours is selected #90017
Changes from 1 commit
14d8cd4
7619127
f80a99d
ed89e4b
b3362b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ const PrependContainer = styled.div` | |
padding: 0 ${px(unit)}; | ||
`; | ||
|
||
const weekDurationInHours = moment.duration(7, 'days').asHours(); | ||
|
||
function formatPreviousPeriodDates({ | ||
momentStart, | ||
momentEnd, | ||
|
@@ -38,7 +40,6 @@ function formatPreviousPeriodDates({ | |
function getSelectOptions({ start, end }: { start?: string; end?: string }) { | ||
const momentStart = moment(start); | ||
const momentEnd = moment(end); | ||
const dateDiff = getDateDifference(momentStart, momentEnd, 'days'); | ||
|
||
const yesterdayOption = { | ||
value: 'yesterday', | ||
|
@@ -59,13 +60,15 @@ function getSelectOptions({ start, end }: { start?: string; end?: string }) { | |
text: formatPreviousPeriodDates({ momentStart, momentEnd }), | ||
cauemarcondes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
const dateDiffInHours = getDateDifference(momentStart, momentEnd, 'hours'); | ||
|
||
// Less than one day | ||
if (dateDiff < 1) { | ||
if (dateDiffInHours <= 24) { | ||
return [yesterdayOption, aWeekAgoOption]; | ||
} | ||
|
||
// Less than one week | ||
if (dateDiff <= 7) { | ||
if (dateDiffInHours <= weekDurationInHours) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a test for this component? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! I'm still wondering why the test doesn't need updating when the implementation changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a few more tests, also to cover what was discussed in the comments below. |
||
return [aWeekAgoOption]; | ||
} | ||
|
||
|
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.
nit: There's always the vanilla option. Might also be the simplest to read:
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.
IMHO we should consider using moment here, but scoped to the current time, to deal with issues like DST. E.g.:
(we should figure out how exactly moment.subtract() deals with DST ofc)
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'll admit I'm not quite sure why we are using hours here, are we rounding?
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.
Btw, should this not be "a day before" and "a week before" (the current time range), rather than yesterday/a week ago?
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.
Good point. The current copy is only applicable if the end range is now.
I think we could keep the labels if we add a check like:
We might have to add some padding like:
If
isEndNow
is false we'll fall back toprevPeriodOption
which might be ok.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.
Good catch! And I agree, the more clear we can be with the relative time the easier it is to parse for the user. So if we can add a check as @sqren proposes, I'm very happy 👍
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.
That's why I thought we could add padding. But since rounding is up to 5 minutes we'd need a lot of padding so I agree, not a great solution.
Much better idea. Let's try to do that.
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.
@dgieselaar I switched to use
hours
because when I useddays
and the difference between the dates is for example25 hours
the days difference still returns1
. But I only want to show theyesterday
option when the difference is less or equal to 24 hours.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.
you can pass a third argument, a boolean, to diff to get a floating point number instead of an integer. then you could just use <= 1. https://jsfiddle.net/8whg49qj/
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.
thanks will do it