From 461f8246153d560a178e0ca424884920e53e097f Mon Sep 17 00:00:00 2001 From: ismay Date: Thu, 14 Mar 2024 11:28:45 +0100 Subject: [PATCH] feat: add test policy field --- .../FormFields/Custom/TestPolicyField.js | 47 +++++++++++++++++++ src/components/FormFields/ParameterFields.js | 7 +++ src/services/server-translations/index.js | 1 + .../server-translations/testPolicies.js | 11 +++++ 4 files changed, 66 insertions(+) create mode 100644 src/components/FormFields/Custom/TestPolicyField.js create mode 100644 src/services/server-translations/testPolicies.js diff --git a/src/components/FormFields/Custom/TestPolicyField.js b/src/components/FormFields/Custom/TestPolicyField.js new file mode 100644 index 00000000..fb8ad115 --- /dev/null +++ b/src/components/FormFields/Custom/TestPolicyField.js @@ -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 ( + + ) + } + + const options = constants.map((option) => ({ + value: option, + label: testPolicies[option] || option, + })) + + return ( + + ) +} + +const { string, arrayOf } = PropTypes + +TestPolicyField.propTypes = { + constants: arrayOf(string).isRequired, + label: string.isRequired, + name: string.isRequired, +} + +export default TestPolicyField diff --git a/src/components/FormFields/ParameterFields.js b/src/components/FormFields/ParameterFields.js index b47772e2..c743e943 100644 --- a/src/components/FormFields/ParameterFields.js +++ b/src/components/FormFields/ParameterFields.js @@ -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' @@ -64,6 +65,12 @@ const getCustomComponent = (jobType, parameterName) => { return PushAnalyticsModeField } + return null + case 'TEST': + if (parameterName === 'failWithPolicy') { + return TestPolicyField + } + return null default: return null diff --git a/src/services/server-translations/index.js b/src/services/server-translations/index.js index f340ef06..7f190427 100644 --- a/src/services/server-translations/index.js +++ b/src/services/server-translations/index.js @@ -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' diff --git a/src/services/server-translations/testPolicies.js b/src/services/server-translations/testPolicies.js new file mode 100644 index 00000000..f22434f1 --- /dev/null +++ b/src/services/server-translations/testPolicies.js @@ -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