Skip to content

Commit

Permalink
PR feedback: simplify syntax, improve comments, use styled components
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilb4a committed Nov 4, 2024
1 parent 9e77bb3 commit b4fbcdd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ const ContestDiscrepanciesTable = styled(HTMLTable).attrs({
}
`

const TableHeader = styled(H6)`
&:first-child {
margin-top: 8px;
}
`

/* istanbul ignore next */
function getContestName(contests: IContest[], contestId: string) {
const contest = contests.find(c => c.id === contestId)
return contest ? contest.name : 'Contest not found'
return contest ? contest.name : `Contest Unknown: ID ${contestId}`
}

/* istanbul ignore next */
Expand All @@ -38,9 +44,9 @@ function getChoiceName(
choiceId: string
) {
const contest = contests.find(c => c.id === contestId)
if (!contest) return 'Choice not found'
if (!contest) return `Contest Unknown: ID ${choiceId}`
const choice = contest.choices.find(c => c.id === choiceId)
return choice ? choice.name : 'Choice not found'
return choice ? choice.name : `Choice Unknown: ID ${choiceId}`
}

export interface IJurisdictionDiscrepanciesProps {
Expand Down Expand Up @@ -78,11 +84,11 @@ const JurisdictionDiscrepancies: React.FC<IJurisdictionDiscrepanciesProps> = ({
{Object.entries(discrepanciesByBatch).map(
([batchName, discrepanciesByContest]) => {
return Object.entries(discrepanciesByContest).map(
([contestId, contestDiscrepancies], idx) => (
([contestId, contestDiscrepancies]) => (
<div key={contestId}>
<H6 style={idx === 0 ? { marginTop: '8px' } : {}}>
<TableHeader>
{batchName} - {getContestName(contests, contestId)}
</H6>
</TableHeader>
<ContestDiscrepanciesTable>
<thead>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/AuditAdmin/Progress/Progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ const Progress: React.FC<IProgressProps> = ({
auditSettings={auditSettings}
/>
)}
{jurisdictionDiscrepanciesId && round && (
{jurisdictionDiscrepanciesId && (
<JurisdictionDiscrepancies
jurisdiction={
jurisdictions.find(
Expand Down
17 changes: 7 additions & 10 deletions client/src/components/useJurisdictions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ export const useDiscrepancyCountsByJurisdiction = (
)
}

// { jurisidictionId: { batchName: { contestId: { "reportedVotes": {choiceId: int}, "auditedVotes": {choiceId: int}, "discrepancies": {choiceId: int}}}}
export type DiscrepanciesByJurisdiction = Record<
string,
Record<string, Record<string, ContestDiscrepancies>>
string, // [jurisdictionId]
Record<
string, // [batchName]
Record<string, ContestDiscrepancies> // [contestId]: contestDiscrepancies
>
>

type ContestDiscrepancies = {
reportedVotes: Record<string, number>
reportedVotes: Record<string, number> // `Record` keys are choiceId
auditedVotes: Record<string, number>
discrepancies: Record<string, number>
}
Expand All @@ -187,12 +189,7 @@ export const useDiscrepanciesByJurisdiction = (
): UseQueryResult<DiscrepanciesByJurisdiction, ApiError> => {
return useQuery(
discrepanciesByJurisdictionQueryKey(electionId),
async () => {
const response: DiscrepanciesByJurisdiction = await fetchApi(
`/api/election/${electionId}/discrepancy`
)
return response
},
() => fetchApi(`/api/election/${electionId}/discrepancy`),
options
)
}

0 comments on commit b4fbcdd

Please sign in to comment.