<commit_before>'use strict';

var React = require('react');

var DomUtil = require('../../../utils/dom-util');

require('./notice.less');


var Notice = React.createClass({
    propTypes: {
        text: React.PropTypes.string.isRequired,
        type: React.PropTypes.string,
        onClick: React.PropTypes.func, // if not provided button won't be rendered no matter if buttonText or isButtonEnabled present
        buttonText: React.PropTypes.string,
        isButtonEnabled: React.PropTypes.bool.isRequired,
        onClose: React.PropTypes.func // if not provided close-button won't be rendered
    },

    getDefaultProps: function() {
        return {
            isButtonEnabled: true
        };
    },

    componentDidMount: function() {
        DomUtil.scrollToTheTop();
    },

    shouldComponentUpdate: function(nextProps) {
        return this.props.text !== nextProps.text;
    },

    handleClick: function(event) {
        if (event) {
            event.preventDefault();
        }
        this.props.onClick();
    },

    handleClose: function(event) {
        if (event) {
            event.preventDefault();
        }
        this.props.onClose();
    },

    renderButton: function() {
        if (this.props.onClick) {
            return (
                <input
                    type='button'
                    value={ this.props.buttonText }
                    disabled={ !this.props.isButtonEnabled }
                    onClick={ this.handleClick }
                    />
            );
        }
    },

    renderCloseButton: function() {
        if (this.props.onClose) {
            return (
                <div
                    className='close'
                    onClick={ this.handleClose }
                    onTouchStart='' // required for iOS webkit browser to trigger :active pseudo state
                    >
                    x
                </div>
            );
        }
    },

    render: function() {
        var className = 'notice';
        if (this.props.type) {
            className += ' x-' + this.props.type;
        }

        return (
            <div className={ className }>
                { this.props.text }
                { this.renderButton() }
                { this.renderCloseButton() }
            </div>
        );
    }
});

module.exports = Notice;
<commit_msg>Fixed notice component behavor: rerender when diff props passed, scroll to the top when rerendered<commit_after>'use strict';

var React = require('react');

var DomUtil = require('../../../utils/dom-util');

require('./notice.less');


var Notice = React.createClass({
    propTypes: {
        text: React.PropTypes.string.isRequired,
        type: React.PropTypes.string,
        onClick: React.PropTypes.func, // if not provided button won't be rendered no matter if buttonText or isButtonEnabled present
        buttonText: React.PropTypes.string,
        isButtonEnabled: React.PropTypes.bool.isRequired,
        onClose: React.PropTypes.func // if not provided close-button won't be rendered
    },

    getDefaultProps: function() {
        return {
            isButtonEnabled: true
        };
    },

    componentDidMount: function() {
        DomUtil.scrollToTheTop();
    },

    componentDidUpdate: function() {
        DomUtil.scrollToTheTop();
    },

    handleClick: function(event) {
        if (event) {
            event.preventDefault();
        }
        this.props.onClick();
    },

    handleClose: function(event) {
        if (event) {
            event.preventDefault();
        }
        this.props.onClose();
    },

    renderButton: function() {
        if (this.props.onClick) {
            return (
                <input
                    type='button'
                    value={ this.props.buttonText }
                    disabled={ !this.props.isButtonEnabled }
                    onClick={ this.handleClick }
                    />
            );
        }
    },

    renderCloseButton: function() {
        if (this.props.onClose) {
            return (
                <div
                    className='close'
                    onClick={ this.handleClose }
                    onTouchStart={ () => {} } // required for iOS webkit browser to trigger :active pseudo state
                    >
                    x
                </div>
            );
        }
    },

    render: function() {
        var className = 'notice';
        if (this.props.type) {
            className += ' x-' + this.props.type;
        }

        return (
            <div className={ className }>
                { this.props.text }
                { this.renderButton() }
                { this.renderCloseButton() }
            </div>
        );
    }
});

module.exports = Notice;

{'fraction_non_alphanumeric': 0.11514261744966443, 'fraction_numerical': 0.0, 'mean_word_length': 1.4658738366080661, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, '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': '6632620', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1205, 'n_words': 264}