1
+ import { merge , uniqBy } from 'lodash' ;
1
2
import React , { CSSProperties } from 'react' ;
2
- import { useSelector } from 'react-redux' ;
3
- import { uniqBy } from 'lodash ' ;
3
+ // eslint-disable-next-line no-restricted-imports
4
+ import { useDispatch , useSelector } from 'react-redux ' ;
4
5
5
6
import { t } from '@grafana/ui/src/utils/i18n' ;
6
7
import appEvents from 'app/core/app_events' ;
7
8
import { TimeRange , isDateTime , rangeUtil , AppEvents } from '@grafana/data' ;
8
9
import { TimeRangePickerProps , TimeRangePicker , useTheme2 } from '@grafana/ui' ;
9
- import { FnGlobalState } from 'app/core/reducers/fn-slice' ;
10
+ import { FnGlobalState , updatePartialFnStates } from 'app/core/reducers/fn-slice' ;
10
11
import { StoreState } from 'app/types' ;
11
12
12
13
import { LocalStorageValueProvider } from '../LocalStorageValueProvider' ;
@@ -35,6 +36,9 @@ const FnText: React.FC = () => {
35
36
} ;
36
37
37
38
export const TimePickerWithHistory : React . FC < Props > = ( props ) => {
39
+ const { fnGlobalTimeRange } = useSelector < StoreState , FnGlobalState > ( ( { fnGlobalState } ) => fnGlobalState ) ;
40
+ const dispatch = useDispatch ( ) ;
41
+
38
42
return (
39
43
< LocalStorageValueProvider < LSTimePickerHistoryItem [ ] > storageKey = { LOCAL_STORAGE_KEY } defaultValue = { [ ] } >
40
44
{ ( rawValues , onSaveToStore ) => {
@@ -45,7 +49,13 @@ export const TimePickerWithHistory: React.FC<Props> = (props) => {
45
49
< TimeRangePicker
46
50
{ ...props }
47
51
history = { history }
52
+ { ...merge ( { } , props , { value : fnGlobalTimeRange || props . value } ) }
48
53
onChange = { ( value ) => {
54
+ dispatch (
55
+ updatePartialFnStates ( {
56
+ fnGlobalTimeRange : value ,
57
+ } )
58
+ ) ;
49
59
onAppendToHistory ( value , values , onSaveToStore ) ;
50
60
props . onChange ( value ) ;
51
61
} }
0 commit comments