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'); const imageRoot = 'http://localhost:3000/png/'; export const fieldMetaMap = { 'label': { lens: 'label[0]', type: 'text' }, 'unl': { lens: 'unl[0]', type: 'text' }, 'synset': { lens: 'lexprops[0].wnsynset[0]', type: 'text' }, 'guid': { lens: 'guid[0]', type: 'text' }, 'pos': { lens: 'pos[0]', type: 'select' }, 'image': { lens: 'image[0]', type: 'preview' }, 'relations': { lens: 'relations[0]', type: 'text' }, 'frame': { lens: 'syntacticprops[0].property[0]._', type: 'select' }, 'morphclass': { lens: 'lexprops[0].morphology[0].morph[0]._', type: 'select' }, 'stats': { lens: 'stats[0].property[0]._', type: 'text' }, 'lang': { lens: '$.id', type: 'select' }, }; export class LexEdit extends React.Component { public render() { let li = this.props.lexItem; let lexFields = _.keys(fieldMetaMap).map(field => { let defaultText = _.get(li, fieldMetaMap[field].lens, ''); let sh = (e: any) => { let eventData = {}; eventData[field] = e.target.value; this.handleOnChange(eventData); }; // let pred = (x: any) => _.isEqual(fieldMetaMap[ft].type, x); // _.findIndex(['text', 'number'], pred) !== -1 if (fieldMetaMap[field].type === 'text') { return ( ); } else if (fieldMetaMap[field].type === 'select') { return ( ); } else if (fieldMetaMap[field].type === 'preview' && defaultText !== '') { let imageSrc = imageRoot + defaultText; return ( ); } else { return null; } }); return ( {_.get(li, 'label', '')} language: {_.get(li, '$.id', '')} {lexFields} ); } private handleOnChange(event: any) { this.setState(event); } private handleOnSave(event: any) { console.log('saving object', this.props.lexItem); } }