-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update VxAdmin to support importing new CVR export format #3956
Merged
+1,075
−167
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
05c37b9
Move VxAdmin CVR helpers to libs/utils
arsalansufi f8abdf5
Add libs/utils helper for parsing new export directory name format
arsalansufi 8da64a4
Fix artifact authentication bug
arsalansufi 85674ce
Specify encoding when reading files, rather than converting after
arsalansufi c3ae016
Add libs/backend helpers for importing CVRs
arsalansufi 6ea6ad4
Update logic for listing CVR exports on a USB
arsalansufi 9474952
Add new VxAdmin CVR import function
arsalansufi 830a757
Use new CVR import function in API
arsalansufi a668787
Add client-side logic for user readable messages
arsalansufi 84480ad
Use optimized helpers in libs/utils
arsalansufi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,10 @@ import { | |
} from '@votingworks/utils'; | ||
import { assert, throwIllegalValue } from '@votingworks/basics'; | ||
|
||
import type { CvrFileImportInfo } from '@votingworks/admin-backend'; | ||
import type { | ||
CvrFileImportInfo, | ||
ImportCastVoteRecordsError, | ||
} from '@votingworks/admin-backend'; | ||
import { AppContext } from '../contexts/app_context'; | ||
import { Loading } from './loading'; | ||
import { | ||
|
@@ -62,6 +65,89 @@ const Content = styled.div` | |
overflow: hidden; | ||
`; | ||
|
||
/* c8 ignore start */ | ||
function userReadableMessageFromError( | ||
error: ImportCastVoteRecordsError | ||
): string { | ||
switch (error.type) { | ||
case 'authentication-error': { | ||
return 'Unable to authenticate cast vote records. Try exporting them from the scanner again.'; | ||
} | ||
case 'ballot-id-already-exists-with-different-data': { | ||
return `Found a cast vote record at index ${error.index} that has the same ballot ID as a previously imported cast vote record, but with different data.`; | ||
} | ||
case 'invalid-mode': { | ||
return { | ||
official: | ||
'You are currently tabulating official results but the selected cast vote record export contains test results.', | ||
test: 'You are currently tabulating test results but the selected cast vote record export contains official results.', | ||
}[error.currentMode]; | ||
} | ||
case 'invalid-cast-vote-record': { | ||
const messageBase = `Found an invalid cast vote record at index ${error.index}. `; | ||
const messageDetail = (() => { | ||
switch (error.subType) { | ||
case 'ballot-style-not-found': { | ||
return 'The record references a ballot style that does not exist.'; | ||
} | ||
case 'batch-id-not-found': { | ||
return 'The record references a batch ID that does not exist.'; | ||
} | ||
case 'contest-not-found': { | ||
return 'The record references a contest that does not exist.'; | ||
} | ||
case 'contest-option-not-found': { | ||
return 'The record references a contest option that does not exist.'; | ||
} | ||
case 'election-mismatch': { | ||
return 'The record references the wrong election.'; | ||
} | ||
case 'image-file-not-found': { | ||
return 'The record references an image file that does not exist.'; | ||
} | ||
// These two go hand-in-hand | ||
case 'invalid-ballot-image-field': | ||
case 'invalid-write-in-field': { | ||
return 'The record contains an incorrectly formatted ballot image and/or write-in field.'; | ||
} | ||
case 'invalid-ballot-sheet-id': { | ||
return 'The record contains an incorrectly formatted ballot sheet ID.'; | ||
} | ||
case 'layout-file-not-found': { | ||
return 'The record references a layout file that does not exist.'; | ||
} | ||
case 'layout-parse-error': { | ||
return 'The layout file could not be parsed.'; | ||
} | ||
case 'no-current-snapshot': { | ||
return 'The record does not contain a current snapshot of the interpreted results.'; | ||
} | ||
case 'parse-error': { | ||
return 'The record could not be parsed.'; | ||
} | ||
case 'precinct-not-found': { | ||
return 'The record references a precinct that does not exist.'; | ||
} | ||
default: { | ||
throwIllegalValue(error, 'subType'); | ||
} | ||
} | ||
})(); | ||
return [messageBase, messageDetail].join(' '); | ||
} | ||
case 'metadata-file-not-found': { | ||
return 'Unable to find metadata file.'; | ||
} | ||
case 'metadata-file-parse-error': { | ||
return 'Unable to parse metadata file.'; | ||
} | ||
default: { | ||
throwIllegalValue(error, 'type'); | ||
} | ||
} | ||
} | ||
/* c8 ignore stop */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know I've added a lot of code coverage ignores. I've opened issues to track all the tests that I'm deferring to later PRs. |
||
|
||
type ModalState = | ||
| { state: 'error'; errorMessage?: string; filename: string } | ||
| { state: 'loading' } | ||
|
@@ -95,9 +181,13 @@ export function ImportCvrFilesModal({ onClose }: Props): JSX.Element | null { | |
{ | ||
onSuccess: (addCastVoteRecordFileResult) => { | ||
if (addCastVoteRecordFileResult.isErr()) { | ||
const error = addCastVoteRecordFileResult.err(); | ||
setCurrentState({ | ||
state: 'error', | ||
errorMessage: addCastVoteRecordFileResult.err().message, | ||
errorMessage: | ||
'message' in error | ||
? error.message | ||
: userReadableMessageFromError(error), | ||
filename, | ||
}); | ||
} else if (addCastVoteRecordFileResult.ok().wasExistingFile) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this function lives on the frontend. The old import code has an equivalent function live on the backend and sends a user-readable message down to the frontend for it to use. Ultimately, this message-preparation is a UI/frontend concern and not a backend concern, hence my moving it to the frontend.
This will become even more necessary once we start working on multi-language support (as noted here).