Skip to content

[HOLD for payment 2024-11-20] [$250] Search filters - Category list shows default categories when no workspace is created #50564

Closed

Description

@lanitochka17

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


Version Number: 9.0.47-1
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Email or phone of affected tester (no customers): applausetester+pso@applause.expensifail.com
Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Log in with a new account (no workspace)
  3. Go to Search
  4. Click Filters
  5. Click Categories

Expected Result:

Category list should be empty because no workspace is created

Actual Result:

Category list shows default categories when no workspace is created

Workaround:

Unknown

Platforms:

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

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
Bug6630371_1728540215030.20241010_140142.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021844424503641996992
  • Upwork Job ID: 1844424503641996992
  • Last Price Increase: 2024-10-31
Issue OwnerCurrent Issue Owner: @garrettmknight

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 10, 2024
  2. melvin-bot commented on Oct 10, 2024

    @melvin-bot

    Triggered auto assignment to @garrettmknight (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.

  3. lanitochka17 commented on Oct 10, 2024

    @lanitochka17
    Author

    @garrettmknight FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

  4. lanitochka17 commented on Oct 10, 2024

    @lanitochka17
    Author

    We think that this bug might be related to #wave-control

  5. NJ-2020 commented on Oct 10, 2024

    @NJ-2020
    Contributor

    Edited by proposal-police: This proposal was edited at 2024-10-16 06:05:34 UTC.

    Proposal

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

    Search filters - Category list shows default categories when no workspace is created

    What is the root cause of that problem?

    Right here we don't filter out the personal policy for allPolicyIDCategories

    const [allPolicyIDCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES);
    const singlePolicyCategories = allPolicyIDCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`];
    const categoryItems = useMemo(() => {
    if (!singlePolicyCategories) {
    const uniqueCategoryNames = new Set<string>();
    Object.values(allPolicyIDCategories ?? {}).map((policyCategories) => Object.values(policyCategories ?? {}).forEach((category) => uniqueCategoryNames.add(category.name)));
    return Array.from(uniqueCategoryNames).map((categoryName) => ({name: categoryName, value: categoryName}));
    }
    return Object.values(singlePolicyCategories ?? {}).map((category) => ({name: category.name, value: category.name}));
    }, [allPolicyIDCategories, singlePolicyCategories]);

    And inside AdvancedSearchFilters.tsx we don't hide the categories, tags, and taxes if the list is empty

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

    We can create 2 new hooks inside PolicyUtils to get the lists of tags and categories, for taxes we already have right here:

    const taxRates = getAllTaxRates();

    and we will hide the categories, tags and taxes inside AdvancedSearchFilters page if the list is empty

    function getAllTags(): Record<string, string> {
        const tags: Record<string, string> = {};
        Object.values(allTags ?? {})?.forEach((policy) => {
            if (!policy?.Tag.tags) {
                return;
            }
            Object.entries(policy?.Tag.tags).forEach(([tagKey, tag]) => {
                if (!tags[tag.name]) {
                    tags[tag.name] = tagKey;
                    return;
                }
            });
        });
        return tags;
    }
    
    function getAllCategories() {
        const uniqueCategoryNames = new Set<string>();
        const personalPolicyID = getPersonalPolicy()?.id;
        Object.entries(allCategories ?? {})?.forEach(([policyKey, policyCategories]) => {
            if (isEmptyObject(policyCategories) || policyKey === `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${personalPolicyID}`) {
                return;
            }
            Object.values(policyCategories ?? {}).forEach((category) => uniqueCategoryNames.add(category.name));
        });
        return Array.from(uniqueCategoryNames).map((categoryName) => ({name: categoryName, value: categoryName}));
    }

    Then inside AdvancedSearchFilters

    const tags = getAllTags();
    const categories = getAllCategories();
    
    ...
    else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY) {
        if (isEmptyObject(categories)) {
            return undefined;
        }
        filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, key, translate);
    } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG) {
        if (isEmptyObject(tags)) {
            return undefined;
        }
        filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, key, translate);
    }  else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAX_RATE) {
        if (isEmptyObject(taxRates)) {
            return undefined;
        }
        filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, taxRates);
    }

    For cards we already hide right here if the lists are empty

    const [cardList = {}] = useOnyx(ONYXKEYS.CARD_LIST);

    } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.CARD_ID) {
    if (Object.keys(cardList).length === 0) {
    return undefined;
    }
    filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, cardList);

    But i think for cards we should update the if condition from above code to:

    if (isEmptyObject(cardList)) {
        return undefined;
    }

    And Inside the SearchFiltersCategoryPage we can use the new hook we just created getAllCategories if the current policy categories is empty which also will filter out the personal policy
    And we should update from this:

    const categoryItems = useMemo(() => {
    const items = [{name: translate('search.noCategory'), value: CONST.SEARCH.EMPTY_VALUE as string}];
    if (!singlePolicyCategories) {
    const uniqueCategoryNames = new Set<string>();
    Object.values(allPolicyIDCategories ?? {}).map((policyCategories) => Object.values(policyCategories ?? {}).forEach((category) => uniqueCategoryNames.add(category.name)));
    items.push(...Array.from(uniqueCategoryNames).map((categoryName) => ({name: categoryName, value: categoryName})));
    } else {
    items.push(...Object.values(singlePolicyCategories ?? {}).map((category) => ({name: category.name, value: category.name})));
    }
    return items;
    }, [allPolicyIDCategories, singlePolicyCategories, translate]);

    to

    const categoryItems = useMemo(() => {
        if (!singlePolicyCategories) {
            return PolicyUtils.getAllCategories();
        }
        return Object.values(singlePolicyCategories ?? {}).map((category) => ({name: category.name, value: category.name}));
    }, [singlePolicyCategories]);

    Here's the test branch

    Result

    What alternative solutions did you explore? (Optional)

  6. truph01 commented on Oct 10, 2024

    @truph01
    Contributor

    Edited by proposal-police: This proposal was edited at 2024-10-11 23:28:14 UTC.

    Proposal

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

    Category list shows default categories when no workspace is created

    What is the root cause of that problem?

    • In the logic to get the categories from policies:

    Object.values(allPolicyIDCategories ?? {}).map((policyCategories) => Object.values(policyCategories ?? {}).forEach((category) => uniqueCategoryNames.add(category.name)));

    we don't filter out the personal policy, which also has categories.

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

    • In this, we should check if the policy is personal policy, if so, don't get categories from it:
                const personalPolicyID = PolicyUtils.getPersonalPolicy()?.id;
                const allPolicyIDCategoriesWithoutPersonalPolicy = Object.keys(allPolicyIDCategories).map((key)=>{
                    if(key === `policyCategories_${personalPolicyID}`){
                        return {}
                    }
                    return allPolicyIDCategories?.[key]
                })
              
                allPolicyIDCategoriesWithoutPersonalPolicy.map((policyCategories) => Object.values(policyCategories ?? {}).forEach((category) => uniqueCategoryNames.add(category.name)));
    

    What alternative solutions did you explore? (Optional)

    • Beside the main solution, if we want to hide the category option in AdvancedSearchFilters if there is no category option, we can:
    1. Create a util hook to get the categories, tags, cards, ... data:
    const useFilterOption = () => {
        const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM);
        const selectedCategoriesItems = searchAdvancedFiltersForm?.category?.map((category) => ({name: category, value: category}));
        const policyID = searchAdvancedFiltersForm?.policyID ?? '-1';
        const [allPolicyIDCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES);
        const singlePolicyCategories = allPolicyIDCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`];
    
        const categories = useMemo(() => {
            if (!singlePolicyCategories) {
                const uniqueCategoryNames = new Set<string>();
                Object.values(allPolicyIDCategories ?? {}).map((policyCategories) => Object.values(policyCategories ?? {}).forEach((category) => uniqueCategoryNames.add(category.name)));
                return Array.from(uniqueCategoryNames).map((categoryName) => ({name: categoryName, value: categoryName}));
            }
            return Object.values(singlePolicyCategories ?? {}).map((category) => ({name: category.name, value: category.name}));
        }, [allPolicyIDCategories, singlePolicyCategories]);
    
        const [allPoliciesTagsLists] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
        const singlePolicyTagsList: PolicyTagLists | undefined = allPoliciesTagsLists?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`];
    
        const tags = useMemo(() => {
            if (!singlePolicyTagsList) {
                const uniqueTagNames = new Set<string>();
                const tagListsUnpacked = Object.values(allPoliciesTagsLists ?? {}).filter((item) => !!item) as PolicyTagLists[];
                tagListsUnpacked
                    .map((policyTagLists) => {
                        return getTagNamesFromTagsLists(policyTagLists);
                    })
                    .flat()
                    .forEach((tag) => uniqueTagNames.add(tag));
                return Array.from(uniqueTagNames).map((tagName) => ({name: tagName, value: tagName}));
            }
            return getTagNamesFromTagsLists(singlePolicyTagsList).map((name) => ({name, value: name}));
        }, [allPoliciesTagsLists, singlePolicyTagsList]);
    
        const [cards] = useOnyx(ONYXKEYS.CARD_LIST);
        return {categories, tags, cards};
    };
    
    1. In AdvancedSearchFilters use:
        const {cards, categories, tags} = useFilterOption();
    

    then for the key category, tag, or card, check if its options length is greater than 0, if not, return undefined in:

    const filters = typeFiltersKeys[currentType].map((key) => {

  7. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Oct 10, 2024
  8. changed the title [-]Search filters - Category list shows default categories when no workspace is created[/-] [+][$250] Search filters - Category list shows default categories when no workspace is created[/+] on Oct 10, 2024
  9. melvin-bot commented on Oct 10, 2024

    @melvin-bot
  10. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Oct 10, 2024
  11. melvin-bot commented on Oct 10, 2024

    @melvin-bot

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

  12. 52 remaining items

  13. melvin-bot commented on Nov 20, 2024

    @melvin-bot

    Payment Summary

    Upwork Job

    • Contributor: @Kicu is from an agency-contributor and not due payment
    • Reviewer: @fedirjh owed $250 via NewDot

    BugZero Checklist (@garrettmknight)

    • 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/1844424503641996992/hired)
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  14. garrettmknight commented on Nov 21, 2024

    @garrettmknight
    Contributor

    @fedirjh please complete the checklist when you get a chance.

  15. fedirjh commented on Nov 22, 2024

    @fedirjh
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production
    • 2b. Reported on staging (deploy blocker)
    • 2c. Reported on both staging and production
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] 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 This is a new feature rather than a bug fix.

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source 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

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue:

    Regression Test Proposal

    Precondition:

    Test:

    1. Open Search
    2. Open Advanced filters RHP
    3. Verify that there is no tag filter displayed if user has no tags
    4. Verify that there is no category filter displayed if user has no categories
    5. Verify that there is no tax filter displayed if user has no taxes

    Do we agree 👍 or 👎

  16. melvin-bot commented on Nov 25, 2024

    @melvin-bot

    @garrettmknight, @Kicu, @luacmartins, @fedirjh Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  17. garrettmknight commented on Nov 25, 2024

    @garrettmknight
    Contributor

    @fedirjh thanks - submit the payment request when you're ready!

  18. moved this from Hold for Payment to Done in #expensify-bugson Nov 25, 2024
  19. JmillsExpensify commented on Dec 10, 2024

    @JmillsExpensify
    Contributor

    Payment summary: @fedirjh owed $250 via NewDot

  20. garrettmknight commented on Dec 10, 2024

    @garrettmknight
    Contributor

    $250 approved for @fedirjh

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 contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions