benwinding / react-admin-import-csv

A csv file import button for react-admin
https://benwinding.github.io/react-admin-import-csv
MIT License
135 stars 46 forks source link

preCommitCallback running to late #51

Closed fkowal closed 3 years ago

fkowal commented 3 years ago

Hi

I wanted to discuss an issue i ran into to hopefully find a solution

The issue is that the preCommitCallback is called to late in the pipeline

My business case is that Business guy goes to react-admin exports an CSV fills out some missing information in 1 column and the imports the data back into the system

ie. He export 1000 rows, he fills only 50 and the uses the import CSV

So during import id like the pipeline to looks like

parseCSV -> preCommitCallback -> collisionDetection ....

With the currency pipeline
parseCSV -> collsionDetection -> ... -> very end preCommitCallback

The Override/replace Modal shows 950 rows that are going to be ignored

My suggestion would be

  1. add a config: {transform?: (csvRows[]) => csvRows[]) and invoke this right after GetCSVItems
  2. move th preCommitCallback invocation from being the last step to right after GetCSVItems

Adding this transformation after GetCsvItems would also greatly limits the data fetched/send to GetIdsColliding

I am also open to hearing other ideas

benwinding commented 3 years ago

Hi @fkowal,

Thanks for opening a new issue to discuss this further.

So during import id like the pipeline to looks like parseCSV -> preCommitCallback -> collisionDetection ....

  1. add a config: {transform?: (csvRows[]) => csvRows[]) and invoke this right after GetCSVItems
  2. move th preCommitCallback invocation from being the last step to right after GetCSVItems

Yes that seems like a better flow in my opinion, you can make a pull request if you'd like to try, or I can have a look at it in the next few weeks.

Some of these design decisions came after much discussion in this issue here #21. We basically decided to just immediately import all items which weren't colliding, and only warn if there were collisions (like the windows copy dialogue)