-
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 open a new file warning modal and guards
closes #1032
- Loading branch information
Showing
4 changed files
with
104 additions
and
25 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import UploadInput from './UploadInput' | ||
|
||
type Props = { | ||
sessionLoaded: boolean, | ||
createSession: (file: File) => void, | ||
confirmUpload: () => void, | ||
} | ||
|
||
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 (files.length < 1) { | ||
return | ||
} | ||
|
||
if (!this.props.sessionLoaded) { | ||
return this.props.createSession(files[0]) | ||
} | ||
|
||
this.setState({uploadedFile: files[0]}) | ||
return this.props.confirmUpload() | ||
} | ||
|
||
// 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 ( | ||
<div> | ||
<UploadInput onUpload={this.onUpload} isButton /> | ||
<UploadInput onUpload={this.onUpload}/> | ||
</div> | ||
) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,29 @@ | ||
import React from 'react' | ||
import {Route} from 'react-router' | ||
|
||
import {AlertModal} from '@opentrons/components' | ||
import UploadStatus from '../components/UploadStatus' | ||
import Page from '../components/Page' | ||
|
||
export default function UploadPage () { | ||
return ( | ||
<Page> | ||
<UploadStatus /> | ||
<Route path='/upload/cancel' component={ConfirmUploadModal} /> | ||
</Page> | ||
) | ||
} | ||
|
||
function ConfirmUploadModal () { | ||
return ( | ||
<AlertModal | ||
heading={'Are you sure you want to open a new protocol?'} | ||
buttons={[ | ||
{children: 'cancel', onClick: () => console.log('cancel upload')}, | ||
{children: 'continue', onClick: () => console.log('continue upload')} | ||
]} | ||
> | ||
Doing so will close your current protocol and clear any unsaved calibration progress. | ||
</AlertModal> | ||
) | ||
} |