Skip to content

Commit

Permalink
DYN-7754: filter exclusivity (#15630)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnenov authored Nov 12, 2024
1 parent ff657a7 commit 496183c
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,8 @@ Dynamo.PackageManager.PackageManagerSearchViewModel.FilterEntry.FilterName.get -
Dynamo.PackageManager.PackageManagerSearchViewModel.FilterEntry.FilterName.set -> void
Dynamo.PackageManager.PackageManagerSearchViewModel.FilterEntry.GroupName.get -> string
Dynamo.PackageManager.PackageManagerSearchViewModel.FilterEntry.GroupName.set -> void
Dynamo.PackageManager.PackageManagerSearchViewModel.FilterEntry.IsEnabled.get -> bool
Dynamo.PackageManager.PackageManagerSearchViewModel.FilterEntry.IsEnabled.set -> void
Dynamo.PackageManager.PackageManagerSearchViewModel.FilterEntry.OnChecked.get -> bool
Dynamo.PackageManager.PackageManagerSearchViewModel.FilterEntry.OnChecked.set -> void
Dynamo.PackageManager.PackageManagerSearchViewModel.FilterEntry.Tooltip.get -> string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ public class FilterEntry : NotificationObject
/// </summary>
public string Tooltip { get; set; }

/// <summary>
/// Controls the IsEnabled status of the filter
/// </summary>
private bool isEnabled = true;

public bool IsEnabled
{
get { return isEnabled; }
set
{
isEnabled = value;
RaisePropertyChanged(nameof(IsEnabled));
}
}


/// <summary>
/// Filter entry click command, notice this is a dynamic command
/// with command param set to FilterName so that the code is robust
Expand Down Expand Up @@ -410,6 +426,33 @@ public bool IsAnyFilterOn
private void SetFilterChange()
{
IsAnyFilterOn = HostFilter.Any(f => f.OnChecked) || NonHostFilter.Any(f => f.OnChecked) || CompatibilityFilter.Any(f => f.OnChecked);
ApplyFilterRules();
}

/// <summary>
/// Executes any additional logic on the filters
/// </summary>
internal void ApplyFilterRules()
{
// Enable/disable Compatibility filters if any HostFilter is on
if (CompatibilityFilter.Any(f => f.OnChecked))
{
HostFilter.ForEach(x => x.IsEnabled = false);
}
else
{
HostFilter.ForEach(x => x.IsEnabled = true);
}

// Enable/disable Host filters if any CompatibilityFilter is on
if (HostFilter.Any(f => f.OnChecked))
{
CompatibilityFilter.ForEach(x => x.IsEnabled = false);
}
else
{
CompatibilityFilter.ForEach(x => x.IsEnabled = true);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
<Setter Property="Command" Value="{Binding FilterCommand}" />
<Setter Property="CommandParameter" Value="{Binding FilterName}" />
<Setter Property="IsChecked" Value="{Binding OnChecked, UpdateSourceTrigger=PropertyChanged}" />
<Setter Property="IsEnabled" Value="{Binding IsEnabled, UpdateSourceTrigger=PropertyChanged}" />
<Setter Property="ToolTip">
<Setter.Value>
<ToolTip Content="{Binding Tooltip}" Style="{StaticResource GenericToolTipLight}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,57 @@ public void TestComputeVersionNoDynamoCompatibility()
Assert.IsTrue(resultFallbackToDynamo, "Expected compatibility to be true when under host but only Dynamo compatibility is provided.");
}

[Test]
public void HostCompatibilityFiltersExclusivity()
{
var mockGreg = new Mock<IGregClient>();

var clientMock = new Mock<PackageManagerClient>(mockGreg.Object, MockMaker.Empty<IPackageUploadBuilder>(), string.Empty);
var pmCVM = new Mock<PackageManagerClientViewModel>(ViewModel, clientMock.Object) { CallBase = true };
var pmSVM = new PackageManagerSearchViewModel(pmCVM.Object);
pmSVM.RegisterTransientHandlers();

pmSVM.HostFilter = new List<FilterEntry>
{
new FilterEntry("host", "group", "tooltip", pmSVM) { OnChecked = false },
};

pmSVM.CompatibilityFilter = new List<FilterEntry>
{
new FilterEntry("compatibility", "group", "tooltip", pmSVM) { OnChecked = false },
};

pmSVM.HostFilter.ForEach(f => f.PropertyChanged += pmSVM.filter_PropertyChanged);
pmSVM.CompatibilityFilter.ForEach(f => f.PropertyChanged += pmSVM.filter_PropertyChanged);

Assert.IsTrue(pmSVM.HostFilter.All(x => x.IsEnabled), "Expect starting filter state to be enabled");
Assert.IsTrue(pmSVM.CompatibilityFilter.All(x => x.IsEnabled), "Expect starting filter state to be enabled");

// Act/Assert Host -> Compatibility
pmSVM.HostFilter.First().OnChecked = true;
pmSVM.ApplyFilterRules();

Assert.IsFalse(pmSVM.CompatibilityFilter.All(x => x.IsEnabled), "Filter groups should be mutually exclusive");

pmSVM.HostFilter.First().OnChecked = false;
pmSVM.ApplyFilterRules();

Assert.IsTrue(pmSVM.CompatibilityFilter.All(x => x.IsEnabled), "Filter groups should be mutually exclusive");

// Act/Assert Compatibility -> Host
pmSVM.CompatibilityFilter.First().OnChecked = true;
pmSVM.ApplyFilterRules();

Assert.IsFalse(pmSVM.HostFilter.All(x => x.IsEnabled), "Filter groups should be mutually exclusive");

pmSVM.CompatibilityFilter.First().OnChecked = false;
pmSVM.ApplyFilterRules();

Assert.IsTrue(pmSVM.HostFilter.All(x => x.IsEnabled), "Filter groups should be mutually exclusive");
}

#region Compatibility Tests

[Test]
public void TestReverseDynamoCompatibilityFromHost()
{
Expand Down Expand Up @@ -1329,5 +1380,7 @@ public void IsVersionCompatible_InValidMaxRange_ReturnsTrueForVersionInsideOfMaj
"Expected compatibility to be true when major version is greater than Max major version and there is an invalid max range.");
}

#endregion

}
}

0 comments on commit 496183c

Please sign in to comment.