Skip to content

Commit

Permalink
Merge pull request #693 from dinukadesilva/gh-692-fix-tally-sheet-lis…
Browse files Browse the repository at this point in the history
…t-area-mapping

gh-692: Fix tally sheet list area mapping
  • Loading branch information
dinukadesilva authored Jul 15, 2020
2 parents 9a0d890 + 329f590 commit e88a847
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions results-tabulation-ui/src/services/tally-sheet.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,32 @@ export function TallySheetProvider(props) {

const [state, setState] = useState({
tallySheetMap: {},
tallySheetProofFileMap: {}
tallySheetProofFileMap: {},
filteredAreaMap: {}
});

async function getFilteredAreaMap(tallySheet) {
const {areaId} = tallySheet;
if (!state.filteredAreaMap[areaId]) {
const electionAreaMap = await electionContext.getElectionAreaMap(tallySheet.electionId);
state.filteredAreaMap[areaId] = electionAreaMap.filter((areaMap) => {
return areaMap["countryId"] === areaId || areaMap["electoralDistrictId"] === areaId || areaMap["pollingDivisionId"] === areaId || areaMap["countingCentreId"] === areaId || areaMap["countryId"] === areaId;
});
setState({
...state,
filteredAreaMap: {
...state.filteredAreaMap
}
})
}

return state.filteredAreaMap[areaId];
}

async function refactorTallySheetObject(tallySheet) {
tallySheet.tallySheetCode = tallySheet.tallySheetCode.replace(/_/g, "-");
tallySheet.election = await electionContext.getElectionById(tallySheet.electionId);
tallySheet.areaMapList = await electionContext.getElectionAreaMap(tallySheet.electionId);
tallySheet.areaMapList = await getFilteredAreaMap(tallySheet);

// TODO fetch actions and area maps

Expand Down

0 comments on commit e88a847

Please sign in to comment.