-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add check to see if assets pre-exist when uploading
- Loading branch information
Showing
11 changed files
with
204 additions
and
3 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
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,5 @@ | ||
@import 'edx-bootstrap'; | ||
|
||
.assets-upload-confirm-spacer { | ||
margin-bottom: 10px; | ||
} |
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,21 @@ | ||
import { connect } from 'react-redux'; | ||
|
||
import { uploadAssets } from '../../data/actions/assets'; | ||
import AssetsUploadConfirm from '.'; | ||
|
||
const mapStateToProps = state => ({ | ||
files: state.metadata.files, | ||
pre_upload_error: state.metadata.pre_upload_error, | ||
courseDetails: state.studioDetails.course, | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
uploadAssets: (assets, courseDetails) => dispatch(uploadAssets(assets, courseDetails)), | ||
}); | ||
|
||
const WrappedAssetsUploadConfirm = connect( | ||
mapStateToProps, | ||
mapDispatchToProps, | ||
)(AssetsUploadConfirm); | ||
|
||
export default WrappedAssetsUploadConfirm; |
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,16 @@ | ||
import { defineMessages } from 'react-intl'; | ||
|
||
const messages = defineMessages({ | ||
assetsUploadConfirmMessage: { | ||
id: 'assetsUploadConfirmMessage', | ||
defaultMessage: '0 files uploaded. {pre_upload_error}. Continuing to upload will overwrite them. If this is not what you want, retry uploading the files with different names.', | ||
description: 'The message displayed in the confirmation box shown when uploading files with pre-existing names', | ||
}, | ||
assetUploadConfirmOverwrite: { | ||
id: 'assetUploadConfirmOverwrite', | ||
defaultMessage: 'Overwrite', | ||
description: 'The message displayed in the button to confirm overwriting the files', | ||
} | ||
}); | ||
|
||
export default messages; |
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,90 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Button, StatusAlert } from '@edx/paragon'; | ||
import { FormattedNumber } from 'react-intl'; | ||
|
||
import { assetActions } from '../../data/constants/actionTypes'; | ||
import WrappedMessage from '../../utils/i18n/formattedMessageWrapper'; | ||
import { ASSET_STATUS_SHAPE } from '../../utils/constants'; | ||
import styles from './AssetsUploadConfirm.scss'; | ||
import messages from './displayMessages'; | ||
import { courseDetails } from '../../utils/testConstants'; | ||
|
||
const defaultState = { | ||
statusAlertOpen: false, | ||
}; | ||
|
||
export default class AssetsUploadConfirm extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = defaultState; | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
const { files, courseDetails, pre_upload_error } = nextProps; | ||
this.updateStates(files, courseDetails, pre_upload_error); | ||
} | ||
|
||
updateStates = (files, courseDetails, pre_upload_error) => { | ||
this.setState({ | ||
statusAlertOpen: pre_upload_error ? true : false, | ||
}) | ||
}; | ||
|
||
uploadFiles = () => { | ||
this.props.uploadAssets(this.props.files, this.props.courseDetails) | ||
} | ||
|
||
onClose = () => { | ||
this.setState(defaultState); | ||
} | ||
|
||
render() { | ||
const uploadFiles = this.uploadFiles; | ||
const { statusAlertOpen } = this.state | ||
const { pre_upload_error } = this.props | ||
content = ( | ||
<div> | ||
<WrappedMessage | ||
message={messages.assetsUploadConfirmMessage} | ||
values={{ pre_upload_error }} | ||
/> | ||
<br className={styles['assets-upload-confirm-spacer']}/> | ||
<Button | ||
buttonType="primary" | ||
label={<WrappedMessage message={messages.assetUploadConfirmOverwrite}/>} | ||
onClick={uploadFiles} | ||
/> | ||
</div> | ||
) | ||
|
||
return ( | ||
<StatusAlert | ||
alertType="danger" | ||
dialog={content} | ||
open={statusAlertOpen} | ||
onClose={this.onClose} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
AssetsUploadConfirm.propTypes = { | ||
files: PropTypes.arrayOf(PropTypes.string), | ||
uploadAssets: PropTypes.func.isRequired, | ||
courseDetails: PropTypes.shape({ | ||
lang: PropTypes.string, | ||
url_name: PropTypes.string, | ||
name: PropTypes.string, | ||
display_course_number: PropTypes.string, | ||
num: PropTypes.string, | ||
org: PropTypes.string, | ||
id: PropTypes.string, | ||
revision: PropTypes.string, | ||
}), | ||
pre_upload_error: PropTypes.string, | ||
}; | ||
|
||
AssetsUploadConfirm.defaultProps = { | ||
files: [], | ||
}; |
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