added list editor for syntacticprops and selection for cat/subcat
parent
b45e2268b2
commit
c715944fa2
|
|
@ -47,6 +47,36 @@ function simpleAttrAccessor(attrPred: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function listAttrAccessor(attrPred: any) {
|
function listAttrAccessor(attrPred: any) {
|
||||||
|
let { pred, lens } = attrPred;
|
||||||
|
return {
|
||||||
|
get: (li: any) => {
|
||||||
|
let def: any = [];
|
||||||
|
let morphProps = _.get<any>(li, lens, def);
|
||||||
|
let morphExps = _.filter<any>(morphProps, (m) => {
|
||||||
|
return pred(m);
|
||||||
|
});
|
||||||
|
let mEs = morphExps.map((me) => {
|
||||||
|
return _.get<any>(me, '_', me);
|
||||||
|
});
|
||||||
|
return mEs;
|
||||||
|
},
|
||||||
|
set: (li: any, value: any) => {
|
||||||
|
let lexItem = _.cloneDeep(li);
|
||||||
|
let allProps = _.get<any>(lexItem, lens, []);
|
||||||
|
if (allProps.length > 0) {
|
||||||
|
let keepProps = _.filter<any>(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;
|
let { attribKey, pred, lens } = attrPred;
|
||||||
return {
|
return {
|
||||||
get: (li: any) => {
|
get: (li: any) => {
|
||||||
|
|
@ -66,10 +96,10 @@ function listAttrAccessor(attrPred: any) {
|
||||||
let lexItem = _.cloneDeep(li);
|
let lexItem = _.cloneDeep(li);
|
||||||
let allProps = _.get<any>(lexItem, lens, []);
|
let allProps = _.get<any>(lexItem, lens, []);
|
||||||
if (allProps.length > 0) {
|
if (allProps.length > 0) {
|
||||||
let prop = _.filter<any>(allProps, (m) => {
|
let keepProps = _.filter<any>(allProps, (m) => {
|
||||||
return pred(m);
|
return !pred(m);
|
||||||
});
|
});
|
||||||
_.set(prop, '[0]._', value);
|
_.set(lexItem, lens, _.concat(keepProps, value));
|
||||||
} else {
|
} else {
|
||||||
_.set(lexItem, lens, value);
|
_.set(lexItem, lens, value);
|
||||||
}
|
}
|
||||||
|
|
@ -103,6 +133,24 @@ const fieldMetaMap = {
|
||||||
_.isEqual
|
_.isEqual
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
|
cat: {
|
||||||
|
type: 'select',
|
||||||
|
...simpleAttrAccessor(attrPredGen(
|
||||||
|
'uiprops[0].property',
|
||||||
|
'id',
|
||||||
|
'cat',
|
||||||
|
_.isEqual
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
subcat: {
|
||||||
|
type: 'select',
|
||||||
|
...simpleAttrAccessor(attrPredGen(
|
||||||
|
'uiprops[0].property',
|
||||||
|
'id',
|
||||||
|
'subcat',
|
||||||
|
_.isEqual
|
||||||
|
)),
|
||||||
|
},
|
||||||
morphclass: {
|
morphclass: {
|
||||||
type: 'select',
|
type: 'select',
|
||||||
...simpleAttrAccessor(attrPredGen(
|
...simpleAttrAccessor(attrPredGen(
|
||||||
|
|
@ -113,8 +161,8 @@ const fieldMetaMap = {
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
morphexceptions: {
|
morphexceptions: {
|
||||||
type: 'list',
|
type: 'proplist',
|
||||||
...listAttrAccessor(attrPredGen(
|
...propListAttrAccessor(attrPredGen(
|
||||||
'lexprops[0].morphology[0].morph',
|
'lexprops[0].morphology[0].morph',
|
||||||
'form',
|
'form',
|
||||||
'morphclass',
|
'morphclass',
|
||||||
|
|
@ -135,6 +183,7 @@ const fieldMetaMap = {
|
||||||
_.negate(_.isEqual)
|
_.negate(_.isEqual)
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const xmlToEntries = (xmlData: any) => {
|
const xmlToEntries = (xmlData: any) => {
|
||||||
|
|
@ -158,12 +207,14 @@ const xmlToEntries = (xmlData: any) => {
|
||||||
let langs = _.keys(langEntries);
|
let langs = _.keys(langEntries);
|
||||||
let selectFields = _.fromPairs(langs.map((lang) => {
|
let selectFields = _.fromPairs(langs.map((lang) => {
|
||||||
let langOpts = _.fromPairs(_.keys(fieldMetaMap).filter((s) => {
|
let langOpts = _.fromPairs(_.keys(fieldMetaMap).filter((s) => {
|
||||||
return fieldMetaMap[s].type === 'select';
|
return _.includes(['select', 'list'], fieldMetaMap[s].type);
|
||||||
}).map((s) => {
|
}).map((s) => {
|
||||||
let entries = _.get<any>(langEntries, lang, 'en');
|
let entries = _.get<any>(langEntries, lang, 'en');
|
||||||
let selectOptions = _.uniq(entries.map((q: any) => {
|
let allOpts = entries.map((q: any) => {
|
||||||
return fieldMetaMap[s].get(q);
|
return fieldMetaMap[s].get(q);
|
||||||
}));
|
});
|
||||||
|
let select = _.isEqual(fieldMetaMap[s].type, 'select');
|
||||||
|
let selectOptions = select ? _.uniq(allOpts) : _.uniq(_.flatten(allOpts));
|
||||||
return [s, selectOptions];
|
return [s, selectOptions];
|
||||||
}));
|
}));
|
||||||
return [lang, langOpts];
|
return [lang, langOpts];
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ function selectInput(params: any) {
|
||||||
value={value}
|
value={value}
|
||||||
compact={true}
|
compact={true}
|
||||||
selection={true}
|
selection={true}
|
||||||
|
search={true}
|
||||||
style={{ width: '10em' }}
|
style={{ width: '10em' }}
|
||||||
/>
|
/>
|
||||||
</LexSingleInput>
|
</LexSingleInput>
|
||||||
|
|
@ -91,11 +92,34 @@ function imagePreview(params: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function listInput(params: any) {
|
function listInput(params: any) {
|
||||||
let { field, value, changed } = params;
|
let { field, sh, langSelOpts, value, changed } = params;
|
||||||
console.log('field: ', field, 'value: ', value);
|
let fieldOpts = _.get<any>(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 (
|
return (
|
||||||
<LexSingleInput key={field} label={changedLabel(changed, field)}>
|
<LexSingleInput key={field} label={changedLabel(changed, field)}>
|
||||||
<pre>{JSON.stringify(value)}</pre>
|
<Dropdown
|
||||||
|
options={dropOptions}
|
||||||
|
onChange={(e, d) => {
|
||||||
|
sh(d.value);
|
||||||
|
}}
|
||||||
|
value={value}
|
||||||
|
compact={true}
|
||||||
|
selection={true}
|
||||||
|
search={true}
|
||||||
|
multiple={true}
|
||||||
|
fluid={true}
|
||||||
|
style={{ width: '10em' }}
|
||||||
|
renderLabel={renderLabel}
|
||||||
|
/>
|
||||||
</LexSingleInput>
|
</LexSingleInput>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -112,6 +136,7 @@ export function componentForType(type: string, params: any) {
|
||||||
return imagePreview(params);
|
return imagePreview(params);
|
||||||
}
|
}
|
||||||
case 'list': {
|
case 'list': {
|
||||||
|
// return (<ListInput params={params} />);
|
||||||
return listInput(params);
|
return listInput(params);
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue