({
onMappingsChanged,
onMappingsSet,
onBack,
}: Props)
| 20 | } |
| 21 | |
| 22 | export default function HeaderMapper({ |
| 23 | onMappingsChanged, |
| 24 | onMappingsSet, |
| 25 | onBack, |
| 26 | }: Props) { |
| 27 | const { columnMappings, parsedFile } = useImporterState(); |
| 28 | const { sheets: sheetDefinitions } = useImporterDefinition(); |
| 29 | const { t } = useTranslations(); |
| 30 | const [hoveredCsvHeader, setHoveredCsvHeader] = useState<string | null>(null); |
| 31 | |
| 32 | const currentMapping = columnMappings ?? []; |
| 33 | const parsed = parsedFile!; |
| 34 | |
| 35 | const data = parsed.data; |
| 36 | const csvHeaders = parsed.meta.fields!; |
| 37 | |
| 38 | const mappingSelectOptions = useMappingAvailableSelectOptions( |
| 39 | sheetDefinitions, |
| 40 | currentMapping |
| 41 | ); |
| 42 | |
| 43 | const mapingsValid = areAllRequiredMappingsSet( |
| 44 | sheetDefinitions, |
| 45 | currentMapping |
| 46 | ); |
| 47 | |
| 48 | const hoveredExamples = useMemo(() => { |
| 49 | if (!hoveredCsvHeader) return []; |
| 50 | return calculateMappingExamples(data, hoveredCsvHeader); |
| 51 | }, [hoveredCsvHeader, data]); |
| 52 | |
| 53 | const [isMappingInProgress, setIsMappingInProgress] = useState(false); |
| 54 | |
| 55 | async function handleConfirm() { |
| 56 | try { |
| 57 | setIsMappingInProgress(true); |
| 58 | await onMappingsSet(); |
| 59 | } finally { |
| 60 | setIsMappingInProgress(false); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return ( |
| 65 | <div className="flex h-full flex-col"> |
| 66 | <div className="flex-none text-2xl">{t('mapper.reviewAndConfirm')}</div> |
| 67 | <div className="min-h-0 flex-auto"> |
| 68 | <div className="flex h-full justify-between space-x-5"> |
| 69 | <div className="flex flex-2 flex-col"> |
| 70 | <div className="my-5 flex text-sm font-light uppercase"> |
| 71 | <div className="flex-1">{t('mapper.importedColumn')}</div> |
| 72 | <div className="flex-1">{t('mapper.destinationColumn')}</div> |
| 73 | </div> |
| 74 | <div className="flex-1 overflow-y-auto"> |
| 75 | {csvHeaders.map((header, columnIndex) => { |
| 76 | const headerMapping = |
| 77 | currentMapping.find( |
| 78 | (mapping) => mapping.csvColumnName === header |
| 79 | ) ?? null; |
nothing calls this directly
no test coverage detected