-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): Add upload protocol warning modal (#1988)
closes #1032
- Loading branch information
Showing
13 changed files
with
194 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// @flow | ||
import React from 'react' | ||
import {connect} from 'react-redux' | ||
import {goBack} from 'react-router-redux' | ||
import {AlertModal} from '@opentrons/components' | ||
|
||
import { | ||
actions as robotActions | ||
} from '../../robot' | ||
|
||
type Props = { | ||
cancelUpload: () => mixed, | ||
confirmUpload: () => mixed, | ||
} | ||
|
||
export default connect(null, mapDTP)(ConfirmUploadModal) | ||
|
||
function ConfirmUploadModal (props: Props) { | ||
return ( | ||
<AlertModal | ||
heading={'Are you sure you want to open a new protocol?'} | ||
buttons={[ | ||
{children: 'cancel', onClick: props.cancelUpload}, | ||
{children: 'continue', onClick: props.confirmUpload} | ||
]} | ||
alertOverlay | ||
> | ||
Doing so will close your current protocol and clear any unsaved calibration progress. | ||
</AlertModal> | ||
) | ||
} | ||
|
||
function mapDTP (dispatch) { | ||
return { | ||
cancelUpload: () => dispatch(goBack()), | ||
confirmUpload: () => dispatch(robotActions.clearSession()) | ||
} | ||
} |
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,61 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import UploadInput from './UploadInput' | ||
|
||
type Props = { | ||
sessionLoaded: ?boolean, | ||
createSession: (file: File) => mixed, | ||
confirmUpload: () => mixed, | ||
} | ||
|
||
type State = { | ||
uploadedFile: ?File, | ||
} | ||
|
||
export default class Upload extends React.Component<Props, State> { | ||
constructor (props: Props) { | ||
super(props) | ||
this.state = { | ||
uploadedFile: null | ||
} | ||
} | ||
|
||
onUpload = ( | ||
event: SyntheticInputEvent<HTMLInputElement> | SyntheticDragEvent<*> | ||
) => { | ||
let files: Array<File> = [] | ||
if (event.dataTransfer && event.dataTransfer.files) { | ||
files = (event.dataTransfer.files: any) | ||
} else if (event.target.files) { | ||
files = (event.target.files: any) | ||
} | ||
|
||
if (this.props.sessionLoaded) { | ||
this.setState({uploadedFile: files[0]}) | ||
this.props.confirmUpload() | ||
} else { | ||
this.props.createSession(files[0]) | ||
} | ||
|
||
// $FlowFixMe | ||
event.target.value = null | ||
} | ||
|
||
// TODO (ka 2018-7-30): refactor to consider edge case where robot disconnects while on upload page | ||
componentDidUpdate () { | ||
const {uploadedFile} = this.state | ||
if (uploadedFile && !this.props.sessionLoaded) { | ||
this.props.createSession(uploadedFile) | ||
this.setState({uploadedFile: null}) | ||
} | ||
} | ||
|
||
render () { | ||
return ( | ||
<React.Fragment> | ||
<UploadInput onUpload={this.onUpload} isButton /> | ||
<UploadInput onUpload={this.onUpload} /> | ||
</React.Fragment> | ||
) | ||
} | ||
} |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,41 @@ | ||
// @flow | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import {connect} from 'react-redux' | ||
import {push} from 'react-router-redux' | ||
|
||
import { | ||
actions as robotActions, | ||
selectors as robotSelectors | ||
} from '../../robot' | ||
|
||
import {SidePanel} from '@opentrons/components' | ||
import UploadInput from './UploadInput' | ||
import UploadWarning from './UploadWarning' | ||
import Upload from './Upload' | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(UploadPanel) | ||
|
||
UploadPanel.propTypes = { | ||
isSessionLoaded: PropTypes.bool.isRequired, | ||
onUpload: PropTypes.func.isRequired | ||
type Props = { | ||
sessionLoaded: ?boolean, | ||
confirmUpload: () => mixed, | ||
createSession: () => mixed, | ||
} | ||
|
||
function UploadPanel (props) { | ||
const warning = props.isSessionLoaded && (<UploadWarning />) | ||
export default connect(mapStateToProps, mapDispatchToProps)(UploadPanel) | ||
|
||
function UploadPanel (props: Props) { | ||
return ( | ||
<SidePanel title='Open Protocol'> | ||
<div> | ||
<UploadInput {...props} isButton /> | ||
<UploadInput {...props} /> | ||
{warning} | ||
</div> | ||
<Upload {...props} /> | ||
</SidePanel> | ||
) | ||
} | ||
|
||
function mapStateToProps (state) { | ||
return { | ||
isSessionLoaded: robotSelectors.getSessionIsLoaded(state) | ||
sessionLoaded: robotSelectors.getSessionIsLoaded(state) | ||
} | ||
} | ||
|
||
function mapDispatchToProps (dispatch) { | ||
return { | ||
onUpload: (event) => { | ||
let files | ||
|
||
if (event.dataTransfer) { | ||
files = event.dataTransfer.files | ||
} else { | ||
files = event.target.files | ||
} | ||
|
||
dispatch(robotActions.session(files[0])) | ||
|
||
// reset the state of the input to allow file re-uploads | ||
event.target.value = null | ||
} | ||
confirmUpload: () => dispatch(push('/upload/confirm')), | ||
createSession: (file) => dispatch(robotActions.session(file)) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
// @flow | ||
import React from 'react' | ||
|
||
import {Route, type Match} from 'react-router' | ||
import UploadStatus from '../components/UploadStatus' | ||
import UploadAlert from '../components/UploadAlert' | ||
import Page from '../components/Page' | ||
|
||
export default function UploadPage () { | ||
type Props = { | ||
match: Match | ||
} | ||
|
||
export default function UploadPage (props: Props) { | ||
const {match: {path}} = props | ||
return ( | ||
<Page> | ||
<UploadStatus /> | ||
<Route exact path={`${path}/confirm`} component={UploadAlert} /> | ||
</Page> | ||
) | ||
} |
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
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