feat: remove a skill category empty
This commit is contained in:
@@ -6,6 +6,7 @@ interface UseTreeViewOptions<T> {
|
||||
groupBy: (item: T) => string;
|
||||
searchTerm: string;
|
||||
onSearchChange: (term: string) => void;
|
||||
availableCategories?: string[]; // Nouvelles catégories disponibles
|
||||
}
|
||||
|
||||
export function useTreeView<T>({
|
||||
@@ -14,6 +15,7 @@ export function useTreeView<T>({
|
||||
groupBy,
|
||||
searchTerm,
|
||||
onSearchChange,
|
||||
availableCategories = [],
|
||||
}: UseTreeViewOptions<T>) {
|
||||
// État pour les catégories ouvertes/fermées
|
||||
const [expandedCategories, setExpandedCategories] = useState<Set<string>>(
|
||||
@@ -33,7 +35,7 @@ export function useTreeView<T>({
|
||||
}, {} as Record<string, T[]>);
|
||||
|
||||
// Filtrer les données en fonction de la recherche
|
||||
return Object.entries(dataByCategory).reduce(
|
||||
const filteredCategories = Object.entries(dataByCategory).reduce(
|
||||
(acc, [category, categoryItems]) => {
|
||||
const filteredItems = categoryItems.filter((item) => {
|
||||
const matchesSearch = searchFields.some((field) => {
|
||||
@@ -53,7 +55,16 @@ export function useTreeView<T>({
|
||||
},
|
||||
{} as Record<string, T[]>
|
||||
);
|
||||
}, [data, searchFields, groupBy, searchTerm]);
|
||||
|
||||
// Ajouter les catégories vides qui sont dans availableCategories
|
||||
availableCategories.forEach(category => {
|
||||
if (!filteredCategories[category]) {
|
||||
filteredCategories[category] = [];
|
||||
}
|
||||
});
|
||||
|
||||
return filteredCategories;
|
||||
}, [data, searchFields, groupBy, searchTerm, availableCategories]);
|
||||
|
||||
// Fonctions pour gérer l'expansion des catégories
|
||||
const toggleCategory = useCallback((category: string) => {
|
||||
|
||||
Reference in New Issue
Block a user