Repository navigation
[Payment due @eVoloshchak] Add Vendor filter to expense Search using workspace connections #104351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Beamanator
merged 6 commits into
Expensify:main
from
c3024:chaitanya/681919-reland-vendor-filter
Oct 26, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8fa9430
Revert "Merge pull request #103211 from c3024/chaitanya/revert-101309…
c3024 c65428c
List workspace vendors from connections in the Search Vendor filter
c3024 5f5317b
Let React Compiler memoize the vendor selector and document the vendo…
c3024 377252e
Resolve workspace names and keep unsynced selected vendors in the ven…
c3024 a73a406
Merge remote-tracking branch 'origin/main' into chaitanya/681919-rela…
c3024 63a66f9
Merge remote-tracking branch 'origin/main' into chaitanya/681919-rela…
c3024 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import type {Filter, SearchFilterCommonProps} from '@components/Search/types'; | ||
|
|
||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import usePermissions from '@hooks/usePermissions'; | ||
|
|
||
| import {getMatchingVendors, getVendorFeaturePolicyIDs} from '@libs/PolicyUtils'; | ||
| import {getAllPolicyValues, sortOptionsWithEmptyValue} from '@libs/SearchQueryUtils'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| import MultiSelect from './MultiSelect'; | ||
|
|
||
| type VendorSelectorProps = SearchFilterCommonProps<string[] | undefined> & { | ||
| policyID: Filter | undefined; | ||
| }; | ||
|
|
||
| function VendorSelector({value = [], policyID, selectionListTextInputStyle, selectionListStyle, autoFocus, footer, onChange}: VendorSelectorProps) { | ||
| const {translate, localeCompare} = useLocalize(); | ||
| const {isBetaEnabled} = usePermissions(); | ||
| const isVendorMatchingBetaEnabled = isBetaEnabled(CONST.BETAS.VENDOR_MATCHING); | ||
|
|
||
| const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); | ||
|
|
||
| // Uses the same synced vendors the expense Vendor field offers. | ||
| const vendorNamesByPolicyID = Object.fromEntries( | ||
| getVendorFeaturePolicyIDs(allPolicies, isVendorMatchingBetaEnabled).map((id) => [ | ||
| id, | ||
| getMatchingVendors(allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${id}`]).map((vendor) => vendor.name), | ||
| ]), | ||
| ); | ||
|
|
||
| const noVendorLabel = translate('search.noVendor'); | ||
| const selectedVendorItems = value.map((vendor) => { | ||
| if (vendor === CONST.SEARCH.VENDOR_EMPTY_VALUE) { | ||
| return {text: noVendorLabel, value: vendor}; | ||
| } | ||
| return {text: vendor, value: vendor}; | ||
| }); | ||
|
|
||
| // The workspace filter can hold workspace names as well as IDs, so it is resolved to the matching workspaces first. | ||
| const selectedPolicyIDs = policyID?.value?.length ? new Set(getAllPolicyValues(policyID, ONYXKEYS.COLLECTION.POLICY, allPolicies).map((policy) => policy.id)) : undefined; | ||
| const vendorItems = [{text: noVendorLabel, value: CONST.SEARCH.VENDOR_EMPTY_VALUE as string}]; | ||
| const uniqueVendorNames = new Set<string>( | ||
| Object.entries(vendorNamesByPolicyID) | ||
| .filter(([id]) => !selectedPolicyIDs || selectedPolicyIDs.has(id)) | ||
| .flatMap(([, vendorNames]) => vendorNames), | ||
| ); | ||
| vendorItems.push( | ||
| ...Array.from(uniqueVendorNames) | ||
| .filter(Boolean) | ||
| .map((vendorName) => ({text: vendorName, value: vendorName})) | ||
| .toSorted((a, b) => sortOptionsWithEmptyValue(a.text, b.text, localeCompare)), | ||
| ); | ||
|
|
||
| // Selected vendors that are not in the synced lists, such as a typed name or one from a workspace the filter leaves out, stay listed after "No vendor" so they can be deselected. | ||
| const vendorItemValues = new Set(vendorItems.map((item) => item.value)); | ||
| const missingSelectedVendorItems = selectedVendorItems.filter((item) => !vendorItemValues.has(item.value)).toSorted((a, b) => localeCompare(a.text, b.text)); | ||
| vendorItems.splice(1, 0, ...missingSelectedVendorItems); | ||
|
|
||
| return ( | ||
| <MultiSelect | ||
| value={selectedVendorItems} | ||
| items={vendorItems} | ||
| isSearchable={vendorItems.length >= CONST.STANDARD_LIST_ITEM_LIMIT} | ||
| autoFocus={autoFocus} | ||
| selectionListTextInputStyle={selectionListTextInputStyle} | ||
| selectionListStyle={selectionListStyle} | ||
| footer={footer} | ||
| onChange={(vendors) => onChange(vendors.map((vendor) => vendor.value))} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default VendorSelector; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.