Skip to content

Commit

Permalink
Merge pull request #38 from hytech-racing/file_upload
Browse files Browse the repository at this point in the history
File upload
  • Loading branch information
aesteri authored Oct 22, 2024
2 parents 93c3f09 + a028bc3 commit c739949
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 33 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function DataTable({ data }: DataTableProps) {
);

return (
<Table.ScrollContainer h="100%" minWidth={800}>
<Table.ScrollContainer h="100%" minWidth={800} style={{ overflowY: 'auto' }}>
<Table
stickyHeader
highlightOnHover={data && data.length > 0}
Expand Down
106 changes: 106 additions & 0 deletions src/components/FileUpload.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import React, { useState } from 'react';
import { Modal, Button, Notification, FileInput } from '@mantine/core';
import '@/css/FileUpload.css';

interface FileUploadProps {
uploadUrl: string;
}

const FileUpload: React.FC<FileUploadProps> = ({ uploadUrl }) => {
const [showModal, setShowModal] = useState(false);
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
const [error, setError] = useState<string | null>(null);

const handleFileChange = (files: File[]) => {
if (files.length > 0) {
setSelectedFiles((prevFiles) => [...prevFiles, ...files]);
}
};

const handleUpload = async () => {
if (selectedFiles.length > 0) {
const formData = new FormData();
selectedFiles.forEach((file) => {
formData.append('files', file);
});

try {
const response = await fetch(uploadUrl, {
method: 'POST',
body: formData,
});

if (!response.ok) {
setError('Upload failed. Network response was not ok.');
return;
}

const data = await response.json();
console.log('Upload successful:', data);

setSelectedFiles([]);
handleClose();
} catch (error) {
console.error('Upload failed:', error);
setError('An error occurred while uploading. Please try again.');
}
} else {
setError('Please select files to upload.');
}
};

const toggleModal = () => {
setShowModal(!showModal);
};

const handleClose = () => {
setShowModal(false);
setSelectedFiles([]);
setError(null);
};

return (
<div>
<Button onClick={toggleModal}>Upload Files</Button>

<Modal
opened={showModal}
onClose={handleClose}
title="Select files to upload"
centered
style={{ textAlign: "center" }}
>
<div className="files">
<FileInput
multiple
accept=".mcap"
onChange={handleFileChange}
placeholder="Select files to upload"
label="Choose files"
style={{ display: 'block', margin: '0 auto' }}
/>
{selectedFiles.length > 0 && (
<div>
<h3>Chosen Files:</h3>
<ul>
{selectedFiles.map((file, index) => (
<li key={index}>{file.name}</li>
))}
</ul>
</div>
)}
</div>

<Button onClick={handleUpload} style={{ marginTop: 10 }}>Upload</Button>

{error && (
<Notification color="red" onClose={() => setError(null)} style={{ marginTop: 10 }}>
{error}
</Notification>
)}
</Modal>
</div>
);
};

export default FileUpload;
5 changes: 5 additions & 0 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "@mantine/core/styles.css";
import "@/css/Navbar.css";
import { NavLink } from "react-router-dom";
import FileUpload from "@/components/FileUpload"

const mainLinksData = [
{ name: "Files", url: "/" },
Expand All @@ -25,6 +26,10 @@ export default function Navbar() {
className="navbar-icon"
/>
{links}

{/* Once POST API is out -- Currently WIP */}
<FileUpload uploadUrl="http://localhost:8080/api/v2/mcap/upload"/>

{/* Optionally render active link or other content here */}
<h3 className="hytechName">{hytechName}</h3>
</nav>
Expand Down
8 changes: 5 additions & 3 deletions src/components/PreviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ function PreviewCard() {
gap: "10px",
}}
>
<DownloadButton buttonText="MAT" />
<DownloadButton buttonText="MCAP" />
<div className='previewFileButtons'>
<DownloadButton buttonText="MAT" />
<DownloadButton buttonText="MCAP" />
</div>
</div>
</Grid.Col>
</Grid>
Expand Down Expand Up @@ -185,7 +187,7 @@ export const SchemaTable = () => {
}}
/>

<ScrollArea style={{ height: 200, width: 250 }}> {/* Scrollable area with height limit */}
<ScrollArea style={{ height: 200, width: 250, padding: 10}}> {/* Scrollable area with height limit */}
<Table striped highlightOnHover horizontalSpacing="sm" verticalSpacing="0.01rem" withRowBorders withTableBorder withColumnBorders>
<Table.Thead>
<Table.Tr>
Expand Down
30 changes: 30 additions & 0 deletions src/css/FileUpload.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
button {
padding: 10px 10px;
margin: 3px 3px;
border: none;
border-radius: 5px;
background-color: #b39e63;
color: white;
cursor: pointer;
transition: background-color 0.3s;
}

button:hover {
background-color: #d4bc79;
}

ul {
list-style-type: none;
padding: 0;
}

h3 {
margin-top: 20px;
}

.files {
display: flex;
flex-direction: column;
text-align: center;
justify-content: center;
}
8 changes: 8 additions & 0 deletions src/css/PreviewCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@
height: auto; /* Maintains aspect ratio */
margin: 20px;
}

@media (max-width: 600px) {
.previewFileButtons {
display: flex;
flex-direction: column;

}
}
16 changes: 9 additions & 7 deletions src/css/Root.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,33 @@
background-color: #f0f0f0;
width: 100%;
position: fixed;
/*so table doesn't cover it - make sure it stays on top of other elements*/
z-index: 1000;
}

.search-bar {
background-color: #e0e0e0;
border-radius: 0;
}

.main-content {
display: flex;
flex: 1;
overflow: hidden;
height: 500px;
padding-top: 50px;
flex-direction: column;
}

.results-container {
display: flex;
flex: 1;
overflow: hidden;
flex-direction: row;
}

.table-contain-result {
flex-grow: 1;
overflow-y: auto;
padding-bottom: 10px;
}

.footer {
text-align: center;
background: #9b8b5de5;
color: white;
}

21 changes: 1 addition & 20 deletions src/css/SearchBar.css
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
.results-container {
flex: 1;
display: flex;
flex-direction: column;
outline-color: #DEE2E6;
outline-width: 2px;
outline-style: solid;
}


.table-contain-result {
text-align: center;
flex: 1;
}

.preview-contain-result {
text-align: center;
}

.Search {
display: flex;
max-width: 360px;
font-size: 15px;

overflow: auto;
}


Expand Down
58 changes: 57 additions & 1 deletion src/data/sampledata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,62 @@ export const data: MCAPFileInformation[] = [
notes: "car ran!",
event_type: "acceleration",
},
{
id: "0723984238489-21312-4e75e6f76",
mcap_file_name: "file5.3.mcap",
matlab_file_name: "file5.3.mat",
aws_bucket: "bucket",
mcap_path: "/path/to/s3/object",
mat_path: "/path/to/s3/object",
vn_lat_lon_path: "/path/to/s3/object",
velocity_plot_path: "/path/to/s3/object",
date: "08-16-2024",
location: "rome",
notes: "car performed nice",
event_type: "autocross",
},
{
id: "091823792-2321312-a081",
mcap_file_name: "file7.1.mcap",
matlab_file_name: "file7.1.mat",
aws_bucket: "bucket",
mcap_path: "/path/to/s3/object",
mat_path: "/path/to/s3/object",
vn_lat_lon_path: "/path/to/s3/object",
velocity_plot_path: "/path/to/s3/object",
date: "08-29-2024",
location: "MRDC",
notes: "car did jk turn on",
event_type: null,
},
{
id: "07a0sdjwne-597f-4637-8b61-6134e75e6f76",
mcap_file_name: "file2.3.mcap",
matlab_file_name: "file2.3.mat",
aws_bucket: "bucket",
mcap_path: "/path/to/s3/object",
mat_path: "/path/to/s3/object",
vn_lat_lon_path: "/path/to/s3/object",
velocity_plot_path: "/path/to/s3/object",
date: "08-16-2024",
location: "rome",
notes: "car did not latch",
event_type: "autocross",
},
{
id: "605deb4b-44a8-4801-9da6-a671c1d3eccd",
mcap_file_name: "file1.3.mcap",
matlab_file_name: "file1.3.mat",
aws_bucket: "bucket",
mcap_path: "/path/to/s3/object",
mat_path: "/path/to/s3/object",
vn_lat_lon_path: "/path/to/s3/object",
velocity_plot_path: "/path/to/s3/object",
date: "08-22-2024",
location: "MRDC",
notes: "car failed",
event_type: "acceleration",
},
{
id: "fb48f265-a44a-4fd5-a873-26cd581950a0",
mcap_file_name: "file2.mcap",
Expand Down Expand Up @@ -97,4 +153,4 @@ export const data: MCAPFileInformation[] = [
notes: "car did not turn on",
event_type: null,
},
];
];

0 comments on commit c739949

Please sign in to comment.