From 6159f53137ccd7d4df9117028f38c6be2bcdb474 Mon Sep 17 00:00:00 2001 From: Malar Kannan Date: Mon, 19 Jun 2017 12:08:08 +0530 Subject: [PATCH] 1. split lex components to a module 2. added editor for lex dictid --- src/App.tsx | 128 +---------------------------------------- src/LexComponents.tsx | 129 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 127 deletions(-) create mode 100644 src/LexComponents.tsx diff --git a/src/App.tsx b/src/App.tsx index c8c456c..27c1c88 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,25 +1,6 @@ import * as React from 'react'; -import { - // Button, - // Classes, - // InputGroup, - // Intent, - // Menu, - // MenuItem, - // Popover, - // Position, - // Spinner, - // Switch, - // Tag, - // Tooltip, - FocusStyleManager, -} from '@blueprintjs/core'; -import * as XML from 'xml2js'; -import * as XPath from 'xml2js-xpath'; +import LexEditor from './LexComponents'; // import { Table } from '@blueprintjs/table'; - -FocusStyleManager.onlyShowFocusOnTabs(); - // const logo = require('./logo.svg'); class App extends React.Component<{}, null> { @@ -38,111 +19,4 @@ class App extends React.Component<{}, null> { } } -type ReactEvent = React.ChangeEvent; - -interface LexEditorProps { - fileName: RequestInfo; -} - -class LexEditor extends React.Component { - constructor(props: LexEditorProps) { - super(props); - this.handleOnSearch = this.handleOnSearch.bind(this); - this.state = { lexData: {}, matchedEntries: [] }; - } - - public componentDidMount() { - return fetch(this.props.fileName) - .then((response) => response.text()) - .then((xmlString) => { - XML.parseString(xmlString, (err, lexData) => { - this.setState({ ...this.state, lexData }); - }); - }); - // .catch((error) => { - // console.error(error); - // }); - } - - public render() { - return ( -
- - -
- ); - } - - private handleOnSearch(event: ReactEvent): void { - let searchText = event.target.value; - // this.setState({ ...this.state, searchText }); - let pathQ = './/lang'; - let words = XPath.find(this.state.lexData.document, pathQ); - let matchedEntries = words.filter((obj) => { - if (obj.label[0] === searchText) { - return true; - } - return false; - }); - this.setState({ ...this.state, matchedEntries }); - } -} - -interface LexSearchProps { - handleOnSearch: (e: ReactEvent) => void; -} - -class LexSearch extends React.Component { - public render() { - return ( -
- - this.props.handleOnSearch(e)} - /> -
- ); - } -} - -class LexMatches extends React.Component { - public render() { - return ( -
- {this.props.matchedEntries.map((mObj: any) => { - console.log('Matched ObjectEntry' + mObj); - return (); - })} -
- ); - } -} - -class LexEntry extends React.Component { - public render() { - return ( -
- -
- -
-
- ); - } -} - export default App; diff --git a/src/LexComponents.tsx b/src/LexComponents.tsx new file mode 100644 index 0000000..4fc441e --- /dev/null +++ b/src/LexComponents.tsx @@ -0,0 +1,129 @@ +import * as React from 'react'; +import { + // Button, + // Classes, + // InputGroup, + // Intent, + // Menu, + // MenuItem, + // Popover, + // Position, + // Spinner, + // Switch, + // Tag, + // Tooltip, + FocusStyleManager, +} from '@blueprintjs/core'; +import * as XML from 'xml2js'; +import * as XPath from 'xml2js-xpath'; + +FocusStyleManager.onlyShowFocusOnTabs(); + +type ReactEvent = React.ChangeEvent; + +interface LexEditorProps { + fileName: RequestInfo; +} + +class LexEditor extends React.Component { + constructor(props: LexEditorProps) { + super(props); + this.handleOnSearch = this.handleOnSearch.bind(this); + this.state = { lexData: {}, matchedEntries: [] }; + } + + public componentDidMount() { + return fetch(this.props.fileName) + .then((response) => response.text()) + .then((xmlString) => { + XML.parseString(xmlString, (err, lexData) => { + this.setState({ ...this.state, lexData }); + }); + }); + // .catch((error) => { + // console.error(error); + // }); + } + + public render() { + return ( +
+ + +
+ ); + } + + private handleOnSearch(event: ReactEvent): void { + let searchText = event.target.value; + // this.setState({ ...this.state, searchText }); + let pathQ = './/lang'; + let words = XPath.find(this.state.lexData.document, pathQ); + let matchedEntries = words.filter((obj) => { + if (obj.label[0] === searchText) { + return true; + } + return false; + }); + this.setState({ ...this.state, matchedEntries }); + } +} + +interface LexSearchProps { + handleOnSearch: (e: ReactEvent) => void; +} + +class LexSearch extends React.Component { + public render() { + return ( +
+ + this.props.handleOnSearch(e)} + /> +
+ ); + } +} + +class LexMatches extends React.Component { + public render() { + return ( +
+ {this.props.matchedEntries.map((mObj: any) => { + console.log('Matched ObjectEntry' + mObj); + return (); + })} +
+ ); + } +} + +class LexEntry extends React.Component { + public render() { + return ( +
+ +
+ +
+
+ ); + } +} + +export default LexEditor;