App icon indicating copy to clipboard operation
App copied to clipboard

Move logic to start report actions list at index to BaseInvertedFlatList

Open janicduplessis opened this issue 1 year ago • 23 comments

Explanation of Change

This PR is the first step towards being able to open chats at the last unread message. We currently have some logic to open a chat at a specific message for comment linking, but this code is heavily coupled with the comment linking code and ReportActionsView. This moves the logic that allows the list to open at a specific index to BaseInvertedFlatList which will make it easy to reuse for opening chat at last unread also.

FlatList has a initialScrollIndex prop, but it doesn't work very well, it also doesn't work at all if the index is too big and is not rendered initially. To avoid this problem we implemented a workaround in the comment linking code. What we do is render the list initially from the initial index we want and progressively add items before it in onStartReached.

This code can actually be completely decoupled from the comment linking logic and just make the initialScrollIndex prop of BaseInvertedFlatList use that same logic. This is what this PR does.

Fixed Issues

$ https://github.com/Expensify/App/issues/35011 PROPOSAL:

Tests

  • [x] Verify that no errors appear in the JS console
  • [x] Tested comment linking flows described in QA Steps

Offline tests

QA Steps

  • [ ] Test common comment linking flows (testing steps taken from https://github.com/Expensify/App/pull/41962). Note that there should be no behaviour changes from main. If you find something that looks like a bug, please make sure it does not happen on main.

Test 1: Basic Navigation

  • Create a chat between Account A and Account B.
  • Send 200 messages from Account A to Account B.
  • Copy the link to the 70th message and send it to Account B (first link).
  • Copy the link to the 150th message and send it to Account B (second link).
  • From Account A, click on the first link. Verify redirection to the exact message.
  • From Account A, click on the second link. Verify redirection to the exact message.
  • From Account B, click on the first link. Verify redirection to the exact message.
  • From Account B, click on the second link. Verify redirection to the exact message.

Note: Links can be copied to any message and used in any order.

Test 2: Popup Navigation

  • Continue using the chat from Test 1.
  • From Account A, click on the first link. Verify redirection to the exact message.
  • After redirection, a popup should appear at the top of the screen (similar to new message popup).
  • Click on this popup.
  • Verify navigation to the end of the list (newest messages).

Test 3: Cache and Logout

  • Logout from the accounts and clear the cache.
  • Log back in.
  • From Account A, click on the first link. Verify redirection to the exact message.
  • From Account A, click on the second link. Verify redirection to the exact message.
  • From Account B, click on the first link. Verify redirection to the exact message.
  • From Account B, click on the second link. Verify redirection to the exact message.

Test 4:

  • Create a workspace as User A.
  • Invite User B.
  • Navigate to the created Workspace Chat as User B.
  • Observe User B has a whisper message.
  • Send a few messagse as User B inside the workspace chat.
  • Navigate to Chat as User A.
  • Observe User A does not see any whisper messages nor have them in their Onyx data.
  • User A should see the previous actions

Notes: Ensure the chat contains at least 150 messages. Initially, up to 50 messages are rendered. Navigating to the 70th message should allow further navigation up to the 150th message, even with gaps.

  • [ ] 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: mWeb Chrome
    • [x] iOS: Native
    • [x] iOS: mWeb 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 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)
    • [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 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(theme.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 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.
  • [x] 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:
    • [x] I verified that all the inputs inside a form are aligned with each other.
    • [x] I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • [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.

Screenshots/Videos

Android: Native

https://github.com/user-attachments/assets/be6fd2f1-ca4a-4c75-be26-6fc52c8b25c9

Android: mWeb Chrome

https://github.com/user-attachments/assets/a6a7b411-36bd-4cc7-82b2-39488834ff1b

iOS: Native

https://github.com/user-attachments/assets/e79ae37f-edcd-4122-979c-ab9dbaea10e6

iOS: mWeb Safari

https://github.com/user-attachments/assets/2ac41b1e-0811-4c85-9185-d53b91c9e00d

MacOS: Chrome / Safari

https://github.com/user-attachments/assets/aa827f30-c10d-41d5-92b0-d76f41cba6ae

MacOS: Desktop

https://github.com/user-attachments/assets/a1ae6b67-da52-4810-a9c6-1f3432f80351

janicduplessis avatar Nov 06 '24 22:11 janicduplessis

@ishpaul777 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]

melvin-bot[bot] avatar Nov 07 '24 01:11 melvin-bot[bot]

As you can see in the videos there seems to be a lot of jumping going on after comment linking on native platforms (ios / android). It also happens on main so it is not related to this change. I will try to take some time soon to investigate those, especially important since we're going to use that case more now if opening at last unread.

janicduplessis avatar Nov 07 '24 01:11 janicduplessis

I think we are cutting some messages when opening a link to a message, maybe it happens if the newer messages are already loaded? image

https://github.com/user-attachments/assets/8d7fadf4-fdf4-40aa-8f4a-d3d31a50b0ed

rlinoz avatar Nov 08 '24 18:11 rlinoz

@rlinoz Are you able to consistently reproduce? I am trying the same thing as the video, but the messages do load.

This is with messages already in cache.

janicduplessis avatar Nov 12 '24 15:11 janicduplessis

Its on my radar, i'll review try to review this sometime tmrw 🙇

ishpaul777 avatar Nov 12 '24 20:11 ishpaul777

@ishpaul777 friendly bump

Are you able to consistently reproduce?

I will check again and try to get better steps

rlinoz avatar Nov 14 '24 16:11 rlinoz

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: mWeb Chrome
    • [x] iOS: Native
    • [x] iOS: mWeb 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 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)
    • [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(theme.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 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.
  • [x] 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:
    • [x] I verified that all the inputs inside a form are aligned with each other.
    • [x] I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • [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

Android: Native

https://github.com/user-attachments/assets/dc3ce802-cca3-418f-af2a-4b3fe79d5420

Android: mWeb Chrome

https://github.com/user-attachments/assets/a8c8b666-1c3f-43a4-9805-54338db5a957

iOS: Native

https://github.com/user-attachments/assets/67f9b5b2-8312-4c76-a522-b8e79dbb4121

iOS: mWeb Safari

https://github.com/user-attachments/assets/41abfef3-8e8b-404a-9af6-5dc641d7c3da

MacOS: Chrome / Safari

https://github.com/user-attachments/assets/f3d04498-4866-48c6-8ed9-ad4f44acb447

MacOS: Desktop

https://github.com/user-attachments/assets/e6e8288c-9316-49cd-87bf-fb61fd6fa69d

ishpaul777 avatar Nov 17 '24 14:11 ishpaul777

Bug?: New message fetching and redering is quite jerky as compare to staging it often skips many messages load to end

staging

https://github.com/user-attachments/assets/b22e0475-715c-4cb7-b00a-2d4edad83dc2

This branch

https://github.com/user-attachments/assets/ad084771-8770-4816-92f9-432742306bbf

ishpaul777 avatar Nov 17 '24 20:11 ishpaul777

@ishpaul777 I can reproduce the problem, looking at it now, thanks!

janicduplessis avatar Nov 18 '24 20:11 janicduplessis

That was harder that I thought to fix, I missed part of what the code did. It also handle pagination cases when new items are added, it adds it progressively to make sure no jumping happens.

janicduplessis avatar Nov 19 '24 07:11 janicduplessis

Bug: Now i can't scroll down after linking to ~first~ any of the message and only linked messge is shown, after clear cache and restart

https://github.com/user-attachments/assets/6933ad15-0b23-4b34-9c40-f3f99c58dc74

ishpaul777 avatar Nov 20 '24 18:11 ishpaul777

Oh strange, I was testing this exact case. Will check tomorrow.

janicduplessis avatar Nov 21 '24 03:11 janicduplessis

Seems to only happen if the screen is high enough, that's why I didn't catch it during testing. I can now repro.

janicduplessis avatar Nov 22 '24 04:11 janicduplessis

Hey @janicduplessis any news on this one?

rlinoz avatar Nov 26 '24 13:11 rlinoz

Hey, I haven't had much availability in the past few weeks, will try to pickup work on it soon!

janicduplessis avatar Nov 27 '24 04:11 janicduplessis

@janicduplessis Did you get chance to look into this?

ishpaul777 avatar Dec 04 '24 20:12 ishpaul777

Sorry about the delay, will be able to look at this tomorrow.

janicduplessis avatar Dec 04 '24 20:12 janicduplessis

@ishpaul777 Are you still able to reproduce the issue? Weirdly I am not able to anymore even with increasing my screen resolution like I did last time.

janicduplessis avatar Dec 05 '24 21:12 janicduplessis

i'll test again shortly 🙇

ishpaul777 avatar Dec 06 '24 12:12 ishpaul777

I can still reproduce, but on a different message not the first

https://github.com/user-attachments/assets/a83530bc-6f37-4a0a-a678-918513dc0e95

ishpaul777 avatar Dec 06 '24 21:12 ishpaul777

@ishpaul777 I was finally able to reproduce the bug again. I am not sure exactly how, but once the app state is like this it happens all the time.

Basically if the CREATED action and the message we are linking to is loaded in cache, OpenReport is never called because of this code here.

This code is there to avoid calling OpenReport if we think that the data is already loaded, but it fails if the CREATED action is already loaded since it checks in sortedAllReportActions instead of the current page of data (reportActions).

To fix it I changed to check only in the current page of data (reportActions).

Let me know if that fixes it for you, it is hard to validate the fix as I am not able to consitently reproduce it.

janicduplessis avatar Dec 07 '24 18:12 janicduplessis

I also noticed a little bit more jumping than usual when linking to the first message, I will see if I can fix that too. I suspect that moving the comment linking logic to BaseInvertedFlatList changed a bit how much ReportActionsView renders so it uncovered some bugs.

janicduplessis avatar Dec 07 '24 18:12 janicduplessis

I added some more logic to limit how fast new items are added to the start of the list and now the jumping is gone.

janicduplessis avatar Dec 07 '24 23:12 janicduplessis

i am jammed with many other priority tasks today will try to review tomorrow/coming days.

ishpaul777 avatar Dec 09 '24 18:12 ishpaul777

Hey @ishpaul777 did you have time to take a look at it?

also, @janicduplessis apparently we have some conflicts now

rlinoz avatar Dec 13 '24 15:12 rlinoz

Yes I'll review today

ishpaul777 avatar Dec 13 '24 15:12 ishpaul777

Conflicts fixed

janicduplessis avatar Dec 13 '24 17:12 janicduplessis

I think we may have broken the jump to new message button, but I can't repro every time

  1. Hit clear cache and restart
  2. Open the link to one of the messages in the chat with a lot of them
  3. Click on New message

https://github.com/user-attachments/assets/499974f2-af9c-43a3-b7f4-7df28eaaa476

rlinoz avatar Dec 16 '24 14:12 rlinoz

@janicduplessis friendly bump on the above

rlinoz avatar Dec 19 '24 13:12 rlinoz

Any updates @janicduplessis ?

ishpaul777 avatar Dec 23 '24 19:12 ishpaul777