Simplify StoreAlerts component logic
This commit is contained in:
parent
2e2fb90cde
commit
c3ff6fca49
|
@ -61,30 +61,30 @@ class StoreAlerts extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const hasAlerts = Boolean( wcSettings.alertCount ) || null;
|
const alerts = this.props.alerts || [];
|
||||||
|
const preloadAlertCount = wcSettings.alertCount && parseInt( wcSettings.alertCount );
|
||||||
|
|
||||||
if ( ! hasAlerts ) {
|
if ( preloadAlertCount > 0 && 0 === alerts.length ) {
|
||||||
|
return <StoreAlertsPlaceholder hasMultipleAlerts={ preloadAlertCount > 1 } />;
|
||||||
|
} else if ( 0 === alerts.length ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { alerts } = this.props;
|
|
||||||
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 ];
|
||||||
const type = alert && alert.type ? alert.type : null;
|
const type = alert.type;
|
||||||
const className = classnames( 'woocommerce-store-alerts', {
|
const className = classnames( 'woocommerce-store-alerts', {
|
||||||
'is-alert-error': 'error' === type,
|
'is-alert-error': 'error' === type,
|
||||||
'is-alert-update': 'update' === type,
|
'is-alert-update': 'update' === type,
|
||||||
} );
|
} );
|
||||||
const actions =
|
const actions = alert.actions.map( action => (
|
||||||
alert &&
|
<Button key={ action.name } isDefault href={ action.url }>
|
||||||
alert.actions.map( action => (
|
{ action.label }
|
||||||
<Button key={ action.name } isDefault href={ action.url }>
|
</Button>
|
||||||
{ action.label }
|
) );
|
||||||
</Button>
|
|
||||||
) );
|
|
||||||
|
|
||||||
return alert ? (
|
return (
|
||||||
<Card
|
<Card
|
||||||
title={ [
|
title={ [
|
||||||
alert.icon && <Dashicon key="icon" icon={ alert.icon } />,
|
alert.icon && <Dashicon key="icon" icon={ alert.icon } />,
|
||||||
|
@ -129,8 +129,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>
|
||||||
) : (
|
|
||||||
<StoreAlertsPlaceholder hasMultipleAlerts={ wcSettings.alertCount > 1 } />
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue