Skip to content

Commit

Permalink
Presentation: Fix Presentation.selection.selectionChange event not …
Browse files Browse the repository at this point in the history
…being emitted for `BlankConnection` (backport #7002) [release/4.7.x] (#7022)

Co-authored-by: Saulius Skliutas <[email protected]>
Co-authored-by: Grigas Petraitis <[email protected]>
  • Loading branch information
3 people authored Jul 31, 2024
1 parent e39ede9 commit aeb086d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/presentation-frontend",
"comment": "Fix `Presentation.selection.selectionChange` event not being emitted for `BlankConnection`.",
"type": "none"
}
],
"packageName": "@itwin/presentation-frontend"
}
8 changes: 4 additions & 4 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion full-stack-tests/presentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"deep-equal": "^1",
"faker": "^4.1.0",
"fast-sort": "^3.0.2",
"fast-xml-parser": "^4.3.5",
"fast-xml-parser": "^4.4.1",
"mocha": "^10.2.0",
"rimraf": "^3.0.2",
"sinon": "^17.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ export class SelectionManager implements ISelectionProvider {
}

private handleEvent(evt: SelectionChangeEventArgs): void {
if (!this._knownIModels.has(evt.imodel.key)) {
this._knownIModels.set(evt.imodel.key, evt.imodel);
}

switch (evt.changeType) {
case SelectionChangeType.Add:
this._selectionStorage.addToSelection({
Expand Down Expand Up @@ -370,6 +374,7 @@ export class SelectionManager implements ISelectionProvider {
return this._currentSelection.computeSelection(args.iModelKey, args.level, currentSelectables, args.selectables).pipe(
mergeMap(({ level, changedSelection }): Observable<SelectionChangeEventArgs> => {
const imodel = this._knownIModels.get(args.iModelKey);
// istanbul ignore if
if (!imodel) {
return EMPTY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { expect } from "chai";
import * as sinon from "sinon";
import { assert, BeDuration, Id64, Id64Arg, Id64String, StopWatch, using } from "@itwin/core-bentley";
import { IModelApp, IModelConnection, SelectionSet, SelectionSetEventType } from "@itwin/core-frontend";
import { BlankConnection, IModelApp, IModelConnection, SelectionSet, SelectionSetEventType } from "@itwin/core-frontend";
import { InstanceKey, KeySet, NodeKey, SelectionScope, StandardNodeTypes } from "@itwin/presentation-common";
import {
createRandomId,
Expand Down Expand Up @@ -432,6 +432,23 @@ describe("SelectionManager", () => {
selectionManager.replaceSelection(source, imodel, []);
expect(raiseEventSpy, "Expected selectionChange.raiseEvent to not be called").to.not.have.been.called;
});

it("fires `selectionChange` event after `addToSelection`, `replaceSelection`, `clearSelection`, `removeFromSelection` with `BlankConnection", async () => {
// creating blank connection does not raise `IModelConnection.onOpen` event.
const blankImodel = { key: "blank", name: "blankConnection" } as BlankConnection;
const raiseEventSpy = sinon.spy(selectionManager.selectionChange, "raiseEvent");
selectionManager.addToSelection(source, blankImodel, baseSelection);
await waitFor(() => expect(raiseEventSpy, "Expected selectionChange.raiseEvent to be called").to.have.callCount(1));
selectionManager.removeFromSelection(source, blankImodel, baseSelection);
await waitFor(() => expect(raiseEventSpy, "Expected selectionChange.raiseEvent to be called").to.have.callCount(2));
selectionManager.replaceSelection(source, blankImodel, baseSelection);
await waitFor(() => expect(raiseEventSpy, "Expected selectionChange.raiseEvent to be called").to.have.callCount(3));
selectionManager.clearSelection(source, blankImodel);
await waitFor(() => expect(raiseEventSpy, "Expected selectionChange.raiseEvent to be called").to.have.callCount(4));

// simulate connection closing
IModelConnection.onClose.raiseEvent(blankImodel);
});
});

describe("setSyncWithIModelToolSelection", () => {
Expand Down

0 comments on commit aeb086d

Please sign in to comment.