From 7297e302129f8dbec0c29a74b9db91f6cca65c1d Mon Sep 17 00:00:00 2001 From: Alexandre Brandizzi Date: Thu, 24 Sep 2026 21:45:06 -0300 Subject: [PATCH] fix(dashboard): count All time over the same window the board lists (SH-392) The Unassigned drill-down opens the board with no range, which searches 2000-01-01..2099-12-31 plus undated work. The All time count had no bounds, so a work order dated outside that window was counted but not listed. The count now uses the same window. --- .../DashboardUnassignedTests.cs | 3 +++ .../Helpers/WorkOrderBoardQueryFilters.cs | 8 ++++++++ .../Implementation/DashboardDataService.cs | 11 +++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Api.SeaHavenIndustries.Tests/DashboardUnassignedTests.cs b/Api.SeaHavenIndustries.Tests/DashboardUnassignedTests.cs index dbdbc7e..b3cc03e 100644 --- a/Api.SeaHavenIndustries.Tests/DashboardUnassignedTests.cs +++ b/Api.SeaHavenIndustries.Tests/DashboardUnassignedTests.cs @@ -152,6 +152,9 @@ public class DashboardUnassignedTests { using var ctx = NewContext(); Seed(ctx); + // Dated outside the board's all-weeks window: neither side may count them. + ctx.workOrders.AddRange(Wo(11, new DateTime(1999, 12, 31)), Wo(12, new DateTime(2100, 1, 1))); + ctx.SaveChanges(); var user = AccountUser(1); var stats = await NewDashboard(ctx).GetStatsAsync( diff --git a/SeaHaven.DataServices/Helpers/WorkOrderBoardQueryFilters.cs b/SeaHaven.DataServices/Helpers/WorkOrderBoardQueryFilters.cs index b665f2c..d4810ca 100644 --- a/SeaHaven.DataServices/Helpers/WorkOrderBoardQueryFilters.cs +++ b/SeaHaven.DataServices/Helpers/WorkOrderBoardQueryFilters.cs @@ -5,6 +5,14 @@ namespace SeaHaven.DataServices.Helpers { public static class WorkOrderBoardQueryFilters { + /// + /// The window the Work Orders board searches when no date range is selected + /// (client ADVANCED_SEARCH_ALL_WEEKS_FROM/TO), used with includeDateless. + /// Counts that drill into that list use it too, so both see the same rows. + /// + public static readonly DateOnly AllWeeksFrom = new(2000, 1, 1); + public static readonly DateOnly AllWeeksTo = new(2099, 12, 31); + public static IQueryable ApplyBaseScope(IQueryable query) => query.Where(w => w.istemplate != true && (w.IsDeleted != true || w.IsDeleted == null)); diff --git a/SeaHaven.DataServices/Implementation/DashboardDataService.cs b/SeaHaven.DataServices/Implementation/DashboardDataService.cs index 7f9767f..02362a2 100644 --- a/SeaHaven.DataServices/Implementation/DashboardDataService.cs +++ b/SeaHaven.DataServices/Implementation/DashboardDataService.cs @@ -61,8 +61,15 @@ namespace SeaHaven.DataServices.Implementation query = WorkOrderBoardQueryFilters.ApplyDispatcherFilter( query, new[] { "__unassigned__" }, myWorkOrders: false, currentUserId: null); query = WorkOrderBoardQueryFilters.ApplyStatusFilter(query, OpenLifecycleStatuses); - if (dateFrom is DateOnly from && dateTo is DateOnly to) - query = WorkOrderBoardQueryFilters.ApplyDateRangeFilter(query, from, to); + // All time counts what the board lists with no range: every week plus + // undated work, so the tile and its drill-down agree (SH-392). + query = dateFrom is DateOnly from && dateTo is DateOnly to + ? WorkOrderBoardQueryFilters.ApplyDateRangeFilter(query, from, to) + : WorkOrderBoardQueryFilters.ApplyDateRangeFilter( + query, + WorkOrderBoardQueryFilters.AllWeeksFrom, + WorkOrderBoardQueryFilters.AllWeeksTo, + includeDateless: true); return await query.CountAsync(cancellationToken); }