fix: update the time filter for 'Last Year' option in explore (#10829)

* Update explore time filter ranges

* rm console statements

* only update moment calculation for years

* tests

* add open/close test
This commit is contained in:
Moriah Kreeger
2020-09-21 11:39:11 -07:00
committed by GitHub
parent 56d001835e
commit 4aa53244c7
2 changed files with 101 additions and 40 deletions

View File

@@ -128,22 +128,23 @@ function getStateFromSeparator(value) {
function getStateFromCommonTimeFrame(value) {
const units = `${value.split(' ')[1]}s`;
let sinceMoment;
if (value === 'No filter') {
sinceMoment = '';
} else if (units === 'years') {
sinceMoment = moment().utc().startOf(units).subtract(1, units);
} else {
sinceMoment = moment().utc().startOf('day').subtract(1, units);
}
return {
tab: TABS.DEFAULTS,
type: TYPES.DEFAULTS,
common: value,
since:
value === 'No filter'
? ''
: moment()
.utc()
.startOf('day')
.subtract(1, units)
.format(MOMENT_FORMAT),
since: sinceMoment === '' ? '' : sinceMoment.format(MOMENT_FORMAT),
until:
value === 'No filter'
? ''
: moment().utc().startOf('day').format(MOMENT_FORMAT),
sinceMoment === '' ? '' : sinceMoment.add(1, units).format(MOMENT_FORMAT),
};
}
@@ -396,7 +397,6 @@ class DateFilterControl extends React.Component {
));
const timeFrames = COMMON_TIME_FRAMES.map(timeFrame => {
const nextState = getStateFromCommonTimeFrame(timeFrame);
const timeRange = buildTimeRangeString(nextState.since, nextState.until);
return (