fix(tgrid): create and assign unique data ids#3840
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue with tree grid data by ensuring unique IDs across duplicated records. Previously, the code was directly pushing the same data objects multiple times, resulting in duplicate IDs. Now, each record gets a unique ID by applying an offset based on the iteration.
Key changes:
- Modified data population logic to create unique IDs for duplicated records using an offset calculation
- Reduced iteration count from 15,000 to 9,000
- Removed duplicate
primaryKeyattribute from the tree grid template
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tree-grid-export-visualization.component.ts | Updated constructor to create new objects with unique IDs and ParentIDs using offset calculations |
| tree-grid-export-visualization.component.html | Removed duplicate primaryKey attribute declaration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ...item, | ||
| ID: item.ID + offset, | ||
| ParentID: item.ParentID === -1 ? -1 : item.ParentID + offset, | ||
| OrderDate: new Date(item.OrderDate) |
There was a problem hiding this comment.
Creating a new Date object from item.OrderDate assumes it's already a valid date input. If item.OrderDate is already a Date object, this creates a copy; if it's a string or timestamp, it parses it. However, if OrderDate is already being shared as a reference across multiple items in the original data, this could be necessary. Consider whether this conversion is intentional for all data types or if it should handle different input formats explicitly.
| OrderDate: new Date(item.OrderDate) | |
| OrderDate: (item.OrderDate instanceof Date) | |
| ? new Date(item.OrderDate.getTime()) | |
| : (typeof item.OrderDate === 'string' || typeof item.OrderDate === 'number') | |
| ? new Date(item.OrderDate) | |
| : null |
Closes #3829