diff --git a/public/app/core/components/TimePicker/TimePickerWithHistory.tsx b/public/app/core/components/TimePicker/TimePickerWithHistory.tsx
index cb0d84bcc3583..c0ff897f4afd3 100644
--- a/public/app/core/components/TimePicker/TimePickerWithHistory.tsx
+++ b/public/app/core/components/TimePicker/TimePickerWithHistory.tsx
@@ -1,5 +1,5 @@
import { merge } from 'lodash';
-import React, { CSSProperties } from 'react';
+import React, { CSSProperties, FC, useEffect } from 'react';
// eslint-disable-next-line no-restricted-imports
import { useDispatch, useSelector } from 'react-redux';
@@ -23,31 +23,48 @@ const FnText: React.FC = () => {
return <>{FNDashboard ? UTC : ''}>;
};
-export const TimePickerWithHistory: React.FC = (props) => {
+export const TimePickerWithHistory: FC = (props) => (
+ storageKey={LOCAL_STORAGE_KEY} defaultValue={[]}>
+ {(values, onSaveToStore) => {
+ return ;
+ }}
+
+);
+
+export interface PickerProps {
+ values: TimeRange[];
+ onSaveToStore: (value: TimeRange[]) => void;
+ pickerProps: Props;
+}
+
+export const Picker: FC = ({ values, onSaveToStore, pickerProps }) => {
const { fnGlobalTimeRange } = useSelector(({ fnGlobalState }) => fnGlobalState);
const dispatch = useDispatch();
+ useEffect(() => {
+ if (!fnGlobalTimeRange) {
+ return;
+ }
+ onAppendToHistory(fnGlobalTimeRange, values, onSaveToStore);
+ pickerProps.onChange(fnGlobalTimeRange);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
return (
- storageKey={LOCAL_STORAGE_KEY} defaultValue={[]}>
- {(values, onSaveToStore) => {
- return (
- {
- dispatch(
- updatePartialFnStates({
- fnGlobalTimeRange: value,
- })
- );
- onAppendToHistory(value, values, onSaveToStore);
- props.onChange(value);
- }}
- fnText={}
- />
+ {
+ dispatch(
+ updatePartialFnStates({
+ fnGlobalTimeRange: value,
+ })
);
+ onAppendToHistory(value, values, onSaveToStore);
+ pickerProps.onChange(value);
}}
-
+ fnText={}
+ />
);
};
@@ -69,6 +86,7 @@ function onAppendToHistory(toAppend: TimeRange, values: TimeRange[], onSaveToSto
if (!isAbsolute(toAppend)) {
return;
}
+
const toStore = limit([toAppend, ...values]);
onSaveToStore(toStore);
}