<commit_before>/*
 * Copyright (C) 2017 - present Instructure, Inc.
 *
 * This module is part of Canvas.
 *
 * This module and Canvas are free software: you can redistribute them and/or modify them under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * This module and Canvas are distributed in the hope that they will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */
import formatMessage from '../format-message';
import _ from 'lodash';

const PILL_MAPPING = {
  'missing': { id: 'missing', text: formatMessage('Missing'), variant: 'danger' },
  'late': { id: 'late', text: formatMessage('Late'), variant: 'danger' },
  'graded': { id: 'graded', text: formatMessage('Graded') },
  'excused': { id: 'excused', text: formatMessage('Excused') },
  'submitted': { id: 'submitted', text: formatMessage('Submitted') },
  'new_grades': { id: 'new_grades', text: formatMessage('New Grades') },
  'new_feedback': { id: 'new_feedback', text: formatMessage('New Feedback') },
  'new_replies': { id: 'new_replies', text: formatMessage('New Replies') },
};

export function isNewActivityItem (item) {
  return item.newActivity;
}

export function anyNewActivity (items) {
  return items && items.some(isNewActivityItem);
}

/**
* Returns an array of pill objects that the particular item
* qualifies to have
*/
export function getBadgesForItem (item) {
  let badges = [];
  if (item.status) {
    badges = Object.keys(item.status)
      .filter(key => item.status[key] && PILL_MAPPING.hasOwnProperty(key))
      .map(a => PILL_MAPPING[a]);

    if (item.status.unread_count) {
      badges.push(PILL_MAPPING.new_replies);
    }
    if (item.newActivity && item.status.has_feedback) {
      badges.push(PILL_MAPPING.new_feedback);
    }
  }

  return badges;
}

/**
* Returns an array of pill objects that the items qualify to have
*/
export function getBadgesForItems (items) {
  const badges = [];
  if (items.some(i => i.status && i.newActivity && i.status.graded)) {
    badges.push(PILL_MAPPING.new_grades);
  }
  if (items.some(i => i.status && i.newActivity && i.status.has_feedback)) {
    badges.push(PILL_MAPPING.new_feedback);
  }
  if (items.some(i => i.status && i.status.unread_count)) {
    badges.push(PILL_MAPPING.new_replies);
  }
  return badges;
}<commit_msg>fix pill localization<commit_after>/*
 * Copyright (C) 2017 - present Instructure, Inc.
 *
 * This module is part of Canvas.
 *
 * This module and Canvas are free software: you can redistribute them and/or modify them under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * This module and Canvas are distributed in the hope that they will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */
import formatMessage from '../format-message';
import _ from 'lodash';

const PILL_MAPPING = {
  'missing': () => ({ id: 'missing', text: formatMessage('Missing'), variant: 'danger' }),
  'late': () => ({ id: 'late', text: formatMessage('Late'), variant: 'danger' }),
  'graded': () => ({ id: 'graded', text: formatMessage('Graded') }),
  'excused': () => ({ id: 'excused', text: formatMessage('Excused') }),
  'submitted': () => ({ id: 'submitted', text: formatMessage('Submitted') }),
  'new_grades': () => ({ id: 'new_grades', text: formatMessage('New Grades') }),
  'new_feedback': () => ({ id: 'new_feedback', text: formatMessage('New Feedback') }),
  'new_replies': () => ({ id: 'new_replies', text: formatMessage('New Replies') }),
};

export function isNewActivityItem (item) {
  return item.newActivity;
}

export function anyNewActivity (items) {
  return items && items.some(isNewActivityItem);
}

/**
* Returns an array of pill objects that the particular item
* qualifies to have
*/
export function getBadgesForItem (item) {
  let badges = [];
  if (item.status) {
    badges = Object.keys(item.status)
      .filter(key => item.status[key] && PILL_MAPPING.hasOwnProperty(key))
      .map(a => PILL_MAPPING[a]());

    if (item.status.unread_count) {
      badges.push(PILL_MAPPING.new_replies());
    }
    if (item.newActivity && item.status.has_feedback) {
      badges.push(PILL_MAPPING.new_feedback());
    }
  }

  return badges;
}

/**
* Returns an array of pill objects that the items qualify to have
*/
export function getBadgesForItems (items) {
  const badges = [];
  if (items.some(i => i.status && i.newActivity && i.status.graded)) {
    badges.push(PILL_MAPPING.new_grades());
  }
  if (items.some(i => i.status && i.newActivity && i.status.has_feedback)) {
    badges.push(PILL_MAPPING.new_feedback());
  }
  if (items.some(i => i.status && i.status.unread_count)) {
    badges.push(PILL_MAPPING.new_replies());
  }
  return badges;
}
{'fraction_non_alphanumeric': 0.14312198739340007, 'fraction_numerical': 0.0018539117538005192, 'mean_word_length': 4.084825636192272, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '216193', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1692, 'n_words': 510}