()
| 74 | } |
| 75 | setOpen(true); |
| 76 | async function processCSV(): Promise<[any[], boolean]> { |
| 77 | // Is valid csv |
| 78 | if (!file) { |
| 79 | throw new Error("File not processed from input field"); |
| 80 | } |
| 81 | logger.log("Parsing CSV file"); |
| 82 | const csvRows = await GetCSVItems(logging, translate, file, parseConfig); |
| 83 | const csvItems = transformRows ? await transformRows(csvRows) : csvRows |
| 84 | mounted && setValues(csvItems); |
| 85 | // Does CSV pass user validation |
| 86 | logger.log("Validating CSV file"); |
| 87 | await CheckCSVValidation(logging, translate, csvItems, validateRow); |
| 88 | // Are there any import overwrites? |
| 89 | logger.log("Checking rows to import"); |
| 90 | const collidingIds = await GetIdsColliding( |
| 91 | logging, |
| 92 | translate, |
| 93 | dataProvider, |
| 94 | csvItems, |
| 95 | resourceName, |
| 96 | disableGetMany, |
| 97 | ); |
| 98 | mounted && setIdsConflicting(collidingIds); |
| 99 | const hasCollidingIds = !!collidingIds.length; |
| 100 | logger.log("Has colliding ids?", { hasCollidingIds, collidingIds }); |
| 101 | if (!hasCollidingIds) { |
| 102 | return [csvItems, hasCollidingIds]; |
| 103 | } |
| 104 | // Ask Replace X Rows? Skip these rows? Decied For Each? |
| 105 | const collidingIdsStringsSet = new Set(collidingIds.map((id) => id+'')); |
| 106 | const collidingIdsNumbersSet = new Set(); |
| 107 | |
| 108 | const collidingIdsAsNumbers = collidingIds.map((id) => parseFloat(id+'')); |
| 109 | const allCollidingIdsAreNumbers = collidingIdsAsNumbers.every(id => isFinite(id)); |
| 110 | if (allCollidingIdsAreNumbers) { |
| 111 | collidingIdsAsNumbers.map(id => collidingIdsNumbersSet.add(id)) |
| 112 | } |
| 113 | function idNotInNumbersOrStrings(item: any) { |
| 114 | const matchesIdString = collidingIdsStringsSet.has(item.id+'') |
| 115 | const matchesIdNumber = collidingIdsNumbersSet.has(+item.id) |
| 116 | return !(matchesIdNumber || matchesIdString); |
| 117 | } |
| 118 | const csvItemsNotColliding = csvItems.filter(idNotInNumbersOrStrings); |
| 119 | logger.log("Importing items which arent colliding", { |
| 120 | csvItemsNotColliding, |
| 121 | }); |
| 122 | return [csvItemsNotColliding, hasCollidingIds]; |
| 123 | } |
| 124 | |
| 125 | processCSV() |
| 126 | .then(async ([csvItems, hasCollidingIds]) => { |
no test coverage detected