From 367b4d1f006505b3c87e6add50c5611726592ac3 Mon Sep 17 00:00:00 2001 From: Jack Ord <36296721+j-or@users.noreply.github.com> Date: Thu, 9 Nov 2023 10:14:21 +0100 Subject: [PATCH] Update packages/core/src/context/experiment/experiment-reducers.ts Refactor suggestion count logic Co-authored-by: Jakob Langdal --- .../src/context/experiment/experiment-reducers.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/core/src/context/experiment/experiment-reducers.ts b/packages/core/src/context/experiment/experiment-reducers.ts index 08a5c3fb..755b59a1 100644 --- a/packages/core/src/context/experiment/experiment-reducers.ts +++ b/packages/core/src/context/experiment/experiment-reducers.ts @@ -187,13 +187,12 @@ export const experimentReducer = produce( break case 'updateSuggestionCount': { const payloadVal = Number(action.payload.suggestionCount) - const maxSuggestionCount = action.payload.maxSuggestionCount - let actualVal = payloadVal - if (maxSuggestionCount !== undefined) { - actualVal = - payloadVal <= maxSuggestionCount ? payloadVal : maxSuggestionCount - } - state.extras.experimentSuggestionCount = actualVal >= 1 ? actualVal : 1 + const maxSuggestionCount = + action.payload.maxSuggestionCount ?? Number.MAX_VALUE + state.extras.experimentSuggestionCount = Math.max( + 1, + Math.min(maxSuggestionCount, payloadVal) + ) break } case 'copySuggestedToDataPoints': {