<commit_before>import * as React from 'react'
import { CSSTransitionGroup } from 'react-transition-group'

import { PullRequest } from '../../models/pull-request'
import { Repository } from '../../models/repository'
import { Branch } from '../../models/branch'
import { BranchesTab } from '../../models/branches-tab'

import { Dispatcher } from '../../lib/dispatcher'
import { FoldoutType, PopupType } from '../../lib/app-state'
import { assertNever } from '../../lib/fatal-error'

import { TabBar } from '../tab-bar'

import { BranchList } from './branch-list'
import { PullRequestList } from './pull-request-list'
import { PullRequestsLoading } from './pull-requests-loading'
import { IBranchListItem } from './group-branches'
import { renderDefaultBranch } from './branch-renderer'

const PullRequestsLoadingCrossFadeInTimeout = 300
const PullRequestsLoadingCrossFadeOutTimeout = 200

interface IBranchesContainerProps {
  readonly dispatcher: Dispatcher
  readonly repository: Repository
  readonly selectedTab: BranchesTab
  readonly allBranches: ReadonlyArray<Branch>
  readonly defaultBranch: Branch | null
  readonly currentBranch: Branch | null
  readonly recentBranches: ReadonlyArray<Branch>
  readonly pullRequests: ReadonlyArray<PullRequest>

  /** The pull request associated with the current branch. */
  readonly currentPullRequest: PullRequest | null

  /** Are we currently loading pull requests? */
  readonly isLoadingPullRequests: boolean
}

interface IBranchesContainerState {
  readonly selectedBranch: Branch | null
  readonly selectedPullRequest: PullRequest | null
  readonly branchFilterText: string
  readonly pullRequestFilterText: string
}

/** The unified Branches and Pull Requests component. */
export class BranchesContainer extends React.Component<
  IBranchesContainerProps,
  IBranchesContainerState
> {
  public constructor(props: IBranchesContainerProps) {
    super(props)

    this.state = {
      selectedBranch: props.currentBranch,
      selectedPullRequest: props.currentPullRequest,
      branchFilterText: '',
      pullRequestFilterText: '',
    }
  }

  public render() {
    return (
      <div className="branches-container">
        {this.renderTabBar()}
        {this.renderSelectedTab()}
      </div>
    )
  }

  private renderTabBar() {
    if (!this.props.repository.gitHubRepository) {
      return null
    }

    let countElement = null
    if (this.props.pullRequests) {
      countElement = (
        <span className="count">{this.props.pullRequests.length}</span>
      )
    }

    return (
      <TabBar
        onTabClicked={this.onTabClicked}
        selectedIndex={this.props.selectedTab}
      >
        <span>Branches</span>
        <span className="pull-request-tab">
          {__DARWIN__ ? 'Pull Requests' : 'Pull requests'}

          {countElement}
        </span>
      </TabBar>
    )
  }

  private renderBranch = (
    item: IBranchListItem,
    matches: ReadonlyArray<number>
  ) => {
    return renderDefaultBranch(item, matches, this.props.currentBranch)
  }

  private renderSelectedTab() {
    let tab = this.props.selectedTab
    if (!this.props.repository.gitHubRepository) {
      tab = BranchesTab.Branches
    }

    switch (tab) {
      case BranchesTab.Branches:
        return (
          <BranchList
            defaultBranch={this.props.defaultBranch}
            currentBranch={this.props.currentBranch}
            allBranches={this.props.allBranches}
            recentBranches={this.props.recentBranches}
            onItemClick={this.onBranchItemClick}
            filterText={this.state.branchFilterText}
            onFilterTextChanged={this.onBranchFilterTextChanged}
            selectedBranch={this.state.selectedBranch}
            onSelectionChanged={this.onBranchSelectionChanged}
            canCreateNewBranch={true}
            onCreateNewBranch={this.onCreateBranchWithName}
            renderBranch={this.renderBranch}<commit_msg>add the callback and switch to the compare tab<commit_after>import * as React from 'react'
import { CSSTransitionGroup } from 'react-transition-group'

import { PullRequest } from '../../models/pull-request'
import { Repository } from '../../models/repository'
import { Branch } from '../../models/branch'
import { BranchesTab } from '../../models/branches-tab'

import { Dispatcher } from '../../lib/dispatcher'
import {
  FoldoutType,
  PopupType,
  CompareActionKind,
  ComparisonView,
  RepositorySection,
} from '../../lib/app-state'
import { assertNever } from '../../lib/fatal-error'

import { TabBar } from '../tab-bar'

import { BranchList } from './branch-list'
import { PullRequestList } from './pull-request-list'
import { PullRequestsLoading } from './pull-requests-loading'
import { IBranchListItem } from './group-branches'
import { renderDefaultBranch } from './branch-renderer'

const PullRequestsLoadingCrossFadeInTimeout = 300
const PullRequestsLoadingCrossFadeOutTimeout = 200

interface IBranchesContainerProps {
  readonly dispatcher: Dispatcher
  readonly repository: Repository
  readonly selectedTab: BranchesTab
  readonly allBranches: ReadonlyArray<Branch>
  readonly defaultBranch: Branch | null
  readonly currentBranch: Branch | null
  readonly recentBranches: ReadonlyArray<Branch>
  readonly pullRequests: ReadonlyArray<PullRequest>

  /** The pull request associated with the current branch. */
  readonly currentPullRequest: PullRequest | null

  /** Are we currently loading pull requests? */
  readonly isLoadingPullRequests: boolean
}

interface IBranchesContainerState {
  readonly selectedBranch: Branch | null
  readonly selectedPullRequest: PullRequest | null
  readonly branchFilterText: string
  readonly pullRequestFilterText: string
}

/** The unified Branches and Pull Requests component. */
export class BranchesContainer extends React.Component<
  IBranchesContainerProps,
  IBranchesContainerState
> {
  public constructor(props: IBranchesContainerProps) {
    super(props)

    this.state = {
      selectedBranch: props.currentBranch,
      selectedPullRequest: props.currentPullRequest,
      branchFilterText: '',
      pullRequestFilterText: '',
    }
  }

  public render() {
    return (
      <div className="branches-container">
        {this.renderTabBar()}
        {this.renderSelectedTab()}
      </div>
    )
  }

  private renderTabBar() {
    if (!this.props.repository.gitHubRepository) {
      return null
    }

    let countElement = null
    if (this.props.pullRequests) {
      countElement = (
        <span className="count">{this.props.pullRequests.length}</span>
      )
    }

    return (
      <TabBar
        onTabClicked={this.onTabClicked}
        selectedIndex={this.props.selectedTab}
      >
        <span>Branches</span>
        <span className="pull-request-tab">
          {__DARWIN__ ? 'Pull Requests' : 'Pull requests'}

          {countElement}
        </span>
      </TabBar>
    )
  }

  private onCompareToBranch = async (branch: Branch) => {
    await this.props.dispatcher.initializeCompare(this.props.repository, {
      kind: CompareActionKind.Branch,
      branch,
      mode: ComparisonView.Ahead,
    })
    await this.props.dispatcher.changeRepositorySection(
      this.props.repository,
      RepositorySection.History
    )
    await this.props.dispatcher.closeFoldout(FoldoutType.Branch)
  }

  private renderBranch = (
    item: IBranchListItem,
    matches: ReadonlyArray<number>
  ) => {
    return renderDefaultBranch(
      item,
      matches,
      this.props.currentBranch,
      this.onCompareToBranch
    )
  }

  private renderSelectedTab() {
    let tab = this.props.selectedTab
    if (!this.props.repository.gitHubRepository) {
      tab = BranchesTab.Branches
    }

    switch (tab) {
      case BranchesTab.Branches:
        return (
          <BranchList
            defaultBranch={this.props.defaultBranch}
            currentBranch={this.props.currentBranch}
            allBranches={this.props.allBranches}
            recentBranches={this.props.recentBranches}
            onItemClick={this.onBranchItemClick}
            filterText={this.state.branchFilterText}
            onFilterTextChanged={this.onBranchFilterTextChanged}
            selectedBranch={this.state.selectedBranch}
            onSelectionChanged={this.onBranchSelectionChanged}
            canCreateNewBranch={true}
            onCreateNewBranch={this.onCreateBranchWithName}
            renderBranch={this.renderBranch}
{'fraction_non_alphanumeric': 0.10312204351939451, 'fraction_numerical': 0.0014191106906338694, 'mean_word_length': 3.1887072808320953, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 36, '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': '6070753', 'n_tokens_mistral': 2338, 'n_tokens_neox': 2363, 'n_words': 494}