From 6ff8d08fefc6dd9467c461ef3ce43af4ffd7e456 Mon Sep 17 00:00:00 2001 From: milan-deepfence Date: Fri, 24 Nov 2023 14:27:35 +0530 Subject: [PATCH] fix(2019): correctd advanced filters compliance for integration --- .../components/IntegrationForm.tsx | 281 ++++++++++++------ .../integrations/pages/IntegrationAdd.tsx | 16 + 2 files changed, 208 insertions(+), 89 deletions(-) diff --git a/deepfence_frontend/apps/dashboard/src/features/integrations/components/IntegrationForm.tsx b/deepfence_frontend/apps/dashboard/src/features/integrations/components/IntegrationForm.tsx index 66831d1e7a..94752e58fd 100644 --- a/deepfence_frontend/apps/dashboard/src/features/integrations/components/IntegrationForm.tsx +++ b/deepfence_frontend/apps/dashboard/src/features/integrations/components/IntegrationForm.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { useFetcher, useParams } from 'react-router-dom'; import { Button, @@ -114,6 +114,14 @@ const isJiraIntegration = (integrationType: string) => { return integrationType && integrationType === IntegrationType.jira; }; +const isCloudComplianceNotification = (notificationType: string) => { + return notificationType && notificationType === 'Cloud Compliance'; +}; + +const isComplianceNotification = (notificationType: string) => { + return notificationType && notificationType === 'Compliance'; +}; + const API_SCAN_TYPE_MAP: { [key: string]: ScanTypeEnum; } = { @@ -124,7 +132,13 @@ const API_SCAN_TYPE_MAP: { }; const scanTypes = ['Secret', 'Vulnerability', 'Malware']; -const AdvancedFilters = ({ notificationType }: { notificationType: string }) => { +const AdvancedFilters = ({ + notificationType, + cloudProvider, +}: { + notificationType: string; + cloudProvider?: string; +}) => { // severity const [selectedSeverity, setSelectedSeverity] = useState([]); @@ -137,65 +151,98 @@ const AdvancedFilters = ({ notificationType }: { notificationType: string }) => const [containers, setContainers] = useState([]); const [clusters, setClusters] = useState([]); + const [selectedCloudAccounts, setSelectedCloudAccounts] = useState([]); + + useEffect(() => { + setSelectedSeverity([]); + setSelectedStatus([]); + setHosts([]); + setImages([]); + setContainers([]); + setClusters([]); + setSelectedCloudAccounts([]); + }, [notificationType, cloudProvider]); + return (
Advanced Filter (Optional)
- { - setHosts(value); - }} - onClearAll={() => { - setHosts([]); - }} - agentRunning={false} - active={false} - /> - - { - setContainers(value); - }} - onClearAll={() => { - setContainers([]); - }} - active={false} - /> - - { - setImages(value); - }} - onClearAll={() => { - setImages([]); - }} - /> - - { - setClusters(value); - }} - onClearAll={() => { - setClusters([]); - }} - agentRunning={false} - active={false} - /> + {isCloudComplianceNotification(notificationType) && cloudProvider ? ( + { + setSelectedCloudAccounts([]); + }} + onChange={(value) => { + setSelectedCloudAccounts(value); + }} + /> + ) : ( + { + setHosts(value); + }} + onClearAll={() => { + setHosts([]); + }} + agentRunning={false} + active={false} + /> + )} + {!isComplianceNotification(notificationType) && + !isCloudComplianceNotification(notificationType) && ( + { + setContainers(value); + }} + onClearAll={() => { + setContainers([]); + }} + active={false} + /> + )} + {!isComplianceNotification(notificationType) && + !isCloudComplianceNotification(notificationType) && ( + { + setImages(value); + }} + onClearAll={() => { + setImages([]); + }} + /> + )} + {!isCloudComplianceNotification(notificationType) && ( + { + setClusters(value); + }} + onClearAll={() => { + setClusters([]); + }} + agentRunning={false} + active={false} + /> + )} - {notificationType === 'Compliance' || notificationType === 'CloudCompliance' ? ( + {isComplianceNotification(notificationType) || + isCloudComplianceNotification(notificationType) ? ( <> readOnly value={selectedStatus.length} /> - { - setSelectedStatus(value); - }} - placeholder="Select status" - label="Select status" - multiple - clearAll="Clear" - onClearAll={() => setSelectedStatus([])} - getDisplayValue={(value) => { - return value && value.length ? `${value.length} selected` : ''; - }} - > -
- Host -
- Alarm - Note - Ok -
- Cloud / Kubernetes -
- Pass - Skip - Warn -
- Common -
- Info -
+ {isComplianceNotification(notificationType) && ( + { + setSelectedStatus(value); + }} + placeholder="Select status" + label="Select status" + multiple + clearAll="Clear" + onClearAll={() => setSelectedStatus([])} + getDisplayValue={(value) => { + return value && value.length ? `${value.length} selected` : ''; + }} + > +
+ Host +
+ Alarm + Note + Ok +
+ Kubernetes +
+ Pass + Skip + Warn +
+ Common +
+ Info +
+ )} + {isCloudComplianceNotification(notificationType) && ( + { + setSelectedStatus(value); + }} + placeholder="Select status" + label="Select status" + multiple + clearAll="Clear" + onClearAll={() => setSelectedStatus([])} + getDisplayValue={(value) => { + return value && value.length ? `${value.length} selected` : ''; + }} + > + Pass + Skip + Warn + Info + + )} ) : null} @@ -277,10 +349,17 @@ const AdvancedFilters = ({ notificationType }: { notificationType: string }) => ); }; -const notificationTypeList = ['Vulnerability', 'Secret', 'Malware', 'Compliance']; +const notificationTypeList = [ + 'Vulnerability', + 'Secret', + 'Malware', + 'Compliance', + 'Cloud Compliance', +]; const NotificationType = ({ fieldErrors }: { fieldErrors?: Record }) => { const [notificationType, setNotificationType] = useState(''); + const [cloud, setCloud] = useState('AWS'); const { integrationType } = useParams() as { integrationType: string; @@ -328,6 +407,30 @@ const NotificationType = ({ fieldErrors }: { fieldErrors?: Record + {isCloudComplianceNotification(notificationType) && ( + { + setCloud(value); + }} + placeholder="Select provider" + getDisplayValue={() => { + return cloud; + }} + > + {['AWS', 'GCP', 'AZURE'].map((cloud) => { + return ( + + {cloud} + + ); + })} + + )} + {isCloudTrailNotification(notificationType) && <>Add Cloud trails here} {isUserActivityNotification(notificationType) && ( @@ -344,7 +447,7 @@ const NotificationType = ({ fieldErrors }: { fieldErrors?: Record + ) : null} {notificationType && isVulnerabilityNotification(notificationType) && diff --git a/deepfence_frontend/apps/dashboard/src/features/integrations/pages/IntegrationAdd.tsx b/deepfence_frontend/apps/dashboard/src/features/integrations/pages/IntegrationAdd.tsx index b3fc96d941..dd2a5b86e6 100644 --- a/deepfence_frontend/apps/dashboard/src/features/integrations/pages/IntegrationAdd.tsx +++ b/deepfence_frontend/apps/dashboard/src/features/integrations/pages/IntegrationAdd.tsx @@ -194,6 +194,8 @@ const action = async ({ request, params }: ActionFunctionArgs): Promise( + (id) => { + return { + node_id: id, + node_type: ModelNodeIdentifierNodeTypeEnum.CloudAccount, + }; + }, + ); + nodeIds.push(..._accounts); + } if (severityFilter.length) { const filters = _filters.fields_filters.contains_filter.filter_in; const newFilter = { @@ -327,6 +342,7 @@ const action = async ({ request, params }: ActionFunctionArgs): Promise