Skip to content

Commit

Permalink
feat: add push analytics mode field
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Feb 29, 2024
1 parent aca86f3 commit 5596c30
Show file tree
Hide file tree
Showing 22 changed files with 103 additions and 40 deletions.
34 changes: 20 additions & 14 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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."

Expand All @@ -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."

Expand All @@ -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"

Expand All @@ -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\""

Expand Down Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
47 changes: 47 additions & 0 deletions src/components/FormFields/Custom/PushAnalyticsModeField.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 { pushAnalyticsModes } from '../../../services/server-translations'

const { Field } = ReactFinalForm

const PushAnalyticsModeField = ({ 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: pushAnalyticsModes[option] || option,
}))

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

const { string, arrayOf } = PropTypes

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

export default PushAnalyticsModeField
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 11 additions & 9 deletions src/components/FormFields/ParameterFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -51,7 +53,7 @@ const getCustomComponent = (jobType, parameterName) => {
} else if (parameterName === 'receivers') {
return LabeledOptionsField
} else if (parameterName === 'mode') {
return null
return PushAnalyticsModeField
}

return null
Expand Down Expand Up @@ -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}`,
Expand All @@ -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 (
<Box marginTop="16px" key={name}>
Expand All @@ -110,7 +113,6 @@ const ParameterFields = ({ jobType }) => {
}

// Generic field rendering
let parameterComponent = null
switch (klass) {
case 'java.lang.String':
parameterComponent = (
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -30,7 +30,7 @@ const CustomOption = ({
)
}

CustomOption.propTypes = {
QueueOption.propTypes = {
highlighted: bool.isRequired,
label: string.isRequired,
type: string.isRequired,
Expand All @@ -39,4 +39,4 @@ CustomOption.propTypes = {
onDoubleClick: func.isRequired,
}

export default CustomOption
export default QueueOption
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/components/FormFields/QueueOrderField/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -22,7 +22,7 @@ const QueueTransfer = ({ options, input, meta }) => {
<Transfer
options={options}
selected={value}
renderOption={CustomOption}
renderOption={QueueOption}
filterable
filterPlaceholder={i18n.t('Filter jobs')}
enableOrderChange
Expand Down
2 changes: 1 addition & 1 deletion src/components/FormFields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export { default as JobTypeField } from './JobTypeField'
export { default as NameField } from './NameField'
export { default as ParameterFields } from './ParameterFields'
export { default as ScheduleField } from './ScheduleField'
export { QueueOrderField } from './QueueOrderField'
export { default as QueueOrderField } from './QueueOrderField'

export { fieldNames }
1 change: 1 addition & 0 deletions src/services/server-translations/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,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'
8 changes: 8 additions & 0 deletions src/services/server-translations/pushAnalyticsModes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import i18n from '@dhis2/d2-i18n'

const pushAnalyticsModes = {
EXECUTOR: i18n.t('Executor'),
RECEIVER: i18n.t('Receiver'),
}

export default pushAnalyticsModes

0 comments on commit 5596c30

Please sign in to comment.