Skip to content

Commit

Permalink
Update packages/core/src/context/experiment/experiment-reducers.ts
Browse files Browse the repository at this point in the history
Refactor suggestion count logic

Co-authored-by: Jakob Langdal <[email protected]>
  • Loading branch information
j-or and langdal authored Nov 9, 2023
1 parent 724c9a8 commit 367b4d1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/core/src/context/experiment/experiment-reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down

0 comments on commit 367b4d1

Please sign in to comment.