<commit_before>import React from 'react'
import PropTypes from 'prop-types'
import AUheading from '@gov.au/headings/lib/js/react.js'
import format from 'date-fns/format'
import { rootPath } from 'marketplace/routes'
import NotVisible from 'marketplace/components/Icons/NotVisible/NotVisible'
import { getBriefLastQuestionDate } from 'marketplace/components/helpers'
import { AUcallout } from '@gov.au/callout/lib/js/react.js'
import EvaluationCriteria from './EvaluationCriteria'
import QuestionAnswer from './QuestionAnswer'
import OpportunityInfoCard from './OpportunityInfoCard'
import OpportunitySpecialistInfoCard from './OpportunitySpecialistInfoCard'
import styles from './Opportunity.scss'

// defining default brief data up here so render() has access to it
const defaultBriefProps = {
  id: 0,
  title: '',
  organisation: '',
  dates: {
    closing_time: '',
    questions_closing_date: '',
    questions_close: '',
    published_date: ''
  },
  status: '',
  summary: '',
  startDate: '',
  location: [],
  contractLength: '',
  budgetRange: '',
  securityClearance: '',
  sellerCategory: '',
  includeWeightings: false,
  evaluationCriteria: [],
  evaluationType: [],
  requirementsDocument: [],
  responseTemplate: [],
  attachments: [],
  proposalType: [],
  industryBriefing: '',
  workAlreadyDone: '',
  endUsers: '',
  backgroundInformation: '',
  outcome: '',
  timeframeConstraints: '',
  clarificationQuestions: [],
  clarificationQuestionsAreClosed: true,
  contactEmail: ''
}

const getClosingTime = brief => {
  if (brief.dates.closing_time) {
    return brief.dates.closing_time
  } else if (brief.closedAt) {
    return brief.closedAt
  }
  return ''
}

const getTrimmedFilename = fileName => {
  let newFileName = fileName
  if (fileName.length > 32) {
    // build a limited version of the file name, taking out chars from the middle
    newFileName = `${fileName.substring(0, 14)}...${fileName.substring(fileName.length - 15)}`
  }
  return newFileName
}

const getBriefCategory = (domains, briefCategory) => {
  const category = domains.find(domain => domain.id === briefCategory)
  return category ? category.name : null
}

const showATMObjectives = (lotSlug, isBuyer, canRespond) => {
  if (lotSlug === 'atm' && (isBuyer || canRespond)) {
    return true
  }
  return false
}

const Opportunity = props => {
  const {
    briefResponseCount,
    invitedSellerCount,
    supplierBriefResponseCount,
    canRespond,
    isAssessedForCategory,
    isAssessedForAnyCategory,
    hasChosenBriefCategory,
    isOpenToAll,
    isOpenToCategory,
    isBriefOwner,<commit_msg>Fix issue where null filename caused an oncaught error on the Opportunity page.<commit_after>import React from 'react'
import PropTypes from 'prop-types'
import AUheading from '@gov.au/headings/lib/js/react.js'
import format from 'date-fns/format'
import { rootPath } from 'marketplace/routes'
import NotVisible from 'marketplace/components/Icons/NotVisible/NotVisible'
import { getBriefLastQuestionDate } from 'marketplace/components/helpers'
import { AUcallout } from '@gov.au/callout/lib/js/react.js'
import EvaluationCriteria from './EvaluationCriteria'
import QuestionAnswer from './QuestionAnswer'
import OpportunityInfoCard from './OpportunityInfoCard'
import OpportunitySpecialistInfoCard from './OpportunitySpecialistInfoCard'
import styles from './Opportunity.scss'

// defining default brief data up here so render() has access to it
const defaultBriefProps = {
  id: 0,
  title: '',
  organisation: '',
  dates: {
    closing_time: '',
    questions_closing_date: '',
    questions_close: '',
    published_date: ''
  },
  status: '',
  summary: '',
  startDate: '',
  location: [],
  contractLength: '',
  budgetRange: '',
  securityClearance: '',
  sellerCategory: '',
  includeWeightings: false,
  evaluationCriteria: [],
  evaluationType: [],
  requirementsDocument: [],
  responseTemplate: [],
  attachments: [],
  proposalType: [],
  industryBriefing: '',
  workAlreadyDone: '',
  endUsers: '',
  backgroundInformation: '',
  outcome: '',
  timeframeConstraints: '',
  clarificationQuestions: [],
  clarificationQuestionsAreClosed: true,
  contactEmail: ''
}

const getClosingTime = brief => {
  if (brief.dates.closing_time) {
    return brief.dates.closing_time
  } else if (brief.closedAt) {
    return brief.closedAt
  }
  return ''
}

const getTrimmedFilename = fileName => {
  let newFileName = fileName
  if (fileName && fileName.length > 32) {
    // build a limited version of the file name, taking out chars from the middle
    newFileName = `${fileName.substring(0, 14)}...${fileName.substring(fileName.length - 15)}`
  }
  return newFileName
}

const getBriefCategory = (domains, briefCategory) => {
  const category = domains.find(domain => domain.id === briefCategory)
  return category ? category.name : null
}

const showATMObjectives = (lotSlug, isBuyer, canRespond) => {
  if (lotSlug === 'atm' && (isBuyer || canRespond)) {
    return true
  }
  return false
}

const Opportunity = props => {
  const {
    briefResponseCount,
    invitedSellerCount,
    supplierBriefResponseCount,
    canRespond,
    isAssessedForCategory,
    isAssessedForAnyCategory,
    hasChosenBriefCategory,
    isOpenToAll,
    isOpenToCategory,
    isBriefOwner,
{'fraction_non_alphanumeric': 0.11959818043972707, 'fraction_numerical': 0.003032600454890068, 'mean_word_length': 4.33030303030303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7316582', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1574, 'n_words': 380}