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

Refactor AddressSearch to be compatible with Form #7701

Merged
merged 14 commits into from
Feb 24, 2022

Conversation

kakajann
Copy link
Contributor

Details

  1. An optional isFormInput prop.
  2. If isFormInput is true, require a inputID prop. Use getInputIDPropTypes to enforce this propType rule.
  3. Add an optional shouldSaveDraft prop. Defaults to false.

Done.

  1. Make the value prop optional

It was already optional.

  1. In the input’s onBlur method, call props.onBlur().
  2. In the input’s onChange method (or equivalent e.g. onTextChange, etc), call props.onChange().

Done.

  1. Remove the hasError prop

There was no hasError prop.

  1. Add an optional errorText prop. Defaults to an empty string.
  2. Update the error message to display if errorText is truth.

Done.

  1. Update the inline error display style so it is left aligned with the label and input value. See example image for TextInput

I don't think it's my concern. AdressSearch is using TextInput

  1. Make sure that props.ref is attached to the appropriate DOM node. This could involve forwarding the ref to a child component. This is important so we can call ref.focus().

Done.

  1. Add the input to the test Form stories and make sure that it works. You can check this by running npm run storybook and testing the component in the example form.

Done.

  1. Remove any unused code.

Nothing to remove.

Fixed Issues

$ #7538

Tests

  • Verify that no errors appear in the JS console

QA Steps

Nothing to test I guess. It's only refactor.

  • Verify that no errors appear in the JS console

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Screen Shot 2022-02-11 at 9 59 19 AM
Screen Shot 2022-02-11 at 9 59 07 AM
Screen Shot 2022-02-11 at 9 59 00 AM

@kakajann kakajann requested a review from a team as a code owner February 11, 2022 05:02
@MelvinBot MelvinBot requested review from marcochavezf and rushatgabhane and removed request for a team February 11, 2022 05:02
@kakajann kakajann changed the title Refactor AddressForm to be compatible with Form Refactor AddressSearch to be compatible with Form Feb 11, 2022
@luacmartins luacmartins self-requested a review February 14, 2022 11:25
Copy link
Member

@rushatgabhane rushatgabhane left a comment

Choose a reason for hiding this comment

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

@kakajann two things -

  1. Error from storybook - props.onChange isn't a function.
    image

  2. Point 10 isn't implemented - Error text needs to be aligned with label and input value as show here - [HOLD for payment 2022-03-17] Refactor AddressSearch to be compatible with Form #7538 (comment)

@kakajann
Copy link
Contributor Author

  1. Error from storybook - props.onChange isn't a function.
    image

I'll take a look at this soon.

  1. Point 10 isn't implemented - Error text needs to be aligned with label and input value as show here - #7538 (comment)

As I mentioned above, AddressSearch is using TextInput. I didn't want to modify it. It should have been done in this PR

Also, this PR covers the error alignment: https://github.com/Expensify/App/pull/7627/files

Do you still want me to modify error alignment?

@kakajann
Copy link
Contributor Author

@rushatgabhane

Error from storybook - props.onChange isn't a function

is fixed

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.

Left a few comments. I also see this error in Storybook when typing into the field (possibly related to my comment about onChange)

Screen Shot 2022-02-14 at 12 44 36 PM

src/components/AddressSearch.js Outdated Show resolved Hide resolved
src/components/AddressSearch.js Outdated Show resolved Hide resolved
src/components/AddressSearch.js Show resolved Hide resolved
inputID: props.inputID,
shouldSaveDraft: props.shouldSaveDraft,
onBlur: props.onBlur,
onChange: (text) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm wrong, but I believe that onChanteText passes the text value as argument vs onChange passes an event. We should make sure that we are passing the text value 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.

I think it returns only text value, considering AddressSearch is using TextInput as the base component.

onChangeText={this.setValue}

setValue(value) {
if (this.props.onChange) {
this.props.onChange(value);
}
this.value = value;
Str.result(this.props.onChangeText, value);
this.activateLabel();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm that is onChangeText though, not onChange. I tried logging the text value here and I see the following:

Screen Shot 2022-02-15 at 1 57 32 PM

Is that what we expect?

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.
Should I push this diff?

diff --git a/src/components/AddressSearch.js b/src/components/AddressSearch.js
index 005438f75..bee2e40cb 100644
--- a/src/components/AddressSearch.js
+++ b/src/components/AddressSearch.js
@@ -158,7 +158,7 @@ const AddressSearch = (props) => {
                 inputID: props.inputID,
                 shouldSaveDraft: props.shouldSaveDraft,
                 onBlur: props.onBlur,
-                onChange: (text) => {
+                onChangeText: (text) => {
                     if (skippedFirstOnChangeTextRef.current) {
                         props.onChange({street: text});
                     } else {

Copy link
Contributor

Choose a reason for hiding this comment

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

@kakajann Sorry for the late reply, I was ooo for most of last week. I think it's fine to keep onChangeText as we had before. The onChange handler will be passed by the parent Form component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@luacmartins, done

@kakajann
Copy link
Contributor Author

Left a few comments. I also see this error in Storybook when typing into the field (possibly related to my comment about onChange)

Screen Shot 2022-02-14 at 12 44 36 PM

Is this error occurs on the Form stories or the AddressSearch?

@luacmartins
Copy link
Contributor

Hmm I think that error is caused by a regression in TextInput. I already commented in the offending PR so hopefully we can get it fixed soon.

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 @kakajann! I believe since props.value can be undefined, we should add a check here so we don't try to access .trim() on undefined.

@kakajann
Copy link
Contributor Author

@luacmartins Done

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.

Sorry for all the back and forth. Left a few more comments.

src/stories/AddressSearch.stories.js Outdated Show resolved Hide resolved
* @param {Object} props - props passed to the input
* @returns {Object} - returns an Error object if isFormInput is supplied but inputID is falsey or not a string
*/
inputID: props => FormUtils.getInputIDPropTypes(props),
Copy link
Contributor

Choose a reason for hiding this comment

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

We renamed this util function to validateInputIDProps. Please update 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.

Done

Co-authored-by: Carlos Martins <luacmartins@gmail.com>
@kakajann
Copy link
Contributor Author

No problem @luacmartins

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! Thanks for all the changes @kakajann! @rushatgabhane and @marcochavezf all yours.

@rushatgabhane
Copy link
Member

Thanks for the review @luacmartins 🙇

Copy link
Member

@rushatgabhane rushatgabhane left a comment

Choose a reason for hiding this comment

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

@kakajann could you please merge main into your branch.

@marcochavezf LGTM! 🎉️
Tests well, and I gave this a run after merging main from upstream.

@kakajann
Copy link
Contributor Author

@rushatgabhane Done

@marcochavezf marcochavezf merged commit 1ab42ab into Expensify:main Feb 24, 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 Mar 1, 2022

🚀 Deployed to staging by @marcochavezf in version: 1.1.41-0 🚀

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

@OSBotify
Copy link
Contributor

OSBotify commented Mar 2, 2022

🚀 Deployed to staging by @marcochavezf in version: 1.1.41-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @francoisl in version: 1.1.41-6 🚀

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

@kakajann kakajann deleted the refactor/address-search branch March 11, 2022 00:12
@kakajann kakajann restored the refactor/address-search branch March 11, 2022 00:12
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.

5 participants