<commit_before>import React from 'react';

import AlertService from '../../services/AlertService';
import UserStore from '../../stores/UserStore';
import NotificationActions from '../../actions/NotificationActions';
import * as constants from '../../config/constants';

import { Col } from 'react-flexbox-grid';
import ReactTooltip from 'react-tooltip';
import UpdateAlertPopover from './UpdateAlertPopover.jsx';
import Assignment from 'material-ui/svg-icons/action/assignment-ind';
import Close from 'material-ui/svg-icons/navigation/close';
import RaisedButton from 'material-ui/RaisedButton';
import IconButton from 'material-ui/IconButton';
import AccountCircleIcon from 'material-ui/svg-icons/action/account-circle';
import UndoIcon from 'material-ui/svg-icons/content/undo';
import CheckIcon from 'material-ui/svg-icons/navigation/check';
import Avatar from 'material-ui/Avatar';

require('../../styles/log/Alert.scss');

export default class Alert extends React.Component {

    constructor(props) {
        super(props);

        this.state = {
            showUpdateAlertPopover: false,
            alert: props.alert,
            popoverAnchor: null,
        };

        // binding
        this._toggleUpdateAlertPopover = this._toggleUpdateAlertPopover.bind(this);
        this._closeAlert = this._closeAlert.bind(this);
        this._restoreAlert = this._restoreAlert.bind(this);
    }

    componentWillReceiveProps(props) {
        this.setState({
            alert: props.alert
        });
    }

    /**
     * toggle the boolean to show the popover to assign users to this alert
     */
    _toggleUpdateAlertPopover(e) {
        let state = {
            showUpdateAlertPopover: !this.state.showUpdateAlertPopover,
        };
        if(e && e.currentTarget) {
            state['popoverAnchor'] = e.currentTarget;
        }
        this.setState(state);
    }

    /**
     * Call the service method to close this alert
     */
    _closeAlert() {
        AlertService.update(this.state.alert.id, {severity: "done"})
        .catch(error => NotificationActions.error("Erreur lors de la modification de l'alerte.", error));
    }

    /**
     * Call the service method to restore this alert
     */
    _restoreAlert() {
        AlertService.update(this.state.alert.id, {severity: "serious"})
        .catch(error => NotificationActions.error("Erreur lors de la modification de l'alerte.", error));
    }

    render() {

        return (
            <Col xs={12} sm={6} className="alert">
                <div className="alert__container">
                    <button
                        data-tip
                        data-for={"team-" + this.state.alert.id}
                        className={ 'alert__team-name__container alert__team-name__container--' + this.state.alert.severity}>
                        <div className="alert__team-name">
                            {this.props.alert.sender ? this.state.alert.sender.name : '-'}
                        </div>
                    </button>
                    <ReactTooltip
                        id={"team-" + this.state.alert.id}
                        place="bottom"
                    >
                        <span>{this.props.alert.sender ? this.props.alert.sender.name : 'Équipe supprimé ou alerte automatique'}</span>
                    </ReactTooltip>

                    <div className="alert__separator"><div></div>
                    </div>
                    <div className="alert__content">
                        <div><commit_msg>Add alert sender location in tooltips<commit_after>import React from 'react';

import AlertService from '../../services/AlertService';
import UserStore from '../../stores/UserStore';
import NotificationActions from '../../actions/NotificationActions';
import * as constants from '../../config/constants';

import { Col } from 'react-flexbox-grid';
import ReactTooltip from 'react-tooltip';
import UpdateAlertPopover from './UpdateAlertPopover.jsx';
import Assignment from 'material-ui/svg-icons/action/assignment-ind';
import Close from 'material-ui/svg-icons/navigation/close';
import RaisedButton from 'material-ui/RaisedButton';
import IconButton from 'material-ui/IconButton';
import AccountCircleIcon from 'material-ui/svg-icons/action/account-circle';
import UndoIcon from 'material-ui/svg-icons/content/undo';
import CheckIcon from 'material-ui/svg-icons/navigation/check';
import Avatar from 'material-ui/Avatar';

require('../../styles/log/Alert.scss');

export default class Alert extends React.Component {

    constructor(props) {
        super(props);

        this.state = {
            showUpdateAlertPopover: false,
            alert: props.alert,
            popoverAnchor: null,
        };

        // binding
        this._toggleUpdateAlertPopover = this._toggleUpdateAlertPopover.bind(this);
        this._closeAlert = this._closeAlert.bind(this);
        this._restoreAlert = this._restoreAlert.bind(this);
    }

    componentWillReceiveProps(props) {
        this.setState({
            alert: props.alert
        });
    }

    /**
     * toggle the boolean to show the popover to assign users to this alert
     */
    _toggleUpdateAlertPopover(e) {
        let state = {
            showUpdateAlertPopover: !this.state.showUpdateAlertPopover,
        };
        if(e && e.currentTarget) {
            state['popoverAnchor'] = e.currentTarget;
        }
        this.setState(state);
    }

    /**
     * Call the service method to close this alert
     */
    _closeAlert() {
        AlertService.update(this.state.alert.id, {severity: "done"})
        .catch(error => NotificationActions.error("Erreur lors de la modification de l'alerte.", error));
    }

    /**
     * Call the service method to restore this alert
     */
    _restoreAlert() {
        AlertService.update(this.state.alert.id, {severity: "serious"})
        .catch(error => NotificationActions.error("Erreur lors de la modification de l'alerte.", error));
    }

    render() {

        return (
            <Col xs={12} sm={6} className="alert">
                <div className="alert__container">
                    <button
                        data-tip
                        data-for={"team-" + this.state.alert.id}
                        className={ 'alert__team-name__container alert__team-name__container--' + this.state.alert.severity}>
                        <div className="alert__team-name">
                            {this.props.alert.sender ? this.state.alert.sender.name : '-'}
                        </div>
                    </button>
                    <ReactTooltip
                        id={"team-" + this.state.alert.id}
                        place="bottom"
                    >
                        <span>
                            {this.props.alert.sender ? this.props.alert.sender.name : 'Équipe supprimé ou alerte automatique'}<br/>
                            {this.props.alert.sender && this.props.alert.sender.location}
                        </span>
                    </ReactTooltip>

                    <div className="alert__separator"><div></div>
                    </div>
                    <div className="alert__content">
                        <div>
{'fraction_non_alphanumeric': 0.12032565199392853, 'fraction_numerical': 0.0008279287981233614, 'mean_word_length': 1.9987587918907737, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 40, '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': '5873213', 'n_tokens_mistral': 1951, 'n_tokens_neox': 1877, 'n_words': 402}