From 3e8107a112b1b67bafef51cabf3db59bd83f2974 Mon Sep 17 00:00:00 2001 From: Charlie Zhang Date: Sun, 28 Jul 2024 15:40:48 -0400 Subject: [PATCH] Add organization group sets to allow more disaggregation --- .../src/pages/MainPage/CategoryCombo.jsx | 7 ++++++- src/renderer/src/reducers/categoryReducer.js | 20 +++++++++++++++---- src/renderer/src/reducers/statusReducer.js | 10 ++++++++-- src/renderer/src/service/useApi.js | 5 +++++ src/renderer/src/utils/downloadUtils.js | 6 +++--- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/renderer/src/pages/MainPage/CategoryCombo.jsx b/src/renderer/src/pages/MainPage/CategoryCombo.jsx index f3bba12..7add6d6 100644 --- a/src/renderer/src/pages/MainPage/CategoryCombo.jsx +++ b/src/renderer/src/pages/MainPage/CategoryCombo.jsx @@ -1,6 +1,10 @@ import React, { useEffect, useRef } from 'react' import { useSelector, useDispatch } from 'react-redux' -import { fetchCategoryCombinations, setSelectedCategory } from '../../reducers/categoryReducer' +import { + fetchCategoryCombinations, + fetchOrgUnitGroupSets, + setSelectedCategory +} from '../../reducers/categoryReducer' import { mouseClick, mouseToggle } from '../../reducers/mouseReducer' const CategoryDropdownMenu = () => { @@ -13,6 +17,7 @@ const CategoryDropdownMenu = () => { useEffect(() => { dispatch(fetchCategoryCombinations({ dhis2Url, username, password })) + dispatch(fetchOrgUnitGroupSets({ dhis2Url, username, password })) }, [dhis2Url, username, password, dispatch]) const handleClickOutside = (event) => { diff --git a/src/renderer/src/reducers/categoryReducer.js b/src/renderer/src/reducers/categoryReducer.js index 62e71ad..cb99d5e 100644 --- a/src/renderer/src/reducers/categoryReducer.js +++ b/src/renderer/src/reducers/categoryReducer.js @@ -1,5 +1,5 @@ import { createSlice, createAsyncThunk } from '@reduxjs/toolkit' -import { getCategoryCombination } from '../service/useApi' +import { getCategoryCombination, getOrganizationUnitGroupSets } from '../service/useApi' export const fetchCategoryCombinations = createAsyncThunk( 'category/fetchCategoryCombinations', @@ -9,6 +9,14 @@ export const fetchCategoryCombinations = createAsyncThunk( } ) +export const fetchOrgUnitGroupSets = createAsyncThunk( + 'category/fetchOrgUnitGroupSets', + async ({ dhis2Url, username, password }) => { + const response = await getOrganizationUnitGroupSets(dhis2Url, username, password) + return response.organisationUnitGroupSets + } +) + const categorySlice = createSlice({ name: 'category', initialState: { @@ -26,9 +34,13 @@ const categorySlice = createSlice({ } }, extraReducers: (builder) => { - builder.addCase(fetchCategoryCombinations.fulfilled, (state, action) => { - state.category = action.payload - }) + builder + .addCase(fetchCategoryCombinations.fulfilled, (state, action) => { + state.category = [...state.category, ...action.payload] + }) + .addCase(fetchOrgUnitGroupSets.fulfilled, (state, action) => { + state.category = [...state.category, ...action.payload] + }) } }) diff --git a/src/renderer/src/reducers/statusReducer.js b/src/renderer/src/reducers/statusReducer.js index 1231af1..f97d0f5 100644 --- a/src/renderer/src/reducers/statusReducer.js +++ b/src/renderer/src/reducers/statusReducer.js @@ -20,7 +20,12 @@ const statusSlice = createSlice({ state.errorMessage = action.payload }, setNotification: (state, action) => { - state.notification = action.payload + state.notification = { ...state.notification, ...action.payload } + }, + abortDownload: (state) => { + state.isLoading = false + state.notification.message = 'Download aborted' + state.notification.type = 'info' }, handleExit: (state) => { return initialState @@ -28,5 +33,6 @@ const statusSlice = createSlice({ } }) -export const { setLoading, setError, setNotification, handleExit } = statusSlice.actions +export const { setLoading, setError, setNotification, abortDownload, handleExit } = + statusSlice.actions export default statusSlice.reducer diff --git a/src/renderer/src/service/useApi.js b/src/renderer/src/service/useApi.js index ce20e24..c96edae 100644 --- a/src/renderer/src/service/useApi.js +++ b/src/renderer/src/service/useApi.js @@ -112,3 +112,8 @@ export const getCategoryOptionCombos = (dhis2Url, username, password) => { const catComboOptionUrl = `${dhis2Url}/api/categoryOptionCombos?fields=id,displayName&paging=false` return fetchData(catComboOptionUrl, username, password) } + +export const getOrganizationUnitGroupSets = (dhis2Url, username, password) => { + const orgUnitGroupSetsUrl = `${dhis2Url}/api/organisationUnitGroupSets?fields=id,displayName&paging=false` + return fetchData(orgUnitGroupSetsUrl, username, password) +} diff --git a/src/renderer/src/utils/downloadUtils.js b/src/renderer/src/utils/downloadUtils.js index 9450b3a..436cf5e 100644 --- a/src/renderer/src/utils/downloadUtils.js +++ b/src/renderer/src/utils/downloadUtils.js @@ -4,9 +4,9 @@ export const generateDownloadingUrl = (dhis2Url, ou, dx, pe, co, format = 'csv') '&displayProperty=NAME&ignoreLimit=TRUE&hierarchyMeta=true&hideEmptyRows=TRUE&showHierarchy=true&rows=ou;pe;dx' if (co.length !== 0) { - let coString = co.join(';') - parameters += `&dimension=co:${coString}` - defaultFormat += `;co` + parameters += co.map((el) => `&dimension=${el}`).join('') + let rowString = co.join(';') + defaultFormat += `;${rowString}` } const url = `${dhis2Url}/${parameters}${defaultFormat}`