From a50f3bc55b7c2bfd21cb012c7ac7af668d7f048b Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Sat, 15 Mar 2025 00:15:23 +0530 Subject: [PATCH] (fix:sourceDropdown) ask before delete --- frontend/src/components/SourceDropdown.tsx | 42 ++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/SourceDropdown.tsx b/frontend/src/components/SourceDropdown.tsx index a3f1b38d..e274c8f4 100644 --- a/frontend/src/components/SourceDropdown.tsx +++ b/frontend/src/components/SourceDropdown.tsx @@ -1,9 +1,11 @@ -import React from 'react'; +import React, { useState } from 'react'; import Trash from '../assets/trash.svg'; import Arrow2 from '../assets/dropdown-arrow.svg'; -import { Doc } from '../models/misc'; +import { Doc, ActiveState } from '../models/misc'; import { useDispatch } from 'react-redux'; import { useTranslation } from 'react-i18next'; +import ConfirmationModal from '../modals/ConfirmationModal'; + type Props = { options: Doc[] | null; selectedDocs: Doc | null; @@ -30,6 +32,10 @@ function SourceDropdown({ import.meta.env.VITE_EMBEDDINGS_NAME || 'huggingface_sentence-transformers/all-mpnet-base-v2'; + const [deleteModalState, setDeleteModalState] = + useState('INACTIVE'); + const [documentToDelete, setDocumentToDelete] = useState(null); + const handleEmptyDocumentSelect = () => { dispatch(setSelectedDocs(null)); setIsDocsListOpen(false); @@ -50,6 +56,25 @@ function SourceDropdown({ document.removeEventListener('mousedown', handleClickOutside); }; }, []); + + const confirmDelete = (option: Doc) => { + setDocumentToDelete(option); + setDeleteModalState('ACTIVE'); + }; + + const handleConfirmedDelete = () => { + if (documentToDelete) { + handleDeleteClick(documentToDelete); + setDeleteModalState('INACTIVE'); + setDocumentToDelete(null); + } + }; + + const handleCancelDelete = () => { + setDeleteModalState('INACTIVE'); + setDocumentToDelete(null); + }; + return (
)} + ); }