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 Grid not using getId on select all #11086

Merged
merged 2 commits into from
Jul 30, 2018
Merged

Conversation

tsuoanttila
Copy link
Contributor

@tsuoanttila tsuoanttila commented Jul 26, 2018

Fixes #11083


This change is Reviewable

@tsuoanttila tsuoanttila changed the title Fix/grid select all get Fix Grid not using getId on select all Jul 26, 2018
Copy link
Contributor

@mehdi-vaadin mehdi-vaadin left a comment

Choose a reason for hiding this comment

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

What about doing some refactoring and change the type of selection to HashMap where the ids can be kept as key and the objects as values? It may be better in terms of performance.

Reviewed 1 of 2 files at r1.
Reviewable status: 1 of 2 files reviewed, 2 unresolved discussions (waiting on @tsuoanttila)


server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java, line 436 at r1 (raw file):

Quoted 6 lines of code…
        addedItems.removeIf(item -> removedItems.remove(item));
 
        if (selection.containsAll(addedItems)
                && Collections.disjoint(selection, removedItems)) {
            return;
        }

This part should also be changed.


server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java, line 442 at r1 (raw file):

removedItems.isEmpty()

Although removedItems is not empty, nothing may be removed from selection, therefore allSelected shouldn't be set to false. So, it may be better to set allSelected after removing items and make sure that at least one item is really removed.

Copy link
Contributor

@mehdi-vaadin mehdi-vaadin left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r1.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @tsuoanttila)

Copy link
Contributor Author

@tsuoanttila tsuoanttila left a comment

Choose a reason for hiding this comment

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

In the default case of we'd store the element into the hashmap twice, since by default the id is the item itself (which is true when the equals and hashcode are implemented properly). Would need to investigate if it makes some of the already existing update logic more complex.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @tsuoanttila)


server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java, line 436 at r1 (raw file):

Previously, mehdi-vaadin (Mehdi Javan) wrote…
        addedItems.removeIf(item -> removedItems.remove(item));
 
        if (selection.containsAll(addedItems)
                && Collections.disjoint(selection, removedItems)) {
            return;
        }

This part should also be changed.

This code block attempts to be a shortcut for the case where there is actually no changes at all. In the case of actually having different objects is a valid concern, as updating the selection also updates the current cache of selected items.

I'm not even sure if it ever makes sense to shortcut it at all.


server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java, line 442 at r1 (raw file):

Previously, mehdi-vaadin (Mehdi Javan) wrote…
removedItems.isEmpty()

Although removedItems is not empty, nothing may be removed from selection, therefore allSelected shouldn't be set to false. So, it may be better to set allSelected after removing items and make sure that at least one item is really removed.

This PR is not about universally solving the case of all selection updates. Yes, without digging deeper into the code I can't know if there's something maybe broken with this or maybe not. The issue of this PR is about the select all not using the getId to properly identify the selected items.

If there's an issue with this, it should be made into a ticket and handled in it's own PR.

Copy link
Contributor

@mehdi-vaadin mehdi-vaadin left a comment

Choose a reason for hiding this comment

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

You are right. it needs more investigation.

Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @mehdi-vaadin)


server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java, line 436 at r1 (raw file):

Previously, tsuoanttila (Teemu Suo-Anttila) wrote…

This code block attempts to be a shortcut for the case where there is actually no changes at all. In the case of actually having different objects is a valid concern, as updating the selection also updates the current cache of selected items.

I'm not even sure if it ever makes sense to shortcut it at all.

When using getId is ignored here to find out whether we have any change or not, then we may end up in return and doing nothing. Of course, only in some rare cases.
One more thing is that it looks confusing since two different methods are used to compare objects.


server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java, line 442 at r1 (raw file):

Previously, tsuoanttila (Teemu Suo-Anttila) wrote…

This PR is not about universally solving the case of all selection updates. Yes, without digging deeper into the code I can't know if there's something maybe broken with this or maybe not. The issue of this PR is about the select all not using the getId to properly identify the selected items.

If there's an issue with this, it should be made into a ticket and handled in it's own PR.

OK

Copy link
Contributor Author

@tsuoanttila tsuoanttila left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @tsuoanttila)


server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java, line 436 at r1 (raw file):

Previously, mehdi-vaadin (Mehdi Javan) wrote…

When using getId is ignored here to find out whether we have any change or not, then we may end up in return and doing nothing. Of course, only in some rare cases.
One more thing is that it looks confusing since two different methods are used to compare objects.

True. In the case of removing a not-equals item we might skip it, but not sure how we would end up in that situation. Will fix this.

Copy link
Contributor Author

@tsuoanttila tsuoanttila left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @mehdi-vaadin)


server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java, line 436 at r1 (raw file):

Previously, tsuoanttila (Teemu Suo-Anttila) wrote…

True. In the case of removing a not-equals item we might skip it, but not sure how we would end up in that situation. Will fix this.

Done.

Copy link
Contributor

@mehdi-vaadin mehdi-vaadin left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@tsuoanttila tsuoanttila merged commit 0860c19 into master Jul 30, 2018
@tsuoanttila tsuoanttila deleted the fix/gridSelectAllGetId branch July 30, 2018 09:48
@tsuoanttila tsuoanttila added this to the 8.5.1 milestone Jul 30, 2018
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