add 'seconds' unit if value not valid (#20240)

fixes: #17165
This commit is contained in:
Erik Jan de Wit 2023-05-11 18:10:15 +02:00 committed by GitHub
parent 46782ec139
commit 4326a46dd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,11 +60,6 @@ export const TimeSelector = ({
}: TimeSelectorProps) => {
const { t } = useTranslation("common");
const times = useMemo(
() => units.map((unit) => allTimes.find((time) => time.unit === unit)!),
[units]
);
const defaultMultiplier = useMemo(
() => allTimes.find((time) => time.unit === units[0])?.multiplier,
[units]
@ -74,6 +69,16 @@ export const TimeSelector = ({
const [multiplier, setMultiplier] = useState(defaultMultiplier);
const [open, setOpen] = useState(false);
const times = useMemo(() => {
const filteredUnits = units.map(
(unit) => allTimes.find((time) => time.unit === unit)!
);
if (!filteredUnits.every((u) => u.multiplier === multiplier)) {
filteredUnits.unshift(allTimes[0]);
}
return filteredUnits;
}, [units, multiplier]);
useEffect(() => {
const multiplier = getTimeUnit(value).multiplier;