Skip to content

Commit

Permalink
Populate name on upload
Browse files Browse the repository at this point in the history
  • Loading branch information
overmode committed Nov 28, 2024
1 parent 82b47ae commit 091d5b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 9 additions & 1 deletion front/components/data_source/DocumentUploadOrEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -229,7 +237,7 @@ export const DocumentUploadOrEditModal = ({
});
}
},
[fileUploaderService, sendNotification]
[fileUploaderService, sendNotification, setDocumentState]
);

// Effect: Set the document state when the document is loaded
Expand Down
15 changes: 14 additions & 1 deletion front/components/data_source/TableUploadOrEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -403,3 +408,11 @@ export const TableUploadOrEditModal = ({
</Modal>
);
};

function stripTableName(name: string) {
return name
.replace(/\.(csv|tsv)$/, "")
.replace(/[^a-z0-9]/gi, "_")
.toLowerCase()
.slice(0, 32);
}

0 comments on commit 091d5b6

Please sign in to comment.