-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Decimals and Steps options only allow positive values (DHIS2-900…
…2, DHIS2-9194) v33 (#1254)
- Loading branch information
1 parent
6dce3f4
commit 8b51823
Showing
5 changed files
with
93 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/app/src/components/VisualizationOptions/Options/PositiveNumberBaseType.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import TextField from '@material-ui/core/TextField'; | ||
|
||
import { sGetUiOptions } from '../../../reducers/ui'; | ||
import { acSetUiOptions } from '../../../actions/ui'; | ||
|
||
export const PositiveNumberBaseType = ({ | ||
label, | ||
placeholder, | ||
helpText, | ||
width, | ||
option, | ||
value, | ||
onChange, | ||
disabled, | ||
}) => ( | ||
<TextField | ||
type="number" | ||
label={option.label} | ||
onChange={event => { | ||
const value = event.target.value; | ||
const parsedValue = parseInt(value, 10); | ||
parsedValue >= 0 | ||
? onChange(Math.round(value)) | ||
: onChange(parsedValue ? 0 : null); | ||
}} | ||
name={option.name} | ||
value={value || value === 0 ? value.toString() : ''} | ||
placeholder={placeholder} | ||
disabled={disabled} | ||
helperText={option.helperText} | ||
/> | ||
); | ||
|
||
PositiveNumberBaseType.propTypes = { | ||
disabled: PropTypes.bool, | ||
helpText: PropTypes.string, | ||
label: PropTypes.string, | ||
option: PropTypes.object, | ||
placeholder: PropTypes.string, | ||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
width: PropTypes.string, | ||
onChange: PropTypes.func, | ||
}; | ||
|
||
const mapStateToProps = (state, ownProps) => ({ | ||
value: sGetUiOptions(state)[ownProps.option.name], | ||
enabled: sGetUiOptions(state)[ownProps.option.name] !== undefined, | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch, ownProps) => ({ | ||
onChange: value => | ||
dispatch(acSetUiOptions({ [ownProps.option.name]: value })), | ||
}); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(PositiveNumberBaseType); |
8 changes: 5 additions & 3 deletions
8
packages/app/src/components/VisualizationOptions/Options/RangeAxisDecimals.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
packages/app/src/components/VisualizationOptions/Options/RangeAxisSteps.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters