Skip to content

Commit

Permalink
show label in progress bar when uploading files
Browse files Browse the repository at this point in the history
  • Loading branch information
SteRiccio committed Sep 4, 2024
1 parent e1aadd2 commit 4f2db61
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/i18n/resources/en/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ Do you want to proceed?`,
undefinedName: 'Undefined name',
unique: 'Unique',
upload: 'Upload',
uploadingFile: 'Uploading file ({{progressPercent}}%)',
view: 'View',
warning: 'Warning',
warning_plural: 'Warnings',
Expand Down
16 changes: 12 additions & 4 deletions webapp/components/progressBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,40 @@ import classNames from 'classnames'
import PropTypes from 'prop-types'
import { LinearProgress } from '@mui/material'

import { useI18n } from '@webapp/store/system'

const ProgressBarWithLabel = (props) => {
const { className, color, value } = props
const { className, color, textKey = null, value } = props

const i18n = useI18n()
const progressPercent = Math.floor(value)
const text = textKey ? i18n.t(textKey, { progressPercent }) : `${progressPercent}%`

return (
<div className={classNames('progress-bar-with-label', className)}>
<LinearProgress className={className} color={color} value={value} variant="determinate" />
<span>{Math.floor(value)}%</span>
<span>{text}</span>
</div>
)
}

ProgressBarWithLabel.propTypes = {
className: PropTypes.string,
color: PropTypes.oneOf(['primary', 'secondary', 'error', 'info', 'success', 'warning', 'inherit']),
textKey: PropTypes.string,
value: PropTypes.number,
}

const ProgressBar = (props) => {
const { className: classNameProp, color, indeterminate = true, progress = 0, showText = true } = props
const { className: classNameProp, color, indeterminate = true, progress = 0, showText = true, textKey = null } = props

const className = classNames('progress-bar', classNameProp)

if (indeterminate) {
return <LinearProgress className={className} color={color} />
}
if (showText) {
return <ProgressBarWithLabel className={className} color={color} value={progress} />
return <ProgressBarWithLabel className={className} color={color} textKey={textKey} value={progress} />
}
return <LinearProgress className={className} color={color} variant="determinate" value={progress} />
}
Expand All @@ -42,6 +49,7 @@ ProgressBar.propTypes = {
indeterminate: PropTypes.bool,
progress: PropTypes.number,
showText: PropTypes.bool,
textKey: PropTypes.string,
}

export default ProgressBar
6 changes: 3 additions & 3 deletions webapp/components/survey/SurveyCreate/SurveyCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import { RecordCycle } from '@core/record/recordCycle'

import { appModuleUri, homeModules } from '@webapp/app/appModules'

import { contentTypes } from '@webapp/service/api'
import { useI18n } from '@webapp/store/system'
import { useSurveyInfo } from '@webapp/store/survey'
import { useUserIsSystemAdmin } from '@webapp/store/user'
import { TestId } from '@webapp/utils/testId'
import { contentTypes } from '@webapp/service/api'

import ButtonGroup from '@webapp/components/form/buttonGroup'
import { FormItem, Input } from '@webapp/components/form/Input'
Expand All @@ -27,7 +28,6 @@ import { Button, Dropzone, ProgressBar, RadioButtonGroup } from '@webapp/compone

import { createTypes, importSources, useCreateSurvey } from './store'
import { SurveyDropdown } from '../SurveyDropdown'
import { useUserIsSystemAdmin } from '@webapp/store/user'

const fileMaxSizeDefault = 1000 // 1GB
const fileMaxSizeSystemAdmin = 2000 // 2GB
Expand Down Expand Up @@ -170,7 +170,7 @@ const SurveyCreate = (props) => {
<>
{uploading && uploadProgressPercent >= 0 ? (
<div className="row">
<ProgressBar indeterminate={false} progress={uploadProgressPercent} />
<ProgressBar indeterminate={false} progress={uploadProgressPercent} textKey="common.uploadingFile" />
</div>
) : (
<>
Expand Down
4 changes: 4 additions & 0 deletions webapp/components/survey/SurveyCreate/SurveyCreate.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@
.cycle-dropdown {
width: 10rem;
}

.progress-bar-with-label {
flex-direction: column;
}
}
2 changes: 1 addition & 1 deletion webapp/views/App/FileUploadDialog/FileUploadDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const FileUploadDialog = () => {
<ModalBody>
<Dropzone accept={accept} maxSize={maxSize} onDrop={onFilesDrop} droppedFiles={files} />
{uploading && uploadProgressPercent >= 0 && (
<ProgressBar indeterminate={false} progress={uploadProgressPercent} />
<ProgressBar indeterminate={false} progress={uploadProgressPercent} textKey="common.uploadingFile" />
)}
</ModalBody>
<ModalFooter>
Expand Down
4 changes: 4 additions & 0 deletions webapp/views/App/FileUploadDialog/FileUploadDialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
.dropzone {
height: 15rem;
}

.progress-bar-with-label {
flex-direction: column;
}
}

0 comments on commit 4f2db61

Please sign in to comment.