4

I have saved a query in a DB and recalled it for running again. However, I do not know how re-run the query.

I obtain the query in the onChange and saved the value to the DB as a string for recalling later so it can be worked on.

<ReactiveBase app={this.props.app} url={config.elastic.URL} >
        <StateProvider
          onChange={(prevState, nextState) => {
            queryString = nextState;
            console.log('onChange');
          }}

I was looking at a way to put that query string in the DataSearch component if that is the correct thing to do. The query is quite large as I have additional components attached to the search.

If I set the value of the DataSearch to my queryString I can not type in the search bar

<DataSearch
                dataField={this.props.refinement.searchBar}
                componentId="search"
                placeholder="Search books or videos"
                autosuggest={false}
                debounce={debounce}
                showClear={true}
                customQuery={this.props.customQuery}
                defaultValue={this.props.defaultValue}
                value={queryString}
              >
              </DataSearch>

also the query is an elastic search query so I get a search bar full of JSON. I can get the indavidual elements and set queryString to that which gives me half of what I want but with a searchbar I can not type into.

var objectQuery = JSON.parse(selectedQueryString);
queryString = objectQuery.search.value;

Update

This helped in being able to type in the searchBar and update the value and may even be most of the way there for the DataSearch component.

value={this.state.value}
    onChange={(value, triggerQuery, event) => {
        this.setState(
            {
                value,
            },
            () => triggerQuery(),
        );
  }}
user1767752
  • 360
  • 5
  • 11
  • 1
    Hey, if I am correct by queryString you mean the search value. So you are passing it in value making the component as controlled component, so you may additionally need to define onChange handler as well for changing the value. If you only need to add the value for initial mount you can make use of `defaultValue`. Let me know if you have any issue. – Yash Joshi Apr 15 '20 at 07:32
  • the defaultValue is used when you first load the component I need to to be able to set the value of each component used in the search. I was hoping that some black-box magic would handle this all for me. However, you need to set the value of each component used in the search – user1767752 Apr 24 '20 at 10:29

1 Answers1

0

You can not push the query string back into the component and let it handle all the components used to create the query. You have to get the values from the query string and set the values of the components again. The query then will be re-run using via the onChange mehtod.

user1767752
  • 360
  • 5
  • 11