<commit_before>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router';
import itsSet from 'its-set';
import { FormattedMessage, intlShape } from 'react-intl';
import moment from 'moment';
import LoadingSpinner from '../common/LoadingSpinner';
import ContextMenu from '../common/ContextMenu';
import {
  getTitle, getType, getId,
  getErrorMessage, isPending,
  isFailed, isOk, getStatus, getIconUrl,
  getAuthor, getCreatedTimestamp,
  getSource, isUpdatable,
} from '../../domain/entity';
import { abbr } from '../../utilities/utils';

function getCollectionContextMenuItem(collections, currentCollection) {
  if (currentCollection) {
    return ({
      label: (
        <FormattedMessage
          id="remove_collection"
          values={{ title: currentCollection.title }}
        />
      ),
      value: `remove-from-collection:${currentCollection.id}`,
    });
  }

  return ({
    label: <FormattedMessage id="add_to_collection" />,
    value: 'add-to-collection:new',
    subMenu: [
      ...Object.keys(collections).map(key => ({
        value: `add-to-collection:${key}`,
        label: collections[key].title,
      })),
      {
        label: <FormattedMessage id="new_collection" />,
        value: 'add-to-collection:new',
        customClass: 'newCollection',
      },
    ],
  });
}

function contextMenuOptions(entity, collections, currentCollection) {
  const options = [
    {
      label: <FormattedMessage id="duplicate" />,
      value: 'duplicate',
      customClass: 'notImplemented',
    }, {
      label: <FormattedMessage id="set_permissions" />,
      value: 'set-permissions',
      customClass: 'notImplemented',
    }, {
      label: <FormattedMessage id="add_to_dashboard" />,
      value: 'add-to-dashboard',
      customClass: 'notImplemented',
    },
    getCollectionContextMenuItem(collections, currentCollection),
    {
      label: <FormattedMessage id="view_details" />,
      value: 'view-details',
      customClass: 'notImplemented',
    }, {
      label: <FormattedMessage id="delete" />,
      value: 'delete',
    },
  ];

  if (isUpdatable(entity)) {
    options.push({<commit_msg>Avoid add-to-collection opt in case of failing dataset [#1546]<commit_after>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router';
import itsSet from 'its-set';
import { FormattedMessage, intlShape } from 'react-intl';
import moment from 'moment';
import LoadingSpinner from '../common/LoadingSpinner';
import ContextMenu from '../common/ContextMenu';
import {
  getTitle, getType, getId,
  getErrorMessage, isPending,
  isFailed, isOk, getStatus, getIconUrl,
  getAuthor, getCreatedTimestamp,
  getSource, isUpdatable,
} from '../../domain/entity';
import { abbr } from '../../utilities/utils';

function getCollectionContextMenuItem(entity, collections, currentCollection) {
  if (currentCollection) {
    return ({
      label: (
        <FormattedMessage
          id="remove_collection"
          values={{ title: currentCollection.title }}
        />
      ),
      value: `remove-from-collection:${currentCollection.id}`,
    });
  }

  return (isFailed(entity) ? null : {
    label: <FormattedMessage id="add_to_collection" />,
    value: 'add-to-collection:new',
    subMenu: [
      ...Object.keys(collections).map(key => ({
        value: `add-to-collection:${key}`,
        label: collections[key].title,
      })),
      {
        label: <FormattedMessage id="new_collection" />,
        value: 'add-to-collection:new',
        customClass: 'newCollection',
      },
    ],
  });
}

function contextMenuOptions(entity, collections, currentCollection) {
  const options = [
    {
      label: <FormattedMessage id="duplicate" />,
      value: 'duplicate',
      customClass: 'notImplemented',
    }, {
      label: <FormattedMessage id="set_permissions" />,
      value: 'set-permissions',
      customClass: 'notImplemented',
    }, {
      label: <FormattedMessage id="add_to_dashboard" />,
      value: 'add-to-dashboard',
      customClass: 'notImplemented',
    },
    getCollectionContextMenuItem(entity, collections, currentCollection),
    {
      label: <FormattedMessage id="view_details" />,
      value: 'view-details',
      customClass: 'notImplemented',
    }, {
      label: <FormattedMessage id="delete" />,
      value: 'delete',
    },
  ].filter(opt => (opt !== null));

  if (isUpdatable(entity)) {
    options.push({
{'fraction_non_alphanumeric': 0.14647699488775284, 'fraction_numerical': 0.0008890864636585908, 'mean_word_length': 3.189944134078212, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 22, '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': '930565', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1335, 'n_words': 276}