appbaseio / reactivesearch

Search UI components for React and Vue
https://opensource.appbase.io/reactivesearch
Apache License 2.0
4.9k stars 466 forks source link

Accept `query` key in customQuery prop #433

Open siddharthlatest opened 6 years ago

siddharthlatest commented 6 years ago

Issue Type:

Enhancement

Platform:

Web

Description:

We currently only accept the inner part of the query to be passed in the customQuery prop. This can be confusing as we do accept query key in the defaultQuery prop.

Even though we don't use the query key internally, we can allow users to add it and then strip it when present.

Reactivesearch version: x.y.z

2.6.8

aeronesto commented 6 years ago

Maybe it just needs to be updated in the documentation?

It looks like the updateQuery action creator does check for the presence of query.query in both customQuery & defaultQuery, since query = props.customQuery || CategorySearch.defaultQuery; in DataSearch.js:

function updateQuery(_ref){
  var componentId=_ref.componentId,query=_ref.query,value=_ref.value,_ref$label=_ref.label,label=_ref$label===undefined?null:_ref$label,_ref$showFilter=_ref.showFilter,showFilter=_ref$showFilter===undefined?true:_ref$showFilter,_ref$URLParams=_ref.URLParams,URLParams=_ref$URLParams===undefined?false:_ref$URLParams;
  var execute=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;
  return function(dispatch){
    var queryToDispatch=query;
    if(query&&query.query){
      queryToDispatch=query.query;
    }
...

DataSearch.js:

this.updateQuery = function (componentId, value, props, category) {
    var query = props.customQuery || CategorySearch.defaultQuery;

    props.updateQuery({
        componentId: componentId,
        query: query(value, props, category),
        value: value,
        label: props.filterLabel,
        showFilter: props.showFilter,
        URLParams: props.URLParams
    });
};