-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exporting all conversations feature
- Loading branch information
1 parent
638ac5b
commit b781318
Showing
12 changed files
with
277 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
client/src/components/Nav/SettingsTabs/Data/ExportConversations.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { useState } from 'react'; | ||
import { ArrowRightFromLine } from 'lucide-react'; | ||
import { useExportConversationsMutation } from '~/data-provider'; | ||
import { useLocalize } from '~/hooks'; | ||
import { useToastContext } from '~/Providers'; | ||
|
||
function ExportConversations() { | ||
const localize = useLocalize(); | ||
const { showToast } = useToastContext(); | ||
const [errors, setErrors] = useState<string[]>([]); | ||
const setError = (error: string) => setErrors((prevErrors) => [...prevErrors, error]); | ||
|
||
const exportFile = useExportConversationsMutation({ | ||
onSuccess: (data) => { | ||
console.log('Exporting started', data); | ||
|
||
showToast({ message: localize('com_ui_export_conversation_success') }); | ||
|
||
// Directly initiate download here if `data` contains downloadable content or URL | ||
downloadConversationsJsonFile(data); | ||
}, | ||
onError: (error) => { | ||
console.error('Error: ', error); | ||
setError( | ||
(error as { response: { data: { message?: string } } }).response.data.message ?? | ||
'An error occurred while exporting the file.', | ||
); | ||
showToast({ message: localize('com_ui_export_conversation_error'), status: 'error' }); | ||
}, | ||
}); | ||
|
||
const startExport = () => { | ||
const formdata = new FormData(); | ||
exportFile.mutate(formdata); | ||
}; | ||
|
||
const downloadConversationsJsonFile = (data) => { | ||
// Assuming `data` is the downloadable content; adjust as necessary for your use case | ||
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }); | ||
const url = URL.createObjectURL(blob); | ||
|
||
const link = document.createElement('a'); | ||
link.href = url; | ||
link.download = 'conversations.json'; | ||
document.body.appendChild(link); | ||
link.click(); | ||
document.body.removeChild(link); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="flex items-center justify-between"> | ||
<span>{localize('com_nav_export_all_conversations')}</span> | ||
<button | ||
onClick={startExport} | ||
className="flex h-auto cursor-pointer items-center rounded bg-transparent px-2 py-1 text-xs font-medium font-normal transition-colors hover:bg-gray-100 hover:text-green-700 dark:bg-transparent dark:text-white dark:hover:bg-gray-600 dark:hover:text-green-500" | ||
> | ||
<ArrowRightFromLine className="mr-1 flex w-[22px] items-center stroke-1" /> | ||
<span>{localize('com_endpoint_export')}</span> | ||
</button> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default ExportConversations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,5 +100,8 @@ | |
"admin/", | ||
"packages/" | ||
] | ||
}, | ||
"dependencies": { | ||
"ollama": "^0.5.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.