-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custom calculations for thematic layer (DHIS2-15474) (#2745)
- Loading branch information
Showing
8 changed files
with
212 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { useDataQuery } from '@dhis2/app-runtime' | ||
import i18n from '@dhis2/d2-i18n' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import { SelectField, Help } from '../core/index.js' | ||
import { useUserSettings } from '../UserSettingsProvider.js' | ||
import styles from './styles/CalculationSelect.module.css' | ||
|
||
// Load all calculations | ||
const CALCULATIONS_QUERY = { | ||
calculations: { | ||
resource: 'expressionDimensionItems', | ||
params: ({ nameProperty }) => ({ | ||
fields: ['id', `${nameProperty}~rename(name)`], | ||
paging: false, | ||
}), | ||
}, | ||
} | ||
|
||
const CalculationSelect = ({ calculation, className, errorText, onChange }) => { | ||
const { nameProperty } = useUserSettings() | ||
const { loading, error, data } = useDataQuery(CALCULATIONS_QUERY, { | ||
variables: { nameProperty }, | ||
}) | ||
|
||
const items = data?.calculations.expressionDimensionItems | ||
const value = calculation?.id | ||
|
||
return ( | ||
<div className={styles.calculationSelect}> | ||
<SelectField | ||
label={i18n.t('Calculation')} | ||
loading={loading} | ||
items={items} | ||
value={value} | ||
onChange={(dataItem) => onChange(dataItem, 'calculation')} | ||
className={className} | ||
emptyText={i18n.t('No calculations found')} | ||
errorText={ | ||
error?.message || | ||
(!calculation && errorText ? errorText : null) | ||
} | ||
filterable={true} | ||
dataTest="calculationselect" | ||
/> | ||
<Help> | ||
{i18n.t( | ||
'Calculations can be created in the Data Visualizer app.' | ||
)} | ||
</Help> | ||
</div> | ||
) | ||
} | ||
|
||
CalculationSelect.propTypes = { | ||
onChange: PropTypes.func.isRequired, | ||
calculation: PropTypes.object, | ||
className: PropTypes.string, | ||
errorText: PropTypes.string, | ||
} | ||
|
||
export default CalculationSelect |
3 changes: 3 additions & 0 deletions
3
src/components/calculations/styles/CalculationSelect.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.calculationSelect { | ||
margin-bottom: var(--spacers-dp16); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters