From e7bd9b63236a4bbdbc9ab9c297c96e4bbad386de Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 20 Mar 2023 14:19:12 +0000 Subject: [PATCH 1/2] Update Navigation.tsx --- frontend/src/Navigation.tsx | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index b2b63281..053b9482 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react'; import { NavLink } from 'react-router-dom'; import Arrow1 from './assets/arrow.svg'; import Arrow2 from './assets/dropdown-arrow.svg'; +import Exit from './assets/exit.svg'; import Message from './assets/message.svg'; import Hamburger from './assets/hamburger.svg'; import Key from './assets/key.svg'; @@ -21,6 +22,7 @@ import { } from './preferences/preferenceSlice'; import { useOutsideAlerter } from './hooks'; import Upload from './upload/Upload'; +import { Doc } from './preferences/preferenceApi'; export default function Navigation({ navState, @@ -48,6 +50,23 @@ export default function Navigation({ useState('INACTIVE'); const navRef = useRef(null); + const apiHost = import.meta.env.VITE_API_HOST || 'https://docsapi.arc53.com'; + + const handleDeleteClick = (index: number, doc: Doc) => { + const docPath = 'indexes/' + 'local' + '/' + doc.name; + + fetch(`${apiHost}/api/delete_old?path=${docPath}`, { + method: 'GET', + }) + .then(() => { + // remove the image element from the DOM + const imageElement = document.querySelector( + `#img-${index}`, + ) as HTMLElement; + imageElement.parentNode?.removeChild(imageElement); + }) + .catch((error) => console.error(error)); + }; useOutsideAlerter( navRef, () => { @@ -149,11 +168,18 @@ export default function Navigation({ dispatch(setSelectedDocs(doc)); setIsDocsListOpen(false); }} - className="h-10 w-full cursor-pointer border-x-2 border-b-2 hover:bg-gray-100" + className="flex h-10 w-full cursor-pointer items-center justify-between border-x-2 border-b-2 hover:bg-gray-100" > -

+

{doc.name} {doc.version}

+ Exit handleDeleteClick(index, doc)} + /> ); } From 3e98f9e6bd16762f31813aeca021ce5e85de1a7d Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 20 Mar 2023 14:34:51 +0000 Subject: [PATCH 2/2] Button working now --- application/app.py | 5 ++++- frontend/src/Navigation.tsx | 23 +++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/application/app.py b/application/app.py index 164db166..dfce4970 100644 --- a/application/app.py +++ b/application/app.py @@ -410,8 +410,11 @@ def delete_old(): if dirs[0] not in ['indexes', 'vectors']: return {"status": 'error'} path_clean = '/'.join(dirs) - shutil.rmtree(path) vectors_collection.delete_one({'location': path}) + try: + shutil.rmtree(path_clean) + except FileNotFoundError: + pass return {"status": 'ok'} # handling CORS diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index 053b9482..f4b9eb96 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -63,7 +63,8 @@ export default function Navigation({ const imageElement = document.querySelector( `#img-${index}`, ) as HTMLElement; - imageElement.parentNode?.removeChild(imageElement); + const parentElement = imageElement.parentNode as HTMLElement; + parentElement.parentNode?.removeChild(parentElement); }) .catch((error) => console.error(error)); }; @@ -173,13 +174,18 @@ export default function Navigation({

{doc.name} {doc.version}

- Exit handleDeleteClick(index, doc)} - /> + {doc.location === 'local' ? ( + Exit { + event.stopPropagation(); + handleDeleteClick(index, doc); + }} + /> + ) : null} ); } @@ -189,6 +195,7 @@ export default function Navigation({

No default documentation.

)} + ) )}