From c7f49c7802917a40af5e6ab15d27576a466452b9 Mon Sep 17 00:00:00 2001 From: Antoine Bouchardy Date: Sat, 19 Apr 2025 22:35:04 -0700 Subject: [PATCH] Add category filter on risks Signed-off-by: Antoine Bouchardy Signed-off-by: Bryan Frimin --- .../organizations/risks/ListRiskView.tsx | 58 ++++++++++++++++++- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/apps/console/src/pages/organizations/risks/ListRiskView.tsx b/apps/console/src/pages/organizations/risks/ListRiskView.tsx index c342cbed5..751e04bcb 100644 --- a/apps/console/src/pages/organizations/risks/ListRiskView.tsx +++ b/apps/console/src/pages/organizations/risks/ListRiskView.tsx @@ -43,9 +43,23 @@ import { } from "@/components/ui/popover"; import { Switch } from "@/components/ui/switch"; import { Label } from "@/components/ui/label"; +import { Badge } from "@/components/ui/badge"; const defaultPageSize = 25; +// Define available risk categories +const RISK_CATEGORIES = [ + "Compliance & Legal", + "Cybersecurity", + "Finance", + "Human capital", + "Operations", + "Reputational", + "Strategic", + "Technology", + "Other" +] as const; + const listRiskViewQuery = graphql` query ListRiskViewQuery( $organizationId: ID! @@ -568,6 +582,9 @@ function ListRiskViewContent({ // State for toggling between initial and residual risk matrix const [showResidualRisk, setShowResidualRisk] = useState(false); + // State for category filters + const [selectedCategories, setSelectedCategories] = useState>(new Set()); + // Setup delete mutation const [commitDeleteMutation] = useMutation(deleteRiskMutation); @@ -589,6 +606,27 @@ function ListRiskViewContent({ const pageInfo = risksConnection?.risks?.pageInfo; const connectionId = risksConnection?.risks?.__id; + // Get unique categories from existing risks + const availableCategories = Array.from(new Set(risks.map(risk => risk.category))).sort(); + + // Filter risks based on selected categories + const filteredRisks = selectedCategories.size === 0 + ? risks + : risks.filter(risk => selectedCategories.has(risk.category)); + + // Handle category toggle + const toggleCategory = (category: string) => { + setSelectedCategories(prev => { + const newSet = new Set(prev); + if (newSet.has(category)) { + newSet.delete(category); + } else { + newSet.add(category); + } + return newSet; + }); + }; + // Handle delete risk const handleDeleteRisk = useCallback(() => { if (!riskToDelete || !connectionId) return; @@ -700,7 +738,7 @@ function ListRiskViewContent({ @@ -708,6 +746,20 @@ function ListRiskViewContent({ + {/* Category Filters */} +
+ {availableCategories.map((category) => ( + toggleCategory(category)} + > + {category} + + ))} +
+
@@ -738,7 +790,7 @@ function ListRiskViewContent({ - {risks.length === 0 ? ( + {filteredRisks.length === 0 ? ( ) : ( - risks.map((risk) => ( + filteredRisks.map((risk) => (