feat: enhance column visibility toggle with task counts
- Added `tasks` prop to `ColumnVisibilityToggle` for displaying task counts per status. - Updated `KanbanFilters` to calculate and show counts for priorities and tags, improving filter visibility. - Integrated task counts into UI elements for better user feedback on task distribution across statuses, priorities, and tags.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { useState, useEffect, useRef, useMemo } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { TaskPriority } from '@/lib/types';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
@@ -26,7 +26,7 @@ interface KanbanFiltersProps {
|
||||
}
|
||||
|
||||
export function KanbanFilters({ filters, onFiltersChange }: KanbanFiltersProps) {
|
||||
const { tags: availableTags } = useTasksContext();
|
||||
const { tags: availableTags, tasks } = useTasksContext();
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const [isSortExpanded, setIsSortExpanded] = useState(false);
|
||||
const sortDropdownRef = useRef<HTMLDivElement>(null);
|
||||
@@ -113,10 +113,29 @@ export function KanbanFilters({ filters, onFiltersChange }: KanbanFiltersProps)
|
||||
|
||||
const activeFiltersCount = (filters.tags?.length || 0) + (filters.priorities?.length || 0) + (filters.search ? 1 : 0);
|
||||
|
||||
// Calculer les compteurs pour les priorités
|
||||
const priorityCounts = useMemo(() => {
|
||||
const counts: Record<string, number> = {};
|
||||
getAllPriorities().forEach(priority => {
|
||||
counts[priority.key] = tasks.filter(task => task.priority === priority.key).length;
|
||||
});
|
||||
return counts;
|
||||
}, [tasks]);
|
||||
|
||||
// Calculer les compteurs pour les tags
|
||||
const tagCounts = useMemo(() => {
|
||||
const counts: Record<string, number> = {};
|
||||
availableTags.forEach(tag => {
|
||||
counts[tag.name] = tasks.filter(task => task.tags?.includes(tag.name)).length;
|
||||
});
|
||||
return counts;
|
||||
}, [tasks, availableTags]);
|
||||
|
||||
const priorityOptions = getAllPriorities().map(priorityConfig => ({
|
||||
value: priorityConfig.key,
|
||||
label: priorityConfig.label,
|
||||
color: priorityConfig.color
|
||||
color: priorityConfig.color,
|
||||
count: priorityCounts[priorityConfig.key] || 0
|
||||
}));
|
||||
|
||||
return (
|
||||
@@ -270,7 +289,7 @@ export function KanbanFilters({ filters, onFiltersChange }: KanbanFiltersProps)
|
||||
className="w-2 h-2 rounded-full"
|
||||
style={{ backgroundColor: getPriorityColorHex(priority.color) }}
|
||||
/>
|
||||
{priority.label}
|
||||
{priority.label} ({priority.count})
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
@@ -297,7 +316,7 @@ export function KanbanFilters({ filters, onFiltersChange }: KanbanFiltersProps)
|
||||
className="w-2 h-2 rounded-full"
|
||||
style={{ backgroundColor: tag.color }}
|
||||
/>
|
||||
{tag.name}
|
||||
{tag.name} ({tagCounts[tag.name] || 0})
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user