( sheet: SheetDefinition, csvHeaders: string[] )
| 26 | } |
| 27 | |
| 28 | function buildSheetSuggestedHeaderMappings( |
| 29 | sheet: SheetDefinition, |
| 30 | csvHeaders: string[] |
| 31 | ): ColumnMapping[] { |
| 32 | const mappings: ColumnMapping[] = []; |
| 33 | |
| 34 | csvHeaders.forEach((header) => { |
| 35 | const foundField = sheet.columns.find((column) => { |
| 36 | if (!allowUserToMapColumn(column)) { |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | const keywords = [ |
| 41 | column.id, |
| 42 | ...(column.suggestedMappingKeywords || []), |
| 43 | ].map((k) => normalizeValue(k)); |
| 44 | |
| 45 | const normalizedHeader = normalizeValue(header); |
| 46 | |
| 47 | return keywords.includes(normalizedHeader); |
| 48 | }); |
| 49 | |
| 50 | if (!foundField) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | mappings.push({ |
| 55 | csvColumnName: header, |
| 56 | sheetId: sheet.id, |
| 57 | sheetColumnId: foundField.id, |
| 58 | }); |
| 59 | }); |
| 60 | |
| 61 | return mappings; |
| 62 | } |
| 63 | |
| 64 | export const buildSuggestedHeaderMappings = ( |
| 65 | sheetDefinitions: SheetDefinition[], |
no test coverage detected