Skip to content

Commit

Permalink
#27 #28 added autocompletion with topterms for general search field
Browse files Browse the repository at this point in the history
  • Loading branch information
leoek committed Nov 4, 2018
1 parent f1da107 commit c462e6e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
11 changes: 7 additions & 4 deletions frontend/src/components/SearchForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { withStyles } from "@material-ui/core/styles";
import { Field, reduxForm } from "redux-form";
import { translate } from "react-i18next";
import classnames from "classnames";
import { getSearchIsFetching } from "../redux/selectors";
import { getSearchIsFetching, getSuggestValue } from "../redux/selectors";

import { RenderTextField, RenderCheckbox } from "./common/InputFields";
import { RenderCheckbox, InputAutoSuggest } from "./common/InputFields";

const styles = theme => ({
root: {
Expand Down Expand Up @@ -107,10 +107,13 @@ export class SearchForm extends Component {
lg={10}
className={classes.formItemContainer}
>
<Field
<InputAutoSuggest
label={t("searchform.search.querylbl")}
name="query"
component={RenderTextField}
options={{
endpoint: "top"
}}
suggestionsSelector={getSuggestValue("topTerms")("query")}
className={classes.formItem}
/>
</Grid>
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/components/common/InputFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const RawInputAutoSuggest = ({
count,
suggestions,
classes,
fetchSuggestRequest
fetchSuggestRequest,
options
}) => (
<Field
label={label}
Expand All @@ -72,7 +73,8 @@ const RawInputAutoSuggest = ({
fetchSuggestRequest({
s: value,
field: name,
count
count,
options
})
}
handleClearSuggestions={() => false}
Expand All @@ -82,9 +84,11 @@ const RawInputAutoSuggest = ({
export const InputAutoSuggest = compose(
connect(
(state, ownProps) => {
const { name } = ownProps;
const { name, suggestionsSelector } = ownProps;
return {
suggestions: getSuggestions(name)(state)
suggestions: suggestionsSelector
? suggestionsSelector(state)
: getSuggestions(name)(state)
};
},
{ fetchSuggestRequest }
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import datasheetFormat, { ingredientFormat } from "./datasheetFormat";
const devEnv = process.env.NODE_ENV === "development";

const devConfig = {
apiBaseUrl: "http://localhost:8080"
//apiBaseUrl: "https://api.mss.leoek.tech"
//apiBaseUrl: "http://localhost:8080"
apiBaseUrl: "https://api.mss.leoek.tech"
};

export const baseConfig = {
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/redux/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ export const FETCH_SUGGEST_REQUEST = "MSS/FETCH_SUGGEST_REQUEST";
export const fetchSuggestRequest = ({
s,
field,
count = config.DEFAULTS.suggestionCount
count = config.DEFAULTS.suggestionCount,
options
}) => ({
type: FETCH_SUGGEST_REQUEST,
payload: {
s,
field,
count
count,
options
}
});

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/redux/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ const handleResponseJsonError = (errorMessage, statusCode) => {

export function* fetchSuggestSaga(action) {
const { payload = {} } = action;
const { field, s, count } = payload;
const { field, s, count, options = {} } = payload;
const { endpoint = "suggest" } = options;
const parameters = {
field,
count,
s
};
const response = yield get({
endpoint: "suggest",
endpoint,
parameters
});
const reponseData = yield response.json().catch(handleResponseJsonError);
Expand Down

0 comments on commit c462e6e

Please sign in to comment.