Skip to content

[$250] [HOLD for payment 2024-06-13] Handle showing selfDM as the first item in the list when users search for their own email or display name #42627

Description

@techievivek

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


Problem:

We recently merged a backend PR that returns selfDM reports in search results when users search for their email or display name. However, the backend response does not guarantee that the selfDM report will appear as the first result. This can make it difficult for users to quickly locate their selfDM in the search results even when they are returned by the backend.

Solution:

Update the frontend logic to ensure that the selfDM report appears first in the search results in UI when users specifically search for their own email or display name. Implement post-processing logic to reorder the search results, ensuring the selfDM report is at the top of the list. This will make it easier for users to find their selfDM when searching for their own email or display name.

Issue OwnerCurrent Issue Owner: @
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01401c18bd7e84e155
  • Upwork Job ID: 1801202714715048228
  • Last Price Increase: 2024-06-13

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    FirstPickEngineering only, please! Only add when there is an identified code solution.
    BugSomething is broken. Auto assigns a BugZero manager.
    on May 27, 2024
  2. self-assigned this
    on May 27, 2024
  3. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on May 27, 2024
  4. melvin-bot commented on May 27, 2024

    @melvin-bot

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

  5. melvin-bot commented on May 27, 2024

    @melvin-bot

    Triggered auto assignment to @jliexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  6. dragnoir commented on May 27, 2024

    @dragnoir
    Contributor

    Proposal

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

    Handle showing selfDM as the first item in the list when users search for their own email or display name

    What is the root cause of that problem?

    New feature

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

    On ChatFinderPage we have the filteredOptions that turns the new list when we search.

    const newOptions = OptionsListUtils.filterOptions(searchOptions, debouncedSearchValue, betas);

    To implement the feature where items with isSelfDM: true in newOptions.recentReports are moved to the top of the list, you can use JavaScript's sort method within your useMemo hook. Here's how we can modify the function to achieve this:

    const filteredOptions = useMemo(() => {
        if (debouncedSearchValue.trim() === '') {
            return {
                recentReports: [],
                personalDetails: [],
                userToInvite: null,
                headerMessage: '',
            };
        }
    
        const newOptions = OptionsListUtils.filterOptions(searchOptions, debouncedSearchValue, betas);
        console.log('newOptions: ', newOptions);
    
        // Sort recentReports to move items with isSelfDM: true to the top
        const sortedRecentReports = newOptions.recentReports.sort((a, b) => {
            if (a.isSelfDM && !b.isSelfDM) return -1;
            if (!a.isSelfDM && b.isSelfDM) return 1;
            return 0;
        });
    
        const header = OptionsListUtils.getHeaderMessage(sortedRecentReports.length + Number(!!newOptions.userToInvite) > 0, false, debouncedSearchValue);
        return {
            recentReports: sortedRecentReports,
            personalDetails: newOptions.personalDetails,
            userToInvite: newOptions.userToInvite,
            headerMessage: header,
        };
    }, [debouncedSearchValue, searchOptions, betas]);

    Explanation:

    1. Check if debouncedSearchValue is empty: If it is, return the initial empty state.
    2. Filter Options: Use OptionsListUtils.filterOptions to get the newOptions.
    3. Sort recentReports: Use the sort method to reorder newOptions.recentReports, moving items with isSelfDM: true to the top.
    4. Return Sorted Options: Return the sorted recentReports along with other newOptions properties.

    This ensures that any item with the attribute isSelfDM: true appears at the top of the recentReports array in the returned object.

    POC video:

    my name: Rachid L and my email is mosaixel.org@gmail.com

    20240527_095213.mp4

    We can also integrate this feature inside OptionsListUtils.filterOptions

  7. nkdengineer commented on May 27, 2024

    @nkdengineer
    Contributor

    Proposal

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

    What is the root cause of that problem?

    In here, we're ordering the report by lastVisibleActionCreated and archived report will be remain at the bottom

    const orderedReportOptions = lodashSortBy(filteredReportOptions, (option) => {
    const report = option.item;
    if (option.isArchivedRoom) {
    return CONST.DATE.UNIX_EPOCH;
    }
    return report?.lastVisibleActionCreated;

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

    We should order the selfDM at the top of the report list by return new Date().toString() if the report is selfDM. So this report will be always at the top of the list

    const orderedReportOptions = lodashSortBy(filteredReportOptions, (option) => {
        const report = option.item;
        if (option.isArchivedRoom) {
            return CONST.DATE.UNIX_EPOCH;
        }
        if (option.isSelfDM) {
            return new Date().toString();
        }
    
        return report?.lastVisibleActionCreated;
    });
    

    const orderedReportOptions = lodashSortBy(filteredReportOptions, (option) => {
    const report = option.item;
    if (option.isArchivedRoom) {
    return CONST.DATE.UNIX_EPOCH;
    }
    return report?.lastVisibleActionCreated;

    What alternative solutions did you explore? (Optional)

    NA

  8. bernhardoj commented on May 27, 2024

    @bernhardoj
    Contributor

    Proposal

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

    We want to show self DM as the first result when the user searches for their own login/display name.

    What is the root cause of that problem?

    A feature request.

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

    We currently able to search from 2 pages, ChatFinderPage and NewChatPage. They have different logic to sort.

    For ChatFinderPage, we use this logic to sort the results.

    function orderOptions(options: ReportUtils.OptionData[], searchValue: string | undefined) {
    return lodashOrderBy(
    options,
    [
    (option) => {
    if (!!option.isChatRoom || option.isArchivedRoom) {
    return 3;
    }
    if (!option.login) {
    return 2;
    }
    if (option.login.toLowerCase() !== searchValue?.toLowerCase()) {
    return 1;
    }
    // When option.login is an exact match with the search value, returning 0 puts it at the top of the option list
    return 0;
    },
    ],
    ['asc'],
    );

    It's executed only when we type something in the search field. To put the self-DM at the top of the list, we can return 0 if the option is self DM.

    if (option.isSelfDM) {
        return 0;
    }
    

    For NewChatPage, the result is sorted here.

    const orderedReportOptions = lodashSortBy(filteredReportOptions, (option) => {
    const report = option.item;
    if (option.isArchivedRoom) {
    return CONST.DATE.UNIX_EPOCH;
    }
    return report?.lastVisibleActionCreated;
    });

    To put the self-DM at the top of the list and only when we search for our self, we can add this code:

    if (searchValue) {
        return [option.isSelfDM, report?.lastVisibleActionCreated];
    }
    

    This will sort it first by isSelfDM.

  9. getusha commented on May 28, 2024

    @getusha
    Contributor

    @bernhardoj's proposal looks good to me. the solution is straight forward and works perfectly.
    🎀 👀 🎀 C+ Reviewed

  10. 24 remaining items

  11. melvin-bot commented on Jun 13, 2024

    @melvin-bot
  12. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jun 13, 2024
  13. melvin-bot commented on Jun 13, 2024

    @melvin-bot

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

  14. jliexpensify commented on Jun 13, 2024

    @jliexpensify
    Contributor

    Re-applied label as no Upworks job was initially created

  15. removed
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jun 13, 2024
  16. jliexpensify commented on Jun 13, 2024

    @jliexpensify
    Contributor

    @getusha I don't know who you are - what's your Upworks profile? Please add your full name (as per Upworks) in your GH profile, thanks!

  17. getusha commented on Jun 13, 2024

    @getusha
    Contributor

    @jliexpensify could we hold on payments for a few days please? i am working on moving payments to ND. thanks

  18. jliexpensify commented on Jun 13, 2024

    @jliexpensify
    Contributor

    No worries, I'll just spin up a new Summary.

    Can I also confirm there's no regressions or issues that affect payment @techievivek and @Julesssss (based off this comment)?

    UPDATED Payment Summary:

    https://www.upwork.com/jobs/~01401c18bd7e84e155

  19. jliexpensify commented on Jun 16, 2024

    @jliexpensify
    Contributor

    Hi, sorry another bump for @techievivek and @Julesssss"

    Can I also confirm there's no regressions or issues that affect payment @techievivek and @Julesssss (based off this #42627 (comment))?

  20. Julesssss commented on Jun 17, 2024

    @Julesssss
    Contributor

    Yeah I don't believe there are any regressions. I think it's fine to pay out

  21. jliexpensify commented on Jun 17, 2024

    @jliexpensify
    Contributor

    Paid @bernhardoj, thanks for your patience! @getusha please refer to this summary for ND payments.

  22. jliexpensify commented on Jun 17, 2024

    @jliexpensify
    Contributor

    @getusha also, does a checklist need to be completed here?

  23. getusha commented on Jun 17, 2024

    @getusha
    Contributor

    [@getusha] The PR that introduced the bug has been identified. Link to the PR: N/a it is a feature request
    [@getusha] 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: N/a
    [@getusha] 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: N/a
    [@getusha] Determine if we should create a regression test for this bug. Yes
    [@getusha] 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.

    Regression Test Proposal

    1. Open search page
    2. Search for the account you currently signed in with (email or name)
    3. Verify that self DM appears at the top of the result

    Do we agree 👍 or 👎

  24. JmillsExpensify commented on Jun 19, 2024

    @JmillsExpensify
    Contributor

    $250 approved for @getusha

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.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorFirstPickEngineering only, please! Only add when there is an identified code solution.

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions