Skip to content
Draft
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
84 changes: 52 additions & 32 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,23 @@ type GetValidReportsConfig = {
includeInvoiceRooms?: boolean;
includeDomainEmail?: boolean;
optionsToExclude?: Array<Partial<OptionData>>;

// These two will change the return type
shouldSeparateWorkspaceChat?: boolean;
shouldSeparateSelfDMChat?: boolean;
} & GetValidOptionsSharedConfig;

type GetValidReportsReturnTypeCombined = {
selfDMOptions: OptionData[];
workspaceOptions: OptionData[];
recentReports: OptionData[];
};

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

type GetUserToInviteConfig = {
Expand Down Expand Up @@ -1245,7 +1253,26 @@ function getUserToInviteOption({

function getValidReports(
reports: OptionList['reports'],
{
config: GetValidReportsConfig & {shouldSeparateSelfDMChat: true; shouldSeparateWorkspaceChat: true},
): GetValidReportsReturnTypeCombined;

function getValidReports(
reports: OptionList['reports'],
config: GetValidReportsConfig & {shouldSeparateSelfDMChat: true; shouldSeparateWorkspaceChat?: false},
): Omit<GetValidReportsReturnTypeCombined, 'workspaceOptions'>;

function getValidReports(
reports: OptionList['reports'],
config: GetValidReportsConfig & {shouldSeparateSelfDMChat?: false; shouldSeparateWorkspaceChat: true},
): Omit<GetValidReportsReturnTypeCombined, 'selfDMOptions'>;

function getValidReports(reports: OptionList['reports'], config: GetValidReportsConfig & {shouldSeparateSelfDMChat?: false; shouldSeparateWorkspaceChat?: false}): OptionData[];

function getValidReports(
reports: OptionList['reports'],
config: GetValidReportsConfig,
): GetValidReportsReturnTypeCombined | Omit<GetValidReportsReturnTypeCombined, 'workspaceOptions'> | Omit<GetValidReportsReturnTypeCombined, 'selfDMOptions'> | OptionData[] {
const {
betas = [],
includeMultipleParticipantReports = false,
showChatPreviewLine = false,
Expand All @@ -1263,8 +1290,10 @@ function getValidReports(
includeDomainEmail = false,
shouldBoldTitleByDefault = true,
optionsToExclude = [],
}: GetValidReportsConfig,
) {
shouldSeparateSelfDMChat,
shouldSeparateWorkspaceChat,
} = config;

const topmostReportId = Navigation.getTopmostReportId();

const validReportOptions: OptionData[] = [];
Expand Down Expand Up @@ -1399,6 +1428,22 @@ function getValidReports(
lastIOUCreationDate,
};

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);
}

validReportOptions.push(newReportOption);
}

Expand All @@ -1410,16 +1455,7 @@ function getValidReports(
*/
function getValidOptions(
options: OptionList,
{
excludeLogins = [],
includeSelectedOptions = false,
includeRecentReports = true,
recentAttendees,
selectedOptions = [],
shouldSeparateSelfDMChat = false,
shouldSeparateWorkspaceChat = false,
...config
}: GetOptionsConfig = {},
{excludeLogins = [], includeSelectedOptions = false, includeRecentReports = true, recentAttendees, selectedOptions = [], ...config}: GetOptionsConfig = {},
): Options {
// Gather shared configs:
const optionsToExclude: Option[] = [{login: CONST.EMAIL.NOTIFICATIONS}];
Expand All @@ -1437,7 +1473,7 @@ function getValidOptions(
// Get valid recent reports:
let recentReportOptions: OptionData[] = [];
if (includeRecentReports) {
recentReportOptions = getValidReports(options.reports, {
const res = getValidReports(options.reports, {
...getValidReportsConfig,
includeP2P,
includeDomainEmail,
Expand Down Expand Up @@ -1476,22 +1512,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