|
@@ -23,15 +23,15 @@ export default class SearchTypeahead extends React.Component {
|
|
|
searchError: null,
|
|
searchError: null,
|
|
|
};
|
|
};
|
|
|
this.crowi = this.props.crowi;
|
|
this.crowi = this.props.crowi;
|
|
|
- this.emptyLabel = props.emptyLabel;
|
|
|
|
|
|
|
|
|
|
|
|
+ this.restoreInitialData = this.restoreInitialData.bind(this);
|
|
|
this.search = this.search.bind(this);
|
|
this.search = this.search.bind(this);
|
|
|
this.onInputChange = this.onInputChange.bind(this);
|
|
this.onInputChange = this.onInputChange.bind(this);
|
|
|
this.onKeyDown = this.onKeyDown.bind(this);
|
|
this.onKeyDown = this.onKeyDown.bind(this);
|
|
|
this.dispatchSubmit = this.dispatchSubmit.bind(this);
|
|
this.dispatchSubmit = this.dispatchSubmit.bind(this);
|
|
|
|
|
+ this.getEmptyLabel = this.getEmptyLabel.bind(this);
|
|
|
this.getRestoreFormButton = this.getRestoreFormButton.bind(this);
|
|
this.getRestoreFormButton = this.getRestoreFormButton.bind(this);
|
|
|
this.renderMenuItemChildren = this.renderMenuItemChildren.bind(this);
|
|
this.renderMenuItemChildren = this.renderMenuItemChildren.bind(this);
|
|
|
- this.restoreInitialData = this.restoreInitialData.bind(this);
|
|
|
|
|
this.getTypeahead = this.getTypeahead.bind(this);
|
|
this.getTypeahead = this.getTypeahead.bind(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -48,6 +48,14 @@ export default class SearchTypeahead extends React.Component {
|
|
|
componentWillUnmount() {
|
|
componentWillUnmount() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Initialize keyword
|
|
|
|
|
+ */
|
|
|
|
|
+ restoreInitialData() {
|
|
|
|
|
+ this.refs.typeahead.getInstance().clear();
|
|
|
|
|
+ this.refs.typeahead.getInstance()._updateText(this.props.keywordOnInit);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
search(keyword) {
|
|
search(keyword) {
|
|
|
|
|
|
|
|
if (keyword === '') {
|
|
if (keyword === '') {
|
|
@@ -110,23 +118,20 @@ export default class SearchTypeahead extends React.Component {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- renderMenuItemChildren(option, props, index) {
|
|
|
|
|
- const page = option;
|
|
|
|
|
- return (
|
|
|
|
|
- <span>
|
|
|
|
|
- <UserPicture user={page.lastUpdateUser} size="sm" />
|
|
|
|
|
- <PagePath page={page} />
|
|
|
|
|
- <PageListMeta page={page} />
|
|
|
|
|
- </span>
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ getEmptyLabel() {
|
|
|
|
|
+ // use props.emptyLabel as is if defined
|
|
|
|
|
+ if (this.props.emptyLabel !== undefined) {
|
|
|
|
|
+ return this.props.emptyLabel;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Initialize keyword
|
|
|
|
|
- */
|
|
|
|
|
- restoreInitialData() {
|
|
|
|
|
- this.refs.typeahead.getInstance().clear();
|
|
|
|
|
- this.refs.typeahead.getInstance()._updateText(this.props.keywordOnInit);
|
|
|
|
|
|
|
+ let emptyLabelExceptError = 'No matches found on title...';
|
|
|
|
|
+ if (this.props.emptyLabelExceptError !== undefined) {
|
|
|
|
|
+ emptyLabelExceptError = this.props.emptyLabelExceptError;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return (this.state.searchError !== null)
|
|
|
|
|
+ ? 'Error on searching.'
|
|
|
|
|
+ : emptyLabelExceptError;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -142,26 +147,39 @@ export default class SearchTypeahead extends React.Component {
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ renderMenuItemChildren(option, props, index) {
|
|
|
|
|
+ const page = option;
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span>
|
|
|
|
|
+ <UserPicture user={page.lastUpdateUser} size="sm" />
|
|
|
|
|
+ <PagePath page={page} />
|
|
|
|
|
+ <PageListMeta page={page} />
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
render() {
|
|
render() {
|
|
|
- const emptyLabel = (this.state.searchError !== null)
|
|
|
|
|
- ? 'Error on searching.'
|
|
|
|
|
- : 'No matches found on title...';
|
|
|
|
|
- const restoreFormButton = this.getRestoreFormButton();
|
|
|
|
|
const defaultSelected = (this.props.keywordOnInit != '')
|
|
const defaultSelected = (this.props.keywordOnInit != '')
|
|
|
? [{path: this.props.keywordOnInit}]
|
|
? [{path: this.props.keywordOnInit}]
|
|
|
: [];
|
|
: [];
|
|
|
|
|
+ const inputProps = { autoComplete: 'off' };
|
|
|
|
|
+ if (this.props.inputName != null) {
|
|
|
|
|
+ inputProps.name = this.props.inputName;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const restoreFormButton = this.getRestoreFormButton();
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className="search-typeahead">
|
|
<div className="search-typeahead">
|
|
|
<AsyncTypeahead
|
|
<AsyncTypeahead
|
|
|
{...this.props}
|
|
{...this.props}
|
|
|
ref="typeahead"
|
|
ref="typeahead"
|
|
|
- inputProps={{autoComplete: 'off'}}
|
|
|
|
|
|
|
+ inputProps={inputProps}
|
|
|
isLoading={this.state.isLoading}
|
|
isLoading={this.state.isLoading}
|
|
|
labelKey="path"
|
|
labelKey="path"
|
|
|
minLength={0}
|
|
minLength={0}
|
|
|
options={this.state.pages} // Search result (Some page names)
|
|
options={this.state.pages} // Search result (Some page names)
|
|
|
- emptyLabel={this.emptyLabel ? this.emptyLabel : emptyLabel}
|
|
|
|
|
|
|
+ emptyLabel={this.getEmptyLabel()}
|
|
|
align='left'
|
|
align='left'
|
|
|
submitFormOnEnter={true}
|
|
submitFormOnEnter={true}
|
|
|
onSearch={this.search}
|
|
onSearch={this.search}
|
|
@@ -188,7 +206,9 @@ SearchTypeahead.propTypes = {
|
|
|
onChange: PropTypes.func,
|
|
onChange: PropTypes.func,
|
|
|
onSubmit: PropTypes.func,
|
|
onSubmit: PropTypes.func,
|
|
|
onInputChange: PropTypes.func,
|
|
onInputChange: PropTypes.func,
|
|
|
|
|
+ inputName: PropTypes.string,
|
|
|
emptyLabel: PropTypes.string,
|
|
emptyLabel: PropTypes.string,
|
|
|
|
|
+ emptyLabelExceptError: PropTypes.string,
|
|
|
placeholder: PropTypes.string,
|
|
placeholder: PropTypes.string,
|
|
|
keywordOnInit: PropTypes.string,
|
|
keywordOnInit: PropTypes.string,
|
|
|
promptText: PropTypes.object,
|
|
promptText: PropTypes.object,
|
|
@@ -201,7 +221,6 @@ SearchTypeahead.defaultProps = {
|
|
|
onSearchSuccess: noop,
|
|
onSearchSuccess: noop,
|
|
|
onSearchError: noop,
|
|
onSearchError: noop,
|
|
|
onChange: noop,
|
|
onChange: noop,
|
|
|
- emptyLabel: null,
|
|
|
|
|
placeholder: '',
|
|
placeholder: '',
|
|
|
keywordOnInit: '',
|
|
keywordOnInit: '',
|
|
|
onInputChange: () => {},
|
|
onInputChange: () => {},
|