Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web & vue): icons added for recent & popular searches #1635

Merged
merged 19 commits into from Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
703dd38
feat(web): icons added for recent & popular searches
anik-ghosh-au7 Mar 26, 2021
7c58bca
feat(web): inner class keys updated for recent & popular searches icons
anik-ghosh-au7 Mar 26, 2021
fffd6c3
feat(vue): icons added for recent & popular searches
anik-ghosh-au7 Mar 26, 2021
8a0babb
fix(vue): resolved rendering bug in custom svg components
anik-ghosh-au7 Mar 27, 2021
fb50efc
fix: inner class key changed for recent and popular searches
anik-ghosh-au7 Mar 29, 2021
b9ae5a4
feat: submodules updated for vue and web playground
anik-ghosh-au7 Mar 29, 2021
d9f4cb2
fix(vue): dataSearch component updated
anik-ghosh-au7 Apr 5, 2021
3936296
fix(vue): vue-playgoround example updated
anik-ghosh-au7 Apr 5, 2021
8545902
fix(web): datasearch and categorysearch components updated
anik-ghosh-au7 Apr 5, 2021
450722a
fix(web & vue): search components updated
anik-ghosh-au7 Apr 9, 2021
e0c50d9
fix(vue): prop types defined in custom svg component
anik-ghosh-au7 Apr 9, 2021
ec82c92
Update packages/vue/src/components/search/DataSearch.jsx
bietkul Apr 10, 2021
dcee34c
Update packages/web/src/components/search/DataSearch.js
bietkul Apr 10, 2021
7c93778
Update packages/web/src/components/search/CategorySearch.js
bietkul Apr 10, 2021
d8e2565
Update packages/web/src/components/search/CategorySearch.js
bietkul Apr 10, 2021
2bb6f51
Update packages/web/src/components/search/CategorySearch.js
bietkul Apr 10, 2021
a33b5b8
Update packages/web/src/components/search/DataSearch.js
bietkul Apr 10, 2021
fb42d69
Update packages/web/src/components/search/DataSearch.js
bietkul Apr 10, 2021
bbc0878
Update packages/web/src/components/search/DataSearch.js
bietkul Apr 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/vue/src/components/search/DataSearch.jsx
Expand Up @@ -25,6 +25,7 @@ import SuggestionItem from './addons/SuggestionItem.jsx';
import SearchSvg from '../shared/SearchSvg';
import CancelSvg from '../shared/CancelSvg';
import Mic from './addons/Mic.jsx';
import CustomSvg from '../shared/CustomSvg'

const {
updateQuery,
Expand Down Expand Up @@ -121,7 +122,7 @@ const DataSearch = {
: [];
},
normalizedRecentSearches() {
return this.recentSearches || [];
return (this.recentSearches || []).map(search => ({...search, _recent_search: true}));
},
normalizedPopularSuggestions() {
return getTopSuggestions(
Expand Down Expand Up @@ -206,6 +207,8 @@ const DataSearch = {
strictSelection: VueTypes.bool.def(false),
nestedField: types.string,
enablePredictiveSuggestions: VueTypes.bool.def(false),
recentSearchesIcon: VueTypes.any,
anik-ghosh-au7 marked this conversation as resolved.
Show resolved Hide resolved
popularSearchesIcon: VueTypes.any,
// mic props
showVoiceSearch: types.bool.def(false),
getMicInstance: types.func,
Expand Down Expand Up @@ -705,6 +708,7 @@ const DataSearch = {
},
render() {
const { theme, size } = this.$props;
const { recentSearchesIcon, popularSearchesIcon } = this.$scopedSlots;
const hasSuggestions
= this.currentValue
? this.suggestionsList.length || this.topSuggestions.length : this.defaultSearchSuggestions.length;
Expand Down Expand Up @@ -841,8 +845,13 @@ const DataSearch = {
highlightedIndex,
this.suggestionsList.length + index,
),
justifyContent: 'flex-start',
}}
>
<div style={{ padding: '0 10px 0 0' }}>
{sugg.source && sugg.source._recent_search && <CustomSvg className={getClassName(this.$props.innerClass, 'recent-search-icon') || null} icon={recentSearchesIcon} type="recent-search-icon" />}
{sugg.source && sugg.source._popular_suggestion && <CustomSvg className={getClassName(this.$props.innerClass, 'popular-search-icon') || null} icon={popularSearchesIcon} type="popular-search-icon" />}
</div>
<SuggestionItem
currentValue={this.currentValue}
suggestion={sugg}
Expand Down Expand Up @@ -1115,7 +1124,7 @@ const mapStateToProps = (state, props) => ({
total: state.hits[props.componentId] && state.hits[props.componentId].total,
hidden: state.hits[props.componentId] && state.hits[props.componentId].hidden,
querySuggestions: state.querySuggestions[props.componentId],
defaultPopularSuggestions: state.defaultPopularSuggestions[props.componentId],
defaultPopularSuggestions: (state.defaultPopularSuggestions[props.componentId] || []).map(suggestion => ({...suggestion, _popular_suggestion: true})),
anik-ghosh-au7 marked this conversation as resolved.
Show resolved Hide resolved
componentProps: state.props[props.componentId],
lastUsedQuery: state.queryToHits[props.componentId],
recentSearches: state.recentSearches.data,
Expand Down
51 changes: 51 additions & 0 deletions packages/vue/src/components/shared/CustomSvg.js
@@ -0,0 +1,51 @@
const CustomSvg = {
name: 'CustomSvg',
props: ['className', 'icon', 'type'],
anik-ghosh-au7 marked this conversation as resolved.
Show resolved Hide resolved
data() {
return {
customIcon: this.$props.icon && typeof (this.$props.icon) === 'function' ? this.$props.icon() : null,
}
},
render() {
if (this.customIcon) {
return (
<div class={this.$props.className}>
{this.customIcon}
</div>
);
}
if (this.$props.type === 'popular-search-icon') {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
alt="Popular Searches"
height="20"
width="20"
viewBox="0 0 24 24"
style={{fill: '#707070'}}
class={this.$props.className}
>
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M16 6l2.29 2.29-4.88 4.88-4-4L2 16.59 3.41 18l6-6 4 4 6.3-6.29L22 12V6z"/>
</svg>
)
} else {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
alt="Recent Searches"
height="20"
width="20"
viewBox="0 0 24 24"
style={{fill: '#707070'}}
class={this.$props.className}
>
<path d="M0 0h24v24H0z" fill="none" />
<path d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z" />
</svg>
)
}
},
};

export default CustomSvg;
34 changes: 31 additions & 3 deletions packages/web/src/components/search/CategorySearch.js
Expand Up @@ -43,6 +43,7 @@ import SearchSvg from '../shared/SearchSvg';
import InputIcon from '../../styles/InputIcon';
import Container from '../../styles/Container';
import Mic from './addons/Mic';
anik-ghosh-au7 marked this conversation as resolved.
Show resolved Hide resolved
import CustomSvg from '../shared/CustomSvg';
import {
connect,
isFunction,
Expand Down Expand Up @@ -1021,7 +1022,7 @@ class CategorySearch extends Component {
const {
recentSearches,
} = this.props;
return recentSearches || [];
return (recentSearches || []).map(search => ({ ...search, _recent_search: true }));
}

get normalizedPopularSuggestions() {
Expand Down Expand Up @@ -1082,7 +1083,9 @@ class CategorySearch extends Component {

render() {
const { currentValue } = this.state;
const { theme, themePreset, size } = this.props;
const {
theme, themePreset, size, recentSearchesIcon, popularSearchesIcon,
} = this.props;
const finalSuggestionsList = this.parsedSuggestions;
const hasSuggestions = currentValue
? finalSuggestionsList.length || this.topSuggestions.length : this.defaultSuggestions.length;
Expand Down Expand Up @@ -1187,8 +1190,27 @@ class CategorySearch extends Component {
highlightedIndex,
index,
),
justifyContent: 'flex-start',
}}
>
<div style={{ padding: '0 10px 0 0' }}>
{sugg.source
&& sugg.source._recent_search
&& <CustomSvg
iconId={`${sugg.id}-icon`}
className={getClassName(this.props.innerClass, 'recent-search-icon') || null}
icon={recentSearchesIcon}
type="recent-search-icon"
/>}
{sugg.source
&& sugg.source._popular_suggestion
&& <CustomSvg
iconId={`${sugg.id}-icon`}
className={getClassName(this.props.innerClass, 'popular-search-icon') || null}
icon={popularSearchesIcon}
type="popular-search-icon"
/>}
</div>
<SuggestionItem
currentValue={currentValue}
suggestion={sugg}
Expand Down Expand Up @@ -1359,6 +1381,9 @@ CategorySearch.propTypes = {
URLParams: types.bool,
strictSelection: types.bool,
searchOperators: types.bool,
/* eslint-disable react/forbid-prop-types */
recentSearchesIcon: types.any,
popularSearchesIcon: types.any,
// Mic props
getMicInstance: types.func,
renderMic: types.func,
Expand Down Expand Up @@ -1422,7 +1447,10 @@ const mapStateToProps = (state, props) => ({
time: (state.hits[props.componentId] && state.hits[props.componentId].time),
total: state.hits[props.componentId] && state.hits[props.componentId].total,
hidden: state.hits[props.componentId] && state.hits[props.componentId].hidden,
defaultPopularSuggestions: state.defaultPopularSuggestions[props.componentId],
defaultPopularSuggestions: (state.defaultPopularSuggestions[props.componentId] || [])
.map(suggestion => (
{ ...suggestion, _popular_suggestion: true }
)),
popularSuggestions: state.querySuggestions[props.componentId],
recentSearches: state.recentSearches.data,
});
Expand Down
35 changes: 32 additions & 3 deletions packages/web/src/components/search/DataSearch.js
Expand Up @@ -42,6 +42,7 @@ import SearchSvg from '../shared/SearchSvg';
import CancelSvg from '../shared/CancelSvg';
import InputIcon from '../../styles/InputIcon';
import Container from '../../styles/Container';
import CustomSvg from '../shared/CustomSvg';
import {
connect,
isFunction,
Expand Down Expand Up @@ -896,7 +897,7 @@ class DataSearch extends Component {
const {
recentSearches,
} = this.props;
return recentSearches || [];
return (recentSearches || []).map(search => ({ ...search, _recent_search: true }));
}

get normalizedPopularSuggestions() {
Expand Down Expand Up @@ -929,6 +930,7 @@ class DataSearch extends Component {
const defaultSuggestions = isPopularSuggestionsEnabled
? [...this.normalizedRecentSearches, ...defaultPopularSuggestions]
: this.normalizedRecentSearches;

return getTopSuggestions(
// use default popular suggestions if value is empty
defaultSuggestions,
Expand Down Expand Up @@ -958,7 +960,9 @@ class DataSearch extends Component {
render() {
const { currentValue } = this.state;
const suggestionsList = this.parsedSuggestions;
const { theme, themePreset, size } = this.props;
const {
theme, themePreset, size, recentSearchesIcon, popularSearchesIcon,
} = this.props;
const hasSuggestions = currentValue
? suggestionsList.length || this.topSuggestions.length : this.defaultSuggestions.length;
return (
Expand Down Expand Up @@ -1065,8 +1069,27 @@ class DataSearch extends Component {
highlightedIndex,
index,
),
justifyContent: 'flex-start',
}}
>
<div style={{ padding: '0 10px 0 0' }}>
{sugg.source
&& sugg.source._recent_search
&& <CustomSvg
iconId={`${sugg.id}-icon`}
anik-ghosh-au7 marked this conversation as resolved.
Show resolved Hide resolved
className={getClassName(this.props.innerClass, 'recent-search-icon') || null}
icon={recentSearchesIcon}
type="recent-search-icon"
/>}
{sugg.source
&& sugg.source._popular_suggestion
&& <CustomSvg
iconId={`${sugg.id}-icon`}
anik-ghosh-au7 marked this conversation as resolved.
Show resolved Hide resolved
className={getClassName(this.props.innerClass, 'popular-search-icon') || null}
icon={popularSearchesIcon}
type="popular-search-icon"
/>}
</div>
<SuggestionItem
currentValue={currentValue}
suggestion={sugg}
Expand Down Expand Up @@ -1234,6 +1257,9 @@ DataSearch.propTypes = {
strictSelection: types.bool,
searchOperators: types.bool,
enablePredictiveSuggestions: types.bool,
/* eslint-disable react/forbid-prop-types */
recentSearchesIcon: types.any,
anik-ghosh-au7 marked this conversation as resolved.
Show resolved Hide resolved
popularSearchesIcon: types.any,
// Mic props
getMicInstance: types.func,
renderMic: types.func,
Expand Down Expand Up @@ -1288,7 +1314,10 @@ const mapStateToProps = (state, props) => ({
total: state.hits[props.componentId] && state.hits[props.componentId].total,
hidden: state.hits[props.componentId] && state.hits[props.componentId].hidden,
popularSuggestions: state.querySuggestions[props.componentId],
defaultPopularSuggestions: state.defaultPopularSuggestions[props.componentId],
defaultPopularSuggestions: (state.defaultPopularSuggestions[props.componentId] || [])
anik-ghosh-au7 marked this conversation as resolved.
Show resolved Hide resolved
.map(suggestion => (
{ ...suggestion, _popular_suggestion: true }
)),
recentSearches: state.recentSearches.data,
lastUsedQuery: state.queryToHits[props.componentId],
});
Expand Down
58 changes: 58 additions & 0 deletions packages/web/src/components/shared/CustomSvg.js
@@ -0,0 +1,58 @@
import React from 'react';
import types from '@appbaseio/reactivecore/lib/utils/types';

const CustomSvg = ({
iconId, className, icon, type,
}) => {
if (icon) {
return React.createElement('div', { className }, [
React.cloneElement(icon, { key: iconId }),
]);
}
if (type === 'recent-search-icon') {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
alt="Recent Search"
height="20"
width="20"
viewBox="0 0 24 24"
style={{ fill: '#707070' }}
className={className}
>
<path d="M0 0h24v24H0z" fill="none" />
<path d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z" />
</svg>
);
}
return (
<svg
xmlns="http://www.w3.org/2000/svg"
alt="Popular Search"
height="20"
width="20"
viewBox="0 0 24 24"
style={{ fill: '#707070' }}
className={className}
>
<path d="M0 0h24v24H0z" fill="none" />
<path d="M16 6l2.29 2.29-4.88 4.88-4-4L2 16.59 3.41 18l6-6 4 4 6.3-6.29L22 12V6z" />
</svg>
);
};

CustomSvg.propTypes = {
iconId: types.string,
className: types.string,
icon: types.children,
type: types.string,
};

CustomSvg.defaultProps = {
iconId: undefined,
className: null,
icon: undefined,
type: 'recent-search-icon',
};

export default CustomSvg;