From 864573ef9d328a6b8156f1b0eb4e7f90cfcef4bb Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 19:48:41 +0200 Subject: [PATCH] working leantime widget 74 --- components/flow.tsx | 51 +++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/components/flow.tsx b/components/flow.tsx index 36962b9b..737e90f2 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -89,49 +89,32 @@ export function Flow() { .filter((task: Task) => task.headline && typeof task.headline === 'string' && - task.status !== 3 // Not completed + task.status !== 5 && // Not done + task.editorId === '2' // Only tasks assigned to user 2 ) .sort((a: Task, b: Task) => { - // Define priority order for tasks - const priorityOrder = [ - 'Mettre en ligne site wix SLM-SA', - 'Bi-Dimension Investment', - 'Draft Pax Index Mvt 4 CARE', - 'Finaliser Pax Index Mvt 5 Data Intelligence Governance DIG', - 'Continuous Improving Cycle : Risk Monitoring + Model Assessments + Learning Machine', - 'Rediger pétition ODD18 et intégration au site CLM', - 'complete ressources background and quote' - ]; + // Get valid dates for comparison + const getValidDate = (task: Task) => { + if (task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00') { + return new Date(task.dateToFinish).getTime(); + } + return Number.MAX_SAFE_INTEGER; // Put tasks without due date at the end + }; - const aIndex = priorityOrder.indexOf(a.headline); - const bIndex = priorityOrder.indexOf(b.headline); + const dateA = getValidDate(a); + const dateB = getValidDate(b); - // If both tasks are in the priority list, sort by their position - if (aIndex !== -1 && bIndex !== -1) { - return aIndex - bIndex; + // Sort by date first + if (dateA !== dateB) { + return dateA - dateB; } - // If only one task is in the priority list, it comes first - if (aIndex !== -1) return -1; - if (bIndex !== -1) return 1; - - // For tasks not in the priority list, sort by status and date - if (a.status !== b.status) { - return a.status - b.status; - } - - const dateA = a.dateToFinish && a.dateToFinish !== '0000-00-00 00:00:00' - ? new Date(a.dateToFinish).getTime() - : Number.MAX_SAFE_INTEGER; - const dateB = b.dateToFinish && b.dateToFinish !== '0000-00-00 00:00:00' - ? new Date(b.dateToFinish).getTime() - : Number.MAX_SAFE_INTEGER; - - return dateA - dateB; + // If dates are equal, sort by status + return a.status - b.status; }); console.log('Filtered and sorted tasks:', sortedTasks); - setTasks(sortedTasks); // Remove the slice(0, 6) to show all tasks + setTasks(sortedTasks); setError(null); } catch (err) { console.error('Error fetching tasks:', err);