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-18] [$500] Add markdown syntax for creating a new task #32864

Closed
thienlnam opened this issue Dec 11, 2023 · 31 comments
Closed
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Daily KSv2 External Added to denote the issue can be worked on by a contributor NewFeature Something to build that is a new item.

Comments

@thienlnam
Copy link
Contributor

thienlnam commented Dec 11, 2023

We want to create some syntax that will create a task when the following message is added to the composer

[] @jack This is the task name

Should create a task in the current room that:

  • Is assigned to jack
  • Has the title 'This is the task name'
  • The share destination would be the current report where this comment is posted

The assignee can be optional, in which case the command would look something like this

[] This is the task name

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~013d0a874d62f021b7
  • Upwork Job ID: 1734321392740421632
  • Last Price Increase: 2023-12-18
  • Automatic offers:
    • Ollyws | Reviewer | 28066406
    • suneox | Contributor | 28066407
Issue OwnerCurrent Issue Owner: @anmurali
@thienlnam thienlnam added External Added to denote the issue can be worked on by a contributor NewFeature Something to build that is a new item. labels Dec 11, 2023
@melvin-bot melvin-bot bot changed the title Add markdown syntax for creating a new task [$500] Add markdown syntax for creating a new task Dec 11, 2023
Copy link

melvin-bot bot commented Dec 11, 2023

Job added to Upwork: https://www.upwork.com/jobs/~013d0a874d62f021b7

Copy link

melvin-bot bot commented Dec 11, 2023

@melvin-bot melvin-bot bot added Weekly KSv2 Help Wanted Apply this label when an issue is open to proposals by contributors labels Dec 11, 2023
Copy link

melvin-bot bot commented Dec 11, 2023

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

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Dec 11, 2023
@suneox
Copy link
Contributor

suneox commented Dec 12, 2023

Proposal

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

Add markdown syntax for creating a new task

What is the root cause of that problem?

New feature

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

At function onSubmitComment on ReportScreen we will check if content match with task regex we will create a new task otherwise keep current behavior

    const allPersonalDetails = usePersonalDetails();
    const onSubmitComment = useCallback(
        (text) => {
            const taskRegex = /^\[\](?:\s+@([^\s@]+@[\w.-]+))?\s+(.+)/;
            const match = text.match(taskRegex);
            if (match) {
                const email = match[1] ? match[1].trim() : undefined; // Email might be undefined if not captured
                const title = match[2];
                let assignee = {};
                if (email) {
                    assignee = _.find(_.values(allPersonalDetails), (p) => p.login === email) || {};
                }
                Task.createTaskAndNavigate(getReportID(route), title, '', assignee.login, assignee.accountID, assignee.assigneeChatReport, report.policyID);
            } else {
                Report.addComment(getReportID(route), text);
            }



            // We need to scroll to the bottom of the list after the comment is added
            const refID = setTimeout(() => {
                flatListRef.current.scrollToOffset({animated: false, offset: 0});
            }, 10);

            return () => clearTimeout(refID);
        },
        [route],
    );

POC

32864_POC.mp4

What alternative solutions did you explore? (Optional)

@AmjedNazzal
Copy link
Contributor

Proposal

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

Add markdown syntax for creating a new task

What is the root cause of that problem?

This is a new feature

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

To start, we would modify ReportActionCompose submitForm function to the following:

const submitForm = useCallback(
        (e) => {
            if (e) {
                e.preventDefault();
            }

            const newComment = composerRef.current.prepareCommentAndResetComposer();
            if (!newComment) {
                return;
            }

            const Taskregex = /^\[\]\s*(.+)/;
            const match = newComment.match(Taskregex);
           
            if (match && match[1]) {
                const TaskDetails = match[1];
                return onTriggerTaskCreation(TaskDetails);
            }

            onSubmit(newComment);
        },
        [onSubmit],
    );

What we are doing is we first use a regex that will look for [] at the start of the newComment text and if there is, it will be saved in match variable.
After that we check if that match in index[1] is not empty, and if it's not we assign it's value to TaskDetails constant and pass it to a new function onTriggerTaskCreation which will contain the following logic:

const onTriggerTaskCreation = useCallback((taskDetails) => {
    const assigneeRegex = /@([\S]+)/; 
    const assigneeMatch = taskDetails.match(assigneeRegex);
    const assignee = assigneeMatch ? assigneeMatch[1] : '';
    let assigneeAccountID = 0;
    let assigneeChatReport = null;
    if (assignee) {
        const assigneeDetails = Object.values(personalDetails).find(entry => entry.login === assignee) || {};
        assigneeAccountID = assigneeDetails.accountID ?? 0;
        assigneeChatReport = assigneeDetails.assigneeChatReport ?? Task.setAssigneeValue(assignee, assigneeAccountID);
    }
    const title = assignee
        ? taskDetails.replace(`@${assignee}`, '').trim() || "Untitled Task"
        : taskDetails.trim();

    Task.createTaskAndNavigate(
        reportID,
        title,
        '',
        assignee,
        assigneeAccountID,
        assigneeChatReport,
        report.policyID,
    );
}, []);

The logic of the function works as follows:

const onTriggerTaskCreation = useCallback((taskDetails) => {
    const assigneeRegex = /@([\S]+)/; 
    const assigneeMatch = taskDetails.match(assigneeRegex);
    const assignee = assigneeMatch ? assigneeMatch[1] : '';
    let assigneeAccountID = 0;
    let assigneeChatReport = null;
    if (assignee) {
        const assigneeDetails = Object.values(personalDetails).find(entry => entry.login === assignee) || {};
        assigneeAccountID = assigneeDetails.accountID ?? 0;
        assigneeChatReport = assigneeDetails.assigneeChatReport ?? Task.setAssigneeValue(assignee, assigneeAccountID);
    }
}, []);

In this part we are grabbing the first @ item and assign it to assignee, otherwise it will be empty since it's not required
If there is an assignee we need to access and retrieve it's assigneeAccountID and assigneeChatReport but if there is an assigneeAccountID but no assigneeChatReport then we need to create an optimistic report for it using Task.setAssigneeValue

    const title = assignee
        ? taskDetails.replace(`@${assignee}`, '').trim() || "Untitled Task"
        : taskDetails.trim();

    Task.createTaskAndNavigate(
        reportID,
        title,
        '',
        assignee,
        assigneeAccountID,
        assigneeChatReport,
        report.policyID,
    );
}, []);

In this section we are assigning a title, the logic is that if there is an assignee, we will filter it out and assign the rest of the text as a title
If there is no assignee, we will just assign the whole text to the title
If there is an assignee but no text after it, we will take the assignee and then give the title "Untitled Task" as a placeholder

After that's taken care of we can call Task.createTaskAndNavigate and create the task.

@Ollyws
Copy link
Contributor

Ollyws commented Dec 14, 2023

Can I clarify: Should the task be created when the text is typed into the composer, or when the message is submitted?

@melvin-bot melvin-bot bot removed the Overdue label Dec 14, 2023
@suneox
Copy link
Contributor

suneox commented Dec 14, 2023

I think we should handle create task at ReportScreen after composer submit a message to separate logic due to the business logic shouldn't handle inside composer

@AmjedNazzal
Copy link
Contributor

@Ollyws I think it should be on submit because otherwise the task could be created before the user is ready to create it

@thienlnam
Copy link
Contributor Author

@Ollyws

It should only be created once the message is submitted

@Ollyws
Copy link
Contributor

Ollyws commented Dec 17, 2023

Thanks for clarifying.
@suneox's proposal LGTM.
🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented Dec 17, 2023

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

Copy link

melvin-bot bot commented Dec 18, 2023

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@Ollyws
Copy link
Contributor

Ollyws commented Jan 4, 2024

Yeah, apologies for the delay will review this one now.

@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 11, 2024
@melvin-bot melvin-bot bot changed the title [$500] Add markdown syntax for creating a new task [HOLD for payment 2024-01-18] [$500] Add markdown syntax for creating a new task Jan 11, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Jan 11, 2024
Copy link

melvin-bot bot commented Jan 11, 2024

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

Copy link

melvin-bot bot commented Jan 11, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.24-3 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-18. 🎊

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

Copy link

melvin-bot bot commented Jan 11, 2024

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

  • [@Ollyws] Please propose regression test steps to ensure the new feature will work correctly on production in further releases.
  • 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 17, 2024
Copy link

melvin-bot bot commented Jan 18, 2024

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

@melvin-bot melvin-bot bot added the Overdue label Jan 22, 2024
@Ollyws
Copy link
Contributor

Ollyws commented Jan 22, 2024

Regression Test Proposal

1. Open any chat
2. Send a message in the format `[] @exampleemail@address.com exampletitle` replacing the email with a user email.
3. Verify a task is created and assigned to the entered user, with the entered task title.

Do we agree 👍 or 👎

@iwiznia
Copy link
Contributor

iwiznia commented Jan 22, 2024

Looks good to me

@anmurali
Copy link

@Ollyws - the previously issued offer expired. So I had to reissue an offer to pay you. It is here
@suneox is paid

@melvin-bot melvin-bot bot added Overdue and removed Overdue labels Jan 22, 2024
@iwiznia
Copy link
Contributor

iwiznia commented Jan 29, 2024

@anmurali can we close this then?

@Ollyws
Copy link
Contributor

Ollyws commented Jan 29, 2024

Still awaiting payment on this one.

@iwiznia iwiznia removed the Overdue label Jan 29, 2024
@melvin-bot melvin-bot bot added the Overdue label Jan 29, 2024
@iwiznia
Copy link
Contributor

iwiznia commented Jan 29, 2024

@anmurali can you pay then?

@anmurali
Copy link

Paid @Ollyws now.

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 Daily KSv2 External Added to denote the issue can be worked on by a contributor NewFeature Something to build that is a new item.
Projects
No open projects
Status: CRITICAL
Development

No branches or pull requests

7 participants