<commit_before>//@flow
import * as React from "react";
import PropTypes from "prop-types";
import Button, { buttonTypes, buttonSizes } from "@crave/farmblocks-button";

import StyledAlert from "./styledComponents/Alert";
import AlertTypes from "./constants/alertTypes";
import BrieflyDisplay from "./BrieflyDisplay";

class Alert extends React.Component<Object, Object> {
  static propTypes = {
    text: PropTypes.string.isRequired,
    type: PropTypes.oneOf(Object.keys(AlertTypes)),
    dismissable: PropTypes.bool,
    autoRemove: PropTypes.bool,
    onDismiss: PropTypes.func,
    visibleTime: PropTypes.number,
    zIndex: PropTypes.number
  };

  static defaultProps = {
    type: AlertTypes.NEWS,
    dismissable: true,
    autoRemove: true,
    onDismiss: () => null
  };

  constructor(props: Object) {
    super(props);
    this.state = {
      isVisible: true
    };
  }

  render() {
    if (!this.state.isVisible && this.props.autoRemove) {
      return null;
    }
    const { visibleTime, autoRemove, zIndex } = this.props;
    const dismissHandler = () => {
      this.setState({ isVisible: false });
      this.props.onDismiss();
    };
    const alert = (
      <StyledAlert type={this.props.type} {...(zIndex ? { zIndex } : {})}>
        <p>{this.props.text}</p>

        {this.props.dismissable && (
          <div className="dismiss-button">
            <Button
              icon="wg-close"
              size={buttonSizes.SMALL}
              type={buttonTypes.OFF_NEUTRAL}
              onClick={dismissHandler}
            />
          </div>
        )}
      </StyledAlert>
    );
    if (!visibleTime) {
      return alert;
    }
    return (<commit_msg>refactor(code review): address 2 issues from code review:<commit_after>//@flow
import * as React from "react";
import PropTypes from "prop-types";
import Button, { buttonTypes, buttonSizes } from "@crave/farmblocks-button";

import StyledAlert from "./styledComponents/Alert";
import AlertTypes from "./constants/alertTypes";
import BrieflyDisplay from "./BrieflyDisplay";

class Alert extends React.Component<Object, Object> {
  static propTypes = {
    text: PropTypes.string.isRequired,
    type: PropTypes.oneOf(Object.keys(AlertTypes)),
    dismissable: PropTypes.bool,
    autoRemove: PropTypes.bool,
    onDismiss: PropTypes.func,
    visibleTime: PropTypes.number,
    zIndex: PropTypes.number
  };

  static defaultProps = {
    type: AlertTypes.NEWS,
    dismissable: true,
    autoRemove: true,
    onDismiss: () => null
  };

  dismissHandler: Function;

  constructor(props: Object) {
    super(props);
    this.state = {
      isVisible: true
    };
    this.dismissHandler = this.dismissHandler.bind(this);
  }

  dismissHandler() {
    this.setState({ isVisible: false });
    this.props.onDismiss();
  }

  render() {
    if (!this.state.isVisible && this.props.autoRemove) {
      return null;
    }
    const { visibleTime, autoRemove, zIndex } = this.props;
    const alert = (
      <StyledAlert type={this.props.type} zIndex={zIndex}>
        <p>{this.props.text}</p>

        {this.props.dismissable && (
          <div className="dismiss-button">
            <Button
              icon="wg-close"
              size={buttonSizes.SMALL}
              type={buttonTypes.OFF_NEUTRAL}
              onClick={this.dismissHandler}
            />
          </div>
        )}
      </StyledAlert>
    );
    if (!visibleTime) {
      return alert;
    }
    return (
{'fraction_non_alphanumeric': 0.13048498845265588, 'fraction_numerical': 0.0002886836027713626, 'mean_word_length': 2.5943983402489628, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '895846', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1039, 'n_words': 217}