Skip to content

[HOLD for payment 2023-08-02] [$1000] The cursor position is not at the end of the message when editing the welcome message #21523

Closed

Description

@kavimuru

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. Create a room
  2. Go to the room details > settings and select "Welcome Message"
  3. Enter a message and click on "Save"
  4. Once again, click on the welcome message for editing

Expected Result:

The cursor position should be at the end of the message when editing the welcome message

Actual Result:

The cursor is at the start of the message

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.32-5
Reproducible in staging?: y
Reproducible in production?: y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation

screen-recording-2023-06-20-at-24757-pm_rWeBf4YW.mp4
Recording.5122.mp4

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

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01c431cd4d3b60ebff
  • Upwork Job ID: 1674581546420617216
  • Last Price Increase: 2023-07-14

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 25, 2023
  2. melvin-bot commented on Jun 25, 2023

    @melvin-bot

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

  3. melvin-bot commented on Jun 25, 2023

    @melvin-bot

    Bug0 Triage Checklist (Main S/O)

    • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
    • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
      • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
    • This bug is reproducible using the reproduction steps in the OP. S/O
      • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
      • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
    • This issue is filled out as thoroughly and clearly as possible
      • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
    • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync
  4. chiragxarora commented on Jun 25, 2023

    @chiragxarora
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    The cursor position is not at the end of the message when editing the welcome message

    What is the root cause of that problem?

    Root cause of the issue is that we have not calculated the cursor position by selection property which by default is at zero. This leads to the rendering of cursor at the beginning when we focus it using the ref.

    <TextInput
    inputID="welcomeMessage"
    label={props.translate('welcomeMessagePage.welcomeMessage')}
    multiline
    numberOfLines={10}
    maxLength={CONST.MAX_COMMENT_LENGTH}
    ref={(el) => (welcomeMessageInputRef.current = el)}
    value={welcomeMessage}
    onChangeText={handleWelcomeMessageChange}
    autoCapitalize="none"
    textAlignVertical="top"
    />

    What changes do you think we should make in order to solve the problem?

    First of all we need a state in the component to keep the track of caret position which we can use to update the selection.
    We could create a selection state using react hooks like this:

    const [selection, setSelection] = useState({start: n, end: n});

    Now we need to set an initial positon of caret from where the cursor will start when open the welcome message dalogue.
    For this, we already have a state called welcomeMessage which is storing the previous welcome message received from props. So we can use that to set initial caret position.

    Now we have a state object which keeps the initial caret position, so now while editing the welcome message when user clicks anywhere inside the <TextInput/> to change the caret position, we can update our state by using onSelectionChange prop. This way we will always keep track of latest caret position.

    And now since we have added a util called focusAndUpdateMultiline, we can directly use that once the transition ends and ref is initialised

    `onEntryTransitionEnd={() => if(inputRef && inputRef.current) focusAndUpdateMultiline(inputRef.current);}

    UPDATE: (auto focus on reload)

    Focus mechanism and cursor aren't set on reload because the TextInput is not mounted till the time when we call our focus method.
    In order to solve this, we should go for a more logical approach rather than using timeouts.

    We should run a side-effect when our <TextInput/> has mounted and for this we can track the changes happening on our inputRef.current object.

    useEffect(() => {
        if(welcomeMessageInputRef.current) {
            // now focus
        }
    }, [welcomeMessageInputRef.current]);

    Final code changes

    function ReportWelcomeMessagePage(props) {
     ...................
      useEffect(() => {
        if(welcomeMessageInputRef.current) {
            focusAndUpdateMultilineInputRange(welcomeMessageInputRef.current);
        }
      }, [welcomeMessageInputRef.current]);
     ...................
      <TextInput
          inputID="welcomeMessage"
          label={props.translate('welcomeMessagePage.welcomeMessage')}
          multiline
          numberOfLines={10}
          maxLength={CONST.MAX_COMMENT_LENGTH}
          ref={(el) => (welcomeMessageInputRef.current = el)}
          value={welcomeMessage}
          onChangeText={handleWelcomeMessageChange}
          autoCapitalize="none"
          textAlignVertical="top"
      />

    NOTE: no other proposal proposed this solution till the time of final edit

    Updated Results
    bandicam.2023-07-03.22-12-29-395.mp4

    What alternative solutions did you explore? (Optional)

    We can achieve the similar results by using a callback hook too
    Or
    In the main solution, we can even omit the ref from dependent array after passing the welcomeMessageInputRef directly to the ref prop

  5. sakluger commented on Jun 27, 2023

    @sakluger
    Contributor

    @Expensify/design do you think this is a bug? I'm leaning towards yes, but wanted a second opinion.

  6. shawnborton commented on Jun 27, 2023

    @shawnborton
    Contributor

    Wow, what a find. Yeah, I guess it makes sense that the cursor starts off at the end as opposed to the beginning.

  7. self-assigned this
    on Jun 27, 2023
  8. sakluger commented on Jun 30, 2023

    @sakluger
    Contributor

    Alright let's do this thing. Adding the external label.

  9. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jun 30, 2023
  10. changed the title [-]The cursor position is not at the end of the message when editing the welcome message[/-] [+][$1000] The cursor position is not at the end of the message when editing the welcome message[/+] on Jun 30, 2023
  11. melvin-bot commented on Jun 30, 2023

    @melvin-bot
  12. 64 remaining items

  13. changed the title [-][$1000] The cursor position is not at the end of the message when editing the welcome message[/-] [+][HOLD for payment 2023-08-02] [$1000] The cursor position is not at the end of the message when editing the welcome message[/+] on Jul 26, 2023
  14. melvin-bot commented on Jul 26, 2023

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  15. melvin-bot commented on Jul 26, 2023

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.45-7 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 2023-08-02. 🎊

    After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

    • External issue reporter
    • Contributor that fixed the issue
    • Contributor+ that helped on the issue and/or PR

    For reference, here are some details about the assignees on this issue:

    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
  16. melvin-bot commented on Jul 26, 2023

    @melvin-bot

    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:

    • [@mollfpr] The PR that introduced the bug has been identified. Link to the PR:
    • [@mollfpr] 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] 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:
    • [@mollfpr] Determine if we should create a regression test for this bug.
    • [@mollfpr] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
    • [@sakluger] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  17. mollfpr commented on Aug 3, 2023

    @mollfpr
    Contributor

    [@mollfpr] The PR that introduced the bug has been identified. Link to the PR:

    #18662

    [@mollfpr] 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:

    https://github.com/Expensify/App/pull/18662/files#r1283428248

    [@mollfpr] 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:

    The regression test should be enough.

    [@mollfpr] Determine if we should create a regression test for this bug.
    [@mollfpr] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.

    On Web/mWeb

    1. Create a room
    2. Go to the room details > settings and select "Welcome Message"
    3. Enter a message and click on "Save"
    4. Once again, click on the welcome message for editing
    5. Verify that the cursor position should be at the end of the message when editing the welcome message
    6. Reload the page
    7. Verify that the cursor position should be at the end of the message when editing the welcome message

    On Desktop/Native apps

    1. Create a room
    2. Go to the room details > settings and select "Welcome Message"
    3. Enter a message and click on "Save"
    4. Once again, click on the welcome message for editing
    5. Verify that the cursor position should be at the end of the message when editing the welcome message
  18. sakluger commented on Aug 4, 2023

    @sakluger
    Contributor

    Summarizing payouts for this issue:

    Bug reporter: @ayazhussain79 $250 (hired on Upwork)
    Contributor: @hoangzinh $1000 (hired on Upwork)
    Contributor+: @mollfpr $1000 (hired on Upwork)

    Upwork job: https://www.upwork.com/jobs/~01c431cd4d3b60ebff

  19. sakluger commented on Aug 4, 2023

    @sakluger
    Contributor

    @ayazhussain79 I forgot to send you an offer previously, sorry about that! I just sent you a contract through Upwork, please let me know once you have accepted the offer.

  20. ayazhussain79 commented on Aug 4, 2023

    @ayazhussain79
    Contributor

    @sakluger offer accepted, Thank you

  21. sakluger commented on Aug 4, 2023

    @sakluger
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2EngineeringExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions