@zeniai/client-epic-state 5.0.71-betaML41 → 5.0.71-betaVR2

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 (52) hide show
  1. package/lib/epic.d.ts +3 -2
  2. package/lib/epic.js +3 -2
  3. package/lib/esm/epic.js +3 -2
  4. package/lib/esm/index.js +8 -8
  5. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +21 -5
  6. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/refreshBatchDetailsForBatchIdEpic.js +52 -0
  7. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/syncTabsAfterAutomatchEpic.js +53 -0
  8. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +13 -9
  9. package/lib/esm/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.js +1 -21
  10. package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +78 -3
  11. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +14 -117
  12. package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +2 -0
  13. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +0 -58
  14. package/lib/esm/view/recommendation/recommendationHelper.js +0 -29
  15. package/lib/esm/view/recommendation/recommendationReducer.js +1 -26
  16. package/lib/esm/view/transactionDetail/transactionDetailReducer.js +6 -121
  17. package/lib/esm/view/transactionDetail/transactionDetailSelector.js +0 -22
  18. package/lib/index.d.ts +8 -9
  19. package/lib/index.js +25 -25
  20. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +21 -5
  21. package/lib/view/expenseAutomationView/epics/missingReceipts/refreshBatchDetailsForBatchIdEpic.d.ts +18 -0
  22. package/lib/view/expenseAutomationView/epics/missingReceipts/refreshBatchDetailsForBatchIdEpic.js +56 -0
  23. package/lib/view/expenseAutomationView/epics/missingReceipts/syncTabsAfterAutomatchEpic.d.ts +28 -0
  24. package/lib/view/expenseAutomationView/epics/missingReceipts/syncTabsAfterAutomatchEpic.js +57 -0
  25. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +11 -5
  26. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +12 -8
  27. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +0 -1
  28. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.js +2 -23
  29. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +13 -1
  30. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +80 -4
  31. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +1 -14
  32. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +14 -117
  33. package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +12 -0
  34. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +0 -2
  35. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +2 -0
  36. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.d.ts +0 -3
  37. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +0 -60
  38. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +19 -0
  39. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +0 -1
  40. package/lib/view/recommendation/recommendationHelper.d.ts +0 -9
  41. package/lib/view/recommendation/recommendationHelper.js +1 -31
  42. package/lib/view/recommendation/recommendationReducer.d.ts +1 -20
  43. package/lib/view/recommendation/recommendationReducer.js +2 -27
  44. package/lib/view/transactionDetail/transactionDetailReducer.d.ts +1 -11
  45. package/lib/view/transactionDetail/transactionDetailReducer.js +7 -122
  46. package/lib/view/transactionDetail/transactionDetailSelector.d.ts +0 -2
  47. package/lib/view/transactionDetail/transactionDetailSelector.js +1 -24
  48. package/lib/view/transactionDetail/transactionDetailTypes.d.ts +0 -1
  49. package/package.json +2 -2
  50. package/lib/esm/view/recommendation/fetchEntityRecommendationsForLineUpdateEpic.js +0 -87
  51. package/lib/view/recommendation/fetchEntityRecommendationsForLineUpdateEpic.d.ts +0 -9
  52. package/lib/view/recommendation/fetchEntityRecommendationsForLineUpdateEpic.js +0 -91
@@ -129,6 +129,13 @@ export interface CompletedTransactionsState {
129
129
  export interface BulkUploadState {
130
130
  batchDetailsById: Record<ID, BatchDetails>;
131
131
  batchDetailsPaginationState: FetchStateAndError;
132
+ /**
133
+ * True while a stale-while-revalidate refresh of `batchDetailsById` is in flight (manual refresh
134
+ * or scope-change replacement). Existing entries are kept on screen during this window; the UI
135
+ * can surface a lightweight refresh indicator. Cleared on `fetchMoreBatchDetailsComplete` /
136
+ * `fetchMoreBatchDetailsFailure`.
137
+ */
138
+ batchDetailsRevalidating: boolean;
132
139
  batchListByPeriod: Record<MonthYearPeriodId, BatchListItem[]>;
133
140
  batchListFetchState: FetchStateAndError;
134
141
  batchStatusById: Record<ID, BatchStatus>;
@@ -137,6 +144,18 @@ export interface BulkUploadState {
137
144
  confirmMatchStatus: FetchStateAndError;
138
145
  currentResultsTab: BulkUploadResultsTab;
139
146
  failedBatchDetailIds: ID[];
147
+ /**
148
+ * Set to `true` once the first batch-details page has resolved (success or empty completion).
149
+ * Drives stale-while-revalidate: the Unmatched skeleton is shown only while this is `false`.
150
+ * Reset only by `clearBulkUpload` or by an explicit scope-change (period/tenant) clear.
151
+ */
152
+ initialBatchDetailsLoaded: boolean;
153
+ /**
154
+ * Last time `GET /1.0/batches/:id` was issued for a given batch via the targeted refresh epic.
155
+ * Used to throttle Pusher resend storms — repeat completion events for the same batchId within
156
+ * the dedupe window are dropped.
157
+ */
158
+ lastBatchDetailRefreshAtById: Record<ID, number>;
140
159
  /**
141
160
  * Incremented when manual search Redux state is cleared so Unmatched `ManualSearchInput`
142
161
  * instances remount and drop local query text.
@@ -48,7 +48,6 @@ export interface TransactionCategorizationLineItemData extends TransactionLineBa
48
48
  transactionId: ID;
49
49
  account?: AccountBase;
50
50
  categorizationStatus?: CategorizationStatusType;
51
- categoryClassRecommendationsFetchState?: FetchStateAndError;
52
51
  class?: ClassBase;
53
52
  customer?: CustomerBase;
54
53
  item?: ProductOrService;
@@ -1,17 +1,8 @@
1
1
  import { RecommendationPayload, RecommendationPayloadWithCOT } from '../../commonPayloadTypes/recommendationPayload';
2
2
  import { ID } from '../../commonStateTypes/common';
3
3
  import { Recommendation, RecommendationWithCOT } from '../../commonStateTypes/recommendationBase';
4
- import { Entity } from '../../entity/genericEntity/entity';
5
4
  import { RecommendationByLineId, RecommendationWithCOTByLineId } from '../../entity/transaction/stateTypes/transaction';
6
- import { SupportedTransaction } from '../../entity/transaction/transactionState';
7
5
  export declare const getRecommendationFromRecommendationPayload: (payload: RecommendationPayload[]) => Recommendation[] | undefined;
8
6
  export declare const getRecommendationByLineIdFromRecommendationPayload: (recommendationPayload: RecommendationPayload[], lineIds: ID[]) => RecommendationByLineId | undefined;
9
7
  export declare const getRecommendationWithCOTFromRecommendationPayloadWithCOT: (payload: RecommendationPayloadWithCOT[]) => RecommendationWithCOT[] | undefined;
10
- export declare const buildRecommendationUrl: (accountMicroServiceBaseUrl: string, entity: Entity, amount: number, transactionDetails: {
11
- lineIds: ID[];
12
- transaction: SupportedTransaction;
13
- transactionId: {
14
- id: string;
15
- };
16
- }, isFetchCOT: boolean) => string;
17
8
  export declare const getRecommendationByLineIdWithCOTFromRecommendationPayloadWithCOT: (recommendationPayload: RecommendationPayloadWithCOT[], lineIds: ID[]) => RecommendationWithCOTByLineId | undefined;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRecommendationByLineIdWithCOTFromRecommendationPayloadWithCOT = exports.buildRecommendationUrl = exports.getRecommendationWithCOTFromRecommendationPayloadWithCOT = exports.getRecommendationByLineIdFromRecommendationPayload = exports.getRecommendationFromRecommendationPayload = void 0;
3
+ exports.getRecommendationByLineIdWithCOTFromRecommendationPayloadWithCOT = exports.getRecommendationWithCOTFromRecommendationPayloadWithCOT = exports.getRecommendationByLineIdFromRecommendationPayload = exports.getRecommendationFromRecommendationPayload = void 0;
4
4
  const transactionPayload_1 = require("../../entity/transaction/payloadTypes/transactionPayload");
5
- const transactionDetailState_1 = require("../transactionDetail/transactionDetailState");
6
5
  const getRecommendationFromRecommendationPayload = (payload) => {
7
6
  if (payload == null || payload.length === 0) {
8
7
  return undefined;
@@ -44,35 +43,6 @@ const getRecommendationWithCOTFromRecommendationPayloadWithCOT = (payload) => {
44
43
  return recommendations;
45
44
  };
46
45
  exports.getRecommendationWithCOTFromRecommendationPayloadWithCOT = getRecommendationWithCOTFromRecommendationPayloadWithCOT;
47
- // Pluralized URL segment for entity types. Mirrors the legacy
48
- // fetchEntityRecommendationsByTransactionIdEpic.toEntityTypeURL.
49
- const toEntityTypeUrlSegment = (entityType) => `${entityType}s`;
50
- // Build the recommendations URL for a single entity + transaction target.
51
- // Centralizes the URL shape so the legacy
52
- // fetchEntityRecommendationsByTransactionIdEpic and the new
53
- // fetchEntityRecommendationsForLineUpdateEpic stay in lockstep.
54
- const buildRecommendationUrl = (accountMicroServiceBaseUrl, entity, amount, transactionDetails, isFetchCOT) => {
55
- const entityQuery = {
56
- entity_name: entity.name,
57
- entity_type: entity.type,
58
- };
59
- // Entity-id-null case: server expects entity_name / entity_type query
60
- // instead of the {entityType}/{qboId}/recommendations path.
61
- if (entity.qboId === entity.name) {
62
- return `${accountMicroServiceBaseUrl}/1.0/recommendations?query=${encodeURIComponent(JSON.stringify(entityQuery))}`;
63
- }
64
- const query = {
65
- amount,
66
- transaction_id: (0, transactionDetailState_1.getActualTransactionID)(transactionDetails.transactionId.id),
67
- transaction_type: transactionDetails.transaction.type,
68
- line_ids: transactionDetails.lineIds,
69
- };
70
- if (isFetchCOT === true) {
71
- query.include_cot = true;
72
- }
73
- return `${accountMicroServiceBaseUrl}/1.0/${toEntityTypeUrlSegment(entity.type)}/${entity.qboId}/recommendations?query=${encodeURIComponent(JSON.stringify(query))}`;
74
- };
75
- exports.buildRecommendationUrl = buildRecommendationUrl;
76
46
  const getRecommendationByLineIdWithCOTFromRecommendationPayloadWithCOT = (recommendationPayload, lineIds) => {
77
47
  if (recommendationPayload.length === 0) {
78
48
  return undefined;
@@ -4,26 +4,7 @@ import { Entity, EntityType } from '../../entity/genericEntity/entity';
4
4
  import { TransactionID } from '../../entity/transaction/stateTypes/transaction';
5
5
  import { SupportedTransaction } from '../../entity/transaction/transactionState';
6
6
  import { ZeniAPIStatus } from '../../responsePayload';
7
- import { TransactionsTab } from '../expenseAutomationView/types/transactionsViewState';
8
7
  import { EntityRecommendationState } from './recommendationState';
9
- export type RecommendationLineUpdateFlowType = 'categorization' | 'detail';
10
- type FetchEntityRecommendationsForLineUpdateCommonPayload = {
11
- amount: number;
12
- entity: Entity;
13
- transactionDetails: {
14
- lineIds: ID[];
15
- transaction: SupportedTransaction;
16
- transactionId: TransactionID;
17
- };
18
- isFetchCOT?: boolean;
19
- isUncategorizedExpenseCategoryEnabled?: boolean;
20
- };
21
- export type FetchEntityRecommendationsForLineUpdatePayload = (FetchEntityRecommendationsForLineUpdateCommonPayload & {
22
- flowType: 'categorization';
23
- selectedTab: TransactionsTab;
24
- }) | (FetchEntityRecommendationsForLineUpdateCommonPayload & {
25
- flowType: 'detail';
26
- });
27
8
  export declare const initialState: EntityRecommendationState;
28
9
  export declare const fetchEntityRecommendationsByTransactionId: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[entity: Entity, amount: number, transactionDetails: {
29
10
  lineIds: ID[];
@@ -41,7 +22,7 @@ export declare const fetchEntityRecommendationsByTransactionId: import("@reduxjs
41
22
  isTransactionCategorizationFlow: any;
42
23
  isFetchCOT: any;
43
24
  isUncategorizedExpenseCategoryEnabled: boolean | undefined;
44
- }, "recommendation/fetchEntityRecommendationsByTransactionId", never, never>, fetchEntityRecommendationsForLineUpdate: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[args: FetchEntityRecommendationsForLineUpdatePayload], FetchEntityRecommendationsForLineUpdatePayload, "recommendation/fetchEntityRecommendationsForLineUpdate", never, never>, fetchRecommendationByEntityName: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[entityName: string, entityType: EntityType], {
25
+ }, "recommendation/fetchEntityRecommendationsByTransactionId", never, never>, fetchRecommendationByEntityName: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[entityName: string, entityType: EntityType], {
45
26
  entityName: string;
46
27
  entityType: EntityType;
47
28
  }, "recommendation/fetchRecommendationByEntityName", never, never>, fetchRecommendationByEntityId: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[entityId: string, entityType: EntityType], {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.clearRecommendation = exports.indicateReadyToInitializeRecommendation = exports.updateRecommendationForEntityFailure = exports.updateRecommendationForEntity = exports.fetchRecommendationByEntityId = exports.fetchRecommendationByEntityName = exports.fetchEntityRecommendationsForLineUpdate = exports.fetchEntityRecommendationsByTransactionId = exports.initialState = void 0;
4
+ exports.clearRecommendation = exports.indicateReadyToInitializeRecommendation = exports.updateRecommendationForEntityFailure = exports.updateRecommendationForEntity = exports.fetchRecommendationByEntityId = exports.fetchRecommendationByEntityName = exports.fetchEntityRecommendationsByTransactionId = exports.initialState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  const recommendationState_1 = require("./recommendationState");
7
7
  exports.initialState = {
@@ -37,31 +37,6 @@ const recommendation = (0, toolkit_1.createSlice)({
37
37
  };
38
38
  },
39
39
  },
40
- // Targeted recommendations fetch fired when the user changes the
41
- // payee/customer on a single transaction line (or the JE sibling set
42
- // for that change). Routed by `fetchEntityRecommendationsForLineUpdateEpic`
43
- // which uses groupBy + switchMap to keep fetches for distinct targets
44
- // running in parallel while same-target re-fetches still cancel each
45
- // other. The flowType discriminator selects the categorization vs
46
- // detail slice for the per-line In-Progress / Completed / Error state.
47
- fetchEntityRecommendationsForLineUpdate: {
48
- reducer(draft, action) {
49
- const { entity } = action.payload;
50
- const key = (0, recommendationState_1.getEntityRecommendationKey)(entity.type, entity.id);
51
- // Unconditional flip to In-Progress; the previous variant only
52
- // seeded when missing, which left stale fetchStates when a prior
53
- // fetch had already populated the entity entry.
54
- draft.recommendationByEntity[key] = {
55
- ...(draft.recommendationByEntity[key] ??
56
- recommendationState_1.initialEntityRecommendationState),
57
- fetchState: 'In-Progress',
58
- error: undefined,
59
- };
60
- },
61
- prepare(args) {
62
- return { payload: args };
63
- },
64
- },
65
40
  fetchRecommendationByEntityName: {
66
41
  reducer(draft, action) {
67
42
  const { entityName, entityType } = action.payload;
@@ -140,7 +115,7 @@ const recommendation = (0, toolkit_1.createSlice)({
140
115
  },
141
116
  },
142
117
  });
143
- _a = recommendation.actions, exports.fetchEntityRecommendationsByTransactionId = _a.fetchEntityRecommendationsByTransactionId, exports.fetchEntityRecommendationsForLineUpdate = _a.fetchEntityRecommendationsForLineUpdate, exports.fetchRecommendationByEntityName = _a.fetchRecommendationByEntityName, exports.fetchRecommendationByEntityId = _a.fetchRecommendationByEntityId, exports.updateRecommendationForEntity = _a.updateRecommendationForEntity, exports.updateRecommendationForEntityFailure = _a.updateRecommendationForEntityFailure, exports.indicateReadyToInitializeRecommendation = _a.indicateReadyToInitializeRecommendation, exports.clearRecommendation = _a.clearRecommendation;
118
+ _a = recommendation.actions, exports.fetchEntityRecommendationsByTransactionId = _a.fetchEntityRecommendationsByTransactionId, exports.fetchRecommendationByEntityName = _a.fetchRecommendationByEntityName, exports.fetchRecommendationByEntityId = _a.fetchRecommendationByEntityId, exports.updateRecommendationForEntity = _a.updateRecommendationForEntity, exports.updateRecommendationForEntityFailure = _a.updateRecommendationForEntityFailure, exports.indicateReadyToInitializeRecommendation = _a.indicateReadyToInitializeRecommendation, exports.clearRecommendation = _a.clearRecommendation;
144
119
  exports.default = recommendation.reducer;
145
120
  const doUpdateRecommendationForEntity = (draft, entityId, entityType, payload) => {
146
121
  const key = (0, recommendationState_1.getEntityRecommendationKey)(entityType, entityId);
@@ -115,17 +115,7 @@ export declare const downloadAccountingProviderAttachment: import("@reduxjs/tool
115
115
  amount: number;
116
116
  recommendationWithCOTByLineId: RecommendationWithCOTByLineId;
117
117
  uncategorizedIncomeExpense: UncategorizedAccounts;
118
- }, "transactionDetail/setEntityRecommendationForLineIdsForTransactionDetail", never, never>, markCategoryClassRecommendationsInProgressForTransactionDetail: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionId: TransactionID, lineIds: string[]], {
119
- transactionId: TransactionID;
120
- lineIds: string[];
121
- }, "transactionDetail/markCategoryClassRecommendationsInProgressForTransactionDetail", never, never>, markCategoryClassRecommendationsCompletedForTransactionDetail: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionId: TransactionID, lineIds: string[]], {
122
- transactionId: TransactionID;
123
- lineIds: string[];
124
- }, "transactionDetail/markCategoryClassRecommendationsCompletedForTransactionDetail", never, never>, markCategoryClassRecommendationsFailureForTransactionDetail: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionId: TransactionID, lineIds: string[], error: ZeniAPIStatus<Record<string, unknown>>], {
125
- transactionId: TransactionID;
126
- lineIds: string[];
127
- error: ZeniAPIStatus<Record<string, unknown>>;
128
- }, "transactionDetail/markCategoryClassRecommendationsFailureForTransactionDetail", never, never>, removeEntityRecommendationForLineIdForTransactionDetail: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionId: TransactionID, transaction: SupportedTransaction, lineId: string], {
118
+ }, "transactionDetail/setEntityRecommendationForLineIdsForTransactionDetail", never, never>, removeEntityRecommendationForLineIdForTransactionDetail: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionId: TransactionID, transaction: SupportedTransaction, lineId: string], {
129
119
  transactionId: TransactionID;
130
120
  transaction: SupportedTransaction;
131
121
  lineId: string;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.setIsVendorUpdateAllChecked = exports.updateVendorBulkRecommendationsFetchStatus = exports.updateLatestSelectedEntity = exports.resetAllLineItemsToVendor = exports.updateVendorToAllLineItems = exports.updateLocalDataWithTransactionsUpdateWithVendorCheckbox = exports.resetSelectedCustomer = exports.resetVendor = exports.updateSelectedCustomer = exports.updateSelectedVendor = exports.removeEntityRecommendationForLineIdForTransactionDetail = exports.markCategoryClassRecommendationsFailureForTransactionDetail = exports.markCategoryClassRecommendationsCompletedForTransactionDetail = exports.markCategoryClassRecommendationsInProgressForTransactionDetail = exports.setEntityRecommendationForLineIdsForTransactionDetail = exports.setAllLineItemsLocalDataIsUpdateAllChecked = exports.setAllLineItemsToCategoryClassInLocalData = exports.resetLineItemsCategoryClassInLocalData = exports.clearTransactionDetailLocalData = exports.saveTransactionDetailLocalData = exports.initializeTransactionDetailLocalData = exports.saveTransactionDetail = exports.updateTransactionStateIfUpdateActionNotAllowed = exports.updateStatusConsolidatedSaveTransactionDetail = exports.updateStatusForTransactionNotMiscategorizedUpdate = exports.deleteTransactionAttachmentSuccess = exports.deleteTransactionAttachmentFailure = exports.deleteTransactionAttachment = exports.markTransactionAsNotMiscategorized = exports.clearTransactionDetailSaveStatus = exports.updateTransactionDetailSaveStatus = exports.updateTransactionDetail = exports.uploadMissingAttachmentSuccess = exports.clearTransactionDetail = exports.removeTransactionDetail = exports.updateTransactionDetailFetchState = exports.fetchTransactionDetail = exports.downloadAccountingProviderAttachmentFailure = exports.downloadAccountingProviderAttachmentSuccess = exports.downloadAccountingProviderAttachment = exports.initialState = void 0;
7
+ exports.setIsVendorUpdateAllChecked = exports.updateVendorBulkRecommendationsFetchStatus = exports.updateLatestSelectedEntity = exports.resetAllLineItemsToVendor = exports.updateVendorToAllLineItems = exports.updateLocalDataWithTransactionsUpdateWithVendorCheckbox = exports.resetSelectedCustomer = exports.resetVendor = exports.updateSelectedCustomer = exports.updateSelectedVendor = exports.removeEntityRecommendationForLineIdForTransactionDetail = exports.setEntityRecommendationForLineIdsForTransactionDetail = exports.setAllLineItemsLocalDataIsUpdateAllChecked = exports.setAllLineItemsToCategoryClassInLocalData = exports.resetLineItemsCategoryClassInLocalData = exports.clearTransactionDetailLocalData = exports.saveTransactionDetailLocalData = exports.initializeTransactionDetailLocalData = exports.saveTransactionDetail = exports.updateTransactionStateIfUpdateActionNotAllowed = exports.updateStatusConsolidatedSaveTransactionDetail = exports.updateStatusForTransactionNotMiscategorizedUpdate = exports.deleteTransactionAttachmentSuccess = exports.deleteTransactionAttachmentFailure = exports.deleteTransactionAttachment = exports.markTransactionAsNotMiscategorized = exports.clearTransactionDetailSaveStatus = exports.updateTransactionDetailSaveStatus = exports.updateTransactionDetail = exports.uploadMissingAttachmentSuccess = exports.clearTransactionDetail = exports.removeTransactionDetail = exports.updateTransactionDetailFetchState = exports.fetchTransactionDetail = exports.downloadAccountingProviderAttachmentFailure = exports.downloadAccountingProviderAttachmentSuccess = exports.downloadAccountingProviderAttachment = exports.initialState = void 0;
8
8
  const toolkit_1 = require("@reduxjs/toolkit");
9
9
  const get_1 = __importDefault(require("lodash/get"));
10
10
  const entity_1 = require("../../entity/genericEntity/entity");
@@ -245,34 +245,12 @@ const transactionDetail = (0, toolkit_1.createSlice)({
245
245
  saveTransactionDetailLocalData(draft, action) {
246
246
  const key = (0, transactionDetailState_1.getTransactionDetailKey)(action.payload.transactionId);
247
247
  const detail = (0, get_1.default)(draft.transactionDetailById, key, undefined);
248
- if (detail == null) {
249
- return;
248
+ if (detail != null) {
249
+ draft.transactionDetailById[key] = {
250
+ ...detail,
251
+ transactionDetailLocalData: action.payload.transactionLocalData,
252
+ };
250
253
  }
251
- const incoming = action.payload.transactionLocalData;
252
- const prevById = detail.transactionDetailLocalData.lineItemById;
253
- // Per-line `categoryClassRecommendationsFetchState` is owned by the
254
- // recommendation epic/reducers (markInProgress / markCompleted /
255
- // markFailure / setEntityRecommendationForLineIdsForTransactionDetail).
256
- // Callers that rebuild `transactionLocalData` from a UI snapshot will
257
- // typically have an out-of-date copy of this field (e.g. payee-change
258
- // captures the snapshot before the epic's start arm runs and would
259
- // otherwise clobber In-Progress back to undefined). Treat the field as
260
- // sticky: only let the caller override it when they explicitly set it.
261
- const mergedLineItemById = {};
262
- Object.entries(incoming.lineItemById ?? {}).forEach(([lineId, line]) => {
263
- mergedLineItemById[lineId] = {
264
- ...line,
265
- categoryClassRecommendationsFetchState: line.categoryClassRecommendationsFetchState ??
266
- prevById?.[lineId]?.categoryClassRecommendationsFetchState,
267
- };
268
- });
269
- draft.transactionDetailById[key] = {
270
- ...detail,
271
- transactionDetailLocalData: {
272
- ...incoming,
273
- lineItemById: mergedLineItemById,
274
- },
275
- };
276
254
  },
277
255
  saveTransactionDetail(draft, action) {
278
256
  const key = (0, transactionDetailState_1.getTransactionDetailKey)(action.payload.transactionId);
@@ -394,21 +372,6 @@ const transactionDetail = (0, toolkit_1.createSlice)({
394
372
  const detail = (0, get_1.default)(draft.transactionDetailById, key, undefined);
395
373
  if (detail != null) {
396
374
  const newLocalData = (0, transactionDetailLocalDataHelper_1.setEntityRecommendationForLineIdInLocalData)(transaction, detail.transactionDetailLocalData, action.payload.entity, lineIds, uncategorizedIncomeExpense, recommendationWithCOTByLineId);
397
- // Release the per-line fetch flag for every line this fetch
398
- // covered so the inline skeleton resolves and the page-level
399
- // Save button can re-enable.
400
- lineIds.forEach((lineId) => {
401
- const lineItem = newLocalData.lineItemById[lineId];
402
- if (lineItem != null) {
403
- newLocalData.lineItemById[lineId] = {
404
- ...lineItem,
405
- categoryClassRecommendationsFetchState: {
406
- fetchState: 'Completed',
407
- error: undefined,
408
- },
409
- };
410
- }
411
- });
412
375
  draft.transactionDetailById[key] = {
413
376
  ...detail,
414
377
  transactionDetailLocalData: newLocalData,
@@ -429,84 +392,6 @@ const transactionDetail = (0, toolkit_1.createSlice)({
429
392
  };
430
393
  },
431
394
  },
432
- // Start arm of the line-update recommendations fetch for the detail
433
- // page. Flips covered lines to In-Progress; detail page has no
434
- // checkbox, so no auto-uncheck side effect.
435
- markCategoryClassRecommendationsInProgressForTransactionDetail: {
436
- reducer(draft, action) {
437
- const { transactionId, lineIds } = action.payload;
438
- const key = (0, transactionDetailState_1.getTransactionDetailKey)(transactionId);
439
- const detail = (0, get_1.default)(draft.transactionDetailById, key, undefined);
440
- if (detail != null) {
441
- lineIds.forEach((lineId) => {
442
- const lineItem = detail.transactionDetailLocalData.lineItemById[lineId];
443
- if (lineItem != null) {
444
- detail.transactionDetailLocalData.lineItemById[lineId] = {
445
- ...lineItem,
446
- categoryClassRecommendationsFetchState: {
447
- fetchState: 'In-Progress',
448
- error: undefined,
449
- },
450
- };
451
- }
452
- });
453
- }
454
- },
455
- prepare(transactionId, lineIds) {
456
- return { payload: { transactionId, lineIds } };
457
- },
458
- },
459
- // Completed arm. Used when the HTTP call succeeded but the server
460
- // returned no per-line recommendations — still need to release the
461
- // In-Progress flag.
462
- markCategoryClassRecommendationsCompletedForTransactionDetail: {
463
- reducer(draft, action) {
464
- const { transactionId, lineIds } = action.payload;
465
- const key = (0, transactionDetailState_1.getTransactionDetailKey)(transactionId);
466
- const detail = (0, get_1.default)(draft.transactionDetailById, key, undefined);
467
- if (detail != null) {
468
- lineIds.forEach((lineId) => {
469
- const lineItem = detail.transactionDetailLocalData.lineItemById[lineId];
470
- if (lineItem != null) {
471
- detail.transactionDetailLocalData.lineItemById[lineId] = {
472
- ...lineItem,
473
- categoryClassRecommendationsFetchState: {
474
- fetchState: 'Completed',
475
- error: undefined,
476
- },
477
- };
478
- }
479
- });
480
- }
481
- },
482
- prepare(transactionId, lineIds) {
483
- return { payload: { transactionId, lineIds } };
484
- },
485
- },
486
- markCategoryClassRecommendationsFailureForTransactionDetail: {
487
- reducer(draft, action) {
488
- const { transactionId, lineIds, error } = action.payload;
489
- const key = (0, transactionDetailState_1.getTransactionDetailKey)(transactionId);
490
- const detail = (0, get_1.default)(draft.transactionDetailById, key, undefined);
491
- if (detail != null) {
492
- lineIds.forEach((lineId) => {
493
- const lineItem = detail.transactionDetailLocalData.lineItemById[lineId];
494
- if (lineItem != null) {
495
- detail.transactionDetailLocalData.lineItemById[lineId] = {
496
- ...lineItem,
497
- categoryClassRecommendationsFetchState: {
498
- fetchState: 'Error',
499
- error,
500
- },
501
- };
502
- }
503
- });
504
- }
505
- },
506
- prepare(transactionId, lineIds, error) {
507
- return { payload: { transactionId, lineIds, error } };
508
- },
509
- },
510
395
  removeEntityRecommendationForLineIdForTransactionDetail: {
511
396
  reducer(draft, action) {
512
397
  const { transaction, lineId } = action.payload;
@@ -778,7 +663,7 @@ const transactionDetail = (0, toolkit_1.createSlice)({
778
663
  },
779
664
  },
780
665
  });
781
- _a = transactionDetail.actions, exports.downloadAccountingProviderAttachment = _a.downloadAccountingProviderAttachment, exports.downloadAccountingProviderAttachmentSuccess = _a.downloadAccountingProviderAttachmentSuccess, exports.downloadAccountingProviderAttachmentFailure = _a.downloadAccountingProviderAttachmentFailure, exports.fetchTransactionDetail = _a.fetchTransactionDetail, exports.updateTransactionDetailFetchState = _a.updateTransactionDetailFetchState, exports.removeTransactionDetail = _a.removeTransactionDetail, exports.clearTransactionDetail = _a.clearTransactionDetail, exports.uploadMissingAttachmentSuccess = _a.uploadMissingAttachmentSuccess, exports.updateTransactionDetail = _a.updateTransactionDetail, exports.updateTransactionDetailSaveStatus = _a.updateTransactionDetailSaveStatus, exports.clearTransactionDetailSaveStatus = _a.clearTransactionDetailSaveStatus, exports.markTransactionAsNotMiscategorized = _a.markTransactionAsNotMiscategorized, exports.deleteTransactionAttachment = _a.deleteTransactionAttachment, exports.deleteTransactionAttachmentFailure = _a.deleteTransactionAttachmentFailure, exports.deleteTransactionAttachmentSuccess = _a.deleteTransactionAttachmentSuccess, exports.updateStatusForTransactionNotMiscategorizedUpdate = _a.updateStatusForTransactionNotMiscategorizedUpdate, exports.updateStatusConsolidatedSaveTransactionDetail = _a.updateStatusConsolidatedSaveTransactionDetail, exports.updateTransactionStateIfUpdateActionNotAllowed = _a.updateTransactionStateIfUpdateActionNotAllowed, exports.saveTransactionDetail = _a.saveTransactionDetail, exports.initializeTransactionDetailLocalData = _a.initializeTransactionDetailLocalData, exports.saveTransactionDetailLocalData = _a.saveTransactionDetailLocalData, exports.clearTransactionDetailLocalData = _a.clearTransactionDetailLocalData, exports.resetLineItemsCategoryClassInLocalData = _a.resetLineItemsCategoryClassInLocalData, exports.setAllLineItemsToCategoryClassInLocalData = _a.setAllLineItemsToCategoryClassInLocalData, exports.setAllLineItemsLocalDataIsUpdateAllChecked = _a.setAllLineItemsLocalDataIsUpdateAllChecked, exports.setEntityRecommendationForLineIdsForTransactionDetail = _a.setEntityRecommendationForLineIdsForTransactionDetail, exports.markCategoryClassRecommendationsInProgressForTransactionDetail = _a.markCategoryClassRecommendationsInProgressForTransactionDetail, exports.markCategoryClassRecommendationsCompletedForTransactionDetail = _a.markCategoryClassRecommendationsCompletedForTransactionDetail, exports.markCategoryClassRecommendationsFailureForTransactionDetail = _a.markCategoryClassRecommendationsFailureForTransactionDetail, exports.removeEntityRecommendationForLineIdForTransactionDetail = _a.removeEntityRecommendationForLineIdForTransactionDetail, exports.updateSelectedVendor = _a.updateSelectedVendor, exports.updateSelectedCustomer = _a.updateSelectedCustomer, exports.resetVendor = _a.resetVendor, exports.resetSelectedCustomer = _a.resetSelectedCustomer, exports.updateLocalDataWithTransactionsUpdateWithVendorCheckbox = _a.updateLocalDataWithTransactionsUpdateWithVendorCheckbox, exports.updateVendorToAllLineItems = _a.updateVendorToAllLineItems, exports.resetAllLineItemsToVendor = _a.resetAllLineItemsToVendor, exports.updateLatestSelectedEntity = _a.updateLatestSelectedEntity, exports.updateVendorBulkRecommendationsFetchStatus = _a.updateVendorBulkRecommendationsFetchStatus, exports.setIsVendorUpdateAllChecked = _a.setIsVendorUpdateAllChecked;
666
+ _a = transactionDetail.actions, exports.downloadAccountingProviderAttachment = _a.downloadAccountingProviderAttachment, exports.downloadAccountingProviderAttachmentSuccess = _a.downloadAccountingProviderAttachmentSuccess, exports.downloadAccountingProviderAttachmentFailure = _a.downloadAccountingProviderAttachmentFailure, exports.fetchTransactionDetail = _a.fetchTransactionDetail, exports.updateTransactionDetailFetchState = _a.updateTransactionDetailFetchState, exports.removeTransactionDetail = _a.removeTransactionDetail, exports.clearTransactionDetail = _a.clearTransactionDetail, exports.uploadMissingAttachmentSuccess = _a.uploadMissingAttachmentSuccess, exports.updateTransactionDetail = _a.updateTransactionDetail, exports.updateTransactionDetailSaveStatus = _a.updateTransactionDetailSaveStatus, exports.clearTransactionDetailSaveStatus = _a.clearTransactionDetailSaveStatus, exports.markTransactionAsNotMiscategorized = _a.markTransactionAsNotMiscategorized, exports.deleteTransactionAttachment = _a.deleteTransactionAttachment, exports.deleteTransactionAttachmentFailure = _a.deleteTransactionAttachmentFailure, exports.deleteTransactionAttachmentSuccess = _a.deleteTransactionAttachmentSuccess, exports.updateStatusForTransactionNotMiscategorizedUpdate = _a.updateStatusForTransactionNotMiscategorizedUpdate, exports.updateStatusConsolidatedSaveTransactionDetail = _a.updateStatusConsolidatedSaveTransactionDetail, exports.updateTransactionStateIfUpdateActionNotAllowed = _a.updateTransactionStateIfUpdateActionNotAllowed, exports.saveTransactionDetail = _a.saveTransactionDetail, exports.initializeTransactionDetailLocalData = _a.initializeTransactionDetailLocalData, exports.saveTransactionDetailLocalData = _a.saveTransactionDetailLocalData, exports.clearTransactionDetailLocalData = _a.clearTransactionDetailLocalData, exports.resetLineItemsCategoryClassInLocalData = _a.resetLineItemsCategoryClassInLocalData, exports.setAllLineItemsToCategoryClassInLocalData = _a.setAllLineItemsToCategoryClassInLocalData, exports.setAllLineItemsLocalDataIsUpdateAllChecked = _a.setAllLineItemsLocalDataIsUpdateAllChecked, exports.setEntityRecommendationForLineIdsForTransactionDetail = _a.setEntityRecommendationForLineIdsForTransactionDetail, exports.removeEntityRecommendationForLineIdForTransactionDetail = _a.removeEntityRecommendationForLineIdForTransactionDetail, exports.updateSelectedVendor = _a.updateSelectedVendor, exports.updateSelectedCustomer = _a.updateSelectedCustomer, exports.resetVendor = _a.resetVendor, exports.resetSelectedCustomer = _a.resetSelectedCustomer, exports.updateLocalDataWithTransactionsUpdateWithVendorCheckbox = _a.updateLocalDataWithTransactionsUpdateWithVendorCheckbox, exports.updateVendorToAllLineItems = _a.updateVendorToAllLineItems, exports.resetAllLineItemsToVendor = _a.resetAllLineItemsToVendor, exports.updateLatestSelectedEntity = _a.updateLatestSelectedEntity, exports.updateVendorBulkRecommendationsFetchStatus = _a.updateVendorBulkRecommendationsFetchStatus, exports.setIsVendorUpdateAllChecked = _a.setIsVendorUpdateAllChecked;
782
667
  exports.default = transactionDetail.reducer;
783
668
  function getUpdatedEntityLocalData(detail, updates, entity, resetRecommendations, type) {
784
669
  const key = type === 'customer' ? 'customerUpdates' : 'vendorUpdates';
@@ -18,7 +18,6 @@ export interface TransactionDetailReport extends SelectorView {
18
18
  classHierarchyList: NestedClassHierarchyForReport[];
19
19
  classList: ClassListSelectorView;
20
20
  deleteStatusByAttachmentName: Record<string, FetchStateAndError>;
21
- hasInFlightCategoryClassRecommendations: boolean;
22
21
  isAccountingClassesEnabled: boolean;
23
22
  isAccountingProjectsEnabled: boolean;
24
23
  linkedTransactions: SupportedTransactionWithCOT[];
@@ -31,7 +30,6 @@ export interface TransactionDetailReport extends SelectorView {
31
30
  export interface VendorDetailsView extends SelectorView {
32
31
  vendors: Vendor[];
33
32
  }
34
- export declare const getDetailInFlightRecommendations: (state: RootState, transactionId: TransactionID) => boolean;
35
33
  export declare const getTransactionDetail: (state: RootState, transactionId: TransactionID, fetchLinkedTransactions?: boolean) => TransactionDetailReport;
36
34
  export declare function getTransactionDetailForTransaction(rootState: RootState, transactionId: TransactionID): TransactionDetailReport | undefined;
37
35
  export declare const getInitialUpdatablePeriodsForTransactionRecommendations: (companyIncorporationDate?: ZeniDate, bookCloseDate?: ZeniDate) => {
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getInitialUpdatablePeriodsForTransactionRecommendations = exports.getTransactionDetail = exports.getDetailInFlightRecommendations = void 0;
6
+ exports.getInitialUpdatablePeriodsForTransactionRecommendations = exports.getTransactionDetail = void 0;
7
7
  exports.getTransactionDetailForTransaction = getTransactionDetailForTransaction;
8
8
  const get_1 = __importDefault(require("lodash/get"));
9
9
  const reduceFetchState_1 = require("../../commonStateTypes/reduceFetchState");
@@ -17,27 +17,6 @@ const accountListSelector_1 = require("../accountList/accountListSelector");
17
17
  const classListSelector_1 = require("../classList/classListSelector");
18
18
  const projectListSelector_1 = require("../projectList/projectListSelector");
19
19
  const transactionDetailState_1 = require("./transactionDetailState");
20
- // "Any line on this transaction is fetching category/class recommendations?"
21
- // Inlined as a plain function because the upstream selector
22
- // `getTransactionDetail` is also un-memoized and the iteration is O(lines)
23
- // — typically <10. Exported standalone so consumers that only need the
24
- // flag (e.g. footer save-disable) can avoid materializing the whole
25
- // detail report.
26
- const getDetailInFlightRecommendations = (state, transactionId) => {
27
- const detailKey = (0, transactionDetailState_1.getTransactionDetailKey)(transactionId);
28
- const detail = (0, get_1.default)(state.transactionDetailState.transactionDetailById, detailKey, undefined);
29
- if (detail == null) {
30
- return false;
31
- }
32
- for (const lineItem of Object.values(detail.transactionDetailLocalData.lineItemById)) {
33
- if (lineItem.categoryClassRecommendationsFetchState?.fetchState ===
34
- 'In-Progress') {
35
- return true;
36
- }
37
- }
38
- return false;
39
- };
40
- exports.getDetailInFlightRecommendations = getDetailInFlightRecommendations;
41
20
  const getTransactionDetail = (state, transactionId, fetchLinkedTransactions = true) => {
42
21
  const { transactionDetailState, transactionState, vendorState, vendorListState, accountState, classState, classListState, accountListState, projectState, projectListState, } = state;
43
22
  const detailKey = (0, transactionDetailState_1.getTransactionDetailKey)(transactionId);
@@ -106,7 +85,6 @@ const getTransactionDetail = (state, transactionId, fetchLinkedTransactions = tr
106
85
  : [];
107
86
  const transactionDetailAnyUpdateStatus = reduceUpdateFetchStates(transactionDetail);
108
87
  const vendors = (0, vendorSelector_1.getVendorsByVendorIds)(vendorState, vendorListState.vendorIds);
109
- const hasInFlightCategoryClassRecommendations = (0, exports.getDetailInFlightRecommendations)(state, transactionId);
110
88
  return {
111
89
  reportId: 'transaction_detail',
112
90
  reportTitle: 'Transaction Detail',
@@ -122,7 +100,6 @@ const getTransactionDetail = (state, transactionId, fetchLinkedTransactions = tr
122
100
  classHierarchyList,
123
101
  accountsHierarchyList,
124
102
  classList: classList,
125
- hasInFlightCategoryClassRecommendations,
126
103
  isAccountingClassesEnabled,
127
104
  isAccountingProjectsEnabled,
128
105
  projectList,
@@ -14,7 +14,6 @@ export interface TransactionDetailLineItemData extends TransactionLineBase {
14
14
  isClassMiscategorized: boolean;
15
15
  account?: AccountBase;
16
16
  billable?: BillableStatus;
17
- categoryClassRecommendationsFetchState?: FetchStateAndError;
18
17
  class?: ClassBase;
19
18
  customer?: CustomerBase;
20
19
  isCategoryUpdateSelected?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.0.71-betaML41",
3
+ "version": "5.0.71-betaVR2",
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",
@@ -116,7 +116,7 @@
116
116
  "find-dead-code": "ts-prune | grep -v '(used in module)'",
117
117
  "find-unused-exports": "ts-unused-exports ./tsconfig.json",
118
118
  "circular-dependency": "npx madge --circular --extensions ts ./src",
119
- "build": "concurrently --kill-others-on-fail --handle-input \"echo 'TypeScript build in progress...' && time tsc && echo 'ESM build...' && tsc -p tsconfig.esm.json\" \"echo 'Running tests and typecheck (incl. lint-modified-files)...' && pnpm test\" && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
119
+ "build": "concurrently --kill-others-on-fail --handle-input \"echo 'TypeScript build in progress...' && time tsc && echo 'ESM build...' && tsc -p tsconfig.esm.json\"",
120
120
  "only-build": "eslint . --ext .js,.jsx,.ts,.tsx && time tsc && tsc -p tsconfig.esm.json && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
121
121
  "only-build-dev": "eslint . --ext .js,.jsx,.ts,.tsx && time tsc -p tsconfig.dev.json && tsc -p tsconfig.esm.dev.json && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
122
122
  "format": "prettier --write --ignore-unknown \"src/**/*\" && pnpm lint",
@@ -1,87 +0,0 @@
1
- import { concat, of, timer } from 'rxjs';
2
- import { catchError, debounce, filter, groupBy, mergeMap, switchMap, } from 'rxjs/operators';
3
- import { getIsAccountingClassesEnabled } from '../../entity/tenant/tenantSelector';
4
- import { getTransactionWithCOT, getTransactionWithCOTFromRecommendations, } from '../../entity/transaction/transactionHelper';
5
- import { createZeniAPIStatus, isSuccessResponse } from '../../responsePayload';
6
- import { getUncategorizedAccounts } from '../accountList/accountListSelector';
7
- import { markCategoryClassRecommendationsCompletedForCategorization, markCategoryClassRecommendationsFailureForCategorization, markCategoryClassRecommendationsInProgressForCategorization, setEntityRecommendationForLineIdsForCategorization, } from '../expenseAutomationView/reducers/transactionsViewReducer';
8
- import { markCategoryClassRecommendationsCompletedForTransactionDetail, markCategoryClassRecommendationsFailureForTransactionDetail, markCategoryClassRecommendationsInProgressForTransactionDetail, setEntityRecommendationForLineIdsForTransactionDetail, } from '../transactionDetail/transactionDetailReducer';
9
- import { buildRecommendationUrl, getRecommendationByLineIdWithCOTFromRecommendationPayloadWithCOT, } from './recommendationHelper';
10
- import { fetchEntityRecommendationsForLineUpdate } from './recommendationReducer';
11
- // Close the per-target groupBy bucket after this much idle time so inactive
12
- // groups don't accumulate forever (each group holds a Subject + a chain of
13
- // active subscribers; without a duration selector groupBy retains them for
14
- // the lifetime of the source observable, which is the lifetime of the app).
15
- // Picked at 60s to leave a generous window for re-fetches on the same
16
- // payee/transaction/line target while still bounding memory.
17
- const GROUP_INACTIVITY_TIMEOUT_MS = 60000;
18
- // Build the groupBy key. Same flow + same transaction + same line set
19
- // share a target so switchMap can cancel an in-flight prior fetch. Use
20
- // NUL (\u0000) as separator because it can never appear in transaction
21
- // or line ids (vs the `|` used in an earlier WIP which collides with
22
- // pipe-delimited synthetic ids).
23
- const SEPARATOR = '\u0000';
24
- const toGroupKey = (flowType, transactionId, lineIds) => `${flowType}${SEPARATOR}${transactionId}${SEPARATOR}${[...lineIds]
25
- .sort((a, b) => a.localeCompare(b))
26
- .join(SEPARATOR)}`;
27
- // Targeted recommendations fetch that drives the per-line skeleton, the
28
- // list-page row-checkbox uncheck/recheck, and the page-level Save
29
- // disable.
30
- //
31
- // Concurrency model:
32
- // - groupBy by (flowType, transactionId, sorted lineIds) so distinct
33
- // targets run in parallel.
34
- // - inside each group, switchMap so a re-fetch on the SAME target
35
- // cancels any prior in-flight request for that target.
36
- // - groupBy duration selector closes idle groups to bound memory.
37
- export const fetchEntityRecommendationsForLineUpdateEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchEntityRecommendationsForLineUpdate.match), groupBy((action) => toGroupKey(action.payload.flowType, action.payload.transactionDetails.transactionId.id, action.payload.transactionDetails.lineIds), undefined, (group$) => group$.pipe(debounce(() => timer(GROUP_INACTIVITY_TIMEOUT_MS)))), mergeMap((group$) => group$.pipe(switchMap((action) => {
38
- const payload = action.payload;
39
- const { transactionId, transaction, lineIds } = payload.transactionDetails;
40
- const { entity, amount, isFetchCOT, isUncategorizedExpenseCategoryEnabled, } = payload;
41
- // Synchronously emit the start arm so the per-line skeleton +
42
- // row uncheck happen before the HTTP request begins. The
43
- // discriminated-union payload narrows `payload.selectedTab` to
44
- // a non-optional `TransactionsTab` inside the `'categorization'`
45
- // branch, so no defensive fallthrough is needed.
46
- const startAction = payload.flowType === 'categorization'
47
- ? markCategoryClassRecommendationsInProgressForCategorization(payload.selectedTab, transactionId, lineIds)
48
- : markCategoryClassRecommendationsInProgressForTransactionDetail(transactionId, lineIds);
49
- const url = buildRecommendationUrl(zeniAPI.apiEndPoints.accountMicroServiceBaseUrl, entity, amount, payload.transactionDetails, isFetchCOT === true);
50
- const httpStream$ = zeniAPI
51
- .getJSON(url)
52
- .pipe(mergeMap((response) => {
53
- if (!isSuccessResponse(response) || response.data == null) {
54
- return of(payload.flowType === 'categorization'
55
- ? markCategoryClassRecommendationsFailureForCategorization(payload.selectedTab, transactionId, lineIds, response.status)
56
- : markCategoryClassRecommendationsFailureForTransactionDetail(transactionId, lineIds, response.status));
57
- }
58
- const recommendationWithCOTByLineId = getRecommendationByLineIdWithCOTFromRecommendationPayloadWithCOT(response.data.recommendations, lineIds);
59
- // HTTP 200 with no per-line recommendations: NOT an error.
60
- // Flip lines to Completed so the skeleton resolves and
61
- // downstream UI can treat this as "we tried, nothing to
62
- // apply".
63
- if (recommendationWithCOTByLineId == null) {
64
- return of(payload.flowType === 'categorization'
65
- ? markCategoryClassRecommendationsCompletedForCategorization(payload.selectedTab, transactionId, lineIds)
66
- : markCategoryClassRecommendationsCompletedForTransactionDetail(transactionId, lineIds));
67
- }
68
- const transactionWithCOT = isFetchCOT === true
69
- ? getTransactionWithCOTFromRecommendations(transaction, recommendationWithCOTByLineId)
70
- : getTransactionWithCOT(transaction);
71
- const uncategorizedIncomeExpense = getUncategorizedAccounts(state$.value.accountState, state$.value.accountListState, 'accountList');
72
- if (payload.flowType === 'categorization') {
73
- return of(setEntityRecommendationForLineIdsForCategorization(payload.selectedTab, transactionId, transactionWithCOT, lineIds, entity, amount, recommendationWithCOTByLineId, uncategorizedIncomeExpense, isUncategorizedExpenseCategoryEnabled, getIsAccountingClassesEnabled(state$.value)));
74
- }
75
- return of(setEntityRecommendationForLineIdsForTransactionDetail(transactionId, transactionWithCOT, lineIds, entity, amount, recommendationWithCOTByLineId, uncategorizedIncomeExpense));
76
- }), catchError((error) => {
77
- const errorMessage = 'fetchEntityRecommendationsForLineUpdate failed: ' +
78
- (error instanceof Error
79
- ? error.message
80
- : JSON.stringify(error));
81
- const status = createZeniAPIStatus('Unexpected Error', errorMessage);
82
- return of(payload.flowType === 'categorization'
83
- ? markCategoryClassRecommendationsFailureForCategorization(payload.selectedTab, transactionId, lineIds, status)
84
- : markCategoryClassRecommendationsFailureForTransactionDetail(transactionId, lineIds, status));
85
- }));
86
- return concat(of(startAction), httpStream$);
87
- }))));
@@ -1,9 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { RootState } from '../../reducer';
4
- import { ZeniAPI } from '../../zeniAPI';
5
- import { markCategoryClassRecommendationsCompletedForCategorization, markCategoryClassRecommendationsFailureForCategorization, markCategoryClassRecommendationsInProgressForCategorization, setEntityRecommendationForLineIdsForCategorization } from '../expenseAutomationView/reducers/transactionsViewReducer';
6
- import { markCategoryClassRecommendationsCompletedForTransactionDetail, markCategoryClassRecommendationsFailureForTransactionDetail, markCategoryClassRecommendationsInProgressForTransactionDetail, setEntityRecommendationForLineIdsForTransactionDetail } from '../transactionDetail/transactionDetailReducer';
7
- import { fetchEntityRecommendationsForLineUpdate } from './recommendationReducer';
8
- export type ActionType = ReturnType<typeof fetchEntityRecommendationsForLineUpdate> | ReturnType<typeof markCategoryClassRecommendationsInProgressForCategorization> | ReturnType<typeof markCategoryClassRecommendationsCompletedForCategorization> | ReturnType<typeof markCategoryClassRecommendationsFailureForCategorization> | ReturnType<typeof markCategoryClassRecommendationsInProgressForTransactionDetail> | ReturnType<typeof markCategoryClassRecommendationsCompletedForTransactionDetail> | ReturnType<typeof markCategoryClassRecommendationsFailureForTransactionDetail> | ReturnType<typeof setEntityRecommendationForLineIdsForCategorization> | ReturnType<typeof setEntityRecommendationForLineIdsForTransactionDetail>;
9
- export declare const fetchEntityRecommendationsForLineUpdateEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;