Fix: Do not modify room name on the UI in RoomNameInput.#8512
Conversation
| 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.
@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.
@eVoloshchak can't we get rid of the
valueprop fromTextInput, roomName from state, and the entire selection logic?
We can, I've updated the PR
| */ | ||
| setModifiedRoomName(event) { | ||
| const nativeEvent = event.nativeEvent; | ||
| const roomName = nativeEvent.text; |
There was a problem hiding this comment.
One last change :)
| const roomName = nativeEvent.text; | |
| const roomName = event.nativeEvent.text; |
| 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.
@eVoloshchak sorry that I didn't notice this earlier -
-
Passing
initialValueshows 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
initialValueprop from WorkspaceNewRoomPage.
There was a problem hiding this comment.
- Passing
initialValueshows 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
initialValueprop from WorkspaceNewRoomPage.
We can, updated the PR
| 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.
Can you please add a comment here explaining why the substring() is needed?
There was a problem hiding this comment.
Can you please add a comment here explaining why the
substring()is needed?
Done
| 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.
@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.
@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.
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.
@deetergp LGTM! 🎉
- I verified the correct issue is linked in the
### Fixed Issuessection 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
Testssection - I verified the steps for Staging and/or Production testing are in the
QA stepssection - 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.
toggleReportand 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
displayNameproperty - 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
thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor) - Any internal methods bound to
thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis 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
Avataris modified, I verified thatAvataris 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 |
|
✋ 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 Issuessection aboveTestssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*filesSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */displayNamepropertythisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)Avataris modified, I verified thatAvataris working as expected in all cases)PR Reviewer Checklist
### Fixed Issuessection aboveTestssectionQA stepssectiontoggleReportand notonIconClick).src/languages/*filesSTYLE.md) were followed/** comment above it */displayNamepropertythisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)Avataris modified, I verified thatAvataris 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