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 2024-01-11] [$1000] Draft message doesn't remain when It is empty #25488

Closed
1 of 6 tasks
kavimuru opened this issue Aug 18, 2023 · 86 comments
Closed
1 of 6 tasks
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 Help Wanted Apply this label when an issue is open to proposals by contributors

Comments

@kavimuru
Copy link

kavimuru commented Aug 18, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. Go to any chat
  2. Send new message
  3. Edit this message
  4. Replace the message by empty string (don't click save)
  5. Click another report
  6. Back to previous report

Expected Result:

Draft message should be remained
Note that: When replacing draft message by another string, It will be remained

Actual Result:

Draft message doesn't remain

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.55-0
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

Recording.5919.mp4
Screen.Recording.2023-08-09.at.10.15.13.1.mov

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

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01adda4a6239a4a1af
  • Upwork Job ID: 1693680071403327488
  • Last Price Increase: 2023-09-11
@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 18, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 18, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Aug 18, 2023

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

@samh-nl
Copy link
Contributor

samh-nl commented Aug 18, 2023

Proposal

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

Draft message doesn't remain when It is empty

What is the root cause of that problem?

When the draft is made empty, we reset it to the original message:

// This component is rendered only when draft is set to a non-empty string. In order to prevent component
// unmount when user deletes content of textarea, we set previous message instead of empty string.
if (newDraft.trim().length > 0) {
// We want to escape the draft message to differentiate the HTML from the report action and the HTML the user drafted.
debouncedSaveDraft(_.escape(newDraft));
} else {
debouncedSaveDraft(props.action.message[0].html);
}

This is because if the value is empty, we assume editing is not occurring and we unmount ReportActionItemMessageEdit:

{!props.draftMessage ? (
<View style={props.displayAsGroup && hasBeenFlagged ? styles.blockquote : {}}>
<ReportActionItemMessage

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

We should use a value of undefined to check that editing is not occurring.

To achieve this, we should change:

1. Update deleteDraft to remove the Onyx record instead of making it an empty string:

const deleteDraft = useCallback(() => {
InputFocus.callback(() => setIsFocused(false));
InputFocus.inputFocusChange(false);
debouncedSaveDraft.cancel();
Report.saveReportActionDraft(props.reportID, props.action, '');

2. Use _.isUndefined here:

{!props.draftMessage ? (

3. Always save the newDraft value, instead of using a fallback to the original message if the length is 0:

if (newDraft.trim().length > 0) {
// We want to escape the draft message to differentiate the HTML from the report action and the HTML the user drafted.
debouncedSaveDraft(_.escape(newDraft));
} else {
debouncedSaveDraft(props.action.message[0].html);
}

4. Update saveReportActionDraft here:
We will store it as an object, so that we can migrate and remove existing empty values by checking if it's a string.

- Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}`, {[reportAction.reportActionID]: draftMessage});
+ Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}`, {[reportAction.reportActionID]: { message: draftMessage }});

5. Don't use empty string as default value and update key here:
In memo we check prevProps.draftMessage === nextProps.draftMessage so we need to be able to capture if a draft is deleted ('' -> undefined) or created (undefined -> '').

-            return lodashGet(drafts, [draftKey, props.action.reportActionID], '');
+            return lodashGet(drafts, [draftKey, props.action.reportActionID, 'message']);

6. Migration to remove existing empty drafts

See migration code

import Onyx from 'react-native-onyx';
import _ from 'underscore';
import Log from '@libs/Log';
import ONYXKEYS from '@src/ONYXKEYS';

/**
 * This migration removes empty drafts from reportActionsDrafts.
 *
 * @returns {Promise}
 */
export default function () {
    return new Promise((resolve) => {
        const connectionID = Onyx.connect({
            key: ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS,
            waitForCollectionCallback: true,
            callback: (allReportActionsDrafts) => {
                Onyx.disconnect(connectionID);

                if (!allReportActionsDrafts) {
                    Log.info('[Migrate Onyx] Skipped migration RemoveEmptyReportActionsDrafts because there were no reportActionsDrafts');
                    return resolve();
                }

                const newReportActionsDrafts = {};
                _.each(allReportActionsDrafts, (reportActionDrafts, onyxKey) => {
                    newReportActionsDrafts[onyxKey] = {};

                    // Whether there is at least one draft in this report that has to be migrated
                    let hasUnmigratedDraft = false;

                    _.each(reportActionDrafts, (reportActionDraft, reportActionID) => {
                        // If the draft is a string, it means it hasn't been migrated yet
                        if (_.isString(reportActionDraft)) {
                            hasUnmigratedDraft = true;
                            Log.info(`[Migrate Onyx] Migrating draft for report action ${reportActionID}`);

                            if (_.isEmpty(reportActionDraft)) {
                                Log.info(`[Migrate Onyx] Removing draft for report action ${reportActionID}`);
                                return;
                            }

                            newReportActionsDrafts[onyxKey][reportActionID] = {message: reportActionDraft};
                        } else {
                            // We've already migrated this draft, so keep the existing value
                            newReportActionsDrafts[onyxKey][reportActionID] = reportActionDraft;
                        }
                    });

                    if (_.isEmpty(newReportActionsDrafts[onyxKey])) {
                        // Clear if there are no drafts remaining
                        newReportActionsDrafts[onyxKey] = null;
                    } else if (!hasUnmigratedDraft) {
                        // All drafts for this report have already been migrated, there's no need to overwrite this onyx key with the same data
                        delete newReportActionsDrafts[onyxKey];
                    }
                });

                if (_.isEmpty(newReportActionsDrafts)) {
                    Log.info('[Migrate Onyx] Skipped migration RemoveEmptyReportActionsDrafts because there are no actions drafts to migrate');
                    return resolve();
                }

                Log.info(`[Migrate Onyx] Ran migration RemoveEmptyReportActionsDrafts and updated drafts for ${_.keys(newReportActionsDrafts).length} reports`);
                // eslint-disable-next-line rulesdir/prefer-actions-set-data
                return Onyx.multiSet(newReportActionsDrafts).then(resolve);
            },
        });
    });
}

What alternative solutions did you explore? (Optional)

N/A

@flaviadefaria flaviadefaria removed their assignment Aug 18, 2023
@flaviadefaria flaviadefaria added Bug Something is broken. Auto assigns a BugZero manager. and removed Bug Something is broken. Auto assigns a BugZero manager. labels Aug 18, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 18, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Aug 18, 2023

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

@flaviadefaria flaviadefaria self-assigned this Aug 18, 2023
@flaviadefaria
Copy link
Contributor

@greg-schroeder I'm logging off now and will be OoO for the next week so reassigning this to you in the meantime. Thanks!

@greg-schroeder
Copy link
Contributor

Ok, sure!

@greg-schroeder
Copy link
Contributor

greg-schroeder commented Aug 19, 2023

Hmmmmm. I don't know about this. Why would a user replace a message with an empty string, not save it, and then switch between reports? That doesn't seem like a use case that would be commonly encountered to me. I don't know that we should optimize for that.

@greg-schroeder
Copy link
Contributor

Started a discussion

@melvin-bot melvin-bot bot added the Overdue label Aug 21, 2023
@greg-schroeder greg-schroeder added the External Added to denote the issue can be worked on by a contributor label Aug 21, 2023
@melvin-bot melvin-bot bot changed the title Draft message doesn't remain when It is empty [$1000] Draft message doesn't remain when It is empty Aug 21, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 21, 2023

Job added to Upwork: https://www.upwork.com/jobs/~01adda4a6239a4a1af

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 21, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 21, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Aug 21, 2023

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

@greg-schroeder
Copy link
Contributor

Team agreed it's worth moving over to External

@greg-schroeder
Copy link
Contributor

This is on staging, awaiting deploy to prod

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Jan 4, 2024
@melvin-bot melvin-bot bot changed the title [$1000] Draft message doesn't remain when It is empty [HOLD for payment 2024-01-11] [$1000] Draft message doesn't remain when It is empty Jan 4, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Jan 4, 2024
Copy link

melvin-bot bot commented Jan 4, 2024

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

Copy link

melvin-bot bot commented Jan 4, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.21-4 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 2024-01-11. 🎊

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:

  • @mollfpr requires payment (Needs manual offer from BZ)
  • @samh-nl requires payment (Needs manual offer from BZ)
  • @dukenv0307 requires payment (Needs manual offer from BZ)

Copy link

melvin-bot bot commented Jan 4, 2024

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.
  • [@greg-schroeder] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Jan 11, 2024
Copy link

melvin-bot bot commented Jan 11, 2024

Issue is ready for payment but no BZ is assigned. @sonialiap you are the lucky winner! Please verify the payment summary looks correct and complete the checklist. Thanks!

Copy link

melvin-bot bot commented Jan 11, 2024

Payment Summary

Upwork Job

  • ROLE: @mollfpr paid $(AMOUNT) via Upwork (LINK)
  • ROLE: @samh-nl paid $(AMOUNT) via Upwork (LINK)

BugZero Checklist (@sonialiap)

  • I have verified the correct assignees and roles are listed above and updated the neccesary manual offers
  • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/1693680071403327488/hired)
  • I have paid out the Upwork contracts or cancelled the ones that are incorrect
  • I have verified the payment summary above is correct

@greg-schroeder
Copy link
Contributor

You can ignore this @sonialiap, it's a bug, I will handle payment

@mollfpr
Copy link
Contributor

mollfpr commented Jan 12, 2024

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

No offending PR.

[@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 good.

[@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.

  1. Open any report
  2. Send a message
  3. Press the Edit button in the newly added message
  4. Empty the draft message input
  5. Navigate to a different report
  6. Return to the first report
  7. Verify that the draft message input is empty
  8. 👍 or 👎

@greg-schroeder No need to send me the offer; I'll make a manual request in NewDot. Thank you!

@greg-schroeder
Copy link
Contributor

reporter: $50
c: $500
c+: $500

Offers sent to @dukenv0307 and @samh-nl, and you can do a manual request @mollfpr.

@greg-schroeder
Copy link
Contributor

filing regression test

@JmillsExpensify
Copy link

$500 payment approved for @mollfpr (c+) based on summary above.

@samh-nl
Copy link
Contributor

samh-nl commented Jan 14, 2024

Thanks all! I'd just like to check on the accuracy of the bounty, as this issue stems from Aug last year.

@dukenv0307
Copy link
Contributor

reporter: $50

@greg-schroeder based on this announcement, the $250 reporting bonus still applies for issues opened before Aug 30, 2023. This issue was created on Aug 18, 2023, so I think it qualifies there.

Could you send me another offer for $250, thanks!

@samh-nl
Copy link
Contributor

samh-nl commented Jan 29, 2024

Bump

@greg-schroeder
Copy link
Contributor

Sorry all, let me review this one

@greg-schroeder
Copy link
Contributor

Hmm. This is tricky. The issue was reported/created in August before our first pricing changes, but no PR was created until late 2023, well after our payscale changed. I think we could probably honor the original reporting bonus given the date, but the work done on the PR took place well after the $500 baseline was established. That seems most fair to me.

@samh-nl
Copy link
Contributor

samh-nl commented Jan 30, 2024

True, even though the initial proposal was made under a different premise.
But I can follow your reasoning as well. I've accepted the offer on Upwork.

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 Help Wanted Apply this label when an issue is open to proposals by contributors
Projects
None yet
Development

No branches or pull requests