diff --git a/frontend/common/utils/utils.tsx b/frontend/common/utils/utils.tsx index ef8f56367aed..e41c5d49f722 100644 --- a/frontend/common/utils/utils.tsx +++ b/frontend/common/utils/utils.tsx @@ -506,7 +506,7 @@ const Utils = Object.assign({}, require('./base/_utils'), { } const typedValue = testWithTrim ? str.trim() : str - const isNum = /^\d+$/.test(typedValue) + const isNum = /^-?\d+$/.test(typedValue) if (isNum && parseInt(typedValue) > Number.MAX_SAFE_INTEGER) { return `${str}` diff --git a/frontend/web/components/Feature.js b/frontend/web/components/Feature.js index 7d149631d6e7..bbe6597b4e54 100644 --- a/frontend/web/components/Feature.js +++ b/frontend/web/components/Feature.js @@ -7,10 +7,31 @@ import AddVariationButton from './mv/AddVariationButton' import ErrorMessage from './ErrorMessage' import Tooltip from './Tooltip' import Icon from './Icon' +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 @@ -102,13 +123,30 @@ export default class Feature extends PureComponent { } tooltip={`${Constants.strings.REMOTE_CONFIG_DESCRIPTION}${ !isEdit - ? '
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.' + ? '
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}`} /> )} + {this.state.isNegativeNumberString && ( + + This feature currently has the value of{' '} + "{environmentFlag?.feature_state_value}". + 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 using the{' '} + + API + + . + + } + /> + )} {!!error && (