<commit_before>import React from 'react';
import {Link} from 'react-router';
import Icon from 'react-fa';
import Timestamp from 'react-time';
import FetchResult from 'common/src/fetch-result';
import DefaultError from 'common/src/error.jsx';
import {DATE_FORMAT} from 'common/src/config';
import 'common/asset/less/violation/violation-card.less';

class ViolationCard extends React.Component {
    constructor() {
        super();
        this.state = {
            message: ''
        };
    }

    updateMessage(evt) {
        this.setState({
            message: evt.target.value
        });
    }

    resolve(evt) {
        if (evt) {
            evt.preventDefault();
        }
        let {violation} = this.props,
            {message} = this.state;

        if (this.props.onResolve) {
            this.props.onResolve(violation, message);
        }
    }

    render() {
        let {violation} = this.props;
        if (violation instanceof FetchResult) {
            return violation.isPending() ?
                    <Icon name='circle-o-notch u-spinner' spin /> :
                    <DefaultError error={violation.getResult()} />;
        }
        let {violation_type} = violation;
        return <div
                    data-block='violation-card'
                    className={'violationCard ' +
                                (violation.comment != null ? 'is-resolved ' : '') +
                                (violation_type.audit_relevant ? 'is-audit-relevant' : '')}>
                    <header>
                        <div className='violationCard-id'>
                            <Link
                                to='violation-vioDetail'
                                params={{
                                    violationId: violation.id
                                }}>{violation.id}
                            </Link>
                        </div>
                        <div>
                            <Icon
                                fixedWidth
                                name='calendar-o'
                                title='Time when this violation was discovered' /> <Timestamp value={violation_type.timestamp} format={DATE_FORMAT} />
                        </div>
                        <div>
                            <Icon
                                fixedWidth
                                name='cloud'
                                title='The cloud account number' /> {violation.account_id}
                        </div>
                        <div>
                            <Icon
                                fixedWidth
                                name='map-marker'
                                title='Which region this violation happened in' /> {violation.region}
                        </div>
                        {violation.instance_id ?
                            <div>
                                <Icon
                                    fixedWidth
                                    name='server'
                                    title='Which instance caused this violation' /> {violation.instance_id}
                            </div>
                            :
                            null}
                    </header>
                    <table className='table'>
                        <colgroup>
                            <col width='0*' />
                            <col width='0.5*' />
                        </colgroup>
                        <tbody>
                            <tr>
                                <th>Type</th>
                                <td>{violation_type.id}</td>
                            </tr>
                            <tr>
                                <th>Info</th>
                                <td>{violation_type.help_text}</td>
                            </tr>
                            {violation.meta_info ?
                                <tr>
                                    <th>Metadata</th>
                                    <td>
                                        <code>
                                            {violation.meta_info}
                                        </code>
                                    </td>
                                </tr>
                                :
                                null}
                        </tbody>
                    </table>
                    <blockquote className='violationCard-violationMessage'>
                        {violation.message}
                    </blockquote>
                    <footer>
                        {violation.comment ?
                            <div>
                                <span>{violation.last_modified_by} (<Timestamp value={violation.last_modified} relative />):</span>
                                <blockquote className='violationCard-resolutionMessage'>{violation.comment}</blockquote>
                            </div>
                            :
                            this.props.editable ?
                                <form onSubmit={this.resolve.bind(this)} className='form'>
                                    <div className='input-group'>
                                        <input
                                            autoFocus={this.props.autoFocus}
                                            value={this.state.message}
                                            onChange={this.updateMessage.bind(this)}
                                            placeholder='This is expected because I tested things.'
                                            type='text' />
                                        <button
                                            type='submit'
                                            className='btn btn-default'>
                                            <Icon name='check' /> Resolve
                                        </button>
                                    </div>
                                </form>
                                :
                                null}
                    </footer>
                </div>;
    }
}
ViolationCard.displayName = 'ViolationCard';
ViolationCard.contextTypes = {
    router: React.PropTypes.func.isRequired
};
ViolationCard.propTypes = {
    autoFocus: React.PropTypes.bool,
    onResolve: React.PropTypes.func,
    violation: React.PropTypes.object.isRequired,
    editable: React.PropTypes.bool,
    flux: React.PropTypes.object.isRequired
};

export default ViolationCard;
<commit_msg>#295 fix bug with always current date in violations<commit_after>import React from 'react';
import {Link} from 'react-router';
import Icon from 'react-fa';
import Timestamp from 'react-time';
import FetchResult from 'common/src/fetch-result';
import DefaultError from 'common/src/error.jsx';
import {DATE_FORMAT} from 'common/src/config';
import 'common/asset/less/violation/violation-card.less';

class ViolationCard extends React.Component {
    constructor() {
        super();
        this.state = {
            message: ''
        };
    }

    updateMessage(evt) {
        this.setState({
            message: evt.target.value
        });
    }

    resolve(evt) {
        if (evt) {
            evt.preventDefault();
        }
        let {violation} = this.props,
            {message} = this.state;

        if (this.props.onResolve) {
            this.props.onResolve(violation, message);
        }
    }

    render() {
        let {violation} = this.props;
        if (violation instanceof FetchResult) {
            return violation.isPending() ?
                    <Icon name='circle-o-notch u-spinner' spin /> :
                    <DefaultError error={violation.getResult()} />;
        }
        let {violation_type} = violation;
        return <div
                    data-block='violation-card'
                    className={'violationCard ' +
                                (violation.comment != null ? 'is-resolved ' : '') +
                                (violation_type.audit_relevant ? 'is-audit-relevant' : '')}>
                    <header>
                        <div className='violationCard-id'>
                            <Link
                                to='violation-vioDetail'
                                params={{
                                    violationId: violation.id
                                }}>{violation.id}
                            </Link>
                        </div>
                        <div>
                            <Icon
                                fixedWidth
                                name='calendar-o'
                                title='Time when this violation was discovered' /> <Timestamp value={violation.timestamp} format={DATE_FORMAT} />
                        </div>
                        <div>
                            <Icon
                                fixedWidth
                                name='cloud'
                                title='The cloud account number' /> {violation.account_id}
                        </div>
                        <div>
                            <Icon
                                fixedWidth
                                name='map-marker'
                                title='Which region this violation happened in' /> {violation.region}
                        </div>
                        {violation.instance_id ?
                            <div>
                                <Icon
                                    fixedWidth
                                    name='server'
                                    title='Which instance caused this violation' /> {violation.instance_id}
                            </div>
                            :
                            null}
                    </header>
                    <table className='table'>
                        <colgroup>
                            <col width='0*' />
                            <col width='0.5*' />
                        </colgroup>
                        <tbody>
                            <tr>
                                <th>Type</th>
                                <td>{violation_type.id}</td>
                            </tr>
                            <tr>
                                <th>Info</th>
                                <td>{violation_type.help_text}</td>
                            </tr>
                            {violation.meta_info ?
                                <tr>
                                    <th>Metadata</th>
                                    <td>
                                        <code>
                                            {violation.meta_info}
                                        </code>
                                    </td>
                                </tr>
                                :
                                null}
                        </tbody>
                    </table>
                    <blockquote className='violationCard-violationMessage'>
                        {violation.message}
                    </blockquote>
                    <footer>
                        {violation.comment ?
                            <div>
                                <span>{violation.last_modified_by} (<Timestamp value={violation.last_modified} relative />):</span>
                                <blockquote className='violationCard-resolutionMessage'>{violation.comment}</blockquote>
                            </div>
                            :
                            this.props.editable ?
                                <form onSubmit={this.resolve.bind(this)} className='form'>
                                    <div className='input-group'>
                                        <input
                                            autoFocus={this.props.autoFocus}
                                            value={this.state.message}
                                            onChange={this.updateMessage.bind(this)}
                                            placeholder='This is expected because I tested things.'
                                            type='text' />
                                        <button
                                            type='submit'
                                            className='btn btn-default'>
                                            <Icon name='check' /> Resolve
                                        </button>
                                    </div>
                                </form>
                                :
                                null}
                    </footer>
                </div>;
    }
}
ViolationCard.displayName = 'ViolationCard';
ViolationCard.contextTypes = {
    router: React.PropTypes.func.isRequired
};
ViolationCard.propTypes = {
    autoFocus: React.PropTypes.bool,
    onResolve: React.PropTypes.func,
    violation: React.PropTypes.object.isRequired,
    editable: React.PropTypes.bool,
    flux: React.PropTypes.object.isRequired
};

export default ViolationCard;

{'fraction_non_alphanumeric': 0.08801825789273487, 'fraction_numerical': 0.0006846709775580068, 'mean_word_length': 0.766223297057638, 'pattern_counts': {'":': 0, '<': 143, '<?xml version=': 0, '>': 143, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 66, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2889274', 'n_tokens_mistral': 2769, 'n_tokens_neox': 2659, 'n_words': 484}