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

[Create Expense - Clean up] #55016 Follow up - Performance improvements #55769

Merged
Changes from 3 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 @@ -193,15 +193,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;
} & GetValidReportsConfig;

type GetUserToInviteConfig = {
Expand Down Expand Up @@ -1242,9 +1248,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 @@ -1262,11 +1267,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 @@ -1398,10 +1406,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 @@ -1440,15 +1458,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 @@ -1494,22 +1519,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);
}

return {
personalDetails: personalDetailsOptions,
recentReports: recentReportOptions,
Expand Down
Loading