1
- import { isEqual , uniqBy } from 'lodash' ;
2
- import { CSSProperties , FC , useEffect , useRef } from 'react' ;
3
- // eslint-disable-next-line no-restricted-imports
4
- import { useDispatch , useSelector } from 'react-redux' ;
1
+ import { uniqBy } from 'lodash' ;
2
+ import { CSSProperties , FC } from 'react' ;
5
3
6
4
import { TimeRange , isDateTime , rangeUtil } from '@grafana/data' ;
7
5
import { TimeRangePickerProps , TimeRangePicker , useTheme2 } from '@grafana/ui' ;
8
- import { FnGlobalState , updatePartialFnStates } from 'app/core/reducers/fn-slice' ;
9
- import { StoreState } from 'app/types' ;
6
+ import { useSelector } from 'app/types' ;
10
7
11
8
import { LocalStorageValueProvider } from '../LocalStorageValueProvider' ;
12
9
@@ -24,7 +21,7 @@ interface TimePickerHistoryItem {
24
21
type LSTimePickerHistoryItem = TimePickerHistoryItem | TimeRange ;
25
22
26
23
const FnText : React . FC = ( ) => {
27
- const { FNDashboard } = useSelector < StoreState , FnGlobalState > ( ( { fnGlobalState } ) => fnGlobalState ) ;
24
+ const { FNDashboard } = useSelector ( ( { fnGlobalState } ) => fnGlobalState ) ;
28
25
const theme = useTheme2 ( ) ;
29
26
30
27
const FN_TEXT_STYLE : CSSProperties = { fontWeight : 700 , fontSize : 14 , marginLeft : 8 } ;
@@ -47,32 +44,9 @@ export interface PickerProps {
47
44
}
48
45
49
46
export const Picker : FC < PickerProps > = ( { rawValues, onSaveToStore, pickerProps } ) => {
50
- const { fnGlobalTimeRange } = useSelector < StoreState , FnGlobalState > ( ( { fnGlobalState } ) => fnGlobalState ) ;
51
- const dispatch = useDispatch ( ) ;
52
-
53
47
const values = migrateHistory ( rawValues ) ;
54
48
const history = deserializeHistory ( values ) ;
55
49
56
- const didMountRef = useRef ( false ) ;
57
- useEffect ( ( ) => {
58
- /* The condition below skips the first run of useeffect that happens when this component gets mounted */
59
- if ( didMountRef . current ) {
60
- /* If the current timerange value has changed, update fnGlobalTimeRange */
61
- if ( ! isEqual ( fnGlobalTimeRange ?. raw , pickerProps . value . raw ) ) {
62
- dispatch (
63
- updatePartialFnStates ( {
64
- fnGlobalTimeRange : pickerProps . value ,
65
- } )
66
- ) ;
67
- }
68
- } else if ( fnGlobalTimeRange && ! isEqual ( fnGlobalTimeRange . raw , pickerProps . value . raw ) ) {
69
- /* If fnGlobalTimeRange exists in the initial render, set the time as that */
70
- pickerProps . onChange ( fnGlobalTimeRange ) ;
71
- }
72
-
73
- didMountRef . current = true ;
74
- } , [ dispatch , fnGlobalTimeRange , pickerProps ] ) ;
75
-
76
50
return (
77
51
< TimeRangePicker
78
52
{ ...pickerProps }
0 commit comments