<commit_before>// @flow

import React from 'react'
import {connect} from 'react-redux'
import {Student, type AreaQuery} from '@gob/object-student'
import {pathToOverride} from '@gob/examine-student'
import {AreaOfStudyProvider} from './provider'
import {AreaOfStudy} from './area-of-study'
import {
	changeStudent,
	type ChangeStudentFunc,
} from '../../redux/students/actions/change'

type Props = {
	areaOfStudy: AreaQuery,
	showCloseButton: boolean,
	showEditButton: boolean,
	student: Student,
	changeStudent: ChangeStudentFunc,
}

type State = {|
	isOpen: boolean,
	confirmRemoval: boolean,
|}

class AreaOfStudyConnector extends React.Component<Props, State> {
	state = {
		isOpen: false,
		confirmRemoval: false,
	}

	startRemovalConfirmation = (ev: Event) => {
		ev.stopPropagation()
		this.setState({confirmRemoval: true})
	}

	endRemovalConfirmation = (ev: Event) => {
		ev.stopPropagation()
		this.setState({confirmRemoval: false})
	}

	toggleAreaExpansion = (ev: Event) => {
		ev.stopPropagation()
		this.setState({isOpen: !this.state.isOpen})
	}

	addOverride = (path: string[], ev: Event) => {
		ev.stopPropagation()
		const codifiedPath = pathToOverride(path)
		let s = this.props.student.setOverride(codifiedPath, true)
		this.props.changeStudent(s)
	}

	removeOverride = (path: string[], ev: Event) => {
		ev.stopPropagation()
		const codifiedPath = pathToOverride(path)
		let s = this.props.student.removeOverride(codifiedPath)
		this.props.changeStudent(s)
	}

	toggleOverride = (path: string[], ev: Event) => {
		ev.stopPropagation()
		const codifiedPath = pathToOverride(path)

		if (this.props.student.hasOverride(codifiedPath)) {
			let s = this.props.student.removeOverride(codifiedPath)
			this.props.changeStudent(s)
		} else {
			let s = this.props.student.setOverride(codifiedPath, true)
			this.props.changeStudent(s)
		}
	}

	removeArea = (ev: SyntheticEvent<HTMLButtonElement>) => {
		ev.stopPropagation()
		let s = this.props.student.removeArea(this.props.areaOfStudy)
		this.props.changeStudent(s)
	}

	render() {
		let {areaOfStudy, student} = this.props

		return (
			<AreaOfStudyProvider areaOfStudy={areaOfStudy} student={student}>
				{({error, examining, results}) => {
					return (
						<AreaOfStudy
							areaOfStudy={areaOfStudy}
							error={error}
							examining={examining}
							results={results}
							onToggleOpen={this.toggleAreaExpansion}
							onRemove={this.removeArea}
							onAddOverride={this.addOverride}
							onRemoveOverride={this.removeOverride}
							onToggleOverride={this.toggleOverride}
							onRemovalStart={this.startRemovalConfirmation}
							onRemovalCancel={this.endRemovalConfirmation}
						/>
					)
				}}
			</AreaOfStudyProvider>
		)
	}
}

const connected = connect(
	undefined,
	{changeStudent},
)(AreaOfStudyConnector)

export {connected as ConnectedAreaOfStudy}<commit_msg>fix issues with buttons not working on the new split areas of study<commit_after>// @flow

import React from 'react'
import {connect} from 'react-redux'
import {Student, type AreaQuery} from '@gob/object-student'
import {pathToOverride} from '@gob/examine-student'
import {AreaOfStudyProvider} from './provider'
import {AreaOfStudy} from './area-of-study'
import {
	changeStudent,
	type ChangeStudentFunc,
} from '../../redux/students/actions/change'

type Props = {
	areaOfStudy: AreaQuery,
	showCloseButton: boolean,
	showEditButton: boolean,
	student: Student,
	changeStudent: ChangeStudentFunc,
}

type State = {|
	isOpen: boolean,
	confirmRemoval: boolean,
|}

class AreaOfStudyConnector extends React.Component<Props, State> {
	state = {
		isOpen: false,
		confirmRemoval: false,
	}

	startRemovalConfirmation = (ev: Event) => {
		ev.stopPropagation()
		this.setState({confirmRemoval: true})
	}

	endRemovalConfirmation = (ev: Event) => {
		ev.stopPropagation()
		this.setState({confirmRemoval: false})
	}

	toggleAreaExpansion = (ev: Event) => {
		ev.stopPropagation()
		this.setState({isOpen: !this.state.isOpen})
	}

	addOverride = (path: string[], ev: Event) => {
		ev.stopPropagation()
		const codifiedPath = pathToOverride(path)
		let s = this.props.student.setOverride(codifiedPath, true)
		this.props.changeStudent(s)
	}

	removeOverride = (path: string[], ev: Event) => {
		ev.stopPropagation()
		const codifiedPath = pathToOverride(path)
		let s = this.props.student.removeOverride(codifiedPath)
		this.props.changeStudent(s)
	}

	toggleOverride = (path: string[], ev: Event) => {
		ev.stopPropagation()
		const codifiedPath = pathToOverride(path)

		if (this.props.student.hasOverride(codifiedPath)) {
			let s = this.props.student.removeOverride(codifiedPath)
			this.props.changeStudent(s)
		} else {
			let s = this.props.student.setOverride(codifiedPath, true)
			this.props.changeStudent(s)
		}
	}

	removeArea = (ev: Event) => {
		ev.stopPropagation()
		let s = this.props.student.removeArea(this.props.areaOfStudy)
		this.props.changeStudent(s)
	}

	render() {
		let {areaOfStudy, student, showCloseButton, showEditButton} = this.props

		return (
			<AreaOfStudyProvider areaOfStudy={areaOfStudy} student={student}>
				{({error, examining, results}) => {
					return (
						<AreaOfStudy
							areaOfStudy={areaOfStudy}
							error={error}
							examining={examining}
							results={results}
							isOpen={this.state.isOpen}
							onToggleOpen={this.toggleAreaExpansion}
							onRemove={this.removeArea}
							onAddOverride={this.addOverride}
							onRemoveOverride={this.removeOverride}
							onToggleOverride={this.toggleOverride}
							onRemovalStart={this.startRemovalConfirmation}
							onRemovalCancel={this.endRemovalConfirmation}
							showCloseButton={showCloseButton}
							showEditButton={showEditButton}
							showConfirmRemoval={this.state.confirmRemoval}
						/>
					)
				}}
			</AreaOfStudyProvider>
		)
	}
}

const connected = connect(
	undefined,
	{changeStudent},
)(AreaOfStudyConnector)

export {connected as ConnectedAreaOfStudy}
{'fraction_non_alphanumeric': 0.12619567041449908, 'fraction_numerical': 0.0, 'mean_word_length': 4.316681534344335, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 28, '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': '5557322', 'n_tokens_mistral': 2249, 'n_tokens_neox': 1936, 'n_words': 361}