<commit_before>import React, { Component } from 'react'
import { connect } from 'react-redux'

import CreateAccountService from '../components/services/CreateAccountService'
import ServiceBar from '../components/services/ServiceBar'

import { getKonnector } from '../ducks/konnectors'

class IntentService extends Component {
  constructor(props) {
    super(props)

    if (props.konnectors && props.konnectors.length === 1) {
      this.state = {
        konnector: props.konnectors[0],
        isUnique: true
      }
    }
  }

  reset() {
    this.setState({
      konnector: null
    })
  }

  onSuccess(account) {
    const { isUnique } = this.state

    if (isUnique) {
      this.reset()
      return this.props.onTerminate(account)
    }

    this.reset()
  }

  onCancel() {
    const { isUnique } = this.state

    if (isUnique) {
      return this.props.onCancel()
    }

    this.reset()
  }

  showKonnector(konnector) {
    this.setState({
      konnector: konnector
    })
  }

  render() {
    const { appData, konnectors, onCancel } = this.props
    const { konnector, error, disableSuccessTimeout, closeable } = this.state

    const { t } = this.context

    return (
      <div className="coz-service">
        {error && (
          <div className="coz-error coz-service-error">
            <p>{t(error.message)}</p>
            <p>{t('intent.service.error.cause', { error: error.reason })}</p>
          </div>
        )}
        <div className="coz-service-layout">
          <ServiceBar
            appEditor={appData.cozyAppEditor}
            appName={appData.cozyAppName}
            iconPath={`../${appData.cozyIconPath}`}
            onCancel={onCancel}
            closeable={closeable}
            hasReturnToKonnectorsListButton={
              !error && konnectors.length > 1 && konnector
            }
            returnToKonnectorsList={() => this.setState({ konnector: null })}
            {...this.context}
          />
          {konnector && (
            <CreateAccountService
              konnector={konnector}
              onCancel={() => this.onCancel()}
              onSuccess={account => this.onSuccess(account)}
              disableSuccessTimeout={disableSuccessTimeout}
              closeModal={() => this.onCancel()}
              {...this.context}
            />
          )}
        </div>
      </div>
    )
  }
}

const mapStateToProps = (state, ownProps) => {
  const { data } = ownProps
  const { slug } = data
  return {
    konnectors: (slug && [getKonnector(state.cozy, slug)]) || []
  }
}

export default connect(mapStateToProps)(IntentService)<commit_msg>feat: IntentService now deals with only one konnector 📝<commit_after>import React, { Component } from 'react'
import { connect } from 'react-redux'

import CreateAccountService from '../components/services/CreateAccountService'
import ServiceBar from '../components/services/ServiceBar'

import { getKonnector } from '../ducks/konnectors'

class IntentService extends Component {
  render() {
    const { appData, konnector, onCancel, onTerminate } = this.props
    const { error } = this.state

    const { t } = this.context

    return (
      <div className="coz-service">
        {error && (
          <div className="coz-error coz-service-error">
            <p>{t(error.message)}</p>
            <p>{t('intent.service.error.cause', { error: error.reason })}</p>
          </div>
        )}
        <div className="coz-service-layout">
          <ServiceBar
            appEditor={appData.cozyAppEditor}
            appName={appData.cozyAppName}
            iconPath={`../${appData.cozyIconPath}`}
            onCancel={() => this.props.onCancel()}
            closeable={closeable}
            {...this.context}
          />
          {konnector && (
            <CreateAccountService
              konnector={konnector}
              onCancel={() => onCancel()}
              onSuccess={account => onTerminate(account)}
              disableSuccessTimeout={disableSuccessTimeout}
              closeModal={() => this.onCancel()}
              {...this.context}
            />
          )}
        </div>
      </div>
    )
  }
}

const mapStateToProps = (state, ownProps) => {
  const { data } = ownProps
  const { slug } = data
  return {
    konnector: slug && getKonnector(state.cozy, slug)
  }
}

export default connect(mapStateToProps)(IntentService)
{'fraction_non_alphanumeric': 0.13646736649931537, 'fraction_numerical': 0.0006846188954815153, 'mean_word_length': 2.141935483870968, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 38, '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': '5809914', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1295, 'n_words': 239}