import * as React from 'react'; import * as _ from 'lodash'; import LexSingleInput from './LexSingleInput'; import { Image, Input, Card, Button } from 'semantic-ui-react'; const { Box } = require('reflexbox'); export class LexEdit extends React.Component { imageRoot = '/png/'; constructor(props: any) { super(props); this.state = { lexItem: this.props.lexItem }; } public render() { let li = this.state.lexItem; let editLang = _.get(li, this.props.fieldMetaMap.lang.lens, 'en'); let langSelOpts = _.get(this.props.selectionMeta, editLang, []); let lexFields = _.keys(this.props.fieldMetaMap).map(field => { let lens = this.props.fieldMetaMap[field].lens; let defaultText = _.get(li, lens, ''); let sh = (e: any) => { let eventData = {}; eventData[field] = e.target.value; this.handleOnChange(eventData); }; if (this.props.fieldMetaMap[field].type === 'text') { return ( ); } else if (this.props.fieldMetaMap[field].type === 'select') { let staticOpts = this.props.fieldMetaMap[field].options; let fieldOpts = _.get(langSelOpts, field, []); let selOpts = staticOpts ? staticOpts : fieldOpts; return ( ); } else if (this.props.fieldMetaMap[field].type === 'preview' && defaultText !== '') { let imageSrc = this.imageRoot + defaultText; return ( ); } else { return null; } }); return ( {_.get(li, 'label', '')} language: {_.get(li, '$.id', '')} {lexFields} ); } private handleOnChange(event: any) { let type = _.keys(event)[0]; let value = _.values(event)[0]; let lens = this.props.fieldMetaMap[type].lens; let { lexItem: lexItem } = this.state; _.set(lexItem, lens, value); console.log('setting event :', lexItem); this.setState(lexItem); } private handleOnSave(event: any) { console.log('saving object :', this.state.lexItem); } }