2017-06-19 06:38:08 +00:00
|
|
|
import * as React from 'react';
|
2017-06-20 13:20:54 +00:00
|
|
|
import * as _ from 'lodash';
|
2017-07-12 06:02:01 +00:00
|
|
|
import { LexEdit } from './LexEdit';
|
2017-06-22 11:34:06 +00:00
|
|
|
import {
|
|
|
|
|
Input,
|
|
|
|
|
Dropdown,
|
|
|
|
|
} from 'semantic-ui-react';
|
2017-06-27 09:33:34 +00:00
|
|
|
const { Flex } = require('reflexbox');
|
2017-06-19 06:38:08 +00:00
|
|
|
|
2017-07-12 06:02:01 +00:00
|
|
|
// container component
|
|
|
|
|
export class LexEditor extends React.Component<any, any> {
|
2017-06-19 06:38:08 +00:00
|
|
|
public render() {
|
2017-07-19 11:23:24 +00:00
|
|
|
let searchMeta = this.props.fieldMetaMap[this.props.searchState.searchType];
|
2017-07-13 10:30:36 +00:00
|
|
|
let searchText = this.props.searchState.searchValue;
|
2017-07-13 11:17:37 +00:00
|
|
|
let matchedEntries = _.chain(this.props.allEntries)
|
2017-07-19 11:23:24 +00:00
|
|
|
.filter((q: any) => searchMeta.get(q) === searchText)
|
2017-07-12 12:06:09 +00:00
|
|
|
.take(10)
|
|
|
|
|
.value();
|
2017-07-28 06:56:45 +00:00
|
|
|
let { fieldMetaMap, save, saveXMLBackend } = this.props;
|
2017-06-19 06:38:08 +00:00
|
|
|
return (
|
|
|
|
|
<div>
|
2017-07-12 06:02:01 +00:00
|
|
|
<LexSearch
|
2017-07-12 12:52:15 +00:00
|
|
|
{...this.props}
|
2017-07-12 06:02:01 +00:00
|
|
|
/>
|
2017-06-20 13:20:54 +00:00
|
|
|
<LexMatches
|
2017-07-28 06:56:45 +00:00
|
|
|
{...{ fieldMetaMap, save, saveXMLBackend }}
|
2017-07-12 12:06:09 +00:00
|
|
|
matchedEntries={matchedEntries}
|
2017-07-13 11:17:37 +00:00
|
|
|
selectionMeta={this.props.selectFields}
|
2017-07-12 12:06:09 +00:00
|
|
|
searchText={searchText}
|
2017-07-19 11:23:24 +00:00
|
|
|
searchMeta={searchMeta}
|
2017-06-20 13:20:54 +00:00
|
|
|
/>
|
2017-06-19 06:38:08 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-20 13:20:54 +00:00
|
|
|
class LexSearch extends React.Component<any, any> {
|
2017-06-19 06:38:08 +00:00
|
|
|
public render() {
|
2017-07-12 06:02:01 +00:00
|
|
|
let dropOptions = _.keys(this.props.fieldMetaMap).map((k, i, c) => {
|
2017-06-22 11:34:06 +00:00
|
|
|
return { key: i, value: k, text: _.capitalize(k) };
|
|
|
|
|
});
|
2017-06-19 06:38:08 +00:00
|
|
|
return (
|
2017-06-22 11:34:06 +00:00
|
|
|
<div>
|
|
|
|
|
<Dropdown
|
|
|
|
|
options={dropOptions}
|
|
|
|
|
onChange={(e, d) => this.handleChange(d, true)}
|
2017-07-13 10:30:36 +00:00
|
|
|
value={this.props.searchState.searchType}
|
2017-06-22 11:34:06 +00:00
|
|
|
compact={true}
|
|
|
|
|
selection={true}
|
|
|
|
|
/>
|
|
|
|
|
<Input
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder="Search input"
|
|
|
|
|
dir="auto"
|
2017-07-13 10:30:36 +00:00
|
|
|
value={this.props.searchState.searchValue}
|
2017-07-18 10:24:19 +00:00
|
|
|
icon="filter"
|
2017-06-22 11:34:06 +00:00
|
|
|
onChange={(e, d) => this.handleChange(d, false)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2017-06-19 06:38:08 +00:00
|
|
|
);
|
|
|
|
|
}
|
2017-06-20 13:20:54 +00:00
|
|
|
|
2017-06-22 11:34:06 +00:00
|
|
|
private handleChange(e: any, t: boolean) {
|
|
|
|
|
if (t) {
|
2017-07-13 10:30:36 +00:00
|
|
|
this.props.searchForType(e.value);
|
2017-06-22 11:34:06 +00:00
|
|
|
} else {
|
2017-07-13 10:30:36 +00:00
|
|
|
this.props.searchForValue(e.value);
|
2017-06-22 11:34:06 +00:00
|
|
|
}
|
2017-06-20 13:20:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-12 06:02:01 +00:00
|
|
|
function LexMatches(params: any) {
|
|
|
|
|
const selectMode = (props: any) => {
|
|
|
|
|
if (props.searchText === '') {
|
2017-06-21 12:37:48 +00:00
|
|
|
return (
|
2017-07-12 06:02:01 +00:00
|
|
|
<div>
|
|
|
|
|
<h4>Empty</h4>
|
|
|
|
|
Type something in the searchbar.
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
let editEntries = props.matchedEntries.map((mObj: any) => {
|
|
|
|
|
let uniqueKey = mObj.guid[0] + '#' + mObj.$.id;
|
|
|
|
|
return (
|
|
|
|
|
<LexEdit
|
2017-07-13 13:36:47 +00:00
|
|
|
{...props}
|
2017-07-12 06:02:01 +00:00
|
|
|
key={uniqueKey}
|
|
|
|
|
lexItem={mObj}
|
|
|
|
|
selectionMeta={props.selectionMeta}
|
2017-07-18 10:24:19 +00:00
|
|
|
existing={true}
|
2017-07-12 06:02:01 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
});
|
2017-07-19 11:23:24 +00:00
|
|
|
let addProps = props.searchMeta.set({}, props.searchText);
|
2017-07-12 06:02:01 +00:00
|
|
|
let addEntry = (
|
2017-06-21 12:37:48 +00:00
|
|
|
<LexEdit
|
2017-07-13 13:36:47 +00:00
|
|
|
{...props}
|
2017-07-12 06:02:01 +00:00
|
|
|
key={props.searchText}
|
|
|
|
|
lexItem={addProps}
|
2017-06-21 12:37:48 +00:00
|
|
|
selectionMeta={props.selectionMeta}
|
2017-07-18 10:24:19 +00:00
|
|
|
existing={false}
|
2017-06-21 12:37:48 +00:00
|
|
|
/>
|
|
|
|
|
);
|
2017-07-12 06:02:01 +00:00
|
|
|
editEntries.push(addEntry);
|
|
|
|
|
return editEntries;
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-07-13 10:30:36 +00:00
|
|
|
// const debouncedSelect = _.throttle(selectMode,10000,{leading:true});
|
2017-06-20 13:20:54 +00:00
|
|
|
|
|
|
|
|
return (
|
2017-06-22 11:34:06 +00:00
|
|
|
<Flex wrap={true}>
|
2017-07-12 06:02:01 +00:00
|
|
|
{selectMode(params)}
|
2017-06-20 13:20:54 +00:00
|
|
|
</Flex>
|
|
|
|
|
);
|
2017-06-19 06:38:08 +00:00
|
|
|
}
|