-
Notifications
You must be signed in to change notification settings - Fork 3
Throbber and data upload #355
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
Open
NXXR
wants to merge
20
commits into
develop
Choose a base branch
from
feature/throbbers-and-data-upload
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+327
−25
Open
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
48348cc
add drag & drop function
NXXR d89c651
add file list
NXXR 56a955c
🔼add ldrs for throbbers
NXXR cc9bd82
:wrench: Change throbber and add color to props
NXXR 53724c7
:sparkles: Add new Throbber to App suspense
NXXR a94344b
🔧Use Throbber for started uploads
NXXR fa20bcb
🔧 disable login & upload menu items
NXXR f14089d
✨Run Formatter & Linter
NXXR 580f7bb
Merge branch 'develop' into feature/throbbers-and-data-upload
NXXR 6101891
✨remove logs & fix comments
NXXR 6cd7231
Merge remote-tracking branch 'origin/develop' into feature/throbbers-…
NXXR 79d9af7
add german translations
NXXR 3d113a3
add endpoint calls to send files
NXXR 31915e9
remove unused state
NXXR 0421ecf
Apply suggestions from code review
NXXR 654e1f2
separate imports
NXXR 4f07e84
fix imports and variable naming
NXXR 939c5eb
Merge remote-tracking branch 'origin/develop' into feature/throbbers-…
NXXR 096fd64
run formatter
NXXR 3c1848a
activate authorization token for utilsApi
NXXR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,182 @@ | ||
| // SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR) | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import React, {useCallback, useEffect} from 'react'; | ||
| import {useTheme} from '@mui/material/styles'; | ||
| import Box from '@mui/material/Box'; | ||
| import Typography from '@mui/material/Typography'; | ||
| import {useTranslation} from 'react-i18next'; | ||
| import {Button, List, ListItem, ListItemText} from '@mui/material'; | ||
| import {Clear, CloudUpload, Done} from '@mui/icons-material'; | ||
| import {helix} from 'ldrs'; | ||
| import {useSendCasedataFileQuery} from 'store/services/utilsApi'; | ||
|
|
||
| /** | ||
| * This component displays the accessibility legal text. | ||
| */ | ||
| export default function DataUploadDialog(): JSX.Element { | ||
| const {t} = useTranslation(); | ||
| const theme = useTheme(); | ||
| const [dragActive, setDragActive] = React.useState(false); | ||
|
|
||
| // Register throbber for later use. | ||
| useEffect(() => { | ||
| helix.register(); | ||
| }, []); | ||
|
|
||
| const [uploadList, setUploadList] = React.useState<{fileinfo: string; file: File}[]>([]); | ||
|
|
||
| const fileTypes: string[] = []; | ||
|
|
||
| // Function to handle data upload. | ||
| const handleFiles = useCallback((filelist: FileList) => { | ||
|
NXXR marked this conversation as resolved.
Outdated
|
||
| // Function to increase readability of file size appended behind filename. | ||
| const fileSizeToString = (size: number) => { | ||
| if (size < 1024) { | ||
| return `${size} B`; | ||
| } else if (size >= 1024 && size < 1048576) { | ||
| return `${(size / 1024).toFixed(1)} KB`; | ||
| } else { | ||
| return `${(size / 1048576).toFixed(1)} MB`; | ||
| } | ||
| }; | ||
| // Update file display with new files. | ||
| const displaylist: {fileinfo: string; file: File}[] = []; | ||
| for (let i = 0; i < filelist.length; i++) { | ||
| const file = filelist[i]; | ||
|
|
||
| displaylist.push({ | ||
| fileinfo: `${file.name} (${fileSizeToString(file.size)})`, | ||
| file: file, | ||
| }); | ||
| } | ||
| setUploadList(displaylist); | ||
| }, []); | ||
|
NXXR marked this conversation as resolved.
Outdated
|
||
|
|
||
| // Callback for drag event (to modify styling). | ||
| const handleDrag = useCallback((e: React.DragEvent) => { | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| if (e.type === 'dragenter' || e.type === 'dragover') { | ||
| setDragActive(true); | ||
| } else if (e.type === 'dragleave') { | ||
| setDragActive(false); | ||
| } | ||
| }, []); | ||
|
|
||
| // Callback for files selected through drag & drop. | ||
| const handleDrop = useCallback( | ||
| (e: React.DragEvent) => { | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| setDragActive(false); | ||
| if (e.dataTransfer.files && e.dataTransfer.files[0]) { | ||
| handleFiles(e.dataTransfer.files); | ||
| } | ||
| }, | ||
| [handleFiles] | ||
| ); | ||
|
|
||
| // Callback for files selected through dialog. | ||
| const handleClick = useCallback( | ||
| (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| e.preventDefault(); | ||
| if (e.target.files && e.target.files[0]) { | ||
| handleFiles(e.target.files); | ||
| } | ||
| }, | ||
| [handleFiles] | ||
| ); | ||
|
|
||
| return ( | ||
| <form id='upload-form' onDragEnter={handleDrag} onDragLeave={handleDrag} onSubmit={(e) => e.preventDefault()}> | ||
| <input type='file' id='upload-input' multiple={true} accept={fileTypes.join(',')} onChange={handleClick} hidden /> | ||
| <Box | ||
| sx={{ | ||
| margin: theme.spacing(4), | ||
| padding: theme.spacing(4), | ||
| minHeight: '30vw', | ||
| background: theme.palette.background.paper, | ||
| border: `${theme.palette.divider} ${dragActive ? 'solid' : 'dashed'} 2px`, | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| justifyContent: 'space-around', | ||
| alignItems: 'center', | ||
| }} | ||
| > | ||
| <Typography variant='h1'>{t('upload.header')}</Typography> | ||
| <div>{t('upload.dragNotice')}</div> | ||
| {uploadList.length > 0 && ( | ||
| <List> | ||
| {uploadList.map((item) => ( | ||
| // Create a list item for each file. | ||
| <FileItem key={item.fileinfo} fileinfo={item.fileinfo} file={item.file} /> | ||
| ))} | ||
| </List> | ||
| )} | ||
| <label htmlFor='upload-input'> | ||
| <Button variant='contained' startIcon={<CloudUpload />} component='span'> | ||
| {t('upload.button')} | ||
| </Button> | ||
| </label> | ||
| </Box> | ||
| {dragActive && ( | ||
| // Add an overlay on top of the popup to display a notice and make handling the drag events smoother. | ||
| <div | ||
| id='upload-drop-notice' | ||
| onDragEnter={handleDrag} | ||
| onDragLeave={handleDrag} | ||
| onDragOver={handleDrag} | ||
| onDrop={handleDrop} | ||
| style={{ | ||
| position: 'absolute', | ||
| width: '100%', | ||
| height: '100%', | ||
| top: 0, | ||
| left: 0, | ||
| bottom: 0, | ||
| right: 0, | ||
| background: 'rgba(255, 255, 255, 0.6)', | ||
| display: 'flex', | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
| }} | ||
| > | ||
| <Typography | ||
| variant='h1' | ||
| sx={{ | ||
| background: 'white', | ||
| border: `solid ${theme.palette.divider} 1px`, | ||
| borderRadius: '1em', | ||
| padding: '1em', | ||
| }} | ||
| > | ||
| {t('upload.dropNotice')} | ||
| </Typography> | ||
| </div> | ||
| )} | ||
| </form> | ||
| ); | ||
| } | ||
|
|
||
| function FileItem({fileinfo, file}: {fileinfo: string; file: File}): JSX.Element { | ||
|
NXXR marked this conversation as resolved.
Outdated
|
||
| const theme = useTheme(); | ||
| const {isSuccess, isError} = useSendCasedataFileQuery(file); | ||
|
|
||
| return ( | ||
| <ListItem | ||
| disableGutters | ||
| secondaryAction={ | ||
| isSuccess ? ( | ||
| <Done sx={{color: theme.palette.primary.main, fontSize: 45}} /> | ||
| ) : isError ? ( | ||
| <Clear sx={{color: theme.palette.error.main, fontSize: 45}} /> | ||
| ) : ( | ||
| <l-helix size={45} speed={2.5} color={theme.palette.divider}></l-helix> | ||
| ) | ||
| } | ||
| > | ||
| <ListItemText primary={fileinfo} /> | ||
|
NXXR marked this conversation as resolved.
Outdated
|
||
| </ListItem> | ||
| ); | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.