forked from veraPDF/verapdf-webapp-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
veraPDF#25: Implemented option for conditional settings
- Loading branch information
Igor Poplavsky
committed
May 28, 2020
1 parent
dd8114e
commit c9c688f
Showing
12 changed files
with
252 additions
and
58 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 |
---|---|---|
@@ -1,40 +1,131 @@ | ||
import React, { useMemo } from 'react'; | ||
import React, { useMemo, useState, useCallback } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { hasFilesAttached } from '../../../../store/pdfFiles/selectors'; | ||
import { connect } from 'react-redux'; | ||
import { Redirect } from 'react-router-dom'; | ||
|
||
import AppPages from '../../../AppPages'; | ||
import { toggleUseSettings } from '../../../../store/application/actions'; | ||
import { resetProfile } from '../../../../store/job/settings/actions'; | ||
import { validate } from '../../../../store/job/actions'; | ||
import { hasFilesAttached } from '../../../../store/pdfFiles/selectors'; | ||
import { getUseSettings } from '../../../../store/application/selectors'; | ||
import { getJobId } from '../../../../store/job/selectors'; | ||
import { getProfile } from '../../../../store/job/settings/selectors'; | ||
import { getDefaultProfileName } from '../../../../store/validationProfiles/selectors'; | ||
import Dropzone from './dropzone/Dropzone'; | ||
import Stepper from '../../../shared/stepper/Stepper'; | ||
import PageNavigation from '../../../shared/pageNavigation/PageNavigation'; | ||
import Dropzone from './dropzone/Dropzone'; | ||
import Checkbox from '../../../shared/checkbox/Checkbox'; | ||
import Dialog from '../../../shared/dialog/Dialog'; | ||
|
||
function Upload(props) { | ||
const { filesAttached } = props; | ||
const forwardButton = useMemo( | ||
() => ({ | ||
label: 'Configure job', | ||
to: AppPages.SETTINGS, | ||
disabled: !filesAttached, | ||
}), | ||
[filesAttached] | ||
); | ||
const CHECK_SETTINGS = 'Use custom validation settings'; | ||
|
||
function Upload({ | ||
filesAttached, | ||
useSettings, | ||
toggleSettings, | ||
jobId, | ||
profile, | ||
defaultProfile, | ||
resetProfile, | ||
onValidateClick, | ||
}) { | ||
const [resetSettingsDialogOpened, setResetSettingsDialogOpened] = useState(false); | ||
const forwardButton = useMemo(() => { | ||
const button = { disabled: !filesAttached }; | ||
if (useSettings) { | ||
return { | ||
...button, | ||
label: 'Configure job', | ||
to: AppPages.SETTINGS, | ||
}; | ||
} | ||
return { | ||
...button, | ||
label: 'Validate', | ||
onClick: onValidateClick, | ||
}; | ||
}, [filesAttached, onValidateClick, useSettings]); | ||
const onSettingsToggle = useCallback(() => { | ||
if (profile !== defaultProfile && useSettings) { | ||
return setResetSettingsDialogOpened(true); | ||
} | ||
return toggleSettings(); | ||
}, [defaultProfile, profile, toggleSettings, useSettings]); | ||
const onResetSettingsClose = useCallback(() => { | ||
setResetSettingsDialogOpened(false); | ||
}, []); | ||
const dialogActions = [ | ||
{ | ||
label: 'Cancel', | ||
color: 'primary', | ||
align: 'start', | ||
onClick: onResetSettingsClose, | ||
}, | ||
{ | ||
label: 'Reset settings', | ||
color: 'primary', | ||
variant: 'contained', | ||
onClick: () => { | ||
resetProfile(); | ||
toggleSettings(); | ||
onResetSettingsClose(); | ||
}, | ||
}, | ||
]; | ||
|
||
if (!useSettings && jobId) { | ||
// Once job is initialized and we know its ID redirect to status page to track its progress | ||
return <Redirect push to={AppPages.STATUS.url(jobId)} />; | ||
} | ||
|
||
return ( | ||
<section className="upload"> | ||
<Stepper activeStep={AppPages.UPLOAD} /> | ||
<Dropzone /> | ||
<PageNavigation forward={forwardButton} /> | ||
<PageNavigation | ||
back={<Checkbox checked={useSettings} label={CHECK_SETTINGS} onChange={onSettingsToggle} />} | ||
forward={forwardButton} | ||
/> | ||
<Dialog | ||
onClose={onResetSettingsClose} | ||
open={resetSettingsDialogOpened} | ||
actions={dialogActions} | ||
title={`You are about to reset profile to default ${defaultProfile}.`} | ||
> | ||
Proceed? | ||
</Dialog> | ||
</section> | ||
); | ||
} | ||
|
||
Upload.propTypes = { | ||
jobId: PropTypes.string, | ||
profile: PropTypes.string, | ||
defaultProfile: PropTypes.string, | ||
useSettings: PropTypes.bool.isRequired, | ||
filesAttached: PropTypes.bool.isRequired, | ||
toggleSettings: PropTypes.func.isRequired, | ||
onValidateClick: PropTypes.func.isRequired, | ||
resetProfile: PropTypes.func.isRequired, | ||
}; | ||
|
||
const mapStateToProps = state => { | ||
return { | ||
filesAttached: hasFilesAttached(state), | ||
useSettings: getUseSettings(state), | ||
jobId: getJobId(state), | ||
profile: getProfile(state), | ||
defaultProfile: getDefaultProfileName(state), | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = dispatch => { | ||
return { | ||
toggleSettings: () => dispatch(toggleUseSettings()), | ||
onValidateClick: () => dispatch(validate()), | ||
resetProfile: () => dispatch(resetProfile()), | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps)(Upload); | ||
export default connect(mapStateToProps, mapDispatchToProps)(Upload); |
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 |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
|
||
&__container { | ||
width: 70%; | ||
max-width: 700px; | ||
height: 100px; | ||
margin: auto; | ||
padding: 20px; | ||
|
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,32 @@ | ||
import React, { useCallback } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import MaterialCheckbox from '@material-ui/core/Checkbox'; | ||
import FormControlLabel from '@material-ui/core/FormControlLabel'; | ||
|
||
function Checkbox({ checked, label, disabled, onChange }) { | ||
const handleChange = useCallback(e => onChange(e.target.value), [onChange]); | ||
|
||
return ( | ||
<FormControlLabel | ||
className="checkbox-container" | ||
disabled={disabled} | ||
label={label} | ||
control={<MaterialCheckbox checked={checked} color="primary" onChange={handleChange} />} | ||
/> | ||
); | ||
} | ||
|
||
Checkbox.propTypes = { | ||
checked: PropTypes.bool.isRequired, | ||
label: PropTypes.string, | ||
disabled: PropTypes.bool, | ||
onChange: PropTypes.func.isRequired, | ||
}; | ||
|
||
Checkbox.defaultProps = { | ||
label: '', | ||
disabled: false, | ||
}; | ||
|
||
export default Checkbox; |
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,9 @@ | ||
.dialog { | ||
&__action { | ||
|
||
._start { | ||
flex: 1; | ||
justify-content: flex-start; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
flex-grow: 1; | ||
flex-basis: 0; | ||
justify-content: center; | ||
align-items: start; | ||
|
||
.app-link { | ||
color: inherit; | ||
|
Oops, something went wrong.