Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
fix: DIA-754: [FE] Search option does not reflect actual queries state
Browse files Browse the repository at this point in the history
  • Loading branch information
yyassi-heartex committed Dec 1, 2023
1 parent 93aaec6 commit a0ce76c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/stores/AppStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const AppStore = types
.volatile(() => ({
needsDataFetch: false,
projectFetch: false,
requestsInFlight: new Map(),
}))
.actions((self) => ({
startPolling() {
Expand Down Expand Up @@ -544,12 +545,21 @@ export const AppStore = types
* @param {{ errorHandler?: fn }} [options] additional options like errorHandler
*/
apiCall: flow(function* (methodName, params, body, options) {
const controller = new AbortController();
const signal = controller.signal;
const apiTransform = self.SDK.apiTransform?.[methodName];
const requestParams = apiTransform?.params?.(params) ?? params ?? {};
const requestBody = apiTransform?.body?.(body) ?? body ?? undefined;

const requestBody = { signal, ...(apiTransform?.body?.(body) ?? body) };
const requestKey = `${methodName}_${JSON.stringify(params || {})}`;

if (self.requestsInFlight.has(requestKey)) {
/* if already in flight cancel the first in favor of new one */
self.requestsInFlight.get(requestKey).abort();
}
self.requestsInFlight.set(requestKey, controller);
let result = yield self.API[methodName](requestParams, requestBody);

self.requestsInFlight.delete(requestKey);
if (result.error && result.status !== 404) {
if (options?.errorHandler?.(result)) {
return result;
Expand Down

0 comments on commit a0ce76c

Please sign in to comment.