Refactor Teams components for improved sorting and filtering functionality

Updated the Teams Index and Printout components to prioritize sorting by EventFormat, enhancing the organization of team data. Introduced a regional filter toggle in the Teams Index to allow users to view only regional teams. Adjusted the ScheduledTeamsList to sort teams by EventFormat first, ensuring consistent ordering across components. Additionally, added necessary using directives for improved code clarity.
This commit is contained in:
2026-01-04 14:56:28 -05:00
parent c6fb00c7f4
commit 83522ac52c
7 changed files with 150 additions and 19 deletions
+46
View File
@@ -0,0 +1,46 @@
using Core.Entities;
namespace WebApp.Models;
/// <summary>
/// Extension methods for sorting teams with group teams (EventFormat.Team) appearing before individual teams (EventFormat.Individual).
/// </summary>
public static class TeamExtensions
{
/// <summary>
/// Orders teams with group teams (EventFormat.Team) first, then individual teams (EventFormat.Individual).
/// For use with EF Core IQueryable queries.
/// </summary>
/// <param name="teams">The queryable collection of teams to sort.</param>
/// <returns>An ordered queryable with group teams first, then individual teams.</returns>
public static IOrderedQueryable<Team> OrderByEventFormatFirst(this IQueryable<Team> teams)
{
return teams.OrderByDescending(t => t.Event.EventFormat == EventFormat.Team ? 1 : 0);
}
/// <summary>
/// Orders teams with group teams (EventFormat.Team) first, then individual teams (EventFormat.Individual).
/// For use with in-memory IEnumerable collections.
/// </summary>
/// <param name="teams">The collection of teams to sort.</param>
/// <returns>An ordered enumerable with group teams first, then individual teams.</returns>
public static IOrderedEnumerable<Team> OrderByEventFormatFirst(this IEnumerable<Team> teams)
{
return teams.OrderByDescending(t => t.Event.EventFormat == EventFormat.Team ? 1 : 0);
}
/// <summary>
/// Orders teams with group teams first, then applies default secondary sorting:
/// Event.Name (ascending), then Identifier (ascending with nulls last).
/// </summary>
/// <param name="teams">The collection of teams to sort.</param>
/// <returns>An ordered enumerable with group teams first and default secondary sorting applied.</returns>
public static IOrderedEnumerable<Team> OrderByEventFormatFirstWithDefaults(this IEnumerable<Team> teams)
{
return teams
.OrderByEventFormatFirst()
.ThenBy(t => t.Event.Name)
.ThenBy(t => t.Identifier ?? "");
}
}