Skip to content
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

Hide contact option if we don't include P2P option #42142

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1675,7 +1674,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 @@ -1859,7 +1857,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) : [];
Copy link
Contributor

Choose a reason for hiding this comment

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

based on your comment shouldn't we cleanup includePersonalDetails if it's redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@getusha I updated to cleanup includePersonalDetails.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice I like that.

NAB: We could remove the variable havingLoginPersonalDetails since its unnecessary.

let allPersonalDetailsOptions = havingLoginPersonalDetails;

if (sortPersonalDetailsByAlphaAsc) {
Expand Down Expand Up @@ -1945,22 +1943,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 @@ -2018,7 +2014,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 @@ -2039,7 +2035,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 @@ -2096,7 +2092,6 @@ function getFilteredOptions(
includePolicyReportFieldOptions = false,
policyReportFieldOptions: string[] = [],
recentlyUsedPolicyReportFieldOptions: string[] = [],
includePersonalDetails = true,
maxRecentReportsToShow = 5,
) {
return getOptions(
Expand All @@ -2106,7 +2101,6 @@ function getFilteredOptions(
searchInputValue: searchValue.trim(),
selectedOptions,
includeRecentReports: true,
includePersonalDetails,
maxRecentReportsToShow,
excludeLogins,
includeOwnedWorkspaceChats,
Expand Down Expand Up @@ -2152,7 +2146,6 @@ function getShareDestinationOptions(
maxRecentReportsToShow: 0, // Unlimited
includeRecentReports: true,
includeMultipleParticipantReports: true,
includePersonalDetails: false,
showChatPreviewLine: true,
forcePolicyNamePreview: true,
includeThreads: true,
Expand Down Expand Up @@ -2209,7 +2202,7 @@ function getMemberInviteOptions(
{
betas,
searchInputValue: searchValue.trim(),
includePersonalDetails: true,
includeP2P: true,
excludeLogins,
sortPersonalDetailsByAlphaAsc: true,
includeSelectedOptions,
Expand Down
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
Loading