Skip to content

Commit d9a38fa

Browse files
Orphan entities deletion (#493)
* added orphan delete dialog * added the API services for getting and deleting the orphan nodes * Delete dialog for orphan nodes * Integrated the UI for Orphan node * added the tooltip * checked state fix and aligned the select all with the checkbox of a particular file * added the delete menu * made the origins configurable * format fixes
1 parent fb515ee commit d9a38fa

File tree

17 files changed

+393
-30
lines changed

17 files changed

+393
-30
lines changed

frontend/src/components/Content.tsx

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState, useMemo } from 'react';
1+
import { useEffect, useState, useMemo, useCallback } from 'react';
22
import ConnectionModal from './Popups/ConnectionModal/ConnectionModal';
33
import LlmDropdown from './Dropdown';
44
import FileTable from './FileTable';
@@ -7,10 +7,9 @@ import { useCredentials } from '../context/UserCredentials';
77
import { useFileContext } from '../context/UsersFiles';
88
import CustomAlert from './UI/Alert';
99
import { extractAPI } from '../utils/FileAPI';
10-
import { ContentProps, CustomFile, OptionType, UserCredentials, alertStateType } from '../types';
10+
import { ContentProps, CustomFile, Menuitems, OptionType, UserCredentials, alertStateType } from '../types';
11+
import deleteAPI from '../services/DeleteFiles';
1112
import { postProcessing } from '../services/PostProcessing';
12-
import GraphViewModal from '../components/Graph/GraphViewModal';
13-
import deleteAPI from '../services/deleteFiles';
1413
import DeletePopUp from './Popups/DeletePopUp/DeletePopUp';
1514
import { triggerStatusUpdateAPI } from '../services/ServerSideStatusUpdateAPI';
1615
import useServerSideEvent from '../hooks/useSse';
@@ -20,13 +19,17 @@ import { buttonCaptions, largeFileSize, taskParam, tooltips } from '../utils/Con
2019
import ButtonWithToolTip from './UI/ButtonWithToolTip';
2120
import connectAPI from '../services/ConnectAPI';
2221
import SettingModalHOC from '../HOC/SettingModalHOC';
22+
import GraphViewModal from './Graph/GraphViewModal';
23+
import CustomMenu from './UI/Menu';
24+
import { TrashIconOutline } from '@neo4j-ndl/react/icons';
2325

2426
const Content: React.FC<ContentProps> = ({
2527
isLeftExpanded,
2628
isRightExpanded,
2729
openTextSchema,
2830
isSchema,
2931
setIsSchema,
32+
openOrphanNodeDeletionModal,
3033
}) => {
3134
const [init, setInit] = useState<boolean>(false);
3235
const [openConnection, setOpenConnection] = useState<boolean>(false);
@@ -38,6 +41,8 @@ const Content: React.FC<ContentProps> = ({
3841
const [extractLoading, setextractLoading] = useState<boolean>(false);
3942
const [isLargeFile, setIsLargeFile] = useState<boolean>(false);
4043
const [showSettingnModal, setshowSettingModal] = useState<boolean>(false);
44+
const [openDeleteMenu, setopenDeleteMenu] = useState<boolean>(false);
45+
const [deleteAnchor, setdeleteAnchor] = useState<HTMLElement | null>(null);
4146

4247
const {
4348
filesData,
@@ -480,6 +485,22 @@ const Content: React.FC<ContentProps> = ({
480485
}
481486
};
482487

488+
const deleteMenuItems: Menuitems[] = useMemo(
489+
() => [
490+
{
491+
title: `Delete Files ${selectedfileslength > 0 ? `(${selectedfileslength})` : ''}`,
492+
onClick: () => setshowDeletePopUp(true),
493+
disabledCondition: !selectedfileslength,
494+
},
495+
{
496+
title: 'Delete Orphan Nodes',
497+
onClick: () => openOrphanNodeDeletionModal(),
498+
disabledCondition: false,
499+
},
500+
],
501+
[selectedfileslength]
502+
);
503+
483504
const handleContinue = () => {
484505
if (!isLargeFile) {
485506
handleGenerateGraph(true, filesData);
@@ -624,19 +645,26 @@ const Content: React.FC<ContentProps> = ({
624645
>
625646
{buttonCaptions.exploreGraphWithBloom}
626647
</ButtonWithToolTip>
627-
<ButtonWithToolTip
628-
text={
629-
!selectedfileslength ? tooltips.deleteFile : `${selectedfileslength} ${tooltips.deleteSelectedFiles}`
630-
}
631-
placement='top'
632-
onClick={() => setshowDeletePopUp(true)}
633-
disabled={!selectedfileslength}
634-
className='ml-0.5'
635-
label='Delete Files'
648+
<CustomMenu
649+
open={openDeleteMenu}
650+
closeHandler={useCallback(() => {
651+
setopenDeleteMenu(false);
652+
}, [])}
653+
items={deleteMenuItems}
654+
MenuAnchor={deleteAnchor}
655+
anchorOrigin={useMemo(() => ({ horizontal: 'left', vertical: 'bottom' }), [])}
656+
transformOrigin={useMemo(() => ({ horizontal: 'right', vertical: 'top' }), [])}
657+
></CustomMenu>
658+
<Button
659+
label='Delete Menu trigger'
660+
onClick={(e) => {
661+
setdeleteAnchor(e.currentTarget);
662+
setopenDeleteMenu(true);
663+
}}
636664
>
637-
{buttonCaptions.deleteFiles}
638-
{selectedfileslength > 0 && `(${selectedfileslength})`}
639-
</ButtonWithToolTip>
665+
<TrashIconOutline className='n-size-token-7' />
666+
Delete <TrashIconOutline></TrashIconOutline>
667+
</Button>
640668
</Flex>
641669
</Flex>
642670
</div>

frontend/src/components/DataSources/Local/DropZone.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ const DropZone: FunctionComponent = () => {
221221
)}
222222

223223
<Dropzone
224-
loadingComponent={isLoading && <Loader />}
224+
loadingComponent={isLoading && <Loader title='Uploading' />}
225225
isTesting={true}
226226
className='!bg-none dropzoneContainer'
227227
supportedFilesDescription={

frontend/src/components/FileTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ const FileTable: React.FC<FileTableProps> = ({ isExpanded, connectionStatus, set
392392
userCredentials &&
393393
userCredentials.database
394394
) {
395-
if (item?.fileSize > largeFileSize) {
395+
if (item?.fileSize < largeFileSize) {
396396
subscribe(
397397
item.fileName,
398398
userCredentials?.uri,

frontend/src/components/Graph/GraphViewModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { InteractiveNvlWrapper } from '@neo4j-nvl/react';
55
import NVL, { NvlOptions } from '@neo4j-nvl/base';
66
import type { Node, Relationship } from '@neo4j-nvl/base';
77
import { Resizable } from 're-resizable';
8-
98
import {
109
DragIcon,
1110
FitToScreenIcon,
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import { useMemo } from 'react';
22
import { LegendChipProps } from '../../types';
3+
import Legend from '../UI/Legend';
34

45
export const LegendsChip: React.FunctionComponent<LegendChipProps> = ({ scheme, title, nodes }) => {
56
const chunkcount = useMemo(
67
// @ts-ignore
78
() => [...new Set(nodes?.filter((n) => n?.labels?.includes(title)).map((i) => i.id))].length,
89
[]
910
);
10-
return (
11-
<div className='legend' key={scheme.key} style={{ backgroundColor: `${scheme[title]}` }}>
12-
{title}
13-
{chunkcount && `(${chunkcount})`}
14-
</div>
15-
);
11+
return <Legend title={title} chunkCount={chunkcount} bgColor={scheme[title]}></Legend>;
1612
};

frontend/src/components/Layout/PageLayout.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@ import { OverridableStringUnion } from '@mui/types';
1313
import { useFileContext } from '../../context/UsersFiles';
1414
import SchemaFromTextDialog from '../Popups/Settings/SchemaFromText';
1515
import CustomAlert from '../UI/Alert';
16+
import DeletePopUpForOrphanNodes from '../Popups/DeletePopUpForOrphanNodes';
17+
import deleteOrphanAPI from '../../services/DeleteOrphanNodes';
1618

1719
export default function PageLayoutNew({
1820
isSettingPanelExpanded,
1921
closeSettingModal,
2022
openSettingsDialog,
23+
closeOrphanNodeDeletionModal,
24+
showOrphanNodeDeletionModal,
25+
openOrphanNodeDeletionModal,
2126
}: {
2227
isSettingPanelExpanded: boolean;
2328
closeSettingModal: () => void;
2429
openSettingsDialog: () => void;
30+
closeOrphanNodeDeletionModal: () => void;
31+
showOrphanNodeDeletionModal: boolean;
32+
openOrphanNodeDeletionModal: () => void;
2533
}) {
2634
const [isLeftExpanded, setIsLeftExpanded] = useState<boolean>(true);
2735
const [isRightExpanded, setIsRightExpanded] = useState<boolean>(true);
@@ -32,6 +40,7 @@ export default function PageLayoutNew({
3240
const toggleLeftDrawer = () => setIsLeftExpanded(!isLeftExpanded);
3341
const toggleRightDrawer = () => setIsRightExpanded(!isRightExpanded);
3442
const [openTextSchemaDialog, setOpenTextSchemaDialog] = useState<boolean>(false);
43+
const [orphanDeleteAPIloading, setorphanDeleteAPIloading] = useState<boolean>(false);
3544
const [alertDetails, setalertDetails] = useState<alertStateType>({
3645
showAlert: false,
3746
alertType: 'error',
@@ -75,6 +84,16 @@ export default function PageLayoutNew({
7584
alertMessage: '',
7685
});
7786
};
87+
const orphanNodesDeleteHandler = async (selectedEntities: string[]) => {
88+
try {
89+
setorphanDeleteAPIloading(true);
90+
const response = await deleteOrphanAPI(userCredentials as UserCredentials, selectedEntities);
91+
setorphanDeleteAPIloading(false);
92+
console.log(response);
93+
} catch (error) {
94+
console.log(error);
95+
}
96+
};
7897
return (
7998
<div style={{ maxHeight: 'calc(100vh - 58px)' }} className='flex overflow-hidden'>
8099
{alertDetails.showAlert && (
@@ -93,6 +112,12 @@ export default function PageLayoutNew({
93112
onClose={closeSchemaFromTextDialog}
94113
showAlert={showAlert}
95114
></SchemaFromTextDialog>
115+
<DeletePopUpForOrphanNodes
116+
open={showOrphanNodeDeletionModal}
117+
deleteCloseHandler={closeOrphanNodeDeletionModal}
118+
deleteHandler={orphanNodesDeleteHandler}
119+
loading={orphanDeleteAPIloading}
120+
></DeletePopUpForOrphanNodes>
96121
<SettingsModal
97122
openTextSchema={openSchemaFromTextDialog}
98123
open={isSettingPanelExpanded}
@@ -107,6 +132,7 @@ export default function PageLayoutNew({
107132
isRightExpanded={isRightExpanded}
108133
showChatBot={showChatBot}
109134
openTextSchema={openSchemaFromTextDialog}
135+
openOrphanNodeDeletionModal={openOrphanNodeDeletionModal}
110136
isSchema={isSchema}
111137
setIsSchema={setIsSchema}
112138
/>

0 commit comments

Comments
 (0)