@zeniai/client-epic-state 5.2.54 → 5.2.56-betaRD1
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.
- package/lib/entity/billPay/billTransaction/billTransactionReducer.d.ts +5 -1
- package/lib/entity/billPay/billTransaction/billTransactionReducer.js +17 -2
- package/lib/entity/jeSchedules/jeSchedulesReducer.d.ts +4 -1
- package/lib/entity/jeSchedules/jeSchedulesReducer.js +79 -5
- package/lib/epic.d.ts +4 -1
- package/lib/epic.js +10 -4
- package/lib/esm/entity/billPay/billTransaction/billTransactionReducer.js +16 -1
- package/lib/esm/entity/jeSchedules/jeSchedulesReducer.js +78 -4
- package/lib/esm/epic.js +10 -4
- package/lib/esm/index.js +5 -5
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +39 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +14 -1
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +10 -13
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +38 -17
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +17 -1
- package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +74 -1
- package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +49 -14
- package/lib/esm/view/spendManagement/billPay/billDetailView/billDetailViewReducer.js +87 -1
- package/lib/esm/view/spendManagement/billPay/billDetailView/billDetailViewSelector.js +1 -0
- package/lib/esm/view/spendManagement/billPay/billDetailView/billDetailViewState.js +4 -0
- package/lib/esm/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.js +97 -0
- package/lib/esm/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.js +85 -0
- package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewReducer.js +18 -1
- package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +3 -0
- package/lib/esm/view/spendManagement/billPay/editBillView/epics/applyBillRecommendationsToLocalStoreEpic.js +95 -0
- package/lib/index.d.ts +5 -5
- package/lib/index.js +51 -49
- package/lib/tsconfig.mocks.tsbuildinfo +1 -0
- package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.d.ts +20 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +43 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.d.ts +2 -2
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +13 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +8 -11
- package/lib/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +38 -17
- package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.d.ts +2 -2
- package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +17 -1
- package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +18 -0
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +10 -3
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +76 -3
- package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +3 -0
- package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +49 -14
- package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +16 -0
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewPayload.d.ts +19 -0
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewReducer.d.ts +10 -1
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewReducer.js +88 -2
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewSelector.d.ts +1 -0
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewSelector.js +1 -0
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewState.d.ts +7 -0
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewState.js +4 -0
- package/lib/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.d.ts +37 -0
- package/lib/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.js +104 -0
- package/lib/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.d.ts +24 -0
- package/lib/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.js +92 -0
- package/lib/view/spendManagement/billPay/editBillView/editBillViewReducer.d.ts +4 -1
- package/lib/view/spendManagement/billPay/editBillView/editBillViewReducer.js +19 -2
- package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.d.ts +1 -0
- package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +3 -0
- package/lib/view/spendManagement/billPay/editBillView/epics/applyBillRecommendationsToLocalStoreEpic.d.ts +18 -0
- package/lib/view/spendManagement/billPay/editBillView/epics/applyBillRecommendationsToLocalStoreEpic.js +102 -0
- package/package.json +1 -1
|
@@ -225,7 +225,7 @@ function getExpenseAutomationJESchedulesView(state) {
|
|
|
225
225
|
const accruedSchedules = [];
|
|
226
226
|
const oneTimeAccruals = [];
|
|
227
227
|
const { accountState, accountListState, classState, classListState, expenseAutomationJESchedulesViewState, expenseAutomationViewState, monthEndCloseChecksState, } = state;
|
|
228
|
-
const { jeScheduleTransactionKeysByPeriodAndTab, jeScheduleAccruedKeysByPeriodAndTab, jeScheduleOneTimeAccrualKeysByPeriodAndTab,
|
|
228
|
+
const { jeScheduleTransactionKeysByPeriodAndTab, jeScheduleAccruedKeysByPeriodAndTab, jeScheduleOneTimeAccrualKeysByPeriodAndTab, failedJePostings, jeScheduleLocalDataById, postStatusById, ignoreStatusById, revertStatusById, oneTimeAccrualActionStatusById, uiState, error, fetchState, refreshStatus, newSchedule, } = expenseAutomationJESchedulesViewState;
|
|
229
229
|
const accountSettingsView = (0, jeAccountSettingsViewSelector_1.getJEAccountSettingsView)(state);
|
|
230
230
|
const newScheduleView = newSchedule.selectedDetailScheduleType === 'fixed_assets' ||
|
|
231
231
|
newSchedule.selectedDetailScheduleType === 'prepaid_expenses'
|
|
@@ -264,15 +264,11 @@ function getExpenseAutomationJESchedulesView(state) {
|
|
|
264
264
|
const jeScheduleTransactionKeysForSelectedTab = selectedPeriodTabKey != null
|
|
265
265
|
? jeScheduleTransactionKeysByPeriodAndTab[selectedPeriodTabKey]
|
|
266
266
|
: undefined;
|
|
267
|
-
const failedJeScheduleTransactionKeysForSelectedTab = selectedPeriodTabKey != null
|
|
268
|
-
? failedJeScheduleTransactionKeysByPeriodAndTab[selectedPeriodTabKey]
|
|
269
|
-
: undefined;
|
|
270
267
|
// Distinguishes "this tab has never been fetched for this period" from "fetched and genuinely
|
|
271
268
|
// empty". Without it the page cannot tell a first visit from a real empty state, and renders an
|
|
272
269
|
// empty table where it should render a skeleton.
|
|
273
270
|
const hasLoadedForSelectedTab = jeScheduleTransactionKeysForSelectedTab != null;
|
|
274
271
|
const jeScheduleTransactionKeys = jeScheduleTransactionKeysForSelectedTab ?? [];
|
|
275
|
-
const failedJeScheduleTransactionKeys = failedJeScheduleTransactionKeysForSelectedTab ?? [];
|
|
276
272
|
const jeScheduleAccruedKeys = (selectedPeriodTabKey != null
|
|
277
273
|
? jeScheduleAccruedKeysByPeriodAndTab[selectedPeriodTabKey]
|
|
278
274
|
: undefined) ?? [];
|
|
@@ -295,24 +291,57 @@ function getExpenseAutomationJESchedulesView(state) {
|
|
|
295
291
|
accruedSchedules.push(accruedScheduleDetails);
|
|
296
292
|
}
|
|
297
293
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
294
|
+
// Sourced from the tenant-wide bucket, not the per-period one: a failed posting belongs to no
|
|
295
|
+
// close month, and windowing it is what kept older failures off the only tab that can resolve
|
|
296
|
+
// them.
|
|
297
|
+
failedJePostings.jeScheduleTransactionKeys.forEach((jeScheduleKey) => {
|
|
298
|
+
// getJEScheduledTransactionByJEScheduleTransactionKey throws three different ways: it
|
|
299
|
+
// destructures the result of recordGet without a null check, and it raises explicitly for a
|
|
300
|
+
// missing vendor and for a missing base transaction. Catching rather than pre-checking each
|
|
301
|
+
// one keeps this correct if a fourth is added, and none of the three is recoverable here --
|
|
302
|
+
// the row cannot be drawn either way.
|
|
303
|
+
//
|
|
304
|
+
// This matters more for this bucket than anywhere else on the page. It is tenant-wide, so it
|
|
305
|
+
// names schedules the close-month list never loaded, and the group is defined by deleted
|
|
306
|
+
// vendors and deleted categories -- precisely the rows whose entities are most likely to be
|
|
307
|
+
// missing. Unguarded, one such key takes down the whole JE tab instead of dropping one row.
|
|
308
|
+
try {
|
|
309
|
+
failedJeScheduledTransaction.push((0, jeSchedulesSelector_1.getJEScheduledTransactionByJEScheduleTransactionKey)(jeScheduleKey, state));
|
|
310
|
+
}
|
|
311
|
+
catch {
|
|
312
|
+
// Intentionally swallowed: a failed posting we cannot resolve is one missing row, and the
|
|
313
|
+
// alternative is a blank page for every other row too.
|
|
314
|
+
}
|
|
301
315
|
});
|
|
316
|
+
// What the endpoint last reported as failing. The entity store keeps every month a schedule
|
|
317
|
+
// has and an entry resolved by someone else keeps its old `error` array, so `error` alone would
|
|
318
|
+
// leave a Retry button on a posting that is no longer failing.
|
|
319
|
+
const failedScheduledJournalEntryIDs = new Set(failedJePostings.scheduledJournalEntryIDs);
|
|
302
320
|
const { sortKey, sortOrder, selectedJETypeFilter } = uiState;
|
|
321
|
+
const matchesTypeFilter = (schedule) => selectedJETypeFilter == null ||
|
|
322
|
+
getJEScheduleRowType(schedule) === selectedJETypeFilter;
|
|
303
323
|
const unsortedResolveSchedules = [];
|
|
304
324
|
failedJeScheduledTransaction.forEach((schedule) => {
|
|
305
|
-
|
|
325
|
+
// Only the entries that actually carry an error. The schedule's entry array is shared state:
|
|
326
|
+
// opening a schedule's detail page or Quick View replaces it with every month the schedule
|
|
327
|
+
// has, posted ones included, so fanning out over all of them turned one failed posting into a
|
|
328
|
+
// row per month -- and a month that never failed has nothing to resolve, so it rendered with
|
|
329
|
+
// an empty action column.
|
|
330
|
+
//
|
|
331
|
+
// Intersected with the ids the endpoint actually returned, not just `error`: the entry array
|
|
332
|
+
// is a cache of every month, and an entry whose failure someone else resolved keeps its stale
|
|
333
|
+
// error array until something overwrites it. Only what the last fetch named is still failing.
|
|
334
|
+
schedule.scheduledJournalEntry
|
|
335
|
+
.filter((journalEntry) => journalEntry.error.length > 0 &&
|
|
336
|
+
failedScheduledJournalEntryIDs.has(journalEntry.scheduledJournalEntryID))
|
|
337
|
+
.forEach((journalEntry) => {
|
|
306
338
|
unsortedResolveSchedules.push({
|
|
307
339
|
...schedule,
|
|
308
340
|
scheduledJournalEntry: journalEntry,
|
|
309
341
|
});
|
|
310
342
|
});
|
|
311
343
|
});
|
|
312
|
-
const resolveSchedules = sortJEScheduledTransactions(unsortedResolveSchedules, sortKey, sortOrder);
|
|
313
|
-
const validResolveForPending = unsortedResolveSchedules.filter((r) => jeScheduleLocalDataById[r.scheduledJournalEntry.scheduledJournalEntryID] != null);
|
|
314
|
-
const matchesTypeFilter = (schedule) => selectedJETypeFilter == null ||
|
|
315
|
-
getJEScheduleRowType(schedule) === selectedJETypeFilter;
|
|
344
|
+
const resolveSchedules = sortJEScheduledTransactions(unsortedResolveSchedules.filter(matchesTypeFilter), sortKey, sortOrder);
|
|
316
345
|
const isCreatedStatus = (schedule) => {
|
|
317
346
|
// An accrual is "created" once it is not review work: posted, reversing, reversed, or in a
|
|
318
347
|
// transient posting claim.
|
|
@@ -330,7 +359,6 @@ function getExpenseAutomationJESchedulesView(state) {
|
|
|
330
359
|
];
|
|
331
360
|
const pendingReviewSchedules = sortJEScheduledTransactions([
|
|
332
361
|
...allScheduleRows.filter((schedule) => isPendingReviewRow(schedule) && matchesTypeFilter(schedule)),
|
|
333
|
-
...validResolveForPending,
|
|
334
362
|
], sortKey, sortOrder);
|
|
335
363
|
const createdSchedules = sortJEScheduledTransactions(allScheduleRows.filter((schedule) => isCreatedStatus(schedule) && matchesTypeFilter(schedule)), sortKey, sortOrder);
|
|
336
364
|
// KPI summary — derived from unfiltered schedules so counts are always accurate
|
|
@@ -449,6 +477,13 @@ function getExpenseAutomationJESchedulesView(state) {
|
|
|
449
477
|
kpiSummary,
|
|
450
478
|
pendingReviewSchedules,
|
|
451
479
|
pendingReviewTotal,
|
|
480
|
+
failedPostings: resolveSchedules,
|
|
481
|
+
// Exposed so a consumer can tell "still loading" and "the lookup failed" from "nothing has
|
|
482
|
+
// failed". The bucket keeps its rows on failure precisely so an error can be shown beside
|
|
483
|
+
// them, which is only possible if the state travels with them.
|
|
484
|
+
failedPostingsFetchState: failedJePostings.fetchState,
|
|
485
|
+
// Deprecated alias of failedPostings. Still read by the section's footer-form effect and by
|
|
486
|
+
// app-ui analytics; remove once both are repointed.
|
|
452
487
|
resolveSchedules: resolveSchedules,
|
|
453
488
|
accountSettingsView,
|
|
454
489
|
newScheduleView,
|
|
@@ -19,6 +19,7 @@ export type JESchedulePeriodTabKey = `${JEPageTab}_${MonthYearPeriodId}`;
|
|
|
19
19
|
export declare const getJESchedulePeriodTabKey: (selectedPageTab: JEPageTab, monthYearPeriodId: MonthYearPeriodId) => JESchedulePeriodTabKey;
|
|
20
20
|
export interface JESchedulesViewUIState {
|
|
21
21
|
createdGroupCollapsed: boolean;
|
|
22
|
+
failedGroupCollapsed: boolean;
|
|
22
23
|
pendingGroupCollapsed: boolean;
|
|
23
24
|
scrollPosition: {
|
|
24
25
|
scrollTop: number;
|
|
@@ -41,8 +42,23 @@ export interface JEScheduleLocalData {
|
|
|
41
42
|
updatedClassId?: ID;
|
|
42
43
|
updatedVendor?: VendorBase;
|
|
43
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* The Failed Postings bucket, and the only list on this page that is not scoped to a period.
|
|
47
|
+
*
|
|
48
|
+
* A failed posting is broken until someone resolves it, whatever month it belongs to, so windowing
|
|
49
|
+
* it the way the schedule lists are windowed is what hid a March failure from the September close.
|
|
50
|
+
* It therefore has no period-tab key, and its own fetch state rather than the slice's: the list is
|
|
51
|
+
* fetched separately from `/1.0/expenses_automation/failed_je_postings`, so a slow or failing
|
|
52
|
+
* lookup here must not blank the schedules table, or vice versa.
|
|
53
|
+
*/
|
|
54
|
+
export interface FailedJePostingsState {
|
|
55
|
+
fetchState: FetchStateAndError;
|
|
56
|
+
jeScheduleTransactionKeys: JEScheduleTransactionKey[];
|
|
57
|
+
scheduledJournalEntryIDs: ID[];
|
|
58
|
+
}
|
|
44
59
|
export interface JESchedulesViewState extends FetchedState {
|
|
45
60
|
accountSettings: AccountSettingsState;
|
|
61
|
+
failedJePostings: FailedJePostingsState;
|
|
46
62
|
failedJeScheduleTransactionKeysByPeriodAndTab: Record<JESchedulePeriodTabKey, JEScheduleTransactionKey[]>;
|
|
47
63
|
ignoreStatusById: Record<JEScheduleTransactionKey, FetchStateAndError>;
|
|
48
64
|
jeScheduleAccruedKeysByPeriodAndTab: Record<JESchedulePeriodTabKey, JEScheduleKey[]>;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { RecommendationPayload } from '../../../../commonPayloadTypes/recommendationPayload';
|
|
2
|
+
import { ID } from '../../../../commonStateTypes/common';
|
|
1
3
|
import { AccountPayload } from '../../../../entity/account/accountPayload';
|
|
2
4
|
import { ApprovalRulePayload } from '../../../../entity/approvalRule/approvalRulePayload';
|
|
3
5
|
import { BankAccountPayload } from '../../../../entity/bankAccount/bankAccountPayload';
|
|
@@ -28,6 +30,22 @@ export interface BillDetailViewPayload extends ApproveOrRejectBillPayload {
|
|
|
28
30
|
transaction: BillTransactionPayload;
|
|
29
31
|
vendors: VendorPayload[];
|
|
30
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Wire shape of the dedicated recommendations endpoint
|
|
35
|
+
* `GET /1.0/bills/transactions/{transaction_id}/recommendations`.
|
|
36
|
+
*
|
|
37
|
+
* `recommendations` is flat here, not nested under `transaction` the way the
|
|
38
|
+
* bill detail response carries it, and is per line — positionally aligned with
|
|
39
|
+
* `transaction.lines` from the bill detail response. The element is the same
|
|
40
|
+
* shape the bill detail response nests under `transaction.recommendations`.
|
|
41
|
+
*
|
|
42
|
+
* Both fields are optional: a bill with nothing to recommend is a success, not
|
|
43
|
+
* an error.
|
|
44
|
+
*/
|
|
45
|
+
export interface BillRecommendationsPayload {
|
|
46
|
+
recommendations?: RecommendationPayload[];
|
|
47
|
+
transaction_id?: ID;
|
|
48
|
+
}
|
|
31
49
|
export interface EligibleActionsPayload {
|
|
32
50
|
is_refund_eligible: boolean | null;
|
|
33
51
|
is_retry_eligible: {
|
|
@@ -41,6 +59,7 @@ export interface BillDetailQuery {
|
|
|
41
59
|
transaction_type: string;
|
|
42
60
|
}
|
|
43
61
|
export type BillDetailViewResponse = ZeniAPIResponse<BillDetailViewPayload>;
|
|
62
|
+
export type BillRecommendationsResponse = ZeniAPIResponse<BillRecommendationsPayload>;
|
|
44
63
|
export type EligibleActionsResponse = ZeniAPIResponse<EligibleActionsPayload>;
|
|
45
64
|
export type ApproveOrRejectBillResponse = ZeniAPIResponse<ApproveOrRejectBillPayload>;
|
|
46
65
|
export interface PreviousBillsPayload {
|
|
@@ -8,7 +8,16 @@ export declare const fetchBillDetail: import("@reduxjs/toolkit").ActionCreatorWi
|
|
|
8
8
|
isShowDeletedBillsEnabled: boolean;
|
|
9
9
|
hasZeniAssistAccess: boolean;
|
|
10
10
|
cacheOverride: any;
|
|
11
|
-
}, "billDetailView/fetchBillDetail", never, never>,
|
|
11
|
+
}, "billDetailView/fetchBillDetail", never, never>, fetchBillRecommendations: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[billId: string, cacheOverride?: any], {
|
|
12
|
+
billId: string;
|
|
13
|
+
cacheOverride: any;
|
|
14
|
+
}, "billDetailView/fetchBillRecommendations", never, never>, fetchBillRecommendationsSuccess: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[billId: string, didWriteRecommendations?: any], {
|
|
15
|
+
billId: string;
|
|
16
|
+
didWriteRecommendations: any;
|
|
17
|
+
}, "billDetailView/fetchBillRecommendationsSuccess", never, never>, fetchBillRecommendationsFailure: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[billId: string, error: ZeniAPIStatus<Record<string, unknown>>], {
|
|
18
|
+
billId: string;
|
|
19
|
+
error: ZeniAPIStatus<Record<string, unknown>>;
|
|
20
|
+
}, "billDetailView/fetchBillRecommendationsFailure", never, never>, updateBillDetail: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
12
21
|
billDetail: BillDetailViewPayload;
|
|
13
22
|
billId: ID;
|
|
14
23
|
}, "billDetailView/updateBillDetail">, updateBillDetailFetchState: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[billId: string, fetchState: FetchState, error?: ZeniAPIStatus<Record<string, unknown>> | undefined, vendorId?: string | undefined], {
|
|
@@ -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.retryOrRefundBillFailure = exports.retryOrRefundBillSuccess = exports.retryOrRefundBill = exports.updateFetchEligibleActionsFailureState = exports.updateEligibleActionsForBill = exports.fetchEligibleActionsForBill = exports.waitForVendorByNameThenUpdateBillDetail = exports.cancelAndDeleteBillSuccessOrFailure = exports.cancelAndDeleteBill = exports.updateApprovalStatusOnSuccess = exports.approveOrRejectBillFailure = exports.approveOrRejectBillSuccess = exports.approveOrRejectBill = exports.deleteBillSuccessOrFailure = exports.deleteBill = exports.removeBillDetail = exports.updateBillDetailFetchState = exports.updateBillDetail = exports.fetchBillDetail = exports.initialState = void 0;
|
|
7
|
+
exports.retryOrRefundBillFailure = exports.retryOrRefundBillSuccess = exports.retryOrRefundBill = exports.updateFetchEligibleActionsFailureState = exports.updateEligibleActionsForBill = exports.fetchEligibleActionsForBill = exports.waitForVendorByNameThenUpdateBillDetail = exports.cancelAndDeleteBillSuccessOrFailure = exports.cancelAndDeleteBill = exports.updateApprovalStatusOnSuccess = exports.approveOrRejectBillFailure = exports.approveOrRejectBillSuccess = exports.approveOrRejectBill = exports.deleteBillSuccessOrFailure = exports.deleteBill = exports.removeBillDetail = exports.updateBillDetailFetchState = exports.updateBillDetail = exports.fetchBillRecommendationsFailure = exports.fetchBillRecommendationsSuccess = exports.fetchBillRecommendations = exports.fetchBillDetail = exports.initialState = void 0;
|
|
8
8
|
const toolkit_1 = require("@reduxjs/toolkit");
|
|
9
9
|
const get_1 = __importDefault(require("lodash/get"));
|
|
10
10
|
const rootActions_1 = require("../../../../rootActions");
|
|
@@ -25,6 +25,12 @@ const billDetailView = (0, toolkit_1.createSlice)({
|
|
|
25
25
|
detail.fetchState !== 'In-Progress') {
|
|
26
26
|
draft.billDetailById[key] = {
|
|
27
27
|
...billDetailViewState_1.initialBillDetailView,
|
|
28
|
+
// Deliberately independent of the detail fetch: recommendations
|
|
29
|
+
// are requested separately and must not be reset by a detail
|
|
30
|
+
// refresh, which on the edit route lands right after the
|
|
31
|
+
// recommendations request has already started.
|
|
32
|
+
recommendationsFetchStatus: detail?.recommendationsFetchStatus ??
|
|
33
|
+
billDetailViewState_1.initialBillDetailView.recommendationsFetchStatus,
|
|
28
34
|
};
|
|
29
35
|
}
|
|
30
36
|
},
|
|
@@ -76,6 +82,86 @@ const billDetailView = (0, toolkit_1.createSlice)({
|
|
|
76
82
|
};
|
|
77
83
|
},
|
|
78
84
|
},
|
|
85
|
+
fetchBillRecommendations: {
|
|
86
|
+
reducer(draft, action) {
|
|
87
|
+
const key = (0, billDetailViewState_1.getBillTransactionDetailKey)(action.payload.billId);
|
|
88
|
+
// The edit route can mount before the bill detail entry exists — its
|
|
89
|
+
// screen dispatches this before the parent requests the detail. Seed
|
|
90
|
+
// the entry rather than bailing, or the status would sit at
|
|
91
|
+
// `Not-Started` for the whole wait and round trip.
|
|
92
|
+
const detail = (0, get_1.default)(draft.billDetailById, key, undefined) ?? {
|
|
93
|
+
...billDetailViewState_1.initialBillDetailView,
|
|
94
|
+
billId: action.payload.billId,
|
|
95
|
+
};
|
|
96
|
+
const { fetchState } = detail.recommendationsFetchStatus;
|
|
97
|
+
// Both screens dispatch once per bill — on mount, keyed by bill id,
|
|
98
|
+
// not on every render — so this guard is not what prevents a render
|
|
99
|
+
// loop; the epic's per-bill `exhaustMap` is what collapses the two
|
|
100
|
+
// sites' dispatches into one request.
|
|
101
|
+
//
|
|
102
|
+
// `Error` is deliberately allowed through: a bill whose fetch failed
|
|
103
|
+
// must be able to try again when the screen is next opened.
|
|
104
|
+
if (action.payload.cacheOverride === true ||
|
|
105
|
+
(fetchState !== 'In-Progress' && fetchState !== 'Completed')) {
|
|
106
|
+
draft.billDetailById[key] = {
|
|
107
|
+
...detail,
|
|
108
|
+
recommendationsFetchStatus: {
|
|
109
|
+
fetchState: 'In-Progress',
|
|
110
|
+
error: undefined,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
prepare(billId, cacheOverride = false) {
|
|
116
|
+
return {
|
|
117
|
+
payload: { billId, cacheOverride },
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
fetchBillRecommendationsSuccess: {
|
|
122
|
+
reducer(draft, action) {
|
|
123
|
+
const key = (0, billDetailViewState_1.getBillTransactionDetailKey)(action.payload.billId);
|
|
124
|
+
const detail = (0, get_1.default)(draft.billDetailById, key, undefined);
|
|
125
|
+
if (detail != null) {
|
|
126
|
+
draft.billDetailById[key] = {
|
|
127
|
+
...detail,
|
|
128
|
+
recommendationsFetchStatus: {
|
|
129
|
+
fetchState: 'Completed',
|
|
130
|
+
error: undefined,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
// `didWriteRecommendations` is false on the skip paths, which resolve
|
|
136
|
+
// the status without fetching anything. Consumers that react by
|
|
137
|
+
// recomputing local state must not run then — there is nothing new to
|
|
138
|
+
// apply, and recomputing would reset the line's "update to" selections.
|
|
139
|
+
prepare(billId, didWriteRecommendations = false) {
|
|
140
|
+
return {
|
|
141
|
+
payload: { billId, didWriteRecommendations },
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
fetchBillRecommendationsFailure: {
|
|
146
|
+
reducer(draft, action) {
|
|
147
|
+
const key = (0, billDetailViewState_1.getBillTransactionDetailKey)(action.payload.billId);
|
|
148
|
+
const detail = (0, get_1.default)(draft.billDetailById, key, undefined);
|
|
149
|
+
if (detail != null) {
|
|
150
|
+
draft.billDetailById[key] = {
|
|
151
|
+
...detail,
|
|
152
|
+
recommendationsFetchStatus: {
|
|
153
|
+
fetchState: 'Error',
|
|
154
|
+
error: action.payload.error,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
prepare(billId, error) {
|
|
160
|
+
return {
|
|
161
|
+
payload: { billId, error },
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
},
|
|
79
165
|
deleteBill: {
|
|
80
166
|
reducer(draft, action) {
|
|
81
167
|
const key = (0, billDetailViewState_1.getBillTransactionDetailKey)(action.payload.billId);
|
|
@@ -469,5 +555,5 @@ const billDetailView = (0, toolkit_1.createSlice)({
|
|
|
469
555
|
});
|
|
470
556
|
},
|
|
471
557
|
});
|
|
472
|
-
_a = billDetailView.actions, exports.fetchBillDetail = _a.fetchBillDetail, exports.updateBillDetail = _a.updateBillDetail, exports.updateBillDetailFetchState = _a.updateBillDetailFetchState, exports.removeBillDetail = _a.removeBillDetail, exports.deleteBill = _a.deleteBill, exports.deleteBillSuccessOrFailure = _a.deleteBillSuccessOrFailure, exports.approveOrRejectBill = _a.approveOrRejectBill, exports.approveOrRejectBillSuccess = _a.approveOrRejectBillSuccess, exports.approveOrRejectBillFailure = _a.approveOrRejectBillFailure, exports.updateApprovalStatusOnSuccess = _a.updateApprovalStatusOnSuccess, exports.cancelAndDeleteBill = _a.cancelAndDeleteBill, exports.cancelAndDeleteBillSuccessOrFailure = _a.cancelAndDeleteBillSuccessOrFailure, exports.waitForVendorByNameThenUpdateBillDetail = _a.waitForVendorByNameThenUpdateBillDetail, exports.fetchEligibleActionsForBill = _a.fetchEligibleActionsForBill, exports.updateEligibleActionsForBill = _a.updateEligibleActionsForBill, exports.updateFetchEligibleActionsFailureState = _a.updateFetchEligibleActionsFailureState, exports.retryOrRefundBill = _a.retryOrRefundBill, exports.retryOrRefundBillSuccess = _a.retryOrRefundBillSuccess, exports.retryOrRefundBillFailure = _a.retryOrRefundBillFailure;
|
|
558
|
+
_a = billDetailView.actions, exports.fetchBillDetail = _a.fetchBillDetail, exports.fetchBillRecommendations = _a.fetchBillRecommendations, exports.fetchBillRecommendationsSuccess = _a.fetchBillRecommendationsSuccess, exports.fetchBillRecommendationsFailure = _a.fetchBillRecommendationsFailure, exports.updateBillDetail = _a.updateBillDetail, exports.updateBillDetailFetchState = _a.updateBillDetailFetchState, exports.removeBillDetail = _a.removeBillDetail, exports.deleteBill = _a.deleteBill, exports.deleteBillSuccessOrFailure = _a.deleteBillSuccessOrFailure, exports.approveOrRejectBill = _a.approveOrRejectBill, exports.approveOrRejectBillSuccess = _a.approveOrRejectBillSuccess, exports.approveOrRejectBillFailure = _a.approveOrRejectBillFailure, exports.updateApprovalStatusOnSuccess = _a.updateApprovalStatusOnSuccess, exports.cancelAndDeleteBill = _a.cancelAndDeleteBill, exports.cancelAndDeleteBillSuccessOrFailure = _a.cancelAndDeleteBillSuccessOrFailure, exports.waitForVendorByNameThenUpdateBillDetail = _a.waitForVendorByNameThenUpdateBillDetail, exports.fetchEligibleActionsForBill = _a.fetchEligibleActionsForBill, exports.updateEligibleActionsForBill = _a.updateEligibleActionsForBill, exports.updateFetchEligibleActionsFailureState = _a.updateFetchEligibleActionsFailureState, exports.retryOrRefundBill = _a.retryOrRefundBill, exports.retryOrRefundBillSuccess = _a.retryOrRefundBillSuccess, exports.retryOrRefundBillFailure = _a.retryOrRefundBillFailure;
|
|
473
559
|
exports.default = billDetailView.reducer;
|
|
@@ -42,6 +42,7 @@ export interface BillDetailViewSelector extends SelectorView {
|
|
|
42
42
|
outsideZeniPaymentInfo?: OutsideZeniPaymentLocalData;
|
|
43
43
|
paymentInstrument?: PaymentInstrument;
|
|
44
44
|
paymentMethodType?: BillPayConfig;
|
|
45
|
+
recommendationsFetchStatus?: FetchStateAndError;
|
|
45
46
|
recurringBillConfigDetail?: RecurringBillConfig;
|
|
46
47
|
recurringBillInstances?: RecurringBillData[];
|
|
47
48
|
transactionDetails?: BillTransaction;
|
|
@@ -226,6 +226,7 @@ const getBillDetailView = (state, billId) => {
|
|
|
226
226
|
fetchState: fetchState.fetchState,
|
|
227
227
|
error: fetchState.error,
|
|
228
228
|
version: 0,
|
|
229
|
+
recommendationsFetchStatus: billTransactionDetails?.recommendationsFetchStatus,
|
|
229
230
|
transactionDetails: transaction,
|
|
230
231
|
createdBy,
|
|
231
232
|
bankAccount,
|
|
@@ -11,6 +11,13 @@ export interface BillDetailView extends FetchedState {
|
|
|
11
11
|
deleteStatus: FetchStateAndError;
|
|
12
12
|
entityApprovalIds: ID[];
|
|
13
13
|
eventIds: ID[];
|
|
14
|
+
/**
|
|
15
|
+
* Status of the standalone recommendations fetch for this bill.
|
|
16
|
+
* Deliberately NOT folded into `fetchState` (or any `reduceFetchState` list)
|
|
17
|
+
* so a slow or failing recommendations call can never hold back — or error
|
|
18
|
+
* out — the bill detail / bill edit screens.
|
|
19
|
+
*/
|
|
20
|
+
recommendationsFetchStatus: FetchStateAndError;
|
|
14
21
|
zeniAssist: ZeniAssistForBills;
|
|
15
22
|
billId?: ID;
|
|
16
23
|
vendorId?: ID;
|
package/lib/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { updateBillTransactionRecommendations } from '../../../../../entity/billPay/billTransaction/billTransactionReducer';
|
|
4
|
+
import { RootState } from '../../../../../reducer';
|
|
5
|
+
import { ZeniAPI } from '../../../../../zeniAPI';
|
|
6
|
+
import { fetchBillRecommendations, fetchBillRecommendationsFailure, fetchBillRecommendationsSuccess, updateBillDetail, updateBillDetailFetchState } from '../billDetailViewReducer';
|
|
7
|
+
export type ActionType = ReturnType<typeof fetchBillRecommendations> | ReturnType<typeof fetchBillRecommendationsSuccess> | ReturnType<typeof fetchBillRecommendationsFailure> | ReturnType<typeof updateBillDetail> | ReturnType<typeof updateBillDetailFetchState> | ReturnType<typeof updateBillTransactionRecommendations>;
|
|
8
|
+
/**
|
|
9
|
+
* Standalone recommendations fetch for a bill, so neither the bill detail nor
|
|
10
|
+
* the bill edit screen waits on recommendation composition.
|
|
11
|
+
*
|
|
12
|
+
* Which bills need it is decided from the bill's stage: an approval-stage bill
|
|
13
|
+
* gets them from the dedicated endpoint
|
|
14
|
+
* (`GET /1.0/bills/transactions/{transaction_id}/recommendations`), while a
|
|
15
|
+
* draft gets them on the bill detail response itself. The platform makes that
|
|
16
|
+
* split from the bill's status, so neither request carries a flag asking for
|
|
17
|
+
* one behaviour or the other.
|
|
18
|
+
*
|
|
19
|
+
* Only `recommendations` is read — per line, and what drives the "Update to X"
|
|
20
|
+
* checkbox and the Recommended group in the category/class dropdowns. The
|
|
21
|
+
* endpoint returns no entity-level recommendation and the edit form does not
|
|
22
|
+
* render one.
|
|
23
|
+
*
|
|
24
|
+
* Failure is confined to `recommendationsFetchStatus` — no bill-detail action
|
|
25
|
+
* is emitted, so a failed or slow recommendations fetch can neither block nor
|
|
26
|
+
* error out either screen.
|
|
27
|
+
*
|
|
28
|
+
* @precondition Every site dispatching `fetchBillRecommendations` must also
|
|
29
|
+
* cause the bill detail to be requested for that bill. This epic waits for the
|
|
30
|
+
* detail when it is not already in the store, and that wait settles only on a
|
|
31
|
+
* detail write or a detail error. A caller that dispatches without one would
|
|
32
|
+
* leave the wait open, and the per-bill `exhaustMap` would then drop later
|
|
33
|
+
* retries for that bill. Both current callers satisfy this: the bill detail
|
|
34
|
+
* route dispatches `fetchBillDetail` alongside, and the edit route reaches it
|
|
35
|
+
* through `fetchEditBillDetailPage`.
|
|
36
|
+
*/
|
|
37
|
+
export declare const fetchBillRecommendationsEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fetchBillRecommendationsEpic = void 0;
|
|
7
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
8
|
+
const rxjs_1 = require("rxjs");
|
|
9
|
+
const operators_1 = require("rxjs/operators");
|
|
10
|
+
const responsePayload_1 = require("../../../../../responsePayload");
|
|
11
|
+
const billDetailViewReducer_1 = require("../billDetailViewReducer");
|
|
12
|
+
const billDetailViewState_1 = require("../billDetailViewState");
|
|
13
|
+
const fetchRecommendationsForBill_1 = require("./fetchRecommendationsForBill");
|
|
14
|
+
/**
|
|
15
|
+
* Standalone recommendations fetch for a bill, so neither the bill detail nor
|
|
16
|
+
* the bill edit screen waits on recommendation composition.
|
|
17
|
+
*
|
|
18
|
+
* Which bills need it is decided from the bill's stage: an approval-stage bill
|
|
19
|
+
* gets them from the dedicated endpoint
|
|
20
|
+
* (`GET /1.0/bills/transactions/{transaction_id}/recommendations`), while a
|
|
21
|
+
* draft gets them on the bill detail response itself. The platform makes that
|
|
22
|
+
* split from the bill's status, so neither request carries a flag asking for
|
|
23
|
+
* one behaviour or the other.
|
|
24
|
+
*
|
|
25
|
+
* Only `recommendations` is read — per line, and what drives the "Update to X"
|
|
26
|
+
* checkbox and the Recommended group in the category/class dropdowns. The
|
|
27
|
+
* endpoint returns no entity-level recommendation and the edit form does not
|
|
28
|
+
* render one.
|
|
29
|
+
*
|
|
30
|
+
* Failure is confined to `recommendationsFetchStatus` — no bill-detail action
|
|
31
|
+
* is emitted, so a failed or slow recommendations fetch can neither block nor
|
|
32
|
+
* error out either screen.
|
|
33
|
+
*
|
|
34
|
+
* @precondition Every site dispatching `fetchBillRecommendations` must also
|
|
35
|
+
* cause the bill detail to be requested for that bill. This epic waits for the
|
|
36
|
+
* detail when it is not already in the store, and that wait settles only on a
|
|
37
|
+
* detail write or a detail error. A caller that dispatches without one would
|
|
38
|
+
* leave the wait open, and the per-bill `exhaustMap` would then drop later
|
|
39
|
+
* retries for that bill. Both current callers satisfy this: the bill detail
|
|
40
|
+
* route dispatches `fetchBillDetail` alongside, and the edit route reaches it
|
|
41
|
+
* through `fetchEditBillDetailPage`.
|
|
42
|
+
*/
|
|
43
|
+
const fetchBillRecommendationsEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(billDetailViewReducer_1.fetchBillRecommendations.match),
|
|
44
|
+
// The bill detail route requests these and the edit screen asks again on
|
|
45
|
+
// every mount, so repeats are normal. Drop the ones whose bill is already
|
|
46
|
+
// done before they reach the request.
|
|
47
|
+
(0, operators_1.filter)((action) => action.payload.cacheOverride === true ||
|
|
48
|
+
areRecommendationsAlreadyFetched(state$.value, action.payload.billId) === false),
|
|
49
|
+
// Per bill, then `exhaustMap` rather than `switchMap`: a repeat that
|
|
50
|
+
// arrives while the request (or the wait for the bill detail) is still
|
|
51
|
+
// running is ignored, where `switchMap` would cancel the in-flight one and
|
|
52
|
+
// re-issue it. `groupBy` keeps that per bill, so navigating to another
|
|
53
|
+
// bill mid-flight still fetches for the new one.
|
|
54
|
+
(0, operators_1.groupBy)((action) => action.payload.billId), (0, operators_1.mergeMap)((actionsForBill$) => actionsForBill$.pipe((0, operators_1.exhaustMap)((action) => {
|
|
55
|
+
const { billId, cacheOverride } = action.payload;
|
|
56
|
+
if (isBillReadyForRecommendations(state$.value, billId)) {
|
|
57
|
+
return (0, fetchRecommendationsForBill_1.fetchRecommendationsForBill)(state$.value, billId, zeniAPI, cacheOverride);
|
|
58
|
+
}
|
|
59
|
+
// The edit route can mount before the bill detail response lands,
|
|
60
|
+
// and the request needs the vendor / line ids / amount from it. Wait
|
|
61
|
+
// for the detail write for this bill rather than dropping the fetch,
|
|
62
|
+
// and settle on a detail error too.
|
|
63
|
+
//
|
|
64
|
+
// A leftover `Error` on the bill detail is deliberately NOT treated
|
|
65
|
+
// as terminal here. On the edit route this action is dispatched
|
|
66
|
+
// before the parent screen re-requests the detail — React runs the
|
|
67
|
+
// child's effect first — so failing on the stale error would leave
|
|
68
|
+
// recommendations failed even though the detail is about to succeed.
|
|
69
|
+
//
|
|
70
|
+
// The invariant this relies on: every dispatch site also causes the
|
|
71
|
+
// bill detail to be requested. Both do today. A future site that
|
|
72
|
+
// does not would leave this waiting, and `exhaustMap` would drop
|
|
73
|
+
// later retries for that bill.
|
|
74
|
+
const billDetailSettled$ = actions$.pipe((0, operators_1.filter)((waited) => {
|
|
75
|
+
if (billDetailViewReducer_1.updateBillDetail.match(waited)) {
|
|
76
|
+
return waited.payload.billId === billId;
|
|
77
|
+
}
|
|
78
|
+
return (billDetailViewReducer_1.updateBillDetailFetchState.match(waited) &&
|
|
79
|
+
waited.payload.fetchState === 'Error' &&
|
|
80
|
+
waited.payload.billId === billId);
|
|
81
|
+
}), (0, operators_1.take)(1) // don't listen forever! IMPORTANT!
|
|
82
|
+
);
|
|
83
|
+
return billDetailSettled$.pipe((0, operators_1.mergeMap)((waited) => {
|
|
84
|
+
if (billDetailViewReducer_1.updateBillDetail.match(waited)) {
|
|
85
|
+
return (0, fetchRecommendationsForBill_1.fetchRecommendationsForBill)(state$.value, billId, zeniAPI, cacheOverride);
|
|
86
|
+
}
|
|
87
|
+
// Bill detail failed; there is nothing to recommend against.
|
|
88
|
+
return (0, rxjs_1.of)((0, billDetailViewReducer_1.fetchBillRecommendationsFailure)(billId, waited.payload.error ??
|
|
89
|
+
(0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Bill detail fetch failed before recommendations could be requested')));
|
|
90
|
+
}));
|
|
91
|
+
}))));
|
|
92
|
+
exports.fetchBillRecommendationsEpic = fetchBillRecommendationsEpic;
|
|
93
|
+
/**
|
|
94
|
+
* Helper functions
|
|
95
|
+
*/
|
|
96
|
+
function areRecommendationsAlreadyFetched(state, billId) {
|
|
97
|
+
const billDetail = (0, get_1.default)(state.billDetailViewState.billDetailById, (0, billDetailViewState_1.getBillTransactionDetailKey)(billId), undefined);
|
|
98
|
+
return billDetail?.recommendationsFetchStatus.fetchState === 'Completed';
|
|
99
|
+
}
|
|
100
|
+
function isBillReadyForRecommendations(state, billId) {
|
|
101
|
+
const billDetail = (0, get_1.default)(state.billDetailViewState.billDetailById, (0, billDetailViewState_1.getBillTransactionDetailKey)(billId), undefined);
|
|
102
|
+
return (billDetail?.fetchState === 'Completed' &&
|
|
103
|
+
(0, fetchRecommendationsForBill_1.getBillTransaction)(state, billId) != null);
|
|
104
|
+
}
|
package/lib/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { ID } from '../../../../../commonStateTypes/common';
|
|
3
|
+
import { updateBillTransactionRecommendations } from '../../../../../entity/billPay/billTransaction/billTransactionReducer';
|
|
4
|
+
import { BillTransaction } from '../../../../../entity/billPay/billTransaction/billTransactionState';
|
|
5
|
+
import { RootState } from '../../../../../reducer';
|
|
6
|
+
import { ZeniAPI } from '../../../../../zeniAPI';
|
|
7
|
+
import { fetchBillRecommendationsFailure, fetchBillRecommendationsSuccess } from '../billDetailViewReducer';
|
|
8
|
+
/**
|
|
9
|
+
* What the request itself can emit. `fetchBillRecommendationsEpic` widens this
|
|
10
|
+
* with the actions it consumes; keeping the narrower union here is what lets
|
|
11
|
+
* this module stay free of any import from the epic.
|
|
12
|
+
*/
|
|
13
|
+
export type FetchRecommendationsForBillActionType = ReturnType<typeof fetchBillRecommendationsSuccess> | ReturnType<typeof fetchBillRecommendationsFailure> | ReturnType<typeof updateBillTransactionRecommendations>;
|
|
14
|
+
/**
|
|
15
|
+
* Requests the recommendations for one bill and maps them onto the transaction
|
|
16
|
+
* entity, or resolves without a request for a bill that does not need them.
|
|
17
|
+
*
|
|
18
|
+
* Only `recommendations` is read from the response — per line, and what drives
|
|
19
|
+
* the "Update to X" checkbox and the Recommended group in the category/class
|
|
20
|
+
* dropdowns. The endpoint returns no entity-level recommendation and the edit
|
|
21
|
+
* form does not render one.
|
|
22
|
+
*/
|
|
23
|
+
export declare function fetchRecommendationsForBill(state: RootState, billId: ID, zeniAPI: ZeniAPI, cacheOverride?: boolean): Observable<FetchRecommendationsForBillActionType>;
|
|
24
|
+
export declare function getBillTransaction(state: RootState, billId: ID): BillTransaction | undefined;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fetchRecommendationsForBill = fetchRecommendationsForBill;
|
|
7
|
+
exports.getBillTransaction = getBillTransaction;
|
|
8
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
9
|
+
const rxjs_1 = require("rxjs");
|
|
10
|
+
const operators_1 = require("rxjs/operators");
|
|
11
|
+
const recommendationPayload_1 = require("../../../../../commonPayloadTypes/recommendationPayload");
|
|
12
|
+
const billTransactionReducer_1 = require("../../../../../entity/billPay/billTransaction/billTransactionReducer");
|
|
13
|
+
const responsePayload_1 = require("../../../../../responsePayload");
|
|
14
|
+
const billDetailViewReducer_1 = require("../billDetailViewReducer");
|
|
15
|
+
/**
|
|
16
|
+
* Requests the recommendations for one bill and maps them onto the transaction
|
|
17
|
+
* entity, or resolves without a request for a bill that does not need them.
|
|
18
|
+
*
|
|
19
|
+
* Only `recommendations` is read from the response — per line, and what drives
|
|
20
|
+
* the "Update to X" checkbox and the Recommended group in the category/class
|
|
21
|
+
* dropdowns. The endpoint returns no entity-level recommendation and the edit
|
|
22
|
+
* form does not render one.
|
|
23
|
+
*/
|
|
24
|
+
function fetchRecommendationsForBill(state, billId, zeniAPI, cacheOverride = false) {
|
|
25
|
+
const transaction = getBillTransaction(state, billId);
|
|
26
|
+
const lineIds = transaction?.lines?.map((line) => line.id) ?? [];
|
|
27
|
+
if (transaction == null ||
|
|
28
|
+
shouldSkipRecommendations(transaction, cacheOverride)) {
|
|
29
|
+
return (0, rxjs_1.of)((0, billDetailViewReducer_1.fetchBillRecommendationsSuccess)(billId));
|
|
30
|
+
}
|
|
31
|
+
// The bill is scoped by the path, so this endpoint takes no query — there is
|
|
32
|
+
// no `is_include_*` flag to turn off the way the bill detail request has.
|
|
33
|
+
return zeniAPI
|
|
34
|
+
.getJSON(`${zeniAPI.apiEndPoints.spendManagementMicroServiceBaseUrl}/1.0/bills/transactions/${billId}/recommendations`)
|
|
35
|
+
.pipe((0, operators_1.mergeMap)((response) => {
|
|
36
|
+
if (!(0, responsePayload_1.isSuccessResponse)(response) || response.data == null) {
|
|
37
|
+
return (0, rxjs_1.of)((0, billDetailViewReducer_1.fetchBillRecommendationsFailure)(billId, response.status));
|
|
38
|
+
}
|
|
39
|
+
const actions = [];
|
|
40
|
+
// Positional line <-> recommendation mapping, matching
|
|
41
|
+
// `getRecommendationsPerLine` — the mapping the recommendations went
|
|
42
|
+
// through while the bill detail response still carried them. This
|
|
43
|
+
// endpoint returns them flat, not nested under `transaction`.
|
|
44
|
+
const recommendationPayloads = response.data.recommendations ?? [];
|
|
45
|
+
// The pairing is a convention shared with the platform, not
|
|
46
|
+
// something the payload enforces, so a mismatch would otherwise
|
|
47
|
+
// mis-assign or silently drop recommendations. Degrade safely —
|
|
48
|
+
// extra entries are ignored and unmatched lines get none — but say
|
|
49
|
+
// so, because it means the two sides have diverged.
|
|
50
|
+
if (recommendationPayloads.length !== lineIds.length) {
|
|
51
|
+
console.warn(`Bill ${billId}: ${recommendationPayloads.length} recommendation entries for ${lineIds.length} lines. ` +
|
|
52
|
+
'They are paired by position, so this bill may be scored incorrectly.');
|
|
53
|
+
}
|
|
54
|
+
const recommendationByLineId = {};
|
|
55
|
+
lineIds.forEach((lineId, index) => {
|
|
56
|
+
const recommendationPayload = recommendationPayloads[index];
|
|
57
|
+
if (recommendationPayload != null) {
|
|
58
|
+
recommendationByLineId[lineId] = (0, recommendationPayload_1.transformRecommendation)(recommendationPayload);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
actions.push((0, billTransactionReducer_1.updateBillTransactionRecommendations)(billId, recommendationByLineId));
|
|
62
|
+
// Entity writes first, then the view status, so consumers reading on
|
|
63
|
+
// the status flip already see the recommendations.
|
|
64
|
+
actions.push((0, billDetailViewReducer_1.fetchBillRecommendationsSuccess)(billId, true));
|
|
65
|
+
return (0, rxjs_1.from)(actions);
|
|
66
|
+
}), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, billDetailViewReducer_1.fetchBillRecommendationsFailure)(billId, (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', `Fetch bill recommendations REST API call errored out ${error}`)))));
|
|
67
|
+
}
|
|
68
|
+
function getBillTransaction(state, billId) {
|
|
69
|
+
return (0, get_1.default)(state.billTransactionState.transactionById, billId, undefined);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Helper functions
|
|
73
|
+
*/
|
|
74
|
+
// Awaiting-approval bills are the only ones this request exists for. A draft
|
|
75
|
+
// opens the edit form directly, so its recommendations ride along on the bill
|
|
76
|
+
// detail response; `paid` bills cannot reach the form at all. The platform
|
|
77
|
+
// decides which of those two it is from the bill's status, which is why the
|
|
78
|
+
// request carries no flag asking for either.
|
|
79
|
+
function shouldSkipRecommendations(transaction, cacheOverride) {
|
|
80
|
+
return (transaction.billPayInfo.stage.code !== 'pending_approval' ||
|
|
81
|
+
transaction.isDeleted === true ||
|
|
82
|
+
// No vendor (a draft carrying only a candidate vendor name) means no
|
|
83
|
+
// entity to recommend against — the vendor-selection flow covers that.
|
|
84
|
+
Boolean(transaction.vendor?.id) === false ||
|
|
85
|
+
// The bill detail response already carried them. `toVendorTransaction`
|
|
86
|
+
// maps them straight onto the entity, so requesting again would only
|
|
87
|
+
// re-fetch what is here — this is what lets the platform move the line
|
|
88
|
+
// between embedded and on-demand without a client change. A forced
|
|
89
|
+
// refresh is the one case that still goes to the endpoint.
|
|
90
|
+
(cacheOverride === false &&
|
|
91
|
+
Object.keys(transaction.recommendations ?? {}).length > 0));
|
|
92
|
+
}
|