Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presentation: Fix hierarchy auto update #3628

Merged
merged 4 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/api/presentation-components.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ export abstract class PropertyRecordsBuilder implements IContentVisitor {
// @internal (undocumented)
export interface ReloadedHierarchyPart {
// (undocumented)
nodeItems: TreeNodeItem[];
nodeItems: DelayLoadedTreeNodeItem[];
// (undocumented)
offset: number;
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/presentation-components",
"comment": "Fix: set correct node's children count after hierarchy update",
"type": "none"
}
],
"packageName": "@itwin/presentation-components"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

import * as React from "react";
import { Subscription } from "rxjs/internal/Subscription";
import { HierarchyUpdateRecord, PageOptions, UPDATE_FULL } from "@itwin/presentation-common";
import { IModelHierarchyChangeEventArgs, Presentation } from "@itwin/presentation-frontend";
import {
computeVisibleNodes, isTreeModelNode, isTreeModelNodePlaceholder, MutableTreeModel, MutableTreeModelNode, PagedTreeNodeLoader, RenderedItemsRange,
TreeModelNode, TreeModelNodeInput, TreeModelSource, TreeNodeItem, usePagedTreeNodeLoader, VisibleTreeNodes,
computeVisibleNodes, DelayLoadedTreeNodeItem, isTreeModelNode, isTreeModelNodePlaceholder, MutableTreeModel, MutableTreeModelNode,
PagedTreeNodeLoader, RenderedItemsRange, TreeModelNode, TreeModelNodeInput, TreeModelSource, TreeNodeItem, usePagedTreeNodeLoader, VisibleTreeNodes,
} from "@itwin/components-react";
import { HierarchyUpdateRecord, PageOptions, UPDATE_FULL } from "@itwin/presentation-common";
import { IModelHierarchyChangeEventArgs, Presentation } from "@itwin/presentation-frontend";
import { RulesetRegistrationHelper } from "../../common/RulesetRegistrationHelper";
import { PresentationTreeDataProvider, PresentationTreeDataProviderProps } from "../DataProvider";
import { IPresentationTreeDataProvider } from "../IPresentationTreeDataProvider";
Expand Down Expand Up @@ -330,7 +330,7 @@ async function updateModelSourceAfterIModelChange(
/** @internal */
export interface ReloadedHierarchyPart {
parentId: string | undefined;
nodeItems: TreeNodeItem[];
nodeItems: DelayLoadedTreeNodeItem[];
offset: number;
}

Expand Down Expand Up @@ -398,15 +398,15 @@ function rebuildSubTree(oldModel: MutableTreeModel, newModel: MutableTreeModel,
}
}

function createModelNodeInput(oldNode: MutableTreeModelNode | undefined, newNode: TreeNodeItem): TreeModelNodeInput {
function createModelNodeInput(oldNode: MutableTreeModelNode | undefined, newNode: DelayLoadedTreeNodeItem): TreeModelNodeInput {
const newInput = {
description: newNode.description,
isExpanded: !!newNode.autoExpand,
id: newNode.id,
item: newNode,
label: newNode.label,
isLoading: false,
numChildren: 0,
numChildren: !newNode.hasChildren ? 0 : undefined,
isSelected: false,
};
if (!oldNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,35 @@ describe("applyHierarchyUpdateRecords", () => {
expect(updatedTree.getNode("root1")?.description).to.be.eq("updated-description");
});

it("updates node children count to 'undefined' when it is collapsed and has children", () => {
const initialTree = createTreeModel([
{
root1: [
"child1",
"child2",
],
},
]);

const updatedTree = applyHierarchyChanges(
initialTree,
[{
parent: undefined,
nodesCount: 1,
expandedNodes: [{
node: { ...createNode("root1"), description: "updated-description", hasChildren: true },
position: 0,
}],
}],
[],
{}
);

expectTree(updatedTree, ["root1"]);
expect(updatedTree.getNode("root1")?.description).to.be.eq("updated-description");
expect(updatedTree.getNode("root1")?.numChildren).to.be.undefined;
});

it("updates root node and adds reloaded siblings", () => {
const initialTree = createTreeModel(["root1", "root2", "root3"]);

Expand Down