Skip to content

Commit

Permalink
disable submit when a cell is being edited
Browse files Browse the repository at this point in the history
  • Loading branch information
liberty-rising committed Feb 6, 2024
1 parent 344311b commit 1b5ef4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 15 additions & 2 deletions frontend/src/pages/upload/PreviewTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import { Column } from "primereact/column";
import { InputTextarea } from "primereact/inputtextarea";
import "primereact/resources/themes/lara-light-cyan/theme.css";
import "../../styles/tableStyles.css";
import { set } from "date-fns";

function PreviewTable({ columnNames, previewData, onChangePreviewData }) {
function PreviewTable({
columnNames,
previewData,
onChangePreviewData,
setIsEditingCell,
}) {
const columns = columnNames.map((name) => ({
Header: name.toUpperCase(),
accessor: name,
Expand All @@ -15,6 +21,7 @@ function PreviewTable({ columnNames, previewData, onChangePreviewData }) {
const data = previewData || [];

const cellEditor = (options) => {
setIsEditingCell(true);
return textEditor(options);
};

Expand All @@ -24,7 +31,7 @@ function PreviewTable({ columnNames, previewData, onChangePreviewData }) {
autoResize={true}
style={{ width: "100%", height: "100%" }}
value={options.value}
onChange={(e) => options.onEditorValueChange(e.target.value)}
onChange={(e) => options.editorCallback(e.target.value)}
/>
);
};
Expand All @@ -38,6 +45,7 @@ function PreviewTable({ columnNames, previewData, onChangePreviewData }) {
field,
newValue,
);
setIsEditingCell(false);
} else {
event.preventDefault();
}
Expand All @@ -47,6 +55,11 @@ function PreviewTable({ columnNames, previewData, onChangePreviewData }) {
<DataTable
value={data}
emptyMessage="Upload your files and click preview to see the data"
paginator
rows={5}
rowsPerPageOptions={[5, 10, 25, 50]}
paginatorTemplate="RowsPerPageDropdown FirstPageLink PrevPageLink CurrentPageReport NextPageLink LastPageLink"
currentPageReportTemplate="{first}-{last} of {totalRecords}"
editMode="cell"
resizableColumns
scrollable
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/pages/upload/UploadPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function UploadPage() {
const [previewData, setPreviewData] = useState(null);
const [isPreviewLoading, setIsPreviewLoading] = useState(false);
const [isPreviewTableOpen, setIsPreviewTableOpen] = useState(false);
const [isEditingCell, setIsEditingCell] = useState(false);

useEffect(() => {
axios
Expand Down Expand Up @@ -225,6 +226,7 @@ function UploadPage() {
columnNames={columnNames}
previewData={previewData}
onChangePreviewData={handleChangePreviewData}
setIsEditingCell={setIsEditingCell}
/>
)}
</Box>
Expand All @@ -250,7 +252,8 @@ function UploadPage() {
!dataProfile ||
!previewData ||
!isPreviewTableOpen ||
isPreviewLoading
isPreviewLoading ||
isEditingCell
}
>
Submit
Expand Down

0 comments on commit 1b5ef4e

Please sign in to comment.