Skip to content

Commit

Permalink
fix(TreeData): identifier is not always "id' when unflattening
Browse files Browse the repository at this point in the history
- previous and recent commit was referencing the row data with `id` but in reality it's not always `id`, we should reference the `identifierPropName` in the method `unflattenParentChildArrayToTree()`
  • Loading branch information
ghiscoding-SE committed Sep 11, 2024
1 parent 386867a commit 78653f9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/common/src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ export function unflattenParentChildArrayToTree<P, T extends P & { [childrenProp
if (!(childrenPropName in p)) {
p[childrenPropName] = [];
}
const existIdx = p[childrenPropName]?.findIndex((x: any) => x.id === item.id);
if (existIdx < 0) {
p[childrenPropName].push(item);
} else {
const existIdx = p[childrenPropName]?.findIndex((x: any) => x[identifierPropName] === item[identifierPropName]);
if (existIdx >= 0) {
// replace existing one when already exists (probably equal to the same item in the end)
p[childrenPropName][existIdx] = item;
} else {
p[childrenPropName].push(item);
}
if (p[collapsedPropName] === undefined) {
p[collapsedPropName] = options?.initiallyCollapsed ?? false;
Expand Down

0 comments on commit 78653f9

Please sign in to comment.