Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.53k stars 2.88k forks source link

[$250] Expense - Report header title changes to Workspace owes X after editing custom name field #51862

Open lanitochka17 opened 6 days ago

lanitochka17 commented 6 days ago

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.56-2 Reproducible in staging?: Y Reproducible in production?: Y If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Y If this was caught during regression testing, add the test name, ID and link from TestRail: N/A Email or phone of affected tester (no customers): applausetester+kh2310001@applause.expensifail.com Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Create a new workspace
  3. Go to workspace chat and submit an expense
  4. Open expense report
  5. Note that the report header title is Expense Report #number
  6. Go to workspace settings
  7. Enable Report fields and Rules
  8. Go to Rules
  9. Enable Custom report names
  10. Click Custom name, edit the name and save it
  11. Go back to the expense report in Step 4
  12. Click Title field
  13. Rename the title and save it

Expected Result:

The report header title should still display Expense Report #number (Old Dot behavior)

Actual Result:

The report header title changes to Workspace owes X after editing custom name field

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

Screenshots/Videos

Add any screenshot/video evidence

https://github.com/user-attachments/assets/7a29a435-e880-41f5-930b-59aa5f04e0df

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021853969647585038505
  • Upwork Job ID: 1853969647585038505
  • Last Price Increase: 2024-11-06
Issue OwnerCurrent Issue Owner: @c3024
melvin-bot[bot] commented 6 days ago

Triggered auto assignment to @anmurali (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

lanitochka17 commented 6 days ago

We think that this bug might be related to #wave-control

lanitochka17 commented 6 days ago

@anmurali FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

melvin-bot[bot] commented 3 days ago

@anmurali Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

Tony-MK commented 3 days ago

Proposal

Please re-state the problem that we are trying to solve in this issue.

Report header title changes to Workspace owes X after editing custom name field.

What is the root cause of that problem?

When a user sets a custom report name, the response from the SetPolicyDefaultReportTitle request changes the attribute type in the text_title report field from "formula" to "text" for the policy fields.

SetPolicyDefaultReportTitle Response

Hence, the getMoneyRequestReportName function doesn't return the value of report.reportName since the titleReportField is undefined.

https://github.com/Expensify/App/blob/657531f56427e51d377b642af6ef65faf30605d9/src/libs/ReportUtils.ts#L2958-L2963

This is because the getFormulaTypeReportField function only finds a report field where the type is "formula"

https://github.com/Expensify/App/blob/657531f56427e51d377b642af6ef65faf30605d9/src/libs/ReportUtils.ts#L2878-L2880

What changes do you think we should make in order to solve the problem?

Let's remove titleReportField from this condition to allow the value of report?.reportName to be returned.

Therefore, the condition should resemble the one below.

if (report?.reportName && isPaidGroupPolicyExpenseReport(report)) {
melvin-bot[bot] commented 2 days ago

Job added to Upwork: https://www.upwork.com/jobs/~021853969647585038505

melvin-bot[bot] commented 2 days ago

Triggered auto assignment to Contributor-plus team member for initial proposal review - @c3024 (External)

huult commented 1 day ago

Proposal

Please re-state the problem that we are trying to solve in this issue.

Report header title changes to Workspace owes X after editing custom name field

What is the root cause of that problem?

The title is obtained from getReportName. if the report name is available in the cache, it will be retrieved from there. If it is not in the cache, it will be retrieved using getMoneyRequestReportName. https://github.com/Expensify/App/blob/0f03601422dc02a42b5cf6bbc748b14be3cd1695/src/components/AvatarWithDisplayName.tsx#L74 https://github.com/Expensify/App/blob/0f03601422dc02a42b5cf6bbc748b14be3cd1695/src/libs/ReportUtils.ts#L4016-L4018

For the first expense created without setting up Rules or Report fields, fieldList will not be contained in report or policy, and the report isn't set. Therefore, reportFields will be received from getReportFieldsByPolicyID, with reportFields having type='formula'. As a result, const titleReportField = getFormulaTypeReportField(reportFields ?? {}) will return the text report fields object. Consequently, getMoneyRequestReportName will return the report name, and we will see Expense Report #number displayed in the header

https://github.com/Expensify/App/blob/0f03601422dc02a42b5cf6bbc748b14be3cd1695/src/libs/ReportUtils.ts#L3013-L3019

After that, we went on to set Rules or Report fields, enabled Custom report names, and input report, which is a text type (not a formula). At that point, fieldList exists in policy.Therefore, reportFields will be received from report?.fieldList having type='text' because we input report when setting up Custom report names. so const titleReportField = getFormulaTypeReportField(reportFields ?? {}) will return undefined because reportFields.type === 'text'. As a result, we can't retrieve the report name, and getMoneyRequestReportName will return Localize.translateLocal('iou.payerOwesAmount', {payer: payerOrApproverName, amount: formattedAmount});, which is why we see Workspace owes X

This issue happens after editing the custom name field because, before editing the custom name, the cache exists and we retrieve the value from the cache to display. After editing, we update the cache with the new value, so the new title will display after editing.

What changes do you think we should make in order to solve the problem?

To resolve this issue, we must cover the case where report?.fieldList has type = 'text' and still return the report name. Something like this:

  1. Create a function to get the text-type report field
//.src/libs/ReportUtils.ts#L2935

+   function getTextTypeReportField(reportFields: Record<string, PolicyReportField>) {
+      return Object.values(reportFields).find((field) => field?.type === 'text');
+    }
  1. Update the condition in the getMoneyRequestReportName function to return the report name
    
    function getMoneyRequestReportName(report: OnyxEntry<Report>, policy?: OnyxEntry<Policy>, invoiceReceiverPolicy?: OnyxEntry<Policy>): string {
    ...
    //.src/libs/ReportUtils.ts#L3020
    +   const textTypeReportTitle = getTextTypeReportField(reportFields ?? {});

Optional: getMoneyRequestReportName is used for both money request reports and invoice reports. So, if we want it to be specific to only the money request report, it would be like this:

function getMoneyRequestReportName(report: OnyxEntry<Report>, policy?: OnyxEntry<Policy>, invoiceReceiverPolicy?: OnyxEntry<Policy>): string {
  ...
//.src/libs/ReportUtils.ts#L3020
+   const textTypeReportTitle = getTextTypeReportField(reportFields ?? {});

-   if (titleReportField && report?.reportName && isPaidGroupPolicyExpenseReport(report)) {
+   if ((invoiceReceiverPolicy ? titleReportField : titleReportField ?? textTypeReportTitle) && report?.reportName && isPaidGroupPolicyExpenseReport(report)) {
        return report.reportName;
    }

Test branch

POC https://github.com/user-attachments/assets/ffc6ec22-648a-4d3e-96a6-472b141c21a3
FitseTLT commented 11 hours ago

Proposal

Please re-state the problem that we are trying to solve in this issue.

Expense - Report header title changes to Workspace owes X after editing custom name field

What is the root cause of that problem?

We display the report.reportName only when the title field exists here https://github.com/Expensify/App/blob/8a83e2baa1c7ce7ee2c31103574937c0484854be/src/libs/ReportUtils.ts#L3015-L3018 but the method we use to get the title report field is by searching for a report field with type formula so whenever the title field is set to non-formula text that condition will be unsatisfied and we will show the owes ... title

What changes do you think we should make in order to solve the problem?

The correct way to check if there it the title field is via the fieldID, so we should change it to

    const titleReportField = Object.values(reportFields ?? {}).find((reportField) => reportField?.fieldID === CONST.REPORT_FIELD_TITLE_FIELD_ID);

What alternative solutions did you explore? (Optional)