Added Duplicate-field mapping and minimum-mapping requirements #15442
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.
I think this needs some UI love, for sure, and definitely some testing. But after that, I think it should be ready to go.
This handles a few problems - the main one being where if you switch from one import type to another, the field-names didn't get properly updated. That was getting users confused where they thought we had features we didn't, when you picked import-type: Assets, and then say, oops, I meant Accessories! The field names wouldn't quite update right.
Next, once I got that working I decided to change the "QTY" option in the drop-down to "Quantity" which I think reads a little better. In working with that, I found that we were not 'auto-guessing' quantity fields quite right, so I fixed that.
While I was there, I decided to add some code to detect if you try to map two separate CSV fields to the same Snipe-IT field. That doesn't make sense, and we shouldn't allow it.
And finally, I Implemented the start of some logic to prevent you from importing if you don't map the basic number of required fields. We can probably start to expand this out as we figure out more detailed rules on what we can and cannot allow, so I went generally pretty conservatively here - the hope would be that I would rather you import and error, rather than us incorrectly disallow you from importing.
UI fixes needed:
I don't like the visual way I display the "duplicate fields detected" thing. I just put some placeholder text in there, but it should be translated and look more error-ey, and maybe even live somewhere else in the UI.
Right now there's no really clear feedback on when you haven't mapped enough fields - the submit button just goes 'disabled'. And I suspect I don't correctly disable the submit button when you have mapping duplicates - that feature didn't exist yet when I built the first part.
And I had to do a lot of logic to figure out what the minimum fields you had to map, mostly by looking at the importer itself. I'm not necessarily sure I got all of that right.
I'm also uncomfortable with the minimal_fields function thing - it looks a little gross in places, and I hate the
@
signs being sprinkled anywhere. But this was already getting too big anyways.