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

Fix 'select' method to allow deselecting selection #129

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

adiletelf
Copy link
Contributor

  • Fix 'select' method to allow deselecting selection
  • Check if 'callback' is defined in MockISelectionManager (as in API)
  • Add tests for MockISelectionManager

Please, view the source code for 'select' method.

Copy link
Contributor

@AleksSavelev AleksSavelev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you copied select method from selectionManager and this is correct, but I'm not sure if we should copy spaghetti code, what do you think?

resolve(this.selectionIds);
}) as any;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a lot of If else blocks and all of them have the same this.selectionIds = selectionIds

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is right, you can make it much easier:

if(multiSelect){
...all your ifs here
} else {
   this.selectionIds = selectionIds
}

Copy link
Contributor Author

@adiletelf adiletelf Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the code to make it more readable.

// if no multiselect reset current selection and save new passed selections;
if (!multiSelect) {
this.selectionIds = selectionIds;
if (selectionIds.length < 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectionIds.length === 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -112,6 +133,8 @@ export class MockISelectionManager implements ISelectionManager {
}

public simutateSelection(selections: ISelectionId[]): void {
this.callback(selections);
if (this.callback && typeof this.callback === "function") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type guard is enough here, it also checks for undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


const selectedIds: ISelectionId[] = selectionManager.getSelectionIds();
expect(selectedIds).toHaveSize(3);
expect(selectedIds[0].equals(selectionId0)).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(selectedIds[0]).toEqual(selectionId0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines +173 to +175
const selectionId0: ISelectionId = createSelectionId("0");
const selectionId1: ISelectionId = createSelectionId("1");
const selectionId2: ISelectionId = createSelectionId("2");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create a variable with these selectionIds and then compare it with the result using toEqual

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

CHANGELOG.md Outdated
@@ -1,3 +1,7 @@
## 6.1.2
* Fix 'select' method to allow deselecting selection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix 'select' method in MockISelectionManager to allow deselecting selection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

this.selectionIds = this.selectionIds.filter(x => !selectionIds[0].equals(x));
} else {
// if multiSelect is off, the selected item is the new selectedId, else deselect the selection
this.selectionIds = selectionIds.length > 1 ? selectionIds : [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here would be always an empty array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's the expected behavior too. Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants