<commit_before>import FormFactory from './formFactory';

import { checkForUnallowedChar, formatBbox, uuidv4 } from './utilities';
import _find                                         from 'lodash-es/find';
import OverpassQueryPanel                            from './overpassQueryPanel';
import _get                                          from 'lodash-es/get';

export default class GrailPull {
    constructor( instance ) {
        this.instance = instance;
        this.maxFeatureCount = null;
        this.grailMetadata = null;
    }

    render() {
        let titleText = this.instance.bboxSelectType === 'visualExtent'
            ? 'Pull Remote Data for Visual Extent'
            : this.instance.bboxSelectType === 'boundingBox'
                ? 'Pull Remote Data for Bounding Box'
                : 'Pull Remote Data';

        let metadata = {
            title: titleText,
            button: {
                text: 'Submit',
                id: 'SubmitBtn',
                onClick: () => this.handleSubmit()
            }
        };

        let formId = 'grailPullTable';

        this.form         = new FormFactory().generateForm( 'body', formId, metadata );
        this.submitButton = d3.select( `#${ metadata.button.id }` );

        this.addBackButton( metadata.button.id );
        this.submitButton.property( 'disabled', false );

        this.loadingState();

        this.createTable();
    }

    addBackButton( nextButtonId ) {
        const backButton = this.form.select( '.modal-footer' )
            .insert( 'button', `#${ nextButtonId }` )
            .classed( 'round strong primary', true )
            .on( 'click', () => {
                this.form.remove();

                new OverpassQueryPanel( this.instance ).render();
            } );

        backButton.append( 'span' )
            .text( 'Back' );
    }

    async createTable() {
        const { data } = await Hoot.api.grailMetadataQuery();
        this.grailMetadata = data;
        this.maxFeatureCount = +this.grailMetadata.maxFeatureCount;

        const overpassParams = { BBOX: this.instance.bbox };
        if ( this.instance.overpassQueryContainer.select( '#customQueryToggle' ).property( 'checked' ) ) {
            overpassParams.customQuery = this.instance.overpassQueryContainer.select( 'textarea' ).property( 'value' );
        }

        const rowData = await Hoot.api.overpassStats( overpassParams );

        this.loadingState();


        let statsTable = this.form
            .select( '.wrapper div' )
            .insert( 'table', '.modal-footer' )
            .classed( 'pullStatsInfo', true );


        let thead = statsTable.append('thead');
        thead.append('tr')
            .selectAll('th')
            .data([''].concat(rowData.columns.reverse()))<commit_msg>copy the array before reverse (#1667)<commit_after>import FormFactory from './formFactory';

import { checkForUnallowedChar, formatBbox, uuidv4 } from './utilities';
import _find                                         from 'lodash-es/find';
import OverpassQueryPanel                            from './overpassQueryPanel';
import _get                                          from 'lodash-es/get';

export default class GrailPull {
    constructor( instance ) {
        this.instance = instance;
        this.maxFeatureCount = null;
        this.grailMetadata = null;
    }

    render() {
        let titleText = this.instance.bboxSelectType === 'visualExtent'
            ? 'Pull Remote Data for Visual Extent'
            : this.instance.bboxSelectType === 'boundingBox'
                ? 'Pull Remote Data for Bounding Box'
                : 'Pull Remote Data';

        let metadata = {
            title: titleText,
            button: {
                text: 'Submit',
                id: 'SubmitBtn',
                onClick: () => this.handleSubmit()
            }
        };

        let formId = 'grailPullTable';

        this.form         = new FormFactory().generateForm( 'body', formId, metadata );
        this.submitButton = d3.select( `#${ metadata.button.id }` );

        this.addBackButton( metadata.button.id );
        this.submitButton.property( 'disabled', false );

        this.loadingState();

        this.createTable();
    }

    addBackButton( nextButtonId ) {
        const backButton = this.form.select( '.modal-footer' )
            .insert( 'button', `#${ nextButtonId }` )
            .classed( 'round strong primary', true )
            .on( 'click', () => {
                this.form.remove();

                new OverpassQueryPanel( this.instance ).render();
            } );

        backButton.append( 'span' )
            .text( 'Back' );
    }

    async createTable() {
        const { data } = await Hoot.api.grailMetadataQuery();
        this.grailMetadata = data;
        this.maxFeatureCount = +this.grailMetadata.maxFeatureCount;

        const overpassParams = { BBOX: this.instance.bbox };
        if ( this.instance.overpassQueryContainer.select( '#customQueryToggle' ).property( 'checked' ) ) {
            overpassParams.customQuery = this.instance.overpassQueryContainer.select( 'textarea' ).property( 'value' );
        }

        const rowData = await Hoot.api.overpassStats( overpassParams );

        this.loadingState();


        let statsTable = this.form
            .select( '.wrapper div' )
            .insert( 'table', '.modal-footer' )
            .classed( 'pullStatsInfo', true );


        let thead = statsTable.append('thead');
        thead.append('tr')
            .selectAll('th')
            .data([''].concat(rowData.columns.slice().reverse()))
{'fraction_non_alphanumeric': 0.1238875044499822, 'fraction_numerical': 0.001423994304022784, 'mean_word_length': 1.842185128983308, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2739545', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1459, 'n_words': 322}