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

Participants migration #40254

Merged
merged 29 commits into from
May 13, 2024
Merged

Participants migration #40254

merged 29 commits into from
May 13, 2024

Conversation

s77rt
Copy link
Contributor

@s77rt s77rt commented Apr 15, 2024

Details

Fixed Issues

$ #34692

Tests

Test 1:

  1. Open a chat with a user that you have chatted with before
  2. Click the grey plus button in the composer and verify that all actions work correctly i.e. request money, split bill, assign task, etc.

Test 2:

  1. Start a chat with a new user
  2. Verify the chat is created successfully
  3. Click the grey plus button in the composer and verify that all actions work correctly i.e. request money, split bill, assign task, etc.

Test 3:

  1. Repeat Test 1 and Test 2 but with a group chat

Test 4:

  1. Click FAB
  2. Test each option twice, first time with an existing user/group and second time with a new user/group and verify that each action works correctly
  • Verify that no errors appear in the JS console

Offline tests

Same as Tests

QA Steps

Same as Tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov
MacOS: Desktop

@s77rt
Copy link
Contributor Author

s77rt commented Apr 20, 2024

Found a bug in Onyx, mergeCollection does not work will null values as merge.

Onyx.merge('report_123', {reportID: 123, participantAccountIDs: [10, 20]}); // have reportID and participantAccountIDs

Onyx.mergeCollection('report_', {'report_123': {participantAccountIDs: null}}) // still have reportID and participantAccountIDs <-- BUG

Onyx.merge('report_123', {participantAccountIDs: null}) // have reportID
Screen.Recording.2024-04-20.at.9.46.05.PM.mov

@s77rt s77rt changed the title Participants migration [HOLD #41056] Participants migration Apr 28, 2024
@s77rt s77rt marked this pull request as ready for review April 28, 2024 22:15
@s77rt s77rt requested a review from a team as a code owner April 28, 2024 22:15
@melvin-bot melvin-bot bot requested review from ikevin127 and removed request for a team April 28, 2024 22:15
Copy link

melvin-bot bot commented Apr 28, 2024

@ikevin127 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@s77rt
Copy link
Contributor Author

s77rt commented Apr 28, 2024

@marcaaron There is a bug in OpenReport it's not returning the correct participants. After trying to create a new chat the participants contains my user id (it shouldn't) and all members are hidden.

Screenshot 2024-04-28 at 11 09 31 PM

@s77rt
Copy link
Contributor Author

s77rt commented Apr 28, 2024

This PR is held on #41056 which includes the fix for #40254 (comment).

@s77rt
Copy link
Contributor Author

s77rt commented Apr 28, 2024

Code-wise this is ready for review.

@marcaaron
Copy link
Contributor

After trying to create a new chat the participants contains my user id (it shouldn't) and all members are hidden.

Interesting. What kind of chat was this? I have some time today to look into this.

To clarify, I think it should contain your accountID. At least, that's how we envisioned this working. I believe the only case where you wouldn't see yourself is a 1:1 DM. However, we must change that behavior and simply have the frontend determine whether the current user should be shown in the members list or not. Let me know if this makes sense.

@s77rt
Copy link
Contributor Author

s77rt commented Apr 29, 2024

@marcaaron I was trying to create a 1:1 DM

@marcaaron
Copy link
Contributor

There is a bug in OpenReport it's not returning the correct participants.

Ok, I think that everything is working correctly here? I think what you are seeing there is consistent with my expectations and not a bug. Just to be sure I understood you the first time - can you let know if you saw some other kind of bug related to this?

@s77rt
Copy link
Contributor Author

s77rt commented Apr 30, 2024

I see just one problem regarding Onyx migration:
When migrating from participantAccountIDs to participants, I can't tell if I should include my account id in the new participants or not. Example: on both 1:1 DM and a public room the participantAccountIDs won't have my id, but in the former the participants object includes my id while in the latter it does not

@s77rt
Copy link
Contributor Author

s77rt commented Apr 30, 2024

I see inconsistency in the participants return object, on self dm the participants is empty (and it's an array?) I expected to see my account id

Screenshot 2024-04-30 at 5 18 21 PM

Same thing with public room, the participants is an empty array instead of an object

@s77rt s77rt marked this pull request as draft April 30, 2024 16:19
@marcaaron
Copy link
Contributor

I can't tell if I should include my account id in the new participants or not. Example: on both 1:1 DM and a public room the participantAccountIDs won't have my id, but in the former the participants object includes my id while in the latter it does not

The participants object should always have the current user in it (unless it's a room they have not joined yet or something). Which situations are you finding that it's not there? Seems we must fix that before we can proceed.

I see inconsistency in the participants return object, on self dm the participants is empty (and it's an array?) I expected to see my account id

That seems very wrong. I'll have a look. Let me know if you see any other inconsistencies! Thanks!

@marcaaron
Copy link
Contributor

marcaaron commented May 1, 2024

I see inconsistency in the participants return object, on self dm the participants is empty (and it's an array?) I expected to see my account id

Heads up - I'm struggling to see where in the backend we might be sending an array for the report.participants - but do see that we can end up with an empty object for the self DM (fixing that now - is there anyway to work around it?). Not ruling anything out, but is it possible this could be a front end mistake somewhere? 🤔

@s77rt
Copy link
Contributor Author

s77rt commented May 7, 2024

@ikevin127 Can you please complete the checklist

@ikevin127
Copy link
Contributor

ikevin127 commented May 7, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari *
328600445-08cc485d-3970-4a2f-9c0e-af294af16b6a.mov
MacOS: Desktop

@marcaaron
Copy link
Contributor

This is looking great! Quick heads up that we are on a merge freeze and I likely won't get to review this until Monday, but will prioritize it as soon as possible (merge freeze should hopefully minimize the number of conflicts we get on this - but appreciate your patience on this one @s77rt 🙇).

Copy link
Contributor

@ikevin127 ikevin127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@melvin-bot melvin-bot bot requested a review from marcaaron May 7, 2024 21:56
@marcaaron
Copy link
Contributor

Reviewing this today! There are some small conflicts on it.

Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look very good 👍

I had a few small comments, but I think I'd prefer to merge this sooner vs. later and have them addressed in a follow up PR since this touches quite a few things and will help unblock some backend initiatives.

const participantAccountIDs = report?.participantAccountIDs ?? [];
const participantAccountIDs = Object.keys(report?.participants ?? {})
.map(Number)
.filter((accountID) => accountID !== session?.accountID || !isOneOnOneChat);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like we should have a utility for this like ReportUtils.getAccountIDsForDisplay(report) or something.

const visibleParticipantAccountIDs = Object.entries(report.participants ?? {})
.filter(([, participant]) => participant && !participant.hidden)
.map(([accountID]) => Number(accountID))
.filter((accountID) => accountID !== currentUserAccountID || !isOneOnOneChat);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAccountIDsForDisplay(report, excludeHidden)

// and add the `ownerAccountId`. Money request reports don't add `ownerAccountId` in `participantAccountIDs` array
const defaultParticipantAccountIDs = finalReport?.participantAccountIDs ?? [];
// For money requests i.e the IOU (1:1 person) and Expense (1:* person) reports, use the full `participants`
// and add the `ownerAccountId`. Money request reports don't add `ownerAccountId` in `participants` array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment needs to be fixed. There's not participants array anymore. Also, idk if this is true anymore. The owner needs to be added? Why? I would think they should be there already 🤔

@@ -586,12 +587,27 @@ function buildOnyxDataForMoneyRequest(
});
}

const redundantParticipants: Record<number, null> = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a bit more of a comment about why we do this? It's not entirely clear. This solves the problem of potentially "optimistic" accountIDs ending up as duplicate users?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@marcaaron marcaaron merged commit c701d16 into Expensify:main May 13, 2024
16 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@s77rt
Copy link
Contributor Author

s77rt commented May 13, 2024

@marcaaron Can you please create a new issue so I don't forget to work on the follow up

@VickyStash
Copy link
Contributor

@s77rt I've noticed that the invoice report started to show inside recents section during Send Invoice / Submit expense flow after I've merged this PR. Could you please take a look?
image

@s77rt
Copy link
Contributor Author

s77rt commented May 14, 2024

@VickyStash Thanks for reporting! Indeed this is coming from this PR due to wrong(?) optimistic participants data but I think it may have to do with the backend too.

@marcaaron After sending an invoice the invoice report is as follow:
Screenshot 2024-05-14 at 5 06 02 PM

You can see that it does not have any participants (and again this is somehow an array).

Question: What should be the participants of the invoice report? (report.type = invoice)

@s77rt
Copy link
Contributor Author

s77rt commented May 14, 2024

while at at, @marcaaron did you get a chance to check this bug too #40254 (comment)

@marcaaron
Copy link
Contributor

marcaaron commented May 14, 2024

after creating a task with a new user the returned report onyx data method is SET

I reproduced and see the problem. I'm not sure why we use a SET @thienlnam do you know? code here.

After sending an invoice the invoice report... does not have any participants (and again this is somehow an array).

I will check this too. But this should be a participants object here. I also don't really see any reason why the notification preference should be 'hidden' either. cc @cristipaval as you implemented this here

@marcaaron
Copy link
Contributor

Ok, I solved both of these issues, but it will take some time for the changes to go live. I don't think either are blockers for the next release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/marcaaron in version: 1.4.74-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/chiragsalian in version: 1.4.74-6 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@@ -1107,7 +1107,7 @@ function isProcessingReport(report: OnyxEntry<Report> | EmptyObject): boolean {
* and personal detail of participant is optimistic data
*/
function shouldDisableDetailPage(report: OnyxEntry<Report>): boolean {
const participantAccountIDs = report?.participantAccountIDs ?? [];
const participantAccountIDs = Object.keys(report?.participants ?? {}).map(Number);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change caused this issue

participants contains both the user and the current user, so the length is 2, as result participantAccountIDs.length === 1 condition is never satisfied

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! Thanks for fixing that

Comment on lines +45 to +46
// If we have participantAccountIDs then this report is eligible for migration
if (report?.participantAccountIDs) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition here will be true if participantAccountIDs is empty array [] (no need for migration in this case), and the migration in this case will remove valid accountIDs in participants in Line 65 participants[accountID] = null, and this happened after login with new accounts, and we handled it here #45369

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is participantAccountIDs an empty array in the first place? That was the source of truth before migrating and after migrating it should be null.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is participantAccountIDs an empty array in the first place?

I think backend should not return participantAccountIDs or return it with null value for this case (new logged user), because the returned data is already migrated. But may be the backend doing that to prevent old version from crashes and unexpected errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

participantAccountIDs shouldn't be returned by the backend indeed. cc @marcaaron Maybe you can double check this one?

Copy link
Contributor

@ahmedGaber93 ahmedGaber93 Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this will be better if it is not affected on old versions or can cause unexpected errors, but any way we add extra check in FE for empty array here #45369

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We internally paused the project related to this so I think doing a frontend solution is fine until I am free to clean it up the whole way. Took a quick look and it's possible for this to be an empty array - but unlikely/impossible for it to have accountID values in it and we should still use the report.participants object in all cases. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants