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' ;
53
64import { TimeRange , isDateTime , rangeUtil } from '@grafana/data' ;
75import { 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' ;
107
118import { LocalStorageValueProvider } from '../LocalStorageValueProvider' ;
129
@@ -24,7 +21,7 @@ interface TimePickerHistoryItem {
2421type LSTimePickerHistoryItem = TimePickerHistoryItem | TimeRange ;
2522
2623const FnText : React . FC = ( ) => {
27- const { FNDashboard } = useSelector < StoreState , FnGlobalState > ( ( { fnGlobalState } ) => fnGlobalState ) ;
24+ const { FNDashboard } = useSelector ( ( { fnGlobalState } ) => fnGlobalState ) ;
2825 const theme = useTheme2 ( ) ;
2926
3027 const FN_TEXT_STYLE : CSSProperties = { fontWeight : 700 , fontSize : 14 , marginLeft : 8 } ;
@@ -47,32 +44,9 @@ export interface PickerProps {
4744}
4845
4946export const Picker : FC < PickerProps > = ( { rawValues, onSaveToStore, pickerProps } ) => {
50- const { fnGlobalTimeRange } = useSelector < StoreState , FnGlobalState > ( ( { fnGlobalState } ) => fnGlobalState ) ;
51- const dispatch = useDispatch ( ) ;
52-
5347 const values = migrateHistory ( rawValues ) ;
5448 const history = deserializeHistory ( values ) ;
5549
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-
7650 return (
7751 < TimeRangePicker
7852 { ...pickerProps }
0 commit comments