<commit_before>import {CountrySection} from './countrySection'
import {EETableSection} from './eeTableSection'
import {Form} from 'widget/form/form'
import {MosaicPreview} from '../../mosaicPreview'
import {PolygonSection} from './polygonSection'
import {RecipeFormPanel, recipeFormPanel} from 'app/home/body/process/recipeFormPanel'
import {SectionSelection} from './sectionSelection'
import {compose} from 'compose'
import {countryEETable, setAoiLayer} from 'app/home/map/aoiLayer'
import {msg} from 'translate'
import PanelSections from 'widget/panelSections'
import PropTypes from 'prop-types'
import React from 'react'
import styles from './aoi.module.css'

const fields = {
    section: new Form.Field()
        .notBlank('process.mosaic.panel.areaOfInterest.form.section.required'),
    country: new Form.Field()
        .skip((value, {section}) => section !== 'COUNTRY')
        .notBlank('process.mosaic.panel.areaOfInterest.form.country.required')
        .notEmpty('process.mosaic.panel.areaOfInterest.form.country.required'),
    area: new Form.Field(),
    eeTable: new Form.Field()
        .skip((value, {section}) => section !== 'EE_TABLE')
        .notBlank('process.mosaic.panel.areaOfInterest.form.eeTable.eeTable.required'),
    allowWholeEETable: new Form.Field(),
    eeTableRowSelection: new Form.Field(),
    eeTableColumn: new Form.Field()
        .skip((value, {section}) => section !== 'EE_TABLE')
        .skip((_, {eeTableRowSelection}) => eeTableRowSelection === 'INCLUDE_ALL')
        .skip((value, {eeTable}) => !eeTable)
        .notBlank('process.mosaic.panel.areaOfInterest.form.eeTable.column.required'),
    eeTableRow: new Form.Field()
        .skip((value, {section}) => section !== 'EE_TABLE')
        .skip((_, {eeTableRowSelection}) => eeTableRowSelection === 'INCLUDE_ALL')
        .skip((value, {eeTableColumn}) => !eeTableColumn)
        .notBlank('process.mosaic.panel.areaOfInterest.form.eeTable.row.required'),
    buffer: new Form.Field()
        .skip((value, {section}) => !['EE_TABLE', 'COUNTRY'].includes(section))
        .int(),
    polygon: new Form.Field()
        .skip((value, {section}) => section !== 'POLYGON')
        .notBlank('process.mosaic.panel.areaOfInterest.form.country.required')
}

class Aoi extends React.Component {
    constructor(props) {
        super(props)
        this.state = {canceled: false}
        const {recipeId, mapContext: {sepalMap}} = props
        this.preview = MosaicPreview(recipeId)
        this.initialBounds = sepalMap.getBounds()
        this.initialZoom = sepalMap.getZoom()
    }

    render() {
        const {recipeId, allowWholeEETable, inputs, layerIndex = 1} = this.props
        const sections = [{
            component: <SectionSelection recipeId={recipeId} inputs={inputs}/>
        }, {
            value: 'COUNTRY',
            label: msg('process.mosaic.panel.areaOfInterest.form.country.title'),
            title: 'COUNTRY/PROVINCE',
            component: <CountrySection recipeId={recipeId} inputs={inputs} layerIndex={layerIndex}/>
        }, {
            value: 'EE_TABLE',
            label: msg('process.mosaic.panel.areaOfInterest.form.eeTable.title'),
            title: 'EE TABLE',
            component: <EETableSection
                recipeId={recipeId}
                inputs={inputs}
                allowWholeEETable={allowWholeEETable}
                layerIndex={layerIndex}/>
        }, {
            value: 'POLYGON',
            label: msg('process.mosaic.panel.areaOfInterest.form.polygon.title'),
            title: 'POLYGON',
            component: <PolygonSection recipeId={recipeId} inputs={inputs} layerIndex={layerIndex}/>
        }]
        return (
            <RecipeFormPanel
                className={styles.panel}
                placement='bottom-right'
                onApply={(values, model) => this.onApply(values, model)}
                onCancel={() => this.setState({canceled: true})}>
                <PanelSections
                    inputs={inputs}
                    sections={sections}
                    selected={inputs.section}
                    icon='globe'
                    label={msg('process.mosaic.panel.areaOfInterest.title')}
                />
            </RecipeFormPanel>
        )
    }

    componentDidMount() {
        this.preview.hide()
    }

    componentDidUpdate() {
        const {inputs, allowWholeEETable = ''} = this.props
        inputs.allowWholeEETable.set(allowWholeEETable)
    }

    componentWillUnmount() {
        const {canceled} = this.state
        if (canceled) {
            this.onCancel()
        }
    }

    onApply(values, model) {
        this.preview.show()
        this.updateLayer(model)
    }

    onCancel() {
        const {model, mapContext: {sepalMap}} = this.props
        this.preview.show()
        this.updateLayer(model)
        sepalMap.fitBounds(this.initialBounds)
        sepalMap.setZoom(this.initialZoom)
    }

    updateLayer(model) {
        const {mapContext} = this.props
        setAoiLayer({
            mapContext,
            aoi: model,
            fill: false,
            layerIndex: 1
        })<commit_msg>Fixed AOI panel close behavior when using buttons.<commit_after>import {CountrySection} from './countrySection'
import {EETableSection} from './eeTableSection'
import {Form} from 'widget/form/form'
import {MosaicPreview} from '../../mosaicPreview'
import {PolygonSection} from './polygonSection'
import {RecipeFormPanel, recipeFormPanel} from 'app/home/body/process/recipeFormPanel'
import {SectionSelection} from './sectionSelection'
import {compose} from 'compose'
import {countryEETable, setAoiLayer} from 'app/home/map/aoiLayer'
import {msg} from 'translate'
import PanelSections from 'widget/panelSections'
import PropTypes from 'prop-types'
import React from 'react'
import styles from './aoi.module.css'

const fields = {
    section: new Form.Field()
        .notBlank('process.mosaic.panel.areaOfInterest.form.section.required'),
    country: new Form.Field()
        .skip((value, {section}) => section !== 'COUNTRY')
        .notBlank('process.mosaic.panel.areaOfInterest.form.country.required')
        .notEmpty('process.mosaic.panel.areaOfInterest.form.country.required'),
    area: new Form.Field(),
    eeTable: new Form.Field()
        .skip((value, {section}) => section !== 'EE_TABLE')
        .notBlank('process.mosaic.panel.areaOfInterest.form.eeTable.eeTable.required'),
    allowWholeEETable: new Form.Field(),
    eeTableRowSelection: new Form.Field(),
    eeTableColumn: new Form.Field()
        .skip((value, {section}) => section !== 'EE_TABLE')
        .skip((_, {eeTableRowSelection}) => eeTableRowSelection === 'INCLUDE_ALL')
        .skip((value, {eeTable}) => !eeTable)
        .notBlank('process.mosaic.panel.areaOfInterest.form.eeTable.column.required'),
    eeTableRow: new Form.Field()
        .skip((value, {section}) => section !== 'EE_TABLE')
        .skip((_, {eeTableRowSelection}) => eeTableRowSelection === 'INCLUDE_ALL')
        .skip((value, {eeTableColumn}) => !eeTableColumn)
        .notBlank('process.mosaic.panel.areaOfInterest.form.eeTable.row.required'),
    buffer: new Form.Field()
        .skip((value, {section}) => !['EE_TABLE', 'COUNTRY'].includes(section))
        .int(),
    polygon: new Form.Field()
        .skip((value, {section}) => section !== 'POLYGON')
        .notBlank('process.mosaic.panel.areaOfInterest.form.country.required')
}

class Aoi extends React.Component {
    constructor(props) {
        super(props)
        this.state = {canceled: false}
        const {recipeId, mapContext: {sepalMap}} = props
        this.preview = MosaicPreview(recipeId)
        this.initialBounds = sepalMap.getBounds()
        this.initialZoom = sepalMap.getZoom()
    }

    render() {
        const {recipeId, allowWholeEETable, inputs, layerIndex = 1} = this.props
        const sections = [{
            component: <SectionSelection recipeId={recipeId} inputs={inputs}/>
        }, {
            value: 'COUNTRY',
            label: msg('process.mosaic.panel.areaOfInterest.form.country.title'),
            title: 'COUNTRY/PROVINCE',
            component: <CountrySection recipeId={recipeId} inputs={inputs} layerIndex={layerIndex}/>
        }, {
            value: 'EE_TABLE',
            label: msg('process.mosaic.panel.areaOfInterest.form.eeTable.title'),
            title: 'EE TABLE',
            component: <EETableSection
                recipeId={recipeId}
                inputs={inputs}
                allowWholeEETable={allowWholeEETable}
                layerIndex={layerIndex}/>
        }, {
            value: 'POLYGON',
            label: msg('process.mosaic.panel.areaOfInterest.form.polygon.title'),
            title: 'POLYGON',
            component: <PolygonSection recipeId={recipeId} inputs={inputs} layerIndex={layerIndex}/>
        }]
        return (
            <RecipeFormPanel
                className={styles.panel}
                placement='bottom-right'
                onApply={(values, model) => this.onApply(values, model)}
                onClose={() => this.onCancel()}
            >
                <PanelSections
                    inputs={inputs}
                    sections={sections}
                    selected={inputs.section}
                    icon='globe'
                    label={msg('process.mosaic.panel.areaOfInterest.title')}
                />
            </RecipeFormPanel>
        )
    }

    componentDidMount() {
        this.preview.hide()
    }

    componentDidUpdate() {
        const {inputs, allowWholeEETable = ''} = this.props
        inputs.allowWholeEETable.set(allowWholeEETable)
    }

    onApply(values, model) {
        this.preview.show()
        this.updateLayer(model)
    }

    onCancel() {
        const {model, mapContext: {sepalMap}} = this.props
        this.preview.show()
        this.updateLayer(model)
        sepalMap.fitBounds(this.initialBounds)
        sepalMap.setZoom(this.initialZoom)
    }

    updateLayer(model) {
        const {mapContext} = this.props
        setAoiLayer({
            mapContext,
            aoi: model,
            fill: false,
            layerIndex: 1
        })
{'fraction_non_alphanumeric': 0.13541564672476256, 'fraction_numerical': 0.0003916576911779105, 'mean_word_length': 2.4812542603953647, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 41, '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': '1893703', 'n_tokens_mistral': 3049, 'n_tokens_neox': 2933, 'n_words': 527}