From adec8522e7e80d264d936aba3cc0d9d46d92fefc Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 31 Jan 2024 00:20:04 +0530 Subject: [PATCH 01/26] show recents in participants page based on action type --- src/CONST.ts | 1 + src/libs/OptionsListUtils.ts | 125 ++++++++++++++---- src/libs/TransactionUtils.ts | 20 +++ ...yForRefactorRequestParticipantsSelector.js | 6 +- .../MoneyRequestParticipantsSelector.js | 3 + src/pages/tasks/TaskAssigneeSelectorModal.js | 4 + 6 files changed, 130 insertions(+), 29 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 1ccdfd9a82a8..999ae523f222 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1214,6 +1214,7 @@ const CONST = { DISTANCE: 'distance', MANUAL: 'manual', SCAN: 'scan', + SPLIT: 'split', }, REPORT_ACTION_TYPE: { PAY: 'pay', diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 812ebb051624..d95d74f0e2da 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -18,6 +18,7 @@ import type DeepValueOf from '@src/types/utils/DeepValueOf'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import times from '@src/utils/times'; +import * as Task from './actions/Task'; import Timing from './actions/Timing'; import * as CollectionUtils from './CollectionUtils'; import * as ErrorUtils from './ErrorUtils'; @@ -99,6 +100,7 @@ type GetOptionsConfig = { includePolicyTaxRates?: boolean; policyTaxRates?: PolicyTaxRateWithDefault; transactionViolations?: OnyxCollection; + actionTypeForParticipants?: string; }; type MemberForList = { @@ -550,6 +552,7 @@ function createOption( report: OnyxEntry, reportActions: ReportActions, {showChatPreviewLine = false, forcePolicyNamePreview = false}: PreviewConfig, + isTaskActionTypeForParticipants = false, ): ReportUtils.OptionData { const result: ReportUtils.OptionData = { text: undefined, @@ -595,7 +598,7 @@ function createOption( result.participantsList = personalDetailList; result.isOptimisticPersonalDetail = personalDetail?.isOptimisticPersonalDetail; - if (report) { + if (report && !isTaskActionTypeForParticipants) { result.isChatRoom = ReportUtils.isChatRoom(report); result.isDefaultRoom = ReportUtils.isDefaultRoom(report); result.isArchivedRoom = ReportUtils.isArchivedRoom(report); @@ -1323,8 +1326,14 @@ function getOptions( transactionViolations = {}, includePolicyTaxRates, policyTaxRates, + actionTypeForParticipants = '', }: GetOptionsConfig, ): GetOptions { + const isMoneyRequestActionType = + actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.MANUAL || + actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.SCAN || + actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.DISTANCE || + actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.SPLIT; if (includeCategories) { const categoryOptions = getCategoryListSections(categories, recentlyUsedCategories, selectedOptions as Category[], searchInputValue, maxRecentReportsToShow); @@ -1380,6 +1389,7 @@ function getOptions( } let recentReportOptions = []; + const recentReportOptionsByAction = []; let personalDetailsOptions: ReportUtils.OptionData[] = []; const reportMapForAccountIDs: Record = {}; const parsedPhoneNumber = PhoneNumber.parsePhoneNumber(LoginUtils.appendCountryCode(Str.removeSMSDomain(searchInputValue))); @@ -1417,6 +1427,7 @@ function getOptions( orderedReports.reverse(); const allReportOptions: ReportUtils.OptionData[] = []; + const isTaskActionTypeForParticipants = !includeTasks && actionTypeForParticipants === CONST.REPORT.TYPE.TASK; orderedReports.forEach((report) => { if (!report) { return; @@ -1427,7 +1438,10 @@ function getOptions( const isTaskReport = ReportUtils.isTaskReport(report); const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); - const accountIDs = report.visibleChatMemberAccountIDs ?? []; + let accountIDs = report.visibleChatMemberAccountIDs ?? []; + if (isTaskReport && isTaskActionTypeForParticipants) { + accountIDs = report.ownerAccountID ? [report.ownerAccountID] : []; + } if (isPolicyExpenseChat && report.isOwnPolicyExpenseChat && !includeOwnedWorkspaceChats) { return; @@ -1442,7 +1456,7 @@ function getOptions( return; } - if (isTaskReport && !includeTasks) { + if (isTaskReport && !(includeTasks || isTaskActionTypeForParticipants)) { return; } @@ -1468,10 +1482,17 @@ function getOptions( const isPolicyChatAdmin = ReportUtils.isPolicyExpenseChatAdmin(report, policies); allReportOptions.push( - createOption(accountIDs, personalDetails, report, reportActions, { - showChatPreviewLine, - forcePolicyNamePreview: isPolicyExpenseChat ? isSearchingSomeonesPolicyExpenseChat || isPolicyChatAdmin : forcePolicyNamePreview, - }), + createOption( + accountIDs, + personalDetails, + report, + reportActions, + { + showChatPreviewLine, + forcePolicyNamePreview: isPolicyExpenseChat ? isSearchingSomeonesPolicyExpenseChat || isPolicyChatAdmin : forcePolicyNamePreview, + }, + isTaskActionTypeForParticipants, + ), ); }); // We're only picking personal details that have logins set @@ -1482,10 +1503,17 @@ function getOptions( ? {} : Object.fromEntries(Object.entries(personalDetails ?? {}).filter(([, detail]) => !!detail?.login && !!detail.accountID && !detail?.isOptimisticPersonalDetail)); let allPersonalDetailsOptions = Object.values(havingLoginPersonalDetails).map((personalDetail) => - createOption([personalDetail?.accountID ?? -1], personalDetails, reportMapForAccountIDs[personalDetail?.accountID ?? -1], reportActions, { - showChatPreviewLine, - forcePolicyNamePreview, - }), + createOption( + [personalDetail?.accountID ?? -1], + personalDetails, + reportMapForAccountIDs[personalDetail?.accountID ?? -1], + reportActions, + { + showChatPreviewLine, + forcePolicyNamePreview, + }, + isTaskActionTypeForParticipants, + ), ); if (sortPersonalDetailsByAlphaAsc) { @@ -1494,7 +1522,7 @@ function getOptions( } // Exclude the current user from the personal details list - const optionsToExclude: Option[] = [{login: currentUserLogin}, {login: CONST.EMAIL.NOTIFICATIONS}]; + let optionsToExclude: Option[] = [{login: currentUserLogin}, {login: CONST.EMAIL.NOTIFICATIONS}]; // If we're including selected options from the search results, we only want to exclude them if the search input is empty // This is because on certain pages, we show the selected options at the top when the search input is empty @@ -1507,13 +1535,16 @@ function getOptions( optionsToExclude.push({login}); }); + const optionsToExcludeByActions: Option[] = []; + optionsToExcludeByActions.push(...optionsToExclude); + if (includeRecentReports) { - for (const reportOption of allReportOptions) { - // Stop adding options to the recentReports array when we reach the maxRecentReportsToShow value - if (recentReportOptions.length > 0 && recentReportOptions.length === maxRecentReportsToShow) { - break; - } + let recentTransactions: Array> = []; + if (isMoneyRequestActionType) { + recentTransactions = TransactionUtils.getTransactionsByRequestType(actionTypeForParticipants); + } + for (const reportOption of allReportOptions) { // Skip notifications@expensify.com if (reportOption.login === CONST.EMAIL.NOTIFICATIONS) { continue; @@ -1527,15 +1558,6 @@ function getOptions( continue; } - // If we're excluding threads, check the report to see if it has a single participant and if the participant is already selected - if ( - !includeThreads && - (!!reportOption.login || reportOption.reportID) && - optionsToExclude.some((option) => option.login === reportOption.login || option.reportID === reportOption.reportID) - ) { - continue; - } - // Finally check to see if this option is a match for the provided search string if we have one const {searchText, participantsList, isChatRoom} = reportOption; const participantNames = getParticipantNames(participantsList); @@ -1552,9 +1574,50 @@ function getOptions( } } + let isActionTypeOptionForParticipants = false; + if (actionTypeForParticipants === CONST.REPORT.TYPE.TASK && reportOption.isTaskReport) { + const taskReport = ReportUtils.getReport(reportOption.reportID); + if (!(!isEmptyObject(taskReport) && Task.getTaskAssigneeAccountID(taskReport) === currentUserAccountID)) { + isActionTypeOptionForParticipants = true; + } + } + + if (isMoneyRequestActionType && recentTransactions.some((transaction: OnyxEntry) => transaction?.reportID === String(reportOption.iouReportID))) { + isActionTypeOptionForParticipants = true; + } + + if (isActionTypeOptionForParticipants && optionsToExcludeByActions.some((option) => option.login === reportOption.login || option.reportID === reportOption.reportID)) { + continue; + } + reportOption.isSelected = isReportSelected(reportOption, selectedOptions); - recentReportOptions.push(reportOption); + if (isActionTypeOptionForParticipants) { + recentReportOptionsByAction.push(reportOption); + if (reportOption.login) { + optionsToExcludeByActions.push({login: reportOption.login}); + } + continue; + } + + // Stop adding options to the recentReports by action array when we reach the maxRecentReportsToShow value + if (recentReportOptionsByAction.length > 0 && recentReportOptionsByAction.length === maxRecentReportsToShow) { + break; + } + + // If we're excluding threads, check the report to see if it has a single participant and if the participant is already selected + if ( + !includeThreads && + (!!reportOption.login || reportOption.reportID) && + optionsToExclude.some((option) => option.login === reportOption.login || option.reportID === reportOption.reportID) + ) { + continue; + } + + // Stop adding options to the recentReports array when we reach the maxRecentReportsToShow value + if (recentReportOptions.length < maxRecentReportsToShow) { + recentReportOptions.push(reportOption); + } // Add this login to the exclude list so it won't appear when we process the personal details if (reportOption.login) { @@ -1562,6 +1625,10 @@ function getOptions( } } } + if (recentReportOptionsByAction.length > 0) { + optionsToExclude = [...optionsToExcludeByActions]; + recentReportOptions = [...recentReportOptionsByAction]; + } if (includePersonalDetails) { // Next loop over all personal details removing any that are selectedUsers or recentChats @@ -1660,7 +1727,7 @@ function getOptions( return { personalDetails: personalDetailsOptions, - recentReports: recentReportOptions, + recentReports: recentReportOptionsByAction.length > 0 ? recentReportOptionsByAction : recentReportOptions, userToInvite: canInviteUser ? userToInvite : null, currentUserOption, categoryOptions: [], @@ -1750,6 +1817,7 @@ function getFilteredOptions( includeSelectedOptions = false, includePolicyTaxRates = false, policyTaxRates: PolicyTaxRateWithDefault = {} as PolicyTaxRateWithDefault, + actionTypeForParticipants = '', ) { return getOptions(reports, personalDetails, { betas, @@ -1771,6 +1839,7 @@ function getFilteredOptions( includeSelectedOptions, includePolicyTaxRates, policyTaxRates, + actionTypeForParticipants, }); } diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index b1a900675949..3e30cfe24e0c 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -57,6 +57,10 @@ function isScanRequest(transaction: Transaction): boolean { return Boolean(transaction?.receipt?.source); } +function isSplitRequest(transaction: Transaction): boolean { + return Boolean(transaction?.comment?.source === CONST.IOU.TYPE.SPLIT); +} + function getRequestType(transaction: Transaction): ValueOf { if (isDistanceRequest(transaction)) { return CONST.IOU.REQUEST_TYPE.DISTANCE; @@ -76,6 +80,20 @@ function isManualRequest(transaction: Transaction): boolean { return getRequestType(transaction) === CONST.IOU.REQUEST_TYPE.MANUAL; } +function getTransactionsByRequestType(iouRequestType?: ValueOf): Array> { + return Object.values(allTransactions ?? {}) + .filter( + (transaction): transaction is Transaction => + transaction != null && (iouRequestType === CONST.IOU.REQUEST_TYPE.SPLIT ? isSplitRequest(transaction) : getRequestType(transaction) === iouRequestType), + ) + .sort((transactionA, transactionB) => { + const transactionATime = new Date(transactionA?.created); + const transactionBTime = new Date(transactionB?.created); + return transactionATime.valueOf() - transactionBTime.valueOf(); + }) + .reverse(); +} + /** * Optimistically generate a transaction. * @@ -561,6 +579,7 @@ export { getRequestType, isManualRequest, isScanRequest, + isSplitRequest, getAmount, getCurrency, getDistance, @@ -596,4 +615,5 @@ export { waypointHasValidAddress, getRecentTransactions, hasViolation, + getTransactionsByRequestType, }; diff --git a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js index 15f98205839e..0f808e2f1ce2 100644 --- a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js +++ b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js @@ -88,6 +88,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ const offlineMessage = isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : ''; const maxParticipantsReached = participants.length === CONST.REPORT.MAXIMUM_PARTICIPANTS; + const actionTypeForParticipants = iouType === CONST.IOU.TYPE.REQUEST && participants.length > 0 ? CONST.IOU.REQUEST_TYPE.SPLIT : iouRequestType; /** * Returns the sections needed for the OptionsSelector @@ -126,6 +127,9 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ // This functionality is being built here: https://github.com/Expensify/App/issues/23291 iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE, false, + false, + {}, + actionTypeForParticipants, ); const formatResults = OptionsListUtils.formatSectionsFromSearchTerm( @@ -173,7 +177,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ } return [newSections, chatOptions]; - }, [didScreenTransitionEnd, reports, personalDetails, betas, searchTerm, participants, iouType, iouRequestType, maxParticipantsReached, translate]); + }, [didScreenTransitionEnd, reports, personalDetails, betas, searchTerm, participants, iouType, iouRequestType, maxParticipantsReached, translate, actionTypeForParticipants]); /** * Adds a single participant to the request diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js index 59081599736c..8bb57fd5a47e 100755 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js @@ -116,6 +116,9 @@ function MoneyRequestParticipantsSelector({ // This functionality is being built here: https://github.com/Expensify/App/issues/23291 !isDistanceRequest, true, + false, + {}, + CONST.IOU.REQUEST_TYPE.MANUAL, ); return { recentReports: chatOptions.recentReports, diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.js b/src/pages/tasks/TaskAssigneeSelectorModal.js index 1a526a9cdd9b..c397aa8ce6e7 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.js +++ b/src/pages/tasks/TaskAssigneeSelectorModal.js @@ -105,6 +105,10 @@ function TaskAssigneeSelectorModal(props) { {}, [], true, + false, + false, + {}, + CONST.REPORT.TYPE.TASK, ); setHeaderMessage(OptionsListUtils.getHeaderMessage(recentReports?.length + personalDetails?.length !== 0 || currentUserOption, Boolean(userToInvite), searchValue)); From 5faec9469948fdacdd3f1e3a4fc705c63b6a918b Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 31 Jan 2024 11:22:30 +0530 Subject: [PATCH 02/26] get transactions by action type --- src/CONST.ts | 1 - src/libs/OptionsListUtils.ts | 16 ++++++++-------- src/libs/TransactionUtils.ts | 6 +++--- ...raryForRefactorRequestParticipantsSelector.js | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 999ae523f222..1ccdfd9a82a8 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1214,7 +1214,6 @@ const CONST = { DISTANCE: 'distance', MANUAL: 'manual', SCAN: 'scan', - SPLIT: 'split', }, REPORT_ACTION_TYPE: { PAY: 'pay', diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index a08588636822..5decb7b27b81 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1340,11 +1340,6 @@ function getOptions( actionTypeForParticipants = '', }: GetOptionsConfig, ): GetOptions { - const isMoneyRequestActionType = - actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.MANUAL || - actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.SCAN || - actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.DISTANCE || - actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.SPLIT; if (includeCategories) { const categoryOptions = getCategoryListSections(categories, recentlyUsedCategories, selectedOptions as Category[], searchInputValue, maxRecentReportsToShow); @@ -1439,6 +1434,11 @@ function getOptions( const allReportOptions: ReportUtils.OptionData[] = []; const isTaskActionTypeForParticipants = !includeTasks && actionTypeForParticipants === CONST.REPORT.TYPE.TASK; + const isMoneyRequestActionTypeForParticipants = + actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.MANUAL || + actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.SCAN || + actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.DISTANCE || + actionTypeForParticipants === CONST.IOU.TYPE.SPLIT; orderedReports.forEach((report) => { if (!report) { return; @@ -1546,8 +1546,8 @@ function getOptions( if (includeRecentReports) { let recentTransactions: Array> = []; - if (isMoneyRequestActionType) { - recentTransactions = TransactionUtils.getTransactionsByRequestType(actionTypeForParticipants); + if (isMoneyRequestActionTypeForParticipants) { + recentTransactions = TransactionUtils.getTransactionsByActionType(actionTypeForParticipants); } for (const reportOption of allReportOptions) { @@ -1588,7 +1588,7 @@ function getOptions( } } - if (isMoneyRequestActionType && recentTransactions.some((transaction: OnyxEntry) => transaction?.reportID === String(reportOption.iouReportID))) { + if (isMoneyRequestActionTypeForParticipants && recentTransactions.some((transaction: OnyxEntry) => transaction?.reportID === String(reportOption.iouReportID))) { isActionTypeOptionForParticipants = true; } diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 9dd919bbdb97..6586b7504dee 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -80,11 +80,11 @@ function isManualRequest(transaction: Transaction): boolean { return getRequestType(transaction) === CONST.IOU.REQUEST_TYPE.MANUAL; } -function getTransactionsByRequestType(iouRequestType?: ValueOf): Array> { +function getTransactionsByActionType(actionType?: string): Array> { return Object.values(allTransactions ?? {}) .filter( (transaction): transaction is Transaction => - transaction != null && (iouRequestType === CONST.IOU.REQUEST_TYPE.SPLIT ? isSplitRequest(transaction) : getRequestType(transaction) === iouRequestType), + transaction != null && (actionType === CONST.IOU.TYPE.SPLIT ? isSplitRequest(transaction) : getRequestType(transaction) === actionType), ) .sort((transactionA, transactionB) => { const transactionATime = new Date(transactionA?.created); @@ -615,5 +615,5 @@ export { waypointHasValidAddress, getRecentTransactions, hasViolation, - getTransactionsByRequestType, + getTransactionsByActionType, }; diff --git a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js index 0f808e2f1ce2..0eee45fb546a 100644 --- a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js +++ b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js @@ -88,7 +88,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ const offlineMessage = isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : ''; const maxParticipantsReached = participants.length === CONST.REPORT.MAXIMUM_PARTICIPANTS; - const actionTypeForParticipants = iouType === CONST.IOU.TYPE.REQUEST && participants.length > 0 ? CONST.IOU.REQUEST_TYPE.SPLIT : iouRequestType; + const actionTypeForParticipants = iouType === CONST.IOU.TYPE.REQUEST && participants.length > 0 ? CONST.IOU.TYPE.SPLIT : iouRequestType; /** * Returns the sections needed for the OptionsSelector From 69b5ff6df190e520d5fc29ab2296605c3a5704c9 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 31 Jan 2024 13:59:31 +0530 Subject: [PATCH 03/26] regression fixes --- src/libs/OptionsListUtils.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 5decb7b27b81..1f9af195e683 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1621,13 +1621,12 @@ function getOptions( } // Stop adding options to the recentReports array when we reach the maxRecentReportsToShow value - if (recentReportOptions.length < maxRecentReportsToShow) { + if (!maxRecentReportsToShow || recentReportOptions.length < maxRecentReportsToShow) { recentReportOptions.push(reportOption); - } - - // Add this login to the exclude list so it won't appear when we process the personal details - if (reportOption.login) { - optionsToExclude.push({login: reportOption.login}); + // Add this login to the exclude list so it won't appear when we process the personal details + if (reportOption.login) { + optionsToExclude.push({login: reportOption.login}); + } } } } From 64e6273f7d08292770a5e5ebce7db2b51c972003 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 31 Jan 2024 20:19:12 +0530 Subject: [PATCH 04/26] Fix for showing recent tasks --- src/libs/OptionsListUtils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 1f9af195e683..d11bf84e3b81 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -676,6 +676,10 @@ function createOption( } reportName = ReportUtils.getReportName(report); } else { + if(isTaskActionTypeForParticipants && report) { + result.reportID = report.reportID; + result.isTaskReport = ReportUtils.isTaskReport(report); + } // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing reportName = ReportUtils.getDisplayNameForParticipant(accountIDs[0]) || LocalePhoneNumber.formatPhoneNumber(personalDetail?.login ?? ''); result.keyForList = String(accountIDs[0]); From 7299643c02efcc6fddb96aee6e725865afa2b70e Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 31 Jan 2024 20:54:14 +0530 Subject: [PATCH 05/26] prettier fix --- src/libs/OptionsListUtils.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index d11bf84e3b81..cbc5d6f28876 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -676,10 +676,6 @@ function createOption( } reportName = ReportUtils.getReportName(report); } else { - if(isTaskActionTypeForParticipants && report) { - result.reportID = report.reportID; - result.isTaskReport = ReportUtils.isTaskReport(report); - } // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing reportName = ReportUtils.getDisplayNameForParticipant(accountIDs[0]) || LocalePhoneNumber.formatPhoneNumber(personalDetail?.login ?? ''); result.keyForList = String(accountIDs[0]); @@ -687,6 +683,11 @@ function createOption( result.alternateText = LocalePhoneNumber.formatPhoneNumber(personalDetails?.[accountIDs[0]]?.login ?? ''); } + if (isTaskActionTypeForParticipants && report) { + result.reportID = report.reportID; + result.isTaskReport = ReportUtils.isTaskReport(report); + } + result.isIOUReportOwner = ReportUtils.isIOUOwnedByCurrentUser(result); result.iouReportAmount = ReportUtils.getMoneyRequestSpendBreakdown(result).totalDisplaySpend; From 998f47464d9528009a35016be4a0c2bec27058a9 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 31 Jan 2024 21:03:35 +0530 Subject: [PATCH 06/26] sort optimization --- src/libs/TransactionUtils.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 6586b7504dee..bd0214b32ed6 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -81,17 +81,16 @@ function isManualRequest(transaction: Transaction): boolean { } function getTransactionsByActionType(actionType?: string): Array> { - return Object.values(allTransactions ?? {}) - .filter( - (transaction): transaction is Transaction => - transaction != null && (actionType === CONST.IOU.TYPE.SPLIT ? isSplitRequest(transaction) : getRequestType(transaction) === actionType), - ) - .sort((transactionA, transactionB) => { - const transactionATime = new Date(transactionA?.created); - const transactionBTime = new Date(transactionB?.created); - return transactionATime.valueOf() - transactionBTime.valueOf(); - }) - .reverse(); + return ( + Object.values(allTransactions ?? {}) + .filter( + (transaction): transaction is Transaction => + transaction != null && (actionType === CONST.IOU.TYPE.SPLIT ? isSplitRequest(transaction) : getRequestType(transaction) === actionType), + ) + // String based sorting of dates having format [YYYY-MM-DD HH:MM:SS.mmm] + .sort((transactionA, transactionB) => (transactionA?.created && transactionB?.created && transactionA?.created > transactionB?.created ? 1 : -1)) + .reverse() + ); } /** From 8aa96014fd2442081f8ddf107f7f79459f07d782 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 31 Jan 2024 23:45:46 +0530 Subject: [PATCH 07/26] use participant account ids for tasks --- src/libs/OptionsListUtils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index cbc5d6f28876..2820ae4f06ed 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1454,10 +1454,10 @@ function getOptions( const isTaskReport = ReportUtils.isTaskReport(report); const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); - let accountIDs = report.visibleChatMemberAccountIDs ?? []; - if (isTaskReport && isTaskActionTypeForParticipants) { - accountIDs = report.ownerAccountID ? [report.ownerAccountID] : []; - } + const accountIDs = + isTaskReport && isTaskActionTypeForParticipants + ? report.participantAccountIDs?.filter((accountID) => accountID !== currentUserAccountID) ?? [] + : report.visibleChatMemberAccountIDs ?? []; if (isPolicyExpenseChat && report.isOwnPolicyExpenseChat && !includeOwnedWorkspaceChats) { return; From c62108ac09c96a561cb5b75e6ed11c86ab7ccb70 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Thu, 1 Feb 2024 03:40:08 +0530 Subject: [PATCH 08/26] fix for max num of recents displayed --- src/libs/OptionsListUtils.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 2820ae4f06ed..9ccc7d9c26eb 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1603,6 +1603,10 @@ function getOptions( reportOption.isSelected = isReportSelected(reportOption, selectedOptions); + if (recentReportOptionsByAction.length > 0 && recentReportOptionsByAction.length === maxRecentReportsToShow) { + break; + } + if (isActionTypeOptionForParticipants) { recentReportOptionsByAction.push(reportOption); if (reportOption.login) { @@ -1611,11 +1615,6 @@ function getOptions( continue; } - // Stop adding options to the recentReports by action array when we reach the maxRecentReportsToShow value - if (recentReportOptionsByAction.length > 0 && recentReportOptionsByAction.length === maxRecentReportsToShow) { - break; - } - // If we're excluding threads, check the report to see if it has a single participant and if the participant is already selected if ( !includeThreads && From d9cd09159af9d7c81b139bfc02a4d9943ba36086 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Thu, 1 Feb 2024 09:27:08 +0530 Subject: [PATCH 09/26] reverting recent list by task action type --- src/libs/OptionsListUtils.ts | 54 ++++---------------- src/pages/tasks/TaskAssigneeSelectorModal.js | 4 -- 2 files changed, 11 insertions(+), 47 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 9ccc7d9c26eb..6c0cc7aa6521 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -18,7 +18,6 @@ import type DeepValueOf from '@src/types/utils/DeepValueOf'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import times from '@src/utils/times'; -import * as Task from './actions/Task'; import Timing from './actions/Timing'; import * as CollectionUtils from './CollectionUtils'; import * as ErrorUtils from './ErrorUtils'; @@ -580,7 +579,6 @@ function createOption( report: OnyxEntry, reportActions: ReportActions, {showChatPreviewLine = false, forcePolicyNamePreview = false}: PreviewConfig, - isTaskActionTypeForParticipants = false, ): ReportUtils.OptionData { const result: ReportUtils.OptionData = { text: undefined, @@ -626,7 +624,7 @@ function createOption( result.participantsList = personalDetailList; result.isOptimisticPersonalDetail = personalDetail?.isOptimisticPersonalDetail; - if (report && !isTaskActionTypeForParticipants) { + if (report) { result.isChatRoom = ReportUtils.isChatRoom(report); result.isDefaultRoom = ReportUtils.isDefaultRoom(report); result.isArchivedRoom = ReportUtils.isArchivedRoom(report); @@ -683,11 +681,6 @@ function createOption( result.alternateText = LocalePhoneNumber.formatPhoneNumber(personalDetails?.[accountIDs[0]]?.login ?? ''); } - if (isTaskActionTypeForParticipants && report) { - result.reportID = report.reportID; - result.isTaskReport = ReportUtils.isTaskReport(report); - } - result.isIOUReportOwner = ReportUtils.isIOUOwnedByCurrentUser(result); result.iouReportAmount = ReportUtils.getMoneyRequestSpendBreakdown(result).totalDisplaySpend; @@ -1438,7 +1431,6 @@ function getOptions( orderedReports.reverse(); const allReportOptions: ReportUtils.OptionData[] = []; - const isTaskActionTypeForParticipants = !includeTasks && actionTypeForParticipants === CONST.REPORT.TYPE.TASK; const isMoneyRequestActionTypeForParticipants = actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.MANUAL || actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.SCAN || @@ -1454,10 +1446,7 @@ function getOptions( const isTaskReport = ReportUtils.isTaskReport(report); const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); - const accountIDs = - isTaskReport && isTaskActionTypeForParticipants - ? report.participantAccountIDs?.filter((accountID) => accountID !== currentUserAccountID) ?? [] - : report.visibleChatMemberAccountIDs ?? []; + const accountIDs = report.visibleChatMemberAccountIDs ?? []; if (isPolicyExpenseChat && report.isOwnPolicyExpenseChat && !includeOwnedWorkspaceChats) { return; @@ -1472,7 +1461,7 @@ function getOptions( return; } - if (isTaskReport && !(includeTasks || isTaskActionTypeForParticipants)) { + if (isTaskReport && !includeTasks) { return; } @@ -1493,17 +1482,10 @@ function getOptions( } allReportOptions.push( - createOption( - accountIDs, - personalDetails, - report, - reportActions, - { - showChatPreviewLine, - forcePolicyNamePreview, - }, - isTaskActionTypeForParticipants, - ), + createOption(accountIDs, personalDetails, report, reportActions, { + showChatPreviewLine, + forcePolicyNamePreview, + }), ); }); // We're only picking personal details that have logins set @@ -1514,17 +1496,10 @@ function getOptions( ? {} : Object.fromEntries(Object.entries(personalDetails ?? {}).filter(([, detail]) => !!detail?.login && !!detail.accountID && !detail?.isOptimisticPersonalDetail)); let allPersonalDetailsOptions = Object.values(havingLoginPersonalDetails).map((personalDetail) => - createOption( - [personalDetail?.accountID ?? -1], - personalDetails, - reportMapForAccountIDs[personalDetail?.accountID ?? -1], - reportActions, - { - showChatPreviewLine, - forcePolicyNamePreview, - }, - isTaskActionTypeForParticipants, - ), + createOption([personalDetail?.accountID ?? -1], personalDetails, reportMapForAccountIDs[personalDetail?.accountID ?? -1], reportActions, { + showChatPreviewLine, + forcePolicyNamePreview, + }), ); if (sortPersonalDetailsByAlphaAsc) { @@ -1586,13 +1561,6 @@ function getOptions( } let isActionTypeOptionForParticipants = false; - if (actionTypeForParticipants === CONST.REPORT.TYPE.TASK && reportOption.isTaskReport) { - const taskReport = ReportUtils.getReport(reportOption.reportID); - if (!(!isEmptyObject(taskReport) && Task.getTaskAssigneeAccountID(taskReport) === currentUserAccountID)) { - isActionTypeOptionForParticipants = true; - } - } - if (isMoneyRequestActionTypeForParticipants && recentTransactions.some((transaction: OnyxEntry) => transaction?.reportID === String(reportOption.iouReportID))) { isActionTypeOptionForParticipants = true; } diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.js b/src/pages/tasks/TaskAssigneeSelectorModal.js index c397aa8ce6e7..1a526a9cdd9b 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.js +++ b/src/pages/tasks/TaskAssigneeSelectorModal.js @@ -105,10 +105,6 @@ function TaskAssigneeSelectorModal(props) { {}, [], true, - false, - false, - {}, - CONST.REPORT.TYPE.TASK, ); setHeaderMessage(OptionsListUtils.getHeaderMessage(recentReports?.length + personalDetails?.length !== 0 || currentUserOption, Boolean(userToInvite), searchValue)); From 557049381c8c10264b969444eee8db0551563ab9 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Thu, 1 Feb 2024 13:15:23 +0530 Subject: [PATCH 10/26] fixes for recent list for money request action type --- src/libs/OptionsListUtils.ts | 14 +++++++++++--- .../MoneyRequestParticipantsSelector.js | 3 --- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 6c0cc7aa6521..18c9da116783 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1525,9 +1525,17 @@ function getOptions( optionsToExcludeByActions.push(...optionsToExclude); if (includeRecentReports) { - let recentTransactions: Array> = []; + const recentChatReportIDsForMoneyRequestActionType: string[] = []; if (isMoneyRequestActionTypeForParticipants) { - recentTransactions = TransactionUtils.getTransactionsByActionType(actionTypeForParticipants); + TransactionUtils.getTransactionsByActionType(actionTypeForParticipants).every((recentTransaction) => { + const iouReport = ReportUtils.getReport(recentTransaction?.reportID); + if (!recentChatReportIDsForMoneyRequestActionType.some((reportID: string) => iouReport?.parentReportID === reportID)) { + if (iouReport?.parentReportID) { + recentChatReportIDsForMoneyRequestActionType.push(iouReport?.parentReportID); + } + } + return true; + }); } for (const reportOption of allReportOptions) { @@ -1561,7 +1569,7 @@ function getOptions( } let isActionTypeOptionForParticipants = false; - if (isMoneyRequestActionTypeForParticipants && recentTransactions.some((transaction: OnyxEntry) => transaction?.reportID === String(reportOption.iouReportID))) { + if (isMoneyRequestActionTypeForParticipants && recentChatReportIDsForMoneyRequestActionType.some((reportID: string) => reportID === String(reportOption.reportID))) { isActionTypeOptionForParticipants = true; } diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js index 8bb57fd5a47e..59081599736c 100755 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js @@ -116,9 +116,6 @@ function MoneyRequestParticipantsSelector({ // This functionality is being built here: https://github.com/Expensify/App/issues/23291 !isDistanceRequest, true, - false, - {}, - CONST.IOU.REQUEST_TYPE.MANUAL, ); return { recentReports: chatOptions.recentReports, From 9149a6a95867787f19d475f7872a8f8d10a0d5df Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Thu, 1 Feb 2024 14:27:55 +0530 Subject: [PATCH 11/26] fixes for recent list of task action type --- src/libs/OptionsListUtils.ts | 33 +++++++++++++++----- src/pages/tasks/TaskAssigneeSelectorModal.js | 4 +++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 18c9da116783..c54cf3f057f3 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1431,11 +1431,13 @@ function getOptions( orderedReports.reverse(); const allReportOptions: ReportUtils.OptionData[] = []; + const isTaskActionTypeForParticipants = actionTypeForParticipants === CONST.REPORT.TYPE.TASK; const isMoneyRequestActionTypeForParticipants = actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.MANUAL || actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.SCAN || actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.DISTANCE || actionTypeForParticipants === CONST.IOU.TYPE.SPLIT; + const recentChatReportIDsForActionType: string[] = []; orderedReports.forEach((report) => { if (!report) { return; @@ -1461,6 +1463,24 @@ function getOptions( return; } + if (isTaskActionTypeForParticipants && isTaskReport && includeRecentReports) { + let parentReportID = report.parentReportID; + let topmostChatReportID = report.parentReportID; + while (parentReportID) { + const parentReport = ReportUtils.getReport(parentReportID); + if (parentReport?.parentReportID) { + topmostChatReportID = parentReport?.parentReportID; + } + parentReportID = parentReport?.parentReportID; + } + if (!recentChatReportIDsForActionType.some((reportID: string) => topmostChatReportID === reportID)) { + if (topmostChatReportID) { + recentChatReportIDsForActionType.push(topmostChatReportID); + } + } + return; + } + if (isTaskReport && !includeTasks) { return; } @@ -1525,13 +1545,12 @@ function getOptions( optionsToExcludeByActions.push(...optionsToExclude); if (includeRecentReports) { - const recentChatReportIDsForMoneyRequestActionType: string[] = []; if (isMoneyRequestActionTypeForParticipants) { TransactionUtils.getTransactionsByActionType(actionTypeForParticipants).every((recentTransaction) => { const iouReport = ReportUtils.getReport(recentTransaction?.reportID); - if (!recentChatReportIDsForMoneyRequestActionType.some((reportID: string) => iouReport?.parentReportID === reportID)) { + if (!recentChatReportIDsForActionType.some((reportID: string) => iouReport?.parentReportID === reportID)) { if (iouReport?.parentReportID) { - recentChatReportIDsForMoneyRequestActionType.push(iouReport?.parentReportID); + recentChatReportIDsForActionType.push(iouReport?.parentReportID); } } return true; @@ -1568,11 +1587,9 @@ function getOptions( } } - let isActionTypeOptionForParticipants = false; - if (isMoneyRequestActionTypeForParticipants && recentChatReportIDsForMoneyRequestActionType.some((reportID: string) => reportID === String(reportOption.reportID))) { - isActionTypeOptionForParticipants = true; - } - + const isActionTypeOptionForParticipants = + (isMoneyRequestActionTypeForParticipants || isTaskActionTypeForParticipants) && + recentChatReportIDsForActionType.some((reportID: string) => reportID === String(reportOption.reportID)); if (isActionTypeOptionForParticipants && optionsToExcludeByActions.some((option) => option.login === reportOption.login || option.reportID === reportOption.reportID)) { continue; } diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.js b/src/pages/tasks/TaskAssigneeSelectorModal.js index 1a526a9cdd9b..c397aa8ce6e7 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.js +++ b/src/pages/tasks/TaskAssigneeSelectorModal.js @@ -105,6 +105,10 @@ function TaskAssigneeSelectorModal(props) { {}, [], true, + false, + false, + {}, + CONST.REPORT.TYPE.TASK, ); setHeaderMessage(OptionsListUtils.getHeaderMessage(recentReports?.length + personalDetails?.length !== 0 || currentUserOption, Boolean(userToInvite), searchValue)); From 21e4eb6f09f153f38886c5d5305cace7ca6b1994 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Thu, 1 Feb 2024 15:18:28 +0530 Subject: [PATCH 12/26] Minor fix and added comments --- src/libs/OptionsListUtils.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index c54cf3f057f3..44f3712a7890 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1463,6 +1463,8 @@ function getOptions( return; } + // During task assignment, we collect the top most chat report ids of the task reports + // for display in the recent reports list if (isTaskActionTypeForParticipants && isTaskReport && includeRecentReports) { let parentReportID = report.parentReportID; let topmostChatReportID = report.parentReportID; @@ -1545,6 +1547,8 @@ function getOptions( optionsToExcludeByActions.push(...optionsToExclude); if (includeRecentReports) { + // During money request generation, we collect chat report ids + // of the money request report's parent for display in the recent reports list if (isMoneyRequestActionTypeForParticipants) { TransactionUtils.getTransactionsByActionType(actionTypeForParticipants).every((recentTransaction) => { const iouReport = ReportUtils.getReport(recentTransaction?.reportID); @@ -1587,6 +1591,7 @@ function getOptions( } } + // Check if this report option is to be displayed based on the action type const isActionTypeOptionForParticipants = (isMoneyRequestActionTypeForParticipants || isTaskActionTypeForParticipants) && recentChatReportIDsForActionType.some((reportID: string) => reportID === String(reportOption.reportID)); @@ -1596,10 +1601,12 @@ function getOptions( reportOption.isSelected = isReportSelected(reportOption, selectedOptions); + // Stop adding to the recent report option list if we have reached the maxRecentReportsToShow value if (recentReportOptionsByAction.length > 0 && recentReportOptionsByAction.length === maxRecentReportsToShow) { break; } + // Push the report option to be displayed based on action type if (isActionTypeOptionForParticipants) { recentReportOptionsByAction.push(reportOption); if (reportOption.login) { @@ -1617,7 +1624,7 @@ function getOptions( continue; } - // Stop adding options to the recentReports array when we reach the maxRecentReportsToShow value + // Keep adding to the recentReports array if there is no limit set or until maxRecentReportsToShow limit is reached if (!maxRecentReportsToShow || recentReportOptions.length < maxRecentReportsToShow) { recentReportOptions.push(reportOption); // Add this login to the exclude list so it won't appear when we process the personal details @@ -1627,6 +1634,8 @@ function getOptions( } } } + // Let us reset the recent list and the options to exclude if we have found + // recent reports by action type for setting personal details and for search results. if (recentReportOptionsByAction.length > 0) { optionsToExclude = [...optionsToExcludeByActions]; recentReportOptions = [...recentReportOptionsByAction]; @@ -1729,7 +1738,7 @@ function getOptions( return { personalDetails: personalDetailsOptions, - recentReports: recentReportOptionsByAction.length > 0 ? recentReportOptionsByAction : recentReportOptions, + recentReports: recentReportOptions, userToInvite: canInviteUser ? userToInvite : null, currentUserOption, categoryOptions: [], From 745ed17a2a581d3b3fcfe68a2d9cfca4ebd75e3d Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Thu, 1 Feb 2024 16:43:49 +0530 Subject: [PATCH 13/26] prettier fix and check perf --- src/libs/OptionsListUtils.ts | 42 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 44f3712a7890..ca4be1b679a8 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1463,25 +1463,25 @@ function getOptions( return; } - // During task assignment, we collect the top most chat report ids of the task reports - // for display in the recent reports list - if (isTaskActionTypeForParticipants && isTaskReport && includeRecentReports) { - let parentReportID = report.parentReportID; - let topmostChatReportID = report.parentReportID; - while (parentReportID) { - const parentReport = ReportUtils.getReport(parentReportID); - if (parentReport?.parentReportID) { - topmostChatReportID = parentReport?.parentReportID; - } - parentReportID = parentReport?.parentReportID; - } - if (!recentChatReportIDsForActionType.some((reportID: string) => topmostChatReportID === reportID)) { - if (topmostChatReportID) { - recentChatReportIDsForActionType.push(topmostChatReportID); - } - } - return; - } + // // During task assignment, we collect the top most chat report ids of the task reports + // // for display in the recent reports list + // if (isTaskActionTypeForParticipants && isTaskReport && includeRecentReports) { + // let parentReportID = report.parentReportID; + // let topmostChatReportID = report.parentReportID; + // while (parentReportID) { + // const parentReport = ReportUtils.getReport(parentReportID); + // if (parentReport?.parentReportID) { + // topmostChatReportID = parentReport?.parentReportID; + // } + // parentReportID = parentReport?.parentReportID; + // } + // if (!recentChatReportIDsForActionType.some((reportID: string) => topmostChatReportID === reportID)) { + // if (topmostChatReportID) { + // recentChatReportIDsForActionType.push(topmostChatReportID); + // } + // } + // return; + // } if (isTaskReport && !includeTasks) { return; @@ -1547,7 +1547,7 @@ function getOptions( optionsToExcludeByActions.push(...optionsToExclude); if (includeRecentReports) { - // During money request generation, we collect chat report ids + // During money request generation, we collect chat report ids // of the money request report's parent for display in the recent reports list if (isMoneyRequestActionTypeForParticipants) { TransactionUtils.getTransactionsByActionType(actionTypeForParticipants).every((recentTransaction) => { @@ -1634,7 +1634,7 @@ function getOptions( } } } - // Let us reset the recent list and the options to exclude if we have found + // Let us reset the recent list and the options to exclude if we have found // recent reports by action type for setting personal details and for search results. if (recentReportOptionsByAction.length > 0) { optionsToExclude = [...optionsToExcludeByActions]; From d9bcc73ebd9ce148d1946227997099ec727c223d Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Thu, 1 Feb 2024 18:36:00 +0530 Subject: [PATCH 14/26] fix for recent list of task action type --- src/libs/OptionsListUtils.ts | 50 +++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index ca4be1b679a8..dbcdd302fc40 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1437,7 +1437,7 @@ function getOptions( actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.SCAN || actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.DISTANCE || actionTypeForParticipants === CONST.IOU.TYPE.SPLIT; - const recentChatReportIDsForActionType: string[] = []; + const reportIDsForTaskReport: string[] = []; orderedReports.forEach((report) => { if (!report) { return; @@ -1463,25 +1463,11 @@ function getOptions( return; } - // // During task assignment, we collect the top most chat report ids of the task reports - // // for display in the recent reports list - // if (isTaskActionTypeForParticipants && isTaskReport && includeRecentReports) { - // let parentReportID = report.parentReportID; - // let topmostChatReportID = report.parentReportID; - // while (parentReportID) { - // const parentReport = ReportUtils.getReport(parentReportID); - // if (parentReport?.parentReportID) { - // topmostChatReportID = parentReport?.parentReportID; - // } - // parentReportID = parentReport?.parentReportID; - // } - // if (!recentChatReportIDsForActionType.some((reportID: string) => topmostChatReportID === reportID)) { - // if (topmostChatReportID) { - // recentChatReportIDsForActionType.push(topmostChatReportID); - // } - // } - // return; - // } + // Save the task report ids in an array for finding out recent reports based on task action type + if (isTaskActionTypeForParticipants && isTaskReport && includeRecentReports) { + reportIDsForTaskReport.push(report.reportID); + return; + } if (isTaskReport && !includeTasks) { return; @@ -1547,6 +1533,7 @@ function getOptions( optionsToExcludeByActions.push(...optionsToExclude); if (includeRecentReports) { + const recentChatReportIDsForActionType: string[] = []; // During money request generation, we collect chat report ids // of the money request report's parent for display in the recent reports list if (isMoneyRequestActionTypeForParticipants) { @@ -1561,6 +1548,29 @@ function getOptions( }); } + // During task assignment, we collect the top most chat report ids of the task reports + // for display in the recent reports list + if (isTaskActionTypeForParticipants) { + const parentReportIDs: string[] = []; + reportIDsForTaskReport.every((taskReportID) => { + const taskReport = ReportUtils.getReport(taskReportID); + let parentReportID = taskReport?.parentReportID; + let topmostChatReportID = taskReport?.parentReportID; + while (parentReportID) { + const parentReport = ReportUtils.getReport(parentReportID); + if (parentReport?.parentReportID) { + topmostChatReportID = parentReport?.parentReportID; + } + parentReportID = parentReport?.parentReportID; + } + if (topmostChatReportID) { + parentReportIDs.push(topmostChatReportID); + } + return true; + }); + recentChatReportIDsForActionType.push(...parentReportIDs.filter((reportID, reportIDIndex) => parentReportIDs.indexOf(reportID) === reportIDIndex)); + } + for (const reportOption of allReportOptions) { // Skip notifications@expensify.com if (reportOption.login === CONST.EMAIL.NOTIFICATIONS) { From 54032a0936a135d1791e933a1c4d5ef729f0ac1b Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Sat, 3 Feb 2024 00:06:02 +0530 Subject: [PATCH 15/26] review feedback changes --- src/libs/OptionsListUtils.ts | 18 +++++++++++------- src/libs/TransactionUtils.ts | 23 ++++++++++++++++++----- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 945837a4fa0a..a6dc82118a4f 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -7,6 +7,7 @@ import lodashSet from 'lodash/set'; import lodashSortBy from 'lodash/sortBy'; import Onyx from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; +import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -68,6 +69,8 @@ type Category = { type Hierarchy = Record; +type ActionType = ValueOf | ValueOf> | ValueOf> | undefined; + type GetOptionsConfig = { reportActions?: ReportActions; betas?: Beta[]; @@ -99,7 +102,7 @@ type GetOptionsConfig = { includePolicyTaxRates?: boolean; policyTaxRates?: PolicyTaxRateWithDefault; transactionViolations?: OnyxCollection; - actionTypeForParticipants?: string; + actionTypeForParticipants?: ActionType; }; type MemberForList = { @@ -1335,7 +1338,7 @@ function getOptions( transactionViolations = {}, includePolicyTaxRates, policyTaxRates, - actionTypeForParticipants = '', + actionTypeForParticipants, }: GetOptionsConfig, ): GetOptions { if (includeCategories) { @@ -1433,10 +1436,11 @@ function getOptions( const allReportOptions: ReportUtils.OptionData[] = []; const isTaskActionTypeForParticipants = actionTypeForParticipants === CONST.REPORT.TYPE.TASK; const isMoneyRequestActionTypeForParticipants = - actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.MANUAL || - actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.SCAN || - actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.DISTANCE || - actionTypeForParticipants === CONST.IOU.TYPE.SPLIT; + !isTaskActionTypeForParticipants && + (actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.MANUAL || + actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.SCAN || + actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.DISTANCE || + actionTypeForParticipants === CONST.IOU.TYPE.SPLIT); const reportIDsForTaskReport: string[] = []; orderedReports.forEach((report) => { if (!report) { @@ -1838,7 +1842,7 @@ function getFilteredOptions( includeSelectedOptions = false, includePolicyTaxRates = false, policyTaxRates: PolicyTaxRateWithDefault = {} as PolicyTaxRateWithDefault, - actionTypeForParticipants = '', + actionTypeForParticipants: ActionType = undefined, ) { return getOptions(reports, personalDetails, { betas, diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index bd0214b32ed6..2ba8f32baab9 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -16,6 +16,8 @@ type AdditionalTransactionChanges = {comment?: string; waypoints?: WaypointColle type TransactionChanges = Partial & AdditionalTransactionChanges; +type IOUActionType = ValueOf | ValueOf>; + let allTransactions: OnyxCollection = {}; Onyx.connect({ @@ -80,13 +82,23 @@ function isManualRequest(transaction: Transaction): boolean { return getRequestType(transaction) === CONST.IOU.REQUEST_TYPE.MANUAL; } -function getTransactionsByActionType(actionType?: string): Array> { +/** + * Returns the type of action for the given transaction + */ +function getTransactionActionType(transaction: Transaction): IOUActionType { + if (isSplitRequest(transaction)) { + return CONST.IOU.TYPE.SPLIT; + } + return getRequestType(transaction); +} + +/** + * Returns a sorted array of transactions based on the type of action + */ +function getTransactionsByActionType(actionType?: IOUActionType): Array> { return ( Object.values(allTransactions ?? {}) - .filter( - (transaction): transaction is Transaction => - transaction != null && (actionType === CONST.IOU.TYPE.SPLIT ? isSplitRequest(transaction) : getRequestType(transaction) === actionType), - ) + .filter((transaction): transaction is Transaction => transaction != null && actionType === getTransactionActionType(transaction)) // String based sorting of dates having format [YYYY-MM-DD HH:MM:SS.mmm] .sort((transactionA, transactionB) => (transactionA?.created && transactionB?.created && transactionA?.created > transactionB?.created ? 1 : -1)) .reverse() @@ -615,4 +627,5 @@ export { getRecentTransactions, hasViolation, getTransactionsByActionType, + getTransactionActionType, }; From f34dd98f8f017da2a601cbe29bc77ee1e5358b78 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Fri, 9 Feb 2024 22:45:55 +0530 Subject: [PATCH 16/26] fix merge issues for IOUActionType --- src/libs/TransactionUtils.ts | 2 +- src/types/onyx/Transaction.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index d2e7ae17e366..843753e0b19c 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -6,7 +6,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {RecentWaypoint, Report, ReportAction, Transaction, TransactionViolation} from '@src/types/onyx'; import type {PolicyTaxRate, PolicyTaxRates} from '@src/types/onyx/PolicyTaxRates'; -import type {Comment, Receipt, TransactionChanges, Waypoint, WaypointCollection, IOUActionType} from '@src/types/onyx/Transaction'; +import type {Comment, IOUActionType, Receipt, TransactionChanges, Waypoint, WaypointCollection} from '@src/types/onyx/Transaction'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import {isCorporateCard, isExpensifyCard} from './CardUtils'; import DateUtils from './DateUtils'; diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts index b559346a48de..93f00f4944a2 100644 --- a/src/types/onyx/Transaction.ts +++ b/src/types/onyx/Transaction.ts @@ -207,5 +207,7 @@ type AdditionalTransactionChanges = { type TransactionChanges = Partial & AdditionalTransactionChanges; +type IOUActionType = ValueOf | ValueOf>; + export default Transaction; -export type {WaypointCollection, Comment, Receipt, Waypoint, ReceiptError, ReceiptErrors, TransactionPendingFieldsKey, TransactionChanges, TaxRate, ReceiptSource}; +export type {WaypointCollection, Comment, Receipt, Waypoint, ReceiptError, ReceiptErrors, TransactionPendingFieldsKey, TransactionChanges, TaxRate, ReceiptSource, IOUActionType}; From 33218759acb91fd1e6364edea209fd783592672e Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Tue, 13 Feb 2024 00:36:05 +0530 Subject: [PATCH 17/26] use parent report of task in recent list --- src/libs/OptionsListUtils.ts | 45 ++++++++++-------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index b07de962c83d..832fba9f6230 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1458,7 +1458,7 @@ function getOptions( actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.SCAN || actionTypeForParticipants === CONST.IOU.REQUEST_TYPE.DISTANCE || actionTypeForParticipants === CONST.IOU.TYPE.SPLIT); - const reportIDsForTaskReport: string[] = []; + const recentChatReportIDsForActionType: string[] = []; orderedReports.forEach((report) => { if (!report) { return; @@ -1484,9 +1484,11 @@ function getOptions( return; } - // Save the task report ids in an array for finding out recent reports based on task action type + // Collect the parent report of the given task for consideration in recent list. if (isTaskActionTypeForParticipants && isTaskReport && includeRecentReports) { - reportIDsForTaskReport.push(report.reportID); + if (report.parentReportID && ReportUtils.isValidReportIDFromPath(report.parentReportID) && recentChatReportIDsForActionType.indexOf(report.parentReportID) === -1) { + recentChatReportIDsForActionType.push(report.parentReportID); + } return; } @@ -1554,42 +1556,19 @@ function getOptions( optionsToExcludeByActions.push(...optionsToExclude); if (includeRecentReports) { - const recentChatReportIDsForActionType: string[] = []; - // During money request generation, we collect chat report ids - // of the money request report's parent for display in the recent reports list + // Collect the highest context (i.e. DM/Workspace chat) of the money request report for consideration in recent list. if (isMoneyRequestActionTypeForParticipants) { TransactionUtils.getTransactionsByActionType(actionTypeForParticipants).every((recentTransaction) => { const iouReport = ReportUtils.getReport(recentTransaction?.reportID); - if (!recentChatReportIDsForActionType.some((reportID: string) => iouReport?.parentReportID === reportID)) { - if (iouReport?.parentReportID) { - recentChatReportIDsForActionType.push(iouReport?.parentReportID); - } - } - return true; - }); - } - - // During task assignment, we collect the top most chat report ids of the task reports - // for display in the recent reports list - if (isTaskActionTypeForParticipants) { - const parentReportIDs: string[] = []; - reportIDsForTaskReport.every((taskReportID) => { - const taskReport = ReportUtils.getReport(taskReportID); - let parentReportID = taskReport?.parentReportID; - let topmostChatReportID = taskReport?.parentReportID; - while (parentReportID) { - const parentReport = ReportUtils.getReport(parentReportID); - if (parentReport?.parentReportID) { - topmostChatReportID = parentReport?.parentReportID; - } - parentReportID = parentReport?.parentReportID; - } - if (topmostChatReportID) { - parentReportIDs.push(topmostChatReportID); + if ( + iouReport?.parentReportID && + ReportUtils.isValidReportIDFromPath(iouReport?.parentReportID) && + recentChatReportIDsForActionType.indexOf(iouReport?.parentReportID) === -1 + ) { + recentChatReportIDsForActionType.push(iouReport?.parentReportID); } return true; }); - recentChatReportIDsForActionType.push(...parentReportIDs.filter((reportID, reportIDIndex) => parentReportIDs.indexOf(reportID) === reportIDIndex)); } for (const reportOption of allReportOptions) { From 5a5d986eb9474acfc77c17dea07365d05b8c0cac Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Tue, 5 Mar 2024 17:21:40 +0530 Subject: [PATCH 18/26] added timing logs --- src/CONST.ts | 1 + src/libs/OptionsListUtils.ts | 6 ++++++ .../MoneyTemporaryForRefactorRequestParticipantsSelector.js | 3 +++ 3 files changed, 10 insertions(+) diff --git a/src/CONST.ts b/src/CONST.ts index 9ed2903941b6..ea5e232a0ce0 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -771,6 +771,7 @@ const CONST = { TIMING: { CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION: 'calc_most_recent_last_modified_action', SEARCH_RENDER: 'search_render', + FILTERED_OPTIONS_DATA: 'filtered_options_data', CHAT_RENDER: 'chat_render', HOMEPAGE_INITIAL_RENDER: 'homepage_initial_render', REPORT_INITIAL_RENDER: 'report_initial_render', diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index dfcb1554babb..0e99daa13541 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1682,6 +1682,12 @@ function getOptions( recentReportOptions = [...recentReportOptionsByAction]; } + // if (recentReportOptionsByAction.length > 0) { + // console.log("recentReportOptions["+actionTypeForParticipants+"], count["+recentReportOptions.length+"]"); + // } else { + // console.log("recentReportOptions[DEFAULT], count["+recentReportOptions.length+"]"); + // } + if (includePersonalDetails) { // Next loop over all personal details removing any that are selectedUsers or recentChats allPersonalDetailsOptions.forEach((personalDetailOption) => { diff --git a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js index 2125502bfc4a..cc2f85d214dc 100644 --- a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js +++ b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js @@ -16,6 +16,7 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useSearchTermAndSearch from '@hooks/useSearchTermAndSearch'; import useThemeStyles from '@hooks/useThemeStyles'; +import Timing from '@libs/actions/Timing'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -109,6 +110,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ } let indexOffset = 0; + Timing.start(CONST.TIMING.FILTERED_OPTIONS_DATA); const chatOptions = OptionsListUtils.getFilteredOptions( reports, personalDetails, @@ -139,6 +141,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ false, actionTypeForParticipants, ); + Timing.end(CONST.TIMING.FILTERED_OPTIONS_DATA); const formatResults = OptionsListUtils.formatSectionsFromSearchTerm( searchTerm, From a9aa329110ee0d49e509621dcf58a16ab4d54a83 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Mon, 11 Mar 2024 21:03:59 +0530 Subject: [PATCH 19/26] typecheck and prettier fix --- ...oraryForRefactorRequestParticipantsSelector.js | 15 ++++++++++++++- src/pages/tasks/TaskAssigneeSelectorModal.tsx | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js index 32ef4f76b516..4ec3b3779659 100644 --- a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js +++ b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js @@ -188,7 +188,20 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ } return [newSections, chatOptions]; - }, [didScreenTransitionEnd, reports, personalDetails, betas, searchTerm, participants, iouType, iouRequestType, maxParticipantsReached, canUseP2PDistanceRequests, translate, actionTypeForParticipants]); + }, [ + didScreenTransitionEnd, + reports, + personalDetails, + betas, + searchTerm, + participants, + iouType, + iouRequestType, + maxParticipantsReached, + canUseP2PDistanceRequests, + translate, + actionTypeForParticipants, + ]); /** * Adds a single participant to the request diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.tsx b/src/pages/tasks/TaskAssigneeSelectorModal.tsx index 0e45b473633e..393f19272e38 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.tsx +++ b/src/pages/tasks/TaskAssigneeSelectorModal.tsx @@ -27,7 +27,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {Report, Task} from '@src/types/onyx'; +import type {Report, Task, TaxRatesWithDefault} from '@src/types/onyx'; type TaskAssigneeSelectorModalOnyxProps = { /** All reports shared with the user */ @@ -68,7 +68,7 @@ function useOptions({reports}: UseOptions) { true, false, false, - {}, + {} as TaxRatesWithDefault, false, CONST.REPORT.TYPE.TASK, ); From 7f76198c434d9afbc361552d95db286b3d02333a Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Mon, 11 Mar 2024 21:28:37 +0530 Subject: [PATCH 20/26] removal of temporary code relating to timing logs --- src/CONST.ts | 1 - src/libs/OptionsListUtils.ts | 6 ------ .../MoneyTemporaryForRefactorRequestParticipantsSelector.js | 3 --- 3 files changed, 10 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 79ddc6414790..a903adb8b84b 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -790,7 +790,6 @@ const CONST = { TIMING: { CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION: 'calc_most_recent_last_modified_action', SEARCH_RENDER: 'search_render', - FILTERED_OPTIONS_DATA: 'filtered_options_data', CHAT_RENDER: 'chat_render', HOMEPAGE_INITIAL_RENDER: 'homepage_initial_render', REPORT_INITIAL_RENDER: 'report_initial_render', diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 0eacd24a663e..c4934045b081 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1679,12 +1679,6 @@ function getOptions( recentReportOptions = [...recentReportOptionsByAction]; } - // if (recentReportOptionsByAction.length > 0) { - // console.log("recentReportOptions["+actionTypeForParticipants+"], count["+recentReportOptions.length+"]"); - // } else { - // console.log("recentReportOptions[DEFAULT], count["+recentReportOptions.length+"]"); - // } - if (includePersonalDetails) { // Next loop over all personal details removing any that are selectedUsers or recentChats allPersonalDetailsOptions.forEach((personalDetailOption) => { diff --git a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js index 4ec3b3779659..e79af0fe68e1 100644 --- a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js +++ b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js @@ -17,7 +17,6 @@ import useNetwork from '@hooks/useNetwork'; import usePermissions from '@hooks/usePermissions'; import useSearchTermAndSearch from '@hooks/useSearchTermAndSearch'; import useThemeStyles from '@hooks/useThemeStyles'; -import Timing from '@libs/actions/Timing'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -112,7 +111,6 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ } let indexOffset = 0; - Timing.start(CONST.TIMING.FILTERED_OPTIONS_DATA); const chatOptions = OptionsListUtils.getFilteredOptions( reports, personalDetails, @@ -139,7 +137,6 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ false, actionTypeForParticipants, ); - Timing.end(CONST.TIMING.FILTERED_OPTIONS_DATA); const formatResults = OptionsListUtils.formatSectionsFromSearchTerm( searchTerm, From b51298ed84840cf882baa5f7aaf5bc71e901bae2 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Tue, 12 Mar 2024 00:05:33 +0530 Subject: [PATCH 21/26] Update src/libs/TransactionUtils.ts Co-authored-by: Muhammad Hur Ali --- src/libs/TransactionUtils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 6af8708d79b6..7bce4b59e164 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -97,8 +97,7 @@ function getTransactionsByActionType(actionType?: IOUActionType): Array transaction != null && actionType === getTransactionActionType(transaction)) // String based sorting of dates having format [YYYY-MM-DD HH:MM:SS.mmm] - .sort((transactionA, transactionB) => (transactionA?.created && transactionB?.created && transactionA?.created > transactionB?.created ? 1 : -1)) - .reverse() + .sort((transactionA, transactionB) => (transactionA?.created && transactionB?.created && transactionA?.created < transactionB?.created ? 1 : -1)) ); } From 5180407a8b0695dc9f7cdb7f38109d976b03b275 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 3 Apr 2024 12:00:51 +0530 Subject: [PATCH 22/26] prettier fix --- ...oraryForRefactorRequestParticipantsSelector.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js index 30a2977af900..da1511dbd3ed 100644 --- a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js +++ b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js @@ -180,7 +180,20 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ } return [newSections, chatOptions]; - }, [didScreenTransitionEnd, reports, personalDetails, betas, debouncedSearchTerm, participants, iouType, canUseP2PDistanceRequests, iouRequestType, maxParticipantsReached, translate, actionTypeForParticipants]); + }, [ + didScreenTransitionEnd, + reports, + personalDetails, + betas, + debouncedSearchTerm, + participants, + iouType, + canUseP2PDistanceRequests, + iouRequestType, + maxParticipantsReached, + translate, + actionTypeForParticipants, + ]); /** * Adds a single participant to the request From 78374dc44e8e1a3313bc72be312c25fd98ae2ed5 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Sun, 7 Apr 2024 23:00:22 +0530 Subject: [PATCH 23/26] task selector fix --- src/pages/tasks/TaskAssigneeSelectorModal.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.tsx b/src/pages/tasks/TaskAssigneeSelectorModal.tsx index 29bf2579e03d..7406dc6c16d2 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.tsx +++ b/src/pages/tasks/TaskAssigneeSelectorModal.tsx @@ -69,7 +69,10 @@ function useOptions() { false, {} as TaxRatesWithDefault, false, - CONST.REPORT.TYPE.TASK, + false, + [], + [], + CONST.REPORT.TYPE.TASK, ); const headerMessage = OptionsListUtils.getHeaderMessage( From 29d68b4392f3934999da9c71888f8cd09b478841 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Sun, 7 Apr 2024 23:09:25 +0530 Subject: [PATCH 24/26] typecheck fix for recentReportOptions --- src/libs/OptionsListUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 251e6c2cf43f..948d6a59d8d0 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1599,7 +1599,7 @@ function getOptions( }; } - const recentReportOptionsByAction = []; + const recentReportOptionsByAction: ReportUtils.OptionData[] = []; const parsedPhoneNumber = PhoneNumber.parsePhoneNumber(LoginUtils.appendCountryCode(Str.removeSMSDomain(searchInputValue))); const searchValue = parsedPhoneNumber.possible ? parsedPhoneNumber.number?.e164 : searchInputValue.toLowerCase(); const topmostReportId = Navigation.getTopmostReportId() ?? ''; @@ -1731,7 +1731,7 @@ function getOptions( const optionsToExcludeByActions: Option[] = []; optionsToExcludeByActions.push(...optionsToExclude); - let recentReportOptions = []; + let recentReportOptions: ReportUtils.OptionData[] = []; let personalDetailsOptions: ReportUtils.OptionData[] = []; if (includeRecentReports) { // Collect the highest context (i.e. DM/Workspace chat) of the money request report for consideration in recent list. From 92bec33d6d43b40f8edcc1a6d4e09430fa498fcd Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Mon, 8 Apr 2024 15:26:25 +0530 Subject: [PATCH 25/26] fix for split request and prettier fix --- src/libs/OptionsListUtils.ts | 6 +++--- .../MoneyTemporaryForRefactorRequestParticipantsSelector.js | 4 ++-- src/pages/tasks/TaskAssigneeSelectorModal.tsx | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 948d6a59d8d0..efe1c1ff81cf 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1540,7 +1540,7 @@ function getOptions( includePolicyReportFieldOptions = false, policyReportFieldOptions = [], recentlyUsedPolicyReportFieldOptions = [], - actionTypeForParticipants, + actionTypeForParticipants, }: GetOptionsConfig, ): GetOptions { if (includeCategories) { @@ -1827,7 +1827,7 @@ function getOptions( } } } - + // Let us reset the recent list and the options to exclude if we have found // recent reports by action type for setting personal details and for search results. if (recentReportOptionsByAction.length > 0) { @@ -2044,7 +2044,7 @@ function getFilteredOptions( includePolicyReportFieldOptions = false, policyReportFieldOptions: string[] = [], recentlyUsedPolicyReportFieldOptions: string[] = [], - actionTypeForParticipants: ActionType = undefined, + actionTypeForParticipants: ActionType = undefined, ) { return getOptions( {reports, personalDetails}, diff --git a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js index 16142bea3a27..c70aee350db8 100644 --- a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js +++ b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js @@ -94,7 +94,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ const offlineMessage = isOffline ? [`${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}`, {isTranslated: true}] : ''; const maxParticipantsReached = participants.length === CONST.REPORT.MAXIMUM_PARTICIPANTS; - const actionTypeForParticipants = iouType === CONST.IOU.TYPE.REQUEST && participants.length > 0 ? CONST.IOU.TYPE.SPLIT : iouRequestType; + const actionTypeForParticipants = iouType === CONST.IOU.TYPE.SPLIT ? CONST.IOU.TYPE.SPLIT : iouRequestType; useEffect(() => { Report.searchInServer(debouncedSearchTerm.trim()); @@ -137,7 +137,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ false, [], [], - actionTypeForParticipants, + actionTypeForParticipants, ); const formatResults = OptionsListUtils.formatSectionsFromSearchTerm( diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.tsx b/src/pages/tasks/TaskAssigneeSelectorModal.tsx index 7406dc6c16d2..ffa59eeccdaf 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.tsx +++ b/src/pages/tasks/TaskAssigneeSelectorModal.tsx @@ -72,7 +72,7 @@ function useOptions() { false, [], [], - CONST.REPORT.TYPE.TASK, + CONST.REPORT.TYPE.TASK, ); const headerMessage = OptionsListUtils.getHeaderMessage( From 04bffab77455fb81424dc67606d96389e36c341a Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 24 Apr 2024 10:24:13 +0530 Subject: [PATCH 26/26] Resolving merge conflict --- src/pages/tasks/TaskAssigneeSelectorModal.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.tsx b/src/pages/tasks/TaskAssigneeSelectorModal.tsx index 388901d59722..5e28d8c45151 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.tsx +++ b/src/pages/tasks/TaskAssigneeSelectorModal.tsx @@ -72,6 +72,7 @@ function useOptions() { false, [], [], + true, CONST.REPORT.TYPE.TASK, );