1
+ import { merge } from 'lodash' ;
1
2
import React , { CSSProperties } from 'react' ;
2
- import { useSelector } from 'react-redux' ;
3
+ // eslint-disable-next-line no-restricted-imports
4
+ import { useDispatch , useSelector } from 'react-redux' ;
3
5
4
6
import { TimeRange , isDateTime , toUtc } from '@grafana/data' ;
5
7
import { TimeRangePickerProps , TimeRangePicker , useTheme2 } from '@grafana/ui' ;
6
- import { FnGlobalState } from 'app/core/reducers/fn-slice' ;
8
+ import { FnGlobalState , updatePartialFnStates } from 'app/core/reducers/fn-slice' ;
7
9
import { StoreState } from 'app/types' ;
8
10
9
11
import { LocalStorageValueProvider } from '../LocalStorageValueProvider' ;
@@ -22,14 +24,22 @@ const FnText: React.FC = () => {
22
24
} ;
23
25
24
26
export const TimePickerWithHistory : React . FC < Props > = ( props ) => {
27
+ const { fnGlobalTimeRange } = useSelector < StoreState , FnGlobalState > ( ( { fnGlobalState } ) => fnGlobalState ) ;
28
+ const dispatch = useDispatch ( ) ;
29
+
25
30
return (
26
31
< LocalStorageValueProvider < TimeRange [ ] > storageKey = { LOCAL_STORAGE_KEY } defaultValue = { [ ] } >
27
32
{ ( values , onSaveToStore ) => {
28
33
return (
29
34
< TimeRangePicker
30
- { ...props }
35
+ { ...merge ( { } , props , { value : fnGlobalTimeRange || props . value } ) }
31
36
history = { convertIfJson ( values ) }
32
37
onChange = { ( value ) => {
38
+ dispatch (
39
+ updatePartialFnStates ( {
40
+ fnGlobalTimeRange : value ,
41
+ } )
42
+ ) ;
33
43
onAppendToHistory ( value , values , onSaveToStore ) ;
34
44
props . onChange ( value ) ;
35
45
} }
0 commit comments