Skip to content

Commit 90cc1ca

Browse files
committed
Introduce an opt-in shouldKeepSelectedInAvailableOptions prop in useSearchSelector to keep existing behavior in other flows
1 parent 9cff2d2 commit 90cc1ca

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/hooks/useSearchSelector.base.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ type UseSearchSelectorConfig = {
7979

8080
/** Whether to allow name-only options */
8181
shouldAllowNameOnlyOptions?: boolean;
82+
83+
/** Whether to keep selected options in availableOptions instead of filtering them out */
84+
shouldKeepSelectedInAvailableOptions?: boolean;
8285
};
8386

8487
type ContactState = {
@@ -170,6 +173,7 @@ function useSearchSelectorBase({
170173
includeSelfDM = false,
171174
recentAttendees,
172175
shouldAllowNameOnlyOptions = false,
176+
shouldKeepSelectedInAvailableOptions = false,
173177
}: UseSearchSelectorConfig): UseSearchSelectorReturn {
174178
const {options: defaultOptions, areOptionsInitialized} = useOptionsList({
175179
shouldInitialize,
@@ -352,18 +356,17 @@ function useSearchSelectorBase({
352356
: null,
353357
};
354358

355-
const isSingleSelect = selectionMode === CONST.SEARCH_SELECTOR.SELECTION_MODE_SINGLE;
356-
const filteredRecentReports = isSingleSelect ? searchOptions.recentReports : searchOptions.recentReports.filter((option) => !option.isSelected);
359+
const filteredRecentReports = shouldKeepSelectedInAvailableOptions ? searchOptions.recentReports : searchOptions.recentReports.filter((option) => !option.isSelected);
357360

358361
// Filter out people who appear in recent reports from personal details (recents take priority)
359362
const recentReportLogins = new Set(filteredRecentReports.map((option) => option.login).filter(Boolean));
360-
const filteredPersonalDetails = searchOptions.personalDetails.filter((option) => (isSingleSelect || !option.isSelected) && !recentReportLogins.has(option.login));
363+
const filteredPersonalDetails = searchOptions.personalDetails.filter((option) => (shouldKeepSelectedInAvailableOptions || !option.isSelected) && !recentReportLogins.has(option.login));
361364

362365
const availableOptions = {
363366
...searchOptions,
364367
personalDetails: filteredPersonalDetails,
365368
recentReports: filteredRecentReports,
366-
userToInvite: !isSingleSelect && searchOptions.userToInvite?.isSelected ? null : searchOptions.userToInvite,
369+
userToInvite: !shouldKeepSelectedInAvailableOptions && searchOptions.userToInvite?.isSelected ? null : searchOptions.userToInvite,
367370
};
368371

369372
/**

src/pages/settings/Security/AddDelegate/AddDelegatePage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function AddDelegatePage() {
4040
excludeLogins: {...CONST.EXPENSIFY_EMAILS_OBJECT, ...existingDelegates},
4141
includeRecentReports: true,
4242
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
43+
shouldKeepSelectedInAvailableOptions: true,
4344
});
4445

4546
const handleSelectRow = (option: OptionData) => {

0 commit comments

Comments
 (0)