Skip to content

Commit 916a169

Browse files
committed
refactor logics
1 parent ece90a5 commit 916a169

2 files changed

Lines changed: 7 additions & 14 deletions

File tree

src/components/Search/FilterDropdowns/UserSelectPopup.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,7 @@ function UserSelectPopup({value, closeOverlay, onChange}: UserSelectPopupProps)
124124
};
125125
});
126126

127-
const userOptions =
128-
filteredOptions.currentUserOption && !filteredOptions.personalDetails.find((personalDetail) => personalDetail.accountID === accountID)
129-
? [
130-
{
131-
...filteredOptions.currentUserOption,
132-
isSelected: selectedOptions.some((selectedOption) => selectedOption.accountID === filteredOptions.currentUserOption?.accountID),
133-
},
134-
]
135-
: [];
136-
137-
return [...userOptions, ...personalDetailList, ...recentReportsList];
127+
return [...personalDetailList, ...recentReportsList];
138128
}, [filteredOptions, selectedOptions, accountID, selectedAccountIDs]);
139129

140130
const {sections, headerMessage} = useMemo(() => {

src/libs/OptionsListUtils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ type GetValidReportsReturnTypeCombined = {
243243

244244
type GetOptionsConfig = {
245245
excludeLogins?: Record<string, boolean>;
246+
includeCurrentUser?: boolean;
246247
includeRecentReports?: boolean;
247248
includeSelectedOptions?: boolean;
248249
recentAttendees?: Option[];
@@ -251,7 +252,6 @@ type GetOptionsConfig = {
251252
searchString?: string;
252253
maxElements?: number;
253254
includeUserToInvite?: boolean;
254-
includeCurrentUser?: boolean;
255255
} & GetValidReportsConfig;
256256

257257
type GetUserToInviteConfig = {
@@ -2360,7 +2360,7 @@ function formatSectionsFromSearchTerm(
23602360
// This will add them to the list of options, deduping them if they already exist in the other lists
23612361
const selectedParticipantsWithoutDetails = selectedOptions.filter((participant) => {
23622362
const accountID = participant.accountID ?? null;
2363-
const searchTerms = currentUserAccountID === accountID ? getCurrentUserSearchTerms(participant) : getPersonalDetailSearchTerms(participant);
2363+
const searchTerms = getPersonalDetailSearchTerms(participant);
23642364
const isPartOfSearchTerm = searchTerms.join(' ').toLowerCase().includes(cleanSearchTerm);
23652365
const isReportInRecentReports = filteredRecentReports.some((report) => report.accountID === accountID) || filteredWorkspaceChats.some((report) => report.accountID === accountID);
23662366
const isReportInPersonalDetails = filteredPersonalDetails.some((personalDetail) => personalDetail.accountID === accountID);
@@ -2396,10 +2396,13 @@ function getFirstKeyForList(data?: Option[] | null) {
23962396
}
23972397

23982398
function getPersonalDetailSearchTerms(item: Partial<OptionData>) {
2399+
if (item.accountID === currentUserAccountID) {
2400+
return getCurrentUserSearchTerms(item);
2401+
}
23992402
return [item.participantsList?.[0]?.displayName ?? '', item.login ?? '', item.login?.replace(CONST.EMAIL_SEARCH_REGEX, '') ?? ''];
24002403
}
24012404

2402-
function getCurrentUserSearchTerms(item: OptionData) {
2405+
function getCurrentUserSearchTerms(item: Partial<OptionData>) {
24032406
return [item.text ?? '', item.login ?? '', item.login?.replace(CONST.EMAIL_SEARCH_REGEX, '') ?? '', translateLocal('common.you'), translateLocal('common.me')];
24042407
}
24052408

0 commit comments

Comments
 (0)