Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Conversation

@grokys
Copy link
Contributor

@grokys grokys commented Jul 5, 2016

The empty list item was getting added twice: once by the XAML and once in PullRequestListViewModel. This adds a new overload of TrackingCollection.CreateListenerCollection so that the logical can be carried out at the VM layer instead of being mixed between VM and view.

Fixes #390.

@shana
Copy link
Contributor

shana commented Jul 5, 2016

This fix is not correct. Selecting [None] should remove it from the list and reset the filter to nothing, so everything shows up. [None] should only be visible when there is a selection in the list. The StickieListItemConverter is there to return null if [None] is set (so that the filter is reset), and the interaction behaviour is there to add/remove the [None] item on top of the list, depending on the selection.

@grokys
Copy link
Contributor Author

grokys commented Jul 5, 2016

Ok, I'd misunderstood the intention then. Will try and work out the correct fix.

@shana
Copy link
Contributor

shana commented Jul 5, 2016

Initially, [None] should not be on the list, the interaction behaviour should be removing it when things load. It could be the IAccount type comparison not detecting that [None] and [None] are the same, and failing to initially remove it, which might explain why it looks duplicated. A quick unit test using the same data and asserting identity comparisons might work. Maybe I'm doing == instead of Equals in the logic (I've tweaked comparison implementations a bit, so that might have broken it)

grokys added 3 commits July 5, 2016 15:53
If the source tracking collection already contains items at the time
`CreateListenerCollection` is called, make sure the listener collection
is populated with these items.
Added a method that creates an observable collection that tracks an
ITrackingCollection and adds a sticky item to the top of the collection
when a related selection is null.
grokys added 2 commits July 5, 2016 16:25
Instead of using a behavior to add/remove the [None] item in the pull
request list view, use the new listener collection to add/remove it.
This should now be implemented at the viewmodel level using
CreateListenerCollection.
@grokys grokys force-pushed the fixes/390-none-added-twice-to-filters branch from 5fdff92 to 2edd3e4 Compare July 5, 2016 14:27
@paladique
Copy link
Contributor

👍

@shana
Copy link
Contributor

shana commented Jul 6, 2016

I added two tests that clarify the behaviour this should have when initially created and when the TrackingCollection is reset. They're failing 😉

Also, the [None] selection is broken:
Nevermind the gif above, my checkout had some stale code!

@shana
Copy link
Contributor

shana commented Jul 6, 2016

Seeing as the SelectedAssignee and SelectedAuthor are being set twice (once with None and then with null), we should probably filter out the None value when updating the filter, there's no point in filtering twice. Something like this perhaps?

this.WhenAny(x => x.SelectedAssignee, x => x.Value)
                 .Where(x => x != EmptyAssignee)
                 .Where(x => PullRequests != null)
                 .Subscribe(a => UpdateFilter(SelectedState, a, SelectedAuthor));

this.WhenAny(x => x.SelectedAuthor, x => x.Value)
                 .Where(x => x != EmptyAuthor)
                 .Where(x => PullRequests != null)
                 .Subscribe(a => UpdateFilter(SelectedState, SelectedAssignee, a));

grokys added 2 commits July 7, 2016 10:42
Setting the Author/Assignee filter to [None] should not trigger a filter
in the view model: doing this will remove the [None] entry from Authors,
which will cause the selection in the view to be set to null which will
reset the filter.
{
foreach (var item in stickieItemsOnTop)
if (addedStickieItem)
{
Copy link
Contributor

@shana shana Jul 7, 2016

Choose a reason for hiding this comment

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

How about we just do a result.FirstOrDefault() == stickieItemOnTop instead of tracking with a flag? We know it's always going to be either the first or not there at all, and that way we don't have to keep state (and the first element look up is fast and doesn't consume the whole collection). That would work equally well to replace the hasSelection flag, too (or maybe not entirely for that flag, I'm trying to follow all the edge cases in my head here but brain is tired)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I was wondering about that, but assumed you had a scenario in mind when writing it like that.

if (col.Contains(item))
offset++;
result.Remove(stickieItemOnTop);
hasStickieItem = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't need to be set.

@shana shana merged commit 649387a into master Jul 8, 2016
@shana shana deleted the fixes/390-none-added-twice-to-filters branch July 8, 2016 12:11
@shana
Copy link
Contributor

shana commented Jul 8, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants