@zeniai/client-epic-state 5.1.18-betaRD2 → 5.1.18-betaRD3

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, of } from 'rxjs';
1
+ import { EMPTY, from, of } from 'rxjs';
2
2
  import { catchError, filter, groupBy, mergeMap, switchMap } from 'rxjs/operators';
3
3
  import { toString } from '../../../../commonStateTypes/timePeriod';
4
4
  import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
@@ -16,6 +16,7 @@ groupBy((action) => action.payload.selectedTab), mergeMap((group$) => group$.pip
16
16
  const { period, keepExistingListItems, selectedTab, refreshViewInBackground, } = action.payload;
17
17
  const uiState = expenseAutomationTransactionsViewState.transactionCategorizationView[selectedTab].uiState;
18
18
  const { pageToken, sortOrder, sortKey } = uiState;
19
+ const requestSearchString = uiState.searchString;
19
20
  const currentTenant = getCurrentTenant(state$.value);
20
21
  const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
21
22
  const queryParam = {
@@ -39,6 +40,17 @@ groupBy((action) => action.payload.selectedTab), mergeMap((group$) => group$.pip
39
40
  .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/expense-automation/transactions?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
40
41
  .pipe(mergeMap((response) => {
41
42
  if (isSuccessResponse(response) && response.data != null) {
43
+ // Stale-response guard: if search was cleared while this
44
+ // request was in-flight (restoreFullDatasetSnapshot ran),
45
+ // discard results to avoid overwriting the restored IDs and
46
+ // counts. switchMap only cancels on a new fetchTransactionCategorization
47
+ // for the same tab; restore doesn't dispatch one, so we guard here.
48
+ const currentSearchString = state$.value.expenseAutomationTransactionsViewState
49
+ .transactionCategorizationView[selectedTab].uiState
50
+ .searchString;
51
+ if (currentSearchString !== requestSearchString) {
52
+ return EMPTY;
53
+ }
42
54
  const updateActions = [];
43
55
  updateActions.push(updateTransactions(response.data.transactions, (value) => value.transaction_id, 'merge'));
44
56
  const transactionIds = response.data.transactions.map((transaction) => transaction.transaction_id);
@@ -744,6 +744,10 @@ const expenseAutomationTransactionsView = createSlice({
744
744
  '';
745
745
  draft.transactionCategorizationView[selectedTab].uiState.pageToken = null;
746
746
  draft.transactionCategorizationView[selectedTab].fetchState = 'Completed';
747
+ draft.transactionCategorizationView[selectedTab].refreshStatus = {
748
+ fetchState: 'Not-Started',
749
+ error: undefined,
750
+ };
747
751
  draft.transactionCategorizationView[selectedTab].error = undefined;
748
752
  draft.transactionCategorizationView[selectedTab].fullDatasetSnapshot =
749
753
  undefined;
@@ -19,6 +19,7 @@ const fetchTransactionCategorizationEpic = (actions$, state$, zeniAPI) => action
19
19
  const { period, keepExistingListItems, selectedTab, refreshViewInBackground, } = action.payload;
20
20
  const uiState = expenseAutomationTransactionsViewState.transactionCategorizationView[selectedTab].uiState;
21
21
  const { pageToken, sortOrder, sortKey } = uiState;
22
+ const requestSearchString = uiState.searchString;
22
23
  const currentTenant = (0, tenantSelector_1.getCurrentTenant)(state$.value);
23
24
  const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
24
25
  const queryParam = {
@@ -42,6 +43,17 @@ const fetchTransactionCategorizationEpic = (actions$, state$, zeniAPI) => action
42
43
  .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/expense-automation/transactions?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
43
44
  .pipe((0, operators_1.mergeMap)((response) => {
44
45
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
46
+ // Stale-response guard: if search was cleared while this
47
+ // request was in-flight (restoreFullDatasetSnapshot ran),
48
+ // discard results to avoid overwriting the restored IDs and
49
+ // counts. switchMap only cancels on a new fetchTransactionCategorization
50
+ // for the same tab; restore doesn't dispatch one, so we guard here.
51
+ const currentSearchString = state$.value.expenseAutomationTransactionsViewState
52
+ .transactionCategorizationView[selectedTab].uiState
53
+ .searchString;
54
+ if (currentSearchString !== requestSearchString) {
55
+ return rxjs_1.EMPTY;
56
+ }
45
57
  const updateActions = [];
46
58
  updateActions.push((0, transactionReducer_1.updateTransactions)(response.data.transactions, (value) => value.transaction_id, 'merge'));
47
59
  const transactionIds = response.data.transactions.map((transaction) => transaction.transaction_id);
@@ -751,6 +751,10 @@ const expenseAutomationTransactionsView = (0, toolkit_1.createSlice)({
751
751
  '';
752
752
  draft.transactionCategorizationView[selectedTab].uiState.pageToken = null;
753
753
  draft.transactionCategorizationView[selectedTab].fetchState = 'Completed';
754
+ draft.transactionCategorizationView[selectedTab].refreshStatus = {
755
+ fetchState: 'Not-Started',
756
+ error: undefined,
757
+ };
754
758
  draft.transactionCategorizationView[selectedTab].error = undefined;
755
759
  draft.transactionCategorizationView[selectedTab].fullDatasetSnapshot =
756
760
  undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.1.18-betaRD2",
3
+ "version": "5.1.18-betaRD3",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/esm/index.js",