Skip to content
Snippets Groups Projects
Commit bd6c6599 authored by Paul Kaplan's avatar Paul Kaplan
Browse files

Add download and retry saving to saving error alert.

I do not like how the alert component is hyper specialized for two distinct use cases. It would be much better to refactor the alerts so that the alerter can just fill the alert with whatever they want. But I do not feel comfortable making that refactor because I know ben and evelyn have gone back and forth about these alerts.
parent a3431a99
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,11 @@ const AlertComponent = ({ ...@@ -22,7 +22,11 @@ const AlertComponent = ({
iconSpinner, iconSpinner,
iconURL, iconURL,
level, level,
showDownload,
showSaveNow,
onCloseAlert, onCloseAlert,
onDownload,
onSaveNow,
onReconnect, onReconnect,
showReconnect showReconnect
}) => ( }) => (
...@@ -53,6 +57,30 @@ const AlertComponent = ({ ...@@ -53,6 +57,30 @@ const AlertComponent = ({
/> />
) : content} ) : content}
</div> </div>
{showSaveNow && (
<button
className={styles.alertConnectionButton}
onClick={onSaveNow}
>
<FormattedMessage
defaultMessage="Try&nbsp;Again" // TODO control wrapping in css
description="Button to try saving again"
id="gui.alerts.tryAgain"
/>
</button>
)}
{showDownload && (
<button
className={styles.alertConnectionButton}
onClick={onDownload}
>
<FormattedMessage
defaultMessage="Download"
description="Button to download project locally"
id="gui.alerts.download"
/>
</button>
)}
{showReconnect && ( {showReconnect && (
<button <button
className={styles.alertConnectionButton} className={styles.alertConnectionButton}
...@@ -88,8 +116,12 @@ AlertComponent.propTypes = { ...@@ -88,8 +116,12 @@ AlertComponent.propTypes = {
iconURL: PropTypes.string, iconURL: PropTypes.string,
level: PropTypes.string, level: PropTypes.string,
onCloseAlert: PropTypes.func.isRequired, onCloseAlert: PropTypes.func.isRequired,
onDownload: PropTypes.func,
onReconnect: PropTypes.func, onReconnect: PropTypes.func,
showReconnect: PropTypes.bool onSaveNow: PropTypes.func,
showDownload: PropTypes.func,
showReconnect: PropTypes.bool,
showSaveNow: PropTypes.bool
}; };
AlertComponent.defaultProps = { AlertComponent.defaultProps = {
......
...@@ -25,7 +25,9 @@ const AlertsComponent = ({ ...@@ -25,7 +25,9 @@ const AlertsComponent = ({
key={index} key={index}
level={a.level} level={a.level}
message={a.message} message={a.message}
showDownload={a.showDownload}
showReconnect={a.showReconnect} showReconnect={a.showReconnect}
showSaveNow={a.showSaveNow}
onCloseAlert={onCloseAlert} onCloseAlert={onCloseAlert}
/> />
))} ))}
......
...@@ -2,10 +2,11 @@ import React from 'react'; ...@@ -2,10 +2,11 @@ import React from 'react';
import bindAll from 'lodash.bindall'; import bindAll from 'lodash.bindall';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import SB3Downloader from './sb3-downloader.jsx';
import AlertComponent from '../components/alerts/alert.jsx'; import AlertComponent from '../components/alerts/alert.jsx';
import {openConnectionModal} from '../reducers/modals'; import {openConnectionModal} from '../reducers/modals';
import {setConnectionModalExtensionId} from '../reducers/connection-modal'; import {setConnectionModalExtensionId} from '../reducers/connection-modal';
import {manualUpdateProject} from '../reducers/project-state';
class Alert extends React.Component { class Alert extends React.Component {
constructor (props) { constructor (props) {
...@@ -32,21 +33,30 @@ class Alert extends React.Component { ...@@ -32,21 +33,30 @@ class Alert extends React.Component {
iconSpinner, iconSpinner,
iconURL, iconURL,
message, message,
showReconnect onSaveNow,
showDownload,
showReconnect,
showSaveNow
} = this.props; } = this.props;
return ( return (
<AlertComponent <SB3Downloader>{(_, downloadProject) => (
closeButton={closeButton} <AlertComponent
content={content} closeButton={closeButton}
extensionName={extensionName} content={content}
iconSpinner={iconSpinner} extensionName={extensionName}
iconURL={iconURL} iconSpinner={iconSpinner}
level={level} iconURL={iconURL}
message={message} level={level}
showReconnect={showReconnect} message={message}
onCloseAlert={this.handleOnCloseAlert} showDownload={showDownload}
onReconnect={this.handleOnReconnect} showReconnect={showReconnect}
/> showSaveNow={showSaveNow}
onCloseAlert={this.handleOnCloseAlert}
onDownload={downloadProject}
onReconnect={this.handleOnReconnect}
onSaveNow={onSaveNow}
/>
)}</SB3Downloader>
); );
} }
} }
...@@ -57,6 +67,9 @@ const mapDispatchToProps = dispatch => ({ ...@@ -57,6 +67,9 @@ const mapDispatchToProps = dispatch => ({
onOpenConnectionModal: id => { onOpenConnectionModal: id => {
dispatch(setConnectionModalExtensionId(id)); dispatch(setConnectionModalExtensionId(id));
dispatch(openConnectionModal()); dispatch(openConnectionModal());
},
onSaveNow: () => {
dispatch(manualUpdateProject());
} }
}); });
...@@ -72,7 +85,10 @@ Alert.propTypes = { ...@@ -72,7 +85,10 @@ Alert.propTypes = {
message: PropTypes.string, message: PropTypes.string,
onCloseAlert: PropTypes.func.isRequired, onCloseAlert: PropTypes.func.isRequired,
onOpenConnectionModal: PropTypes.func, onOpenConnectionModal: PropTypes.func,
showReconnect: PropTypes.bool onSaveNow: PropTypes.func,
showDownload: PropTypes.bool,
showReconnect: PropTypes.bool,
showSaveNow: PropTypes.bool
}; };
export default connect( export default connect(
......
...@@ -61,11 +61,13 @@ const alerts = [ ...@@ -61,11 +61,13 @@ const alerts = [
}, },
{ {
alertId: 'savingError', alertId: 'savingError',
clearList: ['saving', 'saveSuccess'], clearList: ['saving', 'saveSuccess', 'savingError'],
closeButton: true, showDownload: true,
showSaveNow: true,
closeButton: false,
content: ( content: (
<FormattedMessage <FormattedMessage
defaultMessage="Could not save the project. Please try again!" defaultMessage="Project could not save."
description="Message indicating that project could not be saved" description="Message indicating that project could not be saved"
id="gui.alerts.savingError" id="gui.alerts.savingError"
/> />
...@@ -75,7 +77,7 @@ const alerts = [ ...@@ -75,7 +77,7 @@ const alerts = [
{ {
alertId: 'saveSuccess', alertId: 'saveSuccess',
alertType: AlertTypes.INLINE, alertType: AlertTypes.INLINE,
clearList: ['createSuccess', 'creating', 'saveSuccess', 'saving'], clearList: ['createSuccess', 'creating', 'saveSuccess', 'saving', 'savingError'],
content: ( content: (
<FormattedMessage <FormattedMessage
defaultMessage="Successfully saved." defaultMessage="Successfully saved."
...@@ -90,7 +92,7 @@ const alerts = [ ...@@ -90,7 +92,7 @@ const alerts = [
{ {
alertId: 'saving', alertId: 'saving',
alertType: AlertTypes.INLINE, alertType: AlertTypes.INLINE,
clearList: ['createSuccess', 'creating', 'saveSuccess', 'saving'], clearList: ['createSuccess', 'creating', 'saveSuccess', 'saving', 'savingError'],
content: ( content: (
<FormattedMessage <FormattedMessage
defaultMessage="Saving..." defaultMessage="Saving..."
......
...@@ -84,10 +84,9 @@ const ProjectSaverHOC = function (WrappedComponent) { ...@@ -84,10 +84,9 @@ const ProjectSaverHOC = function (WrappedComponent) {
this.props.onShowSaveSuccessAlert(); this.props.onShowSaveSuccessAlert();
}) })
.catch(err => { .catch(err => {
// NOTE: should throw up a notice for user // Always show the savingError alert because it gives the
if (this.props.isManualUpdating) { // user the chance to download or retry the save manually.
this.props.onShowAlert('savingError'); this.props.onShowAlert('savingError');
}
this.props.onProjectError(err); this.props.onProjectError(err);
}); });
} }
......
...@@ -46,6 +46,8 @@ const reducer = function (state, action) { ...@@ -46,6 +46,8 @@ const reducer = function (state, action) {
newAlert.iconURL = alertData.iconURL; newAlert.iconURL = alertData.iconURL;
newAlert.iconSpinner = alertData.iconSpinner; newAlert.iconSpinner = alertData.iconSpinner;
newAlert.level = alertData.level; newAlert.level = alertData.level;
newAlert.showDownload = alertData.showDownload;
newAlert.showSaveNow = alertData.showSaveNow;
newList.push(newAlert); newList.push(newAlert);
return Object.assign({}, state, { return Object.assign({}, state, {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment