Skip to content

Commit

Permalink
Add negative value warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg committed Aug 14, 2024
1 parent 820aae8 commit d3bd37e
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion frontend/web/components/Feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,31 @@ import AddVariationButton from './mv/AddVariationButton'
import ErrorMessage from './ErrorMessage'
import Tooltip from './Tooltip'
import Icon from './Icon'
import Select from 'react-select'
import InputGroup from './base/forms/InputGroup'
import WarningMessage from './WarningMessage'
function isNegativeNumberString(str) {
if (typeof Utils.getTypedValue(str) !== 'number') {
return false
}
if (typeof str !== 'string') {
return false
}
const num = parseFloat(str)
return !isNaN(num) && num < 0
}

export default class Feature extends PureComponent {
static displayName = 'Feature'

constructor(props) {
super(props)
this.state = {
isNegativeNumberString: isNegativeNumberString(
props.environmentFlag?.feature_state_value,
),
}
}
removeVariation = (i) => {
const idToRemove = this.props.multivariate_options[i].id

Expand Down Expand Up @@ -102,13 +123,30 @@ export default class Feature extends PureComponent {
}
tooltip={`${Constants.strings.REMOTE_CONFIG_DESCRIPTION}${
!isEdit
? '<br/>Setting this when creating a feature will set the value for all environments. You can edit the this individually for each environment once the feature is created.'
? '<br/>Setting this when creating a feature will set the value for all environments. You can edit this individually for each environment once the feature is created.'
: ''
}`}
title={`${valueString}`}
/>
</FormGroup>
)}
{this.state.isNegativeNumberString && (
<WarningMessage
warningMessage={
<div>
This feature currently has the value of{' '}
<strong>"{environmentFlag?.feature_state_value}"</strong> as a
string. As of version <strong>2.137.0</strong>, saving this
feature will convert its value from a string to a number. If you
wish to preserve this value as a string, please save it via our
<a href='https://api.flagsmith.com/api/v1/docs/#/api/api_v1_environments_featurestates_update'>
API
</a>
.
</div>
}
/>
)}

{!!error && (
<div className='mx-2 mt-2'>
Expand Down

0 comments on commit d3bd37e

Please sign in to comment.