refactor: revew all design of services, clients, deadcode, ...
This commit is contained in:
@@ -16,7 +16,9 @@ export function useTreeView<T>({
|
||||
onSearchChange,
|
||||
}: UseTreeViewOptions<T>) {
|
||||
// État pour les catégories ouvertes/fermées
|
||||
const [expandedCategories, setExpandedCategories] = useState<Set<string>>(new Set());
|
||||
const [expandedCategories, setExpandedCategories] = useState<Set<string>>(
|
||||
new Set()
|
||||
);
|
||||
|
||||
// Grouper les données par catégorie et filtrer en fonction de la recherche
|
||||
const filteredDataByCategory = useMemo(() => {
|
||||
@@ -31,23 +33,26 @@ export function useTreeView<T>({
|
||||
}, {} as Record<string, T[]>);
|
||||
|
||||
// Filtrer les données en fonction de la recherche
|
||||
return Object.entries(dataByCategory).reduce((acc, [category, categoryItems]) => {
|
||||
const filteredItems = categoryItems.filter((item) => {
|
||||
const matchesSearch = searchFields.some((field) => {
|
||||
const value = item[field];
|
||||
if (typeof value === 'string') {
|
||||
return value.toLowerCase().includes(searchTerm.toLowerCase());
|
||||
}
|
||||
return false;
|
||||
return Object.entries(dataByCategory).reduce(
|
||||
(acc, [category, categoryItems]) => {
|
||||
const filteredItems = categoryItems.filter((item) => {
|
||||
const matchesSearch = searchFields.some((field) => {
|
||||
const value = item[field];
|
||||
if (typeof value === "string") {
|
||||
return value.toLowerCase().includes(searchTerm.toLowerCase());
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return matchesSearch;
|
||||
});
|
||||
return matchesSearch;
|
||||
});
|
||||
|
||||
if (filteredItems.length > 0) {
|
||||
acc[category] = filteredItems;
|
||||
}
|
||||
return acc;
|
||||
}, {} as Record<string, T[]>);
|
||||
if (filteredItems.length > 0) {
|
||||
acc[category] = filteredItems;
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, T[]>
|
||||
);
|
||||
}, [data, searchFields, groupBy, searchTerm]);
|
||||
|
||||
// Fonctions pour gérer l'expansion des catégories
|
||||
|
||||
Reference in New Issue
Block a user