Skip to content

Commit

Permalink
Update handlePassParams:
Browse files Browse the repository at this point in the history
a) Add functions to clear exisiting params
b) Allow pass disaggregations
  • Loading branch information
ccxzhang committed Aug 23, 2024
1 parent d86f6da commit 2b83989
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
30 changes: 27 additions & 3 deletions src/renderer/src/pages/DownloadHistory/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/pages/MainPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const MainPage = ({ queryDb }) => {
organizationLevel: ou,
period: pe,
dimension: dx,
disaggregation: co,
disaggregation: co.join(';'),
url: downloadingUrl,
notes: ''
})
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/reducers/categoryReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const categorySlice = createSlice({
} else {
state.selectedCategory.push(coId)
}
},
clearSelectedCategory: (state) => {
state.selectedCategory = []
}
},
extraReducers: (builder) => {
Expand All @@ -44,6 +47,6 @@ const categorySlice = createSlice({
}
})

export const { setSelectedCategory } = categorySlice.actions
export const { setSelectedCategory, clearSelectedCategory } = categorySlice.actions

export default categorySlice.reducer
6 changes: 5 additions & 1 deletion src/renderer/src/reducers/dataElementsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const dataElementsSlice = createSlice({
},
removeElement: (state, action) => {
state.addedElements = state.addedElements.filter((element) => element.id !== action.payload)
},
clearSelectedElements: (state) => {
state.addedElements = []
}
}
})
Expand All @@ -47,7 +50,8 @@ export const {
setFilteredElements,
setSelectedElements,
addSelectedElements,
removeElement
removeElement,
clearSelectedElements
} = dataElementsSlice.actions

export default dataElementsSlice.reducer
15 changes: 13 additions & 2 deletions src/renderer/src/reducers/orgUnitReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ const orgUnitSlice = createSlice({
} else {
state.selectedOrgUnitLevels.push(level)
}
},
clearOrgUnitSelections: (state) => {
state.selectedOrgUnits = []
},
clearOrgUnitLevels: (state) => {
state.selectedOrgUnitLevels = []
}
},
extraReducers: (builder) => {
Expand Down Expand Up @@ -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

0 comments on commit 2b83989

Please sign in to comment.