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

[PAY 29/04] [$250] Remove deprecated ReportActionUtils.getAllReportActions() method #39091

Closed
Tracked by #27262
tgolen opened this issue Mar 27, 2024 · 42 comments
Closed
Tracked by #27262
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review

Comments

@tgolen
Copy link
Contributor

tgolen commented Mar 27, 2024

This is coming from #27262. You can read the issue description there to get the context behind the problem being solved and the mess being cleaned up.

Problem

ReportActionUtils.getAllReportActions() is called from several view components and other action files which is an anti-pattern.

Why this is important to fix

It maintains a more pure and exact flow of data through the react application. If the view is using report action data, then it needs to subscribe to the data in Onyx so that it's guaranteed that the data will never be stale or out-of-date.

Solution

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01944da5c2a9fee46a
  • Upwork Job ID: 1773061588854910976
  • Last Price Increase: 2024-04-17
  • Automatic offers:
    • Ollyws | Reviewer | 0
    • godofoutcasts94 | Contributor | 0
Issue OwnerCurrent Issue Owner: @bfitzexpensify
@tgolen tgolen added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Mar 27, 2024
@tgolen tgolen self-assigned this Mar 27, 2024
Copy link

melvin-bot bot commented Mar 27, 2024

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Mar 27, 2024
Copy link

melvin-bot bot commented Mar 27, 2024

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

Copy link

melvin-bot bot commented Mar 27, 2024

Triggered auto assignment to @bfitzexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@ghost
Copy link

ghost commented Mar 27, 2024

Proposal

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

Remove deprecated ReportActionUtils.getAllReportActions() method

What is the root cause of that problem?

We have ReportActionUtils.getAllReportActions()here :

const reportActions = ReportActionsUtils.getAllReportActions(report.reportID);

here. :
const reportActions = ReportActionsUtils.getAllReportActions(report.reportID);

and
if (report.parentReportID) {
const itemParentReportActions = ReportActionsUtils.getAllReportActions(report.parentReportID);
itemParentReportAction = report.parentReportActionID ? itemParentReportActions[report.parentReportActionID] : {};
}

and

App/src/libs/actions/IOU.ts

Lines 4556 to 4566 in 9dbec73

function hasIOUToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, excludedIOUReportID: string): boolean {
const chatReportActions = ReportActionsUtils.getAllReportActions(chatReport?.reportID ?? '');
return Object.values(chatReportActions).some((action) => {
const iouReport = ReportUtils.getReport(action.childReportID ?? '');
const policy = ReportUtils.getPolicy(iouReport?.policyID);
const shouldShowSettlementButton = canIOUBePaid(iouReport, chatReport, policy) || canApproveIOU(iouReport, chatReport, policy);
return action.childReportID?.toString() !== excludedIOUReportID && action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && shouldShowSettlementButton;
});
}

and here :

App/src/libs/ReportUtils.ts

Lines 4259 to 4265 in 9dbec73

function shouldHideReport(report: OnyxEntry<Report>, currentReportId: string): boolean {
const currentReport = getReport(currentReportId);
const parentReport = getParentReport(!isEmptyObject(currentReport) ? currentReport : null);
const reportActions = ReportActionsUtils.getAllReportActions(report?.reportID ?? '');
const isChildReportHasComment = Object.values(reportActions ?? {})?.some((reportAction) => (reportAction?.childVisibleActionCount ?? 0) > 0);
return parentReport?.reportID !== report?.reportID && !isChildReportHasComment;
}

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

we need to remove it ReportActionUtils.getAllReportActions() and change it according to mentioned comment here

Add a test here to verify that we do not export getAllReportActions function in ReportUtils

it('does not export getAllReportActions', () => {
    // @ts-expect-error the test is asserting that it's undefined, so the TS error is normal
    expect(ReportUtils.getAllReportActions()).toBeUndefined();
});

What alternative solutions did you explore? (Optional)

N/A

@ghost
Copy link

ghost commented Mar 27, 2024

Updated Proposal

@EzraEllette
Copy link
Contributor

Proposed Solution:

  1. Mark getAllReportActions as deprecated similarly to getParentReport
  2. Remove export and add test.
  3. Modify action files and view components to use Onyx.

Copy link

melvin-bot bot commented Mar 27, 2024

📣 @EzraEllette! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
    Screen Shot 2022-11-16 at 4 42 54 PM
    Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

@EzraEllette
Copy link
Contributor

Contributor details
Your Expensify account email: ezrasellette@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/~015fecd86e270cefef?mp_source=share

Copy link

melvin-bot bot commented Mar 27, 2024

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

@allgandalf
Copy link
Contributor

Proposal

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

Remove deprecated ReportActionUtils.getAllReportActions() method

What is the root cause of that problem?

We need to get away with getAllReportActions

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

ReportActionUtils.getAllReportActions() is used in utils only and not in any component (From what i searched)

So for the libs action, in we should use Onyx.connect:
One example would be as follows:

const childActions = ReportActionUtils.getAllReportActions(reportAction.childReportID);

This would be changed to:

const childActions: OnyxCollection<ReportActions> = {};
Onyx.connect({
    key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
    callback: (actions, key) => {
        if (!key || !actions) {
            return;
        }

        const reportID = CollectionUtils.extractCollectionItemID(key);
        childActions[reportID] = actions;
    },
});

Similar changes would be applied at all other places and then finally remove:

function getAllReportActions(reportID: string): ReportActions {
return allReportActions?.[reportID] ?? {};
}

What alternative solutions did you explore? (Optional)

N/A

@ghost
Copy link

ghost commented Mar 28, 2024

Updated Proposal with test step as well

@melvin-bot melvin-bot bot added the Overdue label Apr 1, 2024
@Ollyws
Copy link
Contributor

Ollyws commented Apr 1, 2024

@godofoutcasts94 was first here so I think it's fair he gets this one.
🎀👀🎀 C+ reviewed

@melvin-bot melvin-bot bot removed the Overdue label Apr 1, 2024
Copy link

melvin-bot bot commented Apr 1, 2024

Current assignee @tgolen is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

@tgolen tgolen assigned ghost Apr 1, 2024
@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 1, 2024
Copy link

melvin-bot bot commented Apr 1, 2024

📣 @Ollyws 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

Copy link

melvin-bot bot commented Apr 1, 2024

📣 @godofoutcasts94 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@tgolen
Copy link
Contributor Author

tgolen commented Apr 4, 2024

@godofoutcasts94 Are you able to get a PR started for this?

@EzraEllette
Copy link
Contributor

@tgolen If there is a deadline you need to meet, I can deliver a PR by EOD.

@ghost
Copy link

ghost commented Apr 4, 2024

Yes definitely today I will do it, I will start a draft PR. Actually, I was out somewhere I will start today itself or latest by tomorrow morning @tgolen

Copy link

melvin-bot bot commented Apr 10, 2024

Current assignee @tgolen is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

Copy link

melvin-bot bot commented Apr 10, 2024

📣 @EzraEllette You have been assigned to this job!
Please apply to the Upwork job and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs!
Keep in mind: Code of Conduct | Contributing 📖

@EzraEllette
Copy link
Contributor

A PR can be expected once I finish testing on all platforms and and double check that my contribution meets the guidelines (Midday CST).

Copy link

melvin-bot bot commented Apr 10, 2024

@tgolen @Ollyws @bfitzexpensify @EzraEllette 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!

@EzraEllette
Copy link
Contributor

Quick update: I'm having a tough time getting the android build running, even after following the steps and doing some googling. I just need to test the android functionality before I create the PR.

@EzraEllette
Copy link
Contributor

#40046

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Apr 11, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 and removed Weekly KSv2 labels Apr 17, 2024
@Ollyws
Copy link
Contributor

Ollyws commented Apr 17, 2024

Any chance we could bump the compensation on this one? It was a bit more work than expected. Thanks!

@tgolen
Copy link
Contributor Author

tgolen commented Apr 17, 2024

I'm OK bumping it up to $250. Thanks for asking

@tgolen tgolen changed the title [$100] Remove deprecated ReportActionUtils.getAllReportActions() method [$250] Remove deprecated ReportActionUtils.getAllReportActions() method Apr 17, 2024
Copy link

melvin-bot bot commented Apr 17, 2024

Upwork job price has been updated to $250

@EzraEllette
Copy link
Contributor

Thanks!

@EzraEllette
Copy link
Contributor

Can someone trigger the bot to send me an offer on upwork?

@tgolen
Copy link
Contributor Author

tgolen commented Apr 24, 2024

Is the offer up here still valid? #39091 (comment)

@EzraEllette
Copy link
Contributor

I already applied to that job. I wonder if it is still assigned to godofoutcasts?

@tgolen
Copy link
Contributor Author

tgolen commented Apr 24, 2024

@bfitzexpensify Could you help us out here, please?

@bfitzexpensify bfitzexpensify added Daily KSv2 and removed Weekly KSv2 labels Apr 25, 2024
@bfitzexpensify
Copy link
Contributor

I've hired you on Upwork @EzraEllette.

Looks like the PR was deployed to prod two days ago.

Updating this to daily and updating the title to reflect the payout date.

@bfitzexpensify bfitzexpensify changed the title [$250] Remove deprecated ReportActionUtils.getAllReportActions() method [PAY 29/04] [$250] Remove deprecated ReportActionUtils.getAllReportActions() method Apr 25, 2024
@bfitzexpensify
Copy link
Contributor

All done here.

@Ollyws
Copy link
Contributor

Ollyws commented Apr 30, 2024

@bfitzexpensify Also C+ payment due for me, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review
Projects
Development

No branches or pull requests

5 participants