-
Notifications
You must be signed in to change notification settings - Fork 47
CSV Import: allow using ignored fields as slug #519
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
base: main
Are you sure you want to change the base?
Conversation
| const possibleSlugFields = calculatePossibleSlugFields(initialMappings, csvRecords) | ||
| setSelectedSlugFieldName(possibleSlugFields[0]?.columnName ?? null) | ||
| const slugField = collection.slugFieldName | ||
| ? (possibleSlugFields.find(field => field.columnName === collection.slugFieldName) ?? |
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.
If we match an existing slug mapped on its own column, won't that result in us ignoring the slug values for new rows? I need to test this out
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 don't think so. Slug values are never ignored - you get an error in additems() if a row has no slug.
| action: "map", | ||
| targetFieldId: matchingField.id, | ||
| hasTypeMismatch, | ||
| action: isSlugField ? "ignore" : "map", |
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.
Hm I just tried an import on a new collection and it didn't auto-ignore the slug column, maybe the change I proposed needs a bugfix
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.
Was the slug column's name the same as the slug field name on the collection, usually "Slug"? It only auto ignores it if the slug column name matches, because we don't want to ignore it by default if it's using a different column for the slug like "Title" for example.
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.
If you copy and paste this table in with the Slug column, it should make the Slug field ignored by default. But if you copy without the first column then it should make Title the slug field and not make Title ignored.
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.
Ah good point.
So I think this might be confusing to be honest, not sure most users will understand why that column is disabled. And also if we're only covering the scenario where the slug name is the same as a column name, then displaying the mapping isn't a bad thing or incorrect right?
Maybe we should bring @johannes-ger in on the discussion?
Description
This pull request updates the CSV import plugin to allow using fields that are ignored/disabled as the slug field. This fixes an issue where if your CSV has a slug column, it would create duplicate fields because it would import as both the slug value and as a separate field.
I also made it check if there's a column that matches the slug field name, and if so it will be selected by default and the row will be ignored by default to avoid creating a duplicate slug field.
Testing
Google Sheet for testing: https://docs.google.com/spreadsheets/d/1JuOKh_Wb0uIytKe4eE7uI6Js826i8V_uf2oFtyolDtA/edit?gid=1174080602#gid=1174080602