* Transform report data by grouping components by componentId
(reportData: UserReport)
| 312 | * Transform report data by grouping components by componentId |
| 313 | */ |
| 314 | private transformReportData(reportData: UserReport): UserReport { |
| 315 | const components = reportData?.report?.detail?.components || []; |
| 316 | |
| 317 | if (!components?.length) return reportData; |
| 318 | |
| 319 | // Group components by componentId |
| 320 | const groupedComponentsMap = new Map<string, UserReport['report']['detail']['components'][number]>(); |
| 321 | |
| 322 | components.forEach((component: UserReport['report']['detail']['components'][number], index: number) => { |
| 323 | const { componentId, componentPath, elementId, validationInfo } = component; |
| 324 | const elementIndex = index + 1; |
| 325 | |
| 326 | if (!groupedComponentsMap.has(componentId)) { |
| 327 | groupedComponentsMap.set(componentId, { |
| 328 | componentId, |
| 329 | componentPath, |
| 330 | elements: [], |
| 331 | }); |
| 332 | } |
| 333 | |
| 334 | groupedComponentsMap.get(componentId)?.elements?.push({ |
| 335 | elementId: elementId || '', |
| 336 | elementIndex, |
| 337 | validationInfo: validationInfo || { x: 0, y: 0 }, |
| 338 | }); |
| 339 | }); |
| 340 | |
| 341 | const groupedComponents = Array.from(groupedComponentsMap.values()); |
| 342 | |
| 343 | return { |
| 344 | ...reportData, |
| 345 | report: { |
| 346 | ...reportData.report, |
| 347 | detail: { |
| 348 | ...reportData.report.detail, |
| 349 | components: groupedComponents, |
| 350 | }, |
| 351 | }, |
| 352 | }; |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Determine the root directory of the package by walking up to find package.json |