Skip to content

Commit

Permalink
Hierarchies-react: Fixed onHierarchyLimitExceeded callback of tree …
Browse files Browse the repository at this point in the history
…state hooks being called with incorrect `limit` value (#734)
  • Loading branch information
grigasp authored Oct 10, 2024
1 parent fdecc5b commit 3f2c165
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shaggy-turkeys-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@itwin/presentation-hierarchies-react": patch
---

Fixed `onHierarchyLimitExceeded` callback of [tree state hooks](./README.md#tree-state-hooks) being called with incorrect `limit` value.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class TreeLoader implements ITreeLoader {
parentId: parent.id,
};
if (isRowsLimitError(err)) {
this._onHierarchyLimitExceeded({ parentId: parent.id, filter: instanceFilter, limit: hierarchyLevelSizeLimit });
this._onHierarchyLimitExceeded({ parentId: parent.id, filter: instanceFilter, limit: err.limit });
return of([{ ...nodeProps, type: "ResultSetTooLarge" as const, resultSetSizeLimit: err.limit }]);
}
this._onHierarchyLoadError({ parentId: parent.id, type: isTimeoutError(err) ? "timeout" : "unknown" });
Expand Down
27 changes: 27 additions & 0 deletions packages/hierarchies-react/src/test/UseTree.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
PresentationHierarchyNode,
PresentationInfoNode,
PresentationNoFilterMatchesInfoNode,
PresentationResultSetTooLargeInfoNode,
PresentationTreeNode,
} from "../presentation-hierarchies-react/TreeNode";
import { UnifiedSelectionProvider } from "../presentation-hierarchies-react/UnifiedSelectionContext";
Expand Down Expand Up @@ -594,6 +595,32 @@ describe("useTree", () => {
});
});

it("reports nodes load performance", async () => {
hierarchyProvider.getNodes.callsFake(() => createAsyncIterator([]));
const onPerformanceMeasuredSpy = sinon.spy();
const { result } = renderHook(useTree, { initialProps: { ...initialProps, onPerformanceMeasured: onPerformanceMeasuredSpy } });

await waitFor(() => {
expect(result.current.rootNodes).to.deep.eq([]);
expect(onPerformanceMeasuredSpy).to.be.calledWith("initial-load", sinon.match.number);
});
});

it("reports when hierarchy level size exceeds limit", async () => {
hierarchyProvider.getNodes.callsFake(() => {
return throwingAsyncIterator(new hierarchiesModule.RowsLimitExceededError(555));
});
const onHierarchyLimitExceededSpy = sinon.spy();
const { result } = renderHook(useTree, { initialProps: { ...initialProps, onHierarchyLimitExceeded: onHierarchyLimitExceededSpy } });

await waitFor(() => {
expect(result.current.rootNodes).to.have.lengthOf(1);
const node = result.current.rootNodes![0] as PresentationResultSetTooLargeInfoNode;
expect(node.type).to.be.eq("ResultSetTooLarge");
expect(onHierarchyLimitExceededSpy).to.be.calledWith({ parentId: undefined, filter: undefined, limit: 555 });
});
});

it("handles error during nodes load", async () => {
hierarchyProvider.getNodes.callsFake(() => {
return throwingAsyncIterator(new Error("test error"));
Expand Down

0 comments on commit 3f2c165

Please sign in to comment.