diff --git a/deepfence_frontend/apps/dashboard/src/features/settings/pages/ScanHistoryAndDbManagement.tsx b/deepfence_frontend/apps/dashboard/src/features/settings/pages/ScanHistoryAndDbManagement.tsx index b5c2828da9..1ac37f0291 100644 --- a/deepfence_frontend/apps/dashboard/src/features/settings/pages/ScanHistoryAndDbManagement.tsx +++ b/deepfence_frontend/apps/dashboard/src/features/settings/pages/ScanHistoryAndDbManagement.tsx @@ -1,16 +1,8 @@ import { useSuspenseQuery } from '@suspensive/react-query'; import { upperFirst } from 'lodash-es'; -import { Suspense, useEffect, useState } from 'react'; +import { Suspense, useEffect, useMemo, useState } from 'react'; import { ActionFunctionArgs, useFetcher } from 'react-router-dom'; -import { - Button, - FileInput, - Listbox, - ListboxOption, - Modal, - Radio, - Separator, -} from 'ui-components'; +import { Button, FileInput, Modal, Radio, Separator, TextInput } from 'ui-components'; import { getScanResultsApiClient, getSettingsApiClient } from '@/api/api'; import { ModelBulkDeleteScansRequestScanTypeEnum as ModelBulkDeleteScansRequestScanTypeEnumType } from '@/api/generated'; @@ -34,15 +26,7 @@ import { invalidateAllQueries } from '@/queries'; import { get403Message } from '@/utils/403'; import { apiWrapper } from '@/utils/api'; -const DURATION: { [k: string]: number } = { - 'Last 1 Day': 86400000, - 'Last 7 Days': 604800000, - 'Last 30 Days': 2592000000, - 'Last 60 Days': 5184000000, - 'Last 90 Days': 7776000000, - 'Last 180 Days': 15552000000, - All: 0, -}; +const millisecondsOf1Day = 86400000; const files: { [filename: string]: File } = {}; @@ -64,6 +48,7 @@ const action = async ({ request }: ActionFunctionArgs): Promise>; @@ -181,6 +167,7 @@ const DeleteConfirmationModal = ({ duration: number; selectedResource: string; }; + scanPeriodOption: 'older' | 'last' | 'all'; }) => { const fetcher = useFetcher<{ deleteSuccess: boolean; @@ -220,6 +207,7 @@ const DeleteConfirmationModal = ({ const formData = new FormData(); formData.append('actionType', ActionEnumType.DELETE); formData.append('selectedResource', data.selectedResource); + formData.append('scanPeriodOption', scanPeriodOption); formData.append('duration', data.duration.toString()); fetcher.submit(formData, { method: 'post', @@ -674,10 +662,17 @@ const resources: { const ScanHistoryAndDbManagement = () => { const [, setSeverityOrResources] = useState('severity'); + const [scanPeriodOption, setScanPeriodOption] = useState<'older' | 'last' | 'all'>( + 'older', + ); const [selectedResource, setSelectedResource] = useState( ModelBulkDeleteScansRequestScanTypeEnumType.Vulnerability, ); - const [duration, setDuration] = useState(DURATION['Last 1 Day']); + const [duration, setDuration] = useState({ + lastDuration: 1, + olderDuration: 1, + allDuration: 0, + }); const [showDeleteDialog, setShowDeleteDialog] = useState(false); @@ -687,6 +682,15 @@ const ScanHistoryAndDbManagement = () => { } }, [selectedResource]); + const selectedDuration = useMemo(() => { + if (scanPeriodOption === 'older') { + return duration.olderDuration; + } else if (scanPeriodOption === 'last') { + return duration.lastDuration; + } + return duration.allDuration; + }, [duration, scanPeriodOption]); + return ( <> {showDeleteDialog && ( @@ -694,13 +698,14 @@ const ScanHistoryAndDbManagement = () => { showDialog={showDeleteDialog} setShowDialog={setShowDeleteDialog} data={{ - duration, + duration: selectedDuration, selectedResource, }} + scanPeriodOption={scanPeriodOption} /> )}
-

Scan History

+

Delete Scan History

@@ -720,36 +725,112 @@ const ScanHistoryAndDbManagement = () => { }} /> -

- { - setDuration(value); - }} - getDisplayValue={(item) => { - for (const [key, value] of Object.entries(DURATION)) { - if (value == item) { - return key; - } - } - return 'Last 1 Day'; - }} - > - {Object.keys(DURATION).map((key) => { - return ( - - {key} - - ); - })} - +
+
+

Scan Period

+
+
+ { + setScanPeriodOption('older'); + setDuration({ + lastDuration: 1, + olderDuration: 1, + allDuration: 0, + }); + }} + /> + Older than +
+ { + setDuration({ + lastDuration: 1, + olderDuration: parseInt(e.target.value.trim(), 10), + allDuration: 0, + }); + }} + /> +
+ days +
+
+ { + setScanPeriodOption('last'); + setDuration({ + lastDuration: 1, + olderDuration: 1, + allDuration: 0, + }); + }} + /> + Last +
+ { + setDuration({ + lastDuration: parseInt(e.target.value.trim(), 10), + olderDuration: 1, + allDuration: 0, + }); + }} + /> +
+ days +
+
+ { + setScanPeriodOption('all'); + setDuration({ + lastDuration: 1, + olderDuration: 1, + allDuration: 0, + }); + }} + /> + All +
+