Skip to content

Commit

Permalink
feat: show link to Maintenance app
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Dec 18, 2024
1 parent 7286c2a commit e0a6410
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
10 changes: 8 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-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"
Expand Down Expand Up @@ -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."

Expand Down
71 changes: 69 additions & 2 deletions src/components/DataDimension/Info/InfoTable.js
Original file line number Diff line number Diff line change
@@ -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) =>
Expand Down Expand Up @@ -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 (
<>
<tr>
<th>{i18n.t('Maintenance link')}</th>
<td>
<a href={maintenanceUrl} target="_blank" rel="noreferrer">
{i18n.t('Open in Maintenance app')}
</a>
</td>
</tr>
<style jsx>{styles}</style>
</>
)
}

export const InfoTable = ({ type, data, error, loading, children }) => {
const { fromServerDate } = useTimeZoneConversion()
const { baseUrl } = useConfig()
const { currentUser } = useDataDimensionContext()

return (
<>
Expand Down Expand Up @@ -193,6 +253,12 @@ export const InfoTable = ({ data, error, loading, children }) => {
</a>
</td>
</tr>
{renderMaintenanceLink({
baseUrl,
authorities: currentUser?.authorities,
type,
id: data.id,
})}
{data.attributeValues.map(
({ attribute, value }) => (
<tr key={attribute.id}>
Expand All @@ -215,4 +281,5 @@ InfoTable.propTypes = {
data: PropTypes.object,
error: PropTypes.string,
loading: PropTypes.bool,
type: PropTypes.string,
}

0 comments on commit e0a6410

Please sign in to comment.