<commit_before>import * as React from 'react'
import { ChangesList } from './changes-list'
import FileDiff from '../file-diff'
import { IChangesState } from '../../lib/app-state'
import Repository from '../../models/repository'
import { Dispatcher } from '../../lib/dispatcher'

interface IChangesProps {
  repository: Repository
  changes: IChangesState
  dispatcher: Dispatcher
}

/** TODO: handle "repository not found" scenario */

export class Changes extends React.Component<IChangesProps, void> {
  private onCreateCommit(title: string) {
    this.props.dispatcher.commitSelectedChanges(this.props.repository, title)
  }

  private handleSelectionChanged(row: number) {
    const file = this.props.changes.workingDirectory.files[row]
    this.props.dispatcher.changeChangesSelection(this.props.repository, file.path)
  }

  private handleIncludeChanged(row: number, include: boolean) {

    const workingDirectory = this.props.changes.workingDirectory

    const foundFile = workingDirectory.files[row]

    if (!foundFile) {
      console.error('unable to find working directory path to apply included change: ' + row)
      return
    }

    foundFile.include = include

    const allSelected = workingDirectory.files.every((f, index, array) => {
      return f.include
    })

    const noneSelected = workingDirectory.files.every((f, index, array) => {
      return !f.include
    })

    if (allSelected && !noneSelected) {
      workingDirectory.includeAll = true
    } else if (!allSelected && noneSelected) {
      workingDirectory.includeAll = false
    } else {
      workingDirectory.includeAll = null
    }

    this.setState(Object.assign({}, this.state, { workingDirectory: workingDirectory }))
  }

  private handleSelectAll(selectAll: boolean) {
    const workingDirectory = this.props.changes.workingDirectory

    workingDirectory.includeAll = selectAll
    workingDirectory.includeAllFiles(selectAll)

    this.setState(Object.assign({}, this.state, { workingDirectory: workingDirectory }))
  }

  private renderNoSelection() {
    return (
      <div id='changes'>
        <div>No repo selected!</div>
      </div>
    )
  }

  public render() {

    const repo = this.props.repository
    if (!repo) {
      return this.renderNoSelection()
    }

    return (
      <div id='changes'>
        <ChangesList repository={this.props.repository}
                     workingDirectory={this.props.changes.workingDirectory}
                     selectedPath={this.props.changes.selectedPath!}
                     onSelectionChanged={event => this.handleSelectionChanged(event)}
                     onCreateCommit={title => this.onCreateCommit(title)}
                     onIncludeChanged={(row, include) => this.handleIncludeChanged(row, include) }
                     onSelectAll={selectAll => this.handleSelectAll(selectAll) }/>

         <FileDiff repository={this.props.repository}
                   relativePath={this.props.changes.selectedPath}
                   readOnly={false}
                   commit={null} />
      </div>
    )
  }
}
<commit_msg>s/handle/on<commit_after>import * as React from 'react'
import { ChangesList } from './changes-list'
import FileDiff from '../file-diff'
import { IChangesState } from '../../lib/app-state'
import Repository from '../../models/repository'
import { Dispatcher } from '../../lib/dispatcher'

interface IChangesProps {
  repository: Repository
  changes: IChangesState
  dispatcher: Dispatcher
}

/** TODO: handle "repository not found" scenario */

export class Changes extends React.Component<IChangesProps, void> {
  private onCreateCommit(title: string) {
    this.props.dispatcher.commitSelectedChanges(this.props.repository, title)
  }

  private onSelectionChanged(row: number) {
    const file = this.props.changes.workingDirectory.files[row]
    this.props.dispatcher.changeChangesSelection(this.props.repository, file.path)
  }

  private onIncludeChanged(row: number, include: boolean) {

    const workingDirectory = this.props.changes.workingDirectory

    const foundFile = workingDirectory.files[row]

    if (!foundFile) {
      console.error('unable to find working directory path to apply included change: ' + row)
      return
    }

    foundFile.include = include

    const allSelected = workingDirectory.files.every((f, index, array) => {
      return f.include
    })

    const noneSelected = workingDirectory.files.every((f, index, array) => {
      return !f.include
    })

    if (allSelected && !noneSelected) {
      workingDirectory.includeAll = true
    } else if (!allSelected && noneSelected) {
      workingDirectory.includeAll = false
    } else {
      workingDirectory.includeAll = null
    }

    this.setState(Object.assign({}, this.state, { workingDirectory: workingDirectory }))
  }

  private onSelectAll(selectAll: boolean) {
    const workingDirectory = this.props.changes.workingDirectory

    workingDirectory.includeAll = selectAll
    workingDirectory.includeAllFiles(selectAll)

    this.setState(Object.assign({}, this.state, { workingDirectory: workingDirectory }))
  }

  private renderNoSelection() {
    return (
      <div id='changes'>
        <div>No repo selected!</div>
      </div>
    )
  }

  public render() {

    const repo = this.props.repository
    if (!repo) {
      return this.renderNoSelection()
    }

    return (
      <div id='changes'>
        <ChangesList repository={this.props.repository}
                     workingDirectory={this.props.changes.workingDirectory}
                     selectedPath={this.props.changes.selectedPath!}
                     onSelectionChanged={event => this.onSelectionChanged(event)}
                     onCreateCommit={title => this.onCreateCommit(title)}
                     onIncludeChanged={(row, include) => this.onIncludeChanged(row, include) }
                     onSelectAll={selectAll => this.onSelectAll(selectAll) }/>

         <FileDiff repository={this.props.repository}
                   relativePath={this.props.changes.selectedPath}
                   readOnly={false}
                   commit={null} />
      </div>
    )
  }
}

{'fraction_non_alphanumeric': 0.11356980149690855, 'fraction_numerical': 0.0, 'mean_word_length': 2.9127943984723106, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, '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': '5258447', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1612, 'n_words': 342}