Skip to content

Commit

Permalink
fix absolute today/this week on timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Nov 3, 2020
1 parent 24a86d4 commit 56662b7
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,28 @@ export const dispatchUpdateSearch = (dispatch: Dispatch) => ({
if (updateTime) {
const fromDate = formatDate(start);
let toDate = formatDate(end, { roundUp: true });
if (isQuickSelection && end !== start) {
dispatch(
inputsActions.setRelativeRangeDatePicker({
id,
fromStr: start,
toStr: end,
from: fromDate,
to: toDate,
})
);
if (isQuickSelection) {
if (end === start) {
dispatch(
inputsActions.setAbsoluteRangeDatePicker({
id,
fromStr: start,
toStr: end,
from: fromDate,
to: toDate,
})
);
} else {
dispatch(
inputsActions.setRelativeRangeDatePicker({
id,
fromStr: start,
toStr: end,
from: fromDate,
to: toDate,
})
);
}
} else {
toDate = formatDate(end);
dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ export const SuperDatePickerComponent = React.memo<SuperDatePickerProps>(
[recentlyUsedRanges, kqlQuery]
);

const endDate = kind === 'relative' ? toStr : new Date(end).toISOString();
const startDate = kind === 'relative' ? fromStr : new Date(start).toISOString();
const endDate = toStr != null ? toStr : new Date(end).toISOString();
const startDate = fromStr != null ? fromStr : new Date(start).toISOString();

const [quickRanges] = useUiSetting$<Range[]>(DEFAULT_TIMEPICKER_QUICK_RANGES);
const commonlyUsedRanges = isEmpty(quickRanges)
Expand Down Expand Up @@ -230,16 +230,28 @@ export const dispatchUpdateReduxTime = (dispatch: Dispatch) => ({
}: UpdateReduxTime): ReturnUpdateReduxTime => {
const fromDate = formatDate(start);
let toDate = formatDate(end, { roundUp: true });
if (isQuickSelection && end !== start) {
dispatch(
inputsActions.setRelativeRangeDatePicker({
id,
fromStr: start,
toStr: end,
from: fromDate,
to: toDate,
})
);
if (isQuickSelection) {
if (end === start) {
dispatch(
inputsActions.setAbsoluteRangeDatePicker({
id,
fromStr: start,
toStr: end,
from: fromDate,
to: toDate,
})
);
} else {
dispatch(
inputsActions.setRelativeRangeDatePicker({
id,
fromStr: start,
toStr: end,
from: fromDate,
to: toDate,
})
);
}
} else {
toDate = formatDate(end);
dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const setAbsoluteRangeDatePicker = actionCreator<{
id: InputsModelId;
from: string;
to: string;
fromStr?: string;
toStr?: string;
}>('SET_ABSOLUTE_RANGE_DATE_PICKER');

export const setTimelineRangeDatePicker = actionCreator<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { Query, Filter, SavedQuery } from '../../../../../../../src/plugins/data

export interface AbsoluteTimeRange {
kind: 'absolute';
fromStr: undefined;
toStr: undefined;
fromStr?: string;
toStr?: string;
from: string;
to: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,19 @@ export const inputsReducer = reducerWithInitialState(initialInputsState)
},
};
})
.case(setAbsoluteRangeDatePicker, (state, { id, from, to }) => {
const timerange: TimeRange = {
kind: 'absolute',
fromStr: undefined,
toStr: undefined,
from,
to,
};
return updateInputTimerange(id, timerange, state);
})
.case(
setAbsoluteRangeDatePicker,
(state, { id, from, to, fromStr = undefined, toStr = undefined }) => {
const timerange: TimeRange = {
kind: 'absolute',
fromStr,
toStr,
from,
to,
};
return updateInputTimerange(id, timerange, state);
}
)
.case(setRelativeRangeDatePicker, (state, { id, fromStr, from, to, toStr }) => {
const timerange: TimeRange = {
kind: 'relative',
Expand Down

0 comments on commit 56662b7

Please sign in to comment.