<commit_before>import _groupBy from 'lodash/groupBy'
import PropTypes from 'prop-types'
import {injectIntl, FormattedMessage} from 'react-intl'
import {Icon, LoadingSpinner} from 'tocco-ui'
import {download} from 'tocco-util'

import {resultTypes} from '../../api'
import {notificationPropType, TYPES} from '../../types'
import {
  StyledCancelWrapper,
  StyledDetailLinkWrapper,
  StyledFileDescription,
  StyledIconWrapper,
  StyledMessage,
  StyledOutputJobWrapper,
  StyledProgressInner,
  StyledProgressOuter,
  StyledSpinnerWrapper,
  StyledTaskProgressWrapper
} from './StyledComponents'

const Result = injectIntl(({notification: {result}, navigationStrategy, intl}) => {
  const {type, file, content} = result

  const msg = id => intl.formatMessage({id})

  const openLinkTitle = msg('client.common.notification.outputJobFileLink')
  const downloadLinkTitle = msg('client.common.notification.outputJobFileDownload')

  if (type === resultTypes.outputjob) {
    if (file) {
      return (
        <StyledOutputJobWrapper>
          <StyledFileDescription>
            <a href={file.link} target="_blank" rel="noreferrer" title={openLinkTitle}>
              {file.description}
            </a>
          </StyledFileDescription>
          <div>
            <a href={file.link} target="_blank" rel="noreferrer" title={openLinkTitle}>
              <StyledIconWrapper>
                <Icon icon="external-link" />
              </StyledIconWrapper>
              <FormattedMessage id="client.common.notification.outputJobFileLink" />
            </a>
          </div>
          {download.downloadSupportedByBrowser() && (
            <a
              href={download.addParameterToURL(file.link, 'download', true)}
              target="_blank"
              rel="noreferrer"
              title={downloadLinkTitle}
            >
              <StyledIconWrapper>
                <Icon icon="arrow-to-bottom" />
              </StyledIconWrapper>
              <FormattedMessage id="client.common.notification.outputJobFileDownload" />
            </a>
          )}
          <StyledDetailLinkWrapper>
            {navigationStrategy && navigationStrategy.DetailLink && (
              <navigationStrategy.DetailLink entityName={content[0].model} entityKey={content[0].key}>
                <Icon icon="arrow-right" /> <FormattedMessage id="client.common.notification.outputJobOpen" />
              </navigationStrategy.DetailLink>
            )}
          </StyledDetailLinkWrapper>
        </StyledOutputJobWrapper>
      )
    } else {
      return null
    }
  }

  if (type === resultTypes.entities) {
    return (
      <>
        {Object.entries(_groupBy(content, e => e.model)).map(([model, entities]) => (
          <StyledDetailLinkWrapper key={'entitylink-' + model}>
            {navigationStrategy && navigationStrategy.ListOrDetailLink && (
              <navigationStrategy.ListOrDetailLink entityName={model} entityKeys={entities.map(e => e.key)}>
                <Icon icon="arrow-right" /> <FormattedMessage id="client.common.notification.entitiesOpen" />
              </navigationStrategy.ListOrDetailLink>
            )}
          </StyledDetailLinkWrapper>
        ))}
      </>
    )
  }

  return null
})

Result.propTypes = {
  intl: PropTypes.object.isRequired,
  notification: notificationPropType.isRequired,<commit_msg>feat(app-extensions): add model name to notification<commit_after>import _groupBy from 'lodash/groupBy'
import PropTypes from 'prop-types'
import {injectIntl, FormattedMessage} from 'react-intl'
import {Icon, LoadingSpinner} from 'tocco-ui'
import {download} from 'tocco-util'

import {resultTypes} from '../../api'
import {notificationPropType, TYPES} from '../../types'
import {
  StyledCancelWrapper,
  StyledDetailLinkWrapper,
  StyledFileDescription,
  StyledIconWrapper,
  StyledMessage,
  StyledOutputJobWrapper,
  StyledProgressInner,
  StyledProgressOuter,
  StyledSpinnerWrapper,
  StyledTaskProgressWrapper
} from './StyledComponents'

const Result = injectIntl(({notification: {result}, navigationStrategy, intl}) => {
  const {type, file, content} = result

  const msg = id => intl.formatMessage({id})

  const openLinkTitle = msg('client.common.notification.outputJobFileLink')
  const downloadLinkTitle = msg('client.common.notification.outputJobFileDownload')

  if (type === resultTypes.outputjob) {
    if (file) {
      return (
        <StyledOutputJobWrapper>
          <StyledFileDescription>
            <a href={file.link} target="_blank" rel="noreferrer" title={openLinkTitle}>
              {file.description}
            </a>
          </StyledFileDescription>
          <div>
            <a href={file.link} target="_blank" rel="noreferrer" title={openLinkTitle}>
              <StyledIconWrapper>
                <Icon icon="external-link" />
              </StyledIconWrapper>
              <FormattedMessage id="client.common.notification.outputJobFileLink" />
            </a>
          </div>
          {download.downloadSupportedByBrowser() && (
            <a
              href={download.addParameterToURL(file.link, 'download', true)}
              target="_blank"
              rel="noreferrer"
              title={downloadLinkTitle}
            >
              <StyledIconWrapper>
                <Icon icon="arrow-to-bottom" />
              </StyledIconWrapper>
              <FormattedMessage id="client.common.notification.outputJobFileDownload" />
            </a>
          )}
          <StyledDetailLinkWrapper>
            {navigationStrategy && navigationStrategy.DetailLink && (
              <navigationStrategy.DetailLink entityName={content[0].model} entityKey={content[0].key}>
                <Icon icon="arrow-right" /> <FormattedMessage id="client.common.notification.outputJobOpen" />
              </navigationStrategy.DetailLink>
            )}
          </StyledDetailLinkWrapper>
        </StyledOutputJobWrapper>
      )
    } else {
      return null
    }
  }

  if (type === resultTypes.entities) {
    return (
      <>
        {Object.entries(_groupBy(content, e => e.model)).map(([model, entities]) => (
          <StyledDetailLinkWrapper key={'entitylink-' + model}>
            {navigationStrategy && navigationStrategy.ListOrDetailLink && (
              <navigationStrategy.ListOrDetailLink entityName={model} entityKeys={entities.map(e => e.key)}>
                <Icon icon="arrow-right" />
                <FormattedMessage
                  id="client.common.notification.entitiesOpen"
                  values={{modelName: entities.at(0).modelName}}
                />
              </navigationStrategy.ListOrDetailLink>
            )}
          </StyledDetailLinkWrapper>
        ))}
      </>
    )
  }

  return null
})

Result.propTypes = {
  intl: PropTypes.object.isRequired,
  notification: notificationPropType.isRequired,
{'fraction_non_alphanumeric': 0.1205942324497524, 'fraction_numerical': 0.0007282260413632391, 'mean_word_length': 2.512531969309463, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4446444', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1847, 'n_words': 318}