import React, { memo } from 'react';
import { connect } from 'react-redux';
import styles from './exception-mark.less';

function ExceptionMark({ show }) {
  if (!show) {
    return null;
  }

  return <div className={styles.icon} />;
}

const mapStateToProps = ({ componentsById }) => {
  const hasDataError = Object.keys(componentsById).some(
    (d) => componentsById[d] && componentsById[d].errorMessage,
  );

  return {
    show: hasDataError,
  };
};

export default connect(mapStateToProps)(memo(ExceptionMark));
