From 2ea083bd4dd891f9c67392be9e82f00f74a47e51 Mon Sep 17 00:00:00 2001 From: Prakriti Solankey <156313631+prakriti-solankey@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:01:51 +0000 Subject: [PATCH] custom_change --- backend/src/graph_query.py | 2 +- frontend/src/components/Layout/PageLayout.tsx | 110 +++++++++--------- frontend/src/components/Layout/SideNav.tsx | 25 +++- .../ConnectionModal/ConnectionModal.tsx | 5 +- frontend/src/components/UI/CustomMenu.tsx | 19 +-- 5 files changed, 92 insertions(+), 69 deletions(-) diff --git a/backend/src/graph_query.py b/backend/src/graph_query.py index f9af6102..8583d8cc 100644 --- a/backend/src/graph_query.py +++ b/backend/src/graph_query.py @@ -201,7 +201,7 @@ def get_graph_results(uri, username, password,database,document_names): try: logging.info(f"Starting graph query process") driver = get_graphDB_driver(uri, username, password,database) - document_names= list(map(str.strip, json.loads(document_names))) + document_names= list(map(str, json.loads(document_names))) query = GRAPH_QUERY.format(graph_chunk_limit=GRAPH_CHUNK_LIMIT) records, summary , keys = execute_query(driver, query.strip(), document_names) document_nodes = extract_node_elements(records) diff --git a/frontend/src/components/Layout/PageLayout.tsx b/frontend/src/components/Layout/PageLayout.tsx index beb6387a..2bcff94f 100644 --- a/frontend/src/components/Layout/PageLayout.tsx +++ b/frontend/src/components/Layout/PageLayout.tsx @@ -80,8 +80,26 @@ const PageLayout: React.FC = () => { setShowDisconnectButton(isModalOpen); localStorage.setItem('disconnectButtonState', isModalOpen ? 'true' : 'false'); }; - // To parse and set user credentials from session - const setUserCredentialsFromSession = (neo4jConnection: string) => { + const setUserCredentialsLocally = (credentials: any) => { + setUserCredentials(credentials); + setIsGCSActive(credentials.isGCSActive ?? false); + setGdsActive(credentials.isgdsActive); + setIsReadOnlyUser(credentials.isReadonlyUser); + localStorage.setItem( + 'neo4j.connection', + JSON.stringify({ + uri: credentials.uri, + user: credentials.userName, + password: btoa(credentials.password), + database: credentials.database, + userDbVectorIndex: 384, + isReadOnlyUser: credentials.isReadonlyUser, + isgdsActive: credentials.isgdsActive, + isGCSActive: credentials.isGCSActive, + }) + ); + }; + const parseSessionAndSetCredentials = (neo4jConnection: string) => { if (!neo4jConnection) { console.error('Invalid session data:', neo4jConnection); setOpenConnection((prev) => ({ ...prev, openPopUp: true })); @@ -117,20 +135,8 @@ const PageLayout: React.FC = () => { btoa(envCredentials.password) !== storedCredentials.password || envCredentials.database !== storedCredentials.database; if (isDiffCreds) { - setUserCredentials(envCredentials); - setIsGCSActive(envCredentials.isGCSActive ?? false); - localStorage.setItem( - 'neo4j.connection', - JSON.stringify({ - uri: envCredentials.uri, - user: envCredentials.userName, - password: btoa(envCredentials.password), - database: envCredentials.database, - userDbVectorIndex: 384, - isReadOnlyUser: envCredentials.isReadonlyUser, - isgdsActive: envCredentials.isgdsActive, - }) - ); + setUserCredentialsLocally(envCredentials); + setClearHistoryData(true); return true; } return false; @@ -144,48 +150,43 @@ const PageLayout: React.FC = () => { try { backendApiResponse = await envConnectionAPI(); const connectionData = backendApiResponse.data; - const envCredentials = { - uri: connectionData.data.uri, - password: atob(connectionData.data.password), - userName: connectionData.data.user_name, - database: connectionData.data.database, - isReadonlyUser: !connectionData.data.write_access, - isgdsActive: connectionData.data.gds_status, - isGCSActive: connectionData?.data?.gcs_file_cache === 'True', - }; - setIsGCSActive(connectionData?.data?.gcs_file_cache === 'True'); - if (session) { - const updated = updateSessionIfNeeded(envCredentials, session); - if (!updated) { - setUserCredentialsFromSession(session); // Use stored session if no update is needed + if (connectionData.data && connectionData.status === 'Success') { + const envCredentials = { + uri: connectionData.data.uri, + password: atob(connectionData.data.password), + userName: connectionData.data.user_name, + database: connectionData.data.database, + isReadonlyUser: !connectionData.data.write_access, + isgdsActive: connectionData.data.gds_status, + isGCSActive: connectionData?.data?.gcs_file_cache === 'True', + }; + setIsGCSActive(envCredentials.isGCSActive); + if (session) { + const updated = updateSessionIfNeeded(envCredentials, session); + if (!updated) { + parseSessionAndSetCredentials(session); + } + setConnectionStatus(Boolean(connectionData.data.graph_connection)); + setIsBackendConnected(true); + } else { + setUserCredentialsLocally(envCredentials); + setConnectionStatus(true); } - setConnectionStatus(Boolean(connectionData.data.graph_connection)); - setIsBackendConnected(true); handleDisconnectButtonState(false); } else { - setUserCredentials(envCredentials); - localStorage.setItem( - 'neo4j.connection', - JSON.stringify({ - uri: envCredentials.uri, - user: envCredentials.userName, - password: btoa(envCredentials.password), - database: envCredentials.database, - userDbVectorIndex: 384, - isReadOnlyUser: envCredentials.isReadonlyUser, - isgdsActive: envCredentials.isgdsActive, - isGCSActive: envCredentials.isGCSActive, - }) - ); - setConnectionStatus(true); - setGdsActive(envCredentials.isgdsActive); - setIsReadOnlyUser(envCredentials.isReadonlyUser); - handleDisconnectButtonState(false); + if (session) { + parseSessionAndSetCredentials(session); + setConnectionStatus(true); + } else { + setErrorMessage(backendApiResponse?.data?.error); + setOpenConnection((prev) => ({ ...prev, openPopUp: true })); + } + handleDisconnectButtonState(true); } } catch (error) { console.error('Error during backend API call:', error); if (session) { - setUserCredentialsFromSession(session); + parseSessionAndSetCredentials(session); setConnectionStatus(true); } else { setErrorMessage(backendApiResponse?.data?.error); @@ -195,7 +196,7 @@ const PageLayout: React.FC = () => { } } initializeConnection(); - }, []); + }, []); const deleteOnClick = async () => { try { @@ -259,9 +260,8 @@ const PageLayout: React.FC = () => { > {largedesktops ? (