From 31f5508273f9ec95fa5f95fc3f6ee54b1aea6ec9 Mon Sep 17 00:00:00 2001 From: Musale Martin Date: Wed, 27 Nov 2024 17:14:29 +0300 Subject: [PATCH] feat: add confirmation dialog for deleting history groups in HistoryV9 component --- src/app/views/sidebar/history/HistoryV9.tsx | 75 ++++++++++++++++----- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/src/app/views/sidebar/history/HistoryV9.tsx b/src/app/views/sidebar/history/HistoryV9.tsx index 55e37b1b2..f00f403a2 100644 --- a/src/app/views/sidebar/history/HistoryV9.tsx +++ b/src/app/views/sidebar/history/HistoryV9.tsx @@ -2,6 +2,13 @@ import { AriaLiveAnnouncer, Badge, Button, + Dialog, + DialogActions, + DialogBody, + DialogContent, + DialogSurface, + DialogTitle, + DialogTrigger, Divider, FlatTree, FlatTreeItem, @@ -23,10 +30,12 @@ import { IGroup } from '@fluentui/react/lib/DetailsList'; import { ArrowDownloadRegular, DeleteRegular } from '@fluentui/react-icons'; import React, { useEffect, useRef, useState } from 'react'; -import { useAppSelector } from '../../../../store'; +import { historyCache } from '../../../../modules/cache/history-utils'; +import { useAppDispatch, useAppSelector } from '../../../../store'; import { SortOrder } from '../../../../types/enums'; import { Entry } from '../../../../types/har'; import { IHistoryItem } from '../../../../types/history'; +import { removeAllHistoryItems } from '../../../services/slices/history.slice'; import { dynamicSort } from '../../../utils/dynamic-sort'; import { generateGroupsFromList } from '../../../utils/generate-groups'; import { translateMessage } from '../../../utils/translate-messages'; @@ -59,19 +68,13 @@ const useStyles = makeStyles({ }, titleAside: { display: 'flex', - gap: '4px' + gap: '2px' } }) - -const handleDeleteHistoryGroup = (event: React.MouseEvent)=>{ - event.preventDefault() - console.log('deleting history') -} - const handleDownloadHistoryGroup = ( event: React.MouseEvent, value: string, - historyItems: IHistoryItem[], category: string)=>{ + historyItems: IHistoryItem[])=>{ event.preventDefault() const itemsToExport = historyItems.filter((query: IHistoryItem) => getCategory(query) === value); const entries: Entry[] = []; @@ -83,7 +86,7 @@ const handleDownloadHistoryGroup = ( const generatedHarData = generateHar(entries); const { origin } = new URL(itemsToExport[0].url); - const exportTitle = `${origin}/${category.toLowerCase()}/${itemsToExport[0].createdAt.slice(0, 10)}/`; + const exportTitle = `${origin}/${value.toLowerCase()}/${itemsToExport[0].createdAt.slice(0, 10)}/`; exportQuery(generatedHarData, exportTitle); } @@ -91,22 +94,58 @@ const handleDownloadHistoryGroup = ( interface AsideGroupIconsProps { groupName: string historyItems: IHistoryItem[] - category: string } const AsideGroupIcons = (props: AsideGroupIconsProps)=>{ - const {groupName, historyItems, category} = props + const dispatch = useAppDispatch() + const {groupName, historyItems} = props + const [open, setOpen] = useState(false); const styles = useStyles() + + const handleDeleteHistoryGroup = (event: React.MouseEvent)=>{ + event.preventDefault() + const itemsToDelete = historyItems.filter((query: IHistoryItem) => getCategory(query) === groupName); + const listOfKeys: string[] = []; + itemsToDelete.forEach(historyItem => { + listOfKeys.push(historyItem.createdAt); + }); + historyCache.bulkRemoveHistoryData(listOfKeys) + dispatch(removeAllHistoryItems(listOfKeys)); + setOpen(false) + } + return
- - - + setOpen(data.open)}> + + + + + + + + {translateMessage('Delete requests')} "{groupName}" + {translateMessage('Are you sure you want to delete these requests?')} + + + + + + + + + + +
} @@ -144,7 +183,7 @@ const History = (props: HistoryProps)=>{ aria-setsize={2} aria-posinset={pos+1} aria-label={ariaLabel}> - }> + }> {name}{' '} {count}