diff --git a/front/components/data_source/DocumentUploadOrEditModal.tsx b/front/components/data_source/DocumentUploadOrEditModal.tsx index d5afe368f213..a4ecd8d0c68b 100644 --- a/front/components/data_source/DocumentUploadOrEditModal.tsx +++ b/front/components/data_source/DocumentUploadOrEditModal.tsx @@ -221,6 +221,14 @@ export const DocumentUploadOrEditModal = ({ // triggers content extraction -> documentState.text update setFileId(fileBlobs[0].fileId); + setDocumentState((prev) => ({ + ...prev, + name: prev.name.length > 0 ? prev.name : selectedFile.name, + sourceUrl: + prev.sourceUrl.length > 0 + ? prev.sourceUrl + : fileBlobs[0].publicUrl ?? "", + })); } catch (error) { sendNotification({ type: "error", @@ -229,7 +237,7 @@ export const DocumentUploadOrEditModal = ({ }); } }, - [fileUploaderService, sendNotification] + [fileUploaderService, sendNotification, setDocumentState] ); // Effect: Set the document state when the document is loaded diff --git a/front/components/data_source/TableUploadOrEditModal.tsx b/front/components/data_source/TableUploadOrEditModal.tsx index 86346cd6738d..efe6fc274557 100644 --- a/front/components/data_source/TableUploadOrEditModal.tsx +++ b/front/components/data_source/TableUploadOrEditModal.tsx @@ -228,7 +228,12 @@ export const TableUploadOrEditModal = ({ // triggers content extraction -> tableState.content update setFileId(fileBlobs[0].fileId); - setTableState((prev) => ({ ...prev, file: selectedFile })); + setTableState((prev) => ({ + ...prev, + file: selectedFile, + name: + prev.name.length > 0 ? prev.name : stripTableName(selectedFile.name), + })); setIsBigFile(selectedFile.size > BIG_FILE_SIZE); } catch (error) { sendNotification({ @@ -403,3 +408,11 @@ export const TableUploadOrEditModal = ({ ); }; + +function stripTableName(name: string) { + return name + .replace(/\.(csv|tsv)$/, "") + .replace(/[^a-z0-9]/gi, "_") + .toLowerCase() + .slice(0, 32); +}