From e848e85b6369e88d5f97689c59d3fa204825e6e8 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Wed, 28 Jan 2026 13:54:10 +0100 Subject: [PATCH] feat: implement period filtering in OKRsList component with toggle for viewing all OKRs or current quarter's OKRs --- src/components/okrs/OKRsList.tsx | 73 +++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/src/components/okrs/OKRsList.tsx b/src/components/okrs/OKRsList.tsx index 6a91579..5f4bca9 100644 --- a/src/components/okrs/OKRsList.tsx +++ b/src/components/okrs/OKRsList.tsx @@ -1,9 +1,10 @@ 'use client'; -import { useState, useEffect } from 'react'; +import { useState, useEffect, useMemo } from 'react'; import { OKRCard } from './OKRCard'; -import { Card, ToggleGroup } from '@/components/ui'; +import { Card, ToggleGroup, Button } from '@/components/ui'; import { getGravatarUrl } from '@/lib/gravatar'; +import { getCurrentQuarterPeriod, isCurrentQuarterPeriod } from '@/lib/okr-utils'; import type { OKR } from '@/lib/types'; type ViewMode = 'grid' | 'grouped'; @@ -33,6 +34,7 @@ export function OKRsList({ okrsData, teamId, isAdmin = false }: OKRsListProps) { } return 'detailed'; }); + const [showAllPeriods, setShowAllPeriods] = useState(false); useEffect(() => { if (typeof window !== 'undefined') { @@ -40,8 +42,21 @@ export function OKRsList({ okrsData, teamId, isAdmin = false }: OKRsListProps) { } }, [cardViewMode]); + const currentQuarterPeriod = getCurrentQuarterPeriod(); + + // Filter OKRs based on period filter + const filteredOKRsData = useMemo(() => { + if (showAllPeriods) { + return okrsData; + } + return okrsData.map((tm) => ({ + ...tm, + okrs: tm.okrs.filter((okr) => isCurrentQuarterPeriod(okr.period)), + })); + }, [okrsData, showAllPeriods]); + // Flatten OKRs for grid view - const allOKRs = okrsData.flatMap((tm) => + const allOKRs = filteredOKRsData.flatMap((tm) => tm.okrs.map((okr) => ({ ...okr, teamMember: { @@ -52,11 +67,37 @@ export function OKRsList({ okrsData, teamId, isAdmin = false }: OKRsListProps) { if (allOKRs.length === 0) { return ( - -
🎯
-

Aucun OKR défini

-

Aucun OKR n'a encore été défini pour cette équipe

-
+
+ {/* View Toggle */} +
+
+

OKRs

+ {!showAllPeriods && ( + ({currentQuarterPeriod}) + )} +
+
+ +
+
+ +
🎯
+

+ {showAllPeriods ? 'Aucun OKR défini' : `Aucun OKR pour ${currentQuarterPeriod}`} +

+

+ {showAllPeriods + ? "Aucun OKR n'a encore été défini pour cette équipe" + : `Aucun OKR n'a été défini pour le trimestre ${currentQuarterPeriod}. Cliquez sur "Afficher tous les OKR" pour voir les OKR d'autres périodes.`} +

+
+
); } @@ -64,8 +105,20 @@ export function OKRsList({ okrsData, teamId, isAdmin = false }: OKRsListProps) {
{/* View Toggle */}
-

OKRs

+

OKRs

+ {!showAllPeriods && ( + ({currentQuarterPeriod}) + )} +
+
+ - {okrsData + {filteredOKRsData .filter((tm) => tm.okrs.length > 0) .map((teamMember) => (