<commit_before>import _ from 'intl'
import ActionRow from 'action-row-button'
import Component from 'base-component'
import Icon from 'icon'
import Link from 'link'
import React from 'react'
import renderXoItem, { renderXoUnknownItem } from 'render-xo-item'
import SortedTable from 'sorted-table'
import { concat, isEmpty } from 'lodash'
import { connectStore, formatSize } from 'utils'
import { Container, Row, Col } from 'grid'
import { createGetObject, createSelector } from 'selectors'
import { deleteVdi, editVdi } from 'xo'
import { Text } from 'editable'

// ===================================================================

const COLUMNS = [
  {
    name: _('vdiNameLabel'),
    itemRenderer: vdi => (
      <span>
        <Text value={vdi.name_label} onChange={value => editVdi(vdi, { name_label: value })} />
        {' '}
        {vdi.type === 'VDI-snapshot' &&
          <span className='tag tag-info'>
            <Icon icon='vm-snapshot' />
          </span>
        }
      </span>
    ),
    sortCriteria: vdi => vdi.name_label
  },
  {
    name: _('vdiNameDescription'),
    itemRenderer: vdi => (
      <Text value={vdi.name_description} onChange={value => editVdi(vdi, { name_description: value })} />
    )
  },
  {
    name: _('vdiVm'),
    component: connectStore(() => {
      const getObject = createGetObject((_, id) => id)

      return {
        vm: (state, { item: vdi }) => {
          const vbd = getObject(state, vdi.$VBDs[0])
          if (vbd != null) {
            return getObject(state, vbd.VM)
          }
        }
      }
    })(({ vm }) => {
      if (vm === undefined) {
        return renderXoUnknownItem()
      }

      return <Link to={`/vms/${
        vm.type === 'VM-snapshot'
        ? `${vm.$snapshot_of}/snapshots`
        : vm.id
      }`}>
        {renderXoItem(vm)}
      </Link>
    })
  },
  {
    name: _('vdiTags'),
    itemRenderer: vdi => vdi.tags
  },
  {
    name: _('vdiSize'),
    itemRenderer: vdi => formatSize(vdi.size),
    sortCriteria: vdi => vdi.size
  },
  {
    name: _('vdiAction'),
    itemRenderer: vdi => (
      <ActionRow
        btnStyle='danger'
        handler={deleteVdi}<commit_msg>fix(sr/disks): difference between no VM and unknown VM<commit_after>import _ from 'intl'
import ActionRow from 'action-row-button'
import Component from 'base-component'
import Icon from 'icon'
import Link from 'link'
import React from 'react'
import renderXoItem, { renderXoUnknownItem } from 'render-xo-item'
import SortedTable from 'sorted-table'
import { concat, isEmpty } from 'lodash'
import { connectStore, formatSize } from 'utils'
import { Container, Row, Col } from 'grid'
import { createGetObject, createSelector } from 'selectors'
import { deleteVdi, editVdi } from 'xo'
import { Text } from 'editable'

// ===================================================================

const COLUMNS = [
  {
    name: _('vdiNameLabel'),
    itemRenderer: vdi => (
      <span>
        <Text value={vdi.name_label} onChange={value => editVdi(vdi, { name_label: value })} />
        {' '}
        {vdi.type === 'VDI-snapshot' &&
          <span className='tag tag-info'>
            <Icon icon='vm-snapshot' />
          </span>
        }
      </span>
    ),
    sortCriteria: vdi => vdi.name_label
  },
  {
    name: _('vdiNameDescription'),
    itemRenderer: vdi => (
      <Text value={vdi.name_description} onChange={value => editVdi(vdi, { name_description: value })} />
    )
  },
  {
    name: _('vdiVm'),
    component: connectStore(() => {
      const getObject = createGetObject((_, id) => id)

      return {
        vm: (state, { item: { $VBDs: [ vbdId ] } }) => {
          if (vbdId === undefined) {
            return null
          }

          const vbd = getObject(state, vbdId)
          if (vbd != null) {
            return getObject(state, vbd.VM)
          }
        }
      }
    })(({ vm }) => {
      if (vm === null) {
        return null // no attached VM
      }

      if (vm === undefined) {
        return renderXoUnknownItem()
      }

      return <Link to={`/vms/${
        vm.type === 'VM-snapshot'
        ? `${vm.$snapshot_of}/snapshots`
        : vm.id
      }`}>
        {renderXoItem(vm)}
      </Link>
    })
  },
  {
    name: _('vdiTags'),
    itemRenderer: vdi => vdi.tags
  },
  {
    name: _('vdiSize'),
    itemRenderer: vdi => formatSize(vdi.size),
    sortCriteria: vdi => vdi.size
  },
  {
    name: _('vdiAction'),
    itemRenderer: vdi => (
      <ActionRow
        btnStyle='danger'
        handler={deleteVdi}
{'fraction_non_alphanumeric': 0.18045444517979264, 'fraction_numerical': 0.00022060445621001543, 'mean_word_length': 2.416729464958553, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 47, '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': '3278602', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1483, 'n_words': 332}