<commit_before>import React from 'react'
import plugin from 'app/utils/plugin'
import Loading from '../loading'
import {merge, to_keywordmap, match_traits, map_get} from 'app/utils'
import PropTypes from 'prop-types';
import {SectionMenu} from 'app/components'
import store from 'app/utils/store'
import i18n from 'app/utils/i18n'

const plugin_load = plugin.load
const plugin_do_screen = plugin.do_screen

function SelectService(props){
  const services = props.services || []

  return (
    <div className="menu">
      <div style={{width: 30}}/>
      <div className="ui attached tabular menu">
        {services.length > 0 ? services.map( s => (
          <a key={s.uuid} className={`item ${s.uuid == props.selected ? "active" : ""}`} onClick={() => props.onService(s.uuid)}>
            {s.name}
          </a>
        )) : (
          <h3 className="ui red header">{i18n("No services for this screen. Create one.")}</h3>
        )}
      </div>
    </div>
  )
}


class ExternalScreen extends React.Component{
  constructor(props){
    super(props)

    const plugin = props.plugin || props.params.plugin
    const component = props.component || props.params.component
    const screen_id = `${plugin}/${component}`

    // to avoid one method.. feels dirty, but its the right thing to do
    const state = store.getState()
    const screen = state.menu.screens.find( s => s.id == screen_id ) || {}
    const services = state.project.project.services.filter( s => {
      return match_traits({ has: s.traits, any: screen.traits })
    })

    const service = map_get(this.props, ["data", "service"])
    let current = undefined
    if (service)
      current = service.uuid

    const show_menu = (screen.traits.length > 0) && (screen.traits.indexOf("global") == -1)

    this.state = {
      umount: undefined,
      component: undefined,
      screen,
      services,
      current,
      service,
      show_menu,
    }
  }
  componentWillUnmount(){
    if (this.state.umount){
      console.debug("Cleanup plugin screen")<commit_msg>Fix call when no service selected<commit_after>import React from 'react'
import plugin from 'app/utils/plugin'
import Loading from '../loading'
import {merge, to_keywordmap, match_traits, map_get} from 'app/utils'
import PropTypes from 'prop-types';
import {SectionMenu} from 'app/components'
import store from 'app/utils/store'
import i18n from 'app/utils/i18n'

const plugin_load = plugin.load
const plugin_do_screen = plugin.do_screen

function SelectService(props){
  const services = props.services || []

  return (
    <div className="menu">
      <div style={{width: 30}}/>
      <div className="ui attached tabular menu">
        {services.length > 0 ? services.map( s => (
          <a key={s.uuid} className={`item ${s.uuid == props.selected ? "active" : ""}`} onClick={() => props.onService(s.uuid)}>
            {s.name}
          </a>
        )) : (
          <h3 className="ui red header">{i18n("No services for this screen. Create one.")}</h3>
        )}
      </div>
    </div>
  )
}


class ExternalScreen extends React.Component{
  constructor(props){
    super(props)

    const plugin = props.plugin || props.params.plugin
    const component = props.component || props.params.component
    const screen_id = `${plugin}/${component}`

    // to avoid one method.. feels dirty, but its the right thing to do
    const state = store.getState()
    const screen = state.menu.screens.find( s => s.id == screen_id ) || {traits: []}
    const services = map_get(state, ["project", "project", "services"], []).filter( s => {
      return match_traits({ has: s.traits, any: screen.traits })
    })

    const service = map_get(this.props, ["data", "service"])
    let current = undefined
    if (service)
      current = service.uuid

    const show_menu = (screen.traits.length > 0) && (screen.traits.indexOf("global") == -1)

    this.state = {
      umount: undefined,
      component: undefined,
      screen,
      services,
      current,
      service,
      show_menu,
    }
  }
  componentWillUnmount(){
    if (this.state.umount){
      console.debug("Cleanup plugin screen")
{'fraction_non_alphanumeric': 0.1429261226460647, 'fraction_numerical': 0.006277160791887977, 'mean_word_length': 2.976007677543186, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, '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': '4881610', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1240, 'n_words': 341}