Skip to content

Commit

Permalink
fix: variation percentage calculation (#3268)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Jan 19, 2024
1 parent ead0e31 commit ec272ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 6 additions & 4 deletions frontend/web/components/Feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export default class Feature extends PureComponent {

const enabledString = isEdit ? 'Enabled' : 'Enabled by default'
const disabled = hide_from_client
const controlValue = Utils.calculateControl(multivariate_options)
const controlPercentage = Utils.calculateControl(multivariate_options)
const valueString = identity
? 'User override'
: !!multivariate_options && multivariate_options.length
? `Control Value - ${controlValue}%`
? `Control Value - ${controlPercentage}%`
: `Value (optional)${' - these can be set per environment'}`

const showValue = !(
Expand Down Expand Up @@ -103,7 +103,8 @@ export default class Feature extends PureComponent {
<VariationOptions
disabled
select
controlValue={environmentFlag.feature_state_value}
controlValue={environmentFlag?.feature_state_value}
controlPercentage={controlPercentage}
variationOverrides={this.props.identityVariations}
setVariations={this.props.onChangeIdentityVariations}
updateVariation={() => {}}
Expand All @@ -121,7 +122,8 @@ export default class Feature extends PureComponent {
{(!!environmentVariations || !isEdit) && (
<VariationOptions
disabled={!!identity || readOnly}
controlValue={controlValue}
controlValue={environmentFlag?.feature_state_value}
controlPercentage={controlPercentage}
variationOverrides={environmentVariations}
updateVariation={this.props.updateVariation}
weightTitle={
Expand Down
8 changes: 6 additions & 2 deletions frontend/web/components/SegmentOverrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ const SegmentOverrideInner = class Override extends React.Component {
<Row className='gap-3'>
<Tooltip
title={
<label className='cols-sm-2 control-label mb-0 ml-3'><Icon name='info-outlined' /></label>
<label className='cols-sm-2 control-label mb-0 ml-3'>
<Icon name='info-outlined' />
</label>
}
>
Set the Feature state to On or Off for Identities in this Segment
Set the Feature state to On or Off for Identities in this
Segment
</Tooltip>
<Switch
data-test={`segment-override-toggle-${index}`}
Expand Down Expand Up @@ -312,6 +315,7 @@ const SegmentOverrideInner = class Override extends React.Component {
readOnlyValue
disabled={readOnly}
controlValue={controlValue}
controlPercentage={controlPercent}
variationOverrides={mvOptions}
multivariateOptions={multivariateOptions.map((mv) => {
const foundMv =
Expand Down
8 changes: 6 additions & 2 deletions frontend/web/components/mv/VariationOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import InfoMessage from 'components/InfoMessage'
import ErrorMessage from 'components/ErrorMessage'

export default function VariationOptions({
controlPercentage,
controlValue,
disabled,
multivariateOptions,
Expand All @@ -18,7 +19,7 @@ export default function VariationOptions({
variationOverrides,
weightTitle,
}) {
const invalid = multivariateOptions.length && controlValue < 0
const invalid = multivariateOptions.length && controlPercentage < 0
if (!multivariateOptions || !multivariateOptions.length) {
return null
}
Expand All @@ -28,7 +29,10 @@ export default function VariationOptions({
return (
<>
{invalid && (
<ErrorMessage error='Your variation percentage splits total to over 100%' />
<ErrorMessage
className='mt-2'
error='Your variation percentage splits total to over 100%'
/>
)}
{!preventRemove && (
<p className='mb-4'>
Expand Down

3 comments on commit ec272ba

@vercel
Copy link

@vercel vercel bot commented on ec272ba Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs.flagsmith.com
docs-flagsmith.vercel.app
docs.bullet-train.io
docs-git-main-flagsmith.vercel.app

@vercel
Copy link

@vercel vercel bot commented on ec272ba Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on ec272ba Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.