Skip to content
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

[HOLD for payment 2024-01-17] Implement Client-side Violations when creating money requests #31092

Closed
cead22 opened this issue Nov 9, 2023 · 19 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Engineering Improvement Item broken or needs improvement. Weekly KSv2

Comments

@cead22
Copy link
Contributor

cead22 commented Nov 9, 2023

  • Design Doc
  • The following should only apply to users in the violations beta
  • Let's connect MoneyRequestConfirmPage to the POLICY, POLICY_CATEGORIES, and POLICY_TAGS Onyx collections so we can get
    • requiresTag, requiresCategory, hasMultipleTagLists, and isTaxTrackingEnabled from the policy
    • The policy categories, and
    • The policy tags
  • In src/pages/iou/steps/MoneyRequestConfirmPage.js let's pass props.policy.policyID to IOU.requestMoney > from there to getMoneyRequestInformation > and from there to buildOnyxDataForMoneyRequest
  • In buildOnyxDataForMoneyRequest
    • We’ll check If policyID is not available, like for the case of P2P, and return early in that case
    • Then call ViolationUtils.getViolationsOnyxData(transaction, [], policyRequiresTags, policyTags, policyRequiresCategories, policyCategories) and push the return value to optimisticData
    • Note: we're not gonna block users from submitting a money request with violations
    • Refer Implement ViolationUtils lib #31083 to see the data returned by getViolationsOnyxData
    • We can set the value of failure data to an object like the snippet below, to remove the violations if the request isn't created
  • The idea here is that when requests are created, the transactions calculated on the client by ViolationUtils.getViolationsOnyxData should show right away (eg, missing tag, missing category, category out of policy,...)
{
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`,
    value: [],
}
@cead22 cead22 added Engineering Daily KSv2 Improvement Item broken or needs improvement. labels Nov 9, 2023
@cead22
Copy link
Contributor Author

cead22 commented Nov 9, 2023

@lindboe @cdanwards can you comment here so I can assign you?

@cead22 cead22 changed the title [HOLD 31083] Implement Client-side Violations whehn creating money requests [HOLD 31083] Implement Client-side Violations when creating money requests Nov 9, 2023
@cdanwards
Copy link
Contributor

Commenting for assignment

Copy link

melvin-bot bot commented Nov 14, 2023

@cdanwards Whoops! This issue is 2 days overdue. Let's get this updated quick!

@melvin-bot melvin-bot bot added the Overdue label Nov 14, 2023
@cdanwards
Copy link
Contributor

Beginning work on this

@melvin-bot melvin-bot bot removed the Overdue label Nov 16, 2023
Copy link

melvin-bot bot commented Nov 20, 2023

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

@melvin-bot melvin-bot bot added the Overdue label Nov 20, 2023
@cdanwards
Copy link
Contributor

Hey @cead22 I've been working on this and had a question about approach.

Right now, we're connecting POLICY_CATEGORIES and POLICY_TAGS collections in the MoneyRequestPage but not using them, nor passing them down to the subsequent function calls. Will we be using them in another step in this file?

I had a thought that maybe we could update the policy PropTypes to include requiresTag, requiresCategory, hasMultipleTagLists, and isTaxTrackingEnabled and subsequently in IOU.buildOnyxDataForMoneyRequest we could call ReportUtils.getPolicy to get those policy properties.

Similarly we could call ReportUtils.getPolicyTags and ReportUtils.getPolicyCategories in the same manner so that we have access to pass those into the ViolationsUtils.getViolationsOnyxData

Here's the gist of what it would look like:

    if (!policyID) {
        return [optimisticData, successData, failureData];
    }
    const policy = ReportUtils.getPolicy(policyID);
    const policyTags = ReportUtils.getPolicyTags(policyID);
    const policyCategories = ReportUtils.getPolicyCategories(policyID);


    const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(transaction, [], policy.requiresTags, policyTags, policy.requiresCategory, policyCategories);

    if (violationsOnyxData) {
        optimisticData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`,
            value: violationsOnyxData,
        });
        failureData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`,
            value: [],
        });
    }

Let me know what your thoughts are!

@melvin-bot melvin-bot bot removed the Overdue label Nov 21, 2023
@cead22
Copy link
Contributor Author

cead22 commented Nov 21, 2023

Right now, we're connecting POLICY_CATEGORIES and POLICY_TAGS collections in the MoneyRequestPage

You mean MoneyRequestConfirmPage?

but not using them, nor passing them down to the subsequent function calls. Will we be using them in another step in this file?

You mean as part of this PR you're working on? I don't see the connection to those collection in main. If that's the case, let me know and I'll check the design doc to see if we're going to use them somewhere else, and we just haven't added the code for it yet

had a thought that maybe we could update the policy PropTypes to include requiresTag, requiresCategory...

I don't see the benefit of this, but I'm kind of a react noob, can you perhaps spell it out?

Similarly we could call ReportUtils.getPolicyTags and ReportUtils.getPolicyCategories

I don't see why it's better to have these getters, instead of accessing them like policy.requiresCategory & policy.requiresTag since we already have the policy object with those properties. If we had a policy object and were returning it from ReportUtils.getPolicy(policyID);, it'd make sense to have policy.requiresCategory() & policy.requiresTag() methods on the policy object itself

Copy link

melvin-bot bot commented Nov 27, 2023

@cdanwards Eep! 4 days overdue now. Issues have feelings too...

@melvin-bot melvin-bot bot added the Overdue label Nov 27, 2023
@cdanwards
Copy link
Contributor

@cead22

You mean MoneyRequestConfirmPage?

Yes! Sorry, I thought I was referring to the correct component.

You mean as part of this PR you're working on? I don't see the connection to those collection in main. If that's the case, let me know and I'll check the design doc to see if we're going to use them somewhere else, and we just haven't added the code for it yet

I think this was just me making an assumption. Those properties weren't listed as being passed down through the functions but they are needed in the subsequent ViolationsUtils.getViolationsOnyxData call. And after looking through how those getter methods are working I think the point I was getting to was a bit of a moot point 😅 So we can do as you specified originally.

had a thought that maybe we could update the policy PropTypes to include requiresTag, requiresCategory...

I don't see the benefit of this, but I'm kind of a react noob, can you perhaps spell it out?

While originally I was thinking this would be most useful when using the getter getPolicy (which we won't do), I do still think this would be valuable to document in the type that a policy can have these properties.

@melvin-bot melvin-bot bot removed the Overdue label Nov 27, 2023
@cead22
Copy link
Contributor Author

cead22 commented Nov 30, 2023

While originally I was thinking this would be most useful when using the getter getPolicy (which we won't do), I do still think this would be valuable to document in the type that a policy can have these properties.

Thanks for clarifying, that makes sense to me, so long as it doesn't break anything (and let's not block on it)

@melvin-bot melvin-bot bot added the Overdue label Nov 30, 2023
@cdanwards
Copy link
Contributor

@cead22 Great! This is mostly finished, just making sure 31656 doesn't have any last changes then I'll get this up to a PR.

@melvin-bot melvin-bot bot removed the Overdue label Nov 30, 2023
@cead22 cead22 changed the title [HOLD 31083] Implement Client-side Violations when creating money requests Implement Client-side Violations when creating money requests Dec 4, 2023
@melvin-bot melvin-bot bot added the Overdue label Dec 4, 2023
@cead22
Copy link
Contributor Author

cead22 commented Dec 4, 2023

Off hold

@cdanwards
Copy link
Contributor

Now unblocked. Working to get this ready for PR!

@lindboe
Copy link
Contributor

lindboe commented Dec 14, 2023

Commenting for assignment

Copy link

melvin-bot bot commented Jan 8, 2024

This issue has not been updated in over 15 days. @cead22, @lindboe, @cdanwards eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

@lindboe
Copy link
Contributor

lindboe commented Jan 8, 2024

The PR is done, @cead22 can this be closed?

@cead22
Copy link
Contributor Author

cead22 commented Jan 8, 2024

Yes

@cead22 cead22 closed this as completed Jan 8, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Monthly KSv2 labels Jan 10, 2024
@melvin-bot melvin-bot bot changed the title Implement Client-side Violations when creating money requests [HOLD for payment 2024-01-17] Implement Client-side Violations when creating money requests Jan 10, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Jan 10, 2024
Copy link

melvin-bot bot commented Jan 10, 2024

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

Copy link

melvin-bot bot commented Jan 10, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.23-4 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 2024-01-17. 🎊

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

  • @lindboe does not require payment (Contractor)
  • @cdanwards does not require payment (Contractor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Engineering Improvement Item broken or needs improvement. Weekly KSv2
Projects
None yet
Development

No branches or pull requests

3 participants