@zeniai/client-epic-state 5.2.78 → 5.2.79

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.
Files changed (76) hide show
  1. package/lib/esm/view/invoicing/couponView/couponViewReducer.js +14 -25
  2. package/lib/esm/view/invoicing/couponView/couponViewSelector.js +21 -22
  3. package/lib/esm/view/invoicing/couponView/couponViewState.js +2 -0
  4. package/lib/esm/view/invoicing/couponView/fetchInvoicingCouponListEpic.js +26 -8
  5. package/lib/esm/view/invoicing/couponView/fetchInvoicingCouponListPageEpic.js +16 -2
  6. package/lib/esm/view/invoicing/createInvoice/createInvoiceSelector.js +23 -15
  7. package/lib/esm/view/invoicing/createInvoice/epics/fetchCreateInvoiceFormPageEpic.js +5 -2
  8. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +2 -2
  9. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/fetchInvoicingSubscriptionDetailPageEpic.js +9 -6
  10. package/lib/esm/view/invoicing/invoicingCreditNoteListView/epics/fetchInvoicingCreditNoteListEpic.js +25 -8
  11. package/lib/esm/view/invoicing/invoicingCreditNoteListView/epics/fetchInvoicingCreditNoteListPageEpic.js +15 -2
  12. package/lib/esm/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewReducer.js +12 -23
  13. package/lib/esm/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewSelector.js +6 -9
  14. package/lib/esm/view/invoicing/invoicingCustomerListView/epics/fetchInvoicingCustomerListEpic.js +26 -8
  15. package/lib/esm/view/invoicing/invoicingCustomerListView/epics/fetchInvoicingCustomerListPageEpic.js +16 -2
  16. package/lib/esm/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewReducer.js +14 -25
  17. package/lib/esm/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewSelector.js +16 -13
  18. package/lib/esm/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewState.js +2 -0
  19. package/lib/esm/view/invoicing/invoicingDunningCaseListView/epics/fetchInvoicingDunningCaseListEpic.js +25 -8
  20. package/lib/esm/view/invoicing/invoicingDunningCaseListView/epics/fetchInvoicingDunningCaseListPageEpic.js +15 -2
  21. package/lib/esm/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewReducer.js +12 -23
  22. package/lib/esm/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewSelector.js +6 -9
  23. package/lib/esm/view/invoicing/invoicingListTabCache.js +98 -0
  24. package/lib/esm/view/invoicing/invoicingOverview/epics/fetchInvoicingOverviewEpic.js +4 -7
  25. package/lib/esm/view/invoicing/invoicingOverview/invoicingOverviewSelector.js +8 -5
  26. package/lib/esm/view/invoicing/invoicingSubscriptionListView/epics/fetchInvoicingSubscriptionListEpic.js +28 -9
  27. package/lib/esm/view/invoicing/invoicingSubscriptionListView/epics/fetchInvoicingSubscriptionListPageEpic.js +15 -2
  28. package/lib/esm/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewReducer.js +13 -25
  29. package/lib/esm/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewSelector.js +6 -9
  30. package/lib/view/invoicing/couponView/couponViewReducer.d.ts +8 -1
  31. package/lib/view/invoicing/couponView/couponViewReducer.js +14 -25
  32. package/lib/view/invoicing/couponView/couponViewSelector.js +20 -21
  33. package/lib/view/invoicing/couponView/couponViewState.d.ts +7 -4
  34. package/lib/view/invoicing/couponView/couponViewState.js +3 -1
  35. package/lib/view/invoicing/couponView/fetchInvoicingCouponListEpic.d.ts +1 -1
  36. package/lib/view/invoicing/couponView/fetchInvoicingCouponListEpic.js +25 -7
  37. package/lib/view/invoicing/couponView/fetchInvoicingCouponListPageEpic.js +16 -2
  38. package/lib/view/invoicing/createInvoice/createInvoiceSelector.js +22 -14
  39. package/lib/view/invoicing/createInvoice/epics/fetchCreateInvoiceFormPageEpic.js +5 -2
  40. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +1 -1
  41. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/fetchInvoicingSubscriptionDetailPageEpic.js +9 -6
  42. package/lib/view/invoicing/invoicingCreditNoteListView/epics/fetchInvoicingCreditNoteListEpic.d.ts +1 -1
  43. package/lib/view/invoicing/invoicingCreditNoteListView/epics/fetchInvoicingCreditNoteListEpic.js +24 -7
  44. package/lib/view/invoicing/invoicingCreditNoteListView/epics/fetchInvoicingCreditNoteListPageEpic.js +15 -2
  45. package/lib/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewReducer.d.ts +8 -1
  46. package/lib/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewReducer.js +12 -23
  47. package/lib/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewSelector.js +6 -9
  48. package/lib/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewState.d.ts +5 -4
  49. package/lib/view/invoicing/invoicingCustomerListView/epics/fetchInvoicingCustomerListEpic.d.ts +1 -1
  50. package/lib/view/invoicing/invoicingCustomerListView/epics/fetchInvoicingCustomerListEpic.js +25 -7
  51. package/lib/view/invoicing/invoicingCustomerListView/epics/fetchInvoicingCustomerListPageEpic.js +16 -2
  52. package/lib/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewReducer.d.ts +8 -1
  53. package/lib/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewReducer.js +14 -25
  54. package/lib/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewSelector.d.ts +5 -0
  55. package/lib/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewSelector.js +17 -13
  56. package/lib/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewState.d.ts +7 -4
  57. package/lib/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewState.js +3 -1
  58. package/lib/view/invoicing/invoicingDunningCaseListView/epics/fetchInvoicingDunningCaseListEpic.d.ts +1 -1
  59. package/lib/view/invoicing/invoicingDunningCaseListView/epics/fetchInvoicingDunningCaseListEpic.js +24 -7
  60. package/lib/view/invoicing/invoicingDunningCaseListView/epics/fetchInvoicingDunningCaseListPageEpic.js +15 -2
  61. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewReducer.d.ts +8 -1
  62. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewReducer.js +12 -23
  63. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewSelector.js +6 -9
  64. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewState.d.ts +5 -4
  65. package/lib/view/invoicing/invoicingListTabCache.d.ts +71 -0
  66. package/lib/view/invoicing/invoicingListTabCache.js +111 -0
  67. package/lib/view/invoicing/invoicingOverview/epics/fetchInvoicingOverviewEpic.js +4 -7
  68. package/lib/view/invoicing/invoicingOverview/invoicingOverviewSelector.js +8 -5
  69. package/lib/view/invoicing/invoicingSubscriptionListView/epics/fetchInvoicingSubscriptionListEpic.d.ts +1 -1
  70. package/lib/view/invoicing/invoicingSubscriptionListView/epics/fetchInvoicingSubscriptionListEpic.js +27 -8
  71. package/lib/view/invoicing/invoicingSubscriptionListView/epics/fetchInvoicingSubscriptionListPageEpic.js +15 -2
  72. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewReducer.d.ts +8 -1
  73. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewReducer.js +13 -25
  74. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewSelector.js +6 -9
  75. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewState.d.ts +5 -5
  76. package/package.json +1 -1
@@ -1,13 +1,17 @@
1
1
  import { of } from 'rxjs';
2
- import { catchError, filter, switchMap } from 'rxjs/operators';
2
+ import { catchError, filter, groupBy, map, mergeMap, switchMap, } from 'rxjs/operators';
3
3
  import { updateAddresses } from '../../../../entity/address/addressReducer';
4
4
  import { extractInvoicingSubscriptionAddresses } from '../../../../entity/invoicing/invoicingSubscription/invoicingSubscriptionPayload';
5
5
  import { updateInvoicingSubscriptions } from '../../../../entity/invoicing/invoicingSubscription/invoicingSubscriptionReducer';
6
6
  import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
7
7
  import { INVOICING_LIST_PAGE_SIZE, applyListSortParams, withQuery, } from '../../invoicingApiHelper';
8
+ import { invoicingListFetchTab, invoicingListStatusParam, } from '../../invoicingListTabCache';
8
9
  import { fetchInvoicingSubscriptionList, updateInvoicingSubscriptionList, updateInvoicingSubscriptionListFailure, } from '../invoicingSubscriptionListViewReducer';
9
- const buildQuery = (filters, cursor, sort) => {
10
+ const buildQuery = (filters, cursor, sort, status) => {
10
11
  const params = new URLSearchParams();
12
+ if (status != null) {
13
+ params.set('status', status);
14
+ }
11
15
  if (filters.customerId != null) {
12
16
  params.set('customer_id', filters.customerId);
13
17
  }
@@ -27,10 +31,18 @@ const buildQuery = (filters, cursor, sort) => {
27
31
  applyListSortParams(params, sort);
28
32
  return params;
29
33
  };
30
- export const fetchInvoicingSubscriptionListEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchInvoicingSubscriptionList.match), switchMap((action) => {
34
+ export const fetchInvoicingSubscriptionListEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchInvoicingSubscriptionList.match), map((action) => ({
35
+ action,
36
+ tabId: invoicingListFetchTab(state$.value.invoicingSubscriptionListViewState.activeTab, action.payload.tabId),
37
+ })),
38
+ // Per tab: a newer fetch of the same tab replaces its in-flight one, while
39
+ // another tab's request keeps running and lands in its own cache.
40
+ groupBy(({ tabId }) => tabId), mergeMap((tabFetches$) => tabFetches$.pipe(switchMap(({ action, tabId }) => {
31
41
  const { filters, cursor, keepExistingListItems, sort } = action.payload;
32
- const apiUrl = withQuery(`${zeniAPI.apiEndPoints.invoicingMicroServiceBaseUrl}/1.0/subscriptions`, buildQuery(filters, cursor, sort));
33
- return zeniAPI.getJSON(apiUrl).pipe(switchMap((response) => {
42
+ const apiUrl = withQuery(`${zeniAPI.apiEndPoints.invoicingMicroServiceBaseUrl}/1.0/subscriptions`, buildQuery(filters, cursor, sort, invoicingListStatusParam(tabId)));
43
+ return zeniAPI
44
+ .getJSON(apiUrl)
45
+ .pipe(switchMap((response) => {
34
46
  if (isSuccessResponse(response)) {
35
47
  const items = response.data?.items ?? [];
36
48
  return [
@@ -40,10 +52,17 @@ export const fetchInvoicingSubscriptionListEpic = (actions$, _state$, zeniAPI) =
40
52
  ids: items.map((item) => item.id),
41
53
  nextCursor: response.data?.next_cursor ?? null,
42
54
  keepExistingListItems,
55
+ tabId,
43
56
  }),
44
57
  ];
45
58
  }
46
- return of(updateInvoicingSubscriptionListFailure(response.status));
47
- }), catchError((error) => of(updateInvoicingSubscriptionListFailure(createZeniAPIStatus('Unexpected Error', 'Fetch subscription list REST API call errored out ' +
48
- JSON.stringify(error))))));
49
- }));
59
+ return of(updateInvoicingSubscriptionListFailure({
60
+ status: response.status,
61
+ tabId,
62
+ }));
63
+ }), catchError((error) => of(updateInvoicingSubscriptionListFailure({
64
+ status: createZeniAPIStatus('Unexpected Error', 'Fetch subscription list REST API call errored out ' +
65
+ JSON.stringify(error)),
66
+ tabId,
67
+ }))));
68
+ }))));
@@ -1,5 +1,6 @@
1
1
  import { concat, from } from 'rxjs';
2
2
  import { filter, mergeMap } from 'rxjs/operators';
3
+ import { getInvoicingListTab, invoicingListSourceTab, planInvoicingListTabFetch, } from '../../invoicingListTabCache';
3
4
  import { fetchInvoicingSubscriptionCounts, fetchInvoicingSubscriptionList, fetchInvoicingSubscriptionListPage, } from '../invoicingSubscriptionListViewReducer';
4
5
  /**
5
6
  * Fetch unless the endpoint is already loaded or in flight — or always when the
@@ -17,8 +18,20 @@ export const fetchInvoicingSubscriptionListPageEpic = (actions$, state$) => acti
17
18
  const { cacheOverride, filters, sort } = action.payload;
18
19
  const state = state$.value.invoicingSubscriptionListViewState;
19
20
  const pageActions = [];
20
- if (shouldFetch({ fetchState: state.fetchState, error: state.error }, cacheOverride)) {
21
- pageActions.push(fetchInvoicingSubscriptionList({ filters, sort }));
21
+ const tabId = invoicingListSourceTab(state.activeTab);
22
+ const tabFetch = planInvoicingListTabFetch(getInvoicingListTab(state.byTab, tabId), cacheOverride);
23
+ if (tabFetch.kind === 'firstPage') {
24
+ pageActions.push(fetchInvoicingSubscriptionList({ filters, sort, tabId }));
25
+ }
26
+ else if (tabFetch.kind === 'nextPage') {
27
+ // Less than a page cached and the server has more: top it up.
28
+ pageActions.push(fetchInvoicingSubscriptionList({
29
+ cursor: tabFetch.cursor,
30
+ filters,
31
+ keepExistingListItems: true,
32
+ sort,
33
+ tabId,
34
+ }));
22
35
  }
23
36
  if (shouldFetch(state.countsFetchState, cacheOverride)) {
24
37
  pageActions.push(fetchInvoicingSubscriptionCounts());
@@ -1,17 +1,12 @@
1
1
  import { createSlice } from '@reduxjs/toolkit';
2
2
  import { clearAll } from '../../../rootActions';
3
+ import { addToInvoicingListTabs, completeInvoicingListTabFetch, failInvoicingListTabFetch, invoicingListFetchTab, isSameInvoicingListQuery, startInvoicingListTabFetch, } from '../invoicingListTabCache';
3
4
  export const initialState = {
4
- fetchState: 'Not-Started',
5
- error: undefined,
6
5
  activeTab: 'all',
7
- ids: [],
8
- nextCursor: null,
6
+ byTab: {},
9
7
  filters: {},
10
8
  counts: { all: 0 },
11
9
  countsFetchState: { fetchState: 'Not-Started', error: undefined },
12
- hasValidState() {
13
- return this.fetchState === 'Completed';
14
- },
15
10
  };
16
11
  const invoicingSubscriptionListView = createSlice({
17
12
  name: 'invoicingSubscriptionListView',
@@ -19,14 +14,9 @@ const invoicingSubscriptionListView = createSlice({
19
14
  reducers: {
20
15
  fetchInvoicingSubscriptionList: {
21
16
  reducer(draft, action) {
22
- if (!action.payload.keepExistingListItems) {
23
- draft.ids = [];
24
- draft.nextCursor = null;
25
- }
17
+ startInvoicingListTabFetch(draft.byTab, invoicingListFetchTab(draft.activeTab, action.payload.tabId), action.payload.keepExistingListItems);
26
18
  draft.filters = action.payload.filters;
27
19
  draft.sort = action.payload.sort;
28
- draft.fetchState = 'In-Progress';
29
- draft.error = undefined;
30
20
  },
31
21
  prepare(payload) {
32
22
  return {
@@ -35,12 +25,17 @@ const invoicingSubscriptionListView = createSlice({
35
25
  cursor: payload.cursor,
36
26
  keepExistingListItems: payload.keepExistingListItems ?? false,
37
27
  sort: payload.sort,
28
+ tabId: payload.tabId,
38
29
  },
39
30
  };
40
31
  },
41
32
  },
42
33
  fetchInvoicingSubscriptionListPage: {
43
34
  reducer(draft, action) {
35
+ // Another search or sort makes every cached tab stale.
36
+ if (!isSameInvoicingListQuery(draft, action.payload)) {
37
+ draft.byTab = {};
38
+ }
44
39
  draft.filters = action.payload.filters;
45
40
  draft.sort = action.payload.sort;
46
41
  },
@@ -55,16 +50,10 @@ const invoicingSubscriptionListView = createSlice({
55
50
  },
56
51
  },
57
52
  updateInvoicingSubscriptionList(draft, action) {
58
- draft.ids = action.payload.keepExistingListItems
59
- ? [...new Set([...draft.ids, ...action.payload.ids])]
60
- : action.payload.ids;
61
- draft.nextCursor = action.payload.nextCursor;
62
- draft.fetchState = 'Completed';
63
- draft.error = undefined;
53
+ completeInvoicingListTabFetch(draft.byTab, action.payload.tabId, action.payload);
64
54
  },
65
55
  updateInvoicingSubscriptionListFailure(draft, action) {
66
- draft.fetchState = 'Error';
67
- draft.error = action.payload;
56
+ failInvoicingListTabFetch(draft.byTab, action.payload.tabId, action.payload.status);
68
57
  },
69
58
  fetchInvoicingSubscriptionCounts(draft) {
70
59
  draft.countsFetchState.fetchState = 'In-Progress';
@@ -82,8 +71,8 @@ const invoicingSubscriptionListView = createSlice({
82
71
  updateInvoicingSubscriptionFilters(draft, action) {
83
72
  draft.filters = action.payload;
84
73
  },
85
- // Select a status tab. The list API ignores `status` (returns all statuses),
86
- // so the selector filters rows to this tab client-side — no refetch needed.
74
+ // Select a status tab. The view dispatches the page fetch after, which loads
75
+ // the tab from the server only when its cache is empty or failed.
87
76
  setInvoicingSubscriptionActiveTab(draft, action) {
88
77
  draft.activeTab = action.payload;
89
78
  },
@@ -92,10 +81,9 @@ const invoicingSubscriptionListView = createSlice({
92
81
  // doubles as the per-tab count key (tab ids mirror InvoicingSubscriptionStatus).
93
82
  addInvoicingSubscriptionToList(draft, action) {
94
83
  const { id, status } = action.payload;
95
- if (draft.ids.includes(id)) {
84
+ if (!addToInvoicingListTabs(draft.byTab, id, status)) {
96
85
  return;
97
86
  }
98
- draft.ids = [id, ...draft.ids];
99
87
  draft.counts.all += 1;
100
88
  if (status != null) {
101
89
  draft.counts[status] = (draft.counts[status] ?? 0) + 1;
@@ -1,5 +1,6 @@
1
1
  import { createSelector } from '@reduxjs/toolkit';
2
2
  import { getInvoicingSubscriptionsByIds } from '../../../entity/invoicing/invoicingSubscription/invoicingSubscriptionSelector';
3
+ import { getInvoicingListTab, invoicingListSourceTab, } from '../invoicingListTabCache';
3
4
  import { invoicingTabIdsFromConfig } from '../invoicingTabHelper';
4
5
  import { runningInvoicingActionId } from '../runningInvoicingActionId';
5
6
  import { ALL_INVOICING_SUBSCRIPTION_TAB_IDS, INVOICING_SUBSCRIPTION_COLUMNS, } from './invoicingSubscriptionListViewState';
@@ -12,20 +13,16 @@ import { ALL_INVOICING_SUBSCRIPTION_TAB_IDS, INVOICING_SUBSCRIPTION_COLUMNS, } f
12
13
  */
13
14
  export const getInvoicingSubscriptionListView = createSelector((state) => state.invoicingSubscriptionState, (state) => state.invoicingSubscriptionListViewState, (state) => state.invoicingConfigViewState.subscriptionStatusOptions, (state) => state.invoicingConfigViewState, (state) => state.editInvoicingSubscriptionDetailViewState.actionStateById, (subscriptionState, listViewState, statusOptions, configState, actionStateById) => {
14
15
  const { activeTab } = listViewState;
15
- const allSubscriptions = getInvoicingSubscriptionsByIds(subscriptionState, listViewState.ids);
16
- // The list API ignores `status`, so it returns every status; filter to the
17
- // active tab client-side ('all' shows everything).
18
- const subscriptions = activeTab === 'all'
19
- ? allSubscriptions
20
- : allSubscriptions.filter((subscription) => subscription.status === activeTab);
16
+ const tab = getInvoicingListTab(listViewState.byTab, invoicingListSourceTab(activeTab));
17
+ const subscriptions = getInvoicingSubscriptionsByIds(subscriptionState, tab.ids);
21
18
  return {
22
19
  runningActionId: runningInvoicingActionId(actionStateById),
23
20
  activeTab,
24
21
  columns: INVOICING_SUBSCRIPTION_COLUMNS,
25
22
  subscriptions,
26
- fetchState: listViewState.fetchState,
27
- error: listViewState.error,
28
- nextCursor: listViewState.nextCursor,
23
+ fetchState: tab.fetchState,
24
+ error: tab.error,
25
+ nextCursor: tab.nextCursor,
29
26
  filters: listViewState.filters,
30
27
  count: listViewState.counts,
31
28
  countsFetchState: listViewState.countsFetchState,
@@ -10,11 +10,14 @@ export declare const fetchInvoicingCouponList: import("@reduxjs/toolkit").Action
10
10
  filters?: InvoicingCouponFilters;
11
11
  keepExistingListItems?: boolean;
12
12
  sort?: InvoicingListSort;
13
+ /** The tab cache to fill; defaults to the active tab's. */
14
+ tabId?: string;
13
15
  }], {
14
16
  filters: InvoicingCouponFilters;
15
17
  cursor: string | undefined;
16
18
  keepExistingListItems: boolean;
17
19
  sort: InvoicingListSort | undefined;
20
+ tabId: string | undefined;
18
21
  }, "invoicingCouponView/fetchInvoicingCouponList", never, never>, fetchInvoicingCouponListPage: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: {
19
22
  cacheOverride?: boolean;
20
23
  filters?: InvoicingCouponFilters;
@@ -27,7 +30,11 @@ export declare const fetchInvoicingCouponList: import("@reduxjs/toolkit").Action
27
30
  ids: ID[];
28
31
  keepExistingListItems: boolean;
29
32
  nextCursor: string | null;
30
- }, "invoicingCouponView/updateInvoicingCouponList">, updateInvoicingCouponListFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "invoicingCouponView/updateInvoicingCouponListFailure">, fetchInvoicingCouponCounts: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"invoicingCouponView/fetchInvoicingCouponCounts">, updateInvoicingCouponCounts: import("@reduxjs/toolkit").ActionCreatorWithPayload<InvoicingListCounts, "invoicingCouponView/updateInvoicingCouponCounts">, updateInvoicingCouponCountsFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "invoicingCouponView/updateInvoicingCouponCountsFailure">, updateInvoicingCouponFilters: import("@reduxjs/toolkit").ActionCreatorWithPayload<InvoicingCouponFilters, "invoicingCouponView/updateInvoicingCouponFilters">, setInvoicingCouponActiveTab: import("@reduxjs/toolkit").ActionCreatorWithPayload<"active" | "inactive" | "all", "invoicingCouponView/setInvoicingCouponActiveTab">, addInvoicingCouponToList: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
33
+ tabId: string;
34
+ }, "invoicingCouponView/updateInvoicingCouponList">, updateInvoicingCouponListFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
35
+ status: ZeniAPIStatus;
36
+ tabId: string;
37
+ }, "invoicingCouponView/updateInvoicingCouponListFailure">, fetchInvoicingCouponCounts: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"invoicingCouponView/fetchInvoicingCouponCounts">, updateInvoicingCouponCounts: import("@reduxjs/toolkit").ActionCreatorWithPayload<InvoicingListCounts, "invoicingCouponView/updateInvoicingCouponCounts">, updateInvoicingCouponCountsFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "invoicingCouponView/updateInvoicingCouponCountsFailure">, updateInvoicingCouponFilters: import("@reduxjs/toolkit").ActionCreatorWithPayload<InvoicingCouponFilters, "invoicingCouponView/updateInvoicingCouponFilters">, setInvoicingCouponActiveTab: import("@reduxjs/toolkit").ActionCreatorWithPayload<"active" | "inactive" | "all", "invoicingCouponView/setInvoicingCouponActiveTab">, addInvoicingCouponToList: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
31
38
  id: ID;
32
39
  status?: InvoicingCouponStatus;
33
40
  }, "invoicingCouponView/addInvoicingCouponToList">;
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.addInvoicingCouponToList = exports.setInvoicingCouponActiveTab = exports.updateInvoicingCouponFilters = exports.updateInvoicingCouponCountsFailure = exports.updateInvoicingCouponCounts = exports.fetchInvoicingCouponCounts = exports.updateInvoicingCouponListFailure = exports.updateInvoicingCouponList = exports.fetchInvoicingCouponListPage = exports.fetchInvoicingCouponList = exports.initialState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  const rootActions_1 = require("../../../rootActions");
7
+ const invoicingListTabCache_1 = require("../invoicingListTabCache");
8
+ const couponViewState_1 = require("./couponViewState");
7
9
  // The discounts-list tabs look up counts by tab id ('active' / 'inactive'),
8
10
  // while a coupon's status is 'active' | 'expired' | 'archived'. Collapse the
9
11
  // non-active statuses onto the 'inactive' tab; a newly created coupon with no
@@ -12,17 +14,11 @@ function couponStatusToTabCountKey(status) {
12
14
  return status == null || status === 'active' ? 'active' : 'inactive';
13
15
  }
14
16
  exports.initialState = {
15
- fetchState: 'Not-Started',
16
- error: undefined,
17
17
  activeTab: 'all',
18
- ids: [],
19
- nextCursor: null,
18
+ byTab: {},
20
19
  filters: {},
21
20
  counts: { all: 0 },
22
21
  countsFetchState: { fetchState: 'Not-Started', error: undefined },
23
- hasValidState() {
24
- return this.fetchState === 'Completed';
25
- },
26
22
  };
27
23
  const couponView = (0, toolkit_1.createSlice)({
28
24
  name: 'invoicingCouponView',
@@ -30,14 +26,9 @@ const couponView = (0, toolkit_1.createSlice)({
30
26
  reducers: {
31
27
  fetchInvoicingCouponList: {
32
28
  reducer(draft, action) {
33
- if (!action.payload.keepExistingListItems) {
34
- draft.ids = [];
35
- draft.nextCursor = null;
36
- }
29
+ (0, invoicingListTabCache_1.startInvoicingListTabFetch)(draft.byTab, (0, invoicingListTabCache_1.invoicingListFetchTab)(draft.activeTab, action.payload.tabId, couponViewState_1.INVOICING_COUPON_CLIENT_FILTERED_TAB_IDS), action.payload.keepExistingListItems);
37
30
  draft.filters = action.payload.filters;
38
31
  draft.sort = action.payload.sort;
39
- draft.fetchState = 'In-Progress';
40
- draft.error = undefined;
41
32
  },
42
33
  prepare(payload) {
43
34
  return {
@@ -46,12 +37,17 @@ const couponView = (0, toolkit_1.createSlice)({
46
37
  cursor: payload.cursor,
47
38
  keepExistingListItems: payload.keepExistingListItems ?? false,
48
39
  sort: payload.sort,
40
+ tabId: payload.tabId,
49
41
  },
50
42
  };
51
43
  },
52
44
  },
53
45
  fetchInvoicingCouponListPage: {
54
46
  reducer(draft, action) {
47
+ // Another search or sort makes every cached tab stale.
48
+ if (!(0, invoicingListTabCache_1.isSameInvoicingListQuery)(draft, action.payload)) {
49
+ draft.byTab = {};
50
+ }
55
51
  draft.filters = action.payload.filters;
56
52
  draft.sort = action.payload.sort;
57
53
  },
@@ -66,16 +62,10 @@ const couponView = (0, toolkit_1.createSlice)({
66
62
  },
67
63
  },
68
64
  updateInvoicingCouponList(draft, action) {
69
- draft.ids = action.payload.keepExistingListItems
70
- ? [...new Set([...draft.ids, ...action.payload.ids])]
71
- : action.payload.ids;
72
- draft.nextCursor = action.payload.nextCursor;
73
- draft.fetchState = 'Completed';
74
- draft.error = undefined;
65
+ (0, invoicingListTabCache_1.completeInvoicingListTabFetch)(draft.byTab, action.payload.tabId, action.payload);
75
66
  },
76
67
  updateInvoicingCouponListFailure(draft, action) {
77
- draft.fetchState = 'Error';
78
- draft.error = action.payload;
68
+ (0, invoicingListTabCache_1.failInvoicingListTabFetch)(draft.byTab, action.payload.tabId, action.payload.status);
79
69
  },
80
70
  fetchInvoicingCouponCounts(draft) {
81
71
  draft.countsFetchState.fetchState = 'In-Progress';
@@ -93,8 +83,8 @@ const couponView = (0, toolkit_1.createSlice)({
93
83
  updateInvoicingCouponFilters(draft, action) {
94
84
  draft.filters = action.payload;
95
85
  },
96
- // Select a status tab. The list API ignores `status` (returns all statuses),
97
- // so the selector filters rows to this tab client-side — no refetch needed.
86
+ // Select a status tab. The view dispatches the page fetch after, which loads
87
+ // the tab from the server only when its cache is empty or failed.
98
88
  setInvoicingCouponActiveTab(draft, action) {
99
89
  draft.activeTab = action.payload;
100
90
  },
@@ -103,10 +93,9 @@ const couponView = (0, toolkit_1.createSlice)({
103
93
  // the same id/counts, so only creates dispatch this.
104
94
  addInvoicingCouponToList(draft, action) {
105
95
  const { id, status } = action.payload;
106
- if (draft.ids.includes(id)) {
96
+ if (!(0, invoicingListTabCache_1.addToInvoicingListTabs)(draft.byTab, id, couponStatusToTabCountKey(status))) {
107
97
  return;
108
98
  }
109
- draft.ids = [id, ...draft.ids];
110
99
  draft.counts.all += 1;
111
100
  const tabCountKey = couponStatusToTabCountKey(status);
112
101
  draft.counts[tabCountKey] = (draft.counts[tabCountKey] ?? 0) + 1;
@@ -2,21 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getInvoicingCouponListView = exports.getInvoicingCouponCounts = exports.getInvoicingCouponListFilters = exports.getInvoicingCouponListHasMore = exports.getInvoicingCouponListNextCursor = exports.getInvoicingCouponListFetchState = exports.getInvoicingCouponListItems = void 0;
4
4
  const toolkit_1 = require("@reduxjs/toolkit");
5
+ const invoicingListTabCache_1 = require("../invoicingListTabCache");
5
6
  const invoicingTabHelper_1 = require("../invoicingTabHelper");
6
7
  const runningInvoicingActionId_1 = require("../runningInvoicingActionId");
7
8
  const couponViewState_1 = require("./couponViewState");
8
- const getInvoicingCouponListItems = (state) => state.invoicingCouponViewState.ids
9
- .map((id) => state.invoicingCouponState.couponByID[id])
9
+ // These read the unfiltered `all` cache, so a picker never narrows to
10
+ // whichever tab the discounts list was left on.
11
+ const allCouponsTab = (state) => (0, invoicingListTabCache_1.getInvoicingListTab)(state.invoicingCouponViewState.byTab, invoicingListTabCache_1.INVOICING_LIST_ALL_TAB);
12
+ const getInvoicingCouponListItems = (state) => allCouponsTab(state)
13
+ .ids.map((id) => state.invoicingCouponState.couponByID[id])
10
14
  .filter((item) => item != null);
11
15
  exports.getInvoicingCouponListItems = getInvoicingCouponListItems;
12
16
  const getInvoicingCouponListFetchState = (state) => ({
13
- fetchState: state.invoicingCouponViewState.fetchState,
14
- error: state.invoicingCouponViewState.error,
17
+ fetchState: allCouponsTab(state).fetchState,
18
+ error: allCouponsTab(state).error,
15
19
  });
16
20
  exports.getInvoicingCouponListFetchState = getInvoicingCouponListFetchState;
17
- const getInvoicingCouponListNextCursor = (state) => state.invoicingCouponViewState.nextCursor;
21
+ const getInvoicingCouponListNextCursor = (state) => allCouponsTab(state).nextCursor;
18
22
  exports.getInvoicingCouponListNextCursor = getInvoicingCouponListNextCursor;
19
- const getInvoicingCouponListHasMore = (state) => state.invoicingCouponViewState.nextCursor != null;
23
+ const getInvoicingCouponListHasMore = (state) => allCouponsTab(state).nextCursor != null;
20
24
  exports.getInvoicingCouponListHasMore = getInvoicingCouponListHasMore;
21
25
  const getInvoicingCouponListFilters = (state) => state.invoicingCouponViewState.filters;
22
26
  exports.getInvoicingCouponListFilters = getInvoicingCouponListFilters;
@@ -30,20 +34,15 @@ exports.getInvoicingCouponCounts = getInvoicingCouponCounts;
30
34
  */
31
35
  exports.getInvoicingCouponListView = (0, toolkit_1.createSelector)((state) => state.invoicingCouponState, (state) => state.invoicingCouponViewState, (state) => state.invoicingConfigViewState.discountStatusOptions, (state) => state.invoicingConfigViewState.discountLifecycleActionOptions, (state) => state.editInvoicingCouponDetailViewState.actionStateById, (couponState, listViewState, statusOptions, discountLifecycleActionOptions, actionStateById) => {
32
36
  const { activeTab } = listViewState;
33
- const allCoupons = listViewState.ids
37
+ const tab = (0, invoicingListTabCache_1.getInvoicingListTab)(listViewState.byTab, (0, invoicingListTabCache_1.invoicingListSourceTab)(activeTab, couponViewState_1.INVOICING_COUPON_CLIENT_FILTERED_TAB_IDS));
38
+ const tabRows = tab.ids
34
39
  .map((id) => couponState.couponByID[id])
35
40
  .filter((item) => item != null);
36
- // The list API ignores `status`, so it returns every status; filter to the
37
- // active tab client-side. 'all' shows everything and 'inactive' is the
38
- // FE-derived composite of every non-active status (undefined included);
39
- // every other tab is a real backend status and matches exactly — without
40
- // that, config-supplied tabs like `expired` and `archived` would each show
41
- // the whole non-active set.
42
- const coupons = activeTab === 'all'
43
- ? allCoupons
44
- : activeTab === 'inactive'
45
- ? allCoupons.filter((coupon) => coupon.status !== 'active')
46
- : allCoupons.filter((coupon) => coupon.status === activeTab);
41
+ // `inactive` groups every non-active status, which the list API cannot
42
+ // filter on, so it is the `all` rows filtered here.
43
+ const coupons = activeTab === 'inactive'
44
+ ? tabRows.filter((coupon) => coupon.status !== 'active')
45
+ : tabRows;
47
46
  return {
48
47
  activeTab,
49
48
  columns: couponViewState_1.INVOICING_COUPON_COLUMNS,
@@ -51,7 +50,7 @@ exports.getInvoicingCouponListView = (0, toolkit_1.createSelector)((state) => st
51
50
  count: listViewState.counts,
52
51
  countsFetchState: listViewState.countsFetchState,
53
52
  filters: listViewState.filters,
54
- nextCursor: listViewState.nextCursor,
53
+ nextCursor: tab.nextCursor,
55
54
  discountLifecycleActionOptions,
56
55
  statusOptions,
57
56
  tabIds: (0, invoicingTabHelper_1.invoicingTabIdsFromConfig)({
@@ -60,8 +59,8 @@ exports.getInvoicingCouponListView = (0, toolkit_1.createSelector)((state) => st
60
59
  statusOptions,
61
60
  }),
62
61
  runningActionId: (0, runningInvoicingActionId_1.runningInvoicingActionId)(actionStateById),
63
- fetchState: listViewState.fetchState,
64
- error: listViewState.error,
62
+ fetchState: tab.fetchState,
63
+ error: tab.error,
65
64
  sort: listViewState.sort,
66
65
  version: 1.0,
67
66
  };
@@ -1,6 +1,7 @@
1
- import { FetchStateAndError, FetchedState, ID } from '../../../commonStateTypes/common';
1
+ import { FetchStateAndError } from '../../../commonStateTypes/common';
2
2
  import { InvoicingListCounts } from '../../../entity/invoicing/invoicingCommonPayload';
3
3
  import { InvoicingListSort } from '../invoicingApiHelper';
4
+ import { InvoicingListByTab } from '../invoicingListTabCache';
4
5
  export interface InvoicingCouponFilters {
5
6
  search?: string;
6
7
  }
@@ -22,13 +23,15 @@ export declare const INVOICING_COUPON_COLUMNS: InvoicingCouponColumnConfig[];
22
23
  export declare const ALL_INVOICING_COUPON_TAB_IDS: readonly ["all", "active", "inactive"];
23
24
  export declare const toInvoicingCouponTabId: (v: string) => "active" | "inactive" | "all";
24
25
  export type InvoicingCouponTabId = ReturnType<typeof toInvoicingCouponTabId>;
25
- export interface InvoicingCouponViewState extends FetchedState {
26
+ export interface InvoicingCouponViewState {
26
27
  /** Selected status tab (CES-owned so it persists across page revisits). */
27
28
  activeTab: InvoicingCouponTabId;
29
+ /** Per-tab rows, cursor and fetch state; each tab is its own `?status=` query. */
30
+ byTab: InvoicingListByTab;
28
31
  counts: InvoicingListCounts;
29
32
  countsFetchState: FetchStateAndError;
30
33
  filters: InvoicingCouponFilters;
31
- ids: ID[];
32
- nextCursor: string | null;
33
34
  sort?: InvoicingListSort;
34
35
  }
36
+ /** Tabs the list API cannot filter on: they read the `all` rows, filtered here. */
37
+ export declare const INVOICING_COUPON_CLIENT_FILTERED_TAB_IDS: readonly InvoicingCouponTabId[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toInvoicingCouponTabId = exports.ALL_INVOICING_COUPON_TAB_IDS = exports.INVOICING_COUPON_COLUMNS = exports.toInvoicingCouponSortKey = exports.ALL_INVOICING_COUPON_SORT_KEYS = void 0;
3
+ exports.INVOICING_COUPON_CLIENT_FILTERED_TAB_IDS = exports.toInvoicingCouponTabId = exports.ALL_INVOICING_COUPON_TAB_IDS = exports.INVOICING_COUPON_COLUMNS = exports.toInvoicingCouponSortKey = exports.ALL_INVOICING_COUPON_SORT_KEYS = void 0;
4
4
  const stringToUnion_1 = require("../../../commonStateTypes/stringToUnion");
5
5
  exports.ALL_INVOICING_COUPON_SORT_KEYS = [
6
6
  'code',
@@ -33,3 +33,5 @@ exports.ALL_INVOICING_COUPON_TAB_IDS = [
33
33
  ];
34
34
  const toInvoicingCouponTabId = (v) => (0, stringToUnion_1.stringToUnion)(v, exports.ALL_INVOICING_COUPON_TAB_IDS);
35
35
  exports.toInvoicingCouponTabId = toInvoicingCouponTabId;
36
+ /** Tabs the list API cannot filter on: they read the `all` rows, filtered here. */
37
+ exports.INVOICING_COUPON_CLIENT_FILTERED_TAB_IDS = ['inactive'];
@@ -5,4 +5,4 @@ import { RootState } from '../../../rootStateTypes';
5
5
  import { ZeniAPI } from '../../../zeniAPI';
6
6
  import { fetchInvoicingCouponCounts, fetchInvoicingCouponList, fetchInvoicingCouponListPage, updateInvoicingCouponCounts, updateInvoicingCouponCountsFailure, updateInvoicingCouponList, updateInvoicingCouponListFailure } from './couponViewReducer';
7
7
  export type ActionType = ReturnType<typeof fetchInvoicingCouponList> | ReturnType<typeof fetchInvoicingCouponListPage> | ReturnType<typeof fetchInvoicingCouponCounts> | ReturnType<typeof updateInvoicingCouponList> | ReturnType<typeof updateInvoicingCouponListFailure> | ReturnType<typeof updateInvoicingCouponCounts> | ReturnType<typeof updateInvoicingCouponCountsFailure> | ReturnType<typeof updateInvoicingCoupons>;
8
- export declare const fetchInvoicingCouponListEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
8
+ export declare const fetchInvoicingCouponListEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -6,13 +6,18 @@ const operators_1 = require("rxjs/operators");
6
6
  const couponReducer_1 = require("../../../entity/invoicing/coupon/couponReducer");
7
7
  const responsePayload_1 = require("../../../responsePayload");
8
8
  const invoicingApiHelper_1 = require("../invoicingApiHelper");
9
+ const invoicingListTabCache_1 = require("../invoicingListTabCache");
9
10
  const couponViewReducer_1 = require("./couponViewReducer");
11
+ const couponViewState_1 = require("./couponViewState");
10
12
  /**
11
13
  * Fetch unless the endpoint is already loaded or in flight — or always when the
12
14
  * caller forces a refresh via `cacheOverride` (e.g. on a filter/sort change).
13
15
  */
14
- const buildQuery = (filters, cursor, sort) => {
16
+ const buildQuery = (filters, cursor, sort, status) => {
15
17
  const params = new URLSearchParams();
18
+ if (status != null) {
19
+ params.set('status', status);
20
+ }
16
21
  if (filters.search != null && filters.search.length > 0) {
17
22
  params.set('search', filters.search);
18
23
  }
@@ -23,9 +28,15 @@ const buildQuery = (filters, cursor, sort) => {
23
28
  (0, invoicingApiHelper_1.applyListSortParams)(params, sort);
24
29
  return params;
25
30
  };
26
- const fetchInvoicingCouponListEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(couponViewReducer_1.fetchInvoicingCouponList.match), (0, operators_1.switchMap)((action) => {
31
+ const fetchInvoicingCouponListEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(couponViewReducer_1.fetchInvoicingCouponList.match), (0, operators_1.map)((action) => ({
32
+ action,
33
+ tabId: (0, invoicingListTabCache_1.invoicingListFetchTab)(state$.value.invoicingCouponViewState.activeTab, action.payload.tabId, couponViewState_1.INVOICING_COUPON_CLIENT_FILTERED_TAB_IDS),
34
+ })),
35
+ // Per tab: a newer fetch of the same tab replaces its in-flight one, while
36
+ // another tab's request keeps running and lands in its own cache.
37
+ (0, operators_1.groupBy)(({ tabId }) => tabId), (0, operators_1.mergeMap)((tabFetches$) => tabFetches$.pipe((0, operators_1.switchMap)(({ action, tabId }) => {
27
38
  const { filters, cursor, keepExistingListItems, sort } = action.payload;
28
- const apiUrl = (0, invoicingApiHelper_1.withQuery)(`${zeniAPI.apiEndPoints.invoicingMicroServiceBaseUrl}/1.0/discounts`, buildQuery(filters, cursor, sort));
39
+ const apiUrl = (0, invoicingApiHelper_1.withQuery)(`${zeniAPI.apiEndPoints.invoicingMicroServiceBaseUrl}/1.0/discounts`, buildQuery(filters, cursor, sort, (0, invoicingListTabCache_1.invoicingListStatusParam)(tabId)));
29
40
  return zeniAPI.getJSON(apiUrl).pipe((0, operators_1.switchMap)((response) => {
30
41
  if ((0, responsePayload_1.isSuccessResponse)(response)) {
31
42
  const items = response.data?.items ?? [];
@@ -35,11 +46,18 @@ const fetchInvoicingCouponListEpic = (actions$, _state$, zeniAPI) => actions$.pi
35
46
  ids: items.map((item) => item.id),
36
47
  nextCursor: response.data?.next_cursor ?? null,
37
48
  keepExistingListItems,
49
+ tabId,
38
50
  }),
39
51
  ];
40
52
  }
41
- return (0, rxjs_1.of)((0, couponViewReducer_1.updateInvoicingCouponListFailure)(response.status));
42
- }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, couponViewReducer_1.updateInvoicingCouponListFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Fetch discount list REST API call errored out ' +
43
- JSON.stringify(error))))));
44
- }));
53
+ return (0, rxjs_1.of)((0, couponViewReducer_1.updateInvoicingCouponListFailure)({
54
+ status: response.status,
55
+ tabId,
56
+ }));
57
+ }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, couponViewReducer_1.updateInvoicingCouponListFailure)({
58
+ status: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Fetch discount list REST API call errored out ' +
59
+ JSON.stringify(error)),
60
+ tabId,
61
+ }))));
62
+ }))));
45
63
  exports.fetchInvoicingCouponListEpic = fetchInvoicingCouponListEpic;
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchInvoicingCouponListPageEpic = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const operators_1 = require("rxjs/operators");
6
+ const invoicingListTabCache_1 = require("../invoicingListTabCache");
6
7
  const couponViewReducer_1 = require("./couponViewReducer");
8
+ const couponViewState_1 = require("./couponViewState");
7
9
  /**
8
10
  * Fetch unless the endpoint is already loaded or in flight — or always when the
9
11
  * caller forces a refresh via `cacheOverride` (e.g. on a filter/sort change).
@@ -15,8 +17,20 @@ const fetchInvoicingCouponListPageEpic = (actions$, state$) => actions$.pipe((0,
15
17
  const { cacheOverride, filters, sort } = action.payload;
16
18
  const state = state$.value.invoicingCouponViewState;
17
19
  const pageActions = [];
18
- if (shouldFetch({ fetchState: state.fetchState, error: state.error }, cacheOverride)) {
19
- pageActions.push((0, couponViewReducer_1.fetchInvoicingCouponList)({ filters, sort }));
20
+ const tabId = (0, invoicingListTabCache_1.invoicingListSourceTab)(state.activeTab, couponViewState_1.INVOICING_COUPON_CLIENT_FILTERED_TAB_IDS);
21
+ const tabFetch = (0, invoicingListTabCache_1.planInvoicingListTabFetch)((0, invoicingListTabCache_1.getInvoicingListTab)(state.byTab, tabId), cacheOverride);
22
+ if (tabFetch.kind === 'firstPage') {
23
+ pageActions.push((0, couponViewReducer_1.fetchInvoicingCouponList)({ filters, sort, tabId }));
24
+ }
25
+ else if (tabFetch.kind === 'nextPage') {
26
+ // Less than a page cached and the server has more: top it up.
27
+ pageActions.push((0, couponViewReducer_1.fetchInvoicingCouponList)({
28
+ cursor: tabFetch.cursor,
29
+ filters,
30
+ keepExistingListItems: true,
31
+ sort,
32
+ tabId,
33
+ }));
20
34
  }
21
35
  if (shouldFetch(state.countsFetchState, cacheOverride)) {
22
36
  pageActions.push((0, couponViewReducer_1.fetchInvoicingCouponCounts)());