Skip to content
Merged
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
61 changes: 35 additions & 26 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,21 @@ type GetValidReportsConfig = {
includeInvoiceRooms?: boolean;
includeDomainEmail?: boolean;
loginsToExclude?: Record<string, boolean>;
shouldSeparateWorkspaceChat?: boolean;
shouldSeparateSelfDMChat?: boolean;
} & GetValidOptionsSharedConfig;

type GetValidReportsReturnTypeCombined = {
selfDMOption: OptionData | undefined;
workspaceOptions: OptionData[];
recentReports: OptionData[];
};

type GetOptionsConfig = {
excludeLogins?: Record<string, boolean>;
includeRecentReports?: boolean;
includeSelectedOptions?: boolean;
recentAttendees?: Attendee[];
shouldSeparateWorkspaceChat?: boolean;
shouldSeparateSelfDMChat?: boolean;
excludeHiddenReports?: boolean;
} & GetValidReportsConfig;

Expand Down Expand Up @@ -1246,9 +1252,8 @@ function getUserToInviteOption({
return userToInvite;
}

function getValidReports(
reports: OptionList['reports'],
{
function getValidReports(reports: OptionList['reports'], config: GetValidReportsConfig): GetValidReportsReturnTypeCombined {
const {
betas = [],
includeMultipleParticipantReports = false,
showChatPreviewLine = false,
Expand All @@ -1266,11 +1271,14 @@ function getValidReports(
includeDomainEmail = false,
shouldBoldTitleByDefault = true,
loginsToExclude = {},
}: GetValidReportsConfig,
) {
shouldSeparateSelfDMChat,
shouldSeparateWorkspaceChat,
} = config;
const topmostReportId = Navigation.getTopmostReportId();

const validReportOptions: OptionData[] = [];
const workspaceChats: OptionData[] = [];
let selfDMChat: OptionData | undefined;
const preferRecentExpenseReports = action === CONST.IOU.ACTION.CREATE;

for (let i = 0; i < reports.length; i++) {
Expand Down Expand Up @@ -1402,10 +1410,20 @@ function getValidReports(
lastIOUCreationDate,
};

validReportOptions.push(newReportOption);
if (shouldSeparateWorkspaceChat && newReportOption.isOwnPolicyExpenseChat && !newReportOption.private_isArchived) {
workspaceChats.push(newReportOption);
} else if (shouldSeparateSelfDMChat && newReportOption.isSelfDM) {
selfDMChat = newReportOption;
} else {
validReportOptions.push(newReportOption);
}
}

return validReportOptions;
return {
recentReports: validReportOptions,
workspaceOptions: workspaceChats,
selfDMOption: selfDMChat,
};
}

/**
Expand Down Expand Up @@ -1445,15 +1463,22 @@ function getValidOptions(

// Get valid recent reports:
let recentReportOptions: OptionData[] = [];
let workspaceChats: OptionData[] = [];
let selfDMChat: OptionData | undefined;
if (includeRecentReports) {
recentReportOptions = getValidReports(options.reports, {
const {recentReports, workspaceOptions, selfDMOption} = getValidReports(options.reports, {
...getValidReportsConfig,
includeP2P,
includeDomainEmail,
selectedOptions,
loginsToExclude,
shouldBoldTitleByDefault,
shouldSeparateSelfDMChat,
shouldSeparateWorkspaceChat,
});
recentReportOptions = recentReports;
workspaceChats = workspaceOptions;
selfDMChat = selfDMOption;
} else if (recentAttendees && recentAttendees?.length > 0) {
recentAttendees.filter((attendee) => {
const login = attendee.login ?? attendee.displayName;
Expand Down Expand Up @@ -1499,22 +1524,6 @@ function getValidOptions(
}
}

let workspaceChats: OptionData[] = [];

if (shouldSeparateWorkspaceChat) {
workspaceChats = recentReportOptions.filter((option) => option.isOwnPolicyExpenseChat && !option.private_isArchived);
}

let selfDMChat: OptionData | undefined;

if (shouldSeparateWorkspaceChat) {
recentReportOptions = recentReportOptions.filter((option) => !option.isPolicyExpenseChat);
}
if (shouldSeparateSelfDMChat) {
selfDMChat = recentReportOptions.find((option) => option.isSelfDM);
recentReportOptions = recentReportOptions.filter((option) => !option.isSelfDM);
}

if (excludeHiddenReports) {
recentReportOptions = recentReportOptions.filter((option) => option.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);
}
Expand Down
Loading