<commit_before>import React from 'react'

import ActionButton from './action-button'
import Component from './base-component'
import propTypes from './prop-types'
import { connectStore } from './utils'
import { SelectVdi } from './select-objects'
import {
  createGetObjectsOfType,
  createFinder,
  createGetObject,
  createSelector
} from './selectors'
import {
  ejectCd,
  insertCd
} from './xo'

@propTypes({
  vm: propTypes.object.isRequired
})
@connectStore(() => {
  const getCdDrive = createFinder(
    createGetObjectsOfType('VBD').pick(
      (_, { vm }) => vm.$VBDs
    ),
    [ vbd => vbd.is_cd_drive ]
  )

  const getMountedIso = createGetObject(
    (state, props) => {
      const cdDrive = getCdDrive(state, props)
      if (cdDrive) {
        return cdDrive.VDI
      }
    }
  )

  return {
    cdDrive: getCdDrive,
    mountedIso: getMountedIso
  }
})
export default class IsoDevice extends Component {
  _getPredicate = createSelector(
    () => this.props.vm.$pool,
    poolId => sr => sr.$pool === poolId && sr.SR_type === 'iso'
  )

  _handleInsert = iso => {
    const { vm } = this.props

    if (iso) {
      insertCd(vm, iso.id, true)
    } else {
      ejectCd(vm)
    }
  }

  _handleEject = () => ejectCd(this.props.vm)

  render () {
    const { mountedIso } = this.props

    return (
      <div className='input-group'>
        <SelectVdi
          srPredicate={this._getPredicate()}
          onChange={this._handleInsert}
          value={mountedIso}
        />
        <span className='input-group-btn'>
          <ActionButton
            btnStyle='secondary'
            disabled={!mountedIso}
            handler={this._handleEject}
            icon='vm-eject'
          /><commit_msg>feat(iso-device): show DVDs in ISO selector (#1889)<commit_after>import React from 'react'

import ActionButton from './action-button'
import Component from './base-component'
import propTypes from './prop-types'
import { connectStore } from './utils'
import { SelectVdi } from './select-objects'
import {
  createGetObjectsOfType,
  createFinder,
  createGetObject,
  createSelector
} from './selectors'
import {
  ejectCd,
  insertCd
} from './xo'

@propTypes({
  vm: propTypes.object.isRequired
})
@connectStore(() => {
  const getCdDrive = createFinder(
    createGetObjectsOfType('VBD').pick(
      (_, { vm }) => vm.$VBDs
    ),
    [ vbd => vbd.is_cd_drive ]
  )

  const getMountedIso = createGetObject(
    (state, props) => {
      const cdDrive = getCdDrive(state, props)
      if (cdDrive) {
        return cdDrive.VDI
      }
    }
  )

  return {
    cdDrive: getCdDrive,
    mountedIso: getMountedIso
  }
})
export default class IsoDevice extends Component {
  _getPredicate = createSelector(
    () => this.props.vm.$pool,
    () => this.props.vm.$container,
    (vmPool, vmContainer) => sr => {
      const vmRunning = vmContainer !== vmPool
      const sameHost = vmContainer === sr.$container
      const samePool = vmPool === sr.$pool

      return (
        samePool && (vmRunning ? sr.shared || sameHost : true) &&
        sr.SR_type === 'iso' || sr.SR_type === 'udev' && sr.size
      )
    }
  )

  _handleInsert = iso => {
    const { vm } = this.props

    if (iso) {
      insertCd(vm, iso.id, true)
    } else {
      ejectCd(vm)
    }
  }

  _handleEject = () => ejectCd(this.props.vm)

  render () {
    const { mountedIso } = this.props

    return (
      <div className='input-group'>
        <SelectVdi
          srPredicate={this._getPredicate()}
          onChange={this._handleInsert}
          value={mountedIso}
        />
        <span className='input-group-btn'>
          <ActionButton
            btnStyle='secondary'
            disabled={!mountedIso}
            handler={this._handleEject}
            icon='vm-eject'
          />
{'fraction_non_alphanumeric': 0.13568235603470943, 'fraction_numerical': 0.001051801209571391, 'mean_word_length': 2.442533936651584, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 30, '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': '1427589', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1216, 'n_words': 253}