feat: filter teams with zero members in admin components
- Updated `AdminClientWrapper` to filter out teams with zero members in `getFilteredTeamStats`. - Modified `AdminFilters` to only include directions and teams with members in the options. - Enhanced `AdminService` to generate direction stats based on teams with members, improving data accuracy.
This commit is contained in:
@@ -35,6 +35,9 @@ export function AdminClientWrapper({
|
||||
const getFilteredTeamStats = () => {
|
||||
let filtered = teamStats;
|
||||
|
||||
// Filtrer les équipes avec 0 membres
|
||||
filtered = filtered.filter((team) => team.totalMembers > 0);
|
||||
|
||||
if (selectedDirections.length > 0) {
|
||||
filtered = filtered.filter((team) =>
|
||||
selectedDirections.includes(team.direction)
|
||||
|
||||
@@ -28,17 +28,29 @@ export function AdminFilters({
|
||||
const hasFilters = selectedDirections.length > 0 || selectedTeams.length > 0;
|
||||
|
||||
const directionOptions = Array.from(
|
||||
new Set(teams.map((team) => team.direction))
|
||||
new Set(
|
||||
teamStats
|
||||
.filter((team) => team.totalMembers > 0)
|
||||
.map((team) => team.direction)
|
||||
)
|
||||
).map((direction) => ({
|
||||
id: direction,
|
||||
label: direction,
|
||||
count: teams.filter((team) => team.direction === direction).length,
|
||||
count: teamStats.filter(
|
||||
(team) => team.direction === direction && team.totalMembers > 0
|
||||
).length,
|
||||
}));
|
||||
|
||||
const teamOptions = teams.map((team) => ({
|
||||
const teamOptions = teams
|
||||
.filter((team) => {
|
||||
const teamStat = teamStats.find((stat) => stat.teamId === team.id);
|
||||
return teamStat && teamStat.totalMembers > 0;
|
||||
})
|
||||
.map((team) => ({
|
||||
id: team.id,
|
||||
label: `${team.name} (${team.direction})`,
|
||||
count: teamStats.find((stat) => stat.teamId === team.id)?.totalMembers || 0,
|
||||
count:
|
||||
teamStats.find((stat) => stat.teamId === team.id)?.totalMembers || 0,
|
||||
}));
|
||||
|
||||
const handleReset = () => {
|
||||
|
||||
@@ -166,10 +166,16 @@ export class AdminService {
|
||||
* Génère les statistiques par direction à partir des stats d'équipes
|
||||
*/
|
||||
static generateDirectionStats(teamStats: TeamStats[]): DirectionStats[] {
|
||||
const directions = Array.from(new Set(teamStats.map((t) => t.direction)));
|
||||
// Filtrer d'abord les équipes avec 0 membres
|
||||
const teamsWithMembers = teamStats.filter((t) => t.totalMembers > 0);
|
||||
const directions = Array.from(
|
||||
new Set(teamsWithMembers.map((t) => t.direction))
|
||||
);
|
||||
|
||||
return directions.map((direction) => {
|
||||
const directionTeams = teamStats.filter((t) => t.direction === direction);
|
||||
const directionTeams = teamsWithMembers.filter(
|
||||
(t) => t.direction === direction
|
||||
);
|
||||
const totalMembers = directionTeams.reduce(
|
||||
(sum, t) => sum + t.totalMembers,
|
||||
0
|
||||
|
||||
Reference in New Issue
Block a user