Skip to content

Commit fb5d60f

Browse files
authored
Calling the set methods only when the relative time's unit and value changes (#6010)
1 parent c09ced4 commit fb5d60f

File tree

1 file changed

+16
-0
lines changed
  • ui/packages/shared/components/src/DateTimeRangePicker/RelativeDatePicker

1 file changed

+16
-0
lines changed

ui/packages/shared/components/src/DateTimeRangePicker/RelativeDatePicker/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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]);

0 commit comments

Comments
 (0)