made stateless components functional and added typeCheck

master
Malar Kannan 2017-08-01 17:53:19 +05:30
parent f49df77601
commit 1e259c9a1c
5 changed files with 74 additions and 76 deletions

View File

@ -134,7 +134,10 @@ module.exports = {
test: /\.(ts|tsx)$/, test: /\.(ts|tsx)$/,
loader: require.resolve('tslint-loader'), loader: require.resolve('tslint-loader'),
enforce: 'pre', enforce: 'pre',
include: paths.appSrc include: paths.appSrc,
options: {
typeCheck:true
}
}, { }, {
test: /\.js$/, test: /\.js$/,
loader: require.resolve('source-map-loader'), loader: require.resolve('source-map-loader'),

View File

@ -111,6 +111,9 @@ module.exports = {
loader: require.resolve('tslint-loader'), loader: require.resolve('tslint-loader'),
enforce: 'pre', enforce: 'pre',
include: paths.appSrc, include: paths.appSrc,
options: {
typeCheck:true
}
}, },
{ {
test: /\.js$/, test: /\.js$/,

View File

@ -9,43 +9,23 @@ import {
} from 'semantic-ui-react'; } from 'semantic-ui-react';
const { Flex } = require('reflexbox'); const { Flex } = require('reflexbox');
export class LexEditor extends React.Component<any, any> { function LexSearch(props: any) {
public render() { let dropOptions = _.keys(props.fieldMetaMap).map((k, i, c) => {
let searchMeta = this.props.fieldMetaMap[this.props.searchState.searchType];
let searchText = this.props.searchState.searchValue;
let matchedEntries = _.chain(this.props.allEntries)
.filter((q: any) => searchMeta.get(q) === searchText)
.take(10)
.value();
let { fieldMetaMap, save, markDirty, newGuid } = this.props;
return (
<div>
<LexSearch
{...this.props}
/>
<LexMatches
{...{ fieldMetaMap, save, markDirty, newGuid }}
matchedEntries={matchedEntries}
selectionMeta={this.props.selectFields}
searchText={searchText}
searchMeta={searchMeta}
/>
</div>
);
}
}
class LexSearch extends React.Component<any, any> {
public render() {
let dropOptions = _.keys(this.props.fieldMetaMap).map((k, i, c) => {
return { key: i, value: k, text: _.capitalize(k) }; return { key: i, value: k, text: _.capitalize(k) };
}); });
function handleChange(e: any, t: boolean) {
if (t) {
props.searchForType(e.value);
} else {
props.searchForValue(e.value);
}
}
return ( return (
<Container textAlign="center"> <Container textAlign="center">
<Dropdown <Dropdown
options={dropOptions} options={dropOptions}
onChange={(e, d) => this.handleChange(d, true)} onChange={(e, d) => handleChange(d, true)}
value={this.props.searchState.searchType} value={props.searchState.searchType}
compact={true} compact={true}
selection={true} selection={true}
style={{ width: '10em' }} style={{ width: '10em' }}
@ -54,23 +34,14 @@ class LexSearch extends React.Component<any, any> {
type="text" type="text"
placeholder="Search input" placeholder="Search input"
dir="auto" dir="auto"
value={this.props.searchState.searchValue} value={props.searchState.searchValue}
icon="filter" icon="filter"
onChange={(e, d) => this.handleChange(d, false)} onChange={(e, d) => handleChange(d, false)}
/> />
</Container> </Container>
); );
} }
private handleChange(e: any, t: boolean) {
if (t) {
this.props.searchForType(e.value);
} else {
this.props.searchForValue(e.value);
}
}
}
function LexMatches(params: any) { function LexMatches(params: any) {
const selectMode = (props: any) => { const selectMode = (props: any) => {
if (props.searchText === '') { if (props.searchText === '') {
@ -116,3 +87,27 @@ function LexMatches(params: any) {
</Flex> </Flex>
); );
} }
export function LexEditor(props: any) {
let searchMeta = props.fieldMetaMap[props.searchState.searchType];
let searchText = props.searchState.searchValue;
let matchedEntries = _.chain(props.allEntries)
.filter((q: any) => searchMeta.get(q) === searchText)
.take(10)
.value();
let { fieldMetaMap, save, markDirty, newGuid } = props;
return (
<div>
<LexSearch
{...props}
/>
<LexMatches
{...{ fieldMetaMap, save, markDirty, newGuid }}
matchedEntries={matchedEntries}
selectionMeta={props.selectFields}
searchText={searchText}
searchMeta={searchMeta}
/>
</div>
);
}

View File

@ -9,24 +9,22 @@ import {
} from 'semantic-ui-react'; } from 'semantic-ui-react';
import PropListInput from './PropListInput'; import PropListInput from './PropListInput';
class LexInputContainer extends React.Component<any, any> { function LexInputContainer(props: any) {
public render() {
return ( return (
<div> <div>
<Form> <Form>
<Form.Group as={Flex} inline={true} style={{ margin: '0 0 5px 5px' }}> <Form.Group as={Flex} inline={true} style={{ margin: '0 0 5px 5px' }}>
<Form.Field as={Box} w={2 / 5} style={{ textAlign: 'right' }}> <Form.Field as={Box} w={2 / 5} style={{ textAlign: 'right' }}>
{this.props.label} {props.label}
</Form.Field> </Form.Field>
<Form.Field as={Box} w={3 / 5} > <Form.Field as={Box} w={3 / 5} >
{this.props.children} {props.children}
</Form.Field> </Form.Field>
</Form.Group> </Form.Group>
</Form> </Form>
</div> </div>
); );
} }
}
function changedLabel(changed: boolean, text: string) { function changedLabel(changed: boolean, text: string) {
let labelClass = changed ? 'olive' : ''; let labelClass = changed ? 'olive' : '';

View File

@ -16,7 +16,6 @@
"curly": true, "curly": true,
"eofline": false, "eofline": false,
"forin": true, "forin": true,
"type-check": true,
"indent": [true, "spaces"], "indent": [true, "spaces"],
"interface-name": [true, "never-prefix"], "interface-name": [true, "never-prefix"],
"jsdoc-format": true, "jsdoc-format": true,