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

HIGH: (Comment linking: Step 4) Main "glue" PR for Comment Linking #30269

Merged
merged 191 commits into from
Mar 20, 2024

Conversation

perunt
Copy link
Contributor

@perunt perunt commented Oct 24, 2023

Details

This update adds a Comment Linking feature to our project, enabling users to navigate through chat histories by clicking links in the report. This allows quick jumps to different parts of the conversation.

Fixed Issues

$ #20282
PROPOSAL:

Tests

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.
If bugs are found, confirm they are reproducible on another account, or provide credentials for debugging. Thsnks!

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  1. Same as test steps
  2. Important: Create a GitHub Issue to add these test steps to TestRail so they will be tested with every release.
  • 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 approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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 form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label 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
2024-01-09.15.32.57.mp4
Android: mWeb Chrome
2024-01-09.15.05.40.mp4
iOS: Native
Simulator.Screen.Recording.-.14.Pro.-.2024-01-09.at.14.25.25.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
ch.480.mov
S.720.mov
MacOS: Desktop
Untitled.2.mov

@deetergp
Copy link
Contributor

This PR may have caused this blocker/regression #38826

@aldo-expensify
Copy link
Contributor

I think this may be causing this blocker: #38839

@yuwenmemon
Copy link
Contributor

Another blocker this may be causing: #38848

@rlinoz
Copy link
Contributor

rlinoz commented Mar 25, 2024

This may be causing this blocker: #38870

@luacmartins
Copy link
Contributor

luacmartins commented Mar 25, 2024

This may also be the cause for #38869. We're calling GetOlderActions in a loop

@kidroca
Copy link
Contributor

kidroca commented Mar 25, 2024

I've traced this to

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/yuwenmemon in version: 1.4.56-8 🚀

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


if (isFirstLinkedActionRender.current) {
return allReportActions.slice(indexOfLinkedAction);
}
Copy link
Contributor

@rayane-djouah rayane-djouah Apr 2, 2024

Choose a reason for hiding this comment

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

Coming from #38979

Encountered this bug when working on integrating comment linking with reports links :

Recording.2024-04-02.150523.mp4

Steps:

  1. Send some messages
  2. Hover over the last message and click on Reply in thread
  3. Click on parent thread link
  4. Send a message

Expected Result:
We can scroll to the newest sent message.
Actual Result:
New sent message is not displayed until refresh or scroll to top then to down (rerender)

I see that the new message is added to allReportActions but not to reportActions.

@perunt could you please guide on how can I fix this? why do we slice allReportActions here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isFirstLinkedActionRender.current is true only for the first render when we position the linked message. We slice it from the older messages to the linked message so that the linked message is located at the bottom. Then, fetchNewer is called, and we expand this with new items.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've found the cause of the bug: when we already have messages after the linked message, loadNewerChats and handleReportActionPagination are called and isFirstLinkedActionRender.current is set to false, but when the linked message is the last message in the report handleReportActionPagination is not called (based on hasNewestReportAction) and isFirstLinkedActionRender.current remains true.

I fixed it by adding this code in loadNewerChats function:

if (reportActionID && indexOfLinkedAction > -1 && hasNewestReportAction && isFirstLinkedActionRender.current) {
    isFirstLinkedActionRender.current = false;
    setCurrentReportActionID(newestReportAction?.reportActionID);
}

Comment on lines +129 to +135
const listID = useMemo(() => {
isFirstLinkedActionRender.current = true;
const newID = generateNewRandomInt(listOldID, 1, Number.MAX_SAFE_INTEGER);
listOldID = newID;
return newID;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [route, isLoadingInitialReportActions]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This caused #38909 – the fix was to early return if no reportActionID is provided, to trigger re-calculation only in the comment linking flow.

@jjcoffee
Copy link
Contributor

This caused an issue in #38878 where the composer would defocus when trying to edit the parent message in a thread (i.e. 1 level deep). This happens because the onPress event for the parent thread message bubbles to here:

<PressableWithSecondaryInteraction
ref={popoverAnchorRef}
onPress={onPress}

which then navigates to itself. The solution is to block the onPress there when the message is in draft. More details here and here.

@@ -548,7 +602,7 @@ function ReportActionsList({
ref={reportScrollManager.ref}
testID="report-actions-list"
style={styles.overscrollBehaviorContain}
data={sortedReportActions}
data={sortedVisibleReportActions}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same data(sortedVisibleReportActions) we need to pass to the renderItem prop displayAsGroup for consistency. This inconsistency causes the issue #38830 on deleting the comment.

const reportID = report.reportID;
const hasNewestReportAction = reportActions[0]?.isNewestReportAction;
const isLoading = (!!reportActionID && isLoadingInitialReportActions) || !isReadyForCommentLinking;
Copy link
Contributor

Choose a reason for hiding this comment

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

@perunt Coming from this issue, we're considering a proposal that would change the isLoading property to:

const isLoading = !!reportActionID && isLoadingInitialReportActions && !isReadyForCommentLinking;

This is in order to stop setting the reportActions array to empty here

if (isLoading || indexOfLinkedAction === -1) {
return [];
}

for cases where we already have the whole report and actions available in Onyx.

My problem is that I am a bit unsure what isLoadingInitialReportActions part is actually doing here. Are you able to explain why it's needed and/or what case it handles?

My guess is that it shouldn't be true if we've already opened the report and are just returning to it, i.e.

  1. Open some report (non-comment linked, so reportActionID evaluates as falsey)
  2. Navigate away and then return to that report via a comment link, so reportActionID will be true
  3. isLoadingInitialReportActions should not be true as we already have all the reportActions from (1), so isLoading will be false (assuming isReadyForCommentLinking is true).

Copy link
Contributor

Choose a reason for hiding this comment

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

@perunt bump, what do you think about the above proposal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks okay to me, but we need to be sure that we don't skip the first frame of rendering, as the whole positioning would be glitching. So, for testing this proposal, please use the test steps from this PR as well

Comment on lines +543 to +551
const isLinkedReportActionDeleted = useMemo(() => {
if (!reportActionIDFromRoute || !sortedAllReportActions) {
return false;
}
const action = sortedAllReportActions.find((item) => item.reportActionID === reportActionIDFromRoute);
return action && ReportActionsUtils.isDeletedAction(action);
}, [reportActionIDFromRoute, sortedAllReportActions]);

if (isLinkedReportActionDeleted ?? (!shouldShowSkeleton && reportActionIDFromRoute && reportActions?.length === 0 && !isLinkingToMessage)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have considered whisper actions which the user does not have access to here. This later caused #41370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: CRITICAL
Development

Successfully merging this pull request may close these issues.