/** * @author oldj * @blog https://oldj.net */ 'use strict' import React from 'react' import classnames from 'classnames' import Agent from '../Agent' import './list-item.less' export default class ListItem extends React.Component { constructor (props) { super(props) this.is_sys = !!this.props.sys this.state = {} } getTitle () { let {lang} = this.props return this.is_sys ? lang.sys_host_title : this.props.data.title || lang.untitled } beSelected () { this.props.setCurrent(this.props.data) } toggle () { let on = !this.props.data.on Agent.emit('toggle_hosts', this.props.data, on) } toEdit () { Agent.emit('edit_hosts', this.props.data) } componentDidMount () { Agent.on('select', id => { if (id && id === this.props.data.id) { this.beSelected() this.el && this.el.scrollIntoView() } }) } render () { let {data, sys, current} = this.props let is_selected = data === current if (!data) return null return (