removed mode enum
parent
2c62605deb
commit
421b7c79dc
|
|
@ -9,7 +9,9 @@ class App extends React.Component<{}, null> {
|
||||||
<div>
|
<div>
|
||||||
<nav className="pt-navbar pt-dark">
|
<nav className="pt-navbar pt-dark">
|
||||||
<div className="pt-navbar-group pt-align-left">
|
<div className="pt-navbar-group pt-align-left">
|
||||||
<button className="pt-button pt-minimal pt-icon-large pt-icon-edit" />
|
<button
|
||||||
|
className="pt-button pt-minimal pt-icon-large pt-icon-edit"
|
||||||
|
/>
|
||||||
<div className="pt-navbar-heading">Freespeech Lexicon Editor</div>
|
<div className="pt-navbar-heading">Freespeech Lexicon Editor</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,6 @@ const { Flex, Box } = require('reflexbox');
|
||||||
|
|
||||||
FocusStyleManager.onlyShowFocusOnTabs();
|
FocusStyleManager.onlyShowFocusOnTabs();
|
||||||
|
|
||||||
enum EditorMode {
|
|
||||||
Empty = 1, Edit, Add
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LexEditorProps {
|
interface LexEditorProps {
|
||||||
fileName: RequestInfo;
|
fileName: RequestInfo;
|
||||||
}
|
}
|
||||||
|
|
@ -33,7 +29,7 @@ const searchLensMap = {
|
||||||
class LexEditor extends React.Component<LexEditorProps, any> {
|
class LexEditor extends React.Component<LexEditorProps, any> {
|
||||||
constructor(props: LexEditorProps) {
|
constructor(props: LexEditorProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = { lexData: {}, matchedEntries: [] };
|
this.state = { lexData: {}, matchedEntries: [], searchText: '' };
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidMount() {
|
public componentDidMount() {
|
||||||
|
|
@ -57,7 +53,7 @@ class LexEditor extends React.Component<LexEditorProps, any> {
|
||||||
matchedEntries={this.state.matchedEntries}
|
matchedEntries={this.state.matchedEntries}
|
||||||
mode={this.state.mode}
|
mode={this.state.mode}
|
||||||
searchText={this.state.searchText}
|
searchText={this.state.searchText}
|
||||||
searchType={this.state.searchType}
|
searchLens={this.state.searchLens}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
@ -65,7 +61,7 @@ class LexEditor extends React.Component<LexEditorProps, any> {
|
||||||
|
|
||||||
private handleOnSearch(searchEvent: any): void {
|
private handleOnSearch(searchEvent: any): void {
|
||||||
let searchText = searchEvent.searchValue;
|
let searchText = searchEvent.searchValue;
|
||||||
let searchType = searchLensMap[searchEvent.searchType];
|
let searchLens = searchLensMap[searchEvent.searchType];
|
||||||
let matchedEntries = _.chain(this.state.lexData)
|
let matchedEntries = _.chain(this.state.lexData)
|
||||||
.get<any>('document.lexicon[0].item')
|
.get<any>('document.lexicon[0].item')
|
||||||
.flatMap((o: any) => _.chain(o)
|
.flatMap((o: any) => _.chain(o)
|
||||||
|
|
@ -76,11 +72,9 @@ class LexEditor extends React.Component<LexEditorProps, any> {
|
||||||
.value())
|
.value())
|
||||||
.value()
|
.value()
|
||||||
)
|
)
|
||||||
.filter((q: any) => _.get<any>(q, searchType, '') === searchText)
|
.filter((q: any) => _.get<any>(q, searchLens, '') === searchText)
|
||||||
.value();
|
.value();
|
||||||
let emptyOrAdd = searchText === '' ? EditorMode.Empty : EditorMode.Add;
|
this.setState({ ...this.state, matchedEntries, searchText, searchLens });
|
||||||
let mode = matchedEntries.length > 0 ? EditorMode.Edit : emptyOrAdd;
|
|
||||||
this.setState({ ...this.state, matchedEntries, mode, searchText, searchType });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,8 +89,8 @@ class LexSearch extends React.Component<any, any> {
|
||||||
onChange={e => this.handleTypeChange(e)}
|
onChange={e => this.handleTypeChange(e)}
|
||||||
>
|
>
|
||||||
<select>
|
<select>
|
||||||
{_.keys(searchLensMap).map(k => {
|
{_.keys(searchLensMap).map((k, i, c) => {
|
||||||
return <option value={k}> {_.capitalize(k)}</option>;
|
return <option key={i} value={k}> {_.capitalize(k)}</option>;
|
||||||
})}
|
})}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -116,39 +110,43 @@ class LexSearch extends React.Component<any, any> {
|
||||||
|
|
||||||
private handleLookup(e: any) {
|
private handleLookup(e: any) {
|
||||||
this.searchValue = e.target.value;
|
this.searchValue = e.target.value;
|
||||||
this.props.handleOnSearch({ searchType: this.searchType, searchValue: this.searchValue });
|
this.props.handleOnSearch({
|
||||||
|
searchType: this.searchType
|
||||||
|
, searchValue: this.searchValue
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleTypeChange(e: any) {
|
private handleTypeChange(e: any) {
|
||||||
this.searchType = e.target.value;
|
this.searchType = e.target.value;
|
||||||
this.props.handleOnSearch({ searchType: this.searchType, searchValue: this.searchValue });
|
this.props.handleOnSearch({
|
||||||
|
searchType: this.searchType
|
||||||
|
, searchValue: this.searchValue
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectMode(props: any) {
|
function selectMode(props: any) {
|
||||||
let editEntries = props.matchedEntries.map((mObj: any) => {
|
if (props.searchText === '') {
|
||||||
let uniqueKey = mObj.guid[0] + '#' + mObj.$.id;
|
return (
|
||||||
return (<LexEdit key={uniqueKey} lexItem={mObj} />);
|
<div className="pt-non-ideal-state">
|
||||||
});
|
<div className="pt-non-ideal-state-visual pt-non-ideal-state-icon">
|
||||||
switch (props.mode) {
|
<span className="pt-icon pt-icon-folder-open" />
|
||||||
case EditorMode.Edit:
|
|
||||||
return editEntries;
|
|
||||||
case EditorMode.Add:
|
|
||||||
let addProps = {};
|
|
||||||
_.set(addProps, props.searchType, props.searchText);
|
|
||||||
return <LexEdit lexItem={addProps} />;
|
|
||||||
default:
|
|
||||||
return (
|
|
||||||
<div className="pt-non-ideal-state">
|
|
||||||
<div className="pt-non-ideal-state-visual pt-non-ideal-state-icon">
|
|
||||||
<span className="pt-icon pt-icon-folder-open" />
|
|
||||||
</div>
|
|
||||||
<h4 className="pt-non-ideal-state-title">Empty</h4>
|
|
||||||
<div className="pt-non-ideal-state-description">
|
|
||||||
Type something in the searchbar.
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
<h4 className="pt-non-ideal-state-title">Empty</h4>
|
||||||
|
<div className="pt-non-ideal-state-description">
|
||||||
|
Type something in the searchbar.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
let editEntries = props.matchedEntries.map((mObj: any) => {
|
||||||
|
let uniqueKey = mObj.guid[0] + '#' + mObj.$.id;
|
||||||
|
return (<LexEdit key={uniqueKey} lexItem={mObj} />);
|
||||||
|
});
|
||||||
|
let addProps = {};
|
||||||
|
_.set(addProps, props.searchLens, props.searchText);
|
||||||
|
editEntries.push(<LexEdit key={props.searchText} lexItem={addProps} />);
|
||||||
|
return editEntries;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,7 +165,12 @@ class LexEdit extends React.Component<any, any> {
|
||||||
return this.getLabelField(e, searchLensMap[e], li);
|
return this.getLabelField(e, searchLensMap[e], li);
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<Box wx={240} mx={10} my={20} className="pt-card pt-elevation-2 pt-interactive">
|
<Box
|
||||||
|
wx={240}
|
||||||
|
mx={10}
|
||||||
|
my={20}
|
||||||
|
className="pt-card pt-elevation-2 pt-interactive"
|
||||||
|
>
|
||||||
<label className="pt-label">
|
<label className="pt-label">
|
||||||
GUID {_.get<any>(li, 'guid', '')}
|
GUID {_.get<any>(li, 'guid', '')}
|
||||||
</label>
|
</label>
|
||||||
|
|
@ -207,7 +210,11 @@ class LexField extends React.Component<any, any> {
|
||||||
return (
|
return (
|
||||||
<div className="pt-form-group pt-inline">
|
<div className="pt-form-group pt-inline">
|
||||||
<Box w={2 / 5}>
|
<Box w={2 / 5}>
|
||||||
<label style={{ textAlign: 'right' }} className="pt-label" htmlFor="example-form-group-input-a">
|
<label
|
||||||
|
style={{ textAlign: 'right' }}
|
||||||
|
className="pt-label"
|
||||||
|
htmlFor="example-form-group-input-a"
|
||||||
|
>
|
||||||
{this.props.labelText}
|
{this.props.labelText}
|
||||||
</label>
|
</label>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue