Skip to content
Snippets Groups Projects
Unverified Commit 3e7a45da authored by Benjamin Wheeler's avatar Benjamin Wheeler Committed by GitHub
Browse files

Merge pull request #3530 from evhan55/alert-reconnect-button

Add reconnect button to hardware disconnect alerts
parents b18bc447 c0115c9c
No related branches found
No related tags found
No related merge requests found
...@@ -30,7 +30,29 @@ ...@@ -30,7 +30,29 @@
} }
.alert-close-button { .alert-close-button {
outline-style:none;
}
.alert-close-button-container {
margin-top: 7px; margin-top: 7px;
margin-right: 4px; margin-right: 4px;
outline-style:none; outline-style:none;
width: 30px;
height: 30px;
}
.connection-button {
padding: 0.55rem 0.9rem;
border-radius: 0.35rem;
background: #FF8C1A;
color: white;
font-weight: 700;
font-size: 0.77rem;
margin: 0.25rem;
border: none;
cursor: pointer;
display: flex;
align-items: center;
margin-right: 13px;
outline-style:none;
} }
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import {FormattedMessage} from 'react-intl';
import Box from '../box/box.jsx'; import Box from '../box/box.jsx';
import CloseButton from '../close-button/close-button.jsx'; import CloseButton from '../close-button/close-button.jsx';
...@@ -9,7 +10,9 @@ import styles from './alert.css'; ...@@ -9,7 +10,9 @@ import styles from './alert.css';
const AlertComponent = ({ const AlertComponent = ({
iconURL, iconURL,
message, message,
onCloseAlert onCloseAlert,
onReconnect,
showReconnect
}) => ( }) => (
<Box <Box
className={styles.alert} className={styles.alert}
...@@ -23,19 +26,37 @@ const AlertComponent = ({ ...@@ -23,19 +26,37 @@ const AlertComponent = ({
) : null} ) : null}
{message} {message}
</div> </div>
<CloseButton {showReconnect ? (
className={styles.alertCloseButton} <button
color={CloseButton.COLOR_ORANGE} className={styles.connectionButton}
size={CloseButton.SIZE_LARGE} onClick={onReconnect}
onClick={onCloseAlert} >
/> <FormattedMessage
defaultMessage="Reconnect"
description="Button to reconnect the device"
id="gui.connection.reconnect"
/>
</button>
) : null}
<Box
className={styles.alertCloseButtonContainer}
>
<CloseButton
className={styles.alertCloseButton}
color={CloseButton.COLOR_ORANGE}
size={CloseButton.SIZE_LARGE}
onClick={onCloseAlert}
/>
</Box>
</Box> </Box>
); );
AlertComponent.propTypes = { AlertComponent.propTypes = {
iconURL: PropTypes.string, iconURL: PropTypes.string,
message: PropTypes.string, message: PropTypes.string,
onCloseAlert: PropTypes.func.isRequired onCloseAlert: PropTypes.func.isRequired,
onReconnect: PropTypes.func,
showReconnect: PropTypes.bool.isRequired
}; };
export default AlertComponent; export default AlertComponent;
...@@ -15,10 +15,12 @@ const AlertsComponent = ({ ...@@ -15,10 +15,12 @@ const AlertsComponent = ({
> >
{alertsList.map((a, index) => ( {alertsList.map((a, index) => (
<Alert <Alert
extensionId={a.extensionId}
iconURL={a.iconURL} iconURL={a.iconURL}
index={index} index={index}
key={index} key={index}
message={a.message} message={a.message}
showReconnect={a.showReconnect}
onCloseAlert={onCloseAlert} onCloseAlert={onCloseAlert}
/> />
))} ))}
......
...@@ -303,7 +303,7 @@ $fade-out-distance: 15px; ...@@ -303,7 +303,7 @@ $fade-out-distance: 15px;
/* Alerts */ /* Alerts */
.alerts-container { .alerts-container {
width: 448px; width: 520px;
z-index: $z-index-alerts; z-index: $z-index-alerts;
left: 0; left: 0;
right: 0; right: 0;
......
import React from 'react'; 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 AlertComponent from '../components/alerts/alert.jsx'; import AlertComponent from '../components/alerts/alert.jsx';
import {openConnectionModal} from '../reducers/modals';
import {setConnectionModalExtensionId} from '../reducers/connection-modal';
class Alert extends React.Component { class Alert extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
'handleOnCloseAlert' 'handleOnCloseAlert',
'handleOnReconnect'
]); ]);
} }
handleOnCloseAlert () { handleOnCloseAlert () {
this.props.onCloseAlert(this.props.index); this.props.onCloseAlert(this.props.index);
} }
handleOnReconnect () {
this.props.onOpenConnectionModal(this.props.extensionId);
this.handleOnCloseAlert();
}
render () { render () {
const { const {
index, // eslint-disable-line no-unused-vars index, // eslint-disable-line no-unused-vars
iconURL, iconURL,
message message,
showReconnect
} = this.props; } = this.props;
return ( return (
<AlertComponent <AlertComponent
iconURL={iconURL} iconURL={iconURL}
message={message} message={message}
showReconnect={showReconnect}
onCloseAlert={this.handleOnCloseAlert} onCloseAlert={this.handleOnCloseAlert}
onReconnect={this.handleOnReconnect}
/> />
); );
} }
} }
const mapStateToProps = state => ({
state: state
});
const mapDispatchToProps = dispatch => ({
onOpenConnectionModal: id => {
dispatch(setConnectionModalExtensionId(id));
dispatch(openConnectionModal());
}
});
Alert.propTypes = { Alert.propTypes = {
extensionId: PropTypes.string,
iconURL: PropTypes.string, iconURL: PropTypes.string,
index: PropTypes.number, index: PropTypes.number,
message: PropTypes.string, message: PropTypes.string,
onCloseAlert: PropTypes.func.isRequired onCloseAlert: PropTypes.func.isRequired,
onOpenConnectionModal: PropTypes.func,
showReconnect: PropTypes.bool.isRequired
}; };
export default Alert; export default connect(
mapStateToProps,
mapDispatchToProps
)(Alert);
...@@ -15,11 +15,14 @@ const reducer = function (state, action) { ...@@ -15,11 +15,14 @@ const reducer = function (state, action) {
const newList = state.alertsList.slice(); const newList = state.alertsList.slice();
const newAlert = {message: action.data.message}; const newAlert = {message: action.data.message};
const extensionId = action.data.extensionId; const extensionId = action.data.extensionId;
newAlert.showReconnect = false;
if (extensionId) { // if it's an extension if (extensionId) { // if it's an extension
const extension = extensionData.find(ext => ext.extensionId === extensionId); const extension = extensionData.find(ext => ext.extensionId === extensionId);
if (extension && extension.name) { if (extension && extension.name) {
// TODO: is this the right place to assemble this message? // TODO: is this the right place to assemble this message?
newAlert.extensionId = extensionId;
newAlert.message = `${newAlert.message} ${extension.name}.`; newAlert.message = `${newAlert.message} ${extension.name}.`;
newAlert.showReconnect = true;
} }
if (extension && extension.smallPeripheralImage) { if (extension && extension.smallPeripheralImage) {
newAlert.iconURL = extension.smallPeripheralImage; newAlert.iconURL = extension.smallPeripheralImage;
......
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