App icon indicating copy to clipboard operation
App copied to clipboard

Optimistically create policy expense chats for new members of workspaces

Open robertKozik opened this issue 2 years ago • 49 comments

Details

Add creating optimistic policy expense chats while adding new members to the workspace, so created chats would pop up while user is offline.

Fixed Issues

$ https://github.com/Expensify/App/issues/14594 PROPOSAL: https://github.com/Expensify/App/issues/14594#issuecomment-1466995775

Tests

Same as QA steps

  • [X] Verify that no errors appear in the JS console

Offline tests

Same as the QA steps. Workspace chats for each member should appear optimistically

QA Steps

  1. Log in with account that has access to the policy-expense-chat beta
  2. Go offline by navigating to [profile icon] > Preferences > and enable Force offline
  3. Create a new workspace.
  4. Invite some people to the workspace. Verify that workspace chats for each member appear optimistically.
  5. Go online by navigating to [profile icon] > Preferences > disable Force online. Verify that workspace chats created for each members are updated accordingly
  • [X] Verify that no errors appear in the JS console

PR Author Checklist

  • [X] I linked the correct issue in the ### Fixed Issues section above
  • [X] I wrote clear testing steps that cover the changes made in this PR
    • [X] I added steps for local testing in the Tests section
    • [x] I added steps for the expected offline behavior in the Offline steps section
    • [X] I added steps for Staging and/or Production testing in the QA steps section
    • [X] I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • [X] 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)
    • [X] 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).
  • [X] I included screenshots or videos for tests on all platforms
  • [X] I ran the tests on all platforms & verified they passed on:
    • [X] Android / native
    • [X] Android / Chrome
    • [X] iOS / native
    • [X] iOS / Safari
    • [X] MacOS / Chrome / Safari
    • [X] MacOS / Desktop
  • [X] 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)
  • [X] I followed proper code patterns (see Reviewing the code)
    • [X] 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)
    • [X] I verified that comments were added to code that is not self explanatory
    • [X] 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.
    • [X] I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • [X] 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:
    • [X] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • [X] I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • [X] 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.
    • [X] I verified the JSDocs style guidelines (in STYLE.md) were followed
  • [X] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • [X] I followed the guidelines as stated in the Review Guidelines
  • [X] 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)
  • [X] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • [X] 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
  • [X] I verified that if a function's arguments changed that all usages have also been updated correctly
  • [X] If a new component is created I verified that:
    • [X] A similar component doesn't exist in the codebase
    • [X] All props are defined accurately and each prop has a /** comment above it */
    • [X] The file is named correctly
    • [X] The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • [X] The only data being stored in the state is data necessary for rendering and nothing else
    • [X] 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)
    • [X] 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)
    • [X] All JSX used for rendering exists in the render method
    • [X] 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
  • [X] If any new file was added I verified that:
    • [X] 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
  • [X] If a new CSS style is added I verified that:
    • [X] A similar style doesn't already exist
    • [X] The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • [X] 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)
  • [X] 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.
  • [X] 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.
  • [X] 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.
  • [X] I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web

https://user-images.githubusercontent.com/61146594/228816124-18a77c59-8dbc-4901-99a3-bcd603266bc6.mov

Mobile Web - Chrome

https://user-images.githubusercontent.com/61146594/228822830-49b30a11-21f3-47f9-8cd1-b5c24f78bb42.MP4

Mobile Web - Safari

https://user-images.githubusercontent.com/61146594/228822050-f2aa1bc7-a585-434b-99f5-f671747aee98.mov

Desktop

https://user-images.githubusercontent.com/61146594/228823947-bcddeb92-6c9d-4a3d-8d5f-6dd697c1f159.mov

iOS

https://user-images.githubusercontent.com/61146594/228819146-10c9783c-5c18-4052-916e-5bed65dd94aa.mov

Android

https://user-images.githubusercontent.com/61146594/228858213-4561064b-9910-48b7-9121-19b111114467.mov

robertKozik avatar Mar 30 '23 18:03 robertKozik

@bondydaa @0xmiroslav One of you needs to 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]

MelvinBot avatar Mar 30 '23 18:03 MelvinBot

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

github-actions[bot] avatar Mar 30 '23 18:03 github-actions[bot]

I have read the CLA Document and I hereby sign the CLA

robertKozik avatar Mar 30 '23 18:03 robertKozik

oh sorry forgot this PR. reviewing now

0xmiroslav avatar Apr 06 '23 20:04 0xmiroslav

all you @0xmiroslav let me know if you need help with the checklist.

bondydaa avatar Apr 06 '23 20:04 bondydaa

@RobertKozik can you please merge from main since branch is very behind

0xmiroslav avatar Apr 06 '23 20:04 0xmiroslav

@0xmiroslav rebased, so should be up to date

robertKozik avatar Apr 06 '23 21:04 robertKozik

BUG: multiple workspace chats are created for the same user

https://user-images.githubusercontent.com/97473779/230508807-824246f2-0663-4b77-93f9-c5e1d4e20122.mov

0xmiroslav avatar Apr 06 '23 23:04 0xmiroslav

@bondydaa should we also cross-out workspace chat when remove user from workspace offline?

0xmiroslav avatar Apr 06 '23 23:04 0xmiroslav

should we also cross-out workspace chat when remove user from workspace offline?

Hmm I didn't considered that scenario initially.

I think let's try to keep the scope of this PR small and only focused on the AddMembersToWorkspace API method since I'm assuming the removing of a user is a different API command? We can spin up a new issue to ensure the offline behavior for removing a workspace member is handled properly.

bondydaa avatar Apr 07 '23 15:04 bondydaa

BUG: multiple workspace chats are created for the same user

@bondydaa are you able to reproduce this one?

0xmiroslav avatar Apr 07 '23 15:04 0xmiroslav

I didn't see more than 1 when I tested yesterday on desktop but let me try again. Did you only add 1 member while offline? Or multiple? I think I tested adding 2 users but not just a single user so I'll try both.

bondydaa avatar Apr 07 '23 15:04 bondydaa

I didn't see more than 1 when I tested yesterday on desktop but let me try again. Did you only add 1 member while offline? Or multiple? I think I tested adding 2 users but not just a single user so I'll try both.

I tried only one. Please try to repeat adding/removing the same user.

0xmiroslav avatar Apr 07 '23 15:04 0xmiroslav

Hmm yeah I am seeing some weird things when you remove the user while offline.

Steps are like:

  1. Go offline
  2. add new member to workspace, see optimistic report added to LHN
  3. remove user from workspace, optimistic report stays in LHN
  4. Go online
  5. optimistic report in LHN becomes "real chat", if you open that chat it then disappears from LHN and you see it's archived.

Though I think this is related more to removing a user vs adding a user so I think we handle that in the follow up GH for DeleteMembersFromWorkspace API command

bondydaa avatar Apr 07 '23 16:04 bondydaa

@0xmiroslav @bondydaa I came up with quicker fix, as after removing the user chat remains as archived. We can look for this report and just change it's status to open as API will return it's ID as new chat. What you think about such an approach?

edit: @bondydaa I was testing it with following steps:

  1. Go offline
  2. add new member to workspace, see optimistic report added to LHN
  3. Go online
  4. Optimistic chat is replaced with real one
  5. remove user from workspace, optimistic report stays in LHN
  6. Go offline
  7. Add member simmilar to the one from step 1

I came across one more problem though @bondydaa . Now we are passing only the reportID and It's merging into one as it should. But as we are not passing the created report action ID, when user clicks the created chat after coming back online we have double welcome notice. I think we should also pass the reportActionID as it is done when creating normal chat Here are steps to repo this:

  1. Go offline
  2. Invite new member to workspace (optimistic creation of report is doing fine)
  3. Go online
  4. click on created chat and wait for the data to come from server

robertKozik avatar Apr 07 '23 16:04 robertKozik

I created this https://github.com/Expensify/App/issues/17137 for the follow up issue. Let's keep adding reproduce steps for things we see related to removing a user from the workspace / DeleteMembersFromWorkspace APi command to that as we come across them.

bondydaa avatar Apr 07 '23 16:04 bondydaa

I've removed isLoadingReportActions key and add failure onyx data as requested in review.

robertKozik avatar Apr 07 '23 16:04 robertKozik

Though I think this is related more to removing a user vs adding a user so I think we handle that in the follow up GH for DeleteMembersFromWorkspace API command

I think duplicate issue is not related to "remove user when offline". This also happens "when remove user online", so issue should be fixed here.

0xmiroslav avatar Apr 07 '23 16:04 0xmiroslav

Hmm interesting, I'll take a look at logs to see if I can confirm the following:

What I suspect is happening is that onyx is just "out of date" with the removed user and that's why you're able to create a new chat successfully which then shows 2 of them since the first one for the user is technically archived which is why I think it's more related to DeleteMembersFromWorkspace.

The behavior is only showing up now in this PR since previously the policy expense chats couldn't be added optimistically anyways.

bondydaa avatar Apr 07 '23 20:04 bondydaa

I checked this more in depth. In my opinion this bug consists of two separate problems:

  1. When user is offline and tries to remove optimistically workspace member - created chat is not being removed
  2. User is invited and chat is created successfully online, later removed - in this case when member is going to be re-added while app is offline, optimistically created chat will be created, but passed reportID will be ignored by backend. Returned chat will be the same one as when user was being added for the first time.

The first one is more related to DeleteMembersFromWorkspace as @bondydaa stated. But the second one should be resolved in this PR. I came up with the solution: after removing the user chat remains as archived. We will look for this report and just change it's status to open (optimistically) as API will return it's ID as new chat. After coming back online, everything should work as intended.

robertKozik avatar Apr 07 '23 20:04 robertKozik

Hi @bondydaa what is the status of your PRs? Can we proceed with this one?

robertKozik avatar Apr 17 '23 08:04 robertKozik

we just deployed the API changes to staging about half an hour ago so feel free to test this against that.

bondydaa avatar Apr 17 '23 15:04 bondydaa

I know you can't access this link but got a PR up fixing the WAF rule here https://github.com/Expensify/Web-Expensify/pull/37082

I'll get it to staging as soon as it's merged via Cherry Pick (CP).

bondydaa avatar Apr 18 '23 22:04 bondydaa

@0xmiroslav can you handle the the reviewer checklist?

bondydaa avatar Apr 19 '23 17:04 bondydaa

@0xmiroslav can you handle the the reviewer checklist?

Sure

0xmiroslav avatar Apr 19 '23 17:04 0xmiroslav

@RobertKozik @bondydaa While testing with simulating network, I noticed chat room is still doubled. After logout and login, it disappears. All work fine in normal scenario (when switch real network). Can we ignore simulating network tests?

https://user-images.githubusercontent.com/97473779/234062258-f77ec64a-f05d-4c38-89f4-b68ff1d2fa42.mov

Logout and login:

https://user-images.githubusercontent.com/97473779/234062381-e4dcf40f-a3f5-4397-9834-cc6e666ab40c.mp4

0xmiroslav avatar Apr 24 '23 16:04 0xmiroslav

I think this one is more related to deleting the member, thus should be considered in: https://github.com/Expensify/App/issues/17137.

robertKozik avatar Apr 24 '23 17:04 robertKozik

yeah I agree probably most likely related to deleting the member which we know we need to improve in that other issue.

bondydaa avatar Apr 24 '23 18:04 bondydaa

Reviewer Checklist

  • [x] I have verified the author checklist is complete (all boxes are checked off).
  • [x] I verified the correct issue is linked in the ### Fixed Issues section above
  • [x] I verified testing steps are clear and they cover the changes made in this PR
    • [x] I verified the steps for local testing are in the Tests section
    • [x] I verified the steps for Staging and/or Production testing are in the QA steps section
    • [x] 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)
    • [x] 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)
  • [x] I checked that screenshots or videos are included for tests on all platforms
  • [x] I included screenshots or videos for tests on all platforms
  • [x] I verified tests pass on all platforms & I tested again on:
    • [x] Android / native
    • [x] Android / Chrome
    • [x] iOS / native
    • [x] iOS / Safari
    • [x] MacOS / Chrome / Safari
    • [x] MacOS / Desktop
  • [x] 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
  • [x] I verified proper code patterns were followed (see Reviewing the code)
    • [x] 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).
    • [x] I verified that comments were added to code that is not self explanatory
    • [x] 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.
    • [x] I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • [x] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • [x] 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 approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • [x] 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.
    • [x] I verified the JSDocs style guidelines (in STYLE.md) were followed
  • [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • [x] I verified that this PR follows the guidelines as stated in the Review Guidelines
  • [x] 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)
  • [x] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • [x] 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
  • [x] If a new component is created I verified that:
    • [x] A similar component doesn't exist in the codebase
    • [x] All props are defined accurately and each prop has a /** comment above it */
    • [x] The file is named correctly
    • [x] The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • [x] The only data being stored in the state is data necessary for rendering and nothing else
    • [x] 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)
    • [x] 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)
    • [x] All JSX used for rendering exists in the render method
    • [x] 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
  • [x] If any new file was added I verified that:
    • [x] 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
  • [x] If a new CSS style is added I verified that:
    • [x] A similar style doesn't already exist
    • [x] The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • [x] 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.
  • [x] 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)
  • [x] 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.
  • [x] 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.
  • [x] 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.
  • [x] I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web

https://user-images.githubusercontent.com/97473779/235016222-c4d71c4f-2786-4abf-be49-fa89c819d7c8.mov

Mobile Web - Chrome

https://user-images.githubusercontent.com/97473779/235015403-483d3b36-8455-46fe-b7a3-563b43df0b9a.mp4

Mobile Web - Safari
Desktop

https://user-images.githubusercontent.com/97473779/235019685-f6667c63-51d8-4405-81a0-48be57bd1076.mov

iOS

https://user-images.githubusercontent.com/97473779/234062258-f77ec64a-f05d-4c38-89f4-b68ff1d2fa42.mov

Logout and login:

https://user-images.githubusercontent.com/97473779/234062381-e4dcf40f-a3f5-4397-9834-cc6e666ab40c.mp4

Android

https://user-images.githubusercontent.com/97473779/235015302-2713875e-2b06-445e-a13f-4efb50694e27.mp4

0xmiroslav avatar Apr 24 '23 19:04 0xmiroslav

I found weird bug while testing Force offline in android:

  • Let's say workspaces W1, W2 exist and member M1 is already added to W1
  • Enable "Force offline"
  • invite M1 to W2 Looks good so far
  • Disable "Force offline"
  • Suddenly W1 workspace name changes to W2

https://user-images.githubusercontent.com/97473779/234100434-13ac02c1-9034-4eb5-87e0-c895263b875e.mov

0xmiroslav avatar Apr 24 '23 19:04 0xmiroslav