Skip to content

82304: Search - The workspace with the same name is not displayed in the autocomplete - #82784

Merged
MariaHCD merged 18 commits into
Expensify:mainfrom
abbasifaizan70:82304
Apr 20, 2026
Merged

MariaHCD merged 18 commits into
Expensify:mainfrom
abbasifaizan70:82304

Conversation

@abbasifaizan70

@abbasifaizan70 abbasifaizan70 commented Feb 18, 2026 •

Copy link
Copy Markdown
Contributor

Search - The workspace with the same name is not displayed in the autocomplete

Explanation of Change

Fixes Reports search so multiple workspaces that share the same name can all be picked from workspace: autocomplete by storing each choice under an index-based substitution key (policyID:Name, policyID:Name:1, …) instead of one key per name. It also keeps substitutions in sync when the query is edited (e.g. removing a duplicate) by remapping ordered IDs and by always applying the updated substitution map in the page header, including when it becomes empty.

Fixed Issues

$ #82304
PROPOSAL: #82304 (comment)

Tests

  1. Open the app.
  2. Create two workspaces with the same name.
  3. Go to the Reports tab.
  4. In search, type workspace: and verify the autocomplete list appears.
  5. Select one workspace and confirm the results update.
  6. Add a comma after the selected workspace.
  7. Verify the second workspace (with the same name) appears in the autocomplete list.
  • Verify that no errors appear in the JS console

Offline tests

Same as tests.

QA Steps

Same as tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2026-04-07.at.8.28.22.PM.mov
Android: mWeb Chrome
Screen.Recording.2026-04-07.at.8.18.41.PM.mov
iOS: Native
Screen.Recording.2026-04-07.at.8.13.18.PM.mov
iOS: mWeb Safari
Screen.Recording.2026-04-07.at.8.16.16.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2026-04-01.at.5.03.09.AM.mov

Search - The workspace with the same name is not displayed in the autocomplete
@codecov

codecov Bot commented Feb 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/components/Search/SearchAutocompleteList.tsx 89.47% <ø> (ø)
.../Search/SearchPageHeader/SearchPageInputNarrow.tsx 76.92% <ø> (ø)
...ts/Search/SearchPageHeader/SearchPageInputWide.tsx 0.00% <ø> (ø)
...rc/components/Search/SearchRouter/SearchRouter.tsx 44.77% <ø> (+0.65%) ⬆️
...nents/Search/SearchRouter/buildSubstitutionsMap.ts 100.00% <100.00%> (ø)
...hRouter/getAutocompleteSelectionSubstitutionKey.ts 100.00% <100.00%> (ø)
.../Search/SearchRouter/getUpdatedSubstitutionsMap.ts 100.00% <100.00%> (ø)
src/hooks/useAutocompleteSuggestions.ts 76.57% <100.00%> (+3.24%) ⬆️
...nts/Search/SearchPageHeader/useSearchPageInput.tsx 62.85% <0.00%> (+1.74%) ⬆️
...s/Search/SearchRouter/getQueryWithSubstitutions.ts 96.66% <93.33%> (-3.34%) ⬇️
... and 1 more
... and 10 files with indirect coverage changes

@abbasifaizan70
abbasifaizan70 marked this pull request as ready for review April 7, 2026 15:42
@abbasifaizan70
abbasifaizan70 requested review from a team as code owners April 7, 2026 15:42
@melvin-bot
melvin-bot Bot requested review from JmillsExpensify and aimane-chnaif and removed request for a team April 7, 2026 15:42
@melvin-bot

melvin-bot Bot commented Apr 7, 2026

Copy link
Copy Markdown

@aimane-chnaif Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team April 7, 2026 15:42

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a1073b768

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

JmillsExpensify
JmillsExpensify previously approved these changes Apr 8, 2026

@JmillsExpensify JmillsExpensify left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MelvinBot

Copy link
Copy Markdown
Contributor

PR Review

The approach is sound — using index-based substitution keys to disambiguate workspaces (and potentially other entities) that share the same display name is a clean solution. A few items to address:

1. Duplicated substitution-key logic — extract to a shared helper

The 8-line block that parses the query, counts same-key ranges, and builds the substitution key is copy-pasted identically between SearchRouter.tsx (~L282-290) and SearchPageHeaderInput.tsx (~L233-241). Meanwhile, getSubstitutionMapKeyWithIndex already exists and does the key formatting. Consider extracting the full "compute substitution key for the just-selected item" logic into a single utility (e.g. in getQueryWithSubstitutions.ts) and calling it from both files.

2. Unsafe as cast on parser result

Both files cast parseSearchQuery(newSearchQuery) with:

const parsed = parseSearchQuery(newSearchQuery) as {ranges: Array<{key: string; value: string}>};

If the parser ever returns undefined or a different shape, this will crash at runtime. Use the parser's actual return type or add a guard (e.g. parsed?.ranges ?? []).

3. Missing unit tests for the new indexing behavior

The existing tests in getQueryWithSubstitutionsTest.ts and getUpdatedSubstitutionsMapTest.ts don't cover the duplicate-name scenario that this PR fixes. Please add at least:

  • getQueryWithSubstitutions: a test with two identical filter values mapped to different IDs (e.g. workspace:"My WS",workspace:"My WS" with keys policyID:My WS → id1 and policyID:My WS:1 → id2)
  • getUpdatedSubstitutionsMap: a test verifying that removing one of two duplicate-name filters correctly preserves the remaining key and re-indexes

4. Minor: index <= 0 vs index === 0

In the inline logic (SearchRouter.tsx:289, SearchPageHeaderInput.tsx:240), the guard is index <= 0, but getSubstitutionMapKeyWithIndex uses index === 0. The <= 0 version silently swallows a -1 index (which would indicate a bug). Consider using === 0 consistently and letting an unexpected -1 surface as a visible problem rather than hiding it.


Everything else (the useAutocompleteSuggestions filtering by ID instead of name, the backward-compatible fallback in getQueryWithSubstitutions, passing autocompleteSubstitutions down) looks good. CI is green (only the reviewer checklist is failing, which is expected).

Comment thread src/hooks/useAutocompleteSuggestions.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c02a00d48

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@abbasifaizan70

Copy link
Copy Markdown
Contributor Author

@aimane-chnaif Refactored code and added unit test cases. Thanks

@aimane-chnaif

Copy link
Copy Markdown
Contributor

Are all AI reviews addressed?

@abbasifaizan70

Copy link
Copy Markdown
Contributor Author

@aimane-chnaif, yes, all AI feedback is addressed. CI is failing because someone else made changes. I'll update it in the main.

@abbasifaizan70

Copy link
Copy Markdown
Contributor Author

@aimane-chnaif PR is ready for review. Thanks.

@aimane-chnaif

aimane-chnaif commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
android.mov
Android: mWeb Chrome
iOS: HybridApp
ios.mov
iOS: mWeb Safari
msafari.mov
MacOS: Chrome / Safari
web.mov

@aimane-chnaif

Copy link
Copy Markdown
Contributor

Please merge main

@MelvinBot

Copy link
Copy Markdown
Contributor

Code Review

The approach of using indexed substitution keys (policyID:Name, policyID:Name:1, ...) to disambiguate same-name workspaces is sound, and the fallback-to-base-key logic handles backward compatibility well. Tests are thorough. A few items to address:

Issues

1. Unsafe type cast in getAutocompleteSelectionSubstitutionKey.ts

const parsed = parseSearchQuery(newSearchQuery) as {ranges: Array<{key: string; value: string}>};

This casts away the parser's return type. Use the actual SearchAutocompleteQueryRange type (or the parser's declared return type) instead of an inline anonymous type. If the parser can return undefined for ranges, handle that explicitly rather than casting.

2. Duplicated substitution-update block still exists across two files

aimane-chnaif flagged this. The key computation was extracted into getAutocompleteSelectionSubstitutionKey, but the full pattern — compute key, spread substitutions, call setter — is still duplicated verbatim in SearchRouter.tsx:281-286 and SearchPageHeaderInput.tsx:232-237. Consider extracting the entire block (e.g., a addSubstitution(query, fieldKey, item, currentSubs, setter) helper) so both call sites are one-liners.

3. ID-based exclusion only covers workspace filter

In useAutocompleteSuggestions.ts, the new alreadySelectedPolicyIds logic only applies to the policyID autocomplete key. Other filters that could theoretically have duplicate display names (e.g., categories, tags) still use name-based exclusion. This is fine for the scope of the linked issue, but worth a brief code comment noting the intentional scope limit so future maintainers don't wonder why it's asymmetric.

Nit

In getAutocompleteSelectionSubstitutionKey.ts, the function re-parses the entire query string just to count occurrences. The caller (SearchRouter / SearchPageHeaderInput) likely already has parsed ranges available or could pass the count. Not blocking, but worth considering if this path becomes hot.

@aimane-chnaif

Copy link
Copy Markdown
Contributor
  1. Unsafe type cast in getAutocompleteSelectionSubstitutionKey.ts
  2. Duplicated substitution-update block still exists across two files
    Nit

Can you address?

text: value,
}));
}
case CONST.SEARCH.SYNTAX_FILTER_KEYS.POLICY_ID: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot can you confirm all other filter logic is not affected by this PR?
Only CONST.SEARCH.SYNTAX_FILTER_KEYS.POLICY_ID should affect the production behavior.

@MelvinBot

Copy link
Copy Markdown
Contributor

Not entirely. The autocomplete suggestion filtering change is scoped to POLICY_ID only (useAutocompleteSuggestions.ts:411-444). However, the indexed substitution key infrastructure (baseKey:1, baseKey:2, ...) applies to all filter types:

  • buildSubstitutionsMap.ts — the substitutionKeyOccurrences counter runs across all ranges (taxRate branch + general branch covering FROM, TO, TAG, CARD_ID, etc.)
  • getQueryWithSubstitutions.ts — keyValueCount/rangeIndices indexing applies to all parsed ranges
  • getUpdatedSubstitutionsMap.ts — same generic indexing for all filter types
  • getAutocompleteSelectionSubstitutionKey — called for all filter types at selection time (SearchRouter.tsx:282, SearchPageHeaderInput.tsx:233)

This is backward-compatible when a filter+value appears only once (index 0 produces the same key as before). But if two different filter values resolve to the same display name (e.g., two categories named "Travel"), they now get separate keys instead of the second silently overwriting the first. That's arguably a fix, but it is a behavioral change beyond POLICY_ID.

What would it take to scope the infrastructure to POLICY_ID only?

The indexed-key logic in buildSubstitutionsMap, getQueryWithSubstitutions, and getUpdatedSubstitutionsMap would need to conditionally apply indexing only when range.key === CONST.SEARCH.SYNTAX_FILTER_KEYS.POLICY_ID and fall back to the old single-key behavior for all other filter types. Similarly, the getAutocompleteSelectionSubstitutionKey call in SearchRouter.tsx and SearchPageHeaderInput.tsx would need a guard on fieldKey.

That said, the generic approach is safe due to the index-0 fallback, and will naturally extend to other filters if they ever need duplicate-name support.

@abbasifaizan70

Copy link
Copy Markdown
Contributor Author
  1. Unsafe type cast in getAutocompleteSelectionSubstitutionKey.ts
  2. Duplicated substitution-update block still exists across two files
    Nit

Can you address?

@aimane-chnaif I fixed Melvin's feedback. Can u check again? Thanks

@melvin-bot
melvin-bot Bot requested a review from MariaHCD April 14, 2026 18:33
@MelvinBot

Copy link
Copy Markdown
Contributor

PR Review

Summary: This PR fixes workspace search autocomplete so multiple workspaces sharing the same name can all be selected. It introduces index-based substitution keys (policyID:Name, policyID:Name:1, …) instead of a single key per display name. The approach is sound and well-tested.

Overall: Looks good. One correctness concern worth discussing, plus a few minor items.


Correctness concern: positional remapping on deletion of non-last duplicate

In getUpdatedSubstitutionsMap, when the user removes a duplicate workspace from the query, indices are reassigned based on position in the remaining text. Since all duplicates have identical display names, the function can't tell which one was removed.

Example: three workspaces named "Test Workspace" → keys map to policyA (index 0), policyB (index 1), policyC (index 2). If the user removes the first occurrence from the query text, the two remaining occurrences get indices 0 and 1, mapping to policyA and policyB — but the user intended to keep policyB and policyC.

This is inherent to positional indexing with identical display values, and there may not be a clean fix without tracking IDs in the query itself. Since the previous behavior was that only one workspace could be selected per name, this is still a net improvement. But it's worth calling out — consider whether adding a brief code comment noting this limitation would help future readers.

Minor items

  1. getAutocompleteSelectionSubstitutionKey re-parses the full query (parseSearchQuery(newSearchQuery)) on every autocomplete selection. The callers already have access to parsed data in some cases. Not a blocker, but worth noting if autocomplete latency becomes an issue.

  2. Duplicate index-counting pattern — The Map<string, number> counter + getSubstitutionMapKeyWithIndex pattern appears in four places (buildSubstitutionsMap, getQueryWithSubstitutions, getUpdatedSubstitutionsMap, useAutocompleteSuggestions). Consider extracting a small helper like assignRangeIndices(ranges) to reduce repetition and keep the logic consistent. Not required for this PR but would reduce maintenance surface.

  3. getSubstitutionForOccurrence is unexported but only used in one file — it's fine as-is, just noting it's effectively private to getQueryWithSubstitutions.ts.

Tests

Good coverage — tests for all new utilities and the key integration point in useAutocompleteSuggestions. The backward-compatibility test (when duplicate values have only base substitution key, all duplicates still substitute) is a nice touch.


Next Steps: Reply with @MelvinBot <your feedback> to discuss or refine.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd0eed3b1d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

* Index 0 uses the base key for backward compatibility; index > 0 uses baseKey:index.
*/
const getSubstitutionMapKeyWithIndex = (filterKey: SearchFilterKey, value: string, index: number) =>
index === 0 ? getSubstitutionMapKey(filterKey, value) : `${getSubstitutionMapKey(filterKey, value)}:${index}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Escape indexed substitution keys before appending suffix

getSubstitutionMapKeyWithIndex() appends :${index} directly to the serialized key, which makes indexed keys collide with legitimate values that already end in :<number>. For example, selecting workspace:"Foo" twice creates policyID:Foo:1, which is identical to the base key for a workspace literally named Foo:1; the later write overwrites the earlier mapping and getQueryWithSubstitutions() can submit the wrong policy IDs. Please make indexed keys unambiguous (e.g., structured encoding or a delimiter that cannot appear in values).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abbasifaizan70 @aimane-chnaif could you please evaluate this comment?

@abbasifaizan70 abbasifaizan70 Apr 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already fix above in previous comments of codex. @MariaHCD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abbasifaizan70 could you clarify how this was already addressed/fixed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MariaHCD I tried the fallback Claude suggested (indexedKey ?? baseKey for duplicate occurrences), but it causes a correctness regression in real flow: after removing one same-name workspace and adding it back, the duplicate mapping becomes ambiguous, and an already-selected workspace can show again in suggestions.

For duplicate values, each occurrence must stay position-specific (base, :1, :2, ...). If we let non-zero indices fall back to the base key, multiple occurrences can resolve to the same policy ID, which breaks selected-ID exclusion.
So we only allow base-key fallback for the first occurrence (index === 0) and require indexed keys for duplicates. This keeps mapping deterministic and avoids the reappearing-duplicate issue.

@MariaHCD

Copy link
Copy Markdown
Contributor

@abbasifaizan70 could you kindly merge main here to fix the merge conflicts? Thanks!

@abbasifaizan70

Copy link
Copy Markdown
Contributor Author

@MariaHCD Updated with main branch.

@MariaHCD
MariaHCD merged commit dfad59b into Expensify:main Apr 20, 2026
32 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 @MariaHCD has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/MariaHCD in version: 9.3.61-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@MelvinBot

Copy link
Copy Markdown
Contributor

I reviewed the changes in this PR against the help site articles under App/docs/articles.

No help site changes are required.

This PR is a bug fix for the search autocomplete — it corrects how workspaces with duplicate names are handled in the workspace: filter's autocomplete suggestions by using index-based substitution keys. No new features, filters, UI elements, or user-facing behaviors are introduced.

The existing help site articles (Using Search on the Reports Page and Using search operators) already document the workspace: filter and autocomplete behavior adequately.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/marcaaron in version: 9.3.61-4 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants