From c715944fa23a3491b6f9ea23662e1ef4692f9399 Mon Sep 17 00:00:00 2001 From: Malar Kannan Date: Thu, 27 Jul 2017 17:13:40 +0530 Subject: [PATCH] added list editor for syntacticprops and selection for cat/subcat --- src/LexSetup.tsx | 67 +++++++++++++++++++++++++++++++++++++----- src/LexSingleInput.tsx | 31 +++++++++++++++++-- 2 files changed, 87 insertions(+), 11 deletions(-) diff --git a/src/LexSetup.tsx b/src/LexSetup.tsx index b9b5842..2d3360c 100644 --- a/src/LexSetup.tsx +++ b/src/LexSetup.tsx @@ -47,6 +47,36 @@ function simpleAttrAccessor(attrPred: any) { } function listAttrAccessor(attrPred: any) { + let { pred, lens } = attrPred; + return { + get: (li: any) => { + let def: any = []; + let morphProps = _.get(li, lens, def); + let morphExps = _.filter(morphProps, (m) => { + return pred(m); + }); + let mEs = morphExps.map((me) => { + return _.get(me, '_', me); + }); + return mEs; + }, + set: (li: any, value: any) => { + let lexItem = _.cloneDeep(li); + let allProps = _.get(lexItem, lens, []); + if (allProps.length > 0) { + let keepProps = _.filter(allProps, (m) => { + return !pred(m); + }); + _.set(lexItem, lens, _.concat(keepProps, value)); + } else { + _.set(lexItem, lens, value); + } + return lexItem; + } + }; +} + +function propListAttrAccessor(attrPred: any) { let { attribKey, pred, lens } = attrPred; return { get: (li: any) => { @@ -66,10 +96,10 @@ function listAttrAccessor(attrPred: any) { let lexItem = _.cloneDeep(li); let allProps = _.get(lexItem, lens, []); if (allProps.length > 0) { - let prop = _.filter(allProps, (m) => { - return pred(m); + let keepProps = _.filter(allProps, (m) => { + return !pred(m); }); - _.set(prop, '[0]._', value); + _.set(lexItem, lens, _.concat(keepProps, value)); } else { _.set(lexItem, lens, value); } @@ -103,6 +133,24 @@ const fieldMetaMap = { _.isEqual )), }, + cat: { + type: 'select', + ...simpleAttrAccessor(attrPredGen( + 'uiprops[0].property', + 'id', + 'cat', + _.isEqual + )), + }, + subcat: { + type: 'select', + ...simpleAttrAccessor(attrPredGen( + 'uiprops[0].property', + 'id', + 'subcat', + _.isEqual + )), + }, morphclass: { type: 'select', ...simpleAttrAccessor(attrPredGen( @@ -113,8 +161,8 @@ const fieldMetaMap = { )) }, morphexceptions: { - type: 'list', - ...listAttrAccessor(attrPredGen( + type: 'proplist', + ...propListAttrAccessor(attrPredGen( 'lexprops[0].morphology[0].morph', 'form', 'morphclass', @@ -135,6 +183,7 @@ const fieldMetaMap = { _.negate(_.isEqual) )) }, + }; const xmlToEntries = (xmlData: any) => { @@ -158,12 +207,14 @@ const xmlToEntries = (xmlData: any) => { let langs = _.keys(langEntries); let selectFields = _.fromPairs(langs.map((lang) => { let langOpts = _.fromPairs(_.keys(fieldMetaMap).filter((s) => { - return fieldMetaMap[s].type === 'select'; + return _.includes(['select', 'list'], fieldMetaMap[s].type); }).map((s) => { let entries = _.get(langEntries, lang, 'en'); - let selectOptions = _.uniq(entries.map((q: any) => { + let allOpts = entries.map((q: any) => { return fieldMetaMap[s].get(q); - })); + }); + let select = _.isEqual(fieldMetaMap[s].type, 'select'); + let selectOptions = select ? _.uniq(allOpts) : _.uniq(_.flatten(allOpts)); return [s, selectOptions]; })); return [lang, langOpts]; diff --git a/src/LexSingleInput.tsx b/src/LexSingleInput.tsx index 4a7c572..f72742f 100644 --- a/src/LexSingleInput.tsx +++ b/src/LexSingleInput.tsx @@ -74,6 +74,7 @@ function selectInput(params: any) { value={value} compact={true} selection={true} + search={true} style={{ width: '10em' }} /> @@ -91,11 +92,34 @@ function imagePreview(params: any) { } function listInput(params: any) { - let { field, value, changed } = params; - console.log('field: ', field, 'value: ', value); + let { field, sh, langSelOpts, value, changed } = params; + let fieldOpts = _.get(langSelOpts, field, []); + let renderLabel = (label: any) => ({ + content: `${label.value}`, + }); + let dropOptions = fieldOpts.map((k: any, i: any, c: any) => { + return { + key: i, + value: k, + text: k, + }; + }); return ( -
{JSON.stringify(value)}
+ { + sh(d.value); + }} + value={value} + compact={true} + selection={true} + search={true} + multiple={true} + fluid={true} + style={{ width: '10em' }} + renderLabel={renderLabel} + />
); } @@ -112,6 +136,7 @@ export function componentForType(type: string, params: any) { return imagePreview(params); } case 'list': { + // return (); return listInput(params); } default: {