Skip to content

Commit

Permalink
fix: fetch programs based on selected TET
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkrulltott committed Nov 7, 2023
1 parent c4f8dac commit 218c21d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const ProgramDimensionsPanel = ({ visible }) => {
const query = {
programs: {
resource: 'programs',
params: ({ nameProp }) => ({
params: ({ nameProp, selectedEntityTypeId }) => ({
fields: [
'id',
`${nameProp}~rename(name)`,
Expand All @@ -80,26 +80,30 @@ const ProgramDimensionsPanel = ({ visible }) => {
'displayEnrollmentDateLabel',
],
paging: false,
filter: 'access.data.read:eq:true',
filter: [
'access.data.read:eq:true',
`trackedEntityType.id:eq:${selectedEntityTypeId}`,
],
}),
},
}
const { currentUser } = useCachedDataQuery()
const { data, refetch, called } = useDataQuery(query, {
const { data, refetch } = useDataQuery(query, {
lazy: true,
})
// FIXME: the fetching should be consolidated with the fetching in InputPanel and not be duplicated like this

useEffect(() => {
if (visible && !called) {
if (visible && inputType === OUTPUT_TYPE_TRACKED_ENTITY) {
refetch({
nameProp:
currentUser.settings[
DERIVED_USER_SETTINGS_DISPLAY_NAME_PROPERTY
],
selectedEntityTypeId,
})
}
}, [visible, called, refetch])
}, [visible, refetch, selectedEntityTypeId])

Check warning on line 106 in src/components/MainSidebar/ProgramDimensionsPanel/ProgramDimensionsPanel.js

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has missing dependencies: 'currentUser.settings' and 'inputType'. Either include them or remove the dependency array

if (!visible) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ import i18n from '@dhis2/d2-i18n'
import { NoticeBox, SingleSelect, SingleSelectOption } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useEffect } from 'react'
import { PROGRAM_TYPE_WITH_REGISTRATION } from '../../../modules/programTypes.js'
import { useSelector } from 'react-redux'
import { DERIVED_USER_SETTINGS_DISPLAY_NAME_PROPERTY } from '../../../modules/userSettings.js'
import { sGetUiEntityTypeId } from '../../../reducers/ui.js'
import styles from '../ProgramDimensionsPanel/ProgramSelect.module.css'

const query = {
programs: {
resource: 'programs',
params: ({ nameProp }) => ({
params: ({ nameProp, selectedEntityTypeId }) => ({
fields: ['id', `${nameProp}~rename(name)`],
paging: false,
filter: [
'access.data.read:eq:true',
`programType:eq:${PROGRAM_TYPE_WITH_REGISTRATION}`,
`trackedEntityType.id:eq:${selectedEntityTypeId}`,
],
}),
},
}

const ProgramFilter = ({ setSelectedProgramId, selectedProgramId }) => {
const { currentUser } = useCachedDataQuery()
const selectedEntityTypeId = useSelector(sGetUiEntityTypeId)
const { fetching, error, data, refetch, called } = useDataQuery(query, {
lazy: true,
})
Expand All @@ -36,9 +38,10 @@ const ProgramFilter = ({ setSelectedProgramId, selectedProgramId }) => {
currentUser.settings[
DERIVED_USER_SETTINGS_DISPLAY_NAME_PROPERTY
],
selectedEntityTypeId,
})
}
}, [called, currentUser, refetch])
}, [called, currentUser, refetch, selectedEntityTypeId])

return (
<div className={styles.rows}>
Expand Down

0 comments on commit 218c21d

Please sign in to comment.