Skip to content

Commit

Permalink
Merge pull request #42142 from nkdengineer/fix/40790
Browse files Browse the repository at this point in the history
Hide contact option if we don't include P2P option
  • Loading branch information
neil-marcellini authored Jun 5, 2024
2 parents 9b179ce + f213328 commit 4780624
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
41 changes: 17 additions & 24 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ type GetOptionsConfig = {
maxRecentReportsToShow?: number;
excludeLogins?: string[];
includeMultipleParticipantReports?: boolean;
includePersonalDetails?: boolean;
includeRecentReports?: boolean;
includeSelfDM?: boolean;
sortByReportTypeInSearch?: boolean;
Expand Down Expand Up @@ -1698,7 +1697,6 @@ function getOptions(
maxRecentReportsToShow = 0,
excludeLogins = [],
includeMultipleParticipantReports = false,
includePersonalDetails = false,
includeRecentReports = false,
// When sortByReportTypeInSearch flag is true, recentReports will include the personalDetails options as well.
sortByReportTypeInSearch = false,
Expand Down Expand Up @@ -1888,7 +1886,7 @@ function getOptions(
return option;
});

const havingLoginPersonalDetails = options.personalDetails.filter((detail) => !!detail?.login && !!detail.accountID && !detail?.isOptimisticPersonalDetail);
const havingLoginPersonalDetails = includeP2P ? options.personalDetails.filter((detail) => !!detail?.login && !!detail.accountID && !detail?.isOptimisticPersonalDetail) : [];
let allPersonalDetailsOptions = havingLoginPersonalDetails;

if (sortPersonalDetailsByAlphaAsc) {
Expand Down Expand Up @@ -1974,22 +1972,20 @@ function getOptions(
}
}

if (includePersonalDetails) {
const personalDetailsOptionsToExclude = [...optionsToExclude, {login: currentUserLogin}];
// Next loop over all personal details removing any that are selectedUsers or recentChats
allPersonalDetailsOptions.forEach((personalDetailOption) => {
if (personalDetailsOptionsToExclude.some((optionToExclude) => optionToExclude.login === personalDetailOption.login)) {
return;
}
const {searchText, participantsList, isChatRoom} = personalDetailOption;
const participantNames = getParticipantNames(participantsList);
if (searchValue && !isSearchStringMatch(searchValue, searchText, participantNames, isChatRoom)) {
return;
}
const personalDetailsOptionsToExclude = [...optionsToExclude, {login: currentUserLogin}];
// Next loop over all personal details removing any that are selectedUsers or recentChats
allPersonalDetailsOptions.forEach((personalDetailOption) => {
if (personalDetailsOptionsToExclude.some((optionToExclude) => optionToExclude.login === personalDetailOption.login)) {
return;
}
const {searchText, participantsList, isChatRoom} = personalDetailOption;
const participantNames = getParticipantNames(participantsList);
if (searchValue && !isSearchStringMatch(searchValue, searchText, participantNames, isChatRoom)) {
return;
}

personalDetailsOptions.push(personalDetailOption);
});
}
personalDetailsOptions.push(personalDetailOption);
});

let currentUserOption = allPersonalDetailsOptions.find((personalDetailsOption) => personalDetailsOption.login === currentUserLogin);
if (searchValue && currentUserOption && !isSearchStringMatch(searchValue, currentUserOption.searchText)) {
Expand Down Expand Up @@ -2047,7 +2043,7 @@ function getSearchOptions(options: OptionList, searchValue = '', betas: Beta[] =
maxRecentReportsToShow: 0, // Unlimited
sortByReportTypeInSearch: true,
showChatPreviewLine: true,
includePersonalDetails: true,
includeP2P: true,
forcePolicyNamePreview: true,
includeOwnedWorkspaceChats: true,
includeThreads: true,
Expand All @@ -2068,7 +2064,7 @@ function getShareLogOptions(options: OptionList, searchValue = '', betas: Beta[]
includeRecentReports: true,
includeMultipleParticipantReports: true,
sortByReportTypeInSearch: true,
includePersonalDetails: true,
includeP2P: true,
forcePolicyNamePreview: true,
includeOwnedWorkspaceChats: true,
includeSelfDM: true,
Expand Down Expand Up @@ -2125,7 +2121,6 @@ function getFilteredOptions(
includePolicyReportFieldOptions = false,
policyReportFieldOptions: string[] = [],
recentlyUsedPolicyReportFieldOptions: string[] = [],
includePersonalDetails = true,
maxRecentReportsToShow = 5,
) {
return getOptions(
Expand All @@ -2135,7 +2130,6 @@ function getFilteredOptions(
searchInputValue: searchValue.trim(),
selectedOptions,
includeRecentReports: true,
includePersonalDetails,
maxRecentReportsToShow,
excludeLogins,
includeOwnedWorkspaceChats,
Expand Down Expand Up @@ -2181,7 +2175,6 @@ function getShareDestinationOptions(
maxRecentReportsToShow: 0, // Unlimited
includeRecentReports: true,
includeMultipleParticipantReports: true,
includePersonalDetails: false,
showChatPreviewLine: true,
forcePolicyNamePreview: true,
includeThreads: true,
Expand Down Expand Up @@ -2238,7 +2231,7 @@ function getMemberInviteOptions(
{
betas,
searchInputValue: searchValue.trim(),
includePersonalDetails: true,
includeP2P: true,
excludeLogins,
sortPersonalDetailsByAlphaAsc: true,
includeSelectedOptions,
Expand Down
1 change: 0 additions & 1 deletion src/pages/iou/request/MoneyRequestParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ function MoneyRequestParticipantsSelector({participants = [], onFinish, onPartic
undefined,
undefined,
undefined,
!isCategorizeOrShareAction,
isCategorizeOrShareAction ? 0 : undefined,
);

Expand Down
3 changes: 1 addition & 2 deletions tests/unit/OptionsListUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ describe('OptionsListUtils', () => {
undefined,
undefined,
undefined,
false,
undefined,
undefined,
undefined,
Expand All @@ -491,8 +492,6 @@ describe('OptionsListUtils', () => {
undefined,
undefined,
undefined,
undefined,
false,
);

// Then no personal detail options will be returned
Expand Down

0 comments on commit 4780624

Please sign in to comment.