Skip to content

Commit

Permalink
Merge pull request #261 from DocShow-AI/preview-table
Browse files Browse the repository at this point in the history
Preview table
  • Loading branch information
liberty-rising authored Feb 6, 2024
2 parents dd520bd + 1b5ef4e commit dbc1a55
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
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

0 comments on commit dbc1a55

Please sign in to comment.