From aca86f3e8f95716fe90fe3a9f5fa8f0ff0241abe Mon Sep 17 00:00:00 2001 From: ismay Date: Wed, 28 Feb 2024 15:02:10 +0100 Subject: [PATCH] feat: add dashboard and receivers fields --- i18n/en.pot | 7 +++++-- .../FormFields/LabeledOptionsField.js | 20 ++++++++++++------- src/components/FormFields/ParameterFields.js | 9 +++++++++ .../use-parameter-options.js | 14 ++++++++++++- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index 41d86b9f0..b9261aa96 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-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" @@ -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" diff --git a/src/components/FormFields/LabeledOptionsField.js b/src/components/FormFields/LabeledOptionsField.js index bebe55429..41f6322b3 100644 --- a/src/components/FormFields/LabeledOptionsField.js +++ b/src/components/FormFields/LabeledOptionsField.js @@ -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 ( - @@ -22,7 +27,7 @@ const LabeledOptionsField = ({ label, name, parameterName }) => { if (error) { return ( - @@ -31,7 +36,7 @@ const LabeledOptionsField = ({ label, name, parameterName }) => { if (data.length === 0) { return ( - @@ -46,19 +51,20 @@ const LabeledOptionsField = ({ label, name, parameterName }) => { return ( ) } -const { string } = PropTypes +const { string, bool } = PropTypes LabeledOptionsField.propTypes = { label: string.isRequired, name: string.isRequired, parameterName: string.isRequired, + multiple: bool, } export default LabeledOptionsField diff --git a/src/components/FormFields/ParameterFields.js b/src/components/FormFields/ParameterFields.js index a7a746718..87e4b9e1b 100644 --- a/src/components/FormFields/ParameterFields.js +++ b/src/components/FormFields/ParameterFields.js @@ -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 @@ -137,6 +145,7 @@ const ParameterFields = ({ jobType }) => { ) break diff --git a/src/hooks/parameter-options/use-parameter-options.js b/src/hooks/parameter-options/use-parameter-options.js index a7c4748f7..cda6f22d7 100644 --- a/src/hooks/parameter-options/use-parameter-options.js +++ b/src/hooks/parameter-options/use-parameter-options.js @@ -31,6 +31,12 @@ const query = { dataIntegrityChecks: { resource: 'dataIntegrity', }, + dashboard: { + resource: 'dashboards', + }, + receivers: { + resource: 'userGroups', + }, } const useParameterOptions = () => { @@ -45,6 +51,8 @@ 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 || @@ -52,7 +60,9 @@ const useParameterOptions = () => { !pushAnalysis || !predictors || !predictorGroups || - !dataIntegrityChecks + !dataIntegrityChecks || + !dashboard || + !receivers ) { const error = new Error( 'Did not receive the expected parameter options' @@ -67,6 +77,8 @@ const useParameterOptions = () => { predictors, predictorGroups, dataIntegrityChecks, + dashboard, + receivers, } return { ...fetch, data }