@zeniai/client-epic-state 5.0.74 → 5.0.75

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 (34) hide show
  1. package/lib/epic.d.ts +2 -1
  2. package/lib/epic.js +2 -1
  3. package/lib/esm/epic.js +2 -1
  4. package/lib/esm/index.js +6 -6
  5. package/lib/esm/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.js +21 -1
  6. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +117 -14
  7. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +58 -0
  8. package/lib/esm/view/recommendation/fetchEntityRecommendationsForLineUpdateEpic.js +87 -0
  9. package/lib/esm/view/recommendation/recommendationHelper.js +29 -0
  10. package/lib/esm/view/recommendation/recommendationReducer.js +26 -1
  11. package/lib/esm/view/transactionDetail/transactionDetailReducer.js +121 -6
  12. package/lib/esm/view/transactionDetail/transactionDetailSelector.js +22 -0
  13. package/lib/index.d.ts +7 -6
  14. package/lib/index.js +35 -32
  15. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -0
  16. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.js +23 -2
  17. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +14 -1
  18. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +117 -14
  19. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +2 -0
  20. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.d.ts +3 -0
  21. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +60 -1
  22. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +1 -0
  23. package/lib/view/recommendation/fetchEntityRecommendationsForLineUpdateEpic.d.ts +9 -0
  24. package/lib/view/recommendation/fetchEntityRecommendationsForLineUpdateEpic.js +91 -0
  25. package/lib/view/recommendation/recommendationHelper.d.ts +9 -0
  26. package/lib/view/recommendation/recommendationHelper.js +31 -1
  27. package/lib/view/recommendation/recommendationReducer.d.ts +20 -1
  28. package/lib/view/recommendation/recommendationReducer.js +27 -2
  29. package/lib/view/transactionDetail/transactionDetailReducer.d.ts +11 -1
  30. package/lib/view/transactionDetail/transactionDetailReducer.js +122 -7
  31. package/lib/view/transactionDetail/transactionDetailSelector.d.ts +2 -0
  32. package/lib/view/transactionDetail/transactionDetailSelector.js +24 -1
  33. package/lib/view/transactionDetail/transactionDetailTypes.d.ts +1 -0
  34. package/package.json +1 -1
@@ -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.uploadTransactionCategorizationReceiptSuccess = exports.updateTransactionCategorizationUploadReceiptState = exports.backgroundRefetchReviewTab = exports.syncTransactionCategorizationFromDetailSave = exports.updateSelectedTransactionId = exports.setEntityRecommendationForLineIdsForCategorization = exports.clearExpenseAutomationTransactionsView = exports.clearExpenseAutomationTransactionsViewPerTabView = exports.updateSelectedCheckboxTransactionIds = exports.fetchTransactionCategorizationView = exports.resetOtherTabsFetchState = exports.fetchTransactionCategorizationSuccess = exports.updateParentTotalCountForTab = exports.updateTotalCountForTransactionCategorization = exports.setAllItemsToCategoryClassInLocalDataForCategorization = exports.updateSelectedCustomerForTransaction = exports.updateSelectedVendorForTransaction = exports.updateStatusForTransactionNotMiscategorizedUpdateForCategorization = exports.markTransactionAsNotMiscategorized = exports.updateTransactionCategorizationSaveStatus = exports.updateTransactionCategorizationCompletedSubTab = exports.updateCurrentSelectedTransactionCategorizationTab = exports.updateTransactionCategorization = exports.saveTransactionCategorization = exports.fetchTransactionCategorizationFailure = exports.saveTransactionCategorizationLocalData = exports.initializeTransactionCategorizationViewLocalData = exports.updateTransactionFilters = exports.updateTransactionCategorizationUIState = exports.fetchTransactionCategorization = exports.initialState = exports.initialTransactionTabViewState = void 0;
7
+ exports.uploadTransactionCategorizationReceiptSuccess = exports.updateTransactionCategorizationUploadReceiptState = exports.backgroundRefetchReviewTab = exports.syncTransactionCategorizationFromDetailSave = exports.updateSelectedTransactionId = exports.markCategoryClassRecommendationsFailureForCategorization = exports.markCategoryClassRecommendationsCompletedForCategorization = exports.markCategoryClassRecommendationsInProgressForCategorization = exports.setEntityRecommendationForLineIdsForCategorization = exports.clearExpenseAutomationTransactionsView = exports.clearExpenseAutomationTransactionsViewPerTabView = exports.updateSelectedCheckboxTransactionIds = exports.fetchTransactionCategorizationView = exports.resetOtherTabsFetchState = exports.fetchTransactionCategorizationSuccess = exports.updateParentTotalCountForTab = exports.updateTotalCountForTransactionCategorization = exports.setAllItemsToCategoryClassInLocalDataForCategorization = exports.updateSelectedCustomerForTransaction = exports.updateSelectedVendorForTransaction = exports.updateStatusForTransactionNotMiscategorizedUpdateForCategorization = exports.markTransactionAsNotMiscategorized = exports.updateTransactionCategorizationSaveStatus = exports.updateTransactionCategorizationCompletedSubTab = exports.updateCurrentSelectedTransactionCategorizationTab = exports.updateTransactionCategorization = exports.saveTransactionCategorization = exports.fetchTransactionCategorizationFailure = exports.saveTransactionCategorizationLocalData = exports.initializeTransactionCategorizationViewLocalData = exports.updateTransactionFilters = exports.updateTransactionCategorizationUIState = exports.fetchTransactionCategorization = exports.initialState = exports.initialTransactionTabViewState = void 0;
8
8
  const toolkit_1 = require("@reduxjs/toolkit");
9
9
  const get_1 = __importDefault(require("lodash/get"));
10
10
  const uniq_1 = __importDefault(require("lodash/uniq"));
@@ -437,12 +437,9 @@ const expenseAutomationTransactionsView = (0, toolkit_1.createSlice)({
437
437
  const selectedCheckBoxTransactionIds = draft.transactionCategorizationView[selectedTab]
438
438
  .selectedCheckBoxTransactionIds;
439
439
  if (selectedTransaction != null &&
440
- (0, transactionCategorizationLocalDataHelper_1.checkIfAllLineItemsAreCategoryClassFilled)(selectedTransaction, newTransactionLocalData, uncategorizedAccounts, isUncategorizedExpenseCategoryEnabled, isAccountingClassesEnabled) === true && // check if all line items are filled
441
- selectedCheckBoxTransactionIds.length < transactionCategorizationLocalDataHelper_1.MAX_SELECTION_LIMIT &&
442
- selectedCheckBoxTransactionIds.includes(transactionId) === false) {
440
+ (0, transactionCategorizationLocalDataHelper_1.shouldAutoSelectAndAdd)(selectedTransaction, newTransactionLocalData, selectedCheckBoxTransactionIds, uncategorizedAccounts, isUncategorizedExpenseCategoryEnabled, isAccountingClassesEnabled)) {
443
441
  draft.transactionCategorizationView[selectedTab].selectedCheckBoxTransactionIds = [
444
- ...draft.transactionCategorizationView[selectedTab]
445
- .selectedCheckBoxTransactionIds,
442
+ ...selectedCheckBoxTransactionIds,
446
443
  transactionId,
447
444
  ];
448
445
  }
@@ -525,9 +522,26 @@ const expenseAutomationTransactionsView = (0, toolkit_1.createSlice)({
525
522
  const transactionLocalData = (0, get_1.default)(draft.transactionCategorizationView[selectedTab]
526
523
  .transactionReviewLocalDataById, transactionId.id, undefined);
527
524
  if (transactionLocalData != null) {
525
+ const newLocalData = (0, transactionCategorizationLocalDataHelper_1.setEntityRecommendationForLineIdInLocalData)(draft.transactionCategorizationView[selectedTab], transaction, transactionLocalData.transactionReviewLocalData, entity, lineIds, uncategorizedAccounts, action.payload.recommendationWithCOTByLineId, isUncategorizedExpenseCategoryEnabled, isAccountingClassesEnabled);
526
+ // Release the per-line fetch flag for every line this fetch
527
+ // covered. Done in-place on the freshly returned local data
528
+ // (the helper produces a new mutable object), before we write
529
+ // it back to the draft.
530
+ lineIds.forEach((lineId) => {
531
+ const lineItem = newLocalData.lineItemById[lineId];
532
+ if (lineItem != null) {
533
+ newLocalData.lineItemById[lineId] = {
534
+ ...lineItem,
535
+ categoryClassRecommendationsFetchState: {
536
+ fetchState: 'Completed',
537
+ error: undefined,
538
+ },
539
+ };
540
+ }
541
+ });
528
542
  draft.transactionCategorizationView[selectedTab].transactionReviewLocalDataById[transaction.id] = {
529
543
  transactionId: transaction.id,
530
- transactionReviewLocalData: (0, transactionCategorizationLocalDataHelper_1.setEntityRecommendationForLineIdInLocalData)(draft.transactionCategorizationView[selectedTab], transaction, transactionLocalData.transactionReviewLocalData, entity, lineIds, uncategorizedAccounts, action.payload.recommendationWithCOTByLineId, isUncategorizedExpenseCategoryEnabled, isAccountingClassesEnabled),
544
+ transactionReviewLocalData: newLocalData,
531
545
  };
532
546
  // Mark transaction as dirty (autofill happened)
533
547
  if (!draft.transactionCategorizationView[selectedTab].transactionIdsWithUnsavedData.includes(transaction.id)) {
@@ -540,6 +554,99 @@ const expenseAutomationTransactionsView = (0, toolkit_1.createSlice)({
540
554
  }
541
555
  },
542
556
  },
557
+ // Start arm of the line-update recommendations fetch. Flips covered
558
+ // lines to In-Progress AND removes the transaction from
559
+ // selectedCheckBoxTransactionIds — the row is unchecked + disabled
560
+ // until either the success arm (recheck if limit allows) or the
561
+ // failure arm releases the per-line flag.
562
+ markCategoryClassRecommendationsInProgressForCategorization: {
563
+ reducer(draft, action) {
564
+ const { selectedTab, transactionId, lineIds } = action.payload;
565
+ const tab = draft.transactionCategorizationView[selectedTab];
566
+ const transactionLocalData = (0, get_1.default)(tab.transactionReviewLocalDataById, transactionId.id, undefined);
567
+ if (transactionLocalData != null) {
568
+ lineIds.forEach((lineId) => {
569
+ const lineItem = transactionLocalData.transactionReviewLocalData.lineItemById[lineId];
570
+ if (lineItem != null) {
571
+ transactionLocalData.transactionReviewLocalData.lineItemById[lineId] = {
572
+ ...lineItem,
573
+ categoryClassRecommendationsFetchState: {
574
+ fetchState: 'In-Progress',
575
+ error: undefined,
576
+ },
577
+ };
578
+ }
579
+ });
580
+ }
581
+ // Uncheck on fetch start: the row's existing category/class are
582
+ // stale after a payee change, so we drop the auto-selection until
583
+ // fresh recommendations land.
584
+ if (tab.selectedCheckBoxTransactionIds.includes(transactionId.id)) {
585
+ tab.selectedCheckBoxTransactionIds =
586
+ tab.selectedCheckBoxTransactionIds.filter((id) => id !== transactionId.id);
587
+ }
588
+ },
589
+ prepare(selectedTab, transactionId, lineIds) {
590
+ return { payload: { selectedTab, transactionId, lineIds } };
591
+ },
592
+ },
593
+ // Completed arm. Used by the epic when the HTTP call succeeds but the
594
+ // server returned no per-line recommendations — we still need to
595
+ // release the In-Progress flag so the skeleton resolves. Successful
596
+ // responses with recommendations go through
597
+ // setEntityRecommendationForLineIdsForCategorization instead (which
598
+ // also flips the lines to Completed).
599
+ markCategoryClassRecommendationsCompletedForCategorization: {
600
+ reducer(draft, action) {
601
+ const { selectedTab, transactionId, lineIds } = action.payload;
602
+ const transactionLocalData = (0, get_1.default)(draft.transactionCategorizationView[selectedTab]
603
+ .transactionReviewLocalDataById, transactionId.id, undefined);
604
+ if (transactionLocalData != null) {
605
+ lineIds.forEach((lineId) => {
606
+ const lineItem = transactionLocalData.transactionReviewLocalData.lineItemById[lineId];
607
+ if (lineItem != null) {
608
+ transactionLocalData.transactionReviewLocalData.lineItemById[lineId] = {
609
+ ...lineItem,
610
+ categoryClassRecommendationsFetchState: {
611
+ fetchState: 'Completed',
612
+ error: undefined,
613
+ },
614
+ };
615
+ }
616
+ });
617
+ }
618
+ },
619
+ prepare(selectedTab, transactionId, lineIds) {
620
+ return { payload: { selectedTab, transactionId, lineIds } };
621
+ },
622
+ },
623
+ // Failure arm. Flips covered lines to Error so the skeleton resolves
624
+ // and downstream UI can react to the failure. The transaction stays
625
+ // unchecked from the start-arm action.
626
+ markCategoryClassRecommendationsFailureForCategorization: {
627
+ reducer(draft, action) {
628
+ const { selectedTab, transactionId, lineIds, error } = action.payload;
629
+ const transactionLocalData = (0, get_1.default)(draft.transactionCategorizationView[selectedTab]
630
+ .transactionReviewLocalDataById, transactionId.id, undefined);
631
+ if (transactionLocalData != null) {
632
+ lineIds.forEach((lineId) => {
633
+ const lineItem = transactionLocalData.transactionReviewLocalData.lineItemById[lineId];
634
+ if (lineItem != null) {
635
+ transactionLocalData.transactionReviewLocalData.lineItemById[lineId] = {
636
+ ...lineItem,
637
+ categoryClassRecommendationsFetchState: {
638
+ fetchState: 'Error',
639
+ error,
640
+ },
641
+ };
642
+ }
643
+ });
644
+ }
645
+ },
646
+ prepare(selectedTab, transactionId, lineIds, error) {
647
+ return { payload: { selectedTab, transactionId, lineIds, error } };
648
+ },
649
+ },
543
650
  fetchTransactionCategorizationSuccess(draft, action) {
544
651
  const { selectedTab, refreshViewInBackground } = action.payload;
545
652
  if (draft.transactionCategorizationView[selectedTab].fetchState ===
@@ -635,9 +742,7 @@ const expenseAutomationTransactionsView = (0, toolkit_1.createSlice)({
635
742
  .selectedCheckBoxTransactionIds;
636
743
  if (newTransactionLocalData.customer != null &&
637
744
  newTransactionLocalData.customer.id != null &&
638
- (0, transactionCategorizationLocalDataHelper_1.checkIfAllLineItemsAreCategoryClassFilled)(selectedTransaction, newTransactionLocalData, uncategorizedAccounts, isUncategorizedExpenseCategoryEnabled, isAccountingClassesEnabled) === true && // check if all line items are filled
639
- selectedCheckBoxTransactionIds.length < transactionCategorizationLocalDataHelper_1.MAX_SELECTION_LIMIT &&
640
- selectedCheckBoxTransactionIds.includes(transactionId) === false) {
745
+ (0, transactionCategorizationLocalDataHelper_1.shouldAutoSelectAndAdd)(selectedTransaction, newTransactionLocalData, selectedCheckBoxTransactionIds, uncategorizedAccounts, isUncategorizedExpenseCategoryEnabled, isAccountingClassesEnabled)) {
641
746
  draft.transactionCategorizationView[selectedTab].selectedCheckBoxTransactionIds = [
642
747
  ...selectedCheckBoxTransactionIds,
643
748
  transactionId,
@@ -711,9 +816,7 @@ const expenseAutomationTransactionsView = (0, toolkit_1.createSlice)({
711
816
  .selectedCheckBoxTransactionIds;
712
817
  if (newTransactionLocalData.vendor != null &&
713
818
  newTransactionLocalData.vendor.id != null &&
714
- (0, transactionCategorizationLocalDataHelper_1.checkIfAllLineItemsAreCategoryClassFilled)(selectedTransaction, newTransactionLocalData, uncategorizedAccounts, isUncategorizedExpenseCategoryEnabled, isAccountingClassesEnabled) === true && // check if all line items are filled
715
- selectedCheckBoxTransactionIds.length < transactionCategorizationLocalDataHelper_1.MAX_SELECTION_LIMIT &&
716
- selectedCheckBoxTransactionIds.includes(transactionId) === false) {
819
+ (0, transactionCategorizationLocalDataHelper_1.shouldAutoSelectAndAdd)(selectedTransaction, newTransactionLocalData, selectedCheckBoxTransactionIds, uncategorizedAccounts, isUncategorizedExpenseCategoryEnabled, isAccountingClassesEnabled)) {
717
820
  draft.transactionCategorizationView[selectedTab].selectedCheckBoxTransactionIds = [
718
821
  ...selectedCheckBoxTransactionIds,
719
822
  transactionId,
@@ -946,5 +1049,5 @@ const expenseAutomationTransactionsView = (0, toolkit_1.createSlice)({
946
1049
  },
947
1050
  },
948
1051
  });
949
- _a = expenseAutomationTransactionsView.actions, exports.fetchTransactionCategorization = _a.fetchTransactionCategorization, exports.updateTransactionCategorizationUIState = _a.updateTransactionCategorizationUIState, exports.updateTransactionFilters = _a.updateTransactionFilters, exports.initializeTransactionCategorizationViewLocalData = _a.initializeTransactionCategorizationViewLocalData, exports.saveTransactionCategorizationLocalData = _a.saveTransactionCategorizationLocalData, exports.fetchTransactionCategorizationFailure = _a.fetchTransactionCategorizationFailure, exports.saveTransactionCategorization = _a.saveTransactionCategorization, exports.updateTransactionCategorization = _a.updateTransactionCategorization, exports.updateCurrentSelectedTransactionCategorizationTab = _a.updateCurrentSelectedTransactionCategorizationTab, exports.updateTransactionCategorizationCompletedSubTab = _a.updateTransactionCategorizationCompletedSubTab, exports.updateTransactionCategorizationSaveStatus = _a.updateTransactionCategorizationSaveStatus, exports.markTransactionAsNotMiscategorized = _a.markTransactionAsNotMiscategorized, exports.updateStatusForTransactionNotMiscategorizedUpdateForCategorization = _a.updateStatusForTransactionNotMiscategorizedUpdateForCategorization, exports.updateSelectedVendorForTransaction = _a.updateSelectedVendorForTransaction, exports.updateSelectedCustomerForTransaction = _a.updateSelectedCustomerForTransaction, exports.setAllItemsToCategoryClassInLocalDataForCategorization = _a.setAllItemsToCategoryClassInLocalDataForCategorization, exports.updateTotalCountForTransactionCategorization = _a.updateTotalCountForTransactionCategorization, exports.updateParentTotalCountForTab = _a.updateParentTotalCountForTab, exports.fetchTransactionCategorizationSuccess = _a.fetchTransactionCategorizationSuccess, exports.resetOtherTabsFetchState = _a.resetOtherTabsFetchState, exports.fetchTransactionCategorizationView = _a.fetchTransactionCategorizationView, exports.updateSelectedCheckboxTransactionIds = _a.updateSelectedCheckboxTransactionIds, exports.clearExpenseAutomationTransactionsViewPerTabView = _a.clearExpenseAutomationTransactionsViewPerTabView, exports.clearExpenseAutomationTransactionsView = _a.clearExpenseAutomationTransactionsView, exports.setEntityRecommendationForLineIdsForCategorization = _a.setEntityRecommendationForLineIdsForCategorization, exports.updateSelectedTransactionId = _a.updateSelectedTransactionId, exports.syncTransactionCategorizationFromDetailSave = _a.syncTransactionCategorizationFromDetailSave, exports.backgroundRefetchReviewTab = _a.backgroundRefetchReviewTab, exports.updateTransactionCategorizationUploadReceiptState = _a.updateTransactionCategorizationUploadReceiptState, exports.uploadTransactionCategorizationReceiptSuccess = _a.uploadTransactionCategorizationReceiptSuccess;
1052
+ _a = expenseAutomationTransactionsView.actions, exports.fetchTransactionCategorization = _a.fetchTransactionCategorization, exports.updateTransactionCategorizationUIState = _a.updateTransactionCategorizationUIState, exports.updateTransactionFilters = _a.updateTransactionFilters, exports.initializeTransactionCategorizationViewLocalData = _a.initializeTransactionCategorizationViewLocalData, exports.saveTransactionCategorizationLocalData = _a.saveTransactionCategorizationLocalData, exports.fetchTransactionCategorizationFailure = _a.fetchTransactionCategorizationFailure, exports.saveTransactionCategorization = _a.saveTransactionCategorization, exports.updateTransactionCategorization = _a.updateTransactionCategorization, exports.updateCurrentSelectedTransactionCategorizationTab = _a.updateCurrentSelectedTransactionCategorizationTab, exports.updateTransactionCategorizationCompletedSubTab = _a.updateTransactionCategorizationCompletedSubTab, exports.updateTransactionCategorizationSaveStatus = _a.updateTransactionCategorizationSaveStatus, exports.markTransactionAsNotMiscategorized = _a.markTransactionAsNotMiscategorized, exports.updateStatusForTransactionNotMiscategorizedUpdateForCategorization = _a.updateStatusForTransactionNotMiscategorizedUpdateForCategorization, exports.updateSelectedVendorForTransaction = _a.updateSelectedVendorForTransaction, exports.updateSelectedCustomerForTransaction = _a.updateSelectedCustomerForTransaction, exports.setAllItemsToCategoryClassInLocalDataForCategorization = _a.setAllItemsToCategoryClassInLocalDataForCategorization, exports.updateTotalCountForTransactionCategorization = _a.updateTotalCountForTransactionCategorization, exports.updateParentTotalCountForTab = _a.updateParentTotalCountForTab, exports.fetchTransactionCategorizationSuccess = _a.fetchTransactionCategorizationSuccess, exports.resetOtherTabsFetchState = _a.resetOtherTabsFetchState, exports.fetchTransactionCategorizationView = _a.fetchTransactionCategorizationView, exports.updateSelectedCheckboxTransactionIds = _a.updateSelectedCheckboxTransactionIds, exports.clearExpenseAutomationTransactionsViewPerTabView = _a.clearExpenseAutomationTransactionsViewPerTabView, exports.clearExpenseAutomationTransactionsView = _a.clearExpenseAutomationTransactionsView, exports.setEntityRecommendationForLineIdsForCategorization = _a.setEntityRecommendationForLineIdsForCategorization, exports.markCategoryClassRecommendationsInProgressForCategorization = _a.markCategoryClassRecommendationsInProgressForCategorization, exports.markCategoryClassRecommendationsCompletedForCategorization = _a.markCategoryClassRecommendationsCompletedForCategorization, exports.markCategoryClassRecommendationsFailureForCategorization = _a.markCategoryClassRecommendationsFailureForCategorization, exports.updateSelectedTransactionId = _a.updateSelectedTransactionId, exports.syncTransactionCategorizationFromDetailSave = _a.syncTransactionCategorizationFromDetailSave, exports.backgroundRefetchReviewTab = _a.backgroundRefetchReviewTab, exports.updateTransactionCategorizationUploadReceiptState = _a.updateTransactionCategorizationUploadReceiptState, exports.uploadTransactionCategorizationReceiptSuccess = _a.uploadTransactionCategorizationReceiptSuccess;
950
1053
  exports.default = expenseAutomationTransactionsView.reducer;
@@ -20,6 +20,8 @@ export interface ExpenseAutomationTransactionViewSelector extends SelectorView {
20
20
  classList: ClassBase[];
21
21
  completionStatus: CompletionStatusType;
22
22
  fetchStateByTransactionTabs: Record<TransactionsTab, FetchStateAndError>;
23
+ hasInFlightCategoryClassRecommendations: boolean;
24
+ inFlightCategoryClassRecommendationsByTransactionId: Record<ID, boolean>;
23
25
  isAccountingProjectsEnabled: boolean;
24
26
  markAsNotMiscategorizedStatus: FetchStateAndError;
25
27
  /**
@@ -1,6 +1,9 @@
1
+ import { ID } from '../../../commonStateTypes/common';
1
2
  import { TransactionWithCOT } from '../../../entity/transaction/stateTypes/transaction';
2
3
  import { RootState } from '../../../reducer';
3
4
  import { TransactionView } from '../transactionFilterHelpers';
4
5
  import { ExpenseAutomationTransactionViewSelector, TransactionReviewLocalDataSelectorView } from '../selectorTypes/transactionsViewSelectorTypes';
6
+ export declare const getCategorizationInFlightRecommendationsByTransactionId: (state: RootState) => Record<ID, boolean>;
7
+ export declare const getCategorizationHasInFlightRecommendations: (state: RootState) => boolean;
5
8
  export declare const toTransactionView: (transaction: TransactionWithCOT, transactionLocalData?: TransactionReviewLocalDataSelectorView) => TransactionView;
6
9
  export declare function getExpenseAutomationTransactionView(state: RootState): ExpenseAutomationTransactionViewSelector;
@@ -3,8 +3,9 @@ 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.toTransactionView = void 0;
6
+ exports.toTransactionView = exports.getCategorizationHasInFlightRecommendations = exports.getCategorizationInFlightRecommendationsByTransactionId = void 0;
7
7
  exports.getExpenseAutomationTransactionView = getExpenseAutomationTransactionView;
8
+ const toolkit_1 = require("@reduxjs/toolkit");
8
9
  const omit_1 = __importDefault(require("lodash/omit"));
9
10
  const reduceFetchState_1 = require("../../../commonStateTypes/reduceFetchState");
10
11
  const timePeriod_1 = require("../../../commonStateTypes/timePeriod");
@@ -16,6 +17,60 @@ const accountListSelector_1 = require("../../accountList/accountListSelector");
16
17
  const classListSelector_1 = require("../../classList/classListSelector");
17
18
  const projectListSelector_1 = require("../../projectList/projectListSelector");
18
19
  const expenseAutomationViewSelectorTypes_1 = require("../selectorTypes/expenseAutomationViewSelectorTypes");
20
+ // Walks the tab's transactionReviewLocalDataById map and returns
21
+ // `{ [transactionId]: true }` for every transaction that has at least
22
+ // one line whose targeted-fetch is In-Progress. Pulled out as a plain
23
+ // function so each tab's createSelector can share it.
24
+ const computeCategorizationInFlightRecommendations = (transactionReviewLocalDataById) => {
25
+ const result = {};
26
+ if (transactionReviewLocalDataById == null) {
27
+ return result;
28
+ }
29
+ for (const [transactionId, data] of Object.entries(transactionReviewLocalDataById)) {
30
+ const lineItems = Object.values(data.transactionReviewLocalData.lineItemById);
31
+ if (lineItems.some((lineItem) => lineItem.categoryClassRecommendationsFetchState?.fetchState ===
32
+ 'In-Progress')) {
33
+ result[transactionId] = true;
34
+ }
35
+ }
36
+ return result;
37
+ };
38
+ // Per-tab createSelector instances. Each one is memoized on its OWN tab's
39
+ // transactionReviewLocalDataById reference. Switching tabs A->B->A no
40
+ // longer busts the memo for tab A — the dispatcher below just returns
41
+ // whichever per-tab selector matches the active tab, and reselect keeps
42
+ // the prior result alive as long as the underlying slice ref is stable.
43
+ const getReviewInFlightRecommendationsByTransactionId = (0, toolkit_1.createSelector)((state) => state.expenseAutomationTransactionsViewState.transactionCategorizationView
44
+ .review.transactionReviewLocalDataById, computeCategorizationInFlightRecommendations);
45
+ const getAutoCategorizedInFlightRecommendationsByTransactionId = (0, toolkit_1.createSelector)((state) => state.expenseAutomationTransactionsViewState.transactionCategorizationView
46
+ .autoCategorized.transactionReviewLocalDataById, computeCategorizationInFlightRecommendations);
47
+ // Per-transaction "any line is fetching category/class recommendations?"
48
+ // map for the active categorization tab. Dispatches to the per-tab
49
+ // memoized selector above so steady state (no fetches in flight)
50
+ // recomputes only when the active tab's local data changes; tab switches
51
+ // are O(1) cache lookups.
52
+ //
53
+ // `default` guards against the union "lying" at runtime: `TransactionsTab`
54
+ // is produced via `stringToUnion`, which falls back to `s as StringUnion`
55
+ // for unrecognized strings, so an unexpected value can land in state. The
56
+ // downstream `getCategorizationHasInFlightRecommendations` calls
57
+ // `Object.keys` on this result, so we must always return an object.
58
+ const getCategorizationInFlightRecommendationsByTransactionId = (state) => {
59
+ const tab = state.expenseAutomationTransactionsViewState
60
+ .selectedTransactionCategorizationTab;
61
+ switch (tab) {
62
+ case 'review':
63
+ return getReviewInFlightRecommendationsByTransactionId(state);
64
+ case 'autoCategorized':
65
+ return getAutoCategorizedInFlightRecommendationsByTransactionId(state);
66
+ default:
67
+ return {};
68
+ }
69
+ };
70
+ exports.getCategorizationInFlightRecommendationsByTransactionId = getCategorizationInFlightRecommendationsByTransactionId;
71
+ // Page-level "any line on the active tab is in flight?" flag. Drives the
72
+ // list-page Save disable.
73
+ exports.getCategorizationHasInFlightRecommendations = (0, toolkit_1.createSelector)(exports.getCategorizationInFlightRecommendationsByTransactionId, (inFlightByTransactionId) => Object.keys(inFlightByTransactionId).length > 0);
19
74
  const toTransactionView = (transaction, transactionLocalData) => {
20
75
  return {
21
76
  id: transaction.id,
@@ -168,6 +223,8 @@ function getExpenseAutomationTransactionView(state) {
168
223
  : [];
169
224
  const transactionCompletionStatus = allSteps.find((step) => step.step === 'transaction_categorization')?.completionStatus;
170
225
  const completionStatus = transactionCompletionStatus ?? 'incomplete';
226
+ const inFlightCategoryClassRecommendationsByTransactionId = (0, exports.getCategorizationInFlightRecommendationsByTransactionId)(state);
227
+ const hasInFlightCategoryClassRecommendations = (0, exports.getCategorizationHasInFlightRecommendations)(state);
171
228
  return {
172
229
  version: 0,
173
230
  fetchState: fetchStatus.fetchState,
@@ -181,6 +238,8 @@ function getExpenseAutomationTransactionView(state) {
181
238
  classList: allClasses,
182
239
  accountsHierarchyList,
183
240
  classHierarchyList,
241
+ hasInFlightCategoryClassRecommendations,
242
+ inFlightCategoryClassRecommendationsByTransactionId,
184
243
  isAccountingProjectsEnabled,
185
244
  projectList,
186
245
  transactionLocalData: filteredTransactionLocalData,
@@ -49,6 +49,7 @@ export interface TransactionCategorizationLineItemData extends TransactionLineBa
49
49
  transactionId: ID;
50
50
  account?: AccountBase;
51
51
  categorizationStatus?: CategorizationStatusType;
52
+ categoryClassRecommendationsFetchState?: FetchStateAndError;
52
53
  class?: ClassBase;
53
54
  customer?: CustomerBase;
54
55
  item?: ProductOrService;
@@ -0,0 +1,9 @@
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>;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchEntityRecommendationsForLineUpdateEpic = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const tenantSelector_1 = require("../../entity/tenant/tenantSelector");
7
+ const transactionHelper_1 = require("../../entity/transaction/transactionHelper");
8
+ const responsePayload_1 = require("../../responsePayload");
9
+ const accountListSelector_1 = require("../accountList/accountListSelector");
10
+ const transactionsViewReducer_1 = require("../expenseAutomationView/reducers/transactionsViewReducer");
11
+ const transactionDetailReducer_1 = require("../transactionDetail/transactionDetailReducer");
12
+ const recommendationHelper_1 = require("./recommendationHelper");
13
+ const recommendationReducer_1 = require("./recommendationReducer");
14
+ // Close the per-target groupBy bucket after this much idle time so inactive
15
+ // groups don't accumulate forever (each group holds a Subject + a chain of
16
+ // active subscribers; without a duration selector groupBy retains them for
17
+ // the lifetime of the source observable, which is the lifetime of the app).
18
+ // Picked at 60s to leave a generous window for re-fetches on the same
19
+ // payee/transaction/line target while still bounding memory.
20
+ const GROUP_INACTIVITY_TIMEOUT_MS = 60000;
21
+ // Build the groupBy key. Same flow + same transaction + same line set
22
+ // share a target so switchMap can cancel an in-flight prior fetch. Use
23
+ // NUL (\u0000) as separator because it can never appear in transaction
24
+ // or line ids (vs the `|` used in an earlier WIP which collides with
25
+ // pipe-delimited synthetic ids).
26
+ const SEPARATOR = '\u0000';
27
+ const toGroupKey = (flowType, transactionId, lineIds) => `${flowType}${SEPARATOR}${transactionId}${SEPARATOR}${[...lineIds]
28
+ .sort((a, b) => a.localeCompare(b))
29
+ .join(SEPARATOR)}`;
30
+ // Targeted recommendations fetch that drives the per-line skeleton, the
31
+ // list-page row-checkbox uncheck/recheck, and the page-level Save
32
+ // disable.
33
+ //
34
+ // Concurrency model:
35
+ // - groupBy by (flowType, transactionId, sorted lineIds) so distinct
36
+ // targets run in parallel.
37
+ // - inside each group, switchMap so a re-fetch on the SAME target
38
+ // cancels any prior in-flight request for that target.
39
+ // - groupBy duration selector closes idle groups to bound memory.
40
+ const fetchEntityRecommendationsForLineUpdateEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(recommendationReducer_1.fetchEntityRecommendationsForLineUpdate.match), (0, operators_1.groupBy)((action) => toGroupKey(action.payload.flowType, action.payload.transactionDetails.transactionId.id, action.payload.transactionDetails.lineIds), undefined, (group$) => group$.pipe((0, operators_1.debounce)(() => (0, rxjs_1.timer)(GROUP_INACTIVITY_TIMEOUT_MS)))), (0, operators_1.mergeMap)((group$) => group$.pipe((0, operators_1.switchMap)((action) => {
41
+ const payload = action.payload;
42
+ const { transactionId, transaction, lineIds } = payload.transactionDetails;
43
+ const { entity, amount, isFetchCOT, isUncategorizedExpenseCategoryEnabled, } = payload;
44
+ // Synchronously emit the start arm so the per-line skeleton +
45
+ // row uncheck happen before the HTTP request begins. The
46
+ // discriminated-union payload narrows `payload.selectedTab` to
47
+ // a non-optional `TransactionsTab` inside the `'categorization'`
48
+ // branch, so no defensive fallthrough is needed.
49
+ const startAction = payload.flowType === 'categorization'
50
+ ? (0, transactionsViewReducer_1.markCategoryClassRecommendationsInProgressForCategorization)(payload.selectedTab, transactionId, lineIds)
51
+ : (0, transactionDetailReducer_1.markCategoryClassRecommendationsInProgressForTransactionDetail)(transactionId, lineIds);
52
+ const url = (0, recommendationHelper_1.buildRecommendationUrl)(zeniAPI.apiEndPoints.accountMicroServiceBaseUrl, entity, amount, payload.transactionDetails, isFetchCOT === true);
53
+ const httpStream$ = zeniAPI
54
+ .getJSON(url)
55
+ .pipe((0, operators_1.mergeMap)((response) => {
56
+ if (!(0, responsePayload_1.isSuccessResponse)(response) || response.data == null) {
57
+ return (0, rxjs_1.of)(payload.flowType === 'categorization'
58
+ ? (0, transactionsViewReducer_1.markCategoryClassRecommendationsFailureForCategorization)(payload.selectedTab, transactionId, lineIds, response.status)
59
+ : (0, transactionDetailReducer_1.markCategoryClassRecommendationsFailureForTransactionDetail)(transactionId, lineIds, response.status));
60
+ }
61
+ const recommendationWithCOTByLineId = (0, recommendationHelper_1.getRecommendationByLineIdWithCOTFromRecommendationPayloadWithCOT)(response.data.recommendations, lineIds);
62
+ // HTTP 200 with no per-line recommendations: NOT an error.
63
+ // Flip lines to Completed so the skeleton resolves and
64
+ // downstream UI can treat this as "we tried, nothing to
65
+ // apply".
66
+ if (recommendationWithCOTByLineId == null) {
67
+ return (0, rxjs_1.of)(payload.flowType === 'categorization'
68
+ ? (0, transactionsViewReducer_1.markCategoryClassRecommendationsCompletedForCategorization)(payload.selectedTab, transactionId, lineIds)
69
+ : (0, transactionDetailReducer_1.markCategoryClassRecommendationsCompletedForTransactionDetail)(transactionId, lineIds));
70
+ }
71
+ const transactionWithCOT = isFetchCOT === true
72
+ ? (0, transactionHelper_1.getTransactionWithCOTFromRecommendations)(transaction, recommendationWithCOTByLineId)
73
+ : (0, transactionHelper_1.getTransactionWithCOT)(transaction);
74
+ const uncategorizedIncomeExpense = (0, accountListSelector_1.getUncategorizedAccounts)(state$.value.accountState, state$.value.accountListState, 'accountList');
75
+ if (payload.flowType === 'categorization') {
76
+ return (0, rxjs_1.of)((0, transactionsViewReducer_1.setEntityRecommendationForLineIdsForCategorization)(payload.selectedTab, transactionId, transactionWithCOT, lineIds, entity, amount, recommendationWithCOTByLineId, uncategorizedIncomeExpense, isUncategorizedExpenseCategoryEnabled, (0, tenantSelector_1.getIsAccountingClassesEnabled)(state$.value)));
77
+ }
78
+ return (0, rxjs_1.of)((0, transactionDetailReducer_1.setEntityRecommendationForLineIdsForTransactionDetail)(transactionId, transactionWithCOT, lineIds, entity, amount, recommendationWithCOTByLineId, uncategorizedIncomeExpense));
79
+ }), (0, operators_1.catchError)((error) => {
80
+ const errorMessage = 'fetchEntityRecommendationsForLineUpdate failed: ' +
81
+ (error instanceof Error
82
+ ? error.message
83
+ : JSON.stringify(error));
84
+ const status = (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', errorMessage);
85
+ return (0, rxjs_1.of)(payload.flowType === 'categorization'
86
+ ? (0, transactionsViewReducer_1.markCategoryClassRecommendationsFailureForCategorization)(payload.selectedTab, transactionId, lineIds, status)
87
+ : (0, transactionDetailReducer_1.markCategoryClassRecommendationsFailureForTransactionDetail)(transactionId, lineIds, status));
88
+ }));
89
+ return (0, rxjs_1.concat)((0, rxjs_1.of)(startAction), httpStream$);
90
+ }))));
91
+ exports.fetchEntityRecommendationsForLineUpdateEpic = fetchEntityRecommendationsForLineUpdateEpic;
@@ -1,8 +1,17 @@
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';
4
5
  import { RecommendationByLineId, RecommendationWithCOTByLineId } from '../../entity/transaction/stateTypes/transaction';
6
+ import { SupportedTransaction } from '../../entity/transaction/transactionState';
5
7
  export declare const getRecommendationFromRecommendationPayload: (payload: RecommendationPayload[]) => Recommendation[] | undefined;
6
8
  export declare const getRecommendationByLineIdFromRecommendationPayload: (recommendationPayload: RecommendationPayload[], lineIds: ID[]) => RecommendationByLineId | undefined;
7
9
  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;
8
17
  export declare const getRecommendationByLineIdWithCOTFromRecommendationPayloadWithCOT: (recommendationPayload: RecommendationPayloadWithCOT[], lineIds: ID[]) => RecommendationWithCOTByLineId | undefined;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRecommendationByLineIdWithCOTFromRecommendationPayloadWithCOT = exports.getRecommendationWithCOTFromRecommendationPayloadWithCOT = exports.getRecommendationByLineIdFromRecommendationPayload = exports.getRecommendationFromRecommendationPayload = void 0;
3
+ exports.getRecommendationByLineIdWithCOTFromRecommendationPayloadWithCOT = exports.buildRecommendationUrl = 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");
5
6
  const getRecommendationFromRecommendationPayload = (payload) => {
6
7
  if (payload == null || payload.length === 0) {
7
8
  return undefined;
@@ -43,6 +44,35 @@ const getRecommendationWithCOTFromRecommendationPayloadWithCOT = (payload) => {
43
44
  return recommendations;
44
45
  };
45
46
  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;
46
76
  const getRecommendationByLineIdWithCOTFromRecommendationPayloadWithCOT = (recommendationPayload, lineIds) => {
47
77
  if (recommendationPayload.length === 0) {
48
78
  return undefined;
@@ -4,7 +4,26 @@ 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';
7
8
  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
+ });
8
27
  export declare const initialState: EntityRecommendationState;
9
28
  export declare const fetchEntityRecommendationsByTransactionId: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[entity: Entity, amount: number, transactionDetails: {
10
29
  lineIds: ID[];
@@ -22,7 +41,7 @@ export declare const fetchEntityRecommendationsByTransactionId: import("@reduxjs
22
41
  isTransactionCategorizationFlow: any;
23
42
  isFetchCOT: any;
24
43
  isUncategorizedExpenseCategoryEnabled: boolean | undefined;
25
- }, "recommendation/fetchEntityRecommendationsByTransactionId", never, never>, fetchRecommendationByEntityName: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[entityName: string, entityType: EntityType], {
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], {
26
45
  entityName: string;
27
46
  entityType: EntityType;
28
47
  }, "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.fetchEntityRecommendationsByTransactionId = exports.initialState = void 0;
4
+ exports.clearRecommendation = exports.indicateReadyToInitializeRecommendation = exports.updateRecommendationForEntityFailure = exports.updateRecommendationForEntity = exports.fetchRecommendationByEntityId = exports.fetchRecommendationByEntityName = exports.fetchEntityRecommendationsForLineUpdate = 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,6 +37,31 @@ 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
+ },
40
65
  fetchRecommendationByEntityName: {
41
66
  reducer(draft, action) {
42
67
  const { entityName, entityType } = action.payload;
@@ -115,7 +140,7 @@ const recommendation = (0, toolkit_1.createSlice)({
115
140
  },
116
141
  },
117
142
  });
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;
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;
119
144
  exports.default = recommendation.reducer;
120
145
  const doUpdateRecommendationForEntity = (draft, entityId, entityType, payload) => {
121
146
  const key = (0, recommendationState_1.getEntityRecommendationKey)(entityType, entityId);
@@ -115,7 +115,17 @@ export declare const downloadAccountingProviderAttachment: import("@reduxjs/tool
115
115
  amount: number;
116
116
  recommendationWithCOTByLineId: RecommendationWithCOTByLineId;
117
117
  uncategorizedIncomeExpense: UncategorizedAccounts;
118
- }, "transactionDetail/setEntityRecommendationForLineIdsForTransactionDetail", never, never>, removeEntityRecommendationForLineIdForTransactionDetail: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionId: TransactionID, transaction: SupportedTransaction, lineId: string], {
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], {
119
129
  transactionId: TransactionID;
120
130
  transaction: SupportedTransaction;
121
131
  lineId: string;