Skip to content

[Due for payment 2025-07-04] Remove call to getReportNameValuePairs() in canEditWriteCapability() #64014

Closed

Description

@tgolen

Coming from #59961

Problem

canEditWriteCapability() is not a pure function because it references the report's NVPs from a global variable here. This is an anti-pattern that we are actively trying to unwind.

Solution

Using test driven development:

  1. Make sure a unit test exists for canEditWriteCapability() in its current form (or create one if it doesn't exist)
  2. Refactor canEditWriteCapability() to be a pure function, adding isReportArchived = false as a new parameter
  3. Implement the new parameter in all code that calls canEditWriteCapability()
  4. Ensure the unit tests still pass

Important

Please be sure that your proposal follows these best practices:

  • Don't add any more references to data obtained via Onyx.connect
  • Don't add any more references to isArchivedReport(nameValuePairs) unless absolutely necessary
  • Focus on connecting to the data in a UI component and passing the data all the way down with params
  • The React hook useReportIsArchived() is very useful for these
  • Look for existing references in the functions for the report's NVPs or see if isReportArchived has already been passed or calculated
Issue OwnerCurrent Issue Owner: @
Issue OwnerCurrent Issue Owner: @DylanDylann

Activity

  1. self-assigned this
    on Jun 11, 2025
  2. added theissue type on Jun 11, 2025
  3. added
    Help Wanted
    Bug
    on Jun 11, 2025
  4. melvin-bot commented on Jun 11, 2025

    @melvin-bot

    Triggered auto assignment to @isabelastisser (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.

  5. FitseTLT commented on Jun 11, 2025

    @FitseTLT
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-06-11 20:25:23 UTC.

    Proposal

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

    Remove call to getReportNameValuePairs() in canEditWriteCapability()

    What is the root cause of that problem?

    Refactor

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

    Update the line here by isArchived param passed to canEditWriteCapability

    !isArchivedReport(getReportNameValuePairs(report?.reportID)) &&

    function canEditWriteCapability(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, isArchived = false): boolean {
        return (
            isPolicyAdminPolicyUtils(policy) &&
            !isAdminRoom(report) &&
            !isArchived &&
    

    and pass isArchived argument from all components here and here getting the value from useReportIsArchived hook

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    Update the tests for canEditWriteCapability and also add one by passing isArchived param.

    What alternative solutions did you explore? (Optional)

  6. DylanDylann commented on Jun 12, 2025

    @DylanDylann
    Contributor

    @tgolen Could I help on this stuff as C+?

  7. removed
    Help Wanted
    on Jun 12, 2025
  8. DylanDylann commented on Jun 12, 2025

    @DylanDylann
    Contributor

    @FitseTLT This issue is straighforward, I expect the contributor can give a more detailed unit test for canEditWriteCapability function

    Update the tests for canEditWriteCapability and also add one by passing isArchived param.

    Your statement is so general

  9. 25 remaining items

  10. melvin-bot commented on Jun 27, 2025

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  11. melvin-bot commented on Jun 27, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.71-11 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2025-07-04. 🎊

    For reference, here are some details about the assignees on this issue:

    • @FitseTLT requires payment (Needs manual offer from BZ)
    • @DylanDylann requires payment through NewDot Manual Requests
  12. melvin-bot commented on Jun 27, 2025

    @melvin-bot

    @DylanDylann @isabelastisser @DylanDylann The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  13. isabelastisser commented on Jul 1, 2025

    @isabelastisser
    Contributor

    BugZero Checklist:

    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • @DylanDylann The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment:

    • @DylanDylann If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion:

    • @DylanDylann If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Regression Test Proposal Template
    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue:

    Regression Test Proposal

    Precondition:

    Test:

    Do we agree 👍 or 👎

  14. DylanDylann commented on Jul 2, 2025

    @DylanDylann
    Contributor

    This is a refactor, I think we don't need the checklist

  15. added
    Daily
    and removed
    Weekly
    on Jul 4, 2025
  16. melvin-bot commented on Jul 4, 2025

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@isabelastisser)

    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants//hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  17. isabelastisser commented on Jul 7, 2025

    @isabelastisser
    Contributor

    Payment summary:

    @FitseTLT paid in Upwork, $250 for proposal.
    @DylanDylann requires payment through NewDot Manual Requests, $250 for C+ review.

  18. FitseTLT commented on Jul 7, 2025

    @FitseTLT
    Contributor

    Offer Accepted @isabelastisser 👍

  19. trjExpensify commented on Oct 3, 2025

    @trjExpensify
    Contributor

    approved $250 for @DylanDylann.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugDailyEngineering

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions