Skip to content

[$250] Workspace - Single category and tag isn't auto selected when requesting money #40591

Closed

Description

@lanitochka17

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: 1.4.63.0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by:
Slack conversation:

Issue found when executing PR #40217

Action Performed:

  1. Log in with a new Gmail account
  2. Create a workspace
  3. Edit categories and tags so you only have one of each
  4. Make tags and categories required
  5. Navigate to FAB - Submit expense - Manual
  6. Select the workspace chat
  7. Tap on the "Show more" button

Expected Result:

Category and tag fields should auto select the single entry

Actual Result:

Single category and tag isn't auto selected when requesting money

Workaround:

Unknown

Platforms:

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

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6454173_1713468126792.OHYC4360.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01342dc85ef896c8e8
  • Upwork Job ID: 1782368096132030464
  • Last Price Increase: 2024-04-22
  • Automatic offers:
    • ahmedGaber93 | Reviewer | 0
    • dukenv0307 | Contributor | 0
    • GandalfGwaihir | Contributor | 0

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Apr 19, 2024
  2. melvin-bot commented on Apr 19, 2024

    @melvin-bot

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

  3. lanitochka17 commented on Apr 19, 2024

    @lanitochka17
    Author

    @zanyrenney 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

  4. lanitochka17 commented on Apr 19, 2024

    @lanitochka17
    Author

    We think that this bug might be related to #wave-collect - Release 1

  5. Krishna2323 commented on Apr 19, 2024

    @Krishna2323
  6. allgandalf commented on Apr 20, 2024

    @allgandalf
    Contributor

    Proposal

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

    Single category and tags aren't auto selected when requesting money.

    What is the root cause of that problem?

    Here when we have only one tag / one category we have a check which sets the auto selected value, but here before that we have certain conditions as below:
    For Category:

    if (iouCategory || !shouldShowCategories || enabledCategories.length !== 1 || !isCategoryRequired) {
    return;
    }

    For Tag:

    const isTagListRequired = tagList.required === undefined ? false : tagList.required && canUseViolations;
    if (!isTagListRequired || enabledTags.length !== 1 || TransactionUtils.getTag(transaction, index)) {
    return;
    }

    When I debugged this I found out that !isCategoryRequired and isTagListRequired are always set to true, regardless of whatever we have set on the BE (In workspace category and tags page, when we set the values as required those values are successfully changed on the BE), so no issue on the BE.

    Now coming to why values isCategoryRequired and isTagListRequired are always false regardless of the backend value, that is because we had added an extra check during the feature addition of categories and tags to only set those values to true if the user has beta access by checking the canUseViolations value, we check isCategoryRequired as well as isTagListRequired with canUseViolations and their respective BE values:

    const isCategoryRequired = canUseViolations && !!policy?.requiresCategory;

    const isTagListRequired = tagList.required === undefined ? false : tagList.required && canUseViolations;

    This causes the values to be always set to false.

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

    We should remove the && canUseViolations from both isTagListRequired as well as isCategoryRequired

    Result Video

    Screen.Recording.2024-04-20.at.5.47.20.AM.mov

    Now that I searched more, I think we should get rid of the canUseViolations hook altogether, because this also gives us regression, it doesn't make tags required (Even when we have required value on the BE):

    const isTagRequired = required === undefined ? false : canUseViolations && required;

    So I guess we should remove the use of hook from the page as the categories and tags for collect policy are no longer in beta

  7. Tony-MK commented on Apr 20, 2024

    @Tony-MK
    Contributor

    Proposal

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

    Workspace - Single category and tag isn't auto selected when requesting money

    What is the root cause of that problem?

    This is a regression caused by #40217 and was suggested in #38744 (comment).

    iouCategory and transactionID should be included in the category dependencies required because the iouCategory will change after the first render.

    // Auto select the category if there is only one enabled category and it is required
    useEffect(() => {
    const enabledCategories = Object.values(policyCategories ?? {}).filter((category) => category.enabled);
    if (iouCategory || !shouldShowCategories || enabledCategories.length !== 1 || !isCategoryRequired) {
    return;
    }
    IOU.setMoneyRequestCategory(transactionID, enabledCategories[0].name);
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [shouldShowCategories, policyCategories, isCategoryRequired]);

    The tag field does not have this issue because the dependencies are set properly.

    IOU.setMoneyRequestTag(transactionID, updatedTagsString);
    }
    }, [policyTagLists, transaction, transactionID, policyTags, canUseViolations]);

    This is why I only experienced this with the category field.

    I believe the category dependencies should not have the eslint rule line like the tag dependencies`.

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

    First, add iouCategory and transactionID as apart dependencies.
    Hence, it should look like the code example below.

    }, [iouCategory, transactionID, shouldShowCategories, policyCategories, isCategoryRequired]);
    

    Finally, remove the eslint rule line below because there will be no dependency issues.

    // eslint-disable-next-line react-hooks/exhaustive-deps

    What alternative solutions did you explore? (Optional)

    Since iouCategory is defaulted to an empty string, we can initialize it to the only categories in the MoneyRequestConfirmationListProps if the enabledCategories is equal to one and categories are required.

    Note

    I noticed you can empty the tag and category for a brief moment before the backend reverts them.

    Hence, I recommend we prohibit the ability to change the tag or category in this situation on the edit pages in the PR.

    POC.-.Chrome.mov
  8. Krishna2323 commented on Apr 20, 2024

    @Krishna2323
    Contributor

    Proposal Updated

    • Added optional to not show category/tag as supplementary when we autoselect.
  9. Krishna2323 commented on Apr 20, 2024

    @Krishna2323
    Contributor

    @Tony-MK, I don't think that it is a regression from my PR, can you pls explain why do you think that it is regression?

  10. Tony-MK commented on Apr 22, 2024

    @Tony-MK
    Contributor

    Hey @krishna232, the useEffect needs the iouCategory dependency like the useEffect for the tags hook.

  11. zanyrenney commented on Apr 22, 2024

    @zanyrenney
    Contributor

    adding external label

  12. 37 remaining items

  13. melvin-bot commented on May 3, 2024

    @melvin-bot

    @cristipaval @ahmedGaber93 @zanyrenney @GandalfGwaihir this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

  14. allgandalf commented on May 3, 2024

    @allgandalf
    Contributor

    Chill Melvin!, PR would be ready in 1 hour :)

  15. added
    ReviewingHas a PR in review
    and removed on May 5, 2024
  16. allgandalf commented on May 5, 2024

    @allgandalf
    Contributor

    PR ready for review c.c. @ahmedGaber93 , sorry got under the weather at the time of the above message, feeling better now 😃

  17. ahmedGaber93 commented on May 6, 2024

    @ahmedGaber93
    Contributor

    I am not sure if we should have waited for @cristipaval to accept the proposal before move forward with PR, but as the contributor is assigned to the issue and the PR is already started, I am going to review the PR, and we can move any discussion there.

  18. allgandalf commented on May 23, 2024

    @allgandalf
    Contributor

    ⚠️ Automation Failed here, This was deployed to Production today @zanyrenney

  19. allgandalf commented on May 29, 2024

    @allgandalf
    Contributor

    I think this is ready for payment @zanyrenney , can you take a look once you find time 😄

    Update:

    Screenshot 2024-05-29 at 11 44 29 AM

    Their GH says they're OoO until June 9, so maybe lets hold this until then, have great vacation @zanyrenney 🏖️

  20. allgandalf commented on Jun 12, 2024

    @allgandalf
    Contributor

    Can you pay this out please @zanyrenney, hope you enjoyed your time out :)

  21. zanyrenney commented on Jun 19, 2024

    @zanyrenney
    Contributor

    Hey @allgandalf thanks for checking the status, great thing to do :) I was also then at a conference so i appreciate your patience.

  22. zanyrenney commented on Jun 19, 2024

    @zanyrenney
    Contributor

    not sure why @dukenv0307 is on the Upwork listingm because the payments should be

    @allgandalf as contributor
    @ahmedGaber93 as contributor+

    paying out as per these assignments:

    2024-06-19_12-00-26
  23. zanyrenney commented on Jun 19, 2024

    @zanyrenney
    Contributor

    paid @ahmedGaber93 $250
    paid @allgandalf $250

    closing!

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions