computing entries from redux xmldata
parent
c32fea2881
commit
fedeb0c104
|
|
@ -21,13 +21,8 @@ const fieldMetaMap = {
|
||||||
lang: { lens: '$.id', type: 'select', options: ['en', 'es'] },
|
lang: { lens: '$.id', type: 'select', options: ['en', 'es'] },
|
||||||
};
|
};
|
||||||
|
|
||||||
export class LexSetup extends React.Component<any, any> {
|
const xmlToEntries = (xmlData: any) => {
|
||||||
public componentDidMount() {
|
let allEntries = _.chain(xmlData)
|
||||||
fetch(this.props.fileName)
|
|
||||||
.then((response) => response.text())
|
|
||||||
.then((xmlString) => {
|
|
||||||
XML.parseString(xmlString, (err, lexData) => {
|
|
||||||
let allEntries = _.chain(lexData)
|
|
||||||
.get<any>('document.lexicon[0].item')
|
.get<any>('document.lexicon[0].item')
|
||||||
.flatMap((o: any) => _.chain(o)
|
.flatMap((o: any) => _.chain(o)
|
||||||
.get<any>('entry')
|
.get<any>('entry')
|
||||||
|
|
@ -38,7 +33,6 @@ export class LexSetup extends React.Component<any, any> {
|
||||||
.value()
|
.value()
|
||||||
)
|
)
|
||||||
.value();
|
.value();
|
||||||
|
|
||||||
let langReducer = ((result: any, q: any) => {
|
let langReducer = ((result: any, q: any) => {
|
||||||
let lang = _.get<any>(q, fieldMetaMap.lang.lens, 'en');
|
let lang = _.get<any>(q, fieldMetaMap.lang.lens, 'en');
|
||||||
(result[lang] || (result[lang] = [])).push(q);
|
(result[lang] || (result[lang] = [])).push(q);
|
||||||
|
|
@ -59,10 +53,23 @@ export class LexSetup extends React.Component<any, any> {
|
||||||
}));
|
}));
|
||||||
return [lang, langOpts];
|
return [lang, langOpts];
|
||||||
}));
|
}));
|
||||||
this.props.addXmlData(lexData);
|
return ({
|
||||||
this.setState({
|
|
||||||
allEntries, selectFields, fieldMetaMap
|
allEntries, selectFields, fieldMetaMap
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export class LexSetup extends React.Component<any, any> {
|
||||||
|
constructor(props: any) {
|
||||||
|
super(props);
|
||||||
|
this.state = { xmlLoaded: false };
|
||||||
|
}
|
||||||
|
public componentDidMount() {
|
||||||
|
fetch(this.props.fileName)
|
||||||
|
.then((response) => response.text())
|
||||||
|
.then((xmlString) => {
|
||||||
|
XML.parseString(xmlString, (err, xmlData) => {
|
||||||
|
this.props.addXmlData(xmlData);
|
||||||
|
this.setState({ xmlLoaded: true });
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
|
@ -71,8 +78,8 @@ export class LexSetup extends React.Component<any, any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return this.state ? (
|
return this.state.xmlLoaded ? (
|
||||||
<LexEditor {...this.state} {...this.props} />
|
<LexEditor {...xmlToEntries(this.props.xmlData)} {...this.props} />
|
||||||
) : (
|
) : (
|
||||||
<Dimmer active={true} inverted={true}>
|
<Dimmer active={true} inverted={true}>
|
||||||
<Loader inverted={true}>Loading</Loader>
|
<Loader inverted={true}>Loading</Loader>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue