<commit_before>import React, { Component } from 'react'
import PropTypes from 'prop-types'
import update from 'immutability-helper'

import SosModelSelector from './SosModelRun/SosModelSelector.js'
import ScenarioSelector from './SosModelRun/ScenarioSelector.js'
import NarrativeSelector from './SosModelRun/NarrativeSelector.js'
import TimestepSelector from './SosModelRun/TimestepSelector.js'

class SosModelRunConfigForm extends Component {
    constructor(props) {
        super(props)

        this.handleKeyPress = this.handleKeyPress.bind(this)
        this.handleSosModelChange = this.handleSosModelChange.bind(this)
        this.handleScenariosChange = this.handleScenariosChange.bind(this)
        this.handleNarrativeChange = this.handleNarrativeChange.bind(this)
        this.handleTimestepChange = this.handleTimestepChange.bind(this)
        this.handleInputChange = this.handleInputChange.bind(this)
        this.handleSave = this.handleSave.bind(this)
        this.handleCancel = this.handleCancel.bind(this)

        this.state = {}
        this.state.selectedSosModelRun = this.props.sosModelRun
    }

    componentDidMount(){
        document.addEventListener("keydown", this.handleKeyPress, false)
    }

    componentWillUnmount(){
        document.removeEventListener("keydown", this.handleKeyPress, false)
    }

    handleKeyPress(){
        if(event.keyCode === 27) {
            this.handleCancel()
        }
    }

    handleSosModelChange(sos_model) {
        this.setState({
            selectedSosModelRun: update(this.state.selectedSosModelRun, {sos_model: {$set: sos_model}})
        })
    }

    handleScenariosChange(scenario_set, scenario) {
    /**
     * Set a scenario change in the local selectedSosModelRun state representation
     *
     * Arguments
     * ---------
     * scenario_set: str
     *     The scenario set that has changed
     * scenario: str
     *     The the scenario that has been selected
     */
        const { scenarios } = this.state.selectedSosModelRun

        scenarios[scenario_set] = scenario

        this.forceUpdate()
    }

    handleNarrativeChange(narrative_set, narrative, active) {
    /**
     * Add or remove a narrative from the local selectedSosModelRun state representation
     *
     * Arguments
     * ---------
     * narrative_set:
     *     The narrative set that has been changed
     * narrative:<commit_msg>Remove key scenario when deselected in SosModelRun<commit_after>import React, { Component } from 'react'
import PropTypes from 'prop-types'
import update from 'immutability-helper'

import SosModelSelector from './SosModelRun/SosModelSelector.js'
import ScenarioSelector from './SosModelRun/ScenarioSelector.js'
import NarrativeSelector from './SosModelRun/NarrativeSelector.js'
import TimestepSelector from './SosModelRun/TimestepSelector.js'

class SosModelRunConfigForm extends Component {
    constructor(props) {
        super(props)

        this.handleKeyPress = this.handleKeyPress.bind(this)
        this.handleSosModelChange = this.handleSosModelChange.bind(this)
        this.handleScenariosChange = this.handleScenariosChange.bind(this)
        this.handleNarrativeChange = this.handleNarrativeChange.bind(this)
        this.handleTimestepChange = this.handleTimestepChange.bind(this)
        this.handleInputChange = this.handleInputChange.bind(this)
        this.handleSave = this.handleSave.bind(this)
        this.handleCancel = this.handleCancel.bind(this)

        this.state = {}
        this.state.selectedSosModelRun = this.props.sosModelRun
    }

    componentDidMount(){
        document.addEventListener("keydown", this.handleKeyPress, false)
    }

    componentWillUnmount(){
        document.removeEventListener("keydown", this.handleKeyPress, false)
    }

    handleKeyPress(){
        if(event.keyCode === 27) {
            this.handleCancel()
        }
    }

    handleSosModelChange(sos_model) {
        this.setState({
            selectedSosModelRun: update(this.state.selectedSosModelRun, {sos_model: {$set: sos_model}})
        })
    }

    handleScenariosChange(scenario_set, scenario) {
    /**
     * Set a scenario change in the local selectedSosModelRun state representation
     *
     * Arguments
     * ---------
     * scenario_set: str
     *     The scenario set that has changed
     * scenario: str
     *     The the scenario that has been selected
     */
        const { scenarios } = this.state.selectedSosModelRun

        if (scenario == "") {
            delete scenarios[scenario_set]
        } else {
            scenarios[scenario_set] = scenario
        }

        this.forceUpdate()
    }

    handleNarrativeChange(narrative_set, narrative, active) {
    /**
     * Add or remove a narrative from the local selectedSosModelRun state representation
     *
     * Arguments
     * ---------
     * narrative_set:
     *     The narrative set that has been changed
     * narrative:
{'fraction_non_alphanumeric': 0.09500707499494643, 'fraction_numerical': 0.0008085708510208206, 'mean_word_length': 2.859594383775351, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4043617', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1387, 'n_words': 276}