Skip to content

Commit

Permalink
Merge pull request #133 from oss-slu/129-choose-file-button-functiona…
Browse files Browse the repository at this point in the history
…lity

added alert when duplicate file is selected
  • Loading branch information
bhumulanandinireddy authored Feb 4, 2025
2 parents 76b6253 + 6094b51 commit ec36034
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions client-app/src/components/OrcaDashboardComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ const OrcaDashboardComponent = () => {
const isSectionsEmpty = sections.length === 0;
const [sameCriteria, setSameCriteria] = useState(false);
const [previewContent, setPreviewContent] = useState("");
const [showPreviewModal, setShowPreviewModal] = useState(false);
const [showPreviewModal, setShowPreviewModal] = useState(false);

const onFileSelected = (event) => {
const selectedFile = event.target.files[0];
if (selectedFile.type !== "text/plain") {
alert("Invalid file type. Please upload a .txt file.");
return;
}

if (uploadedFiles.includes(selectedFile.name)) {
alert(`The file "${selectedFile.name}" has already been uploaded.`);
return;
}
setSelectedFile(selectedFile);
};

Expand Down Expand Up @@ -69,17 +74,22 @@ const OrcaDashboardComponent = () => {

const formatSpecifyLines = () => {
const line = specifyLines[0];
return line.value === "WHOLE" || line.value === "SELECT"
? line.value
return line.value === "WHOLE" || line.value === "SELECT"
? line.value
: `${line.value} ${line.lineNumber}`;
};
};

const onUpload = () => {
if (!selectedFile) {
console.error("No file selected");
return;
}

if (uploadedFiles.includes(selectedFile.name)) {
alert(`The file "${selectedFile.name}" has already been uploaded.`);
return;
}

const formData = new FormData();
formData.append("file", selectedFile);

Expand Down Expand Up @@ -109,7 +119,7 @@ const OrcaDashboardComponent = () => {
file_path: filePath.toString(),
search_terms: searchTerms,
sections: sections,
specify_lines: formatSpecifyLines()
specify_lines: formatSpecifyLines(),
};

axios
Expand Down Expand Up @@ -203,14 +213,14 @@ const OrcaDashboardComponent = () => {
file_path: filePath.toString(),
search_terms: searchTerms,
sections: sections,
specify_lines: formatSpecifyLines()
specify_lines: formatSpecifyLines(),
};

axios
.post(`${config.apiBaseUrl}/preview`, data)
.then((response) => {
setPreviewContent(response.data.document_content);
setShowPreviewModal(true);
setPreviewContent(response.data.document_content);
setShowPreviewModal(true);
})
.catch((error) => {
if (error.response && error.response.status === 404) {
Expand Down Expand Up @@ -354,28 +364,32 @@ const OrcaDashboardComponent = () => {
<button
className="btn btn-primary"
onClick={fetchDocumentPreview}
disabled={
!searchTerms.length ||
!specifyLines.length ||
!sections.length ||
!selectedFile ||
isUploadedFilesEmpty
}>
disabled={
!searchTerms.length ||
!specifyLines.length ||
!sections.length ||
!selectedFile ||
isUploadedFilesEmpty
}>
Preview
</button>
</div>
</div>
{showPreviewModal && (
<div className="modal" style={{ display: "block", backgroundColor: "rgba(0, 0, 0, 0.5)" }}>
<div className="modal-dialog" style={{ maxWidth: "80vw"}}>
<div
className="modal"
style={{ display: "block", backgroundColor: "rgba(0, 0, 0, 0.5)" }}>
<div className="modal-dialog" style={{ maxWidth: "80vw" }}>
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title">Document Preview</h5>
<button type="button" className="btn-close" aria-label="Close" onClick={() => setShowPreviewModal(false)}></button>
<button
type="button"
className="btn-close"
aria-label="Close"
onClick={() => setShowPreviewModal(false)}></button>
</div>
<div className="modal-body">
<pre>
{previewContent}
</pre>
<pre>{previewContent}</pre>
</div>
<div className="modal-footer">
<button className="btn btn-secondary" onClick={() => setShowPreviewModal(false)}>
Expand All @@ -401,7 +415,6 @@ const OrcaDashboardComponent = () => {
Download Output
</button>
</div>

</div>
</div>
);
Expand Down

0 comments on commit ec36034

Please sign in to comment.