Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3478 from ethcore/ng-errors-overlay
Browse files Browse the repository at this point in the history
Better Errors Snackbar in UI
  • Loading branch information
gavofyork authored Nov 17, 2016
2 parents a9f0176 + 05dc1ab commit 4c41195
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
6 changes: 6 additions & 0 deletions js/src/ui/Errors/errors.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@

.container {
z-index: 10101 !important;

button {
color: white !important;
margin: 0 !important;
margin-right: -16px !important;
}
}
51 changes: 46 additions & 5 deletions js/src/ui/Errors/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ import { closeErrors } from './actions';

import styles from './errors.css';

const ERROR_REGEX = /-(\d+): (.+)$/;

class Errors extends Component {
static propTypes = {
message: PropTypes.string,
error: PropTypes.object,
visible: PropTypes.bool,
onCloseErrors: PropTypes.func
};
Expand All @@ -37,22 +40,60 @@ class Errors extends Component {
return null;
}

const text = this.getErrorMessage();

return (
<Snackbar
open
className={ styles.container }
message={ message }
autoHideDuration={ 5000 }
onRequestClose={ onCloseErrors } />
open
action='close'
autoHideDuration={ 60000 }
message={ text }
onActionTouchTap={ onCloseErrors }
onRequestClose={ this.onRequestClose }
bodyStyle={ {
whiteSpace: 'pre-line',
height: 'auto'
} }
contentStyle={ {
display: 'flex',
flexDirection: 'row',
lineHeight: '1.5em',
padding: '0.75em 0',
alignItems: 'center'
} }
/>
);
}

getErrorMessage = () => {
const { message, error } = this.props;

if (!error.text && !ERROR_REGEX.test(message)) {
return message;
}

const matches = ERROR_REGEX.exec(message);

const code = error.code || parseInt(matches[1]) * -1;
const text = error.text || matches[2];

return `[${code}] ${text}`;
}

onRequestClose = (reason) => {
if (reason === 'timeout') {
this.props.onCloseErrors();
}
}
}

function mapStateToProps (state) {
const { message, visible } = state.errors;
const { message, error, visible } = state.errors;

return {
message,
error,
visible
};
}
Expand Down
3 changes: 2 additions & 1 deletion js/src/ui/Errors/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function newError (state, action) {

return Object.assign({}, state, {
visible: true,
message: error.message
message: error.message,
error
});
}

Expand Down

0 comments on commit 4c41195

Please sign in to comment.