Skip to content

Commit

Permalink
put back the code that make everything works (#49643)
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Oct 29, 2019
1 parent 02978c3 commit fac7b07
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,18 @@ interface UpdateReduxTime extends OnTimeChangeProps {
timelineId?: string;
}

interface ReturnUpdateReduxTime {
kqlHaveBeenUpdated: boolean;
}

export type DispatchUpdateReduxTime = ({
end,
id,
isQuickSelection,
kql,
start,
timelineId,
}: UpdateReduxTime) => void;
}: UpdateReduxTime) => ReturnUpdateReduxTime;

interface SuperDatePickerDispatchProps {
setDuration: ({ id, duration }: { id: InputsModelId; duration: number }) => void;
Expand Down Expand Up @@ -105,7 +110,7 @@ export const SuperDatePickerComponent = React.memo<SuperDatePickerProps>(
);
const onRefresh = useCallback(
({ start: newStart, end: newEnd }: OnRefreshProps): void => {
updateReduxTime({
const { kqlHaveBeenUpdated } = updateReduxTime({
end: newEnd,
id,
isInvalid: false,
Expand All @@ -118,7 +123,10 @@ export const SuperDatePickerComponent = React.memo<SuperDatePickerProps>(
const currentEnd = isQuickSelection
? formatDate(newEnd, { roundUp: true })
: formatDate(newEnd);
if (!isQuickSelection || (start === currentStart && end === currentEnd)) {
if (
!kqlHaveBeenUpdated &&
(!isQuickSelection || (start === currentStart && end === currentEnd))
) {
refetchQuery(queries);
}
},
Expand Down Expand Up @@ -217,9 +225,10 @@ export const dispatchUpdateReduxTime = (dispatch: Dispatch) => ({
end,
id,
isQuickSelection,
kql,
start,
timelineId,
}: UpdateReduxTime): void => {
}: UpdateReduxTime): ReturnUpdateReduxTime => {
const fromDate = formatDate(start);
let toDate = formatDate(end, { roundUp: true });
if (isQuickSelection) {
Expand Down Expand Up @@ -251,6 +260,15 @@ export const dispatchUpdateReduxTime = (dispatch: Dispatch) => ({
})
);
}
if (kql) {
return {
kqlHaveBeenUpdated: kql.refetch(dispatch),
};
}

return {
kqlHaveBeenUpdated: false,
};
};

export const makeMapStateToProps = () => {
Expand Down

0 comments on commit fac7b07

Please sign in to comment.