-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into route-connection
- Loading branch information
Showing
14 changed files
with
328 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Build on Pull Request | ||
|
||
on: | ||
pull_request: | ||
branches: ['main'] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20' # Use the Node.js version you're working with | ||
cache: 'npm' # Use the Node.js version you're working with | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Build | ||
run: npm run build |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { useState } from "react"; | ||
import { Autocomplete, Button } from "@mantine/core"; | ||
import "@/css/SchemaSearch.css"; | ||
|
||
interface SchemaSearch { | ||
schemas: string[]; | ||
} | ||
|
||
const SchemaSearch: React.FC<SchemaSearch> = ({ schemas }) => { | ||
const [value, setValue] = useState<string>(""); | ||
const [selectedSchema, setSelected] = useState<string[]>([]); | ||
|
||
const filteredSchemas = schemas.filter((schema) => | ||
schema.toLowerCase().includes(value.toLowerCase()), | ||
); | ||
|
||
const addSchema = (newSchema: string) => { | ||
if (!selectedSchema.includes(newSchema)) { | ||
setSelected([...selectedSchema, newSchema]); | ||
} else { | ||
alert("Schema already selected!"); | ||
} | ||
}; | ||
|
||
const clearSchema = () => { | ||
setSelected([]); | ||
}; | ||
|
||
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (event.key === "Enter" && filteredSchemas.length > 0) { | ||
setValue(filteredSchemas[0]); | ||
addSchema(filteredSchemas[0]); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Autocomplete | ||
label="Search by Schema" | ||
placeholder="Start typing a schema name" | ||
data={filteredSchemas} | ||
value={value} | ||
onChange={setValue} | ||
onKeyDown={handleKeyDown} | ||
/> | ||
<br /> | ||
{selectedSchema.length > 0 && ( | ||
<div> | ||
<label>Selected Schema</label> | ||
<ul> | ||
{selectedSchema.map((str, index) => ( | ||
<li key={index}>{str}</li> | ||
))} | ||
</ul> | ||
<Button className="cancel-button" onClick={clearSchema}> | ||
Cancel | ||
</Button> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SchemaSearch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.