Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 1x 2x 2x 2x 2x 2x 2x 2x | import { GroupedError, XlsxError } from './types'
export const groupErrorsByGroupAndPath = (arr: XlsxError[]): GroupedError[] => {
const grouped: { [key: string]: { message: string; paths: string[] }[] } = {}
arr.forEach(item => {
const group = item.payload?.xlsxErrorGroup
const path = item.propertyPath
const message = item.message
if (!grouped[group]) {
grouped[group] = []
}
const existingError = grouped[group].find(error => error.message === message)
if (existingError) {
if (!existingError.paths.includes(path)) {
existingError.paths.push(path)
}
} else {
grouped[group].push({
message,
paths: [path],
})
}
})
const result: GroupedError[] = Object.keys(grouped).map(group => {
return {
xlsxErrorGroup: group,
errors: grouped[group],
}
})
return result
}
|