Skip to content

Commit b1b52d3

Browse files
added the conversation download button (#800)
1 parent a8d1d96 commit b1b52d3

File tree

3 files changed

+58
-24
lines changed

3 files changed

+58
-24
lines changed

frontend/src/components/ChatBot/Chatbot.tsx

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { buttonCaptions, chatModeLables } from '../../utils/Constants';
3737
import useSpeechSynthesis from '../../hooks/useSpeech';
3838
import ButtonWithToolTip from '../UI/ButtonWithToolTip';
3939
import FallBackDialog from '../UI/FallBackDialog';
40-
import { getDateTime } from '../../utils/Utils';
40+
import { downloadClickHandler, getDateTime } from '../../utils/Utils';
4141
import ChatModesSwitch from './ChatModesSwitch';
4242
import CommonActions from './CommonChatActions';
4343
const InfoModal = lazy(() => import('./ChatInfoModal'));
@@ -407,15 +407,6 @@ const Chatbot: FC<ChatbotProps> = (props) => {
407407
}
408408
}, []);
409409

410-
const downloadClickHandler = useCallback(function downloadClickHandler<Type>(JsonData: Type) {
411-
const textFile = new Blob([JSON.stringify(JsonData)], { type: 'application/json' });
412-
if (downloadLinkRef && downloadLinkRef.current) {
413-
downloadLinkRef.current.href = URL.createObjectURL(textFile);
414-
downloadLinkRef.current.download = 'graph-builder-chat-details.json';
415-
downloadLinkRef.current.click();
416-
}
417-
}, []);
418-
419410
return (
420411
<div className='n-bg-palette-neutral-bg-weak flex flex-col justify-between min-h-full max-h-full overflow-hidden'>
421412
<div className='flex overflow-y-auto pb-12 min-w-full chatBotContainer pl-3 pr-3'>
@@ -590,17 +581,21 @@ const Chatbot: FC<ChatbotProps> = (props) => {
590581
clean
591582
disabled={metricsLoading || infoLoading}
592583
onClick={() => {
593-
downloadClickHandler({
594-
chatResponse: activeChat,
595-
chunks,
596-
metricDetails,
597-
communities,
598-
responseTime,
599-
entities: infoEntities,
600-
nodes,
601-
tokensUsed,
602-
model,
603-
});
584+
downloadClickHandler(
585+
{
586+
chatResponse: activeChat,
587+
chunks,
588+
metricDetails,
589+
communities,
590+
responseTime,
591+
entities: infoEntities,
592+
nodes,
593+
tokensUsed,
594+
model,
595+
},
596+
downloadLinkRef,
597+
'graph-builder-chat-details.json'
598+
);
604599
}}
605600
>
606601
<ArrowDownTrayIconOutline />

frontend/src/components/Layout/SideNav.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import React, { useEffect, useState } from 'react';
2-
import { Dialog, SideNavigation, Tip, useMediaQuery } from '@neo4j-ndl/react';
1+
import React, { useEffect, useRef, useState } from 'react';
2+
import { Dialog, SideNavigation, TextLink, Tip, useMediaQuery } from '@neo4j-ndl/react';
33
import {
44
ArrowRightIconOutline,
55
ArrowLeftIconOutline,
66
TrashIconOutline,
77
ArrowsPointingOutIconOutline,
88
ChatBubbleOvalLeftEllipsisIconOutline,
99
CloudArrowUpIconSolid,
10+
ArrowDownTrayIconOutline,
1011
} from '@neo4j-ndl/react/icons';
1112
import { SideNavProps } from '../../types';
1213
import Chatbot from '../ChatBot/Chatbot';
1314
import { createPortal } from 'react-dom';
1415
import { useMessageContext } from '../../context/UserMessages';
15-
import { getIsLoading } from '../../utils/Utils';
16+
import { downloadClickHandler, getIsLoading } from '../../utils/Utils';
1617
import ExpandedChatButtonContainer from '../ChatBot/ExpandedChatButtonContainer';
1718
import { APP_SOURCES, tooltips } from '../../utils/Constants';
1819
import ChatModeToggle from '../ChatBot/ChatModeToggle';
@@ -46,6 +47,7 @@ const SideNav: React.FC<SideNavProps> = ({
4647
const [showChatMode, setshowChatMode] = useState<boolean>(false);
4748
const largedesktops = useMediaQuery(`(min-width:1440px )`);
4849
const { connectionStatus, isReadOnlyUser } = useCredentials();
50+
const downloadLinkRef = useRef<HTMLAnchorElement>(null);
4951

5052
const date = new Date();
5153
useEffect(() => {
@@ -93,6 +95,7 @@ const SideNav: React.FC<SideNavProps> = ({
9395
toggleDrawer();
9496
}
9597
};
98+
9699
return (
97100
<div style={{ height: 'calc(100vh - 58px)', minHeight: '200px', display: 'flex' }}>
98101
<SideNavigation iconMenu={true} expanded={false} position={position}>
@@ -189,6 +192,30 @@ const SideNav: React.FC<SideNavProps> = ({
189192
}
190193
/>
191194
</Tip>
195+
<Tip allowedPlacements={['left']}>
196+
<SideNavigation.Item
197+
onClick={() => {
198+
downloadClickHandler(
199+
{ conversation: messages },
200+
downloadLinkRef,
201+
'graph-builder-conversation.json'
202+
);
203+
}}
204+
icon={
205+
<>
206+
<Tip.Trigger>
207+
<ArrowDownTrayIconOutline className='n-size-token-7' />
208+
</Tip.Trigger>
209+
<Tip.Content>
210+
Download Conversation
211+
<TextLink ref={downloadLinkRef} className='!hidden'>
212+
""
213+
</TextLink>
214+
</Tip.Content>
215+
</>
216+
}
217+
/>
218+
</Tip>
192219
{!isChatModalOpen && (
193220
<SideNavigation.Item
194221
onClick={(e) => {

frontend/src/utils/Utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,15 @@ export const graphTypeFromNodes = (allNodes: ExtendedNode[]) => {
498498
}
499499
return graphType;
500500
};
501+
export function downloadClickHandler<Type>(
502+
JsonData: Type,
503+
downloadLinkRef: React.RefObject<HTMLAnchorElement>,
504+
filename: string
505+
) {
506+
const textFile = new Blob([JSON.stringify(JsonData)], { type: 'application/json' });
507+
if (downloadLinkRef && downloadLinkRef.current) {
508+
downloadLinkRef.current.href = URL.createObjectURL(textFile);
509+
downloadLinkRef.current.download = filename;
510+
downloadLinkRef.current.click();
511+
}
512+
}

0 commit comments

Comments
 (0)