@zeniai/client-epic-state 5.0.69-betaAR5 → 5.0.69-betaAS1

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 (50) hide show
  1. package/lib/entity/account/accountSelector.d.ts +0 -26
  2. package/lib/entity/account/accountSelector.js +1 -47
  3. package/lib/entity/account/accountState.d.ts +0 -5
  4. package/lib/entity/account/accountState.js +4 -11
  5. package/lib/entity/class/classSelector.d.ts +0 -35
  6. package/lib/entity/class/classSelector.js +0 -50
  7. package/lib/esm/entity/account/accountSelector.js +1 -46
  8. package/lib/esm/entity/account/accountState.js +1 -7
  9. package/lib/esm/entity/class/classSelector.js +0 -48
  10. package/lib/esm/index.js +4 -10
  11. package/lib/esm/view/companyHealthMetricView/companyHealthMetricViewSelector.js +1 -1
  12. package/lib/esm/view/companyView/helpers/cockpitHelpers.js +1 -1
  13. package/lib/esm/view/companyView/selector/companyManagementViewSelector.js +1 -1
  14. package/lib/esm/view/companyView/selector/companyPortfolioViewSelector.js +1 -1
  15. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +1 -11
  16. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +12 -69
  17. package/lib/esm/view/spendManagement/commonHistoryView/commonHistoryPayload.js +1 -0
  18. package/lib/esm/view/spendManagement/spendManagementFilterHelpers.js +2 -4
  19. package/lib/esm/view/subscriptionView/subscriptionViewSelector.js +1 -1
  20. package/lib/esm/view/taskManager/taskListView/taskListReducer.js +1 -1
  21. package/lib/index.d.ts +5 -7
  22. package/lib/index.js +32 -41
  23. package/lib/view/companyHealthMetricView/companyHealthMetricViewSelector.js +1 -1
  24. package/lib/view/companyView/helpers/cockpitHelpers.js +1 -1
  25. package/lib/view/companyView/selector/companyManagementViewSelector.js +1 -1
  26. package/lib/view/companyView/selector/companyPortfolioViewSelector.js +1 -1
  27. package/lib/view/companyView/types/cockpitTypes.d.ts +1 -1
  28. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +1 -5
  29. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +2 -12
  30. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.d.ts +1 -4
  31. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +12 -71
  32. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +0 -2
  33. package/lib/view/spendManagement/billPay/billList/billListState.d.ts +1 -1
  34. package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistory.d.ts +1 -1
  35. package/lib/view/spendManagement/commonHistoryView/commonHistory.d.ts +1 -0
  36. package/lib/view/spendManagement/commonHistoryView/commonHistoryPayload.d.ts +1 -0
  37. package/lib/view/spendManagement/commonHistoryView/commonHistoryPayload.js +1 -0
  38. package/lib/view/spendManagement/reimbursement/remiListView/remiListState.d.ts +1 -1
  39. package/lib/view/spendManagement/spendManagementFilterHelpers.d.ts +3 -12
  40. package/lib/view/spendManagement/spendManagementFilterHelpers.js +2 -4
  41. package/lib/view/subscriptionView/subscriptionViewSelector.js +1 -1
  42. package/lib/view/taskManager/taskListView/taskList.d.ts +1 -1
  43. package/lib/view/taskManager/taskListView/taskListReducer.js +1 -1
  44. package/package.json +1 -1
  45. package/lib/commonStateTypes/filterPrimitives.d.ts +0 -23
  46. package/lib/commonStateTypes/filterPrimitives.js +0 -21
  47. package/lib/esm/commonStateTypes/filterPrimitives.js +0 -20
  48. package/lib/esm/view/expenseAutomationView/transactionFilterHelpers.js +0 -245
  49. package/lib/view/expenseAutomationView/transactionFilterHelpers.d.ts +0 -66
  50. package/lib/view/expenseAutomationView/transactionFilterHelpers.js +0 -249
@@ -3,7 +3,6 @@ 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;
7
6
  exports.getExpenseAutomationTransactionView = getExpenseAutomationTransactionView;
8
7
  const omit_1 = __importDefault(require("lodash/omit"));
9
8
  const reduceFetchState_1 = require("../../../commonStateTypes/reduceFetchState");
@@ -11,34 +10,14 @@ const timePeriod_1 = require("../../../commonStateTypes/timePeriod");
11
10
  const tenantSelector_1 = require("../../../entity/tenant/tenantSelector");
12
11
  const transactionHelper_1 = require("../../../entity/transaction/transactionHelper");
13
12
  const transactionSelector_1 = require("../../../entity/transaction/transactionSelector");
14
- const transactionFilterHelpers_1 = require("../transactionFilterHelpers");
15
13
  const accountListSelector_1 = require("../../accountList/accountListSelector");
16
14
  const classListSelector_1 = require("../../classList/classListSelector");
17
15
  const projectListSelector_1 = require("../../projectList/projectListSelector");
18
16
  const expenseAutomationViewSelectorTypes_1 = require("../selectorTypes/expenseAutomationViewSelectorTypes");
19
- const toTransactionView = (transaction, transactionLocalData) => {
20
- return {
21
- id: transaction.id,
22
- date: transaction.date,
23
- amount: transaction.amount,
24
- vendorName: transaction.vendorName,
25
- customerName: transaction.customerName,
26
- vendorId: transaction.vendorId,
27
- customerId: transaction.customerId,
28
- description: transaction.description,
29
- memo: transaction.memo,
30
- type: transaction.type,
31
- typeName: transaction.typeName,
32
- createTime: transaction.createTime,
33
- transaction: transaction,
34
- transactionLocalData,
35
- };
36
- };
37
- exports.toTransactionView = toTransactionView;
38
17
  function getExpenseAutomationTransactionView(state) {
39
18
  const { accountState, classState, classListState, accountListState, expenseAutomationTransactionsViewState, expenseAutomationViewState, projectState, projectListState, transactionState, monthEndCloseChecksState, monthEndCloseChecksViewState, } = state;
40
19
  const { selectedTransactionCategorizationCompletedSubTab, selectedTransactionCategorizationTab, } = expenseAutomationTransactionsViewState;
41
- const { uiState, refreshStatus, saveStatus, markAsNotMiscategorizedStatus, transactionIdsBySelectedPeriod, transactionReviewLocalDataById, selectedCheckBoxTransactionIds, transactionIdsWithUnsavedData, uploadReceiptStatusById, selectedTransactionId, selectedTransactionLineId, filters, } = expenseAutomationTransactionsViewState.transactionCategorizationView[selectedTransactionCategorizationTab];
20
+ const { uiState, refreshStatus, saveStatus, markAsNotMiscategorizedStatus, transactionIdsBySelectedPeriod, transactionReviewLocalDataById, selectedCheckBoxTransactionIds, transactionIdsWithUnsavedData, uploadReceiptStatusById, selectedTransactionId, selectedTransactionLineId, } = expenseAutomationTransactionsViewState.transactionCategorizationView[selectedTransactionCategorizationTab];
42
21
  const uncategorizedIncomeExpense = (0, accountListSelector_1.getUncategorizedAccounts)(accountState, accountListState, 'accountList');
43
22
  const accountList = (0, accountListSelector_1.getAccountList)(accountState, accountListState, 'accountList');
44
23
  const classList = (0, classListSelector_1.getClassList)(classState, classListState);
@@ -57,58 +36,20 @@ function getExpenseAutomationTransactionView(state) {
57
36
  ? transactionIdsBySelectedPeriod[monthYearPeriodId]
58
37
  : null;
59
38
  const transactionIds = transactionIdsForSelectedPeriod ?? [];
60
- const transactions = (0, transactionSelector_1.getSupportedTransactionsByIds)(transactionState, transactionIds);
61
- const transactionsWithCOT = transactions.map((transaction) => (0, transactionHelper_1.getTransactionWithCOT)(transaction));
62
- const transactionLocalDataMap = new Map();
63
- transactionIds.forEach((transactionId) => {
39
+ const transactionLocalData = transactionIds
40
+ .map((transactionId) => {
64
41
  const transactionData = transactionReviewLocalDataById[transactionId];
65
42
  if (transactionData != null) {
66
- transactionLocalDataMap.set(transactionId, {
43
+ return {
67
44
  transactionId,
68
45
  transactionReviewLocalData: transactionData.transactionReviewLocalData,
69
- });
46
+ };
70
47
  }
71
- });
72
- // Step 2: Convert to TransactionView and apply advanced filters
73
- const transactionViews = transactionsWithCOT.map((transaction) => {
74
- const localData = transactionLocalDataMap.get(transaction.id);
75
- return (0, exports.toTransactionView)(transaction, localData);
76
- });
77
- // Apply TC-specific filters (lives under expenseAutomationView, independent
78
- // of the Spend Management filter pipeline).
79
- const filteredTransactionViews = (0, transactionFilterHelpers_1.applyTransactionFilters)(transactionViews, filters);
80
- // Convert back to TransactionWithCOT for return
81
- const filteredTransactionsWithCOT = filteredTransactionViews.map((view) => view.transaction);
82
- // Get transactionLocalData for filtered transactions
83
- // Also include transactionLocalData for transactions that don't exist in transactionState
84
- // but have local data (to match original behavior)
85
- const filteredTransactionIds = new Set(filteredTransactionViews.map((view) => view.id));
86
- // Pre-compute the membership set once. The previous implementation called
87
- // `transactions.some(t => t.id === transactionId)` inside the per-id loop,
88
- // turning the pipeline into O(n × m) — measurable on tenants with large
89
- // transaction lists since this selector runs on every Redux dispatch.
90
- const transactionExistsById = new Set(transactions.map((t) => t.id));
91
- // `.flatMap` returns `X[]` directly when the callback returns `[]` for the
92
- // skip case, so we don't need the trailing `.filter((d): d is X => …)` type
93
- // predicate that the previous `map → filter` pipeline required.
94
- const filteredTransactionLocalData = transactionIds.flatMap((transactionId) => {
95
- const transactionData = transactionReviewLocalDataById[transactionId];
96
- if (transactionData == null) {
97
- return [];
98
- }
99
- // Include if transaction is in filtered results, or if transaction doesn't exist in state
100
- // (to maintain backward compatibility with tests)
101
- const transactionExists = transactionExistsById.has(transactionId);
102
- if (filteredTransactionIds.has(transactionId) || !transactionExists) {
103
- return [
104
- {
105
- transactionId,
106
- transactionReviewLocalData: transactionData.transactionReviewLocalData,
107
- },
108
- ];
109
- }
110
- return [];
111
- });
48
+ return null;
49
+ })
50
+ .filter((transaction) => transaction != null);
51
+ const transactions = (0, transactionSelector_1.getSupportedTransactionsByIds)(transactionState, transactionIds);
52
+ const transactionsWithCOT = transactions.map((transaction) => (0, transactionHelper_1.getTransactionWithCOT)(transaction));
112
53
  const monthEndFetchState = monthYearPeriodId != null
113
54
  ? (monthEndCloseChecksViewState.monthEndCloseChecksViewByTenantId[currentTenant.tenantId]?.[monthYearPeriodId] ?? { fetchState: 'Not-Started', error: undefined })
114
55
  : { fetchState: 'Not-Started', error: undefined };
@@ -172,7 +113,7 @@ function getExpenseAutomationTransactionView(state) {
172
113
  version: 0,
173
114
  fetchState: fetchStatus.fetchState,
174
115
  error: fetchStatus.error,
175
- transactions: filteredTransactionsWithCOT,
116
+ transactions: transactionsWithCOT,
176
117
  selectedCheckBoxTransactionIds,
177
118
  transactionIdsWithUnsavedData,
178
119
  uncategorizedAccounts: uncategorizedIncomeExpense,
@@ -183,7 +124,7 @@ function getExpenseAutomationTransactionView(state) {
183
124
  classHierarchyList,
184
125
  isAccountingProjectsEnabled,
185
126
  projectList,
186
- transactionLocalData: filteredTransactionLocalData,
127
+ transactionLocalData,
187
128
  uiState,
188
129
  refreshStatus,
189
130
  saveStatus,
@@ -16,7 +16,6 @@ import { VendorBase } from '../../../entity/vendor/vendorState';
16
16
  import { ZeniAPIStatus } from '../../../responsePayload';
17
17
  import { ZeniDate } from '../../../zeniDayJS';
18
18
  import { EntityRecommendationKey } from '../../recommendation/recommendationState';
19
- import { TransactionFilters } from '../transactionFilterHelpers';
20
19
  import { TransactionDetailKey } from '../../transactionDetail/transactionDetailState';
21
20
  import { CompletedSubTab } from './completedSubTab';
22
21
  export declare const toTransactionsSortKey: (v: string) => "date" | "amount" | "vendor" | "project" | "category" | "class" | "payment_account" | "transaction_type" | "memo_and_receipt";
@@ -94,7 +93,6 @@ export interface SupportedTransactionCategorization {
94
93
  }
95
94
  export declare const initialSupportedTransactionCategorization: SupportedTransactionCategorization;
96
95
  export interface TransactionsTabViewState extends FetchedState {
97
- filters: TransactionFilters;
98
96
  markAsNotMiscategorizedStatus: FetchStateAndError;
99
97
  refreshStatus: FetchStateAndError;
100
98
  saveStatus: FetchStateAndError;
@@ -45,7 +45,7 @@ export interface BillPayFilters {
45
45
  }
46
46
  export interface BillPayFilterCategory {
47
47
  field: BillListViewFilterCategoryField;
48
- matchingOperator: 'equal' | 'not_equal';
48
+ matchingOperator: 'equal' | 'not-equal';
49
49
  values: (string | ZeniDate)[];
50
50
  valuesCombinationOperator: 'ANY';
51
51
  }
@@ -36,7 +36,7 @@ export interface PaymentHistoryFilters {
36
36
  }
37
37
  export interface PaymentHistoryFilterCategory {
38
38
  field: PaymentHistoryFilterCategoryField;
39
- matchingOperator: 'equal' | 'not_equal';
39
+ matchingOperator: 'equal' | 'not-equal';
40
40
  values: (string | ZeniDate)[];
41
41
  valuesCombinationOperator: 'ANY';
42
42
  }
@@ -11,6 +11,7 @@ export interface HistoricEvent {
11
11
  eventSubText: string[];
12
12
  eventText: string[];
13
13
  updates: HistoricEventUpdate[];
14
+ paymentTraceId?: string | null;
14
15
  timestamp?: ZeniDate;
15
16
  }
16
17
  export interface HistoricEventUpdate {
@@ -20,6 +20,7 @@ interface HistoricEventMetaDataPayload {
20
20
  activity_title: string;
21
21
  actor_id: string;
22
22
  actor_name: string;
23
+ payment_trace_id?: string | null;
23
24
  }
24
25
  export declare const toHistoricEvent: (payload: HistoricEventPayload) => HistoricEvent;
25
26
  export type FetchEntityHistoryResponse = ZeniAPIResponse<HistoryPayload>;
@@ -8,6 +8,7 @@ const toHistoricEvent = (payload) => ({
8
8
  eventSubText: payload.event_sub_text ?? [],
9
9
  timestamp: payload.timestamp != null ? (0, zeniDayJS_1.dateLocal)(payload.timestamp) : undefined,
10
10
  updates: payload.updates.map((eventUpdatePayload) => toHistoricEventUpdate(eventUpdatePayload)),
11
+ paymentTraceId: payload.metadata.payment_trace_id ?? null,
11
12
  });
12
13
  exports.toHistoricEvent = toHistoricEvent;
13
14
  const toHistoricEventUpdate = (payload) => ({
@@ -46,7 +46,7 @@ export interface ReimbursementFilters {
46
46
  }
47
47
  export interface ReimbursementFilterCategory {
48
48
  field: RemiListViewFilterCategoryField;
49
- matchingOperator: 'equal' | 'not_equal';
49
+ matchingOperator: 'equal' | 'not-equal';
50
50
  values: (string | ZeniDate)[];
51
51
  valuesCombinationOperator: 'ANY';
52
52
  }
@@ -1,4 +1,3 @@
1
- import { CategoryCombinationOperator, FilterCategoryType } from '../../commonStateTypes/filterPrimitives';
2
1
  import { TimePeriod } from '../../commonStateTypes/timePeriod';
3
2
  import { UserRoleType } from '../../entity/userRole/userRoleType';
4
3
  import { RootState } from '../../reducer';
@@ -13,20 +12,12 @@ import { ReimbursementView } from './reimbursement/remiListView/remiListSelector
13
12
  import { ReimbursementFilters, RemiListViewFilterCategoryField } from './reimbursement/remiListView/remiListState';
14
13
  export type SpendManagementFiltersType = BillPayFilters | ReimbursementFilters | TaskListFilters | PaymentHistoryFilters;
15
14
  export type SpendManagementFilterEntityType = 'bill_pay' | 'reimbursement' | 'task_management' | 'charge_card_payment_history';
16
- /**
17
- * Re-exported here so consumers of `spendManagementFilterHelpers` keep
18
- * their existing import path stable after the primitives moved to
19
- * `commonStateTypes/filterPrimitives`. Downstream files (`taskList`,
20
- * `remiListState`, `chargeCardPaymentHistory`, `billListState`) and the
21
- * CES barrel still pull `CategoryCombinationOperator` / `FilterCategoryType`
22
- * from this module — the source of truth is upstream but the surface is
23
- * unchanged.
24
- */
25
- export type { CategoryCombinationOperator, FilterCategoryType };
15
+ export type FilterCategoryType = 'searchAutocomplete' | 'user' | 'dateRange' | 'numberRange' | 'dropdown';
26
16
  export interface MatchingOperatorDropdownOption {
27
17
  label: 'is' | 'is not';
28
- value: 'equal' | 'not_equal';
18
+ value: 'equal' | 'not-equal';
29
19
  }
20
+ export type CategoryCombinationOperator = 'AND' | 'OR';
30
21
  export interface BillPayFilterCategoryDropdownOption {
31
22
  value: BillListViewFilterCategoryField;
32
23
  multiple?: boolean;
@@ -14,8 +14,6 @@ const helpers_1 = require("./helpers");
14
14
  const remiListSelector_1 = require("./reimbursement/remiListView/remiListSelector");
15
15
  const remiListState_1 = require("./reimbursement/remiListView/remiListState");
16
16
  //filters items against filter values representing a range. ex: date (from-to), amount(1k<-->5k)
17
- // Spend Management uses only equal/not_equal — TC amount operators
18
- // (inBetween, lessThan, greaterThan) live in the TC filter pipeline.
19
17
  const filterItemOnRangeCategoryType = (valueForItem, currentFilter) => {
20
18
  let doesItemFallInValueRange = false;
21
19
  const filterField = currentFilter.field;
@@ -49,7 +47,7 @@ const filterItemOnCategoriesWithSingleValue = (categoryValue, currentFilter, ran
49
47
  return filterItemOnRangeCategoryType(categoryValue, currentFilter);
50
48
  }
51
49
  // if filter category is not rangeType
52
- if (currentFilter.matchingOperator === 'not_equal') {
50
+ if (currentFilter.matchingOperator === 'not-equal') {
53
51
  return currentFilter.values.indexOf(categoryValue.toString()) === -1;
54
52
  }
55
53
  return currentFilter.values.indexOf(categoryValue.toString()) > -1;
@@ -123,7 +121,7 @@ const applyAdvancedFiltersOnList = (entity, allItems, filters, filteredItems = [
123
121
  ? getCategoryValueForTaskList(key, item)
124
122
  : getCategoryValueForPaymentHistory(key, item);
125
123
  if (categoryValue == null) {
126
- if (currentFilter.matchingOperator === 'not_equal') {
124
+ if (currentFilter.matchingOperator === 'not-equal') {
127
125
  return true;
128
126
  }
129
127
  return false;
@@ -217,7 +217,7 @@ const applyAdvancedFiltersOnCompaniesList = (allCompanies, filters, filteredComp
217
217
  const key = currentFilter.field;
218
218
  const categoryValue = getCategoryValueForCompany(key, company);
219
219
  if (categoryValue == null) {
220
- if (currentFilter.matchingOperator === 'not_equal') {
220
+ if (currentFilter.matchingOperator === 'not-equal') {
221
221
  return true;
222
222
  }
223
223
  return false;
@@ -44,7 +44,7 @@ export interface TaskListFilters {
44
44
  }
45
45
  export interface TaskFilterCategory {
46
46
  field: TaskListFilterCategoryField;
47
- matchingOperator: 'equal' | 'not_equal';
47
+ matchingOperator: 'equal' | 'not-equal';
48
48
  values: (string | ZeniDate)[];
49
49
  valuesCombinationOperator: 'ANY';
50
50
  }
@@ -70,7 +70,7 @@ exports.initialState = {
70
70
  categories: [
71
71
  {
72
72
  field: 'status',
73
- matchingOperator: 'not_equal',
73
+ matchingOperator: 'not-equal',
74
74
  values: ['resolved'],
75
75
  valuesCombinationOperator: 'ANY',
76
76
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.0.69-betaAR5",
3
+ "version": "5.0.69-betaAS1",
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",
@@ -1,23 +0,0 @@
1
- /**
2
- * Shared filter primitives — used by both Transaction Categorization and
3
- * Spend Management filter pipelines.
4
- *
5
- * These types are deliberately decoupled from any specific feature group:
6
- *
7
- * - `CategoryCombinationOperator` is how a `categories[]` array combines
8
- * (`AND` ⇒ every category must match; `OR` ⇒ any category matches).
9
- * - `FilterCategoryType` is the input-type tag a filter category uses to
10
- * pick its value-picker UI (text autocomplete, user picker, date range,
11
- * number range, plain dropdown).
12
- *
13
- * They used to be redeclared locally in both `transactionFilterHelpers.ts`
14
- * and `spendManagementFilterHelpers.ts` to keep the feature groups
15
- * independent. Centralising them here is consistent with Route B (which
16
- * separated the *matching pipelines*, not the *shared primitive types*) and
17
- * removes the maintenance trap of two identical type definitions drifting
18
- * apart over time.
19
- */
20
- /** How `categories[]` combines: AND requires every category to match, OR requires any. */
21
- export type CategoryCombinationOperator = 'AND' | 'OR';
22
- /** Input-type tag a filter category uses to pick its value-picker UI. */
23
- export type FilterCategoryType = 'searchAutocomplete' | 'user' | 'dateRange' | 'numberRange' | 'dropdown';
@@ -1,21 +0,0 @@
1
- "use strict";
2
- /**
3
- * Shared filter primitives — used by both Transaction Categorization and
4
- * Spend Management filter pipelines.
5
- *
6
- * These types are deliberately decoupled from any specific feature group:
7
- *
8
- * - `CategoryCombinationOperator` is how a `categories[]` array combines
9
- * (`AND` ⇒ every category must match; `OR` ⇒ any category matches).
10
- * - `FilterCategoryType` is the input-type tag a filter category uses to
11
- * pick its value-picker UI (text autocomplete, user picker, date range,
12
- * number range, plain dropdown).
13
- *
14
- * They used to be redeclared locally in both `transactionFilterHelpers.ts`
15
- * and `spendManagementFilterHelpers.ts` to keep the feature groups
16
- * independent. Centralising them here is consistent with Route B (which
17
- * separated the *matching pipelines*, not the *shared primitive types*) and
18
- * removes the maintenance trap of two identical type definitions drifting
19
- * apart over time.
20
- */
21
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,20 +0,0 @@
1
- /**
2
- * Shared filter primitives — used by both Transaction Categorization and
3
- * Spend Management filter pipelines.
4
- *
5
- * These types are deliberately decoupled from any specific feature group:
6
- *
7
- * - `CategoryCombinationOperator` is how a `categories[]` array combines
8
- * (`AND` ⇒ every category must match; `OR` ⇒ any category matches).
9
- * - `FilterCategoryType` is the input-type tag a filter category uses to
10
- * pick its value-picker UI (text autocomplete, user picker, date range,
11
- * number range, plain dropdown).
12
- *
13
- * They used to be redeclared locally in both `transactionFilterHelpers.ts`
14
- * and `spendManagementFilterHelpers.ts` to keep the feature groups
15
- * independent. Centralising them here is consistent with Route B (which
16
- * separated the *matching pipelines*, not the *shared primitive types*) and
17
- * removes the maintenance trap of two identical type definitions drifting
18
- * apart over time.
19
- */
20
- export {};
@@ -1,245 +0,0 @@
1
- /**
2
- * Narrowing type-guard for "has a non-empty string here". Used in place of
3
- * raw `if (foo)` truthiness checks on `string | null | undefined` values so
4
- * the `@typescript-eslint/strict-boolean-expressions` lint stays clean —
5
- * empty strings should explicitly fall through to the next candidate
6
- * (vendorName → customerName → localData.vendor.name → ...) rather than
7
- * being implicitly coerced to falsy.
8
- */
9
- const isNonEmptyString = (s) => s != null && s !== '';
10
- export const TRANSACTION_FILTER_CATEGORIES = [
11
- { value: 'payment_account_name', type: 'dropdown' },
12
- { value: 'payment_account_type', type: 'dropdown' },
13
- { value: 'payee', type: 'searchAutocomplete' },
14
- { value: 'category', type: 'dropdown' },
15
- { value: 'class', type: 'dropdown' },
16
- { value: 'amount', type: 'numberRange' },
17
- ];
18
- /**
19
- * Resolve the comparable value for a transaction against a given filter field.
20
- * Returns undefined when the transaction doesn't carry the field — callers
21
- * decide whether absence counts as a match (for 'not_equal' it does).
22
- */
23
- const getCategoryValueForTransaction = (key, transaction) => {
24
- switch (key) {
25
- case 'amount': {
26
- // Prefer transactionLocalData line items (sum). Fall back to lines on
27
- // the transaction itself. Final fallback: transaction-level amount.
28
- const localDataForAmount = transaction.transactionLocalData?.transactionReviewLocalData;
29
- if (localDataForAmount?.lineItemById) {
30
- const lineItems = Object.values(localDataForAmount.lineItemById);
31
- if (lineItems.length > 0) {
32
- return lineItems.reduce((sum, lineItem) => sum + (lineItem.amount?.amount ?? 0), 0);
33
- }
34
- }
35
- if (transaction.transaction.lines &&
36
- transaction.transaction.lines.length > 0) {
37
- return transaction.transaction.lines.reduce((sum, line) => sum + (line.amount?.amount ?? 0), 0);
38
- }
39
- return transaction.amount.amount;
40
- }
41
- case 'payee': {
42
- if (isNonEmptyString(transaction.vendorName)) {
43
- return transaction.vendorName;
44
- }
45
- if (isNonEmptyString(transaction.customerName)) {
46
- return transaction.customerName;
47
- }
48
- const localData = transaction.transactionLocalData?.transactionReviewLocalData;
49
- const vendorName = localData?.vendor?.name;
50
- if (isNonEmptyString(vendorName)) {
51
- return vendorName;
52
- }
53
- const customerName = localData?.customer?.name;
54
- if (isNonEmptyString(customerName)) {
55
- return customerName;
56
- }
57
- return undefined;
58
- }
59
- case 'payment_account_name': {
60
- // Match what TransactionCategorizationListRow renders for the cell.
61
- return transaction.transaction.account?.accountName;
62
- }
63
- case 'payment_account_type': {
64
- // Raw `paymentType` enum ("credit_card" / "check" / "cash"). Dropdown
65
- // option values use the same enum; row uses `paymentTypeName` for the
66
- // human label.
67
- return transaction.transaction.paymentType;
68
- }
69
- case 'category': {
70
- const localDataForCategory = transaction.transactionLocalData?.transactionReviewLocalData;
71
- if (localDataForCategory != null) {
72
- const firstLineItem = Object.values(localDataForCategory.lineItemById)[0];
73
- const accountId = firstLineItem?.account?.accountId;
74
- if (isNonEmptyString(accountId)) {
75
- return accountId;
76
- }
77
- const qboId = firstLineItem?.account?.qboId;
78
- if (isNonEmptyString(qboId)) {
79
- return qboId;
80
- }
81
- const accountName = firstLineItem?.account?.accountName;
82
- if (isNonEmptyString(accountName)) {
83
- return accountName;
84
- }
85
- }
86
- const firstLineForCategory = transaction.transaction.lines?.[0];
87
- if (firstLineForCategory?.type ===
88
- 'transaction_with_account_and_class_line' ||
89
- firstLineForCategory?.type ===
90
- 'transaction_with_product_or_service_line' ||
91
- firstLineForCategory?.type === 'journal_entry_transaction_line') {
92
- const account = firstLineForCategory.account;
93
- return account?.accountId ?? account?.qboId ?? account?.accountName;
94
- }
95
- return undefined;
96
- }
97
- case 'class': {
98
- const localDataForClass = transaction.transactionLocalData?.transactionReviewLocalData;
99
- if (localDataForClass != null) {
100
- const firstLineItemForClass = Object.values(localDataForClass.lineItemById)[0];
101
- const classId = firstLineItemForClass?.class?.classId;
102
- if (isNonEmptyString(classId)) {
103
- return classId;
104
- }
105
- const qboId = firstLineItemForClass?.class?.qboId;
106
- if (isNonEmptyString(qboId)) {
107
- return qboId;
108
- }
109
- const className = firstLineItemForClass?.class?.className;
110
- if (isNonEmptyString(className)) {
111
- return className;
112
- }
113
- }
114
- const firstLineForClass = transaction.transaction.lines?.[0];
115
- if (firstLineForClass?.type === 'transaction_with_account_and_class_line' ||
116
- firstLineForClass?.type ===
117
- 'transaction_with_product_or_service_line' ||
118
- firstLineForClass?.type === 'journal_entry_transaction_line') {
119
- const classData = firstLineForClass.class;
120
- return classData?.classId ?? classData?.qboId ?? classData?.className;
121
- }
122
- return undefined;
123
- }
124
- default:
125
- return undefined;
126
- }
127
- };
128
- /**
129
- * TC-only amount matcher. Supports all five operators TC defines, including
130
- * the legacy "1000<->5000" range-string form (kept for backward compatibility
131
- * with persisted filter state that may still contain that encoding).
132
- *
133
- * The `'equal' | 'not_equal'` branch matches if `amount` equals ANY of the
134
- * configured values (consistent with how non-amount filters interpret a
135
- * multi-value `values` array). `.some()` over the values array also makes
136
- * the empty-values case behave correctly — empty array → `matched = false`
137
- * — though in practice `applyTransactionFilters` strips empty-values
138
- * categories before they reach this matcher. The trailing
139
- * `op === 'not_equal' ? !matched : matched` line inverts for `not_equal`.
140
- */
141
- const matchAmount = (amount, category) => {
142
- const op = category.matchingOperator;
143
- const values = category.values;
144
- let matched = false;
145
- if (op === 'in_between') {
146
- if (values.length >= 2) {
147
- const min = Number(values[0]);
148
- const max = Number(values[1]);
149
- matched = amount >= min && amount <= max;
150
- }
151
- }
152
- else if (op === 'less_than') {
153
- if (values.length >= 1) {
154
- matched = amount < Number(values[0]);
155
- }
156
- }
157
- else if (op === 'greater_than') {
158
- if (values.length >= 1) {
159
- matched = amount > Number(values[0]);
160
- }
161
- }
162
- else if (op === 'equal' || op === 'not_equal') {
163
- matched = values.some((v) => {
164
- const s = String(v);
165
- // Backward compatibility: legacy "low<->high" range-string form
166
- // persisted under `matchingOperator: 'equal'`.
167
- if (s.includes('<->')) {
168
- const parts = s.split('<->');
169
- return (amount >= Number(parts[0] ?? '') && amount <= Number(parts[1] ?? ''));
170
- }
171
- return amount === Number(v);
172
- });
173
- }
174
- return op === 'not_equal' ? !matched : matched;
175
- };
176
- const transactionMatchesCategory = (transaction, category) => {
177
- const value = getCategoryValueForTransaction(category.field, transaction);
178
- if (value == null) {
179
- // Absent-value semantics — pinning these down explicitly so the
180
- // asymmetry isn't surprising:
181
- //
182
- // not_equal: a missing value IS NOT EQUAL to any candidate, so the
183
- // transaction matches the filter (passes through).
184
- // equal: a missing value is not equal to any candidate, so the
185
- // transaction does NOT match (filtered out).
186
- // less_than / greater_than: SQL-style three-valued logic — comparing
187
- // against a missing value is "unknown", which we treat as
188
- // "does not match" (filtered out). A user setting
189
- // "amount < $1000" probably wants transactions with a
190
- // concrete amount that satisfies the bound, not rows
191
- // where the amount can't be determined.
192
- // in_between: same as the single-sided comparators — missing values
193
- // are filtered out.
194
- //
195
- // Only the `not_equal` branch returns `true` here; everything else
196
- // falls through to the `false` below.
197
- return category.matchingOperator === 'not_equal';
198
- }
199
- if (category.field === 'amount') {
200
- return matchAmount(Number(value), category);
201
- }
202
- const valueStr = value.toString();
203
- const valueInList = category.values.some((v) => v.toString() === valueStr);
204
- return category.matchingOperator === 'not_equal' ? !valueInList : valueInList;
205
- };
206
- /**
207
- * TC-only equivalent of `applyAdvancedFiltersOnList`. Filters a list of
208
- * `TransactionView` items against a `TransactionFilters` object using the
209
- * AND/OR combination semantics from `categoryCombinationOperator`.
210
- *
211
- * Independent of `view/spendManagement` — keeps the TC filter pipeline cleanly
212
- * inside the Expense Automation feature group.
213
- */
214
- export const applyTransactionFilters = (transactions, filters) => {
215
- if (filters?.categories == null || filters.categories.length === 0) {
216
- return transactions;
217
- }
218
- // Mirrors the predicate used by `getTransactionAppliedFiltersCount` on the
219
- // webc side. A half-filled category — e.g. `in_between` with only the
220
- // `min` typed — would otherwise survive the filter pass and produce zero
221
- // matches because `Number("")` collapses to `0`, artificially emptying
222
- // the list while editing. Skipping such categories keeps the filtered
223
- // view stable while the user finishes typing.
224
- const activeCategories = filters.categories.filter((c) => {
225
- if (c.field == null || c.values.length === 0) {
226
- return false;
227
- }
228
- if (c.field === 'amount' && c.matchingOperator === 'in_between') {
229
- return (c.values.length >= 2 &&
230
- String(c.values[0] ?? '').trim() !== '' &&
231
- String(c.values[1] ?? '').trim() !== '');
232
- }
233
- return String(c.values[0] ?? '').trim() !== '';
234
- });
235
- if (activeCategories.length === 0) {
236
- return transactions;
237
- }
238
- const op = filters.categoryCombinationOperator;
239
- return transactions.filter((txn) => {
240
- if (op === 'AND') {
241
- return activeCategories.every((cat) => transactionMatchesCategory(txn, cat));
242
- }
243
- return activeCategories.some((cat) => transactionMatchesCategory(txn, cat));
244
- });
245
- };