@commercetools-frontend-extensions/operations 3.1.2 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -2
- package/dist/commercetools-frontend-extensions-operations.cjs.dev.js +84 -72
- package/dist/commercetools-frontend-extensions-operations.cjs.prod.js +84 -72
- package/dist/commercetools-frontend-extensions-operations.esm.js +83 -68
- package/dist/declarations/src/@api/file-import-jobs.d.ts +21 -0
- package/dist/declarations/src/@api/import-containers.d.ts +5 -1
- package/dist/declarations/src/@hooks/use-file-upload.d.ts +0 -1
- package/dist/declarations/src/@types/file-import-job.d.ts +7 -1
- package/dist/declarations/src/@utils/file-upload.d.ts +0 -8
- package/package.json +9 -9
- package/src/@api/file-import-jobs.ts +52 -0
- package/src/@api/import-containers.ts +34 -3
- package/src/@components/uploading-modal/uploading-modal.tsx +6 -4
- package/src/@hooks/use-file-upload.ts +2 -15
- package/src/@types/file-import-job.ts +12 -11
- package/src/@utils/file-upload.ts +0 -39
|
@@ -131,45 +131,6 @@ export const countJsonFileItems = async (
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
/**
|
|
135
|
-
* Count unique resources in a CSV file by counting unique values in the "key" column.
|
|
136
|
-
* A single resource can span multiple rows (when it has array fields like variants, assets...),
|
|
137
|
-
* so we count unique keys rather than rows.
|
|
138
|
-
* @param file The CSV file to process
|
|
139
|
-
* @returns A promise that resolves to the number of unique resources
|
|
140
|
-
*/
|
|
141
|
-
export const countUniqueResourcesInCsv = (file: File): Promise<number> => {
|
|
142
|
-
return new Promise((resolve) => {
|
|
143
|
-
const uniqueKeys = new Set<string>()
|
|
144
|
-
let keyColumnIndex = -1
|
|
145
|
-
let isFirstRow = true
|
|
146
|
-
|
|
147
|
-
Papa.parse<string[]>(file, {
|
|
148
|
-
step: ({ data }) => {
|
|
149
|
-
if (!Array.isArray(data)) return
|
|
150
|
-
|
|
151
|
-
if (isFirstRow) {
|
|
152
|
-
keyColumnIndex = data.findIndex(
|
|
153
|
-
(col) => col?.toLowerCase().trim() === 'key'
|
|
154
|
-
)
|
|
155
|
-
isFirstRow = false
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (keyColumnIndex === -1) return
|
|
160
|
-
|
|
161
|
-
const keyValue = data[keyColumnIndex]?.trim()
|
|
162
|
-
if (keyValue) {
|
|
163
|
-
uniqueKeys.add(keyValue)
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
complete: () => {
|
|
167
|
-
resolve(uniqueKeys.size)
|
|
168
|
-
},
|
|
169
|
-
})
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
|
|
173
134
|
/**
|
|
174
135
|
* Map file upload errors to upload file error rows with unique IDs
|
|
175
136
|
* @param uploadFileErrors Array of file upload errors
|