Skip to content

Commit

Permalink
fix(ui): properly debounce/abort logs search (#3412)
Browse files Browse the repository at this point in the history
## Changes

Fixes
https://linear.app/nango/issue/NAN-2629/date-filter-issue-when-selecting-past-dates

![Screenshot 2025-01-30 at 14 41
03](https://github.com/user-attachments/assets/4d23fea7-712b-4d25-a14d-fb5dbfe27e10)


- Properly debounce/abort logs search
When you start selecting a day in the date picker it triggers an initial
search that would be done by the time you finished picking the end day
of your date range. Which then triggered a second query but with the
previous invalid data not being removed.
I had bad cancellation/concurrency strategies:
- with the `isLoading` debounce which was not triggering some search =
not aborting and not fetching
- the signal was passed as reference which could be replaced by another
signal controller before being checked

## 🧪 Tests
- Go to UI
- Pick a first day, try to wait 100-200ms before clicking another day
(it's not that simple though)
- At the end you should have proper data
e.g: have the last 2 days picked, start clicking Jan 22, wait, then
click Jan 23 as the end day. You should not see Jan 30 as the last
operation
  • Loading branch information
bodinsamuel authored Jan 30, 2025
1 parent 70985e9 commit 64805ae
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/webapp/src/hooks/useLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export function useSearchOperations(env: string, body: SearchOperations['Body'],
}

setLoading(true);
signal.current = new AbortController();
const mySignal = new AbortController();
mySignal.signal.throwIfAborted();
signal.current = mySignal;
try {
let period = body.period;
// Slide the window automatically when live
Expand All @@ -30,7 +32,7 @@ export function useSearchOperations(env: string, body: SearchOperations['Body'],
const res = await apiFetch(`/api/v1/logs/operations?env=${env}`, {
method: 'POST',
body: JSON.stringify({ ...body, period, cursor }),
signal: signal.current.signal
signal: mySignal.signal
});
if (res.status !== 200) {
return { error: (await res.json()) as SearchOperations['Errors'] };
Expand Down Expand Up @@ -70,9 +72,7 @@ export function useSearchOperations(env: string, body: SearchOperations['Body'],
// }, [enabled, env, body.limit, body.states, body.integrations, body.period, body.types, body.connections, body.syncs]);

function trigger(cursor?: SearchOperations['Body']['cursor']) {
if (!loading) {
void fetchData(cursor);
}
void fetchData(cursor);
}

return { data, error, loading, trigger, manualFetch };
Expand Down

0 comments on commit 64805ae

Please sign in to comment.