App icon indicating copy to clipboard operation
App copied to clipboard

[HOLD for payment 2022-07-15] [$250] When sending text that NewDot thinks is a link, it adds the link markdown automatically and doesn't allow to edit

Open mvtglobally opened this issue 4 years ago • 55 comments

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. Open any chat
  2. send safe.directory/link message
  3. Edit the message to remove the link

Expected Result:

User would expect it to save the text as-is and be able to remove the link

Actual Result:

App won't let user to remove the link. If I remove the [] and (http://safe.directory/) from the message and hit Save, it adds them back.

Workaround:

unknown

Platform:

Where is this issue occurring?

  • Web
  • iOS
  • Android
  • Desktop App
  • Mobile Web

Version Number: 1.1.63-0 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: Any additional supporting documentation

https://user-images.githubusercontent.com/43995119/169213256-805d3d4e-c468-46c9-a0ca-4daddc5b9261.mp4

Screen Shot 2022-05-17 at 10 26 22 AM (1)

Expensify/Expensify Issue URL: Issue reported by: @rafecolton Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1652808490521729

View all open jobs on GitHub

mvtglobally avatar May 19 '22 05:05 mvtglobally

Triggered auto assignment to @luacmartins (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

melvin-bot[bot] avatar May 19 '22 05:05 melvin-bot[bot]

I think this can be external

luacmartins avatar May 19 '22 15:05 luacmartins

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

melvin-bot[bot] avatar May 19 '22 15:05 melvin-bot[bot]

Posted to Upwork!

https://www.upwork.com/ab/applicants/1527523209823019008/job-details https://www.upwork.com/jobs/~012f7992db0fb8f099

kadiealexander avatar May 20 '22 05:05 kadiealexander

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

melvin-bot[bot] avatar May 20 '22 05:05 melvin-bot[bot]

Current assignee @luacmartins is eligible for the Exported assigner, not assigning anyone new.

melvin-bot[bot] avatar May 20 '22 05:05 melvin-bot[bot]

https://user-images.githubusercontent.com/4989101/169474379-25c795a4-cb36-4dac-a11d-e43261cd9b3a.mov

Hi, I would like to work on this issue! The text won't be converted to link automatically!

We can skip the parsing

const parser = new ExpensiMark();

if its in editMode! Is this the expected behaviour?

NehaSantani avatar May 20 '22 07:05 NehaSantani

@NehaSantani Thanks for the proposal. However, I think that skipping the parser would affect other styles as well (code blocks, quotes, etc) and we wouldn't want that. Let me know if that doesn't answer your question and I can try to clarify any remaining concerns.

luacmartins avatar May 20 '22 13:05 luacmartins

@luacmartins Hi, I want a bit clarification on this issue!

  • 1.) Do you want to remove the hyperlink styling on text after edit? Or
  • 2.) you want to avoid mdText that is being displayed in input while edit is clicked.

If its a yes for 2 : Then My Proposed solution to this problem is use parser.htmlToText instead of parser.htmlToMarkdown ! Is there any specific reason we are using below line in ReportActionItemMessageEdit.js file at line no - 77

        const draftMessage = parser.htmlToMarkdown(this.props.draftMessage);

Instead we can use

        const draftMessage = parser.htmlToText(this.props.draftMessage);

And if its a yes for 1 : I will propose another solution for it soon!

Have attached the output for 2!

https://user-images.githubusercontent.com/4989101/169580760-31b66f41-1f17-4e5a-b5dc-1e4facbdbeca.mov

NehaSantani avatar May 20 '22 17:05 NehaSantani

Hey @NehaSantani! Thanks for the questions.

I think the intention is 1. We want to be able to:

  1. Edit the comment
  2. Remove the link md
  3. When we save the edited comment, the link should be display as text (since we removed the link md).

What we have right now is that after editing, the link md is added back and the link is shown as a link instead of text.

luacmartins avatar May 20 '22 17:05 luacmartins

Proposal

We should change the following: https://github.com/Expensify/App/blob/56213d07d5e10b5ecf1cb2fae2d82aff9360bb5a/src/libs/actions/Report.js#L1391-L1393 to

function editReportComment(reportID, originalReportAction, textForNewComment) {
    const parser = new ExpensiMark();
    const htmlForNewComment = parser.replace(textForNewComment, ["autoLink"]);

This will not run the link rule of the parser. We'll also need to change the expensify-common library so that the parser.replace function accepts a second argument with an array of rules to skip.

Following changes: https://github.com/Expensify/expensify-common/blob/237fb782678fec9542d0a2608ea18ef2302995fd/lib/ExpensiMark.js#L297-L301 to

    replace(text, skippedRules = []) {
        // This ensures that any html the user puts into the comment field shows as raw html
        let replacedText = Str.safeEscape(text);


        this.rules.filter((rule) => !skippedRules.includes(rule.name)).forEach((rule) => {

allroundexperts avatar May 20 '22 18:05 allroundexperts

@allroundexperts the library can be found here and I believe you have access to it. Let me know if that's not the case.

luacmartins avatar May 20 '22 19:05 luacmartins

@luacmartins I can access it. I'll update my proposal.

allroundexperts avatar May 20 '22 19:05 allroundexperts

@luacmartins Updated.

allroundexperts avatar May 20 '22 19:05 allroundexperts

Cause

We cant detect url changes.

Solution

If the original text is changed but the output is not affected, we can ignore the link conversion. It is active only if the link has been updated and is the same as the old one. When we add this code to line 1394, we can achieve this. let htmlForNewComment of course.

https://github.com/Expensify/App/blob/56213d07d5e10b5ecf1cb2fae2d82aff9360bb5a/src/libs/actions/Report.js#L1391-L1394

if (htmlForNewComment === originalReportAction.message[0].html && textForNewComment === originalReportAction.message[0].text) {
        //alert('link not present anymore and same text show up');
        parser.rules = parser.rules.map(rule => rule.name !== 'link');
        htmlForNewComment = parser.replace(textForNewComment);
    }

https://user-images.githubusercontent.com/6093207/169603919-37c80004-0297-4719-b1de-44ae5486c6bf.mp4

note : I just realized that he mentioned this approach actually @allroundexperts . It would be nicer if it was detected and done in this way, in my humble opinion.

You can think of it as if I didn't do proposal @luacmartins 😅 . I wrote it so that maybe I can contribute to the solution 👼 .

metehanozyurt avatar May 20 '22 20:05 metehanozyurt

@NehaSantani Thanks for the proposal. However, I think that skipping the parser would affect other styles as well (code blocks, quotes, etc) and we wouldn't want that. Let me know if that doesn't answer your question and I can try to clarify any remaining concerns.

@luacmartins As directed by you, have skipped only "autolink" style while editing and not affecting other styles! However to achieve this, we need to update

  • ExpensiMark.js library file with following code

//Previously called method
   replace(text) {return this.replaceSkipRules(text,[]);}
  
  // Updated method
   replaceSkipRules(text,skipRules) {
        // This ensures that any html the user puts into the comment field shows as raw html
        let replacedText = Str.safeEscape(text);

        this.rules.forEach((rule) => {

            if(skipRules.length && skipRules.includes(rule.name))
            return true;
            
            // Pre-process text before applying regex
            if (rule.pre) {
                replacedText = rule.pre(replacedText);
  • Call above method from Report.js as follows

function editReportComment(reportID, originalReportAction, textForNewComment) {
  const parser = new ExpensiMark();
  const htmlForNewComment = parser.replaceSkipRules(textForNewComment,["autolink"]);

Proposed Output :

https://user-images.githubusercontent.com/4989101/169616521-0712ca76-5b1f-4262-9c18-6f7550498322.mov

NehaSantani avatar May 20 '22 21:05 NehaSantani

I'll try to evaluate the proposals today!

luacmartins avatar May 23 '22 14:05 luacmartins

@luacmartins I going OOO on next week, so I am happy to defer this to another C+. Can you reapply exported, I am un-assigning myself here.

Santhosh-Sellavel avatar May 23 '22 20:05 Santhosh-Sellavel

Current status: Proposals yet to be reviewed!

Santhosh-Sellavel avatar May 23 '22 20:05 Santhosh-Sellavel

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

melvin-bot[bot] avatar May 23 '22 22:05 melvin-bot[bot]