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

Preview table #261

Merged
merged 2 commits into from
Feb 6, 2024
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
12 changes: 11 additions & 1 deletion frontend/src/components/layouts/AppLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ const AppLayout = ({ children }) => {
<Box sx={{ display: "flex" }}>
<Header navLinks={navLinks} />
<Navigation />
<Box component="main" sx={{ flexGrow: 1, p: 6, marginTop: "10px" }}>
<Box
component="main"
sx={{
flexGrow: 1,
p: 6,
marginTop: "10px",
marginTop: "10px",
maxWidth: "100vw", // Ensures the main content does not exceed the viewport width
overflowX: "hidden",
}}
>
<Toolbar />
{children}
</Box>
Expand Down
19 changes: 17 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,8 +55,15 @@ 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
scrollHeight="flex"
showGridlines
tableStyle={{ minWidth: "150px" }}
>
Expand Down
7 changes: 5 additions & 2 deletions 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 @@ -219,12 +220,13 @@ function UploadPage() {
<FileUploader setFiles={setUploadFiles} id="upload-page-uploader" />
</Box>

<Box mt={2}>
<Box mt={2} sx={{ width: "100%", maxWidth: "100%" }}>
{((columnNames && columnNames.length > 0) || previewData) && (
<PreviewTable
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
Loading