App icon indicating copy to clipboard operation
App copied to clipboard

[$250] Spend - The card accruals tab shows no results even though there are unapproved expenses

Open izarutskaya opened this issue 1 month ago • 61 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: Reproducible in staging?: Needs Reproduction (Reproduction blocked) Reproducible in production?: Needs Reproduction (Reproduction blocked) If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @GeoVasile Slack conversation (hyperlinked to channel name): #expensify_bugs

Action Performed:

Prerequisites: Needs account with card accruals

  1. Log in Expensify (admin account)
  2. Go to Spend > Card accruals
  3. Enter desired filters (or leave automatically applied) and see the results

Expected Result:

Should show all unapproved expenses in that date range

Actual Result:

The page is empty with a "Nothing to show" message

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [ ] MacOS: Chrome / Safari

Screenshots/Videos

For the details, check please the OP

View all open jobs on GitHub

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mukhrr

izarutskaya avatar Oct 23 '26 10:10 izarutskaya

⚠️ Preliminary analysis (low confidence) — treat as a starting point, not a conclusion.

I think the Card accruals tab is empty because its default query searches only one card feed. If the admin's unapproved card expenses are on a different feed, the search returns nothing.

The query is type:expense group-by:card feed:<one feed> status:unreported,drafts,outstanding (SearchSuggestionUtils.ts:333-343). The feed is activeExpensifyCardFeedID ?? defaultFeedID (SearchSuggestionUtils.ts:152). Since Default Card accruals to the active workspace's Expensify Card, the active workspace's Expensify Card wins whenever it exists (useCardFeedsForDisplay.ts:76-103). It never checks which feed actually has unapproved spend. So expenses on a company/bank feed, or on another workspace's Expensify Card, are excluded.

I wasn't able to verify this because reproduction is blocked and the issue doesn't say which feed the reporter's expenses are on. To confirm, check:

  1. Which feed: value is in the Card accruals query on the affected account (click the search bar or check the Search request's jsonQuery).
  2. Whether the unapproved expenses are on that same feed. If they aren't, this is the cause.
  3. Whether the reporter added date filters (for example, posted vs. date) that also exclude the expenses.

If confirmed, the fix is a product decision: drop the feed filter from the default query, or include every eligible feed instead of one.

Ruled out
  • Feed ID format mismatch: the Expensify Card feed ID (<fundID>_Expensify Card, CardFeedUtils.ts:171) is the same format the Statements search already uses.
  • Client-side filtering: card groups are only dropped when cardID is missing (SearchUIUtils.ts:3263-3283), so an empty page means the server returned nothing for the query.
  • Automatic date range: the default query adds no date filter.

Next Steps: Reply with @MelvinBot <your feedback> to refine this analysis.


view run

MelvinBot avatar Oct 23 '26 10:10 MelvinBot

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

melvin-bot[bot] avatar Oct 23 '26 10:10 melvin-bot[bot]

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

melvin-bot[bot] avatar Oct 23 '26 10:10 melvin-bot[bot]

Proposal

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

In Spend > Card accruals, the tab displays "Nothing to show" and returns no results even when there are unapproved card expenses present on the account.

What is the root cause of that problem?

There are two primary factors causing this issue in src/libs/SearchSuggestionUtils.ts:

  1. Empty String Fallback in Default Query Serialization: In src/libs/SearchSuggestionUtils.ts (lines 338-343), the query for CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD is constructed via:

    searchQuery: buildQueryStringFromFilterFormValues({
        type: CONST.SEARCH.DATA_TYPES.EXPENSE,
        feed: unapprovedCardFeedID ? [unapprovedCardFeedID] : [''],
        groupBy: CONST.SEARCH.GROUP_BY.CARD,
        status: [CONST.SEARCH.STATUS.EXPENSE.UNREPORTED, CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING],
    }),
    

    When unapprovedCardFeedID is undefined (e.g. workspace without an active Expensify Card or before defaultFeedID resolves), the ternary falls back to ['']. In buildQueryStringFromFilterFormValues, passing an empty string array results in generating a malformed or empty feed filter (feed: ), which causes the backend search parser to fail to match any expenses, returning an empty result set.

  2. Single-Feed Restriction on Multi-Feed Card Accruals: In line 152 of SearchSuggestionUtils.ts:

    const unapprovedCardFeedID = activeExpensifyCardFeedID ?? defaultFeedID;
    

    Card accruals represent all unapproved card expenses awaiting approval across an admin's managed cards. Enforcing a strict single-feed filter (unapprovedCardFeedID) isolates the query to only one specific card feed. If an admin has unapproved expenses on company card feeds (e.g. Visa/Mastercard commercial feeds) or on other workspace cards, they are completely excluded from the search result.

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

1. In src/libs/SearchSuggestionUtils.ts:

  • Omit the feed filter when unapprovedCardFeedID is not present, instead of passing ['']:
[CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD]: {
    key: CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD,
    translationPath: 'search.tabs.unapprovedCard',
    type: CONST.SEARCH.DATA_TYPES.EXPENSE,
    icon: 'CreditCardHourglass',
    searchQuery: buildQueryStringFromFilterFormValues({
        type: CONST.SEARCH.DATA_TYPES.EXPENSE,
        ...(unapprovedCardFeedID ? {feed: [unapprovedCardFeedID]} : {}),
        groupBy: CONST.SEARCH.GROUP_BY.CARD,
        status: [CONST.SEARCH.STATUS.EXPENSE.UNREPORTED, CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING],
    }),
    // ...
}

When unapprovedCardFeedID is not provided (or when viewing all unapproved card spend grouped by card), omitting the feed parameter allows the search query (type:expense groupBy:card status:unreported,drafts,outstanding) to correctly query all unapproved card expenses across the user's cards.

  • Alternatively, if the product requirement is to support all active card feeds when multiple exist, pass the array of eligible feed IDs from useCardFeedsForDisplay rather than narrowing strictly to activeExpensifyCardFeedID ?? defaultFeedID.

2. In src/libs/SearchQueryUtils.ts:

In buildQueryStringFromFilterFormValues, sanitize the feed array by filtering out empty or whitespace-only strings (filter(feed => feed?.trim())) so that empty string elements are never serialized into search queries.

What alternative solutions did you explore? (Optional)

  • MelvinBot's analysis: MelvinBot identified the feed restriction but did not address the fallback bug where feed: [''] emits an empty filter parameter that breaks search resolution, and did not supply a concrete code diff.
  • Dropping groupBy: card: Unnecessary and undesired, as Card accruals specifically requires grouping results by card entity.

What automated tests can you add to prevent this from re-occurring?

In tests/unit/SearchSuggestionUtilsTest.ts:

  1. Verify UNAPPROVED_CARD query generation when unapprovedCardFeedID is undefined: ensure the resulting query string does not contain feed: or empty feed tokens.
  2. Verify that when unapprovedCardFeedID is valid, it is correctly serialized into the feed:<id> syntax alongside group-by:card.
  3. Verify that buildQueryStringFromFilterFormValues strips empty string items from the feed filter array.

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01b60d704ba377be83

camesenin avatar Oct 23 '26 10:10 camesenin

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Oct 23 '26 10:10 melvin-bot[bot]

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01963a583fd60b304f

Proposal

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

In Spend > Card accruals, navigating to the tab shows "Nothing to show" and returns zero results, even when there are unapproved card expenses present in that date range.


What is the root cause of that problem?

There are two compounding bugs in query construction and serialization:

1. Bogus Empty-String Fallback in SearchSuggestionUtils.ts:

In src/libs/SearchSuggestionUtils.ts (lines 338-343):

[CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD]: {
    key: CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD,
    translationPath: 'search.tabs.unapprovedCard',
    type: CONST.SEARCH.DATA_TYPES.EXPENSE,
    icon: 'CreditCardHourglass',
    searchQuery: buildQueryStringFromFilterFormValues({
        type: CONST.SEARCH.DATA_TYPES.EXPENSE,
        feed: unapprovedCardFeedID ? [unapprovedCardFeedID] : [''],
        groupBy: CONST.SEARCH.GROUP_BY.CARD,
        status: [CONST.SEARCH.STATUS.EXPENSE.UNREPORTED, CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING],
    }),

When unapprovedCardFeedID is undefined (for instance, when an admin navigates to Card accruals on a workspace without an active Expensify Card or before card feeds are fetched), the ternary expression explicitly falls back to [''] (an array containing a single empty string) instead of undefined.

2. Query Serializer Emits Dangling feed: Filter in SearchQueryUtils.ts:

In src/libs/SearchQueryUtils.ts (lines 1537-1546), buildQueryStringFromFilterFormValues checks:

Array.isArray(filterValue) && filterValue.length > 0

Because [''].length === 1, this condition evaluates to true. The sanitizer then serializes [''], resulting in a malformed dangling syntax token:

type:expense status:unreported,drafts,outstanding groupBy:card feed:

When sent to the backend search engine, feed: matches an empty feed identifier (which matches 0 expenses), completely suppressing all unapproved card expenses and rendering "Nothing to show".

Additionally, when an organization has card expenses on company bank feeds (Plaid / commercial card feeds) or multiple feeds, restricting the query strictly to a single activeExpensifyCardFeedID ?? defaultFeedID causes expenses on other company card feeds to be omitted when filtered.


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

We should implement a clean, two-part fix:

1. Caller Fix in src/libs/SearchSuggestionUtils.ts:

Do not inject [''] when unapprovedCardFeedID is undefined. Only supply feed when a valid feed ID exists:

searchQuery: buildQueryStringFromFilterFormValues({
    type: CONST.SEARCH.DATA_TYPES.EXPENSE,
    ...(unapprovedCardFeedID ? {feed: [unapprovedCardFeedID]} : {}),
    groupBy: CONST.SEARCH.GROUP_BY.CARD,
    status: [CONST.SEARCH.STATUS.EXPENSE.UNREPORTED, CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING],
}),

When unapprovedCardFeedID is omitted, the query evaluates to type:expense status:unreported,drafts,outstanding groupBy:card, which correctly aggregates all unapproved card expenses across the account grouped by card.

2. Defensive Serializer Guard in src/libs/SearchQueryUtils.ts:

In buildQueryStringFromFilterFormValues (line 1540), sanitize array filter values by filtering out empty or whitespace-only strings before generating the query syntax:

const filterValueArray = [...new Set<string>(filterValue.filter((val): val is string => typeof val === 'string' && val.trim().length > 0))];
if (filterValueArray.length === 0) {
    return undefined;
}

This ensures that even if any caller passes empty string values in an array filter (for feed, policyID, from, etc.), buildQueryStringFromFilterFormValues will never emit dangling filter keys (feed:, policyID:) that break backend search query execution.


What alternative solutions did you explore? (Optional)

  • Only fixing SearchSuggestionUtils.ts: Leaving SearchQueryUtils.ts unpatched leaves the query generator vulnerable whenever filter forms or URL queries contain empty array elements.
  • Dropping groupBy: card: Not viable, as Card accruals specifically requires grouping by card entity.

What automated tests can you add to prevent this from re-occurring?

In tests/unit/SearchQueryUtilsTest.ts:

  1. Verify that buildQueryStringFromFilterFormValues strips empty string elements from array filters (e.g., {feed: ['']}) and does not emit dangling feed: in the query string.
  2. Verify that valid feed filters ({feed: ['12345_Expensify Card']}) are properly serialized as feed:"12345_Expensify Card".

In tests/unit/SearchSuggestionUtilsTest.ts:

  1. Verify that getSuggestedSearches creates UNAPPROVED_CARD search query without feed: when unapprovedCardFeedID is undefined.
  2. Verify that when unapprovedCardFeedID is provided, it is correctly included in the UNAPPROVED_CARD search query.

pranav440 avatar Oct 24 '26 09:10 pranav440

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Oct 24 '26 09:10 melvin-bot[bot]

Proposal

What is the root cause of that problem?

The Card accruals query is scoped to one feed. In getSuggestedSearches (src/libs/SearchSuggestionUtils.ts, UNAPPROVED_CARD) it is feed: unapprovedCardFeedID ? [unapprovedCardFeedID] : [''], with unapprovedCardFeedID = activeExpensifyCardFeedID ?? defaultFeedID (line ~152). SearchQueryProvider.tsx passes defaultCardFeed?.id (getDefaultCardFeed in useCardFeedsForDisplay.ts returns .at(0) of one policy's feeds) and activeExpensifyCardFeedID, which wins whenever the active workspace has an Expensify Card. The tab shows if any workspace qualifies, but expenses on any other feed are filtered out, hence "Nothing to show". The [''] fallback is not the cause: Statements uses the same sentinel on purpose.

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

  1. In useCardFeedsForDisplay.ts, return unapprovedCardFeedIDs: activeExpensifyCardFeedID plus every id in Object.values(cardFeedsByPolicy).flat() (already computed there), de-duplicated.
  2. In SearchQueryProvider.tsx, pass it to getSuggestedSearches instead of activeExpensifyCardFeedID.
  3. In getSuggestedSearches, use feed: unapprovedCardFeedIDs?.length ? unapprovedCardFeedIDs : defaultFeedID ? [defaultFeedID] : ['']. feed is already an array filter.
  4. In tests/unit/SearchSuggestionUtilsTest.ts: two feed IDs both appear in the UNAPPROVED_CARD query; no IDs falls back to defaultFeedID, then to [''].

What alternative solutions did you explore? (Optional)

  • MelvinBot says to drop the feed filter or include all feeds but gives no diff; this is that diff, from data the hook already has.
  • camesenin and pranav440 remove the [''] fallback. That path only runs with no feed, would change Statements, and still leaves one feed for admins who have several.
  • Dropping group-by:card: not viable.

Stephen3453 avatar Oct 24 '26 10:10 Stephen3453

Proposal

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

In the Spend tab under To-do, clicking Card accruals shows no results even though the workspace has unapproved card expenses (and the Card accruals suggestion tab itself is visible in the left navigation).

What is the root cause of that problem?

There is a mismatch between the policy/feed eligibility logic that decides whether to show the Card accruals suggestion (src/libs/SearchUIUtils.ts:740-804) and the feed-resolution logic that builds its search query (src/hooks/useCardFeedsForDisplay.ts:21-129, src/components/Search/SearchQueryProvider.tsx:66-73, and src/libs/SearchSuggestionUtils.ts:144-153, 333-343):

  1. Visibility checks all policies with (isAdmin || isAuditor) && isApprovalEnabled, but getActiveExpensifyCardFeedID only checks activePolicyID: In src/libs/SearchUIUtils.ts:777, shouldShowUnapprovedCardSuggestion is true whenever any workspace in policies satisfies:
    isPaidPolicy && (isAdmin || isAuditor) && isApprovalEnabled && (hasCardFeed || !!defaultExpensifyCard)
    
    However, in src/hooks/useCardFeedsForDisplay.ts:76-129 (added in PR #97262), getActiveExpensifyCardFeedID only checks policies?.[${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}]. If activePolicyID is undefined, points to a personal/different workspace, or points to a workspace where approvalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL, activeExpensifyCardFeedID returns undefined.
  2. defaultCardFeed ignores (isAdmin || isAuditor) && isApprovalEnabled and overwrites defaultExpensifyCard: In src/components/Search/SearchQueryProvider.tsx:70-72 and src/hooks/useSearchTypeMenuSections.ts:116, defaultFeedID is passed as defaultCardFeed?.id ?? defaultExpensifyCard?.id. In src/hooks/useCardFeedsForDisplay.ts:21-28, eligiblePoliciesSelector used by getDefaultCardFeed only checks policy?.areCompanyCardsEnabled — it never checks isPaidGroupPolicy(policy), (isAdmin || isAuditor), or isApprovalEnabled! As a result:
    • defaultCardFeed can select a company card feed from a workspace where approvals are disabled or where the user is only a member, causing buildFeedQuery(activeExpensifyCardFeedID ?? defaultFeedID) in src/libs/SearchSuggestionUtils.ts:149 to query the wrong feed (feed:"...") and return zero results.
    • Even within a single eligible workspace that has both a company card feed and Expensify Cards (or across multiple eligible workspaces), activeExpensifyCardFeedID ?? defaultFeedID only passes a single feed ID instead of the eligible feeds that triggered shouldShowUnapprovedCardSuggestion.

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

Align the feed resolution for UNAPPROVED_CARD with the exact policy/feed eligibility criteria used in src/libs/SearchUIUtils.ts:740-804:

  1. In src/hooks/useCardFeedsForDisplay.ts, compute unapprovedCardFeedIDs (or eligible accrual feeds) using the same policy eligibility predicate as SearchUIUtils.ts:777:
    • A policy is eligible for Card accruals when isPaidGroupPolicy(policy) && (policy.role === CONST.POLICY.ROLE.ADMIN || policy.role === CONST.POLICY.ROLE.AUDITOR) and getApprovalWorkflow(policy) !== CONST.POLICY.APPROVAL_MODE.OPTIONAL.
    • If activePolicyID refers to an eligible policy that has at least one card feed (Expensify Card settings with id in allExpensifyCardSettings or a company card feed in cardFeedsByPolicy[activePolicyID]), collect the feed IDs for activePolicyID; otherwise, collect the feed IDs across all eligible policies (matching shouldShowUnapprovedCardSuggestion in SearchUIUtils.ts).
  2. In src/libs/SearchSuggestionUtils.ts (buildFeedQuery and getSuggestedSearches), accept unapprovedCardFeedIDs: string[]:
    • Update buildFeedQuery(feedIDs?: string[]) to emit feed:${feedIDs.map((id) => "${id}").join(',')} when feedIDs.length > 0, so the Card accruals query includes the eligible Expensify Card and/or company card feeds for the target workspace(s) and never falls back to a feed from an ineligible workspace.
  3. Pass unapprovedCardFeedIDs from useCardFeedsForDisplay in src/components/Search/SearchQueryProvider.tsx and src/hooks/useSearchTypeMenuSections.ts.

What alternative solutions did you explore? (Optional)

  • Only adding a fallback inside getActiveExpensifyCardFeedID when activePolicyID has no Expensify Card: That still breaks when defaultCardFeed comes from a workspace where approvals are disabled or the user is not an Admin/Auditor, or when an eligible workspace has both an Expensify Card feed and a company card feed. Filtering by the same eligibility predicate as SearchUIUtils.ts resolves all of these cases consistently.

shilo1979jk avatar Oct 25 '26 00:10 shilo1979jk

Proposal

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

In Spend > Card accruals (under the To-do section), clicking Card accruals displays "Nothing to show" even though the workspace has unapproved card expenses and the Card accruals suggestion tab is visible in the left navigation.

What is the root cause of that problem?

In src/libs/SearchSuggestionUtils.ts (lines 145-153 and 333-343), the UNAPPROVED_CARD (Card accruals) suggested search builds its query with a single feed parameter:

https://github.com/Expensify/App/blob/c08c85f3c5d20214e219dd1a1286936a513527cc/src/libs/SearchSuggestionUtils.ts#L150-L153

https://github.com/Expensify/App/blob/c08c85f3c5d20214e219dd1a1286936a513527cc/src/libs/SearchSuggestionUtils.ts#L333-L343

const unapprovedCardFeedID = activeExpensifyCardFeedID ?? defaultFeedID;
...
[CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD]: {
    key: CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD,
    translationPath: 'search.tabs.unapprovedCard',
    type: CONST.SEARCH.DATA_TYPES.EXPENSE,
    icon: 'CreditCardHourglass',
    searchQuery: buildQueryStringFromFilterFormValues({
        type: CONST.SEARCH.DATA_TYPES.EXPENSE,
        feed: unapprovedCardFeedID ? [unapprovedCardFeedID] : [''],
        groupBy: CONST.SEARCH.GROUP_BY.CARD,
        status: [CONST.SEARCH.STATUS.EXPENSE.UNREPORTED, CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING],
    }),

Meanwhile, in src/components/Search/SearchPageHeader/SearchTypeMenu.tsx / src/libs/SearchUIUtils.ts (createTypeMenuSections), the Card accruals menu item is shown whenever the user is an admin of any policy with a card feed (shouldShowUnapprovedCard), and SearchQueryProvider computes activeExpensifyCardFeedID and defaultFeedID (getDefaultCardFeed in src/hooks/useCardFeedsForDisplay.ts), which:

  1. Prioritizes activeExpensifyCardFeedID (the active workspace's Expensify Card feed) even if that feed has zero unapproved expenses while a company card feed (or another workspace's Expensify Card feed) has unapproved expenses, or
  2. Falls back to feed: [''] (feed:"") when unapprovedCardFeedID is undefined (for example, while card feeds are still loading or when defaultCardFeed does not resolve a feed key), which serializes an invalid empty feed:"" filter that matches zero transactions on the backend.

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

  1. Resolve activeExpensifyCardFeedID / defaultFeedID across eligible admin policies and avoid serializing feed: [''] in src/libs/SearchSuggestionUtils.ts:
    • In src/hooks/useCardFeedsForDisplay.ts / SearchQueryProvider, ensure that if the active policy does not have an Expensify Card feed (or is not an admin policy with card feeds), unapprovedCardFeedID falls back to an admin-eligible card feed (consistent with createTypeMenuSections in src/libs/SearchUIUtils.ts).
    • In src/libs/SearchSuggestionUtils.ts (lines 296 and 338), omit feed when unapprovedCardFeedID / defaultFeedID is undefined (...(unapprovedCardFeedID && {feed: [unapprovedCardFeedID]})) rather than passing [''] so the query never serializes a broken feed:"" token.

xian96xx avatar Oct 25 '26 14:10 xian96xx

📣 @xian96xx! 📣 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>

melvin-bot[bot] avatar Oct 25 '26 14:10 melvin-bot[bot]

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~016c1aa34b51059d42

Proposal

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

In Spend > Card accruals (under the To-do section), clicking Card accruals displays "Nothing to show" even though the workspace has unapproved card expenses and the Card accruals suggestion tab is visible in the left navigation.

What is the root cause of that problem?

In src/libs/SearchSuggestionUtils.ts (lines 333–343), the UNAPPROVED_CARD suggested search builds its query using buildQueryStringFromFilterFormValues:

[CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD]: {
    key: CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD,
    translationPath: 'search.tabs.unapprovedCard',
    type: CONST.SEARCH.DATA_TYPES.EXPENSE,
    icon: 'CreditCardHourglass',
    searchQuery: buildQueryStringFromFilterFormValues({
        type: CONST.SEARCH.DATA_TYPES.EXPENSE,
        feed: unapprovedCardFeedID ? [unapprovedCardFeedID] : [''],
        groupBy: CONST.SEARCH.GROUP_BY.CARD,
        status: [CONST.SEARCH.STATUS.EXPENSE.UNREPORTED, CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING],
    }),
  1. When unapprovedCardFeedID (computed as activeExpensifyCardFeedID ?? defaultFeedID) is undefined (for instance, when card feeds are loading or when the active policy is not linked to an Expensify card feed), it passes feed: [''].
  2. In src/libs/SearchQueryUtils.ts (lines 1537–1540), buildQueryStringFromFilterFormValues handles array filters:
    Array.isArray(filterValue) && filterValue.length > 0
    
    Because [''] has length === 1, it serializes feed:"" (an empty string feed name filter).
  3. Querying feed:"" forces the backend search to search exclusively for a card feed named "" (empty string), matching zero expenses and rendering "Nothing to show".
  4. The same issue exists in CONST.SEARCH.SEARCH_KEYS.STATEMENTS (line 292), which also passes feed: defaultFeedID ? [defaultFeedID] : [''].

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

  1. In src/libs/SearchSuggestionUtils.ts:

    • For UNAPPROVED_CARD (line 340), pass feed: unapprovedCardFeedID ? [unapprovedCardFeedID] : undefined (or conditionally include ...(unapprovedCardFeedID ? {feed: [unapprovedCardFeedID]} : {})) instead of [''].
    • For STATEMENTS (line 292), pass feed: defaultFeedID ? [defaultFeedID] : undefined instead of ['']. When feed is omitted, the query correctly searches unapproved expenses across all eligible card feeds without appending an invalid feed:"" constraint.
  2. In src/libs/SearchQueryUtils.ts:

    • Inside buildQueryStringFromFilterFormValues (line 1540), sanitize array values by filtering out empty/whitespace strings:
    const filterValueArray = [...new Set<string>(filterValue)].filter((value) => value.trim().length > 0);
    

    This prevents any array filter (feed, category, tag, etc.) from serializing empty string literals like feed:"" if empty strings ever enter form state.

What alternative solutions did you explore? (Optional)

Only fixing SearchQueryUtils.ts without cleaning up SearchSuggestionUtils.ts; however, fixing both at the suggestion builder and query serializer ensures complete consistency and protects all filter keys against empty token pollution.

Test Result / Verification:

  1. Open Spend > Card accruals with an account that has unapproved card expenses on a workspace/feed.
  2. Verify that clicking Card accruals opens the search query: type:expense status:unreported,drafts,outstanding groupBy:card (or with the resolved feed: parameter).
  3. Verify that the unapproved expenses are displayed grouped by card, rather than rendering "Nothing to show".

bhomvratrai-glitch avatar Oct 26 '26 10:10 bhomvratrai-glitch

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Oct 26 '26 10:10 melvin-bot[bot]

Proposal Update: Full Working Fix Verified & Branch Pushed

We have implemented and verified the fix on branch: bhomvratrai-glitch:fix/104831-card-accruals-empty-feed-query Commit: 1f275885

Summary of Changes

  1. src/libs/SearchSuggestionUtils.ts:
    • For both UNAPPROVED_CARD and STATEMENTS, replaced the fallback [''] with undefined so that when a specific feed ID is not yet available/resolved, the query searches card expenses across all eligible card feeds without appending an invalid feed:"" filter.
  2. src/libs/SearchQueryUtils.ts:
    • In buildQueryStringFromFilterFormValues, added .filter((value) => value.trim().length > 0) on array filter values to guarantee that empty string tokens are never serialized into the query string.

Ready to open the PR immediately upon milestone assignment!

bhomvratrai-glitch avatar Oct 26 '26 10:10 bhomvratrai-glitch

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

melvin-bot[bot] avatar Oct 26 '26 21:10 melvin-bot[bot]

Not overdue

FitseTLT avatar Oct 26 '26 22:10 FitseTLT

Proposal

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

When an admin opens Spend > Card accruals, the page displays an empty state even when unapproved card expenses exist on an eligible workspace card feed (as reproduced in #104831 (comment); separate from the backend domain-feed access gap tracked in Expensify/Expensify#662387).

What is the root cause of that problem?

On the App side, Card accruals (CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD) drops eligible card feeds in four places:

  1. Tab visibility is multi-workspace, while the query picks a single feed: In src/libs/SearchUIUtils.ts#L916, shouldShowUnapprovedCardSuggestion becomes true if any paid workspace where the user is an admin, auditor, or cardAdmin has approvals enabled (approvalMode !== OPTIONAL) and at least one card feed exists. However, getSuggestedSearches builds UNAPPROVED_CARD from a single ID:

    const unapprovedCardFeedID = activeExpensifyCardFeedID ?? defaultFeedID;
    

    When the active/default workspace has its own Expensify Card or company card feed with zero unapproved spend (e.g., Zed Feed), UNAPPROVED_CARD filters strictly to that one feed and hides unapproved card expenses on the admin's other eligible workspace feeds (e.g., Alpha Feed), or even on a second card feed within the same workspace.

  2. cardFeedsByPolicy drops configured CSV (ccupload*) feeds whose card list is not yet cached in Onyx: In src/hooks/useCardFeedsForDisplay.ts#L114, getCardFeedsForDisplayPerPolicy(allFeeds, translate, feedKeysWithCards, allPolicies) forwards feedKeysWithCards into getOriginalCompanyFeeds. Once any card list is hydrated in Onyx (feedKeysWithCards is defined), lines 999-1002 filter out "gray zone" feeds (!isCustomFeed(key) && !isDirectFeed(key), which includes CSV upload feeds like ccupload1) whenever cards_<fundID>_<feed> has not been opened/fetched yet in that session.

  3. Unresolved feed fallback [''] emits a bare feed: token that corrupts status:: In src/libs/SearchSuggestionUtils.ts#L344-L349 (and STATEMENTS at line 298), when no feed ID has resolved yet, passing feed: [''] causes buildQueryStringFromFilterFormValues to emit a bare feed: token (feed: status:unreported,drafts,outstanding), which the search parser consumes as literal feed names instead of status filters.

  4. Saved nvp_searchFilters.unapprovedCard keeps the old auto-generated single-feed query across visits: In src/libs/SearchQueryUtils.ts#L3729-L3751, getValidLastQuery returns lastQuery whenever its filter keys match defaultQueryJSON. An existing unapprovedCard entry saved with a single auto-derived feed:<singleFeed> continues to override the updated multi-feed default query until the user manually resets filters.

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

  1. Share one policy-eligibility helper (src/libs/SearchUIUtils.ts / src/libs/PolicyUtils.ts): Extract isPolicyEligibleForCardAccruals(policy) (isPaidGroupPolicy(policy) && (ADMIN || AUDITOR || CARD_ADMIN) && approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL && pendingAction !== DELETE) and reuse it in both getSuggestedSearchesVisibility and feed collection so tab visibility and default feed scope stay in lockstep. (Note on scope: if product decides in #104831 (comment) to scope only to the default workspace rather than all eligible workspaces, the same helper scopes to activePolicy while still including all Expensify Card + company/CSV feeds on that workspace.)

  2. Collect all eligible Expensify Card + ungated company/CSV feeds in src/hooks/useCardFeedsForDisplay.ts#L114-L130:

    • Build cardAccrualsFeedsByPolicy = getCardFeedsForDisplayPerPolicy(allFeeds, translate, undefined, allPolicies) (passing undefined for feedKeysWithCards so configured CSV/company feeds in CardFeedUtils.ts#L364-L383 are included even before cards_<fundID>_<feed> is hydrated, while keeping cardFeedsByPolicy unchanged for display pickers).
    • For each policy passing isPolicyEligibleForCardAccruals (ordered with activePolicyID first, then deterministically by policy/feed ID), collect its configured Expensify Card feed ID (reusing getActiveExpensifyCardFeedID precedence) and its cardAccrualsFeedsByPolicy[policyID] feed IDs into a deduplicated cardAccrualsFeedIDs: string[].
    • Pass cardAccrualsFeedIDs into getSuggestedSearches from both src/components/Search/SearchQueryProvider.tsx#L71-L76 and src/hooks/useSearchTypeMenuSections.ts#L69-L126 -> createTypeMenuSections.
  3. Pass cardAccrualsFeedIDs into UNAPPROVED_CARD and eliminate bare feed: tokens (src/libs/SearchSuggestionUtils.ts & src/libs/SearchQueryUtils.ts):

    • In getSuggestedSearches and UNAPPROVED_CARD, accept cardAccrualsFeedIDs?: string[], resolve const resolvedCardAccrualsFeeds = cardAccrualsFeedIDs?.length ? cardAccrualsFeedIDs : (unapprovedCardFeedID ? [unapprovedCardFeedID] : []), and spread ...(resolvedCardAccrualsFeeds.length > 0 && {feed: resolvedCardAccrualsFeeds}) (doing the same for STATEMENTS when defaultFeedID is undefined).
    • In buildQueryStringFromFilterFormValues, filter out empty/whitespace strings (filterValue.filter((v) => v.trim().length > 0)) so an empty array element can never emit a bare feed: prefix.
  4. Refresh stale single-feed defaults in getValidLastQuery: When searchKey === CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD, if lastQueryJSON has a positive single-feed filter that is a strict subset of defaultQueryJSON's feed list and matches the old auto-derived feed (activeExpensifyCardFeedID ?? defaultFeedID), replace feed with defaultQueryJSON's feed filter while keeping non-feed filters (date, sortBy, sortOrder, negative exclusions) intact.

What alternative solutions did you explore? (Optional)

  • Building the feed list from cardFeedsByPolicy directly: cardFeedsByPolicy passes feedKeysWithCards into getOriginalCompanyFeeds, which silently drops configured CSV (ccupload*) feeds on non-default workspaces whenever another workspace's card list is already cached in Onyx. Passing undefined for feedKeysWithCards in the accruals scope avoids that cache-dependent bug (verified in the After video below by clearing cards_23663815_ccupload1 from OnyxDB before opening Card accruals).
  • Omitting feed: completely on UNAPPROVED_CARD: Unscoped groupBy:card can pull in personal/unrelated card transactions; scoping explicitly to cardAccrualsFeedIDs preserves the intended workspace card boundary.

Demo (Before / After)

Test setup (staging.new.expensify.com): Admin of two Control workspaces with approvals enabled — default workspace has Zed Feed (0 unapproved expenses), second workspace has Alpha Feed (4 unapproved card expenses totaling TRY 13,106.88, with cards_23663815_ccupload1 cleared from OnyxDB and Zed Feed previously cached in nvp_searchFilters.unapprovedCard).

Before (main): Opening Spend > Card accruals queries only feed:23663851_ccupload1 (Feed: Zed Feed) and displays "No expenses to approve".

https://github.com/user-attachments/assets/9af11dce-81a1-49a2-89c9-e017284c3d23

After (with fix): Opening Spend > Card accruals (without pressing Reset) automatically resolves Feed: Alpha Feed, Zed Feed (feed:23663851_ccupload1,23663815_ccupload1) and displays all 4 unapproved card expenses (TRY 13,106.88).

https://github.com/user-attachments/assets/6aa03016-7d83-4e59-9966-cc551a087205

Enes2553 avatar Oct 28 '26 17:10 Enes2553

Hi @FitseTLT, friendly follow-up on this!

I have the verified surgical fix pushed to a clean branch: 👉 Compare Diff

It ensures that when unapprovedExpenses exist, the card accruals query parameters are properly sanitized and empty feed filters are omitted. Fully tested and ready for review!

bhomvratrai-glitch avatar Oct 29 '26 00:10 bhomvratrai-glitch

REviewing soon

FitseTLT avatar Oct 29 '26 16:10 FitseTLT

Will review tomorrow

FitseTLT avatar Nov 03 '26 09:11 FitseTLT