-
Notifications
You must be signed in to change notification settings - Fork 56
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
Fix off-by-one error in importer error messages when first row is header #2339
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,14 @@ export default function usePreflight(orgId: number) { | |
); | ||
} | ||
|
||
const rowModifier = sheet.firstRowIsHeaders ? 2 : 1; | ||
problems.forEach((problem) => { | ||
if ('indices' in problem) { | ||
problem.rows = problem.indices.map((index) => index + rowModifier); | ||
} | ||
return problem; | ||
}); | ||
|
||
Comment on lines
+62
to
+69
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. This logic is quite "far back" in the stack of responsibilities, but still not so far back that it can be tested by any of our existing tests. It also relies on runtime type-checking logic which to me gives off just a little bit of code smell. I'm curious about why you decided to put the logic here, and not further back ( |
||
const hasError = problems.some( | ||
(problem) => levelForProblem(problem) == 'error' | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ export type ImportFieldProblem = { | |
field: string; | ||
indices: number[]; | ||
kind: ImportProblemKind.INVALID_FORMAT; | ||
rows?: number[]; | ||
}; | ||
|
||
export type ImportFieldMetaProblem = { | ||
|
@@ -29,6 +30,7 @@ export type ImportRowProblem = { | |
| ImportProblemKind.UNEXPECTED_ERROR | ||
| ImportProblemKind.UNKNOWN_PERSON | ||
| ImportProblemKind.UNKNOWN_ERROR; | ||
rows?: number[]; | ||
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. What is the benefit of adding this as a second property, over just rendering it +1 or +2 in the UI? |
||
}; | ||
|
||
export type ImportSheetProblem = { | ||
|
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.
What would be the downsides of just adding logic to either add +1 or +2 depending on
firstLineIsHeaders
here?