From ec16a1cbce139728646a97ed193abed54b8bcbdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Wed, 29 Aug 2018 23:38:14 +0100 Subject: [PATCH] fix(ui): fix duration minute decrease handling Negative adjustment needs a different logic than positive one --- .../SilenceModal/DateTimeSelect/index.js | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ui/src/Components/SilenceModal/DateTimeSelect/index.js b/ui/src/Components/SilenceModal/DateTimeSelect/index.js index 6867d867a..650f0192c 100644 --- a/ui/src/Components/SilenceModal/DateTimeSelect/index.js +++ b/ui/src/Components/SilenceModal/DateTimeSelect/index.js @@ -107,8 +107,8 @@ const TabContentEnd = observer(({ silenceFormStore }) => { ); }); -// calculate value for duration increase and decrease buttons using a goal step -const CalculateChangeValue = (currentValue, step) => { +// calculate value for duration increase button using a goal step +const CalculateChangeValueUp = (currentValue, step) => { // if current value is less than step (but >0) then use 1 if (currentValue > 0 && currentValue < step) { return 1; @@ -117,6 +117,16 @@ const CalculateChangeValue = (currentValue, step) => { return step - (currentValue % step) || step; }; +// calculate value for duration decrease button using a goal step +const CalculateChangeValueDown = (currentValue, step) => { + // if current value is less than step (but >0) then use 1 + if (currentValue > 0 && currentValue < step) { + return 1; + } + // otherwise use step or a value that moves current value to the next step + return currentValue % step || step; +}; + const TabContentDuration = observer(({ silenceFormStore }) => { return (
@@ -137,12 +147,15 @@ const TabContentDuration = observer(({ silenceFormStore }) => { value={silenceFormStore.data.toDuration.minutes} onInc={() => silenceFormStore.data.incEnd( - CalculateChangeValue(silenceFormStore.data.toDuration.minutes, 5) + CalculateChangeValueUp(silenceFormStore.data.toDuration.minutes, 5) ) } onDec={() => silenceFormStore.data.decEnd( - CalculateChangeValue(silenceFormStore.data.toDuration.minutes, 5) + CalculateChangeValueDown( + silenceFormStore.data.toDuration.minutes, + 5 + ) ) } />