@zeniai/client-epic-state 4.19.84-betaVR3 → 4.19.84-betaVR4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { from, merge, of } from 'rxjs';
1
+ import { EMPTY, from, merge, of } from 'rxjs';
2
2
  import { catchError, debounceTime, filter, mergeMap, switchMap } from 'rxjs/operators';
3
3
  import { convertToPeriod } from '../../../../commonStateTypes/timePeriod';
4
4
  import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
@@ -16,9 +16,14 @@ export const MANUAL_TRANSACTION_SEARCH_AUTO_CATEGORIZED = false;
16
16
  export const searchTransactionsForManualMatchEpic = (actions$, state$, zeniAPI) => {
17
17
  const searchActions$ = actions$.pipe(filter(searchTransactionsForManualMatch.match));
18
18
  const pagination$ = searchActions$.pipe(filter((a) => a.payload.pageToken != null));
19
- const newSearch$ = searchActions$.pipe(filter((a) => a.payload.pageToken == null), debounceTime(300));
20
- return merge(pagination$, newSearch$).pipe(switchMap((action) => {
19
+ /** Clears: no debounce so switchMap cancels in-flight HTTP from the previous query immediately. */
20
+ const newSearchClear$ = searchActions$.pipe(filter((a) => a.payload.pageToken == null && a.payload.query.trim() === ''));
21
+ const newSearchDebounced$ = searchActions$.pipe(filter((a) => a.payload.pageToken == null && a.payload.query.trim() !== ''), debounceTime(300));
22
+ return merge(pagination$, newSearchClear$, newSearchDebounced$).pipe(switchMap((action) => {
21
23
  const { query, pageToken } = action.payload;
24
+ if (pageToken == null && query.trim() === '') {
25
+ return EMPTY;
26
+ }
22
27
  const state = state$.value;
23
28
  const { expenseAutomationViewState: { selectedPeriodByTenantId }, expenseAutomationMissingReceiptsViewState: { bulkUpload: { manualSearch, sortKey, sortOrder }, }, } = state;
24
29
  const currentTenant = getCurrentTenant(state);
@@ -384,6 +384,16 @@ const expenseAutomationMissingReceiptsView = createSlice({
384
384
  reducer(draft, action) {
385
385
  const { query, pageToken } = action.payload;
386
386
  const isLoadMore = pageToken != null;
387
+ const trimmed = query.trim();
388
+ /**
389
+ * Cleared input: reset fully (no In-Progress) so we never show a loader with stale rows,
390
+ * and the epic can cancel any in-flight search via switchMap without a debounce delay.
391
+ */
392
+ if (!isLoadMore && trimmed === '') {
393
+ draft.bulkUpload.manualSearch = initialBulkUploadState.manualSearch;
394
+ draft.bulkUpload.manualSearchUiResetKey += 1;
395
+ return;
396
+ }
387
397
  draft.bulkUpload.manualSearch.searchQuery = query;
388
398
  if (isLoadMore) {
389
399
  draft.bulkUpload.manualSearch.isLoadingMore = true;