import React from 'react'; import Select from './Select.jsx'; import { addModuleItem } from '../service/dashboardService.js'; export default class AddSelectItem extends React.Component { constructor(props) { super(props); this.state = { value: '', item: null, }; this.onClick = this.onClick.bind(this); this.onChange = this.onChange.bind(this); } componentDidMount() { if (this.props.value) { const option = this.props.options.find(o => o.id === this.props.value); this.setState({ value: this.props.value, item: { id: option.id, name: option.name, }, }); } } componentWillReceiveProps(props) { if (props.value === this.state.value) { return; } if (props.value) { const option = props.options.find(o => o.id === props.value); this.setState({ value: props.value, item: { id: option.id, name: option.name, }, }); } } onChange(event) { const option = event.target.selectedOptions[0]; this.setState({ value: option.value, item: { id: option.value, name: option.dataset.name, }, }); } async onClick(event) { if (this.props.onClick) { this.props.onClick(event, this.state.item); } else { addModuleItem(this.props.module, this.props.setting, this.state.item, this.props.friendlyName); } } render() { return (
{!this.props.hideLabel ? () : ''}

); } }