-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Revert "follow-up: Start & End date does not matches Title format with Trip-based Auto-reporting" #86918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert "follow-up: Start & End date does not matches Title format with Trip-based Auto-reporting" #86918
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,7 +138,6 @@ | |
| canEditFieldOfMoneyRequest, | ||
| canSubmitAndIsAwaitingForCurrentUser, | ||
| canUserPerformWriteAction as canUserPerformWriteActionReportUtils, | ||
| computeOptimisticReportName, | ||
| findSelfDMReportID, | ||
| generateReportID, | ||
| getAllHeldTransactions as getAllHeldTransactionsReportUtils, | ||
|
|
@@ -189,6 +188,7 @@ | |
| isSettled, | ||
| isTestTransactionReport, | ||
| isTrackExpenseReport, | ||
| populateOptimisticReportFormula, | ||
| prepareOnboardingOnyxData, | ||
| shouldCreateNewMoneyRequestReport as shouldCreateNewMoneyRequestReportReportUtils, | ||
| shouldEnableNegative, | ||
|
|
@@ -792,7 +792,7 @@ | |
| }; | ||
|
|
||
| let allPersonalDetails: OnyxTypes.PersonalDetailsList = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.PERSONAL_DETAILS_LIST, | ||
| callback: (value) => { | ||
| allPersonalDetails = value ?? {}; | ||
|
|
@@ -925,7 +925,7 @@ | |
| }; | ||
|
|
||
| let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.TRANSACTION, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
|
|
@@ -939,7 +939,7 @@ | |
| }); | ||
|
|
||
| let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
|
|
@@ -948,7 +948,7 @@ | |
| }); | ||
|
|
||
| let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
|
|
@@ -962,7 +962,7 @@ | |
| }); | ||
|
|
||
| let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.POLICY_TAGS, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
|
|
@@ -975,7 +975,7 @@ | |
| }); | ||
|
|
||
| let allReports: OnyxCollection<OnyxTypes.Report>; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.REPORT, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
|
|
@@ -984,7 +984,7 @@ | |
| }); | ||
|
|
||
| let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
|
|
@@ -994,7 +994,7 @@ | |
|
|
||
| let deprecatedUserAccountID = -1; | ||
| let deprecatedCurrentUserEmail = ''; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.SESSION, | ||
| callback: (value) => { | ||
| deprecatedCurrentUserEmail = value?.email ?? ''; | ||
|
|
@@ -1003,7 +1003,7 @@ | |
| }); | ||
|
|
||
| let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.PERSONAL_DETAILS_LIST, | ||
| callback: (value) => { | ||
| deprecatedCurrentUserPersonalDetails = value?.[deprecatedUserAccountID] ?? undefined; | ||
|
|
@@ -1011,7 +1011,7 @@ | |
| }); | ||
|
|
||
| let allReportActions: OnyxCollection<OnyxTypes.ReportActions>; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, | ||
| waitForCollectionCallback: true, | ||
| callback: (actions) => { | ||
|
|
@@ -3192,45 +3192,25 @@ | |
| * This is needed when report totals change (e.g., adding expenses or changing reimbursable status) | ||
| * to ensure the report title reflects the updated values like {report:reimbursable}. | ||
| */ | ||
| function recalculateOptimisticReportName(iouReport: OnyxTypes.Report, policy: OnyxEntry<OnyxTypes.Policy>, newTransaction?: OnyxTypes.Transaction): string | undefined { | ||
| function recalculateOptimisticReportName(iouReport: OnyxTypes.Report, policy: OnyxEntry<OnyxTypes.Policy>): string | undefined { | ||
| if (!policy?.fieldList?.[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]) { | ||
| return undefined; | ||
| } | ||
| const titleFormula = policy.fieldList[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]?.defaultValue ?? ''; | ||
| if (!titleFormula) { | ||
| return undefined; | ||
| } | ||
|
|
||
| // Gather existing transactions + the optimistic one not yet in Onyx. | ||
| const existingTransactions = getReportTransactions(iouReport.reportID); | ||
| const transactionsRecord: Record<string, OnyxTypes.Transaction> = {}; | ||
| for (const transaction of existingTransactions) { | ||
| if (transaction?.transactionID) { | ||
| transactionsRecord[transaction.transactionID] = transaction; | ||
| } | ||
| } | ||
| if (newTransaction?.transactionID) { | ||
| transactionsRecord[newTransaction.transactionID] = newTransaction; | ||
| } | ||
|
|
||
| const computedName = computeOptimisticReportName(iouReport, policy, iouReport.policyID, transactionsRecord); | ||
| return computedName ?? undefined; | ||
| return populateOptimisticReportFormula(titleFormula, iouReport as Parameters<typeof populateOptimisticReportFormula>[1], policy); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| function maybeUpdateReportNameForFormulaTitle(iouReport: OnyxTypes.Report, policy: OnyxEntry<OnyxTypes.Policy>, newTransaction?: OnyxTypes.Transaction): OnyxTypes.Report { | ||
| function maybeUpdateReportNameForFormulaTitle(iouReport: OnyxTypes.Report, policy: OnyxEntry<OnyxTypes.Policy>): OnyxTypes.Report { | ||
| const reportNameValuePairs = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`]; | ||
| const titleField = reportNameValuePairs?.expensify_text_title; | ||
|
|
||
| // Fall back to policy.fieldList when reportNameValuePairs doesn't exist yet (optimistic reports). | ||
| const isFormulaTitle = reportNameValuePairs | ||
| ? titleField?.type === CONST.REPORT_FIELD_TYPES.FORMULA | ||
| : policy?.fieldList?.[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]?.type === CONST.REPORT_FIELD_TYPES.FORMULA; | ||
|
|
||
| if (!isFormulaTitle) { | ||
| if (titleField?.type !== CONST.REPORT_FIELD_TYPES.FORMULA) { | ||
| return iouReport; | ||
| } | ||
|
|
||
| const updatedReportName = recalculateOptimisticReportName(iouReport, policy, newTransaction); | ||
| const updatedReportName = recalculateOptimisticReportName(iouReport, policy); | ||
| if (!updatedReportName) { | ||
| return iouReport; | ||
| } | ||
|
|
@@ -3414,6 +3394,8 @@ | |
| iouReport.nonReimbursableTotal = (iouReport.nonReimbursableTotal ?? 0) - amount; | ||
| } | ||
| } | ||
|
|
||
| iouReport = maybeUpdateReportNameForFormulaTitle(iouReport, policy); | ||
| } | ||
| if (typeof iouReport.unheldTotal === 'number') { | ||
| // Use newReportTotal in scenarios where the total is based on more than just the current transaction amount, and we need to override it manually | ||
|
|
@@ -3515,11 +3497,6 @@ | |
| } | ||
| } | ||
|
|
||
| // Recalculate report name after STEP 3 so the optimistic transaction is included in formula computation. | ||
| if (!shouldCreateNewMoneyRequestReport && isPolicyExpenseChat) { | ||
| iouReport = maybeUpdateReportNameForFormulaTitle(iouReport, policy, optimisticTransaction); | ||
| } | ||
|
|
||
| // STEP 4: Build optimistic reportActions. We need: | ||
| // 1. CREATED action for the chatReport | ||
| // 2. CREATED action for the iouReport | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
computeAutoReportingInfo()stopped forwardingFormulaContextintogetAutoReportingDates(), so trip auto-reporting dates can no longer see optimistic/context transactions during expense creation and edit flows. In practice,{report:autoreporting:start|end}may be computed from stale Onyx data (or current time fallbacks) until sync completes, which reintroduces incorrect optimistic titles/date ranges for trip-based reports.Useful? React with 👍 / 👎.