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:
Julien Froidefond
2025-08-21 17:12:39 +02:00
parent a4b680b092
commit dc3f030fce
3 changed files with 30 additions and 9 deletions

View File

@@ -35,6 +35,9 @@ export function AdminClientWrapper({
const getFilteredTeamStats = () => { const getFilteredTeamStats = () => {
let filtered = teamStats; let filtered = teamStats;
// Filtrer les équipes avec 0 membres
filtered = filtered.filter((team) => team.totalMembers > 0);
if (selectedDirections.length > 0) { if (selectedDirections.length > 0) {
filtered = filtered.filter((team) => filtered = filtered.filter((team) =>
selectedDirections.includes(team.direction) selectedDirections.includes(team.direction)

View File

@@ -28,18 +28,30 @@ export function AdminFilters({
const hasFilters = selectedDirections.length > 0 || selectedTeams.length > 0; const hasFilters = selectedDirections.length > 0 || selectedTeams.length > 0;
const directionOptions = Array.from( 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) => ({ ).map((direction) => ({
id: direction, id: direction,
label: 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
id: team.id, .filter((team) => {
label: `${team.name} (${team.direction})`, const teamStat = teamStats.find((stat) => stat.teamId === team.id);
count: teamStats.find((stat) => stat.teamId === team.id)?.totalMembers || 0, 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,
}));
const handleReset = () => { const handleReset = () => {
onDirectionsChange([]); onDirectionsChange([]);

View File

@@ -166,10 +166,16 @@ export class AdminService {
* Génère les statistiques par direction à partir des stats d'équipes * Génère les statistiques par direction à partir des stats d'équipes
*/ */
static generateDirectionStats(teamStats: TeamStats[]): DirectionStats[] { 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) => { return directions.map((direction) => {
const directionTeams = teamStats.filter((t) => t.direction === direction); const directionTeams = teamsWithMembers.filter(
(t) => t.direction === direction
);
const totalMembers = directionTeams.reduce( const totalMembers = directionTeams.reduce(
(sum, t) => sum + t.totalMembers, (sum, t) => sum + t.totalMembers,
0 0