mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50:15 +01:00
📂 refactor: Improve FileAttachment & File Form Deletion (#7471)
* refactor: optional attachment properties for `FileAttachment` * refactor: update ActionButton to use localized text * chore: localize text in DataTableFile, add missing translation, imports order, and linting * chore: linting in DataTable * fix: integrate Recoil state management for file deletion in DataTableFile * fix: integrate Recoil state management for file deletion in DataTable * fix: add temp_file_id to BatchFile type and update deleteFiles logic to properly remove files that are mapped to temp_file_id
This commit is contained in:
parent
e86842fd19
commit
eb1668ff22
7 changed files with 65 additions and 40 deletions
|
|
@ -19,7 +19,6 @@ const useFileDeletion = ({
|
|||
assistant_id?: string;
|
||||
tool_resource?: EToolResources;
|
||||
}) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const [_batch, setFileDeleteBatch] = useState<t.BatchFile[]>([]);
|
||||
const setFilesToDelete = useSetFilesToDelete();
|
||||
|
||||
|
|
@ -109,22 +108,33 @@ const useFileDeletion = ({
|
|||
|
||||
const deleteFiles = useCallback(
|
||||
({ files, setFiles }: { files: ExtendedFile[] | t.TFile[]; setFiles?: FileMapSetter }) => {
|
||||
const batchFiles = files.map((_file) => {
|
||||
const { file_id, embedded, filepath = '', source = FileSources.local } = _file;
|
||||
const batchFiles: t.BatchFile[] = [];
|
||||
for (const _file of files) {
|
||||
const {
|
||||
file_id,
|
||||
embedded,
|
||||
temp_file_id,
|
||||
filepath = '',
|
||||
source = FileSources.local,
|
||||
} = _file;
|
||||
|
||||
return {
|
||||
batchFiles.push({
|
||||
source,
|
||||
file_id,
|
||||
filepath,
|
||||
embedded,
|
||||
};
|
||||
});
|
||||
temp_file_id,
|
||||
embedded: embedded ?? false,
|
||||
});
|
||||
}
|
||||
|
||||
if (setFiles) {
|
||||
setFiles((currentFiles) => {
|
||||
const updatedFiles = new Map(currentFiles);
|
||||
batchFiles.forEach((file) => {
|
||||
updatedFiles.delete(file.file_id);
|
||||
if (file.temp_file_id) {
|
||||
updatedFiles.delete(file.temp_file_id);
|
||||
}
|
||||
});
|
||||
const filesToUpdate = Object.fromEntries(updatedFiles);
|
||||
setFilesToDelete(filesToUpdate);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue