Skip to content

Commit

Permalink
gh-692: Fix tally sheet list area mapping
Browse files Browse the repository at this point in the history
This fixes #692
  • Loading branch information
dinukadesilva committed Jul 15, 2020
1 parent 06924c8 commit 329f590
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 329f590

Please sign in to comment.