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

Fix editing the message #24154

Closed

Conversation

Piotrfj
Copy link
Contributor

@Piotrfj Piotrfj commented Aug 4, 2023

Details

Fixed Issues

$ #18805
PROPOSAL: #18805 (comment)

Tests

  • Verify that no errors appear in the JS console
    Scenario 1:
  1. Open chat as a user A with user B.
  2. write a message and open edit mode on it.
  3. As a user B write couple (or just spam a lot) of messages on the same chat.
  4. The edit box should not be pushed up as new messages are appearing.

Scenario 2:

  1. Open chat and open edit mode on some report.
  2. Lose focus on the edit box and move it somewhere upper on the screen.
  3. Focus the box again, the box should be moved to the bottom of the screen without any troubles.

Offline tests

Bug is only testable on online mode since we are testing behavior when new messages are appearing.

QA Steps

  • Verify that no errors appear in the JS console

Scenario 1:

  1. Open chat as a user A with user B.
  2. write a message and open edit mode on it.
  3. As a user B write couple (or just spam a lot) of messages on the same chat.
  4. The edit box should not be pushed up as new messages are appearing.

Scenario 2:

  1. Open chat and open edit mode on some report.
  2. Lose focus on the edit box and move it somewhere upper on the screen.
  3. Focus the box again, the box should be moved to the bottom of the screen without any troubles.

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 / Chrome
    • iOS / native
    • iOS / 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 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
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • 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(themeColors.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 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 author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Kapture.2023-08-30.at.23.43.00.mp4
Android
Kapture.2023-08-30.at.23.14.54.mp4

@Piotrfj Piotrfj marked this pull request as ready for review August 14, 2023 12:32
@Piotrfj Piotrfj requested a review from a team as a code owner August 14, 2023 12:32
@melvin-bot melvin-bot bot requested review from srikarparsi and removed request for a team August 14, 2023 12:32
@melvin-bot
Copy link

melvin-bot bot commented Aug 14, 2023

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

Copy link
Contributor

@rezkiy37 rezkiy37 left a comment

Choose a reason for hiding this comment

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

Left a couple comments

…2-Unable-to-edit-message

# Conflicts:
#	src/pages/home/report/ReportActionItemMessageEdit.js
#	src/pages/home/report/ReportActionsList.js
Comment on lines +8 to +11
shouldFreezeScroll: PropTypes.bool,

/** Function to update the state */
setShouldFreezeScroll: PropTypes.func,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
shouldFreezeScroll: PropTypes.bool,
/** Function to update the state */
setShouldFreezeScroll: PropTypes.func,
shouldFreezeScroll: PropTypes.bool.isRequired,
/** Function to update the state */
setShouldFreezeScroll: PropTypes.func.isRequired,

);

return <ReportActionListFrozenScrollContext.Provider
value={contextValue}>{props.children}</ReportActionListFrozenScrollContext.Provider>;
Copy link
Contributor

Choose a reason for hiding this comment

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

The useMemo looks like an overhead here.
cc @fabioh8010 @gedu

Suggested change
value={contextValue}>{props.children}</ReportActionListFrozenScrollContext.Provider>;
value={{
shouldFreezeScroll,
setShouldFreezeScroll,
}}>{props.children}</ReportActionListFrozenScrollContext.Provider>;

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's correct @rezkiy37, because if we pass an object in this way, is like we are creating a new object every time and it will trigger unnecessary re-renders (old object will never equal newly created one). It makes sense to me to memoize.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is ok to memo. it is a common practice to always memo the objects from Context

Copy link
Contributor

@ArekChr ArekChr Aug 21, 2023

Choose a reason for hiding this comment

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

This does not need to be memoized. We could return the useStateobject to the provider (as an array, not object), which will be the same reference on every render. WDYT?

function ReportActionListFrozenScrollContextProvider(props) {
    const shouldFreezeScrollState = useState(false);
    return (
        <ReportActionListFrozenScrollContext.Provider value={shouldFreezeScrollState}>
            {props.children}
        </ReportActionListFrozenScrollContext.Provider>
    );
}

Copy link
Contributor

@rezkiy37 rezkiy37 Aug 21, 2023

Choose a reason for hiding this comment

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

Agree with @ArekChr's approach.

Copy link
Contributor

@rezkiy37 rezkiy37 left a comment

Choose a reason for hiding this comment

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

Left a couple comments. In general, LGTM.

);

return <ReportActionListFrozenScrollContext.Provider
value={contextValue}>{props.children}</ReportActionListFrozenScrollContext.Provider>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's correct @rezkiy37, because if we pass an object in this way, is like we are creating a new object every time and it will trigger unnecessary re-renders (old object will never equal newly created one). It makes sense to me to memoize.

children: PropTypes.node.isRequired,
};

function withScrollFrozen(WrappedComponent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we creating this HOC? It's not being used anywhere.

* @returns {Object}
*/
export default function useFrozenScroll() {
return useContext(ReportActionListFrozenScrollContext);
Copy link
Contributor

@ArekChr ArekChr Aug 21, 2023

Choose a reason for hiding this comment

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

We could improve error handling here.

Suggested change
return useContext(ReportActionListFrozenScrollContext);
const context = useContext(ReportActionListFrozenScrollContext);
if (context === undefined)
throw new Error('useFrozenScroll must be used within ReportActionListFrozenScrollContextProvider');
}
return context;

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

Resolve conflicts. Adding myself as a reviewer

…2-Unable-to-edit-message

# Conflicts:
#	src/pages/home/ReportScreen.js
#	src/pages/home/report/ReportActionItemMessageEdit.js
#	src/pages/home/report/ReportActionsList.js
@Piotrfj
Copy link
Contributor Author

Piotrfj commented Aug 23, 2023

@Santhosh-Sellavel conflicts are resolved

@Santhosh-Sellavel
Copy link
Collaborator

Still conflicts

…2-Unable-to-edit-message

# Conflicts:
#	src/pages/home/report/ReportActionItemMessageEdit.js
@Piotrfj
Copy link
Contributor Author

Piotrfj commented Aug 28, 2023

@Santhosh-Sellavel conflicts resolved, looks like in the middle of pr there were changes again in one of the files

@Santhosh-Sellavel
Copy link
Collaborator

This ran into conflicts again.

…2-Unable-to-edit-message

# Conflicts:
#	src/pages/home/ReportScreen.js
@Piotrfj
Copy link
Contributor Author

Piotrfj commented Aug 29, 2023

@Santhosh-Sellavel looks like there was refactoring meanwhile to functional component, conflicts resolved

@Santhosh-Sellavel
Copy link
Collaborator

@Piotrfj Please add recordings

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented Aug 29, 2023

@Piotrfj Update what to test/verify on different platforms.

@Piotrfj
Copy link
Contributor Author

Piotrfj commented Sep 22, 2023

@marcochavezf done :')

@marcochavezf
Copy link
Contributor

Oh now lint errors 😌

@Piotrfj
Copy link
Contributor Author

Piotrfj commented Sep 25, 2023

@marcochavezf done :)

@Santhosh-Sellavel
Copy link
Collaborator

@Piotrfj Still lint failing!

@Santhosh-Sellavel
Copy link
Collaborator

@Piotrfj

Tests fails And Glitch while running test steps on a new thread/chat. Definitely Deploy blockers it could affect new users experience.

Screen.Recording.2023-09-26.at.1.21.53.AM.mov

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

@gedu
Copy link
Contributor

gedu commented Sep 28, 2023

He is on sick leave, he will be back soon

@Piotrfj
Copy link
Contributor Author

Piotrfj commented Oct 2, 2023

@Santhosh-Sellavel looking at it today

@Santhosh-Sellavel
Copy link
Collaborator

Bump @Piotrfj

1 similar comment
@Santhosh-Sellavel
Copy link
Collaborator

Bump @Piotrfj

@Piotrfj
Copy link
Contributor Author

Piotrfj commented Oct 10, 2023

@Santhosh-Sellavel There is a difference between safari and other environments in behavior I havent discovered before, currently Im working on the solution that would take care of that and will not affect other environments

@Santhosh-Sellavel
Copy link
Collaborator

I remember this affects all Mweb not just Safari, please check again & confirm.

@Santhosh-Sellavel
Copy link
Collaborator

Can resolve conflicts please?

@TomaszFrackowiak
Copy link

@Santhosh-Sellavel , hey @Piotrfj is on sick leave. He should be back tomorrow.

@Piotrfj
Copy link
Contributor Author

Piotrfj commented Oct 18, 2023

@Santhosh-Sellavel just came back from sick leave, going back to work on the issue, will give some feedback today.

@Santhosh-Sellavel
Copy link
Collaborator

Any update @Piotrfj?

@Piotrfj
Copy link
Contributor Author

Piotrfj commented Oct 25, 2023

@Santhosh-Sellavel I have put the comment on different task by mistake, first solution was buggy and right now I'm close to complete second solution, but still I'm encountering problems with safari. Will give some more feedback tomorrow as I will discuss this with inner teammates.

@Piotrfj
Copy link
Contributor Author

Piotrfj commented Oct 26, 2023

@Santhosh-Sellavel After all this battle and consulting I haven't been able to provide well working solution. However we have found that the issue is in progres on react-native-web library. So we are suggesting to put our issue ON HOLD until the problem is resolved at source or merge current solution (only safari is not working) and open new issue just for safari.

@Piotrfj
Copy link
Contributor Author

Piotrfj commented Oct 26, 2023

@Santhosh-Sellavel necolas/react-native-web#2588 thats the issue I was talking about.

@srikarparsi
Copy link
Contributor

Hey! Please re-assign me when this PR is ready for review :)

@srikarparsi srikarparsi removed their request for review November 7, 2023 00:42
@Santhosh-Sellavel
Copy link
Collaborator

Can you resolve conflicts, let's test this again to confirm this.

I remember this affects all Mweb not just Safari, please check again & confirm.

@mallenexpensify mallenexpensify requested review from situchan and removed request for situchan May 29, 2024 19:19
@marcochavezf
Copy link
Contributor

It's been a year without activity, I will close it out to remove it from the k2. However, feel free to re-open if there's something we need to look up

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.

10 participants