<commit_before>import React from 'react';

import ComboBoxComponent from '../commons/combo-box-component';
import LinkButton from '../commons/link-button';
import { updatePickedData } from './add-validation-actions';

import { SessionStorage } from '../../utils/browser-storages';

export default class BookDataPick extends React.Component {
    constructor(props) {
        super(props);
        this.pickedData = {
            title: this.props.bookData.title && this.props.bookData.title[0],
            collection: this.props.bookData.title && this.props.bookData.title[0],
            volume: this.props.bookData.volume && this.props.bookData.volume[0],
            price: this.props.bookData.price && this.props.bookData.price[0],
            author: this.props.bookData.author,
            pages: this.props.bookData.pages,
            publisher: this.props.bookData.publisher,
            cover: this.props.bookData.cover,
            isbn: this.props.isbn
        };
        if (this.props.bookData.volume === null) {
            delete this.pickedData.collection;
            delete this.pickedData.volume;
        }
        this.onTitleChange = this.onTitleChange.bind(this);
        this.onCollectionChange = this.onCollectionChange.bind(this);
        this.onVolumeChange = this.onVolumeChange.bind(this);
        this.onPriceChange = this.onPriceChange.bind(this);
        this.renderCollectionFields = this.renderCollectionFields.bind(this);
    }

    componentDidMount() {
        this.dispatchPickedData();
    }

    static get propTypes() {
        return {
            bookData: React.PropTypes.object.isRequired
        };
    }

    onTitleChange(event) {
        this.pickedData.title = event.target.value.trim();
        this.dispatchPickedData()
    }

    onCollectionChange(event) {
        this.pickedData.collection = event.target.value.trim();
        this.dispatchPickedData()
    }

    onVolumeChange(event) {
        this.pickedData.volume = event.target.value;
        this.dispatchPickedData()
    }

    onPriceChange(event) {
        this.pickedData.price = event.target.value;
        this.dispatchPickedData()
    }

    dispatchPickedData() {
        if (this.pickedData.title === '-- No title --') {
            delete this.pickedData.title;
        }

        SessionStorage.setItem('picked', this.pickedData);
        this.props.dispatch(updatePickedData(this.pickedData));
    }

    renderCollectionFields() {
        if (this.props.bookData.volume) {
            return (
                <div className="has-control-centered">
                    <ComboBoxComponent size="large" label="Collection" content={this.props.bookData.title} onChange={this.onCollectionChange} />
                    <ComboBoxComponent size="small" label="Volume" content={this.props.bookData.volume} onChange={this.onVolumeChange} />
                </div>
            );
        }
    }

    render() {
        const titleData = [
            ...this.props.bookData.title,
            '-- No title --'
        ]

        return (
            <section className="spacer has-control-centered columns">
                <ComboBoxComponent size="large" label="Title" content={ titleData } onChange={this.onTitleChange}/>
                { this.renderCollectionFields() }
                { this.props.bookData.price && <ComboBoxComponent size="small" label="Price" content={this.props.bookData.price} onChange={this.onPriceChange} /> }
                <div className="columns is-marginless is-mobile has-text-centered">
                    <div className="column">
                        <LinkButton
                            label="NEXT"
                            path="/validation"
                        />
                    </div>
                    <div className="column"><commit_msg>no price option added [skip ci]<commit_after>import React from 'react';

import ComboBoxComponent from '../commons/combo-box-component';
import LinkButton from '../commons/link-button';
import { updatePickedData } from './add-validation-actions';

import { SessionStorage } from '../../utils/browser-storages';

export default class BookDataPick extends React.Component {
    constructor(props) {
        super(props);
        this.pickedData = {
            title: this.props.bookData.title && this.props.bookData.title[0],
            collection: this.props.bookData.title && this.props.bookData.title[0],
            volume: this.props.bookData.volume && this.props.bookData.volume[0],
            price: this.props.bookData.price && this.props.bookData.price[0],
            author: this.props.bookData.author,
            pages: this.props.bookData.pages,
            publisher: this.props.bookData.publisher,
            cover: this.props.bookData.cover,
            isbn: this.props.isbn
        };
        if (this.props.bookData.volume === null) {
            delete this.pickedData.collection;
            delete this.pickedData.volume;
        }
        this.onTitleChange = this.onTitleChange.bind(this);
        this.onCollectionChange = this.onCollectionChange.bind(this);
        this.onVolumeChange = this.onVolumeChange.bind(this);
        this.onPriceChange = this.onPriceChange.bind(this);
        this.renderCollectionFields = this.renderCollectionFields.bind(this);
    }

    componentDidMount() {
        this.dispatchPickedData();
    }

    static get propTypes() {
        return {
            bookData: React.PropTypes.object.isRequired
        };
    }

    onTitleChange(event) {
        this.pickedData.title = event.target.value.trim();
        this.dispatchPickedData()
    }

    onCollectionChange(event) {
        this.pickedData.collection = event.target.value.trim();
        this.dispatchPickedData()
    }

    onVolumeChange(event) {
        this.pickedData.volume = event.target.value;
        this.dispatchPickedData()
    }

    onPriceChange(event) {
        this.pickedData.price = event.target.value;
        this.dispatchPickedData()
    }

    dispatchPickedData() {
        if (this.pickedData.title === '-- No title --') {
            delete this.pickedData.title;
        }

        if (this.pickedData.price === '-- No price --') {
            delete this.pickedData.price;
        }

        SessionStorage.setItem('picked', this.pickedData);
        this.props.dispatch(updatePickedData(this.pickedData));
    }

    renderCollectionFields() {
        if (this.props.bookData.volume) {
            return (
                <div className="has-control-centered">
                    <ComboBoxComponent size="large" label="Collection" content={this.props.bookData.title} onChange={this.onCollectionChange} />
                    <ComboBoxComponent size="small" label="Volume" content={this.props.bookData.volume} onChange={this.onVolumeChange} />
                </div>
            );
        }
    }

    render() {
        const titleData = [
            ...this.props.bookData.title,
            '-- No title --'
        ]

        const priceData = [
            ...this.props.bookData.price,
            '-- No price --'
        ];

        return (
            <section className="spacer has-control-centered columns">
                <ComboBoxComponent size="large" label="Title" content={ titleData } onChange={this.onTitleChange}/>
                { this.renderCollectionFields() }
                { this.props.bookData.price && <ComboBoxComponent size="small" label="Price" content={ priceData } onChange={this.onPriceChange} /> }
                <div className="columns is-marginless is-mobile has-text-centered">
                    <div className="column">
                        <LinkButton
                            label="NEXT"
                            path="/validation"
                        />
                    </div>
                    <div className="column">
{'fraction_non_alphanumeric': 0.12236072246247774, 'fraction_numerical': 0.0010175527855507504, 'mean_word_length': 2.028890600924499, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '2009551', 'n_tokens_mistral': 2143, 'n_tokens_neox': 2094, 'n_words': 328}