Return immediately if no alerts found

This commit is contained in:
Tiago Noronha 2019-03-04 13:52:20 +00:00
parent 416d41279f
commit f8e97b8152
1 changed files with 49 additions and 46 deletions

View File

@ -61,6 +61,11 @@ class StoreAlerts extends Component {
render() { render() {
const { alerts } = this.props; const { alerts } = this.props;
if ( ! alerts || alerts.length === 0 ) {
return null;
}
const { currentIndex } = this.state; const { currentIndex } = this.state;
const numberOfAlerts = alerts.length; const numberOfAlerts = alerts.length;
const alert = alerts[ currentIndex ] ? alerts[ currentIndex ] : null; const alert = alerts[ currentIndex ] ? alerts[ currentIndex ] : null;
@ -78,7 +83,6 @@ class StoreAlerts extends Component {
) ); ) );
return ( return (
numberOfAlerts > 0 && (
<Card <Card
title={ [ title={ [
alert.icon && <Dashicon key="icon" icon={ alert.icon } />, alert.icon && <Dashicon key="icon" icon={ alert.icon } />,
@ -123,7 +127,6 @@ class StoreAlerts extends Component {
/> />
{ actions && <div className="woocommerce-store-alerts__actions">{ actions }</div> } { actions && <div className="woocommerce-store-alerts__actions">{ actions }</div> }
</Card> </Card>
)
); );
} }
} }