File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
ui/packages/shared/components/src/DateTimeRangePicker/RelativeDatePicker Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,14 @@ export const RelativeDatePickerForPanel = ({
7979 // absolute date range is converted to a relative date range and we then use the `onChange` prop to
8080 // update the range in the `RelativeDatePicker` component below.
8181 useEffect ( ( ) => {
82+ // Only update if the unit/value actually changed from what's in the range
83+ if ( range . from . isRelative ( ) ) {
84+ const currentFrom = range . from as RelativeDate ;
85+ if ( currentFrom . unit === unit && currentFrom . value === value ) {
86+ return ;
87+ }
88+ }
89+
8290 onChange ( new RelativeDate ( unit , value ) , createNow ( ) ) ;
8391 // eslint-disable-next-line react-hooks/exhaustive-deps
8492 } , [ unit , value ] ) ;
@@ -142,6 +150,14 @@ const RelativeDatePicker = ({
142150 useEffect ( ( ) => {
143151 const formattedRange = formatRange ( validRange . value , validRange . unit ) ;
144152 setRangeInputString ( formattedRange ) ;
153+
154+ // Only update if the value actually changed from what's in the range
155+ if ( range . from . isRelative ( ) ) {
156+ const currentFrom = range . from as RelativeDate ;
157+ if ( currentFrom . unit === validRange . unit && currentFrom . value === validRange . value ) {
158+ return ;
159+ }
160+ }
145161 onChange ( new RelativeDate ( validRange . unit , validRange . value ) , createNow ( ) ) ;
146162 // eslint-disable-next-line react-hooks/exhaustive-deps
147163 } , [ validRange ] ) ;
You can’t perform that action at this time.
0 commit comments