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

[HOLD for payment 2022-12-02] [$250] Cursor moves to end after adding space in Room Name reported by @varshamb #12741

Closed
kavimuru opened this issue Nov 15, 2022 · 48 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@kavimuru
Copy link

kavimuru commented Nov 15, 2022

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:-

  1. Navigate to Room
  2. Click header to open details of Room
  3. goto Room Settings
  4. Add space in Room Name and observe the Cursor

Expected Result:

Cursor should not moves to end after adding space in Room Name.

Actual Result:

Cursor is moving to end after adding space in Room Name.

Workaround:

unknown

Platform:

Where is this issue occurring?

  • Web

Version Number: 1.2.27-4
Reproducible in staging?: y
Reproducible in production?: y
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos:

Screen.Recording.2022-11-15.at.9.16.54.AM.mov
Recording.935.mp4

Expensify/Expensify Issue URL:
Issue reported by: @varshamb
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1668484634763459

View all open jobs on GitHub

Upwork Automation - Do Not Edit

@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Nov 15, 2022
@melvin-bot
Copy link

melvin-bot bot commented Nov 15, 2022

Triggered auto assignment to @Christinadobrzyn (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@Christinadobrzyn
Copy link
Contributor

Christinadobrzyn commented Nov 16, 2022

  • Can this be reproduced? Yes

  • I can reproduce this on the Production desktop app v 1.2.27-4 (1.2.27-4)

  • I can reproduce this on staging and mobile app staging v1.2.28-0

  • Any other Ghs relate to this? No

  • I don't see any other GHs related to this issue

  • Does this need to be fixed? I don't know

  • Thinking more about this, I'm not actually sure we need to change anything. When a space is added, it creates a _ so it's not like it doesn't work but the display is different than what a user might expect. But is there any reason to have a space in a room name? I'm not 100% sold on why this needs to be fixed. Going to assign the Exernal label to get more thoughts.

2022-11-16_10-53-32 (1)

@Christinadobrzyn Christinadobrzyn added the External Added to denote the issue can be worked on by a contributor label Nov 16, 2022
@melvin-bot
Copy link

melvin-bot bot commented Nov 16, 2022

Current assignee @Christinadobrzyn is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Nov 16, 2022

Triggered auto assignment to Contributor-plus team member for initial proposal review - @Santhosh-Sellavel (External)

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 16, 2022
@melvin-bot
Copy link

melvin-bot bot commented Nov 16, 2022

Triggered auto assignment to @thienlnam (External), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@melvin-bot melvin-bot bot changed the title Cursor moves to end after adding space in Room Name reported by @varshamb [$250] Cursor moves to end after adding space in Room Name reported by @varshamb Nov 16, 2022
@Pujan92
Copy link
Contributor

Pujan92 commented Nov 16, 2022

I can see it is the intentional behavior from the code, on room name change we are applying the modifyRoomName function to replace space(' ') with underscore('_') and etc. As we are replacing the string on each keystroke cursor will moves to the end only.

modifyRoomName(roomName) {
const modifiedRoomNameWithoutHash = roomName
.replace(/ /g, '_')
.replace(/[^a-zA-Z\d_]/g, '')
.substr(0, CONST.REPORT.MAX_ROOM_NAME_LENGTH)
.toLowerCase();
return `${CONST.POLICY.ROOM_PREFIX}${modifiedRoomNameWithoutHash}`;
}

@varshamb
Copy link
Contributor

@thienlnam @Santhosh-Sellavel
Is there any specific reason for not allowing Room Name with space?

@Santhosh-Sellavel
Copy link
Collaborator

I guess the room name should single word

@thienlnam
Copy link
Contributor

Yeah, this is intentional - we could update it so that it keeps the cursor where the underscore was added. Though, similar to #11146 (comment) we're going close since it's related to keyboard navigation / accessibility

@melvin-bot
Copy link

melvin-bot bot commented Nov 16, 2022

Looks like something related to react-navigation may have been mentioned in this issue discussion.

As a reminder, please make sure that all proposals are not workarounds and that any and all attempt to fix the issue holistically have been made before proceeding with a solution. Proposals to change our DeprecatedCustomActions.js files should not be accepted.

Feel free to drop a note in #expensify-open-source with any questions.

@s77rt
Copy link
Contributor

s77rt commented Nov 16, 2022

Proposal

diff --git a/src/components/RoomNameInput.js b/src/components/RoomNameInput.js
index 95e016cd6..07d025613 100644
--- a/src/components/RoomNameInput.js
+++ b/src/components/RoomNameInput.js
@@ -17,6 +17,15 @@ const propTypes = {
     /** Error text to show */
     errorText: PropTypes.string,
 
+    /** Update selection position on change */
+    onSelectionChange: PropTypes.func,
+
+    /** Selection Object */
+    selection: PropTypes.shape({
+        start: PropTypes.number,
+        end: PropTypes.number,
+    }),
+
     ...withLocalizePropTypes,
 
     /** A ref forwarded to the TextInput */
@@ -28,6 +37,11 @@ const defaultProps = {
     value: '',
     disabled: false,
     errorText: '',
+    onSelectionChange: () => {},
+    selection: {
+        start: 0,
+        end: 0,
+    },
     forwardedRef: () => {},
 };
 
@@ -46,8 +60,34 @@ class RoomNameInput extends Component {
         const roomName = event.nativeEvent.text;
         const modifiedRoomName = this.modifyRoomName(roomName);
         this.props.onChangeText(modifiedRoomName);
+
+        // If we made a modification to the room name, update the cursor position
+        // to avoid cursor jump behaviour
+        const roomNameWithHash = `${CONST.POLICY.ROOM_PREFIX}${roomName}`;
+        if (modifiedRoomName !== roomNameWithHash) {
+            const offset = roomNameWithHash.length - modifiedRoomName.length;
+            // customEvent must have the same signature as react-native TextInput onSelectionChange's argument
+            const customEvent = {
+                nativeEvent: {
+                    selection: {
+                        start: event.target.selectionStart - offset,
+                        end: event.target.selectionEnd - offset,
+                    },
+                },
+            };
+            this.setSelection(customEvent);
+        }
     }
 
+    /**
+     * Calls the onSelectionChange callback with the updated selection
+     * @param {Event} event
+     */
+    setSelection(event) {
+        this.props.onSelectionChange(event);
+    }
+
+
     /**
      * Modifies the room name to follow our conventions:
      * - Max length 80 characters
@@ -76,6 +116,8 @@ class RoomNameInput extends Component {
                 placeholder={this.props.translate('newRoomPage.social')}
                 onChange={this.setModifiedRoomName}
                 value={this.props.value.substring(1)} // Since the room name always starts with a prefix, we omit the first character to avoid displaying it twice.
+                selection={this.props.selection}
+                onSelectionChange={this.setSelection}
                 errorText={this.props.errorText}
                 autoCapitalize="none"
             />
diff --git a/src/pages/ReportSettingsPage.js b/src/pages/ReportSettingsPage.js
index 4eb29ef28..8fdf33c5f 100644
--- a/src/pages/ReportSettingsPage.js
+++ b/src/pages/ReportSettingsPage.js
@@ -71,6 +71,10 @@ class ReportSettingsPage extends Component {
 
         this.state = {
             newRoomName: this.props.report.reportName,
+            newRoomNameSelection: {
+                start: 0,
+                end: 0,
+            },
             errors: {},
         };
 
@@ -130,6 +134,16 @@ class ReportSettingsPage extends Component {
         }));
     }
 
+    /**
+     * @param {String} inputKey
+     * @param {Object} selection
+     */
+    setSelection(inputKey, selection) {
+        this.setState({
+            [`${inputKey}Selection`]: selection,
+        });
+    }
+
     render() {
         const shouldShowRoomName = !ReportUtils.isPolicyExpenseChat(this.props.report);
         const shouldDisableRename = ReportUtils.isDefaultRoom(this.props.report)
@@ -184,9 +198,11 @@ class ReportSettingsPage extends Component {
                                                 <RoomNameInput
                                                     ref={el => this.roomNameInputRef = el}
                                                     value={this.state.newRoomName}
+                                                    selection={this.state.newRoomNameSelection}
                                                     policyID={linkedWorkspace && linkedWorkspace.id}
                                                     errorText={this.state.errors.newRoomName}
                                                     onChangeText={newRoomName => this.clearErrorAndSetValue('newRoomName', newRoomName)}
+                                                    onSelectionChange={event => this.setSelection('newRoomName', event.nativeEvent.selection)}
                                                     disabled={shouldDisableRename}
                                                 />
                                             )}
diff --git a/src/pages/workspace/WorkspaceNewRoomPage.js b/src/pages/workspace/WorkspaceNewRoomPage.js
index 654e2ce8c..8bfc1fe75 100644
--- a/src/pages/workspace/WorkspaceNewRoomPage.js
+++ b/src/pages/workspace/WorkspaceNewRoomPage.js
@@ -49,6 +49,10 @@ class WorkspaceNewRoomPage extends React.Component {
 
         this.state = {
             roomName: '',
+            roomNameSelection: {
+                start: 0,
+                end: 0,
+            },
             policyID: '',
             visibility: CONST.REPORT.VISIBILITY.RESTRICTED,
             errors: {},
@@ -128,6 +132,16 @@ class WorkspaceNewRoomPage extends React.Component {
         }));
     }
 
+    /**
+     * @param {String} inputKey
+     * @param {Object} selection
+     */
+    setSelection(inputKey, selection) {
+        this.setState({
+            [`${inputKey}Selection`]: selection,
+        });
+    }
+
     focusRoomNameInput() {
         if (!this.roomNameInputRef) {
             return;
@@ -162,7 +176,9 @@ class WorkspaceNewRoomPage extends React.Component {
                             policyID={this.state.policyID}
                             errorText={this.state.errors.roomName}
                             onChangeText={roomName => this.clearErrorAndSetValue('roomName', roomName)}
+                            onSelectionChange={event => this.setSelection('roomName', event.nativeEvent.selection)}
                             value={this.state.roomName}
+                            selection={this.state.roomNameSelection}
                         />
                     </View>
                     <View style={styles.mb5}>

Details

Implemented selection and onSelectionChange on RoomNameInput

Kooha-2022-11-16-20-54-04.mp4

@thienlnam Sorry for the ping, can you consider reopening?

@thienlnam
Copy link
Contributor

@s77rt I closed it since this is intentional and we're freezing accessibility changes from #12741 (comment). What is the reason for your change?

@varshamb
Copy link
Contributor

@thienlnam the behavior of replacing space with _ is intentional. As cursor is moving to end after space, we should consider opening it.

@s77rt
Copy link
Contributor

s77rt commented Nov 17, 2022

@thienlnam
Replacing spaces with underscores is intentional.
Moving the cursor to the end is not <-- my proposal fixes this.

@thienlnam
Copy link
Contributor

Yeah that's a good point, @Santhosh-Sellavel could you please review the above proposal?

@thienlnam thienlnam reopened this Nov 17, 2022
@mountiny
Copy link
Contributor

Actually we might want to use dashes here https://expensify.slack.com/archives/C01GTK53T8Q/p1668113640697309

@varshamb
Copy link
Contributor

@thienlnam

Yeah, this is intentional - we could update it so that it keeps the cursor where the underscore was added. Though, similar to #11146 (comment) we're going close since it's related to keyboard navigation / accessibility

I don't think this is accessibility issue. This bug is open for Cursor position.

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented Nov 18, 2022

@Christinadobrzyn Can you assign this to another C+, I can't get to this sooner.

cc: @thienlnam

@Santhosh-Sellavel Santhosh-Sellavel removed their assignment Nov 18, 2022
@Christinadobrzyn Christinadobrzyn removed the External Added to denote the issue can be worked on by a contributor label Nov 18, 2022
@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 21, 2022
@melvin-bot
Copy link

melvin-bot bot commented Nov 21, 2022

📣 @s77rt You have been assigned to this job by @thienlnam!
Please apply to this job in Upwork and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@s77rt
Copy link
Contributor

s77rt commented Nov 21, 2022

@thienlnam @mollfpr
Should I apply the approved proposal? There is a possibility of improvement #12741 (comment)

PS: In order to be eligible for the bonus I will have to apply the approved proposal if there is no response about this.

@mollfpr
Copy link
Contributor

mollfpr commented Nov 21, 2022

IMO keep on the approved proposal with the platform-specific. What do you think @thienlnam?

@thienlnam
Copy link
Contributor

Yes please just apply the approved proposal here, and then you can address the other improvement in the other issue

@s77rt
Copy link
Contributor

s77rt commented Nov 21, 2022

Thanks for the quick response. Working on it

@s77rt
Copy link
Contributor

s77rt commented Nov 21, 2022

Applied in Upwork (+50% Bonus)
PR is ready.

@Christinadobrzyn
Copy link
Contributor

Christinadobrzyn commented Nov 22, 2022

Hired @varshamb as reporter, @s77rt as contributor and @mollfpr as C+
Upwork job here - https://www.upwork.com/jobs/~01b4bebba6c8508e8c

@s77rt I'm confused about the +50% bonus, can you confirm what that relates to?

@mollfpr
Copy link
Contributor

mollfpr commented Nov 22, 2022

I think @s77rt referring to CONTRIBUTING.md where there will be a bonus if the PR is merged within 3 days after the issue assigned. @Christinadobrzyn

@s77rt
Copy link
Contributor

s77rt commented Nov 22, 2022

@Christinadobrzyn as @mollfpr stated it's about the bonus if the PR is merged within 3 days. I submitted the PR on the same day of being assigned so it's more likely to be merged within that period.

@Christinadobrzyn
Copy link
Contributor

Christinadobrzyn commented Nov 23, 2022

Ah sounds good! Thank you for confirming @s77rt and @mollfpr! I'll hire for that amount so I don't forget about the 50% bonus but when we come to the payment, I'll change to pay $250 for the job and add the $125 as a bonus. Thanks!

@Christinadobrzyn
Copy link
Contributor

I think this can be moved to weekly while we review the PR? I'm going to move it but feel free to move it back to daily if that's best.

@Christinadobrzyn Christinadobrzyn added Weekly KSv2 and removed Daily KSv2 labels Nov 24, 2022
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Nov 25, 2022
@melvin-bot
Copy link

melvin-bot bot commented Nov 25, 2022

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.2.31-8 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2022-12-02. 🎊

After the hold period, please check if any of the following need payment for this issue, and if so check them off after paying:

  • External issue reporter YES @varshamb
  • Contributor that fixed the issue YES @s77rt
  • Contributor+ that helped on the issue and/or PR @mollfpr

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot melvin-bot bot changed the title [$250] Cursor moves to end after adding space in Room Name reported by @varshamb [HOLD for payment 2022-12-02] [$250] Cursor moves to end after adding space in Room Name reported by @varshamb Nov 25, 2022
@melvin-bot
Copy link

melvin-bot bot commented Nov 25, 2022

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Dec 2, 2022
@mollfpr
Copy link
Contributor

mollfpr commented Dec 3, 2022

Bump @Christinadobrzyn it’s payday time 🚀

@Christinadobrzyn
Copy link
Contributor

Christinadobrzyn commented Dec 5, 2022

Paid:

Job closed in Upwork, @mollfpr and @thienlnam can you please complete these steps and close out this GH?

@mollfpr
Copy link
Contributor

mollfpr commented Dec 5, 2022

I think the bonus also applies to the C+?

@Christinadobrzyn
Copy link
Contributor

Ah yep, you're right, I'll add that bonus for you now. Just added it.

@mollfpr
Copy link
Contributor

mollfpr commented Dec 5, 2022

[@mollfpr / @thienlnam] The PR that introduced the bug has been identified. Link to the PR:
[@mollfpr / @thienlnam] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
[@mollfpr / @thienlnam] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:

I feel this issue is not related to any PR but is something we need to take care of when working with the input component and ensure that all platforms are working consistently.

cc @Christinadobrzyn @thienlnam

@thienlnam
Copy link
Contributor

I've completed the rest of the checklist. This bug was technically added when we implemented User Created Policy Rooms #7028 so it was always there but now that a regression test has been added, that should be enough for this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

9 participants