Skip to content

Commit

Permalink
feat: add dashboard and receivers fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Feb 28, 2024
1 parent da122e4 commit aca86f3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
7 changes: 5 additions & 2 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-21T09:54:31.937Z\n"
"PO-Revision-Date: 2024-02-21T09:54:31.937Z\n"
"POT-Creation-Date: 2024-02-28T13:31:16.191Z\n"
"PO-Revision-Date: 2024-02-28T13:31:16.191Z\n"

msgid "Something went wrong"
msgstr "Something went wrong"
Expand Down Expand Up @@ -453,6 +453,9 @@ msgstr "Event programs data sync"
msgid "File resource clean up"
msgstr "File resource clean up"

msgid "HTML push analytics"
msgstr "HTML push analytics"

msgid "GEOJSON import"
msgstr "GEOJSON import"

Expand Down
20 changes: 13 additions & 7 deletions src/components/FormFields/LabeledOptionsField.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import React from 'react'
import PropTypes from 'prop-types'
import { MultiSelectFieldFF, ReactFinalForm, MultiSelectField } from '@dhis2/ui'
import {
MultiSelectFieldFF,
SingleSelectFieldFF,
ReactFinalForm,
SingleSelectField,
} from '@dhis2/ui'
import i18n from '@dhis2/d2-i18n'
import { useParameterOption } from '../../hooks/parameter-options'

const { Field } = ReactFinalForm

// A labeled options field has options that have both an id and a label.
const LabeledOptionsField = ({ label, name, parameterName }) => {
const LabeledOptionsField = ({ label, name, parameterName, multiple }) => {
const { loading, error, data } = useParameterOption(parameterName)
const disabledProps = { disabled: true, label }

if (loading) {
return (
<MultiSelectField
<SingleSelectField
{...disabledProps}
helpText={i18n.t('Loading options')}
/>
Expand All @@ -22,7 +27,7 @@ const LabeledOptionsField = ({ label, name, parameterName }) => {

if (error) {
return (
<MultiSelectField
<SingleSelectField
{...disabledProps}
helpText={i18n.t('Something went wrong whilst loading options')}
/>
Expand All @@ -31,7 +36,7 @@ const LabeledOptionsField = ({ label, name, parameterName }) => {

if (data.length === 0) {
return (
<MultiSelectField
<SingleSelectField
{...disabledProps}
helpText={i18n.t('No options available')}
/>
Expand All @@ -46,19 +51,20 @@ const LabeledOptionsField = ({ label, name, parameterName }) => {
return (
<Field
name={name}
component={MultiSelectFieldFF}
component={multiple ? MultiSelectFieldFF : SingleSelectFieldFF}
options={labeledOptions}
label={label}
/>
)
}

const { string } = PropTypes
const { string, bool } = PropTypes

LabeledOptionsField.propTypes = {
label: string.isRequired,
name: string.isRequired,
parameterName: string.isRequired,
multiple: bool,
}

export default LabeledOptionsField
9 changes: 9 additions & 0 deletions src/components/FormFields/ParameterFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ const getCustomComponent = (jobType, parameterName) => {

return null
case 'HTML_PUSH_ANALYTICS':
if (parameterName === 'dashboard') {
return LabeledOptionsField
} else if (parameterName === 'receivers') {
return LabeledOptionsField
} else if (parameterName === 'mode') {
return null
}

return null
default:
return null
Expand Down Expand Up @@ -137,6 +145,7 @@ const ParameterFields = ({ jobType }) => {
<LabeledOptionsField
{...defaultProps}
parameterName={name}
multiple
/>
)
break
Expand Down
14 changes: 13 additions & 1 deletion src/hooks/parameter-options/use-parameter-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ const query = {
dataIntegrityChecks: {
resource: 'dataIntegrity',
},
dashboard: {
resource: 'dashboards',
},
receivers: {
resource: 'userGroups',
},
}

const useParameterOptions = () => {
Expand All @@ -45,14 +51,18 @@ const useParameterOptions = () => {
const predictors = fetch.data?.predictors?.predictors
const predictorGroups = fetch.data?.predictorGroups?.predictorGroups
const dataIntegrityChecks = fetch.data?.dataIntegrityChecks
const dashboard = fetch.data?.dashboard?.dashboards
const receivers = fetch.data?.receivers?.userGroups

if (
!skipTableTypes ||
!validationRuleGroups ||
!pushAnalysis ||
!predictors ||
!predictorGroups ||
!dataIntegrityChecks
!dataIntegrityChecks ||
!dashboard ||
!receivers
) {
const error = new Error(
'Did not receive the expected parameter options'
Expand All @@ -67,6 +77,8 @@ const useParameterOptions = () => {
predictors,
predictorGroups,
dataIntegrityChecks,
dashboard,
receivers,
}

return { ...fetch, data }
Expand Down

0 comments on commit aca86f3

Please sign in to comment.