Import column mapper
Match CSV or spreadsheet columns to import fields with auto-matching and sample previews.
Installation
Writes app/components/import-column-mapper.tsx and adds @shopify/polaris-types@2.0.0 once authenticated.
API reference
columnsRequiredreadonly ImportColumn[]Pass columns in file order with a unique id, a display label, and optional sample or samples strings. Repeated headers show their one-based column positions.- Required
fieldsRequiredreadonly ImportField[]Pass destination fields with id, label, optional description details, optional required flag, and optional header aliases used by auto-match.- Required
valueRequiredImportMappingKey the mapping by destination field id. Use a source column id for a match, omit for unmapped, or use null to skip an optional field.- Required
onChangeRequired(value: ImportMapping) => voidAccept the new controlled mapping and use it with the parsed rows when preparing the import.- Required
previewRows / showAutoMatch / maxPreviewRows / defaultPreviewOpenreadonly Readonly<Record<string, string>>[] / boolean / number / booleanSupply parsed rows keyed by column id for a collapsible mapped-row preview (maxPreviewRows caps table rows, defaultPreviewOpen sets initial expanded state, while field sample cards collect up to 3 distinct values from column.sample, column.samples, and previewRows), and toggle the Auto-match columns helper.showAutoMatch: true, maxPreviewRows: 3errorsImportMappingErrorsPass validation messages keyed by destination field id. Missing required mappings and references to removed columns have built-in messages.OptionalheadingstringName the column mapping section.Map columnsdisabledbooleanDisable mapping edits while the host is loading a file or submitting the import.false
Run under Shopify App Home AppProvider. Point polarisUrl to the Polaris 2.0 runtime.
Mount the mapper after parsing the file, use autoMatchImportColumns(columns, fields, existing) to pre-map matching headers while preserving manual selections and explicit skips, and reset when the merchant replaces the file.
When multiple destination fields select the same source column, each shared sample card shows a non-blocking collision badge without preventing submission.
The CSV example validates product data locally. Pass onSave to ProductImportForm to persist or queue the draft in your authenticated import action.