From 12d736ee8d790fc14b8871be5008dd61813faf62 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Fri, 3 Oct 2025 21:57:13 +0530 Subject: [PATCH 1/2] fix: XYNE-94 removed unsupported files while sending to server --- .../_authenticated/knowledgeManagement.tsx | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/frontend/src/routes/_authenticated/knowledgeManagement.tsx b/frontend/src/routes/_authenticated/knowledgeManagement.tsx index bc0253440..4159f74b9 100644 --- a/frontend/src/routes/_authenticated/knowledgeManagement.tsx +++ b/frontend/src/routes/_authenticated/knowledgeManagement.tsx @@ -37,6 +37,7 @@ import { deleteCollection, deleteItem, } from "@/utils/fileUtils" +import { isValidFile } from "shared/fileUtils" import type { Collection as CollectionType, CollectionItem, @@ -662,9 +663,21 @@ function KnowledgeManagementContent() { return } - // Start the global upload progress - const batches = createBatches(selectedFiles, collectionName.trim()) - const files = selectedFiles.map(f => ({ file: f.file, id: f.id })) + // Filter out unsupported files before upload + const validFiles = selectedFiles.filter(f => isValidFile(f.file)) + + + if (validFiles.length === 0) { + toast.error({ + title: "Upload Error", + description: "No valid files to upload. All selected files are unsupported.", + }) + return + } + + // Start the global upload progress with only valid files + const batches = createBatches(validFiles, collectionName.trim()) + const files = validFiles.map(f => ({ file: f.file, id: f.id })) const { uploadId, abortController } = startUpload(collectionName.trim(), files, batches.length, true) // Close the modal immediately after starting upload @@ -858,9 +871,20 @@ function KnowledgeManagementContent() { return } - // Start the global upload progress - const batches = createBatches(selectedFiles, addingToCollection.name) - const files = selectedFiles.map(f => ({ file: f.file, id: f.id })) + // Filter out unsupported files before upload + const validFiles = selectedFiles.filter(f => isValidFile(f.file)) + + if (validFiles.length === 0) { + toast.error({ + title: "Upload Error", + description: "No valid files to upload. All selected files are unsupported.", + }) + return + } + + // Start the global upload progress with only valid files + const batches = createBatches(validFiles, addingToCollection.name) + const files = validFiles.map(f => ({ file: f.file, id: f.id })) const { uploadId, abortController } = startUpload(addingToCollection.name, files, batches.length, false, addingToCollection.id) // Close the modal immediately after starting upload From 68ba2c51c8657d53e8f50f27b99b3febf53f9547 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Fri, 3 Oct 2025 22:14:34 +0530 Subject: [PATCH 2/2] refactor: XYNE-94 comments resolved --- .../_authenticated/knowledgeManagement.tsx | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/frontend/src/routes/_authenticated/knowledgeManagement.tsx b/frontend/src/routes/_authenticated/knowledgeManagement.tsx index 4159f74b9..9666a9124 100644 --- a/frontend/src/routes/_authenticated/knowledgeManagement.tsx +++ b/frontend/src/routes/_authenticated/knowledgeManagement.tsx @@ -641,6 +641,21 @@ function KnowledgeManagementContent() { setOpenDropdown(null) } + // Utility function to filter valid files and show error if none are valid + const getValidFilesOrShowError = (files: FileUploadSelectedFile[]) => { + const validFiles = files.filter(f => isValidFile(f.file)) + + if (validFiles.length === 0) { + toast.error({ + title: "Unsupported Files", + description: "No valid files to upload. All selected files are unsupported.", + }) + return null + } + + return validFiles + } + const handleUpload = async () => { if (selectedFiles.length === 0) { toast.error({ @@ -664,16 +679,8 @@ function KnowledgeManagementContent() { } // Filter out unsupported files before upload - const validFiles = selectedFiles.filter(f => isValidFile(f.file)) - - - if (validFiles.length === 0) { - toast.error({ - title: "Upload Error", - description: "No valid files to upload. All selected files are unsupported.", - }) - return - } + const validFiles = getValidFilesOrShowError(selectedFiles) + if (!validFiles) return // Start the global upload progress with only valid files const batches = createBatches(validFiles, collectionName.trim()) @@ -872,15 +879,8 @@ function KnowledgeManagementContent() { } // Filter out unsupported files before upload - const validFiles = selectedFiles.filter(f => isValidFile(f.file)) - - if (validFiles.length === 0) { - toast.error({ - title: "Upload Error", - description: "No valid files to upload. All selected files are unsupported.", - }) - return - } + const validFiles = getValidFilesOrShowError(selectedFiles) + if (!validFiles) return // Start the global upload progress with only valid files const batches = createBatches(validFiles, addingToCollection.name)