diff --git a/src/components/Inputs/ProgramPicker.js b/src/components/Inputs/ProgramPicker.js
index f53431d32..daa92f1c0 100644
--- a/src/components/Inputs/ProgramPicker.js
+++ b/src/components/Inputs/ProgramPicker.js
@@ -12,7 +12,8 @@ const LISTNAME = 'selectedPrograms'
const FILTERLABEL = i18n.t('Filter programs')
const SELECTEDLABEL = i18n.t('Selected programs')
const ERRORMESSAGE = i18n.t('Something went wrong when loading the programs!')
-const RESOURCETYPE = resourceTypes.PROGRAM
+const PROGRAM_RESOURCE_TYPE = resourceTypes.PROGRAM
+const PROGRAM_WITH_EVENTS_RESOURCE_TYPE = resourceTypes.PROGRAM_WITH_EVENTS
const SINGLE_PROGRAM_VALIDATOR = (selectedPrograms) =>
selectedPrograms.length == 0
@@ -22,18 +23,27 @@ const SINGLE_PROGRAM_VALIDATOR = (selectedPrograms) =>
const SINGLE_EXACT_PROGRAM_VALIDATOR = (selectedPrograms) =>
!selectedPrograms ? i18n.t('One program must be selected') : undefined
-const ProgramPicker = ({ multiSelect, label, show, ...rest }) => {
+const ProgramPicker = ({
+ multiSelect,
+ label,
+ show,
+ includeEvents,
+ ...rest
+}) => {
const programValidator = multiSelect
? SINGLE_PROGRAM_VALIDATOR
: SINGLE_EXACT_PROGRAM_VALIDATOR
const validator = composeValidators(hasValue, programValidator)
+ const resourceType = includeEvents
+ ? PROGRAM_WITH_EVENTS_RESOURCE_TYPE
+ : PROGRAM_RESOURCE_TYPE
return (
show && (
({
+ ...jest.requireActual('@dhis2/app-runtime'),
+ // eslint-disable-next-line no-unused-vars
+ useDataQuery: jest.fn((query, options) => ({ refetch: () => {} })),
+}))
+
+const renderWithFormWrapper = (children) =>
+ render(
+ {}}>
+ {() => }
+
+ )
+
+describe('ProgramPicker', () => {
+ test('it invokes useDataQuery with programs query by default', () => {
+ renderWithFormWrapper()
+ expect(useDataQuery).toHaveBeenCalledWith(
+ programQuery,
+ expect.anything()
+ )
+ })
+
+ test('it invokes useDataQuery with programs and events query if includeEvents is true', () => {
+ renderWithFormWrapper()
+ expect(useDataQuery).toHaveBeenCalledWith(
+ programWithEventsQuery,
+ expect.anything()
+ )
+ })
+})
diff --git a/src/components/ResourcePicker/ResourcePicker.js b/src/components/ResourcePicker/ResourcePicker.js
index 6ce24659b..759068481 100644
--- a/src/components/ResourcePicker/ResourcePicker.js
+++ b/src/components/ResourcePicker/ResourcePicker.js
@@ -15,6 +15,7 @@ import {
TETypeQuery,
userQuery,
geojsonAttributesQuery,
+ programWithEventsQuery,
} from './queries.js'
import styles from './ResourcePicker.module.css'
import { resourceTypes } from './resourceTypes.js'
@@ -26,6 +27,8 @@ const resourceToQuery = (resourceType) => {
return { resourceName: 'dataSets', query: dataSetQuery }
} else if (resourceType == resourceTypes.PROGRAM) {
return { resourceName: 'programs', query: programQuery }
+ } else if (resourceType == resourceTypes.PROGRAM_WITH_EVENTS) {
+ return { resourceName: 'programs', query: programWithEventsQuery }
} else if (resourceType == resourceTypes.TETYPE) {
return { resourceName: 'trackedEntityTypes', query: TETypeQuery }
} else if (resourceType == resourceTypes.USER) {
diff --git a/src/components/ResourcePicker/queries.js b/src/components/ResourcePicker/queries.js
index 6c4765a1c..caf7b90a7 100644
--- a/src/components/ResourcePicker/queries.js
+++ b/src/components/ResourcePicker/queries.js
@@ -19,6 +19,16 @@ const programQuery = {
},
}
+const programWithEventsQuery = {
+ programs: {
+ resource: 'programs',
+ params: {
+ fields: 'id,displayName',
+ paging: 'false',
+ },
+ },
+}
+
const TETypeQuery = {
trackedEntityTypes: {
resource: 'trackedEntityTypes',
@@ -56,6 +66,7 @@ const geojsonAttributesQuery = {
export {
dataSetQuery,
programQuery,
+ programWithEventsQuery,
TETypeQuery,
userQuery,
geojsonAttributesQuery,
diff --git a/src/components/ResourcePicker/resourceTypes.js b/src/components/ResourcePicker/resourceTypes.js
index ae240f6da..86331d1f0 100644
--- a/src/components/ResourcePicker/resourceTypes.js
+++ b/src/components/ResourcePicker/resourceTypes.js
@@ -4,6 +4,7 @@ const resourceTypes = {
TETYPE: 3,
USER: 4,
GEOJSON_ATTRIBUTE: 5,
+ PROGRAM_WITH_EVENTS: 6,
}
export { resourceTypes }
diff --git a/src/pages/EventExport/EventExport.js b/src/pages/EventExport/EventExport.js
index e88f1fef5..678724a9a 100644
--- a/src/pages/EventExport/EventExport.js
+++ b/src/pages/EventExport/EventExport.js
@@ -92,7 +92,7 @@ const EventExport = () => {
-
+