Skip to content

Commit

Permalink
feat: configure options for Outlier table vis type (DHIS2-16347)
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Dec 20, 2023
1 parent a41012b commit 7f54ec3
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/components/VisualizationOptions/Options/MaxResults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import i18n from '@dhis2/d2-i18n'
import React from 'react'
import NumberBaseType from './NumberBaseType.js'

const MaxResults = () => (
<NumberBaseType
width="70px"
label={i18n.t('Max results')}
option={{
name: 'maxResults',
}}
min={1}
max={500}
dataTest={'max-results'}
/>
)

export default MaxResults
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import i18n from '@dhis2/d2-i18n'
import { Checkbox, FieldSet, Help, Legend } from '@dhis2/ui'

Check failure on line 2 in src/components/VisualizationOptions/Options/OutliersForOutliersTable.js

View workflow job for this annotation

GitHub Actions / lint

'Checkbox' is defined but never used

Check failure on line 2 in src/components/VisualizationOptions/Options/OutliersForOutliersTable.js

View workflow job for this annotation

GitHub Actions / lint

'Help' is defined but never used

Check failure on line 2 in src/components/VisualizationOptions/Options/OutliersForOutliersTable.js

View workflow job for this annotation

GitHub Actions / lint

'Checkbox' is defined but never used

Check failure on line 2 in src/components/VisualizationOptions/Options/OutliersForOutliersTable.js

View workflow job for this annotation

GitHub Actions / lint

'Help' is defined but never used

Check failure on line 2 in src/components/VisualizationOptions/Options/OutliersForOutliersTable.js

View workflow job for this annotation

GitHub Actions / lint

'Checkbox' is defined but never used

Check failure on line 2 in src/components/VisualizationOptions/Options/OutliersForOutliersTable.js

View workflow job for this annotation

GitHub Actions / lint

'Help' is defined but never used
import PropTypes from 'prop-types'
import React from 'react'
import { connect } from 'react-redux'
import { acSetUiOptions } from '../../../actions/ui.js'
import { sGetUiOptions } from '../../../reducers/ui.js'
import styles from '../styles/Outliers.module.css'

Check failure on line 8 in src/components/VisualizationOptions/Options/OutliersForOutliersTable.js

View workflow job for this annotation

GitHub Actions / lint

'styles' is defined but never used

Check failure on line 8 in src/components/VisualizationOptions/Options/OutliersForOutliersTable.js

View workflow job for this annotation

GitHub Actions / lint

'styles' is defined but never used

Check failure on line 8 in src/components/VisualizationOptions/Options/OutliersForOutliersTable.js

View workflow job for this annotation

GitHub Actions / lint

'styles' is defined but never used
import {
tabSectionOption,
tabSectionTitle,
} from '../styles/VisualizationOptions.style.js'
import OutlierDetectionMethod from './OutlierDetectionMethod.js'

const METHOD_PROP = 'outlierMethod'
const THRESHOLD_PROP = 'thresholdFactor'

const OUTLIER_ANALYSIS_OPTION_NAME = 'outlierAnalysis'

const METHOD_STANDARD_Z_SCORE = 'STANDARD_Z_SCORE'
const METHOD_MODIFIED_Z_SCORE = 'MODIFIED_Z_SCORE'
const methods = [
{
id: METHOD_STANDARD_Z_SCORE,
label: i18n.t('Z-score / Standard score'),
defaultThreshold: 3,
},
{
id: METHOD_MODIFIED_Z_SCORE,
label: i18n.t('Modified Z-score'),
defaultThreshold: 3,
},
]

const DEFAULT_STATE = {
[METHOD_PROP]: METHOD_MODIFIED_Z_SCORE,
[THRESHOLD_PROP]: 3,
}

const dataTest = 'option-outliers'

Check failure on line 40 in src/components/VisualizationOptions/Options/OutliersForOutliersTable.js

View workflow job for this annotation

GitHub Actions / lint

'dataTest' is assigned a value but never used

Check failure on line 40 in src/components/VisualizationOptions/Options/OutliersForOutliersTable.js

View workflow job for this annotation

GitHub Actions / lint

'dataTest' is assigned a value but never used

Check failure on line 40 in src/components/VisualizationOptions/Options/OutliersForOutliersTable.js

View workflow job for this annotation

GitHub Actions / lint

'dataTest' is assigned a value but never used

const Outliers = ({ outlierAnalysis, onChange }) => {
const storeProp = (prop, value) =>
onChange({ ...outlierAnalysis, [prop]: value })

return (
<div className={tabSectionOption.className}>
<FieldSet>
<Legend>
<span className={tabSectionTitle.className}>
{i18n.t('Outlier detection method')}
</span>
</Legend>
<div className={tabSectionOption.className}>
<OutlierDetectionMethod
methods={methods}
onMethodChange={(value) =>
onChange({
...outlierAnalysis,
[METHOD_PROP]: value,
[THRESHOLD_PROP]: methods.find(
(item) => item.id === value
).defaultThreshold,
})
}
onThresholdChange={(value) =>
storeProp(THRESHOLD_PROP, value)
}
currentMethodId={outlierAnalysis[METHOD_PROP]}
currentThreshold={outlierAnalysis[THRESHOLD_PROP]}
/>
</div>
</FieldSet>
</div>
)
}

Outliers.propTypes = {
outlierAnalysis: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
}

const mapStateToProps = (state) => ({
outlierAnalysis:
sGetUiOptions(state)[OUTLIER_ANALYSIS_OPTION_NAME] || DEFAULT_STATE,
})

const mapDispatchToProps = (dispatch) => ({
onChange: (value) =>
dispatch(acSetUiOptions({ [OUTLIER_ANALYSIS_OPTION_NAME]: value })),
})

export default connect(mapStateToProps, mapDispatchToProps)(Outliers)
4 changes: 4 additions & 0 deletions src/modules/options/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
VIS_TYPE_GAUGE,
VIS_TYPE_SINGLE_VALUE,
VIS_TYPE_SCATTER,
VIS_TYPE_OUTLIERS_TABLE,

Check failure on line 7 in src/modules/options/config.js

View workflow job for this annotation

GitHub Actions / lint

VIS_TYPE_OUTLIERS_TABLE not found in '@dhis2/analytics'

Check failure on line 7 in src/modules/options/config.js

View workflow job for this annotation

GitHub Actions / lint

VIS_TYPE_OUTLIERS_TABLE not found in '@dhis2/analytics'

Check failure on line 7 in src/modules/options/config.js

View workflow job for this annotation

GitHub Actions / lint

VIS_TYPE_OUTLIERS_TABLE not found in '@dhis2/analytics'
isStacked as isStackedType,
isLegendSetType,
isMultiType,
Expand All @@ -17,6 +18,7 @@ import pieConfig from './pieConfig.js'
import pivotTableConfig from './pivotTableConfig.js'
import scatterConfig from './scatterConfig.js'
import singleValueConfig from './singleValueConfig.js'
import outliersTableConfig from './outliersTableConfig.js'

Check failure on line 21 in src/modules/options/config.js

View workflow job for this annotation

GitHub Actions / lint

`./outliersTableConfig.js` import should occur before import of `./pieConfig.js`

Check failure on line 21 in src/modules/options/config.js

View workflow job for this annotation

GitHub Actions / lint

`./outliersTableConfig.js` import should occur before import of `./pieConfig.js`

Check failure on line 21 in src/modules/options/config.js

View workflow job for this annotation

GitHub Actions / lint

`./outliersTableConfig.js` import should occur before import of `./pieConfig.js`

export const getOptionsByType = ({
type,
Expand Down Expand Up @@ -60,6 +62,8 @@ export const getOptionsByType = ({
})
case VIS_TYPE_SCATTER:
return scatterConfig()
case VIS_TYPE_OUTLIERS_TABLE:
return outliersTableConfig(defaultProps)
default:
return defaultConfig(defaultProps)
}
Expand Down
36 changes: 36 additions & 0 deletions src/modules/options/outliersTableConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react'
import DigitGroupSeparator from '../../components/VisualizationOptions/Options/DigitGroupSeparator.js'
import DisplayDensity from '../../components/VisualizationOptions/Options/DisplayDensity.js'
import FontSize from '../../components/VisualizationOptions/Options/FontSize.js'
import MaxResults from '../../components/VisualizationOptions/Options/MaxResults.js'
import Outliers from '../../components/VisualizationOptions/Options/OutliersForOutliersTable.js'
import ShowHierarchy from '../../components/VisualizationOptions/Options/ShowHierarchy.js'
import getDataTab from './tabs/data.js'
import getOutliersTab from './tabs/outliers.js'
import getStyleTab from './tabs/style.js'

export default () => [
getDataTab([
{
key: 'data-section-1',
content: React.Children.toArray([<MaxResults />]),
},
]),
getStyleTab([
{
key: 'style-section-1',
content: React.Children.toArray([
<DisplayDensity />,
<FontSize />,
<DigitGroupSeparator />,
<ShowHierarchy />,
]),
},
]),
getOutliersTab([
{
key: 'outliers-section-1',
content: React.Children.toArray([<Outliers />]),
},
]),
]

0 comments on commit 7f54ec3

Please sign in to comment.