Skip to content

Commit

Permalink
custom_change
Browse files Browse the repository at this point in the history
  • Loading branch information
prakriti-solankey authored Dec 20, 2024
1 parent 60b4393 commit 2ea083b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 69 deletions.
2 changes: 1 addition & 1 deletion backend/src/graph_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
110 changes: 55 additions & 55 deletions frontend/src/components/Layout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -195,7 +196,7 @@ const PageLayout: React.FC = () => {
}
}
initializeConnection();
}, []);
}, []);

const deleteOnClick = async () => {
try {
Expand Down Expand Up @@ -259,9 +260,8 @@ const PageLayout: React.FC = () => {
></SchemaFromTextDialog>
{largedesktops ? (
<div
className={`layout-wrapper ${!isLeftExpanded ? 'drawerdropzoneclosed' : ''} ${
!isRightExpanded ? 'drawerchatbotclosed' : ''
} ${!isRightExpanded && !isLeftExpanded ? 'drawerclosed' : ''}`}
className={`layout-wrapper ${!isLeftExpanded ? 'drawerdropzoneclosed' : ''} ${!isRightExpanded ? 'drawerchatbotclosed' : ''
} ${!isRightExpanded && !isLeftExpanded ? 'drawerclosed' : ''}`}
>
<SideNav
toggles3Modal={toggleS3Modal}
Expand Down
25 changes: 23 additions & 2 deletions frontend/src/components/Layout/SideNav.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { Dialog, SideNavigation, TextLink, Tooltip, useMediaQuery } from '@neo4j-ndl/react';
import {
ArrowRightIconOutline,
Expand Down Expand Up @@ -43,7 +43,7 @@ const SideNav: React.FC<SideNavProps> = ({
}) => {
const [isChatModalOpen, setIsChatModalOpen] = useState(false);
const [isFullScreen, setIsFullScreen] = useState(false);
const { setMessages, isDeleteChatLoading } = useMessageContext();
const { setMessages, isDeleteChatLoading,setClearHistoryData } = useMessageContext();
const [showChatMode, setshowChatMode] = useState<boolean>(false);
const largedesktops = useMediaQuery(`(min-width:1440px )`);
const { connectionStatus, isReadOnlyUser } = useCredentials();
Expand Down Expand Up @@ -77,6 +77,27 @@ const SideNav: React.FC<SideNavProps> = ({
}
};

useEffect(() => {
if (clearHistoryData) {
const currentDateTime = new Date();
setMessages([
{
datetime: `${currentDateTime.toLocaleDateString()} ${currentDateTime.toLocaleTimeString()}`,
id: 2,
modes: {
'graph+vector+fulltext': {
message:
'Welcome to the Neo4j Knowledge Graph Chat. You can ask questions related to documents which have been completely processed.',
},
},
user: 'chatbot',
currentMode: 'graph+vector+fulltext',
},
]);
setClearHistoryData(false);
}
}, [clearHistoryData, setMessages]);

return (
<div style={{ height: 'calc(100vh - 58px)', minHeight: '200px', display: 'flex' }}>
<SideNavigation hasIconMenu={true} isExpanded={false} position={position}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function ConnectionModal({
const [username, setUsername] = useState<string>(initialusername ?? 'neo4j');
const [password, setPassword] = useState<string>('');
const [connectionMessage, setMessage] = useState<Message | null>({ type: 'unknown', content: '' });
const { setUserCredentials, userCredentials, setGdsActive, setIsReadOnlyUser, errorMessage, setIsGCSActive } =
const { setUserCredentials, userCredentials, setGdsActive, setIsReadOnlyUser, errorMessage, setIsGCSActive,setShowDisconnectButton } =
useCredentials();
const [isLoading, setIsLoading] = useState<boolean>(false);
const [searchParams, setSearchParams] = useSearchParams();
Expand Down Expand Up @@ -126,7 +126,7 @@ export default function ConnectionModal({

useEffect(() => {
if (errorMessage) {
setMessage({ type: 'danger', content: errorMessage });
setMessage({ type: 'warning', content: errorMessage });
}
}, [errorMessage]);

Expand Down Expand Up @@ -241,6 +241,7 @@ export default function ConnectionModal({
!response.data.data.chunks_exists
) {
setConnectionStatus(true);
setShowDisconnectButton(true);
setOpenConnection((prev) => ({ ...prev, openPopUp: false }));
setMessage({
type: 'success',
Expand Down
19 changes: 10 additions & 9 deletions frontend/src/components/UI/CustomMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ export default function CustomMenu({
anchorOrigin: React.RefObject<HTMLElement | null>;
isRoot?: boolean;
}) {
console.log()
return (
<Menu isOpen={open} anchorRef={anchorOrigin} className='custom-menu' isRoot={isRoot} onClose={closeHandler}>
{items?.map((i) => (
<Menu.Item
key={`${i.title}`}
title={i.title}
onClick={i.onClick}
isDisabled={i.disabledCondition}
className={i.isSelected ? i.selectedClassName : ''}
description={i.description}
/>
{items?.map((i, index) => (
<Menu.Item
key={`${i.title}-${index}`}
title={i.title}
onClick={i.onClick}
isDisabled={i.disabledCondition}
className={i.isSelected ? i.selectedClassName : ''}
description={i.description}
/>
))}
</Menu>
);
Expand Down

0 comments on commit 2ea083b

Please sign in to comment.