Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancing Section Input Flexibility #153

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 51 additions & 22 deletions client-app/src/components/OrcaDashboardComponent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from "react";
import axios from "axios";
import { useEffect } from "react";
import { saveAs } from "file-saver";
import { FaDownload } from "react-icons/fa6";
import "../styles/OrcaDashboardComponent.css";
Expand All @@ -19,7 +20,7 @@ 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 [selectedFileName, setSelectedFileName] = useState("No file chosen");

const onFileSelected = (event) => {
Expand Down Expand Up @@ -143,10 +144,11 @@ const OrcaDashboardComponent = () => {
downloadDocument(blob);
})
.catch((error) => {
if (error.response){
if (error.response) {
if (error.response.status === 404) {
alert("There is no data for the provided search term");
} else {alert(`Error ${error.response.status}: ${error.response.statusText}`);
} else {
alert(`Error ${error.response.status}: ${error.response.statusText}`);
}
}
});
Expand Down Expand Up @@ -201,14 +203,29 @@ const OrcaDashboardComponent = () => {
};

const handleNumSectionsBlur = (e) => {
const parsedSections = e.target.value
.split(",")
.map((val) => val.trim())
.filter((val) => val !== "");
const input = e.target.value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you had written a clean code for range (1-3) to work but Some edge cases is being missed make sure to check it once

let parsedSections = new Set();

input.split(",").forEach((part) => {
part = part.trim();
if (part.includes("-")) {
const [start, end] = part.split("-").map((num) => parseInt(num.trim(), 10));
if (!isNaN(start) && !isNaN(end) && start <= end) {
for (let i = start; i <= end; i++) {
parsedSections.add(i);
}
}
} else {
const num = parseInt(part, 10);
if (!isNaN(num)) {
parsedSections.add(num);
}
}
});

setSections(parsedSections);
setSections(Array.from(parsedSections).sort((a, b) => a - b));
};

const removeTag = (index, setterFunc) => {
setterFunc((prevTerms) => {
const updatedTerms = [...prevTerms];
Expand Down Expand Up @@ -257,14 +274,26 @@ const OrcaDashboardComponent = () => {
});
};

useEffect(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is clean and effective

const handleKeyDown = (event) => {
if (event.key === "Escape") {
setShowPreviewModal(false);
}
};

document.addEventListener("keydown", handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown);
}, []);

return (
<div className="container py-5 d-flex justify-content-center">
<div className="text-center">
<h2 className="mb-4">Extract data from ORCA files to Word documents</h2>
<div className="mb-3 text-start">
<label htmlFor="fileUpload" className="mb-2">Upload your ORCA data file:</label>
<label htmlFor="fileUpload" className="mb-2">
Upload your ORCA data file:
</label>
<div className="input-group">

<input
className="form-control"
type="file"
Expand Down Expand Up @@ -294,7 +323,9 @@ const OrcaDashboardComponent = () => {
</div>

<div className="mb-3 text-start">
<label htmlFor="searchTermInput" className="mb-2">Enter the terms you wish to search for (txt only):</label>
<label htmlFor="searchTermInput" className="mb-2">
Enter the terms you wish to search for (txt only):
</label>
<div>
<input
type="text"
Expand Down Expand Up @@ -331,12 +362,16 @@ const OrcaDashboardComponent = () => {
</div>

<div className="mb-3 text-start">
<label htmlFor="specifyLinesSelect" className="mb-2">Enter how you want the lines specified:</label>
<label htmlFor="specifyLinesSelect" className="mb-2">
Enter how you want the lines specified:
</label>
{renderSpecifyLine()}
</div>

<div className="mb-3 text-start">
<label htmlFor="numSectionsInput" className="mb-2">Number of sections?</label>
<label htmlFor="numSectionsInput" className="mb-2">
Number of sections?
</label>
<input
type="text"
className="form-control"
Expand Down Expand Up @@ -428,10 +463,7 @@ const OrcaDashboardComponent = () => {
!selectedFile ||
isUploadedFilesEmpty
}>
<FaDownload
size="1.2em"
title="Download Output"
/>
<FaDownload size="1.2em" title="Download Output" />
</button>
<button className="btn btn-secondary" onClick={() => setShowPreviewModal(false)}>
Close
Expand All @@ -453,10 +485,7 @@ const OrcaDashboardComponent = () => {
!selectedFile ||
isUploadedFilesEmpty
}>
<FaDownload
size="1.2em"
title="Download Output"
/>
<FaDownload size="1.2em" title="Download Output" />
</button>
</div>
</div>
Expand Down
17 changes: 11 additions & 6 deletions server/services/file_search_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,20 @@ def is_end_pattern(lines, index):
return ""

for term in search_terms:
term_line_num = term_line_nums[term]
for i in range(len(sections)):
section_lines = specify_lines[i].split()
start_line = term_line_num[i] if i < len(term_line_num) else None
term_line_num = term_line_nums.get(term, [])

for section_number in sections:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaver usage of logic and optimal lines of code really good

if section_number > len(specify_lines):
continue

section_lines = specify_lines[section_number - 1].split()
start_line = term_line_num[section_number - 1] if section_number - 1 < len(term_line_num) else None

if start_line is None:
continue # Skip this section if the term is not found
continue

line_empty = 0
document_content += lines[start_line]
document_content += lines[start_line] + "\n"

if section_lines[0].upper() == 'WHOLE' and not use_total_lines:
while line_empty == 0:
Expand Down