From 1ec97594343c526fe42e51f363b5c0dc37b0a130 Mon Sep 17 00:00:00 2001 From: chamiakJ Date: Tue, 3 Jun 2025 17:45:03 +0530 Subject: [PATCH] feat(reporting-allocation): update members and utilization filters to handle "Clear All" scenario - Enhanced members filter logic to return no data when no members are selected. - Updated utilization filter to return an empty array when no utilization states are selected, improving clarity in reporting results. --- .../reporting-allocation-controller.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts b/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts index 0bef5bb1..1987d0fb 100644 --- a/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts +++ b/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts @@ -567,11 +567,14 @@ export default class ReportingAllocationController extends ReportingControllerBa const billableQuery = this.buildBillableQueryWithAlias(billable, 't'); const members = (req.body.members || []) as string[]; - // Prepare members filter + // Prepare members filter - updated logic to handle Clear All scenario let membersFilter = ""; if (members.length > 0) { const memberIds = members.map(id => `'${id}'`).join(","); membersFilter = `AND tmiv.team_member_id IN (${memberIds})`; + } else { + // No members selected - show no data (Clear All scenario) + membersFilter = `AND 1=0`; // This will match no rows } // Prepare projects filter @@ -655,7 +658,6 @@ export default class ReportingAllocationController extends ReportingControllerBa // Precompute totalWorkingHours * 3600 for efficiency const totalWorkingSeconds = totalWorkingHours * 3600; - const hasUtilizationFilter = utilization.length > 0; // calculate utilization state for (let i = 0, len = result.rows.length; i < len; i++) { @@ -691,9 +693,15 @@ export default class ReportingAllocationController extends ReportingControllerBa } } - const filteredRows = hasUtilizationFilter - ? result.rows.filter(member => utilization.includes(member.utilization_state)) - : result.rows; + // Apply utilization filter + let filteredRows; + if (utilization.length > 0) { + // Filter to only show selected utilization states + filteredRows = result.rows.filter(member => utilization.includes(member.utilization_state)); + } else { + // No utilization states selected - show no data (Clear All scenario) + filteredRows = []; + } // Calculate totals const total_time_logs = filteredRows.reduce((sum, member) => sum + parseFloat(member.logged_time || '0'), 0);