Skip to content

Commit

Permalink
fix: update list of fields to fetch by type
Browse files Browse the repository at this point in the history
Implement async request for human readable expressions for some types.
  • Loading branch information
edoardo committed Nov 8, 2024
1 parent fadf01d commit fd5fea8
Show file tree
Hide file tree
Showing 8 changed files with 620 additions and 167 deletions.
150 changes: 108 additions & 42 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-10-30T09:04:20.385Z\n"
"PO-Revision-Date: 2024-10-30T09:04:20.386Z\n"
"POT-Creation-Date: 2024-11-08T14:29:12.042Z\n"
"PO-Revision-Date: 2024-11-08T14:29:12.043Z\n"

msgid "view only"
msgstr "view only"
Expand Down Expand Up @@ -168,8 +168,23 @@ msgstr "Disaggregation"
msgid "No data"
msgstr "No data"

msgid "Expression"
msgstr "Expression"
msgid "Expression description in human readable format"
msgstr "Expression description in human readable format"

msgid "None"
msgstr "None"

msgid "Data set(s)"
msgstr "Data set(s)"

msgid "Zero is significant"
msgstr "Zero is significant"

msgid "True"
msgstr "True"

msgid "False"
msgstr "False"

msgid "Value type"
msgstr "Value type"
Expand All @@ -180,53 +195,116 @@ msgstr "Aggregation type"
msgid "Category combo"
msgstr "Category combo"

msgid "Data element groups"
msgstr "Data element groups"

msgid "Legend sets"
msgstr "Legend sets"

msgid "Zero is significant"
msgstr "Zero is significant"
msgid "Option set"
msgstr "Option set"

msgid "True"
msgstr "True"
msgid "Group membership"
msgstr "Group membership"

msgid "False"
msgstr "False"
msgid "Legend set(s)"
msgstr "Legend set(s)"

msgid "Period type"
msgstr "Period type"

msgid "Data set elements"
msgstr "Data set elements"
msgid "Indicators"
msgstr "Indicators"

msgid "Indicator type"
msgstr "Indicator type"
msgid "Expiry days"
msgstr "Expiry days"

msgid "Type"
msgstr "Type"

msgid "Data element"
msgstr "Data element"

msgid "Tracked entity attribute"
msgstr "Tracked entity attribute"

msgid "Numerator description"
msgstr "Numerator description"

msgid "Numerator expression in human readable format"
msgstr "Numerator expression in human readable format"

msgid "Denominator description"
msgstr "Denominator description"

msgid "Denominator expression in human readable format"
msgstr "Denominator expression in human readable format"

msgid "Annualized"
msgstr "Annualized"

msgid "Numerator"
msgstr "Numerator"
msgid "Yes"
msgstr "Yes"

msgid "Denominator"
msgstr "Denominator"
msgid "No"
msgstr "No"

msgid "Indicator type"
msgstr "Indicator type"

msgid "Decimals in output"
msgstr "Decimals in output"

msgid "Name"
msgstr "Name"

msgid "Description"
msgstr "Description"

msgid "Code"
msgstr "Code"

msgid "Description"
msgstr "Description"
msgid "ID"
msgstr "ID"

msgid "Last updated date"
msgstr "Last updated date"

msgid "Created date"
msgstr "Created date"

msgid "Created by"
msgstr "Created by"

msgid "Last updated"
msgstr "Last updated"
msgid "API link"
msgstr "API link"

msgid "Open in API"
msgstr "Open in API"

msgid "Custom attributes"
msgstr "Custom attributes"

msgid "Program"
msgstr "Program"

msgid "Analytics type"
msgstr "Analytics type"

msgid "Enrollment"
msgstr "Enrollment"

msgid "Event"
msgstr "Event"

msgid "Analytics period boundaries"
msgstr "Analytics period boundaries"

msgid "Target"
msgstr "Target"

msgid "Offset"
msgstr "Offset"

msgid "Expression in human readable format"
msgstr "Expression in human readable format"

msgid "Filter expression in human readable format"
msgstr "Filter expression in human readable format"

msgid "Search by data item name"
msgstr "Search by data item name"
Expand Down Expand Up @@ -508,8 +586,8 @@ msgstr "Filter by name"
msgid "Created"
msgstr "Created"

msgid "Type"
msgstr "Type"
msgid "Last updated"
msgstr "Last updated"

msgid "Clear filters"
msgstr "Clear filters"
Expand Down Expand Up @@ -999,15 +1077,9 @@ msgstr "Actual reports on time"
msgid "Expected reports"
msgstr "Expected reports"

msgid "Program"
msgstr "Program"

msgid "Select a program"
msgstr "Select a program"

msgid "Indicators"
msgstr "Indicators"

msgid "Indicator group"
msgstr "Indicator group"

Expand All @@ -1026,9 +1098,6 @@ msgstr "Loading indicator groups"
msgid "Data element group"
msgstr "Data element group"

msgid "Data element"
msgstr "Data element"

msgid "No data element groups found"
msgstr "No data element groups found"

Expand Down Expand Up @@ -1254,9 +1323,6 @@ msgstr "and {{amount}} more..."
msgid "Linear Regression"
msgstr "Linear Regression"

msgid "Target"
msgstr "Target"

msgid "Base"
msgstr "Base"

Expand Down
52 changes: 45 additions & 7 deletions src/components/DataDimension/Info/CalculationInfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useDataQuery } from '@dhis2/app-runtime'
import { useDataMutation, useDataEngine } from '@dhis2/app-runtime'
import PropTypes from 'prop-types'
import React from 'react'
import React, { useCallback, useEffect, useState } from 'react'
import { validateExpressionMutation } from '../../../api/expression.js'
import i18n from '../../../locales/index.js'
import { getCommonFields, InfoTable } from './InfoTable.js'
import styles from './styles/InfoPopover.style.js'
Expand All @@ -16,16 +17,53 @@ const calculationQuery = {
}

export const CalculationInfo = ({ id, displayNameProp }) => {
const { loading, error, data } = useDataQuery(calculationQuery, {
variables: { id, displayNameProp },
})
const [data, setData] = useState()
const [error, setError] = useState()
const [loading, setLoading] = useState(true)

const engine = useDataEngine()
const [getHumanReadableExpression] = useDataMutation(
validateExpressionMutation,
{ onError: setError }
)

const fetchData = useCallback(async () => {
const { calculation } = await engine.query(calculationQuery, {
variables: { id, displayNameProp },
onError: setError,
})

if (calculation.expression) {
const result = await getHumanReadableExpression({
expression: calculation.expression,
})

if (result?.description) {
calculation.humanReadableExpression = result.description
}
}

setData({ calculation })
setLoading(false)
}, [displayNameProp, engine, getHumanReadableExpression, id])

useEffect(() => {
fetchData()
}, [fetchData])

return (
<>
<InfoTable data={data?.calculation} loading={loading} error={error}>
<tr>
<th>{i18n.t('Expression')}</th>
<td className="code">{data?.calculation.expression}</td>
<th>
{i18n.t(
'Expression description in human readable format'
)}
</th>
<td>
{data?.calculation.humanReadableExpression ||
i18n.t('None')}
</td>
</tr>
</InfoTable>
<style jsx>{styles}</style>
Expand Down
Loading

0 comments on commit fd5fea8

Please sign in to comment.