diff --git a/src/renderer/src/pages/DownloadHistory/index.jsx b/src/renderer/src/pages/DownloadHistory/index.jsx index 6cbffc5..bcd028c 100644 --- a/src/renderer/src/pages/DownloadHistory/index.jsx +++ b/src/renderer/src/pages/DownloadHistory/index.jsx @@ -11,8 +11,14 @@ import { setEditedRow, clearEditedRow } from '../../reducers/historyReducer' -import { addSelectedElements } from '../../reducers/dataElementsReducer' -import { updateOrgUnitLevels, toggleOrgUnitSelection } from '../../reducers/orgUnitReducer' +import { addSelectedElements, clearSelectedElements } from '../../reducers/dataElementsReducer' +import { + updateOrgUnitLevels, + toggleOrgUnitSelection, + clearOrgUnitLevels, + clearOrgUnitSelections +} from '../../reducers/orgUnitReducer' +import { clearSelectedCategory, setSelectedCategory } from '../../reducers/categoryReducer' import { MicroArrowDownTray, MicroArrowTopRight, MicroTrash } from '../../components/Icons' import Pagination from '../../components/Pagination' @@ -177,7 +183,15 @@ const HistoryPage = ({ dictionaryDb, queryDb }) => { } } + const clearExistingParams = () => { + dispatch(clearSelectedElements()) + dispatch(clearOrgUnitSelections()) + dispatch(clearOrgUnitLevels()) + dispatch(clearSelectedCategory()) + } + const handlePassParams = (id) => { + clearExistingParams() const params = downloadQueries.filter((el) => el.id === id) const dimensions = params.flatMap((param) => param.dimension.includes(';') ? param.dimension.split(';') : param.dimension @@ -198,7 +212,17 @@ const HistoryPage = ({ dictionaryDb, queryDb }) => { } }) }) - // date + + // Disaggregation (Additional measures for disaggregations being '') + const disaggregations = params + .flatMap((param) => + param.disaggregation.includes(';') ? param.disaggregation.split(';') : param.disaggregation + ) + .filter((dis) => dis !== '') + + if (disaggregations.length > 0) { + disaggregations.forEach((dis) => dispatch(setSelectedCategory(dis))) + } // dimension const elementsInfo = allElements.filter((el) => dimensions.includes(el.id)) diff --git a/src/renderer/src/pages/MainPage/index.jsx b/src/renderer/src/pages/MainPage/index.jsx index 9d4d52b..e6868aa 100644 --- a/src/renderer/src/pages/MainPage/index.jsx +++ b/src/renderer/src/pages/MainPage/index.jsx @@ -109,7 +109,7 @@ const MainPage = ({ queryDb }) => { organizationLevel: ou, period: pe, dimension: dx, - disaggregation: co, + disaggregation: co.join(';'), url: downloadingUrl, notes: '' }) diff --git a/src/renderer/src/reducers/categoryReducer.js b/src/renderer/src/reducers/categoryReducer.js index cb99d5e..6906bc5 100644 --- a/src/renderer/src/reducers/categoryReducer.js +++ b/src/renderer/src/reducers/categoryReducer.js @@ -31,6 +31,9 @@ const categorySlice = createSlice({ } else { state.selectedCategory.push(coId) } + }, + clearSelectedCategory: (state) => { + state.selectedCategory = [] } }, extraReducers: (builder) => { @@ -44,6 +47,6 @@ const categorySlice = createSlice({ } }) -export const { setSelectedCategory } = categorySlice.actions +export const { setSelectedCategory, clearSelectedCategory } = categorySlice.actions export default categorySlice.reducer diff --git a/src/renderer/src/reducers/dataElementsReducer.js b/src/renderer/src/reducers/dataElementsReducer.js index 4f891e4..2c10718 100644 --- a/src/renderer/src/reducers/dataElementsReducer.js +++ b/src/renderer/src/reducers/dataElementsReducer.js @@ -36,6 +36,9 @@ const dataElementsSlice = createSlice({ }, removeElement: (state, action) => { state.addedElements = state.addedElements.filter((element) => element.id !== action.payload) + }, + clearSelectedElements: (state) => { + state.addedElements = [] } } }) @@ -47,7 +50,8 @@ export const { setFilteredElements, setSelectedElements, addSelectedElements, - removeElement + removeElement, + clearSelectedElements } = dataElementsSlice.actions export default dataElementsSlice.reducer diff --git a/src/renderer/src/reducers/orgUnitReducer.js b/src/renderer/src/reducers/orgUnitReducer.js index 1edbcef..6420904 100644 --- a/src/renderer/src/reducers/orgUnitReducer.js +++ b/src/renderer/src/reducers/orgUnitReducer.js @@ -62,6 +62,12 @@ const orgUnitSlice = createSlice({ } else { state.selectedOrgUnitLevels.push(level) } + }, + clearOrgUnitSelections: (state) => { + state.selectedOrgUnits = [] + }, + clearOrgUnitLevels: (state) => { + state.selectedOrgUnitLevels = [] } }, extraReducers: (builder) => { @@ -96,7 +102,12 @@ const orgUnitSlice = createSlice({ } }) -export const { toggleOrgUnitSelection, toggleOrgUnitExpansion, updateOrgUnitLevels } = - orgUnitSlice.actions +export const { + toggleOrgUnitSelection, + toggleOrgUnitExpansion, + updateOrgUnitLevels, + clearOrgUnitSelections, + clearOrgUnitLevels +} = orgUnitSlice.actions export default orgUnitSlice.reducer