<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import TableCell from '@material-ui/core/TableCell';

function truncate(str) {
  const length = 32;
  const dots = str.length > length ? '...' : '';
  return `${str.substring(0, length)}${dots}`;
}

function formatMultipleChoice(value) {
  const choices = value.split(', ');
  const newValue = choices.slice(0, 3);
  if (choices.length > 3) {
    newValue[2] = `${newValue[2]} + ${choices.length - 3}`;
  }
  return newValue;
}

export default function MetadataCell({ projectMedia, field, type }) {
  let value = projectMedia.list_columns_values[field];

  if (value) {
    switch (type) {
    case 'free_text':
      value = typeof value === 'string' ? truncate(value) : value;
      break;
    case 'file_upload':
      value = <b>{value}</b>;
      break;
    case 'multiple_choice':
      value = formatMultipleChoice(value).map(v => <div>{v}</div>);
      break;
    case 'datetime':
      value = value.replace('at 00:00 notime', '').replace(/\(.*\)/, '');
      break;
    default:
      break;
    }
  }

  return (
    <TableCell align="left" title={value}>
      {value}
    </TableCell>
  );
}

MetadataCell.propTypes = {
  field: PropTypes.string.isRequired,
  type: PropTypes.string.isRequired,
  projectMedia: PropTypes.shape({<commit_msg>Ticket #8804: Removing title from metadata cell<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import TableCell from '@material-ui/core/TableCell';

function truncate(str) {
  const length = 32;
  const dots = str.length > length ? '...' : '';
  return `${str.substring(0, length)}${dots}`;
}

function formatMultipleChoice(value) {
  const choices = value.split(', ');
  const newValue = choices.slice(0, 3);
  if (choices.length > 3) {
    newValue[2] = `${newValue[2]} + ${choices.length - 3}`;
  }
  return newValue;
}

export default function MetadataCell({ projectMedia, field, type }) {
  let value = projectMedia.list_columns_values[field];

  if (value) {
    switch (type) {
    case 'free_text':
      value = typeof value === 'string' ? truncate(value) : value;
      break;
    case 'file_upload':
      value = <b>{value}</b>;
      break;
    case 'multiple_choice':
      value = formatMultipleChoice(value).map(v => <div>{v}</div>);
      break;
    case 'datetime':
      value = value.replace('at 00:00 notime', '').replace(/\(.*\)/, '');
      break;
    default:
      break;
    }
  }

  return (
    <TableCell align="left">
      {value}
    </TableCell>
  );
}

MetadataCell.propTypes = {
  field: PropTypes.string.isRequired,
  type: PropTypes.string.isRequired,
  projectMedia: PropTypes.shape({
{'fraction_non_alphanumeric': 0.1651752423564504, 'fraction_numerical': 0.011185682326621925, 'mean_word_length': 3.2996794871794872, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '6344245', 'n_tokens_mistral': 890, 'n_tokens_neox': 881, 'n_words': 202}