Skip to content

Commit

Permalink
feat: add test policy field
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay authored and ismay committed Mar 18, 2024
1 parent ce486eb commit 461f824
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/components/FormFields/Custom/TestPolicyField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import PropTypes from 'prop-types'
import i18n from '@dhis2/d2-i18n'
import {
SingleSelectField,
ReactFinalForm,
SingleSelectFieldFF,
} from '@dhis2/ui'
import { testPolicies } from '../../../services/server-translations'

const { Field } = ReactFinalForm

const TestPolicyField = ({ label, name, constants }) => {
if (constants.length === 0) {
return (
<SingleSelectField
label={label}
helpText={i18n.t('No options available')}
disabled
/>
)
}

const options = constants.map((option) => ({
value: option,
label: testPolicies[option] || option,
}))

return (
<Field
name={name}
component={SingleSelectFieldFF}
options={options}
label={label}
/>
)
}

const { string, arrayOf } = PropTypes

TestPolicyField.propTypes = {
constants: arrayOf(string).isRequired,
label: string.isRequired,
name: string.isRequired,
}

export default TestPolicyField
7 changes: 7 additions & 0 deletions src/components/FormFields/ParameterFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import DataIntegrityChecksField from './Custom/DataIntegrityChecksField'
import DataIntegrityReportTypeField from './Custom/DataIntegrityReportTypeField'
import AggregatedDataExchangeField from './Custom/AggregatedDataExchangeField'
import PushAnalyticsModeField from './Custom/PushAnalyticsModeField'
import TestPolicyField from './Custom/TestPolicyField'
import styles from './ParameterFields.module.css'
import ListFieldSingle from './ListFieldSingle'
import ListFieldMulti from './ListFieldMulti'
Expand Down Expand Up @@ -64,6 +65,12 @@ const getCustomComponent = (jobType, parameterName) => {
return PushAnalyticsModeField
}

return null
case 'TEST':
if (parameterName === 'failWithPolicy') {
return TestPolicyField
}

return null
default:
return null
Expand Down
1 change: 1 addition & 0 deletions src/services/server-translations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as analyticsTableTypes } from './analyticsTableTypes'
export { default as jobTypesMap } from './jobTypesMap'
export { default as jobStatusMap } from './jobStatusMap'
export { default as pushAnalyticsModes } from './pushAnalyticsModes'
export { default as testPolicies } from './testPolicies'
11 changes: 11 additions & 0 deletions src/services/server-translations/testPolicies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import i18n from '@dhis2/d2-i18n'

const testPolicies = {
PARENT: i18n.t('Parent'),
FAIL: i18n.t('Fail'),
SKIP_STAGE: i18n.t('Skip stage'),
SKIP_ITEM: i18n.t('Skip item'),
SKIP_ITEM_OUTLIER: i18n.t('Skip item outlier'),
}

export default testPolicies

1 comment on commit 461f824

@dhis2-bot
Copy link
Contributor

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.