Skip to content

Commit

Permalink
SQ recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander van Delft committed Dec 16, 2024
1 parent 0a34b2e commit 92c284c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
18 changes: 10 additions & 8 deletions COMET.Web.Common.Tests/Components/CardView/CardViewTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class CardViewTestFixture
private TestClass testClass2 = new ();
private TestClass testClass3 = new ();
private TestClass[] testClasses;
private string[] searchFields = new[] { "Id", "Name" };
private string[] sortFields = new[] { string.Empty, "Id", "Name" };

private static RenderFragment<TestClass> NormalTemplate()
{
Expand Down Expand Up @@ -118,8 +120,8 @@ public void VerifyComponent()
Assert.That(cardView.Instance.AllowSort, Is.True);
Assert.That(cardView.Instance.AllowSearch, Is.True);
Assert.That(cardView.Instance.ItemSize, Is.EqualTo(150));
Assert.That(cardView.Instance.SearchFields, Is.EquivalentTo(new [] {"Id", "Name"}));
Assert.That(cardView.Instance.SortFields, Is.EquivalentTo(new[] { string.Empty, "Id", "Name" }));
Assert.That(cardView.Instance.SearchFields, Is.EquivalentTo(this.searchFields));
Assert.That(cardView.Instance.SortFields, Is.EquivalentTo(this.sortFields));
});

var textBoxParentComponent = component.Find("#search-textbox");
Expand Down Expand Up @@ -297,8 +299,8 @@ public void VerifySelectComponent()
Assert.That(cardView.Instance.AllowSort, Is.True);
Assert.That(cardView.Instance.AllowSearch, Is.True);
Assert.That(cardView.Instance.ItemSize, Is.EqualTo(150));
Assert.That(cardView.Instance.SearchFields, Is.EquivalentTo(new[] { "Id", "Name" }));
Assert.That(cardView.Instance.SortFields, Is.EquivalentTo(new[] { string.Empty, "Id", "Name" }));
Assert.That(cardView.Instance.SearchFields, Is.EquivalentTo(this.searchFields));
Assert.That(cardView.Instance.SortFields, Is.EquivalentTo(this.sortFields));
});

var firstCardField = component.Find(".card");
Expand Down Expand Up @@ -330,8 +332,8 @@ public async Task VerifySearchComponent()
Assert.That(cardView.Instance.AllowSort, Is.True);
Assert.That(cardView.Instance.AllowSearch, Is.True);
Assert.That(cardView.Instance.ItemSize, Is.EqualTo(150));
Assert.That(cardView.Instance.SearchFields, Is.EquivalentTo(new[] { "Id", "Name" }));
Assert.That(cardView.Instance.SortFields, Is.EquivalentTo(new[] { string.Empty, "Id", "Name" }));
Assert.That(cardView.Instance.SearchFields, Is.EquivalentTo(this.searchFields));
Assert.That(cardView.Instance.SortFields, Is.EquivalentTo(this.sortFields));
});

var textBoxParentComponent = component.Find("#search-textbox");
Expand Down Expand Up @@ -395,8 +397,8 @@ public async Task VerifySortComponent()
Assert.That(cardView.Instance.AllowSort, Is.True);
Assert.That(cardView.Instance.AllowSearch, Is.True);
Assert.That(cardView.Instance.ItemSize, Is.EqualTo(150));
Assert.That(cardView.Instance.SearchFields, Is.EquivalentTo(new[] { "Id", "Name" }));
Assert.That(cardView.Instance.SortFields, Is.EquivalentTo(new[] { string.Empty, "Id", "Name" }));
Assert.That(cardView.Instance.SearchFields, Is.EquivalentTo(this.searchFields));
Assert.That(cardView.Instance.SortFields, Is.EquivalentTo(this.sortFields));
Assert.That(cardView.Instance.SelectedSortField == string.Empty);
});

Expand Down
6 changes: 3 additions & 3 deletions COMET.Web.Common/Components/CardView/CardField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ namespace COMET.Web.Common.Components.CardView
public class CardField<T> : ComponentBase
{
/// <summary>
/// The <see cref="TypeAccessor"/> used to read properties from the instance of <see cref="T"/>.
/// The <see cref="FastMember.TypeAccessor"/> used to read properties from the instance of T.
/// This is a static property on a generic type, so it will have different static values for each used generic type in the application
/// </summary>
private static TypeAccessor typeAccessor { get; set; }
private static TypeAccessor typeAccessor;

Check warning on line 45 in COMET.Web.Common/Components/CardView/CardField.cs

View workflow job for this annotation

GitHub Actions / Build

A static field in a generic type is not shared among instances of different close constructed types. (https://rules.sonarsource.com/csharp/RSPEC-2743)

/// <summary>
/// Initializes the static properties of this <see cref="CardField{T}"/> class
Expand Down Expand Up @@ -71,7 +71,7 @@ static CardField()
public T Context { get; set; }

/// <summary>
/// Gets or sets the FieldName (propertyname of <see cref="T"/>) to show in the UI
/// Gets or sets the FieldName (propertyname of T) to show in the UI
/// </summary>
[Parameter]
public string FieldName { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions COMET.Web.Common/Components/CardView/CardView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</DxTextBox>
</td>
<td id="sort-dropdown" style="visibility:@(this.AllowSort ? "block": "hidden");">
<DxComboBox TData="string" TValue="string" CssClass="inline-sort-icon" FilteringMode="DataGridFilteringMode.Contains" SizeMode="SizeMode.Medium" Data="@this.SortFields" SelectedItemChanged="@((string x) => this.OnSelectedSortItemChanged(x))"
<DxComboBox TData="string" TValue="string" CssClass="inline-sort-icon" FilteringMode="DataGridFilteringMode.Contains" SizeMode="SizeMode.Medium" Data="@this.SortFields" SelectedItemChanged="@( x => this.OnSelectedSortItemChanged(x))"
@bind-Value="@this.SelectedSortField">
</DxComboBox>
</td>
Expand All @@ -44,10 +44,10 @@
<ItemContent>
<div class="col" style="padding-left:0px;margin-left:0px;height:(@this.ItemSize)px;min-width:(@this.MinWidth)px;">
<div class="card @(this.GetSelectedClass(@context))"
@onclick="@(() => this.selectItem(@context))">
@onclick="@(() => this.SelectItem(@context))">
<div class="card-body" style="overflow-y:hidden;overflow-x:hidden">
<CascadingValue Name="CardView" Value = "this">
<CascadingValue Name="SearchTerm" Value="this.searchTerm">
<CascadingValue Name="SearchTerm" Value="this.SearchTerm">
@this.ItemTemplate(@context)
</CascadingValue>
</CascadingValue>
Expand Down
26 changes: 13 additions & 13 deletions COMET.Web.Common/Components/CardView/CardView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public partial class CardView<T> : DisposableComponent
public float MinWidth { get; set; } = 250;

/// <summary>
/// Gets or sets a collection of propertynames of type <see cref="T"/>to perform search on
/// Gets or sets a collection of propertynames of type T to perform search on
/// </summary>
public HashSet<string> SearchFields { get; private set; } = [];

/// <summary>
/// Gets or sets a collection of propertynames of type <see cref="T"/> to perform sorting on
/// Gets or sets a collection of propertynames of type T to perform sorting on
/// </summary>
public SortedSet<string> SortFields { get; private set; } = [string.Empty];

Expand All @@ -93,7 +93,7 @@ public partial class CardView<T> : DisposableComponent
private Virtualize<T>? virtualize; // Reference to the Virtualize component

Check warning on line 93 in COMET.Web.Common/Components/CardView/CardView.razor.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 93 in COMET.Web.Common/Components/CardView/CardView.razor.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 93 in COMET.Web.Common/Components/CardView/CardView.razor.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 93 in COMET.Web.Common/Components/CardView/CardView.razor.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 93 in COMET.Web.Common/Components/CardView/CardView.razor.cs

View workflow job for this annotation

GitHub Actions / Build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 93 in COMET.Web.Common/Components/CardView/CardView.razor.cs

View workflow job for this annotation

GitHub Actions / Build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 93 in COMET.Web.Common/Components/CardView/CardView.razor.cs

View workflow job for this annotation

GitHub Actions / Build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 93 in COMET.Web.Common/Components/CardView/CardView.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 93 in COMET.Web.Common/Components/CardView/CardView.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 93 in COMET.Web.Common/Components/CardView/CardView.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 93 in COMET.Web.Common/Components/CardView/CardView.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// The FastMember <see cref="TypeAccessor"/> to use to perform actions on instances of <see cref="T"/>
/// The FastMember <see cref="FastMember.TypeAccessor"/> to use to perform actions on instances of type T
/// </summary>
private TypeAccessor typeAccessor = TypeAccessor.Create(typeof(T));

Expand All @@ -105,7 +105,7 @@ public partial class CardView<T> : DisposableComponent
/// <summary>
/// Gets or sets the term where to search/filter items on
/// </summary>
private string searchTerm { get; set; } = string.Empty;
public string SearchTerm { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the term where to sort items on
Expand All @@ -125,23 +125,23 @@ private string GetSelectedClass(T vm)
/// <summary>
/// Set the selected item
/// </summary>
/// <param name="item">The item <see cref="T"/></param>
private void selectItem(T item)
/// <param name="item">The item of type T</param>
public void SelectItem(T item)
{
this.selected = item;
}

/// <summary>
/// Filters the list of items to show in the UI based on the <see cref="searchTerm"/>
/// Filters the list of items to show in the UI based on the <see cref="SearchTerm"/>
/// </summary>
/// <param name="request">The request to perform filtering of the items list</param>
/// <returns>an waitable <see cref="ValueTask"/></returns>
private async ValueTask<ItemsProviderResult<T>> LoadItems(ItemsProviderRequest request)
private ValueTask<ItemsProviderResult<T>> LoadItems(ItemsProviderRequest request)

Check warning on line 139 in COMET.Web.Common/Components/CardView/CardView.razor.cs

View workflow job for this annotation

GitHub Actions / Build

Add the 'Async' suffix to the name of this method. (https://rules.sonarsource.com/csharp/RSPEC-4261)
{
// Filter items based on the SearchTerm
var filteredItems = !this.AllowSearch || string.IsNullOrWhiteSpace(this.searchTerm)
var filteredItems = !this.AllowSearch || string.IsNullOrWhiteSpace(this.SearchTerm)
? this.Items
: this.Items.Where(item => this.FilterItem(item, this.searchTerm)).ToList();
: this.Items.Where(item => this.FilterItem(item, this.SearchTerm)).ToList();

// Return paged items for virtualization
var items = filteredItems.Skip(request.StartIndex).Take(request.Count);
Expand All @@ -151,11 +151,11 @@ private async ValueTask<ItemsProviderResult<T>> LoadItems(ItemsProviderRequest r
items = items.AsQueryable().OrderBy(this.SelectedSortField);
}

return new ItemsProviderResult<T>(items.ToList(), filteredItems.Count);
return new ValueTask<ItemsProviderResult<T>>(new ItemsProviderResult<T>(items.ToList(), filteredItems.Count));
}

/// <summary>
/// Used to filter items based on the <see cref="searchTerm"/>
/// Used to filter items based on the <see cref="SearchTerm"/>
/// </summary>
/// <param name="item">The item to perform searching on</param>
/// <param name="query">The string to search for</param>
Expand All @@ -182,7 +182,7 @@ private bool FilterItem(T item, string query)
/// <param name="value">The text from the UI element's event</param>
private void OnSearchTextChanged(string value)
{
this.searchTerm = value ?? string.Empty;
this.SearchTerm = value ?? string.Empty;

this.virtualize?.RefreshDataAsync(); // Tell Virtualize to refresh data
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public interface IElementDefinitionDetailsViewModel
/// <summary>
/// A collection of <see cref="ElementDefinitionDetailsRowViewModel" />
/// </summary>
ICollection<ElementDefinitionDetailsRowViewModel> Rows { get; set; }
ICollection<ElementDefinitionDetailsRowViewModel> Rows { get; }
}
}

0 comments on commit 92c284c

Please sign in to comment.