frontend-collective / frontend-collective/react-sortable-tree

getTreeFromFlatData duplicating child nodes

Open
#851 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5k
Forks
914
PR merge metrics
No merged PRs in 30d

Description

My use case is that I have tree data in json that represents a document tree. The flat data has an ID and a parent's ID to represent the structure. Some components of the document can be re-used throughout the document tree. The issue I have is that when I feed this json to getTreeFromFlatData, the resulting tree duplicates child nodes of the reused content. A simple example of what I see in the included screenshot:
![image](https://user-images.githubusercontent.com/6294758/103926333-04484280-50d6-11eb-9c22-072a1c638852.png)

Note that "My Test Image" is only in document "Copy of Simple Topic 1" once. But because "Copy of Simple Topic 1" is included in the tree twice, at different levels, I think the child is being added twice, in each location it's parent is found.

My call to create the tree is;
var treeStruct = getTreeFromFlatData({
flatData: this.props.treeInfo.map(node => ({ ...node, name: node.name })),
getKey: node => node.guid, // resolve a node's key
getParentKey: node => node.parentGuid, // resolve a node's parent's key
rootKey: null, // The value of the parent key when there is no parent (i.e., at root level)
});

and a "node" looks like the following (note the use of guid for ID and parentGuid for the parent:
{
"guid": "GUID-2FC3F579-3764-40F2-8536-A5ED691817A6",
"title": "Copy of Simple Topic 1",
"language": "en",
"parentGuid": "GUID-D1DA3DCB-F85F-436C-B0AF-FE3814C568D4",
"type": "ISHModule",
"subtype": null,
"edt": "EDTXML",
"version": "1",
"author": "Admin",
"created": "04/01/2021 21:25:30",
"modified": "04/01/2021 21:39:05",
"lngref": "3502058",
"status": "Draft",
"copyAction": null,
"lockedName": null,
"versionComments": "Test reuse issue with pub dup tree indexing fix",
"modifiedBy": "Admin"
},

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.