Skip to content

Uncontrolled tree state is not changed #244

@bcburak

Description

@bcburak

I'm trying to create a new node with the same level of tree structure. In React side it's all working with useState. I expect the existing tree will re-render and showed the updated "treeItems" state, however I can not see the tree nodes with updated tree state.
How should I add a new node with a specific properties I define?

Here is my tree and state code;

`const actualTree: ExactTree = {
  root: {
    index: "root",
    canMove: true,
    isFolder: true,
    children: ["Projects"],
    data: "root",
    canRename: true,
    countIndex: 2,
  },
  Projects: {
    index: "Projects",
    canMove: true,
    isFolder: true,
    children: ["GarbageCollector"],
    data: "Projects",
    canRename: true,
    countIndex: 2,
  },
  GarbageCollector: {
    index: "GarbageCollector",
    canMove: true,
    isFolder: true,
    children: ["Mas", "Blueberry"],
    data: "GarbageCollector",
    canRename: true,
    countIndex: 2,
  },
  Mas: {
    index: "Mas",
    canMove: true,
    isFolder: false,
    data: "Mas",
    canRename: true,
    countIndex: 2,
  },
  Blueberry: {
    index: "Blueberry",
    canMove: true,
    isFolder: false,
    data: "Blueberry",
    canRename: true,
    countIndex: 3,
  },
};`
` <UncontrolledTreeEnvironment<string>
            canDragAndDrop
            canDropOnFolder
            canReorderItems
            dataProvider={
              new StaticTreeDataProvider(
                treeItems as ExactTree,
                (item, data) => ({
                  ...item,
                  data,
                })
              )
            }
            getItemTitle={(item) => item.data}
            onFocusItem={(item) => setFocusedItem(item)}
            canRename={true}
            defaultInteractionMode={{
              mode: "custom",
              createInteractiveElementProps: (
                item,
                treeId,
                actions,
                renderFlags
              ) => ({
                onDoubleClick: (e) => {
                  e.preventDefault();
                  onTreeItemDoubleClick(e, item);
                },
                tabIndex: !renderFlags.isRenaming
                  ? renderFlags.isFocused
                    ? 0
                    : -1
                  : undefined,
              }),
            }}
            viewState={{
              "tree-1": {
                expandedItems: [],
              },
            }}
            {...bpRenderers}
          >
            <Tree treeId="tree-1" rootItem="root" treeLabel="Projects tree" />
          </UncontrolledTreeEnvironment>`
const addNewTreeNode = (nodeName: any) => {
       nodeName = "Environment";

    const treeNode = {
      index: nodeName,
      canMove: true,
      isFolder: false,
      data: nodeName,
      canRename: true,
      countIndex: 2,
    };

    actualTree[nodeName] = treeNode;
    // const jsonArray = JSON.stringify([actualTree]);
  
    setTreeItems(actualTree);
    console.log("setted", treeItems);
  };

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions