-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from microcks/v3
V3
- Loading branch information
Showing
8 changed files
with
374 additions
and
152 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
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,112 @@ | ||
import UploadIcon from '@mui/icons-material/Upload'; | ||
import Button from '@mui/material/Button'; | ||
import Checkbox from '@mui/material/Checkbox'; | ||
import Dialog from '@mui/material/Dialog'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import DialogContent from '@mui/material/DialogContent'; | ||
import DialogTitle from '@mui/material/DialogTitle'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import FormGroup from '@mui/material/FormGroup'; | ||
import TextField from '@mui/material/TextField'; | ||
import React, { useState } from 'react'; | ||
import { throwErrorAsString } from '../api/utils'; | ||
import { ExtensionConfig } from '../types/ExtensionConfig'; | ||
|
||
const ImportDialog: React.FC<{ | ||
isDialogOpen: boolean; | ||
config: ExtensionConfig; | ||
closeHandler: (refresh?: boolean) => void; | ||
}> = ({ isDialogOpen, config, closeHandler }) => { | ||
const [fileToUpload, setFileToUpload] = useState<File>(); | ||
const [isSecondary, setIsSecondary] = useState(false); | ||
|
||
const uploadFile = async (event: React.MouseEvent<HTMLElement>) => { | ||
try { | ||
const formData = new FormData(); | ||
formData.append('file', fileToUpload as File); | ||
formData.append('mainArtifact', isSecondary ? 'false' : 'true'); | ||
|
||
const response = await fetch( | ||
`http://localhost:${ | ||
8080 + config.portOffset || 8080 | ||
}/api/artifact/upload`, | ||
{ | ||
method: 'POST', | ||
body: formData, | ||
}, | ||
); | ||
|
||
if (!response.ok) { | ||
console.error(response.statusText); | ||
return; | ||
} | ||
|
||
handleClose(true); | ||
} catch (error) { | ||
throwErrorAsString(error); | ||
} | ||
}; | ||
|
||
const handleClose = (refresh?: boolean) => { | ||
setFileToUpload(undefined); | ||
setIsSecondary(false); | ||
closeHandler(refresh); | ||
}; | ||
|
||
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setFileToUpload(event.target.files?.[0]); | ||
}; | ||
|
||
const handleCheckboxChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setIsSecondary(event.target.checked); | ||
}; | ||
|
||
return ( | ||
<Dialog | ||
open={isDialogOpen} | ||
onClose={(event, reason) => handleClose()} | ||
fullWidth | ||
> | ||
<DialogTitle>Upload Artifact</DialogTitle> | ||
<DialogContent> | ||
<TextField | ||
autoFocus | ||
margin="dense" | ||
id="artifact" | ||
type="file" | ||
fullWidth | ||
onChange={handleInputChange} | ||
/> | ||
<FormGroup> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={isSecondary} | ||
onChange={handleCheckboxChange} | ||
inputProps={{ 'aria-label': 'controlled' }} | ||
/> | ||
} | ||
label="This is a secondary artifact" | ||
/> | ||
</FormGroup> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button variant="outlined" onClick={(event) => handleClose()}> | ||
Cancel | ||
</Button> | ||
<Button | ||
startIcon={<UploadIcon />} | ||
variant="contained" | ||
color="primary" | ||
size="large" | ||
onClick={uploadFile} | ||
disabled={fileToUpload === undefined} | ||
> | ||
Import | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default ImportDialog; |
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.