-
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
Fix: Do not modify room name on the UI in RoomNameInput. #8512
Conversation
src/components/RoomNameInput.js
Outdated
@@ -73,7 +73,7 @@ class RoomNameInput extends Component { | |||
const target = nativeEvent.target; | |||
const selection = target.selectionStart; | |||
const modifiedRoomName = this.modifyRoomName(roomName); | |||
this.setState({roomName: modifiedRoomName}, () => { | |||
this.setState({roomName: `${CONST.POLICY.ROOM_PREFIX}${roomName}`}, () => { |
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.
@eVoloshchak can't we get rid of the value
prop from TextInput
, roomName from state, and the entire selection logic?
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.
@eVoloshchak can't we get rid of the
value
prop fromTextInput
, roomName from state, and the entire selection logic?
We can, I've updated the PR
src/components/RoomNameInput.js
Outdated
|
||
this.setModifiedRoomName = this.setModifiedRoomName.bind(this); | ||
} | ||
|
||
/** | ||
* Sets the modified room name in the state and calls the onChangeText callback | ||
* Calls the onChangeText callback with a modified room name | ||
* @param {Event} event | ||
*/ | ||
setModifiedRoomName(event) { | ||
const nativeEvent = event.nativeEvent; | ||
const roomName = nativeEvent.text; |
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.
One last change :)
const roomName = nativeEvent.text; | |
const roomName = event.nativeEvent.text; |
src/components/RoomNameInput.js
Outdated
@@ -108,7 +96,7 @@ class RoomNameInput extends Component { | |||
prefixCharacter={CONST.POLICY.ROOM_PREFIX} | |||
placeholder={this.props.translate('newRoomPage.social')} | |||
onChange={this.setModifiedRoomName} | |||
value={this.state.roomName.substring(1)} | |||
defaultValue={this.props.initialValue} |
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.
@eVoloshchak sorry that I didn't notice this earlier -
-
Passing
initialValue
shows an extra#
.
We could fix this by not displaying the first character ofinitialValue
(gotta be careful about the edge cases tho). Please let me know if you have any better ideas to fix this. -
I believe we can remove
initialValue
prop from WorkspaceNewRoomPage.
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.
- Passing
initialValue
shows an extra#
.
We could fix this by not displaying the first character ofinitialValue
(gotta be careful about the edge cases tho). Please let me know if you have any better ideas to fix this.
Yup, my bad, omitting first character was actually implemented before.
- I believe we can remove
initialValue
prop from WorkspaceNewRoomPage.
We can, updated the PR
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.
Thanks!
src/components/RoomNameInput.js
Outdated
@@ -108,7 +96,7 @@ class RoomNameInput extends Component { | |||
prefixCharacter={CONST.POLICY.ROOM_PREFIX} | |||
placeholder={this.props.translate('newRoomPage.social')} | |||
onChange={this.setModifiedRoomName} | |||
value={this.state.roomName.substring(1)} | |||
defaultValue={this.props.initialValue.substring(1)} |
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.
Can you please add a comment here explaining why the substring()
is needed?
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.
Can you please add a comment here explaining why the
substring()
is needed?
Done
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.
Looks good, thanks!
src/components/RoomNameInput.js
Outdated
@@ -108,7 +96,7 @@ class RoomNameInput extends Component { | |||
prefixCharacter={CONST.POLICY.ROOM_PREFIX} | |||
placeholder={this.props.translate('newRoomPage.social')} | |||
onChange={this.setModifiedRoomName} | |||
value={this.state.roomName.substring(1)} | |||
defaultValue={this.props.initialValue.substring(1)} // Since room name always starts with a prefix, we omit the first character |
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.
@eVoloshchak NAB: This makes it easier to read the comment
defaultValue={this.props.initialValue.substring(1)} // Since room name always starts with a prefix, we omit the first character | |
// Since room name always starts with a prefix, we omit the first character to avoid displaying it twice. | |
defaultValue={this.props.initialValue.substring(1)} |
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.
@eVoloshchak NAB: This makes it easier to read the comment
This results in a following linter error: Expected no line gap between “onChange” and “defaultValue” react/jsx-props-no-multi-space
.
But if you remove the gap, it breaks another rule: Expected line before comment lines-around-comment
.
I couldn't find a way to satisfy both lines-around-comment
and jsx-props-no-multi-space
(they seem to contradict each other), please let me know if I'm missing something
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.
Ohhh interesting. I'll raise it on slack, but for now please just update this comment.
Everything else looks great!
defaultValue={this.props.initialValue.substring(1)} // Since room name always starts with a prefix, we omit the first character | |
defaultValue={this.props.initialValue.substring(1)} // Since the room name always starts with a prefix, we omit the first character to avoid displaying it twice. |
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.
@deetergp LGTM! 🎉
- 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 verified the steps for local testing are in the
- 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 notonIconClick
). - 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
- 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.
- 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. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor) - Any internal methods bound to
this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
) - 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 thatAvatar
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.
Screen recs for iOS and Desktop because the PR author missed them Screen.Recording.2022-04-11.at.12.40.17.AM.movScreen.Recording.2022-04-11.at.12.44.52.AM.mov |
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.
LGTM!
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
We are unable to fully verify this PR due to known issue #8534 |
🚀 Deployed to production by @yuwenmemon in version: 1.1.55-2 🚀
|
Details
This fix is a result of the audit of all of the forms that aimed to fix any inconsistencies with modifying user input. During the audit it was discovered that RoomNameInput is modifying user's input. As per expected behaviour, I removed modification of user's input on the UI side, while modified room name is still passed to parent components internally.
Fixed Issues
#7524
Tests
PR Review Checklist
Contributor (PR Author) Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
filesSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)PR Reviewer Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
).src/languages/*
filesSTYLE.md
) were followed/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)QA Steps
Screenshots
Web
before.mp4
after.mp4
Mobile Web
22-04-06-19-15-35.mp4
Android
22-04-06-19-20-59.mp4