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

fixed table sizing with length of notes #68

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_API_URL=https://api-url:port
VITE_API_URL=https://hytechracing.duckdns.org
jyuenbeep marked this conversation as resolved.
Show resolved Hide resolved

31 changes: 18 additions & 13 deletions package-lock.json

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

45 changes: 45 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import "@mantine/core/styles.css";
import { MantineProvider } from "@mantine/core";
import { theme } from "@/theme";
import { data } from "@/data/sampledata";
import { useState } from "react";
import Navbar from "@/components/Navbar";
import SearchBar from "@/components/SearchBar";
import "@/css/App.css";
import DataTable from "@/components/DataTable";
import PreviewCard from "@/components/PreviewCard";

export default function App() {
const [filteredData, setFilteredData] = useState<MCAPFileInformation[]>(data);

return (
<MantineProvider theme={theme}>
<div className="app-container">
<header className="navbar">
<Navbar />
</header>

<div className="main-content static">
<div className="results-container">

<div className="table-contain-result scrollable-container">
<div className="scrollable">
<DataTable data={filteredData} />
</div>
</div>

<div className="search-container scrollable">
<SearchBar setFilteredData={setFilteredData}/>
</div>

</div>
<div className="preview-contain-result">
<PreviewCard />
</div>
</div>
</div>

{/* <PreviewCard /> */}
</MantineProvider>
);
}
40 changes: 32 additions & 8 deletions src/components/DataTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Table } from "@mantine/core";
import { useMantineTheme } from "@mantine/core";
import { Input, Textarea } from "@mantine/core";

interface DataTableProps {
data?: MCAPFileInformation[];
Expand All @@ -17,7 +18,7 @@ export default function DataTable({
setSelectedData,
}: DataTableProps) {
const theme = useMantineTheme();

const setPreviewData = (file: MCAPFileInformation) => {
if (selectedRow === file.id) {
setSelectedRow("");
Expand All @@ -30,8 +31,10 @@ export default function DataTable({

// Take out when API server team implements filename id in their get route
const getFileNameWithoutExtension = (fileNameWithExtension: string) => {
const lastDotIndex = fileNameWithExtension.lastIndexOf('.');
return lastDotIndex !== -1 ? fileNameWithExtension.slice(0, lastDotIndex) : fileNameWithExtension;
const lastDotIndex = fileNameWithExtension.lastIndexOf(".");
return lastDotIndex !== -1
? fileNameWithExtension.slice(0, lastDotIndex)
: fileNameWithExtension;
};

const rows = !data ? (
Expand All @@ -51,20 +54,41 @@ export default function DataTable({
<Table.Tr
key={file.id}
onClick={() => setPreviewData(file)}

bg={selectedRow === file.id ? theme.primaryColor : ""}
>
<Table.Td>{getFileNameWithoutExtension(file.mcap_files[0].file_name)}</Table.Td>
<Table.Td>
{getFileNameWithoutExtension(file.mcap_files[0].file_name)}
</Table.Td>
<Table.Td>{file.date}</Table.Td>
<Table.Td>{file.location}</Table.Td>

{/* Change back to notes once notes field is implemented in the server */}
<Table.Td>{file.car_model}</Table.Td>
{/* <Table.Td>{file.car_model}</Table.Td> */}
<Table.Td>
<Input.Wrapper>
<Textarea
variant="unstyled"
value="
testing long text text text text text text text text text text text text text text text text text text text text text text"
// now with four rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows"
// now with four rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows"
// now with four rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows rows"
style={{ whiteSpace: "normal", wordWrap: "break-word" }}
readOnly
placeholder="Note"
rows={4}
/>
</Input.Wrapper>
</Table.Td>
</Table.Tr>
))
);
return (
<Table.ScrollContainer h="100%" minWidth={800} style={{ overflowY: 'auto' }}>
<Table.ScrollContainer
h="100%"
minWidth={800}
style={{ overflowY: "auto" }}
>
<Table
stickyHeader
highlightOnHover={data && data.length > 0}
Expand Down
47 changes: 37 additions & 10 deletions src/components/FileUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { Modal, Button, Notification, FileInput } from '@mantine/core';
import '@/css/FileUpload.css';
import React, { useState } from "react";
import { Modal, Button, Notification, FileInput } from "@mantine/core";
import "@/css/FileUpload.css";

interface FileUploadProps {
uploadUrl: string;
Expand All @@ -22,6 +22,24 @@ const FileUpload: React.FC<FileUploadProps> = ({ uploadUrl }) => {
setError(null);
setSuccess(null)
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);
try {
const formData = new FormData();
selectedFiles.forEach(file => {
Expand Down Expand Up @@ -54,11 +72,12 @@ const FileUpload: React.FC<FileUploadProps> = ({ uploadUrl }) => {

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

Expand All @@ -82,7 +101,7 @@ const FileUpload: React.FC<FileUploadProps> = ({ uploadUrl }) => {
onClose={handleClose}
title="Select files to upload"
centered
style={{ textAlign: "center" }}
style={{ textAlign: "center" }}
>
<div className="files">
<FileInput
Expand All @@ -91,7 +110,7 @@ const FileUpload: React.FC<FileUploadProps> = ({ uploadUrl }) => {
onChange={handleFileChange}
placeholder="Select files to upload"
label="Choose files"
style={{ display: 'block', margin: '0 auto' }}
style={{ display: "block", margin: "0 auto" }}
/>
{selectedFiles.length > 0 && (
<div>
Expand All @@ -105,14 +124,22 @@ const FileUpload: React.FC<FileUploadProps> = ({ uploadUrl }) => {
)}
</div>

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

<Button onClick={handleUpload} style={{ marginTop: 10 }}>Upload</Button>
{success && (
<Notification color="green" onClose={() => setSuccess(null)} style={{ marginTop: 10 }}>
{success}
</Notification>
)}
{error && (
<Notification color="red" onClose={() => setError(null)} style={{ marginTop: 10 }}>
<Notification
color="red"
onClose={() => setError(null)}
style={{ marginTop: 10 }}
>
{error}
</Notification>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@mantine/core/styles.css";
import "@/css/Navbar.css";
import { NavLink } from "react-router-dom";
import FileUpload from "@/components/FileUpload"
import FileUpload from "@/components/FileUpload";

const mainLinksData = [
{ name: "Files", url: "/" },
Expand All @@ -27,6 +27,7 @@ export default function Navbar() {
/>
{links}

{/* Once POST API is out -- Currently WIP */}
<FileUpload uploadUrl={`${import.meta.env.VITE_API_URL}/api/v2/mcaps/bulk_upload`}/>

{/* Optionally render active link or other content here */}
Expand Down
57 changes: 57 additions & 0 deletions src/components/PreviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,63 @@ function PreviewCard({ selectedData }: PreviewCardProps) {
<SchemaTable></SchemaTable>
</Grid.Col>
<Grid.Col span={3} style={{ position: "relative", padding: "10px" }}>
<div style={{ display: "flex", alignItems: "center" }}>
<Text size="md" fw={700}>
run 2024-18-10.mcap
</Text>
</div>
<div style={{ display: "flex", alignItems: "center" }}>
<Text size="xs" fw={700}>
Date:{" "}
</Text>
<span style={{ marginLeft: "5px" }} /> {/* Spacer */}
<Text size="xs" fw={400}>
Fri, Oct 18, 2024
</Text>
</div>
<div style={{ display: "flex", alignItems: "center" }}>
<Text size="xs" fw={700}>
Time:{" "}
</Text>
<span style={{ marginLeft: "5px" }} /> {/* Spacer */}
<Text size="xs" fw={400}>
12:24:02 PM
</Text>
</div>
<div style={{ display: "flex", alignItems: "center" }}>
<Text size="xs" fw={700}>
Location:{" "}
</Text>
<span style={{ marginLeft: "5px" }} /> {/* Spacer */}
<Text size="xs" fw={400}>
MRDC
</Text>
</div>
<div style={{ display: "flex", alignItems: "center" }}>
<Text size="xs" fw={700}>
Sensors:{" "}
</Text>
<span style={{ marginLeft: "5px" }} /> {/* Spacer */}
<Text size="xs" fw={400}>
aero_sensor_1
</Text>
</div>
<div
style={{
display: "flex",
alignItems: "center",
position: "absolute",
bottom: 0,
left: 0,
padding: 20,
gap: "10px",
}}
>
<div className="previewFileButtons">
<DownloadButton buttonText="MAT" />
<DownloadButton buttonText="MCAP" />
</div>
</div>
{selectedData ? (
<>
<PreviewDataDiv name={getFileNameWithoutExtension(selectedData.mcap_files[0].file_name)} val={""} />
Expand Down
Loading