@zeniai/client-epic-state 4.9.33 → 4.9.34

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.
@@ -445,7 +445,7 @@ const setEntityRecommendationForLineIdInLocalData = (transaction, transactionDet
445
445
  line.type === 'transaction_with_product_or_service_line' ||
446
446
  line.type === 'journal_entry_transaction_line') {
447
447
  const record = Object.assign({}, oldRecord);
448
- const recommendations = recommendationByLineId === null || recommendationByLineId === void 0 ? void 0 : recommendationByLineId[lineId];
448
+ const recommendations = mergeTransactionAndEntityRecommendations(oldRecord.recommendations, recommendationByLineId === null || recommendationByLineId === void 0 ? void 0 : recommendationByLineId[lineId]);
449
449
  const accountLine = line;
450
450
  record.account = accountLine.account;
451
451
  record.class = accountLine.class;
@@ -668,3 +668,39 @@ const isAccountUncategorized = (uncategorizedIncomeExpense, accountQboId) => {
668
668
  }
669
669
  return false;
670
670
  };
671
+ /*
672
+ Note: Below helper is used to merge transaction recommendations and entity recommendations.
673
+ On transaction detail page, we get vendors, accounting_classes and accounts inside recommendations. This is stored inside local data.
674
+ When we select a vendor from vendor dropdown, recommendations api is called and in response, only accounting_classes and accounts we get.
675
+ So in this case, we need to merge the transaction recommendation with this new recommendation in order to keep `vendors` part as it is.
676
+
677
+ We are keeping `vendors` of transaction and updated accounting_classes and accounts from recommendations api call.
678
+ */
679
+ const mergeTransactionAndEntityRecommendations = (transactionRecommendations, entityRecommendations) => {
680
+ if (entityRecommendations == null) {
681
+ return transactionRecommendations;
682
+ }
683
+ else if (transactionRecommendations == null) {
684
+ return entityRecommendations;
685
+ }
686
+ else if (entityRecommendations.length > transactionRecommendations.length) {
687
+ return entityRecommendations.map((recommendation, index) => {
688
+ var _a;
689
+ return {
690
+ account: recommendation.account,
691
+ class: recommendation.class,
692
+ vendor: (_a = transactionRecommendations[index]) === null || _a === void 0 ? void 0 : _a.vendor,
693
+ };
694
+ });
695
+ }
696
+ else {
697
+ return transactionRecommendations.map((recommendation, index) => {
698
+ var _a, _b;
699
+ return {
700
+ account: (_a = entityRecommendations[index]) === null || _a === void 0 ? void 0 : _a.account,
701
+ class: (_b = entityRecommendations[index]) === null || _b === void 0 ? void 0 : _b.class,
702
+ vendor: recommendation.vendor,
703
+ };
704
+ });
705
+ }
706
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "4.9.33",
3
+ "version": "4.9.34",
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
  "types": "lib/index.d.ts",