From e0a641014b6b3a57bd940b7bb65b3b7716594768 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Wed, 18 Dec 2024 18:08:46 +0100 Subject: [PATCH] feat: show link to Maintenance app --- i18n/en.pot | 10 ++- .../DataDimension/Info/InfoTable.js | 71 ++++++++++++++++++- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index 14f570fdd..768937f8c 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-12-18T13:00:25.697Z\n" -"PO-Revision-Date: 2024-12-18T13:00:25.697Z\n" +"POT-Creation-Date: 2024-12-18T15:51:04.775Z\n" +"PO-Revision-Date: 2024-12-18T15:51:04.775Z\n" msgid "view only" msgstr "view only" @@ -261,6 +261,12 @@ msgstr "Indicator type" msgid "Decimals in output" msgstr "Decimals in output" +msgid "Maintenance link" +msgstr "Maintenance link" + +msgid "Open in Maintenance app" +msgstr "Open in Maintenance app" + msgid "There was a problem loading information for this data item." msgstr "There was a problem loading information for this data item." diff --git a/src/components/DataDimension/Info/InfoTable.js b/src/components/DataDimension/Info/InfoTable.js index 55f633273..572b66730 100644 --- a/src/components/DataDimension/Info/InfoTable.js +++ b/src/components/DataDimension/Info/InfoTable.js @@ -1,9 +1,19 @@ -import { useTimeZoneConversion } from '@dhis2/app-runtime' +import { useConfig, useTimeZoneConversion } from '@dhis2/app-runtime' import { Center, CircularLoader } from '@dhis2/ui' import moment from 'moment' import PropTypes from 'prop-types' import React from 'react' import i18n from '../../../locales/index.js' +import { REPORTING_RATE } from '../../../modules/dataSets.js' // data sets +import { + DIMENSION_TYPE_DATA_ELEMENT, // data element totals + DIMENSION_TYPE_DATA_ELEMENT_OPERAND, // data element details + DIMENSION_TYPE_INDICATOR, + DIMENSION_TYPE_PROGRAM_ATTRIBUTE, // event data items + DIMENSION_TYPE_PROGRAM_DATA_ELEMENT, // event data items + DIMENSION_TYPE_PROGRAM_INDICATOR, +} from '../../../modules/dataTypes.js' +import { useDataDimensionContext } from '../DataDimension.js' import styles from './styles/InfoPopover.style.js' export const getCommonFields = (displayNameProp) => @@ -95,8 +105,58 @@ export const renderLegendSets = (legendSets) => { ) } -export const InfoTable = ({ data, error, loading, children }) => { +const renderMaintenanceLink = ({ baseUrl, authorities, type, id }) => { + const maintenanceAppAuthority = 'M_dhis-web-maintenance' + const canOpenMaintenanceApp = Array.isArray(authorities) + ? authorities.includes(maintenanceAppAuthority) + : authorities.has(maintenanceAppAuthority) + + const maintenanceUrlMap = { + [DIMENSION_TYPE_INDICATOR]: '/edit/indicatorSection/indicator/', + [DIMENSION_TYPE_DATA_ELEMENT]: '/edit/dataElementSection/dataElement/', + [DIMENSION_TYPE_DATA_ELEMENT_OPERAND]: + '/edit/dataElementSection/dataElement/', + [DIMENSION_TYPE_PROGRAM_ATTRIBUTE]: + '/edit/programSection/trackedEntityAttribute/', + [DIMENSION_TYPE_PROGRAM_DATA_ELEMENT]: + '/edit/dataElementSection/dataElement/', + [DIMENSION_TYPE_PROGRAM_INDICATOR]: + '/edit/indicatorSection/programIndicator/', + [REPORTING_RATE]: '/edit/dataSetSection/dataSet/', + } + + // not everyone has access to Maintenance app + // calculations don't have a page in Maintenance + if (!canOpenMaintenanceApp || !maintenanceUrlMap[type]) { + return null + } + + const maintenanceUrl = new URL( + `dhis-web-maintenance/index.html#${maintenanceUrlMap[type]}${id}`, + baseUrl === '..' + ? window.location.href.split('dhis-web-data-visualizer/')[0] + : `${baseUrl}/` + ).href + + return ( + <> + + {i18n.t('Maintenance link')} + + + {i18n.t('Open in Maintenance app')} + + + + + + ) +} + +export const InfoTable = ({ type, data, error, loading, children }) => { const { fromServerDate } = useTimeZoneConversion() + const { baseUrl } = useConfig() + const { currentUser } = useDataDimensionContext() return ( <> @@ -193,6 +253,12 @@ export const InfoTable = ({ data, error, loading, children }) => { + {renderMaintenanceLink({ + baseUrl, + authorities: currentUser?.authorities, + type, + id: data.id, + })} {data.attributeValues.map( ({ attribute, value }) => ( @@ -215,4 +281,5 @@ InfoTable.propTypes = { data: PropTypes.object, error: PropTypes.string, loading: PropTypes.bool, + type: PropTypes.string, }