#Setting store value and Running Queries in sequence

1 messages · Page 1 of 1 (latest)

dawn igloo
#

I am implementing a custom filter-like widget that lets users change certain variables within the app. I want those variables to only "affect" the queries once. Look at the attached image. Because of this, I cannot use the selected dropdown items and date picker value directly in the query. I have it set up such that when the apply button is clicked, the values mentioned are assigned/updated in the appsmith.store. There are two issues:

  1. When the apply button is tapped, the query params change but the queries do not run automatically.
  2. If I force them to run by calling them via.run() method, the widgets showing ddata do not show the latest data until I tap the Apply button again.
olive frost
#

@dawn igloo would it be possible for you to share your code for the onClick event on the Apply button?

dawn igloo
#
setQueryParams: () => {
        storeValue("listOfStores",selectStores.selectedOptionValues);
        storeValue("date",moment(pickerDate.formattedDate).format("YYYY-MM-DD"));
        utils.refreshAllApiCalls();
    },
    refreshAllApiCalls: () => {
        countClean.run();
        countGrind.run();
        countCasePull.run();
    },
polar burrowBOT
#

Hey there! Thanks for sharing the code, it helps in understanding the problem

#

Now, I assume you are also using those store values listOfStores and date in
the count* queries being run from refreshAllApiCalls. If that's the case then
this is a classic issue of sequential/Async execution. storeValue func is
async in nature so, it can happen that the store is not updated and you are
triggering the APIs. if you want to make it sync, use it like so -

setQueryParams: async () => {
await storeValue('...', <value>);
}

This makes sure that the new values are set before running the APIs/Queries

#

To answer your Que 1 - Actions like APIs/Queries/functions are not triggered
automatically when their dependency changes

dawn igloo
#

That makes a lot sense. Seems like a rookie mistake. I'll give it a try when I get a chance.

Just to reconfirm, I HAVE to manually refresh all of my API calls if query parame change right?

polar burrowBOT
#

Yes