working leantime widget 74

This commit is contained in:
Alma 2025-04-12 19:48:41 +02:00
parent bead369139
commit 864573ef9d

View File

@ -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);