Keep time units upon time entry

Fixes: #26549

Signed-off-by: Hynek Mlnarik <hmlnarik@redhat.com>
This commit is contained in:
Hynek Mlnarik 2024-02-02 15:35:38 +01:00 committed by Hynek Mlnařík
parent 0e1f3ec402
commit 0df5452507

View file

@ -60,6 +60,8 @@ export const TimeSelector = ({
}: TimeSelectorProps) => {
const { t } = useTranslation();
const [lastMultiplier, setLastMultiplier] = useState<number>();
const defaultMultiplier = useMemo(
() => allTimes.find((time) => time.unit === units[0])?.multiplier,
[units],
@ -88,9 +90,11 @@ export const TimeSelector = ({
if (value) {
setMultiplier(multiplier);
setTimeValue(value / multiplier);
setLastMultiplier(multiplier);
} else {
setTimeValue(value || "");
setMultiplier(defaultMultiplier);
setMultiplier(lastMultiplier ?? defaultMultiplier);
setLastMultiplier(lastMultiplier ?? defaultMultiplier);
}
}, [value, defaultMultiplier]);