-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Changes from 3 commits
5fcb7b7
255d268
d699187
4387358
e868e06
2219e26
3cebf96
c2b4ce5
fbee850
996f12b
7186e17
9217a76
2392560
15926e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,13 +9,34 @@ import styles from '../styles/styles'; | |||||||||||||||||||
import TextInput from './TextInput'; | ||||||||||||||||||||
import Log from '../libs/Log'; | ||||||||||||||||||||
import * as GooglePlacesUtils from '../libs/GooglePlacesUtils'; | ||||||||||||||||||||
import * as FormUtils from '../libs/FormUtils'; | ||||||||||||||||||||
|
||||||||||||||||||||
// The error that's being thrown below will be ignored until we fork the | ||||||||||||||||||||
// react-native-google-places-autocomplete repo and replace the | ||||||||||||||||||||
// VirtualizedList component with a VirtualizedList-backed instead | ||||||||||||||||||||
LogBox.ignoreLogs(['VirtualizedLists should never be nested']); | ||||||||||||||||||||
|
||||||||||||||||||||
const propTypes = { | ||||||||||||||||||||
/** Indicates that the input is being used with the Form component */ | ||||||||||||||||||||
isFormInput: PropTypes.bool, | ||||||||||||||||||||
|
||||||||||||||||||||
/** | ||||||||||||||||||||
* The ID used to uniquely identify the input | ||||||||||||||||||||
* | ||||||||||||||||||||
* @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), | ||||||||||||||||||||
|
||||||||||||||||||||
/** Saves a draft of the input value when used in a form */ | ||||||||||||||||||||
shouldSaveDraft: PropTypes.bool, | ||||||||||||||||||||
|
||||||||||||||||||||
/** Callback that is called when the text input is blurred */ | ||||||||||||||||||||
onBlur: PropTypes.func, | ||||||||||||||||||||
|
||||||||||||||||||||
/** Error text to display */ | ||||||||||||||||||||
errorText: PropTypes.string, | ||||||||||||||||||||
|
||||||||||||||||||||
/** The label to display for the field */ | ||||||||||||||||||||
label: PropTypes.string.isRequired, | ||||||||||||||||||||
|
||||||||||||||||||||
|
@@ -32,6 +53,12 @@ const propTypes = { | |||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
const defaultProps = { | ||||||||||||||||||||
// ...defaultFieldPropTypes, | ||||||||||||||||||||
luacmartins marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
isFormInput: false, | ||||||||||||||||||||
inputID: undefined, | ||||||||||||||||||||
shouldSaveDraft: false, | ||||||||||||||||||||
onBlur: () => {}, | ||||||||||||||||||||
errorText: '', | ||||||||||||||||||||
value: '', | ||||||||||||||||||||
luacmartins marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
containerStyles: [], | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
@@ -111,11 +138,28 @@ const AddressSearch = (props) => { | |||||||||||||||||||
}} | ||||||||||||||||||||
textInputProps={{ | ||||||||||||||||||||
InputComp: TextInput, | ||||||||||||||||||||
ref: (node) => { | ||||||||||||||||||||
if (!props.innerRef) { | ||||||||||||||||||||
return; | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
luacmartins marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
if (_.isFunction(props.innerRef)) { | ||||||||||||||||||||
props.innerRef(node); | ||||||||||||||||||||
return; | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
// eslint-disable-next-line no-param-reassign | ||||||||||||||||||||
props.innerRef.current = node; | ||||||||||||||||||||
}, | ||||||||||||||||||||
label: props.label, | ||||||||||||||||||||
containerStyles: props.containerStyles, | ||||||||||||||||||||
errorText: props.errorText, | ||||||||||||||||||||
value: props.value, | ||||||||||||||||||||
onChangeText: (text) => { | ||||||||||||||||||||
isFormInput: props.isFormInput, | ||||||||||||||||||||
inputID: props.inputID, | ||||||||||||||||||||
shouldSaveDraft: props.shouldSaveDraft, | ||||||||||||||||||||
onBlur: props.onBlur, | ||||||||||||||||||||
onChange: (text) => { | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I'm wrong, but I believe that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it returns only text value, considering App/src/components/TextInput/BaseTextInput.js Line 240 in c049cc4
App/src/components/TextInput/BaseTextInput.js Lines 121 to 128 in c049cc4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm that is Is that what we expect? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. 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 { There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @luacmartins, done |
||||||||||||||||||||
if (skippedFirstOnChangeTextRef.current) { | ||||||||||||||||||||
props.onChange({street: text}); | ||||||||||||||||||||
} else { | ||||||||||||||||||||
|
@@ -160,4 +204,7 @@ const AddressSearch = (props) => { | |||||||||||||||||||
AddressSearch.propTypes = propTypes; | ||||||||||||||||||||
AddressSearch.defaultProps = defaultProps; | ||||||||||||||||||||
|
||||||||||||||||||||
export default withLocalize(AddressSearch); | ||||||||||||||||||||
export default withLocalize(React.forwardRef((props, ref) => ( | ||||||||||||||||||||
// eslint-disable-next-line react/jsx-props-no-spreading | ||||||||||||||||||||
<AddressSearch {...props} innerRef={ref} /> | ||||||||||||||||||||
))); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import AddressSearch from '../components/AddressSearch'; | ||
|
||
/** | ||
* We use the Component Story Format for writing stories. Follow the docs here: | ||
* | ||
* https://storybook.js.org/docs/react/writing-stories/introduction#component-story-format | ||
*/ | ||
export default { | ||
title: 'Components/AddressSearch', | ||
component: AddressSearch, | ||
args: { | ||
label: 'Enter street', | ||
errorText: '', | ||
}, | ||
}; | ||
|
||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
const Template = args => <AddressSearch {...args} />; | ||
|
||
// Arguments can be passed to the component by binding | ||
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args | ||
const Default = Template.bind({}); | ||
|
||
const ErrorStory = Template.bind({}); | ||
ErrorStory.args = { | ||
errorText: 'The street you looking for is not exist', | ||
kakajann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
export { | ||
Default, | ||
ErrorStory, | ||
}; |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done