From 184a1c8c99be90caa83186902ddb2976a31ca274 Mon Sep 17 00:00:00 2001 From: Esko Ikkala <esko.ikkala@aalto.fi> Date: Fri, 27 Apr 2018 10:33:03 +0300 Subject: [PATCH] Add sections to suggestions Co-authored-by: Erkki Heino <erkki.heino@aalto.fi> --- src/components/IntegrationAutosuggest.js | 13 +++++++++++++ src/reducers/search.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/IntegrationAutosuggest.js b/src/components/IntegrationAutosuggest.js index bcbe5dfd..9c1ffbdc 100644 --- a/src/components/IntegrationAutosuggest.js +++ b/src/components/IntegrationAutosuggest.js @@ -58,6 +58,16 @@ function renderSuggestionsContainer(options) { ); } +function renderSectionTitle(section) { + return ( + <strong>{section.dataset}</strong> + ); +} + +function getSectionSuggestions(section) { + return section.results; +} + function getSuggestionValue(suggestion) { return suggestion.label; } @@ -102,12 +112,15 @@ const IntegrationAutosuggest = (props) => { suggestionsList: classes.suggestionsList, suggestion: classes.suggestion, }} + multiSection={true} renderInputComponent={renderInput} suggestions={props.search.suggestions} onSuggestionsClearRequested={props.clearSuggestions} onSuggestionsFetchRequested={props.fetchSuggestions} renderSuggestionsContainer={renderSuggestionsContainer} getSuggestionValue={getSuggestionValue} + renderSectionTitle={renderSectionTitle} + getSectionSuggestions={getSectionSuggestions} renderSuggestion={renderSuggestion} inputProps={{ classes, diff --git a/src/reducers/search.js b/src/reducers/search.js index 8f6d0139..225f4994 100644 --- a/src/reducers/search.js +++ b/src/reducers/search.js @@ -2,7 +2,7 @@ import { UPDATE_QUERY, FETCH_SUGGESTIONS, UPDATE_DATASETS, UPDATE_SUGGESTIONS, C export const INITIAL_STATE = { query: '', - datasets: ['warsa_karelian_places'], + datasets: ['warsa_karelian_places', 'warsa_municipalities'], suggestions: [], isFetchingSuggestions: false, }; -- GitLab