-
Notifications
You must be signed in to change notification settings - Fork 54
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
Tweak predictProblems logic, add test for it #2117
base: main
Are you sure you want to change the base?
Conversation
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.
Hi Haeju!! :D
I have played around with this a bit and read the code, and even though it does work for the case you are testing for - this solution, I think, can be made better because it has an unexpected buggy consequence...
If I run your code and import a file without giving selecting a first name, last name or id column, i get "unexpected error". If i do the same thing on main
, I get the error "you have not configured identifying columns", which is what should happen...
So, maybe experiment some more and see that it has no unexpected consequences!
@@ -75,6 +63,7 @@ export function predictProblems( | |||
customFields.forEach((field) => { | |||
customFieldsBySlug[field.slug] = field; | |||
}); | |||
let isMissingValue = false; |
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.
I am not really sure this variable is doing so much 😅 If I remove it from the code, the only difference is that I get both unconfigured ID error and "not all rows have identifiers" error, instead of just the latter.
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.
This is just for removing unconfigured ID error(yellow box). Thought that it is weird to show yellow box with text "I understand and want to proceed anyway" when there is an error. Should I remove isMissingValue
? @ziggabyte
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.
I think it makes sense to do what you've tried to do @kaulfield23, but I think the best way to do it is to write a test that reproduces the problem you found, and then fix it.
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.
@richardolsson Okay! will do 👍
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.
I think that case is already covered with the test I wrote ( test : returns problem when either the first name or last name value is missing ) . And the case that ziggi found is already covered with another test that already exists ( test : returns problem when ID or name are not configured )
Is there a case that I have not added? @richardolsson
@@ -133,11 +122,13 @@ export function predictProblems( | |||
} | |||
} | |||
hadImpact = true; | |||
} else { | |||
isMissingValue = true; |
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.
This made me a bit confused - this will be set to true if any "cell" in the sheet is empty, no matter if it is name/id or not.
Nice work @kaulfield23. Can you also write tests for the edge cases you've handled? |
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.
I've found a regression in this PR (i.e. a bug that was introduced in this PR that doesn't exist on main
). It may be the same thing that @ziggabyte pointed out in his previous review, and it still remains after the most recent commit. Below are instructions for how to reproduce it (and separate a comment on how I think it should be tested).
I think this needs to be fixed before this can be merged. But then I think we also need better testing in the future, and I've created a separate issue for this: #2156.
Steps to reproduce
Use a CSV file with this content (note the missing first name on the last row):
ID,FIRST,LAST,EMAIL
4,Clara,Zetkin,[email protected]
,Clara,Zetin,[email protected]
5,,Zetkin,[email protected]
Configure only the first name and the email address, not the ID or last name columns, and then click "VALIDATE"
Expected results
The user should be presented with an error message indicating that not enough identifying columns have been configured. This should be caught by predictProblems()
and prevent any API requests from being made. This currently works on main
.
Actual results
The user is presented with an "unknown" error message. An API request is made to the /preview API which immediately fails. This likely happens because predictProblems()
finds no errors.
field: 'first_name', | ||
kind: ColumnKind.FIELD, | ||
selected: true, |
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.
Try creating another test that is a copy of this one, except that this column is not configured (ColumnKind.UNKNOWN
and selected: false
). In my experimentation, that seems to not return a problem even though it should return UNCONFIGURED_ID_AND_NAME
because not the full name has been configured.
kind: ImportProblemKind.UNCONFIGURED_ID_AND_NAME, | ||
}, | ||
{ | ||
kind: 'NO_IMPACT', |
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.
I added a new test where column is not configured. And I got this 'NO_IMPACT' together in problem result. Is this fine?
sheetHasId && | ||
!rowHasId && | ||
(sheetHasFirstName || sheetHasLastName) && | ||
(missingFirstOrLastName || !sheetHasFirstName || !sheetHasLastName); |
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.
Handle a case where ID is missing when only one of name column is configured.
For example
columns: [
{
idField: 'id',
kind: ColumnKind.ID_FIELD,
selected: true,
},
{
field: 'first_name',
kind: ColumnKind.FIELD,
selected: true,
},
],
rows: [{ data: [null, 'Clara'] }],
on main
when there is no id value and only one of name is configured, it displays 'Something went wrong...'
I included that case in this fix but not 100% sure if returning ImportProblemKind.MISSING_ID_AND_NAME
is okay in this case
Description
This PR fixes
predictProblems
logic where it shows an error when name value is missing.Screenshots
People.-.Opera.2024-09-01.13-44-28.mp4
Changes
predictProblems.spec.ts
predictProblems
logicNotes to reviewer
Related issues
Resolves #2114