From 5596c30bad7671cff7cb8b0d300db5434dab696f Mon Sep 17 00:00:00 2001 From: ismay Date: Thu, 29 Feb 2024 18:01:10 +0100 Subject: [PATCH] feat: add push analytics mode field --- i18n/en.pot | 34 ++++++++------ .../AggregatedDataExchangeField.js | 0 .../AggregatedDataExchangeField.module.css | 0 .../AggregatedDataExchangeField.test.js | 0 .../{ => Custom}/DataIntegrityChecksField.js | 4 +- .../DataIntegrityChecksField.module.css | 0 .../DataIntegrityReportTypeField.js | 2 +- .../Custom/PushAnalyticsModeField.js | 47 +++++++++++++++++++ .../{ => Custom}/SkipTableTypesField.js | 4 +- .../{ => Custom}/SkipTableTypesField.test.js | 2 +- src/components/FormFields/ParameterFields.js | 20 ++++---- .../CustomOption.js => QueueOption.js} | 8 ++-- ...tion.module.css => QueueOption.module.css} | 0 .../{QueueOrderField => }/QueueOrderField.js | 4 +- .../QueueOrderField.test.js | 2 +- .../FormFields/QueueOrderField/index.js | 1 - .../{QueueOrderField => }/QueueTransfer.js | 4 +- .../QueueTransferTitle.js | 0 .../QueueTransferTitle.module.css | 0 src/components/FormFields/index.js | 2 +- src/services/server-translations/index.js | 1 + .../server-translations/pushAnalyticsModes.js | 8 ++++ 22 files changed, 103 insertions(+), 40 deletions(-) rename src/components/FormFields/{ => Custom}/AggregatedDataExchangeField.js (100%) rename src/components/FormFields/{ => Custom}/AggregatedDataExchangeField.module.css (100%) rename src/components/FormFields/{ => Custom}/AggregatedDataExchangeField.test.js (100%) rename src/components/FormFields/{ => Custom}/DataIntegrityChecksField.js (96%) rename src/components/FormFields/{ => Custom}/DataIntegrityChecksField.module.css (100%) rename src/components/FormFields/{ => Custom}/DataIntegrityReportTypeField.js (91%) create mode 100644 src/components/FormFields/Custom/PushAnalyticsModeField.js rename src/components/FormFields/{ => Custom}/SkipTableTypesField.js (91%) rename src/components/FormFields/{ => Custom}/SkipTableTypesField.test.js (96%) rename src/components/FormFields/{QueueOrderField/CustomOption.js => QueueOption.js} (89%) rename src/components/FormFields/{QueueOrderField/CustomOption.module.css => QueueOption.module.css} (100%) rename src/components/FormFields/{QueueOrderField => }/QueueOrderField.js (92%) rename src/components/FormFields/{QueueOrderField => }/QueueOrderField.test.js (96%) delete mode 100644 src/components/FormFields/QueueOrderField/index.js rename src/components/FormFields/{QueueOrderField => }/QueueTransfer.js (94%) rename src/components/FormFields/{QueueOrderField => }/QueueTransferTitle.js (100%) rename src/components/FormFields/{QueueOrderField => }/QueueTransferTitle.module.css (100%) create mode 100644 src/services/server-translations/pushAnalyticsModes.js diff --git a/i18n/en.pot b/i18n/en.pot index b9261aa96..0e0cf1940 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -5,8 +5,8 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" -"POT-Creation-Date: 2024-02-28T13:31:16.191Z\n" -"PO-Revision-Date: 2024-02-28T13:31:16.191Z\n" +"POT-Creation-Date: 2024-02-29T16:49:15.985Z\n" +"PO-Revision-Date: 2024-02-29T16:49:15.985Z\n" msgid "Something went wrong" msgstr "Something went wrong" @@ -33,6 +33,9 @@ msgstr "Delete job" msgid "Delete queue" msgstr "Delete queue" +msgid "CRON Expression" +msgstr "CRON Expression" + msgid "Please select data exchange ids." msgstr "Please select data exchange ids." @@ -45,9 +48,6 @@ msgstr "There was a problem fetching data exchange ids" msgid "error type" msgstr "error type" -msgid "CRON Expression" -msgstr "CRON Expression" - msgid "Please select checks to run." msgstr "Please select checks to run." @@ -72,6 +72,15 @@ msgstr "Select checks to run." msgid "Report type" msgstr "Report type" +msgid "Loading options" +msgstr "Loading options" + +msgid "Something went wrong whilst loading options" +msgstr "Something went wrong whilst loading options" + +msgid "No options available" +msgstr "No options available" + msgid "Delay" msgstr "Delay" @@ -87,15 +96,6 @@ msgstr "Loading job types" msgid "Something went wrong whilst loading job types" msgstr "Something went wrong whilst loading job types" -msgid "Loading options" -msgstr "Loading options" - -msgid "Something went wrong whilst loading options" -msgstr "Something went wrong whilst loading options" - -msgid "No options available" -msgstr "No options available" - msgid "Queues can't be named \"Add\" or \"add\"" msgstr "Queues can't be named \"Add\" or \"add\"" @@ -543,6 +543,12 @@ msgstr "Tracker search optimization" msgid "Validation results notification" msgstr "Validation results notification" +msgid "Executor" +msgstr "Executor" + +msgid "Receiver" +msgstr "Receiver" + msgid "A CRON expression is required" msgstr "A CRON expression is required" diff --git a/src/components/FormFields/AggregatedDataExchangeField.js b/src/components/FormFields/Custom/AggregatedDataExchangeField.js similarity index 100% rename from src/components/FormFields/AggregatedDataExchangeField.js rename to src/components/FormFields/Custom/AggregatedDataExchangeField.js diff --git a/src/components/FormFields/AggregatedDataExchangeField.module.css b/src/components/FormFields/Custom/AggregatedDataExchangeField.module.css similarity index 100% rename from src/components/FormFields/AggregatedDataExchangeField.module.css rename to src/components/FormFields/Custom/AggregatedDataExchangeField.module.css diff --git a/src/components/FormFields/AggregatedDataExchangeField.test.js b/src/components/FormFields/Custom/AggregatedDataExchangeField.test.js similarity index 100% rename from src/components/FormFields/AggregatedDataExchangeField.test.js rename to src/components/FormFields/Custom/AggregatedDataExchangeField.test.js diff --git a/src/components/FormFields/DataIntegrityChecksField.js b/src/components/FormFields/Custom/DataIntegrityChecksField.js similarity index 96% rename from src/components/FormFields/DataIntegrityChecksField.js rename to src/components/FormFields/Custom/DataIntegrityChecksField.js index 44eb4d61d..2bf5f5ebb 100644 --- a/src/components/FormFields/DataIntegrityChecksField.js +++ b/src/components/FormFields/Custom/DataIntegrityChecksField.js @@ -13,8 +13,8 @@ import { Help, } from '@dhis2/ui' import cx from 'classnames' -import { useParameterOption } from '../../hooks/parameter-options' -import { severityMap } from '../../services/server-translations/dataIntegrityChecks' +import { useParameterOption } from '../../../hooks/parameter-options' +import { severityMap } from '../../../services/server-translations/dataIntegrityChecks' import styles from './DataIntegrityChecksField.module.css' const { Field, useField } = ReactFinalForm diff --git a/src/components/FormFields/DataIntegrityChecksField.module.css b/src/components/FormFields/Custom/DataIntegrityChecksField.module.css similarity index 100% rename from src/components/FormFields/DataIntegrityChecksField.module.css rename to src/components/FormFields/Custom/DataIntegrityChecksField.module.css diff --git a/src/components/FormFields/DataIntegrityReportTypeField.js b/src/components/FormFields/Custom/DataIntegrityReportTypeField.js similarity index 91% rename from src/components/FormFields/DataIntegrityReportTypeField.js rename to src/components/FormFields/Custom/DataIntegrityReportTypeField.js index 8454c2ad9..45fbcbb4b 100644 --- a/src/components/FormFields/DataIntegrityReportTypeField.js +++ b/src/components/FormFields/Custom/DataIntegrityReportTypeField.js @@ -2,7 +2,7 @@ import React from 'react' import PropTypes from 'prop-types' import { SingleSelectFieldFF, ReactFinalForm } from '@dhis2/ui' import i18n from '@dhis2/d2-i18n' -import { getReportTypeLabel } from '../../services/server-translations/dataIntegrityChecks' +import { getReportTypeLabel } from '../../../services/server-translations/dataIntegrityChecks' const { Field } = ReactFinalForm diff --git a/src/components/FormFields/Custom/PushAnalyticsModeField.js b/src/components/FormFields/Custom/PushAnalyticsModeField.js new file mode 100644 index 000000000..1ec6ced11 --- /dev/null +++ b/src/components/FormFields/Custom/PushAnalyticsModeField.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 { pushAnalyticsModes } from '../../../services/server-translations' + +const { Field } = ReactFinalForm + +const PushAnalyticsModeField = ({ label, name, constants }) => { + if (constants.length === 0) { + return ( + + ) + } + + const options = constants.map((option) => ({ + value: option, + label: pushAnalyticsModes[option] || option, + })) + + return ( + + ) +} + +const { string, arrayOf } = PropTypes + +PushAnalyticsModeField.propTypes = { + constants: arrayOf(string).isRequired, + label: string.isRequired, + name: string.isRequired, +} + +export default PushAnalyticsModeField diff --git a/src/components/FormFields/SkipTableTypesField.js b/src/components/FormFields/Custom/SkipTableTypesField.js similarity index 91% rename from src/components/FormFields/SkipTableTypesField.js rename to src/components/FormFields/Custom/SkipTableTypesField.js index 5b5d52bca..0bc8a59d1 100644 --- a/src/components/FormFields/SkipTableTypesField.js +++ b/src/components/FormFields/Custom/SkipTableTypesField.js @@ -2,8 +2,8 @@ import React from 'react' import PropTypes from 'prop-types' import i18n from '@dhis2/d2-i18n' import { MultiSelectField, ReactFinalForm, MultiSelectFieldFF } from '@dhis2/ui' -import { analyticsTableTypes } from '../../services/server-translations' -import { useParameterOption } from '../../hooks/parameter-options' +import { analyticsTableTypes } from '../../../services/server-translations' +import { useParameterOption } from '../../../hooks/parameter-options' const { Field } = ReactFinalForm diff --git a/src/components/FormFields/SkipTableTypesField.test.js b/src/components/FormFields/Custom/SkipTableTypesField.test.js similarity index 96% rename from src/components/FormFields/SkipTableTypesField.test.js rename to src/components/FormFields/Custom/SkipTableTypesField.test.js index 751fca68a..cfefe3fb3 100644 --- a/src/components/FormFields/SkipTableTypesField.test.js +++ b/src/components/FormFields/Custom/SkipTableTypesField.test.js @@ -1,7 +1,7 @@ import React from 'react' import { mount } from 'enzyme' import { ReactFinalForm } from '@dhis2/ui' -import { useParameterOption } from '../../hooks/parameter-options' +import { useParameterOption } from '../../../hooks/parameter-options' import SkipTableTypesField from './SkipTableTypesField' const { Form } = ReactFinalForm diff --git a/src/components/FormFields/ParameterFields.js b/src/components/FormFields/ParameterFields.js index 87e4b9e1b..84cb297d4 100644 --- a/src/components/FormFields/ParameterFields.js +++ b/src/components/FormFields/ParameterFields.js @@ -9,19 +9,21 @@ import { SwitchFieldFF, } from '@dhis2/ui' import { useJobTypeParameters } from '../../hooks/job-types' -import { formatToString } from './formatters' -import SkipTableTypesField from './SkipTableTypesField' -import LabeledOptionsField from './LabeledOptionsField' -import DataIntegrityChecksField from './DataIntegrityChecksField' -import DataIntegrityReportTypeField from './DataIntegrityReportTypeField' +import SkipTableTypesField from './Custom/SkipTableTypesField' +import DataIntegrityChecksField from './Custom/DataIntegrityChecksField' +import DataIntegrityReportTypeField from './Custom/DataIntegrityReportTypeField' +import AggregatedDataExchangeField from './Custom/AggregatedDataExchangeField' +import PushAnalyticsModeField from './Custom/PushAnalyticsModeField' import styles from './ParameterFields.module.css' -import AggregatedDataExchangeField from './AggregatedDataExchangeField' +import LabeledOptionsField from './LabeledOptionsField' +import { formatToString } from './formatters' const { Field } = ReactFinalForm // The key under which the parameters will be sent to the backend const FIELD_NAME = 'jobParameters' +// Overrides for fields where the generic types aren't appropriate const getCustomComponent = (jobType, parameterName) => { switch (jobType) { case 'DATA_INTEGRITY': @@ -51,7 +53,7 @@ const getCustomComponent = (jobType, parameterName) => { } else if (parameterName === 'receivers') { return LabeledOptionsField } else if (parameterName === 'mode') { - return null + return PushAnalyticsModeField } return null @@ -84,6 +86,7 @@ const ParameterFields = ({ jobType }) => { // Map all parameters to the appropriate field types const parameterComponents = data.map( ({ fieldName, name, klass, ...rest }) => { + let parameterComponent = null const defaultProps = { label: fieldName, name: `${FIELD_NAME}.${name}`, @@ -95,8 +98,8 @@ const ParameterFields = ({ jobType }) => { ...rest, } - // Fields that can't be handled by the generic fields const CustomParameterComponent = getCustomComponent(jobType, name) + if (CustomParameterComponent) { return ( @@ -110,7 +113,6 @@ const ParameterFields = ({ jobType }) => { } // Generic field rendering - let parameterComponent = null switch (klass) { case 'java.lang.String': parameterComponent = ( diff --git a/src/components/FormFields/QueueOrderField/CustomOption.js b/src/components/FormFields/QueueOption.js similarity index 89% rename from src/components/FormFields/QueueOrderField/CustomOption.js rename to src/components/FormFields/QueueOption.js index c526e2fa4..5237509e1 100644 --- a/src/components/FormFields/QueueOrderField/CustomOption.js +++ b/src/components/FormFields/QueueOption.js @@ -1,11 +1,11 @@ import React from 'react' import cx from 'classnames' import PropTypes from 'prop-types' -import styles from './CustomOption.module.css' +import styles from './QueueOption.module.css' const { bool, func, string } = PropTypes -const CustomOption = ({ +const QueueOption = ({ label, value, type, @@ -30,7 +30,7 @@ const CustomOption = ({ ) } -CustomOption.propTypes = { +QueueOption.propTypes = { highlighted: bool.isRequired, label: string.isRequired, type: string.isRequired, @@ -39,4 +39,4 @@ CustomOption.propTypes = { onDoubleClick: func.isRequired, } -export default CustomOption +export default QueueOption diff --git a/src/components/FormFields/QueueOrderField/CustomOption.module.css b/src/components/FormFields/QueueOption.module.css similarity index 100% rename from src/components/FormFields/QueueOrderField/CustomOption.module.css rename to src/components/FormFields/QueueOption.module.css diff --git a/src/components/FormFields/QueueOrderField/QueueOrderField.js b/src/components/FormFields/QueueOrderField.js similarity index 92% rename from src/components/FormFields/QueueOrderField/QueueOrderField.js rename to src/components/FormFields/QueueOrderField.js index 7d3feb82a..886c813b2 100644 --- a/src/components/FormFields/QueueOrderField/QueueOrderField.js +++ b/src/components/FormFields/QueueOrderField.js @@ -2,8 +2,8 @@ import React from 'react' import PropTypes from 'prop-types' import { ReactFinalForm, CircularLoader, NoticeBox } from '@dhis2/ui' import i18n from '@dhis2/d2-i18n' -import { jobTypesMap } from '../../../services/server-translations' -import { useQueueables } from '../../../hooks/queueables' +import { jobTypesMap } from '../../services/server-translations' +import { useQueueables } from '../../hooks/queueables' import QueueTransfer from './QueueTransfer' const { Field } = ReactFinalForm diff --git a/src/components/FormFields/QueueOrderField/QueueOrderField.test.js b/src/components/FormFields/QueueOrderField.test.js similarity index 96% rename from src/components/FormFields/QueueOrderField/QueueOrderField.test.js rename to src/components/FormFields/QueueOrderField.test.js index ac1bdedee..8fd0f3150 100644 --- a/src/components/FormFields/QueueOrderField/QueueOrderField.test.js +++ b/src/components/FormFields/QueueOrderField.test.js @@ -1,7 +1,7 @@ import React from 'react' import { mount } from 'enzyme' import { ReactFinalForm, CircularLoader } from '@dhis2/ui' -import { useQueueables } from '../../../hooks/queueables' +import { useQueueables } from '../../hooks/queueables' import QueueOrderField from './QueueOrderField' const { Form } = ReactFinalForm diff --git a/src/components/FormFields/QueueOrderField/index.js b/src/components/FormFields/QueueOrderField/index.js deleted file mode 100644 index f57d86ca8..000000000 --- a/src/components/FormFields/QueueOrderField/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as QueueOrderField } from './QueueOrderField' diff --git a/src/components/FormFields/QueueOrderField/QueueTransfer.js b/src/components/FormFields/QueueTransfer.js similarity index 94% rename from src/components/FormFields/QueueOrderField/QueueTransfer.js rename to src/components/FormFields/QueueTransfer.js index 7711e2e21..01964cf28 100644 --- a/src/components/FormFields/QueueOrderField/QueueTransfer.js +++ b/src/components/FormFields/QueueTransfer.js @@ -3,7 +3,7 @@ import i18n from '@dhis2/d2-i18n' import PropTypes from 'prop-types' import { Field, Transfer } from '@dhis2/ui' import QueueTransferTitle from './QueueTransferTitle' -import CustomOption from './CustomOption' +import QueueOption from './QueueOption' const { bool, arrayOf, shape, func, array, string } = PropTypes @@ -22,7 +22,7 @@ const QueueTransfer = ({ options, input, meta }) => {