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

statepicker refactored to compatible with form #8758

Merged
merged 11 commits into from
Apr 28, 2022

Conversation

jayeshmangwani
Copy link
Contributor

@jayeshmangwani jayeshmangwani commented Apr 23, 2022

Details

Fixed Issues

$ #7537

Tests

  1. Go to Add debit card page under, Settings > Payments > Add Payment method
  2. press save without selecting a state from the StatePicker
  3. we will get an error message for the state picker (before there were no errors)
  4. Now press on the StatePicker, we will able to see states list and select any state from the list , it should work (before it was not selectable onChange was not working before changes)

Test under storybook

  1. run storybook using npm run storybook
  2. Select Form from the LHS
  3. Select InputError from the options
  4. Last option is StatePicker with label State , and we can test here working of the picker (select , update , errorText)
  • Verify that no errors appear in the JS console

PR Review Checklist

Contributor (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 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 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)
    • [ 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)
    • 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 tagging the marketing team 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
  • 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 */
    • Any functional components have the displayName property
    • 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
  • 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.

PR Reviewer Checklist

  • 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 verified tests pass on all platforms & I tested again 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 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 tagging the marketing team 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 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 */
    • Any functional components have the displayName property
    • 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.

QA Steps

  1. Go to Add debit card page under, Settings > Payments > Add Payment method
  2. press save without selecting a state from the StatePicker
  3. we will get an error message for the state picker
  4. Now press on the StatePicker, we will able to see states list and select any state from the list , it should work
  • Verify that no errors appear in the JS console

Screenshots

Web

After-7537.mov

Mobile Web

mWeb.mov

Desktop

8758-Desktop.mov

iOS

8758-iOs.mov

Android

8758-Android.mp4

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

@jayeshmangwani jayeshmangwani requested a review from a team as a code owner April 23, 2022 07:39
@melvin-bot
Copy link

melvin-bot bot commented Apr 23, 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 luacmartins and parasharrajat and removed request for a team April 23, 2022 07:39
@github-actions
Copy link
Contributor

github-actions bot commented Apr 23, 2022

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

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

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

Please attach test videos for all platforms and sign the CLA.

  • Missing QA steps.

src/components/StatePicker.js Outdated Show resolved Hide resolved
value={props.value}
label={props.label || props.translate('common.state')}
hasError={props.hasError}
errorText={props.errorText}
onBlur={props.onBlur}
containerStyles={props.containerStyles}
Copy link
Member

Choose a reason for hiding this comment

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

Did you define this prop? I don't think we need this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I have defined this, onBlur was in task's requirement, and containerStyles added for styling the picker

Copy link
Member

Choose a reason for hiding this comment

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

I don't see the prop definitions for these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes you are right, I have not defined containerStyles in props, and it was also not included in the task to add, so I think I should remove containerStyles from here

placeholder={{value: '', label: '-'}}
items={STATES}
onInputChange={props.onChange}
onInputChange={props.onInputChange}
value={props.value}
label={props.label || props.translate('common.state')}
hasError={props.hasError}
Copy link
Member

Choose a reason for hiding this comment

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

This should be removed. Right?

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 think we have to update the name only from onChange to onInputChange, if i am removing this then picker is not working

Copy link
Member

Choose a reason for hiding this comment

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

I meant the hasError. Review comments refer to the line on which they are tagged.

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 have removed hasError from props only, let me remove hasError from here too


/** Error text to display */
errorText: PropTypes.string,

...withLocalizePropTypes,
};

const defaultProps = {
label: '',
value: '',
Copy link
Member

Choose a reason for hiding this comment

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

Maybe pass undefined. '' is still a value. I am not sure if Picker checks for truthy value before binding it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

an empty string will work here, we are checking this at 2 places

if (_.isEmpty(props.children)) {
return null;
}

const hasError = !_.isEmpty(this.props.errorText);

Copy link
Member

Choose a reason for hiding this comment

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

I am talking about the value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes value will be undefined here

@jayeshmangwani
Copy link
Contributor Author

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

Co-authored-by: Rajat Parashar <parasharrajat@users.noreply.github.com>
value={this.state.incorporationState}
errorText={this.getErrorText('incorporationState')}
hasError={this.getErrors().incorporationState}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we remove these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing out these changes, Yes I need to change all these places where we are using StatePicker,

hasError={Boolean(props.errors.state)}

hasError={this.getErrors().incorporationState}

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

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

Did you run npm run lint? Can you please proactively test your changes? Please ping me when you think it's fully ready.

Copy link
Contributor

@luacmartins luacmartins left a comment

Choose a reason for hiding this comment

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

A few comments:

  1. Test steps seem to be incomplete.
  2. Video for mWeb is 0s long.
  3. There are a few lint errors:
    Screen Shot 2022-04-25 at 11 53 45 AM

@@ -72,7 +72,6 @@ const AddressForm = props => (
value={props.values.state}
onChange={value => props.onFieldChange({state: value})}
Copy link
Contributor

Choose a reason for hiding this comment

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

We have to rename onChange to onInputChange

value={this.state.incorporationState}
hasError={this.getErrors().incorporationState}
errorText={this.getErrorText('incorporationState')}
Copy link
Contributor

Choose a reason for hiding this comment

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

The incorporationState key is not defined here.

inputID="pickState"
shouldSaveDraft
isFormInput
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a top margin like the other inputs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have not defined a style prop for StatePicker, we need to create containerStyles prop here

Copy link
Contributor

@luacmartins luacmartins Apr 25, 2022

Choose a reason for hiding this comment

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

or you can just wrap it in a View like we do in all calls of StatePicker, e.g.

<View style={styles.mt4}>
<StatePicker
label={this.props.translate('companyStep.incorporationState')}
onChange={value => this.clearErrorAndSetValue('incorporationState', value)}
value={this.state.incorporationState}
hasError={this.getErrors().incorporationState}
/>
</View>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohkay

src/components/StatePicker.js Show resolved Hide resolved
@luacmartins
Copy link
Contributor

We should also define StatePicker here

@jayeshmangwani
Copy link
Contributor Author

A few comments:

  1. Test steps seem to be incomplete.
  2. Video for mWeb is 0s long.
  3. There are a few lint errors:
    Screen Shot 2022-04-25 at 11 53 45 AM
  1. tried npm run test, its working, then I tried npm run lint but it is stuck there in command line I have waited 3-4 hours but lint was not showing error nor success message
  2. video updated
  3. lint errors solved

@luacmartins
Copy link
Contributor

tried npm run test, its working, then I tried npm run lint but it is stuck there in command line I have waited 3-4 hours but lint was not showing error nor success message

I mean the Test steps in your PR description, i.e.:

  1. Go to Add debit card
  2. press save without selecting state from the picker
  3. we will get an error message for state picker

@jayeshmangwani
Copy link
Contributor Author

tried npm run test, its working, then I tried npm run lint but it is stuck there in command line I have waited 3-4 hours but lint was not showing error nor success message

I mean the Test steps in your PR description, i.e.:

  1. Go to Add debit card
  2. press save without selecting state from the picker
  3. we will get an error message for state picker

Thank you for the update,

I have updated the description please check whenever you get the time and please let me know if I have missed any point as it's my first PR in the repo.

parasharrajat
parasharrajat previously approved these changes Apr 26, 2022
Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

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

The code looks good and tests well. You will have to add the QA steps before we can merge this. @jayeshmangwani

Note: QA team can't run run storybook using npm run storybook so use Go to https://staging.new.expensify.com/docs/index.html for storybook

cc: @luacmartins

PR Reviewer Checklist

  • I verified the PR has a small number of commits behind main
  • 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 testing environment is mentioned in the test steps
  • I verified testing steps cover success & fail scenarios (if applicable)
  • I checked that screenshots or videos are included 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
  • I verified there are no console errors related to changes in this PR
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified comments were added when the code was not self explanatory
    • I verified any copy / text shown in the product was added in all src/languages/* files (if applicable)
    • I verified proper naming convention for platform-specific files was followed (if applicable)
    • I verified style guidelines were followed
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components are not impacted by changes in this PR (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 the UI performance was not affected (the performance is the same than main branch)
  • If a new component is created I verified that a similar component doesn't exist in the codebase

🎀 👀 🎀 C+ reviewed

@jayeshmangwani
Copy link
Contributor Author

@parasharrajat added QA steps

Copy link
Contributor

@luacmartins luacmartins left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. Left one more comment.

@@ -198,6 +210,7 @@ InputError.args = {
accountNumber: '',
pickFruit: '',
pickAnotherFruit: '',
pickState: '',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also add a non-empty default value for pickState here?

During my testing, the default value didn't seem to work properly on page load.

storybook.mov

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 think we have to add 1 more prop in StatePicker for this change, we need to pass defaultValue to make it work

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 have added a default value for pickState, but we also have to pass defaultValue in StatePicker component, please let me know your thought on this

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds similar to what I'm doing in the Datepicker refactor. If that's the case I think it's fine :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, then its fine

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm the default value still doesn't load for me. Can you please check?

default.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@parasharrajat
Copy link
Member

@jayeshmangwani Please merge main as there are conflicts. Thanks.

@jayeshmangwani
Copy link
Contributor Author

@parasharrajat latest main branch merged,
@luacmartins I have added an extra field in StatePicker for defaultValue, please check this, it is working now

@parasharrajat
Copy link
Member

parasharrajat commented Apr 27, 2022

@jayeshmangwani
Copy link
Contributor Author

Yes this solution is working for me, I have tested in storybook

shouldSaveDraft: false,
isFormInput: false,
inputID: undefined,
onBlur: () => {},
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I see this console warning:
warn

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's solved now, now tested the app in the web and no error is there and picker is working

Screenshot 2022-04-28 at 11 14 19 AM

tested in storybook , its working fine and no console error

storybook-test.mov

value={props.value}
defaultValue={props.defaultValue}
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 we should pass either value or defaultValue but not both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now added conditional value here, if the value is available then the value will be used otherwise defaultValue

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Contributor

@luacmartins luacmartins left a comment

Choose a reason for hiding this comment

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

LGTM and tests well. Thanks for the work @jayeshmangwani

@luacmartins luacmartins merged commit db6fab7 into Expensify:main Apr 28, 2022
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented May 9, 2022

🚀 Cherry-picked to staging by @sketchydroide in version: 1.1.57-8 🚀

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

@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @chiragsalian in version: 1.1.57-17 🚀

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

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.

4 participants