Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/OrgUnitsProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useDataEngine } from '@dhis2/app-runtime'
import PropTypes from 'prop-types'
import React, { useContext, useState, useEffect, createContext } from 'react'
import { useCachedData } from './cachedDataProvider/CachedDataProvider.jsx'

// Fetches the root org units associated with the current user with fallback to data capture org units
const ORG_UNITS_QUERY = {
roots: {
resource: 'organisationUnits',
params: () => ({
fields: ['id', 'displayName~rename(name)', 'path'], // TODO organisationUnits has shortName
params: ({ nameProperty }) => ({
fields: ['id', `${nameProperty}~rename(name)`, 'path'],
userDataViewFallback: true,
}),
},
Expand All @@ -27,17 +28,19 @@ const OrgUnitsProvider = ({ children }) => {
const [orgUnits, setOrgUnits] = useState()
const [error, setError] = useState()
const engine = useDataEngine()
const { nameProperty } = useCachedData()

useEffect(() => {
engine.query(ORG_UNITS_QUERY, {
variables: { nameProperty },
onComplete: ({ levels, roots }) =>
setOrgUnits({
levels: levels.organisationUnitLevels,
roots: roots.organisationUnits,
}),
onError: setError,
})
}, [engine])
}, [engine, nameProperty])

return (
<OrgUnitsCtx.Provider
Expand Down
3 changes: 2 additions & 1 deletion src/components/app/FileMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const FileMenu = ({ onFileMenuAction }) => {
const dispatch = useDispatch()
const engine = useDataEngine()
const { serverVersion } = useConfig()
const { systemSettings, currentUser } = useCachedData()
const { systemSettings, currentUser, nameProperty } = useCachedData()
const defaultBasemap = systemSettings.keyDefaultBaseMap
//alerts
const saveAlert = useAlert(ALERT_MESSAGE_DYNAMIC, ALERT_OPTIONS_DYNAMIC)
Expand Down Expand Up @@ -151,6 +151,7 @@ const FileMenu = ({ onFileMenuAction }) => {
engine,
defaultBasemap,
withSubscribers: true,
nameProperty,
})

const latestMap = {
Expand Down
5 changes: 3 additions & 2 deletions src/components/app/useLoadMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const useLoadMap = () => {
const basemapInvalidAlertRef = useRef(
useAlert(ALERT_MESSAGE_DYNAMIC, ALERT_CRITICAL)
)
const { systemSettings, basemaps } = useCachedData()
const { systemSettings, basemaps, nameProperty } = useCachedData()
const defaultBasemap = systemSettings.keyDefaultBaseMap
const engine = useDataEngine()
const dispatch = useDispatch()
Expand All @@ -50,6 +50,7 @@ export const useLoadMap = () => {
id: params.mapId,
engine,
defaultBasemap,
nameProperty,
})

engine.mutate(dataStatisticsMutation, {
Expand Down Expand Up @@ -86,7 +87,7 @@ export const useLoadMap = () => {

previousParamsRef.current = params
},
[basemaps, defaultBasemap, dispatch, engine]
[basemaps, defaultBasemap, dispatch, engine, nameProperty]
)

useEffect(() => {
Expand Down
3 changes: 1 addition & 2 deletions src/components/edit/LayerEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const getLayerNames = () => ({

const LayerEdit = ({ layer, addLayer, updateLayer, cancelLayer }) => {
const [isValidLayer, setIsValidLayer] = useState(false)
const { systemSettings, periodsSettings, currentUser } = useCachedData()
const { systemSettings, periodsSettings } = useCachedData()
const orgUnits = useOrgUnits()

const onValidateLayer = () => setIsValidLayer(true)
Expand Down Expand Up @@ -106,7 +106,6 @@ const LayerEdit = ({ layer, addLayer, updateLayer, cancelLayer }) => {
{...layer}
systemSettings={systemSettings}
periodsSettings={periodsSettings}
currentUser={currentUser}
orgUnits={orgUnits}
validateLayer={isValidLayer}
onLayerValidation={onLayerValidation}
Expand Down
8 changes: 3 additions & 5 deletions src/components/edit/thematic/ThematicDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
getPeriodsFromFilters,
getDimensionsFromFilters,
} from '../../../util/analytics.js'
import { useCachedData } from '../../cachedDataProvider/CachedDataProvider.jsx'
import NumericLegendStyle from '../../classification/NumericLegendStyle.jsx'
import { Tab, Tabs, Checkbox } from '../../core/index.js'
import DimensionFilter from '../../dimensions/DimensionFilter.jsx'
Expand Down Expand Up @@ -71,7 +72,6 @@ const ThematicDialog = ({
noDataLegend,
unclassifiedLegend,
periodsSettings,
currentUser,
validateLayer,
onLayerValidation,
legendSet,
Expand All @@ -82,6 +82,7 @@ const ThematicDialog = ({
legendIsolated,
}) => {
const dispatch = useDispatch()
const { nameProperty } = useCachedData()
const countFeaturesWithoutCoordinates = useSelector(
(state) => state.layerEdit.countFeaturesWithoutCoordinates
)
Expand Down Expand Up @@ -385,9 +386,7 @@ const ThematicDialog = ({
<div data-test="thematicdialog-datatab">
<div className={styles.flexRowFlow}>
<DataDimension
displayNameProp={
currentUser.keyAnalysisDisplayProperty
}
displayNameProp={nameProperty}
selectedDimensions={
dataItem
? [
Expand Down Expand Up @@ -622,7 +621,6 @@ const ThematicDialog = ({
ThematicDialog.propTypes = {
backupPeriodsDates: PropTypes.object,
columns: PropTypes.array,
currentUser: PropTypes.object,
endDate: PropTypes.string,
eventStatus: PropTypes.string,
filters: PropTypes.array,
Expand Down
3 changes: 1 addition & 2 deletions src/components/map/MapView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ const MapView = (props) => {

const { baseUrl } = useConfig()
const engine = useDataEngine()
const { currentUser } = useCachedData()
const nameProperty = currentUser.keyAnalysisDisplayProperty
const { nameProperty } = useCachedData()

const splitViewLayers = getSplitViewLayers(layers)
const isSplitView = splitViewLayers.length > 0
Expand Down
9 changes: 3 additions & 6 deletions src/components/map/layers/EventLayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,14 @@ class EventLayer extends Layer {
programStage,
eventCoordinateField,
}) {
const displayNameProp =
nameProperty === 'name' ? 'displayName' : 'displayShortName'

let displayItems = []

const programStageResponse = await engine.query(
EVENT_PROGRAM_STAGE_DATA_ELEMENTS_QUERY,
{
variables: {
id: programStage.id,
nameProperty: displayNameProp,
nameProperty,
},
}
)
Expand Down Expand Up @@ -275,7 +272,7 @@ class EventLayer extends Layer {
{
variables: {
id: program.id,
nameProperty: displayNameProp,
nameProperty,
},
}
)
Expand Down Expand Up @@ -316,7 +313,7 @@ class EventLayer extends Layer {
programStage,
eventCoordinateField,
engine,
displayNameProp,
nameProperty,
})

this.setState({ displayItems, eventCoordinateFieldName })
Expand Down
7 changes: 2 additions & 5 deletions src/components/map/layers/TrackedEntityLayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,12 @@ class TrackedEntityLayer extends Layer {
const { trackedEntityType, program } = this.props
// Get relationshipType object from loader if we want to retrieve attributes from secondary dataset

const displayNameProp =
nameProperty === 'name' ? 'displayName' : 'displayShortName'

const { trackedEntityType: data } = await engine.query(
TRACKED_ENTITY_TRACKED_ENTITY_TYPE_ATTRIBUTES_QUERY,
{
variables: {
id: trackedEntityType.id,
nameProperty: displayNameProp,
nameProperty,
},
}
)
Expand All @@ -192,7 +189,7 @@ class TrackedEntityLayer extends Layer {
{
variables: {
id: program.id,
nameProperty: displayNameProp,
nameProperty,
},
}
)
Expand Down
10 changes: 7 additions & 3 deletions src/components/map/layers/TrackedEntityPopup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const TRACKED_ENTITIES_QUERY = {
trackedEntities: {
resource: `tracker/trackedEntities`,
id: ({ id }) => id,
params: ({ program }) => ({
fields: 'updatedAt,orgUnit,attributes[displayName~rename(name),value,attribute],relationships',
params: ({ program, nameProperty }) => ({
fields: `updatedAt,orgUnit,attributes[${nameProperty}~rename(name),value,attribute],relationships`,
program: program?.id,
}),
},
Expand Down Expand Up @@ -85,6 +85,7 @@ const TrackedEntityPopup = ({
variables: {
id: feature.properties.id,
program,
nameProperty,
},
lazy: true,
})
Expand Down Expand Up @@ -118,7 +119,10 @@ const TrackedEntityPopup = ({
})
const orgUnitsNamesMap = {}
for (const id of orgUnitIds) {
const result = await refetchOrgUnit({ id, nameProperty })
const result = await refetchOrgUnit({
id,
nameProperty,
})
orgUnitsNamesMap[id] = result?.orgUnit?.name
}
setOrgUnitNames(orgUnitsNamesMap)
Expand Down
3 changes: 3 additions & 0 deletions src/components/plugin/LayerLoader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const LayerLoader = ({ config, onLoad }) => {
const {
systemSettings: { keyAnalysisDigitGroupSeparator },
currentUser,
nameProperty,
} = useCachedData()
const { keyAnalysisDisplayProperty, id: userId } = currentUser
const periodTypeData = useDataOutputPeriodTypes()
Expand All @@ -48,6 +49,7 @@ const LayerLoader = ({ config, onLoad }) => {
config,
engine,
keyAnalysisDisplayProperty, // name/shortName
nameProperty, // displayName/displayShortName
keyAnalysisDigitGroupSeparator, // NONE/SPACE/COMMA
userId,
baseUrl,
Expand All @@ -66,6 +68,7 @@ const LayerLoader = ({ config, onLoad }) => {
userId,
baseUrl,
keyAnalysisDisplayProperty,
nameProperty,
keyAnalysisDigitGroupSeparator,
serverVersion,
])
Expand Down
14 changes: 5 additions & 9 deletions src/loaders/eventLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const unknownErrorAlert = {
const eventLoader = async ({
config: layerConfig,
engine,
keyAnalysisDisplayProperty,
nameProperty,
keyAnalysisDigitGroupSeparator,
analyticsEngine,
periodTypeData,
Expand All @@ -59,16 +59,12 @@ const eventLoader = async ({
...layerConfig,
keyAnalysisDigitGroupSeparator,
}
const displayNameProp =
keyAnalysisDisplayProperty === 'name'
? 'displayName'
: 'displayShortName'

try {
await loadEventLayer({
config,
engine,
displayNameProp,
nameProperty,
analyticsEngine,
periodTypeData,
loadExtended,
Expand Down Expand Up @@ -98,7 +94,7 @@ const eventLoader = async ({
const loadEventLayer = async ({
config,
engine,
displayNameProp,
nameProperty,
analyticsEngine,
periodTypeData,
loadExtended,
Expand Down Expand Up @@ -162,7 +158,7 @@ const loadEventLayer = async ({

const analyticsRequest = await getAnalyticsRequest(config, {
analyticsEngine,
nameProperty: displayNameProp,
nameProperty,
engine,
})
let alert
Expand Down Expand Up @@ -292,7 +288,7 @@ const loadEventLayer = async ({
programStage,
eventCoordinateField,
engine,
displayNameProp,
nameProperty,
})
if (eventCoordinateFieldName) {
config.legend.coordinateFields = [eventCoordinateFieldName]
Expand Down
6 changes: 3 additions & 3 deletions src/util/coordinatesName.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const loadEventCoordinateFieldName = async ({
programStage,
eventCoordinateField,
engine,
displayNameProp,
nameProperty,
}) => {
if (!eventCoordinateField) {
return
Expand All @@ -22,7 +22,7 @@ export const loadEventCoordinateFieldName = async ({
const { programStage: programStageData } = await engine.query(
EVENT_PROGRAM_STAGE_DATA_ELEMENTS_QUERY,
{
variables: { id: programStage.id, nameProperty: displayNameProp },
variables: { id: programStage.id, nameProperty },
}
)
const { programStageDataElements } = programStageData
Expand All @@ -40,7 +40,7 @@ export const loadEventCoordinateFieldName = async ({
{
variables: {
id: program.id,
nameProperty: displayNameProp,
nameProperty,
},
}
)
Expand Down
Loading
Loading