Skip to content

[$250] Search - Tags from another workspace are displayed when filtering by workspace #84239

Closed

Description

@jponikarchuk

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: v9.3.31-2
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/TR-7606/folder/13176922/47701683/1228589318?sort=%2Bidentifier
Email or phone of affected tester (no customers): n/a
Issue reported by: Applause Internal Team
Bug source: Regression TC Execution
Device used: Mac 15.4.1 Safari/Chrome
App Component: Search

Action Performed:

Preconditons: There are 2 workspaces (one workspace has added tags)

  1. Go to https://staging.new.expensify.com
  2. Go to Reports Tab
  3. Click "Expenses" in the left sidebar
  4. Click on the Search field
  5. Type "workspace:" and Verify that you see autocomplete list for workspaces
  6. Select the workspace without tags added
  7. Click "Filters"
  8. Go to the tags filter page

Expected Result:

Tags from another workspace should not appear in the list

Actual Result:

Tags from another workspace are displayed when filtering by workspace

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @suneox
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022029432897821585422
  • Upwork Job ID: 2029432897821585422
  • Last Price Increase: 2026-03-05

Activity

  1. added
    Daily
    Bug
    on Mar 5, 2026
  2. melvin-bot commented on Mar 5, 2026

    @melvin-bot

    Triggered auto assignment to @JmillsExpensify (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. MobileMage commented on Mar 5, 2026

    @MobileMage
    Contributor

    Proposal

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

    When a user filters search results by a specific workspace and then opens the Tags filter, tags from all workspaces are displayed instead of only tags from the selected workspace.

    What is the root cause of that problem?

    In SearchFiltersTagPage, when building the tagItems list, there is a condition that falls back to showing tags from ALL policies when selectedPoliciesTagLists is empty. The problem is that selectedPoliciesTagLists is only populated when policyIDs (from the search filters form) is non-empty. However, even when a workspace IS selected in the search bar (via workspace: prefix in the query), the policyID field in the advanced filters form may not reflect that selection — so selectedPoliciesTagLists ends up empty and the fallback path runs, pulling tags from every policy.

    if (!selectedPoliciesTagLists || selectedPoliciesTagLists.length === 0) {
    const tagListsUnpacked = Object.values(allPolicyTagLists ?? {}).filter((item) => !!item);
    for (const tag of tagListsUnpacked.map(getTagNamesFromTagsLists).flat()) {
    uniqueTagNames.add(tag);
    }

    The fallback at line 42 is too broad: it iterates over all values of allPolicyTagLists with no workspace restriction, so every tag from every workspace the user belongs to gets included.

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

    The fix is to derive the active policy filter from the current search query (not just the advanced filters form policyID field) and use it when narrowing tags. The searchAdvancedFiltersForm already has a policyID array — we need to make sure this is read correctly AND that when policyID is populated, the fallback path is skipped entirely. Additionally, the condition guarding the fallback should be tightened: if the user has explicitly selected a workspace (policyID is non-empty), we should show an empty list rather than fall back to all tags.

    const policyIDs = searchAdvancedFiltersForm?.policyID ?? [];
    const [allPolicyTagLists = getEmptyObject<NonNullable<OnyxCollection<PolicyTagLists>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
    const selectedPoliciesTagLists = Object.keys(allPolicyTagLists ?? {})
    .filter((key) => policyIDs?.map((policyID) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`)?.includes(key))
    ?.map((key) => getTagNamesFromTagsLists(allPolicyTagLists?.[key] ?? {}))
    .flat();
    const tagItems = useMemo(() => {
    const items = [{name: translate('search.noTag'), value: CONST.SEARCH.TAG_EMPTY_VALUE as string}];
    const uniqueTagNames = new Set<string>();
    if (!selectedPoliciesTagLists || selectedPoliciesTagLists.length === 0) {
    const tagListsUnpacked = Object.values(allPolicyTagLists ?? {}).filter((item) => !!item);
    for (const tag of tagListsUnpacked.map(getTagNamesFromTagsLists).flat()) {
    uniqueTagNames.add(tag);
    }
    } else {
    for (const tag of selectedPoliciesTagLists) {
    uniqueTagNames.add(tag);
    }
    }
    items.push(...Array.from(uniqueTagNames).map((tagName) => ({name: getCleanedTagName(tagName), value: tagName})));
    return items;
    }, [allPolicyTagLists, selectedPoliciesTagLists, translate]);

         const policyIDs = searchAdvancedFiltersForm?.policyID ?? [];
         const [allPolicyTagLists = getEmptyObject<NonNullable<OnyxCollection<PolicyTagLists>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
         const selectedPoliciesTagLists = Object.keys(allPolicyTagLists ?? {})
             .filter((key) => policyIDs?.map((policyID) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`)?.includes(key))
             ?.map((key) => getTagNamesFromTagsLists(allPolicyTagLists?.[key] ?? {}))
             .flat();
    
         const tagItems = useMemo(() => {
             const items = [{name: translate('search.noTag'), value: CONST.SEARCH.TAG_EMPTY_VALUE as string}];
             const uniqueTagNames = new Set<string>();
    
    -        if (!selectedPoliciesTagLists || selectedPoliciesTagLists.length === 0) {
    +        if (policyIDs.length === 0) {
                 const tagListsUnpacked = Object.values(allPolicyTagLists ?? {}).filter((item) => !!item);
                 for (const tag of tagListsUnpacked.map(getTagNamesFromTagsLists).flat()) {
                     uniqueTagNames.add(tag);
                 }
    -        } else {
    +        } else if (selectedPoliciesTagLists.length > 0) {
                 for (const tag of selectedPoliciesTagLists) {
                     uniqueTagNames.add(tag);
                 }
             }
             items.push(...Array.from(uniqueTagNames).map((tagName) => ({name: getCleanedTagName(tagName), value: tagName})));
    
             return items;
    -    }, [allPolicyTagLists, selectedPoliciesTagLists, translate]);
    +    }, [allPolicyTagLists, policyIDs, selectedPoliciesTagLists, translate]);

    The key change is replacing the condition !selectedPoliciesTagLists || selectedPoliciesTagLists.length === 0 with policyIDs.length === 0. The old condition was true whenever a selected policy happened to have no tags, which caused the fallback to show all tags from all other workspaces. The new condition correctly checks whether the user has filtered by a workspace at all — if they have, we only show that workspace's tags (even if that list is empty); if they haven't, we show all tags across all workspaces.

    What alternative solutions did you explore? (Optional)

    N/A

  4. MelvinBot commented on Mar 5, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When a user searches with a specific workspace filter (e.g. workspace:MyWorkspace), then opens Filters > Tags, tags from all workspaces are displayed instead of only tags from the selected workspace. This is especially noticeable when the selected workspace has no tags — the user sees tags from other workspaces that shouldn't appear.

    What is the root cause of that problem?

    In SearchFiltersTagPage.tsx, the code builds a list of tags to display. On line 30, it reads policyIDs from the filter form. On lines 32-35, it filters allPolicyTagLists to only the selected workspace's tags (selectedPoliciesTagLists).

    The bug is on line 41:

    if (!selectedPoliciesTagLists || selectedPoliciesTagLists.length === 0) {
    

    This condition conflates two different scenarios:

    1. No workspace selected → policyIDs is [] → selectedPoliciesTagLists is [] → showing all tags is correct
    2. Workspace selected but has no tags → policyIDs is ['ABC123'] → selectedPoliciesTagLists is [] → should show no tags, but the fallback incorrectly shows all tags from all workspaces

    The condition checks whether the result is empty rather than whether a workspace filter was applied, so it always falls through to the "show everything" path when the selected workspace has no tags.

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

    In SearchFiltersTagPage.tsx, change the condition on line 41 from checking selectedPoliciesTagLists.length === 0 to checking policyIDs.length === 0. This way:

    • When no workspace is selected (policyIDs is empty) → show all tags (existing behavior, correct)
    • When a workspace is selected but has no tags (policyIDs is non-empty, selectedPoliciesTagLists is empty) → show no tags (fixed behavior)

    The same fix should be applied to SearchFiltersCategoryPage.tsx line 63, which has the identical pattern with categories.

    What alternative solutions did you explore? (Optional)

    An alternative would be to pass the policyID as a navigation parameter to the tag filter page rather than relying on the Onyx form state. However, the current Onyx-based approach is the established pattern, and the fix only requires changing the conditional check — no architectural changes needed.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.

  5. added
    External
    on Mar 5, 2026
  6. added
    Help Wanted
    on Mar 5, 2026
  7. melvin-bot commented on Mar 5, 2026

    @melvin-bot

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

  8. changed the title [-]Search - Tags from another workspace are displayed when filtering by workspace[/-] [+][$250] Search - Tags from another workspace are displayed when filtering by workspace[/+] on Mar 5, 2026
  9. melvin-bot commented on Mar 5, 2026

    @melvin-bot
  10. soul5681 commented on Mar 5, 2026

    @soul5681

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  11. melvin-bot commented on Mar 5, 2026

    @melvin-bot

    📣 @soul5681! 📣
    Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
    Please follow these steps:

    1. Make sure you've read and understood the contributing guidelines.
    2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
    3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
    4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
      Screen Shot 2022-11-16 at 4 42 54 PM
      Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
    
  12. 24 remaining items

  13. mallenexpensify commented on Apr 7, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @suneox due $250 via NewDot on 2026-04-09

    @suneox plz complete the BZ checklist and tag me in a post once you have. Thx

  14. suneox commented on Apr 9, 2026

    @suneox
    Contributor

    BugZero Checklist:

    • [Contributor] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

    No offending PR found, since this issue has existed for a long time and the initial feature didn’t cover this case.

    https://github.com/Expensify/App/pull/46736/changes#diff-f3e2c0819ebed173923f13241afa3481c09eb78638caba5b1730f3c0c6dffa49L37
    
    • [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.

    Regression Test Proposal

    Precondition:

    There are 2 workspaces (one workspace has added tags)

    Test:

    1. Go to Reports Tab
    2. Click "Expenses" in the left sidebar
    3. Click on the Search field
    4. Type "workspace:" and Verify that you see autocomplete list for workspaces
    5. Select the workspace without tags added
    6. Click "Filters"
    7. Go to the tags filter page

    Verify Tags from another workspace should not appear in the list

    Do we agree 👍 or 👎

  15. added
    Daily
    and removed
    Weekly
    on Apr 13, 2026
  16. melvin-bot commented on Apr 16, 2026

    @melvin-bot

    @suneox Whoops! This issue is 2 days overdue. Let's get this updated quick!

  17. suneox commented on Apr 17, 2026

    @suneox
    Contributor

    Not overdue, this issue is ready for payment I'll submit on ND soon

  18. melvin-bot commented on Apr 20, 2026

    @melvin-bot

    @suneox Whoops! This issue is 2 days overdue. Let's get this updated quick!

  19. JmillsExpensify commented on Apr 22, 2026

    @JmillsExpensify
    Contributor

    I created the regression test. Closing.

  20. garrettmknight commented on Apr 23, 2026

    @garrettmknight
    Contributor

    $250 approved for @suneox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions