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

Fixed Checkbox and password cursor state while hiding/showing #13317

Closed
wants to merge 4 commits into from

Conversation

esh-g
Copy link
Contributor

@esh-g esh-g commented Dec 4, 2022

@Julesssss
@eVoloshchak

Details

Fixed the regression

Fixed Issues

$ #12018
$ #12018 (comment)

Tests

  1. Click on the password text Input
  2. Enter some text
  3. Verify that the cursor position stays the same on hiding/showing
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  • 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:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 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 was added in all src/languages/* files
    • 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.
    • 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
    • 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 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 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
chrome-new.2.mov
Mobile Web - Chrome
mWeb-Chrome.mp4
Safari
safari.mov
Desktop
Desktop.mov
iOS
iOS.mov
Android
android-new.mov

@esh-g esh-g requested a review from a team as a code owner December 4, 2022 18:36
@melvin-bot
Copy link

melvin-bot bot commented Dec 4, 2022

Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers!

@melvin-bot melvin-bot bot requested review from eVoloshchak and Julesssss and removed request for a team December 4, 2022 18:36
@melvin-bot
Copy link

melvin-bot bot commented Dec 4, 2022

@Julesssss @eVoloshchak 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]

Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

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

I'm seeing this error on pages with input/checkboxes. Not entirely sure it's caused by this PR, but has anyone else noticed it?

@eVoloshchak

Screenshot_1670327625

@esh-g
Copy link
Contributor Author

esh-g commented Dec 6, 2022

Strange. I never saw such error before. Doesn't seem like any property that I have changed..

@Julesssss
Copy link
Contributor

Yep, just confirmed that it's occurring on main too 👍

@esh-g
Copy link
Contributor Author

esh-g commented Dec 6, 2022

Oh nice! So, does this pass all the tests then?

@Julesssss
Copy link
Contributor

I need to review the new changes still, and will do after @eVoloshchak has had a chance to review.

// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
onMouseDown={props.onMouseDown ? props.onMouseDown : props.onPress}
onPress={undefined}
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
onPress={undefined}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this is important to set it as undefined because not doing so makes this event fire twice. That was the reason it was causing a regression earlier.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually this is important to set it as undefined because not doing so makes this event fire twice. That was the reason it was causing a regression earlier.

Oh, I see, thanks for pointing that out, I didn't realize it was passed with the ...props. I think we can use _.omit to make it more readable

// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
onPress={props.onPress ? props.onPress : props.onMouseDown}
onMouseDown={undefined}
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this break with a mouse connected to an android phone/tablet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so because the mouse click must also fire the onPress event as it does on the web version as well. On web, when the mouse is clicked, both onPress and onMouseDown as fired, so I wouldn't expect any reason for a different behaviour with a mouse connected to android..

// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
onMouseDown={props.onMouseDown ? props.onMouseDown : props.onPress}
onPress={undefined}
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually this is important to set it as undefined because not doing so makes this event fire twice. That was the reason it was causing a regression earlier.

Oh, I see, thanks for pointing that out, I didn't realize it was passed with the ...props. I think we can use _.omit to make it more readable

const Checkbox = props => (
<BaseCheckbox
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
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
{...props}
{..._.omit(props, 'onPress')}

const Checkbox = props => (
<BaseCheckbox
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
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
{...props}
{..._.omit(props, 'onMouseDown')}

<BaseCheckbox
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
onMouseDown={props.onMouseDown ? props.onMouseDown : props.onPress}
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
onMouseDown={props.onMouseDown ? props.onMouseDown : props.onPress}
onMouseDown={props.onMouseDown || props.onPress}

I might be wrong but this should be equivalent, for .native file too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me just try to apply all these changes and test once

@esh-g
Copy link
Contributor Author

esh-g commented Dec 7, 2022

Implemented all the requested changes in this commit

@eVoloshchak
Copy link
Contributor

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:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 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 was added in all src/languages/* files
    • 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.
    • 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 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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2022-12-07.at.21.52.03.mov
Mobile Web - Chrome
Screen_Recording_20221207-221022_Chrome.mp4
Mobile Web - Safari
Screen.Recording.2022-12-07.at.21.53.33.mov
Desktop
Screen.Recording.2022-12-07.at.22.14.42.mov
iOS
Screen.Recording.2022-12-07.at.22.12.47.mov
Android
Screen_Recording_20221207-221151_New.Expensify.mp4

@eVoloshchak
Copy link
Contributor

@Someone-here

  • It looks like there were recent updates and there are conflicts that need to be resolved
  • Please edit the title so it indicates what has been fixed

@Julesssss
Copy link
Contributor

Hey @Someone-here, I'll do the final review once the conflicts are resolved, then we can merge 🤞

@esh-g esh-g changed the title Fixed regression Fixed Checkbox and password cursor state while hiding/showing Dec 8, 2022
@esh-g
Copy link
Contributor Author

esh-g commented Dec 8, 2022

I synced my fork main branch with the expensify main then merged it into the current bugfix branch and resolved all the conflicts. I hope this eliminates all the conflicts.

<BaseCheckbox
// eslint-disable-next-line react/jsx-props-no-spreading
{..._.omit(props, 'onMouseDown')}
onPress={props.onPress || props.onMouseDown}
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to not mention this before, but I wonder why onMouseDown is necessary in the native Component? Perhaps a comment would help clear up why we need both to anyone looking at this in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// If no onPress is passed, then execute the onMouseDown function
Is this comment ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I add a commit with this comment?

Copy link
Contributor

@Julesssss Julesssss Dec 8, 2022

Choose a reason for hiding this comment

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

It just doesn't make much sense to me why native components would ever need onMouseDown. Couldn't it be removed entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is actually essential. You see what I'm doing here is not executing any code on the onMouseDown event, but if the onMouseDown prop is passed, then I am executing the prop passed on the onPress event because the onMouseDown doesn't fire in native.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense to me for the general component, but there will never be an onMouseDown event for the native component, right? Or am I missunderstanding

Copy link
Contributor Author

@esh-g esh-g Dec 8, 2022

Choose a reason for hiding this comment

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

Yes there will never be an onMouseDown According to my knowledge. You are you proposing to remove the omit from the props spread? I had just added it to eliminate any chance of double event firing in any edge case or such... At first I thought you were referring to the onPress={props.onPress || props.onMouseDown}, that line is essential but the omit is not essential, it just to make sure no edge cases or double event firing happens...

Copy link
Contributor

Choose a reason for hiding this comment

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

At first I thought you were referring to the onPress={props.onPress || props.onMouseDown}, that line is essential

Oh yeah, sorry that is what I meant. It would be great to add a comment that explains why this is necessary --- to help people like me who are a bit confused by seeing it there.

Copy link
Contributor Author

@esh-g esh-g Dec 8, 2022

Choose a reason for hiding this comment

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

Every checkbox can have two click handlers onPress and onMouseDown. As there is no onMouseDown event on native, any prop that is passed to be executed on the onMouseDown event should be executed on the onPress event instead.
Should I add this as a multiline comment above that line?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @Someone-here. This has made me realise that the solution is just a bit too complex for solving a small issue. Let's drop this one and move onto other bugs 👍

@Julesssss
Copy link
Contributor

I'm having second thoughts about this PR now as it's adding quite a bit of complexity to resolve a simple issue that could actually be considered expected native behavior. I worry that this makes the Checkbox component unnecessarily tied up with the callbacks. We'll still pay out, but I'm going to just close this PR and close the issue.

Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

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

Closed as explained here.

@Julesssss Julesssss closed this Dec 9, 2022
@esh-g
Copy link
Contributor Author

esh-g commented Dec 9, 2022

Okay, I guess.... So what will be my next course of action?

@Julesssss
Copy link
Contributor

Okay, I guess.... So what will be my next course of action?

Nothing left to do here. We'll pay out as usual.

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.

3 participants