From d5e45aab90bac223ac8fa9716363c019dfccfc97 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 2 May 2024 21:55:32 +0700 Subject: [PATCH 1/6] RBR transaction thread is disappearing from the LHN when navigating to another chat --- src/libs/SidebarUtils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index c0d0c9020a64..e837130e12b0 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -96,6 +96,10 @@ function getOrderedReportIDs( const allReportErrors = OptionsListUtils.getAllReportErrors(report, reportActions) ?? {}; const hasErrorsOtherThanFailedReceipt = doesReportHaveViolations || Object.values(allReportErrors).some((error) => error?.[0] !== 'report.genericSmartscanFailureMessage'); const shouldOverrideHidden = hasErrorsOtherThanFailedReceipt || isFocused || report.isPinned; + if (hasErrorsOtherThanFailedReceipt) { + return true; + } + if (isHidden && !shouldOverrideHidden) { return false; } From b9808e7f4ac9582d9b3a57a448db6b774cb7f8fb Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 2 May 2024 22:19:40 +0700 Subject: [PATCH 2/6] lint fix --- src/libs/SidebarUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index e837130e12b0..40c032bb3e55 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -99,7 +99,7 @@ function getOrderedReportIDs( if (hasErrorsOtherThanFailedReceipt) { return true; } - + if (isHidden && !shouldOverrideHidden) { return false; } From 013863e7bb76fd05370f5021de54c6abaf548853 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 20 May 2024 15:00:36 +0700 Subject: [PATCH 3/6] show rbr transaction thread --- src/libs/OptionsListUtils.ts | 19 +++++++----- src/libs/SidebarUtils.ts | 56 ++++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 544ced533e82..481d1a0431f9 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1636,6 +1636,16 @@ function getUserToInviteOption({ return userToInvite; } +/** + * check whether report has violations + */ +function checkReportHasViolations(report: Report, betas: OnyxEntry, transactionViolations: OnyxCollection) { + const {parentReportID, parentReportActionID} = report ?? {}; + const canGetParentReport = parentReportID && parentReportActionID && allReportActions; + const parentReportAction = canGetParentReport ? allReportActions[parentReportID]?.[parentReportActionID] ?? null : null; + return (Permissions.canUseViolations(betas) && !!parentReportAction && ReportUtils.shouldDisplayTransactionThreadViolations(report, transactionViolations, parentReportAction)) ?? false; +} + /** * filter options based on specific conditions */ @@ -1743,13 +1753,7 @@ function getOptions( // Filter out all the reports that shouldn't be displayed const filteredReportOptions = options.reports.filter((option) => { const report = option.item; - - const {parentReportID, parentReportActionID} = report ?? {}; - const canGetParentReport = parentReportID && parentReportActionID && allReportActions; - const parentReportAction = canGetParentReport ? allReportActions[parentReportID]?.[parentReportActionID] ?? null : null; - const doesReportHaveViolations = - (betas?.includes(CONST.BETAS.VIOLATIONS) && ReportUtils.doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction)) ?? false; - + const doesReportHaveViolations = checkReportHasViolations(report, betas, transactionViolations); return ReportUtils.shouldReportBeInOptionList({ report, currentReportId: topmostReportId, @@ -2430,6 +2434,7 @@ export { getTaxRatesSection, getFirstKeyForList, getUserToInviteOption, + checkReportHasViolations, }; export type {MemberForList, CategorySection, CategoryTreeSection, Options, OptionList, SearchOption, PayeePersonalDetails, Category, Tax, TaxRatesOption, Option, OptionTree}; diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index fd7dbc2eb348..4cc29861c47d 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -81,43 +81,46 @@ function getOrderedReportIDs( const allReportsDictValues = Object.values(allReports ?? {}); // Filter out all the reports that shouldn't be displayed - let reportsToDisplay = allReportsDictValues.filter((report) => { + let reportsToDisplay: Array = []; + + allReportsDictValues.forEach((report) => { if (!report) { - return false; + return; } - const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`; - const parentReportActions = allReportActions?.[parentReportActionsKey]; const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`] ?? {}; - const parentReportAction = parentReportActions?.find((action) => action && action?.reportActionID === report.parentReportActionID); - const doesReportHaveViolations = !!( - betas?.includes(CONST.BETAS.VIOLATIONS) && - !!parentReportAction && - ReportUtils.doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction as OnyxEntry) - ); + const doesReportHaveViolations = OptionsListUtils.checkReportHasViolations(report, betas, transactionViolations); const isHidden = report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; const isFocused = report.reportID === currentReportId; const allReportErrors = OptionsListUtils.getAllReportErrors(report, reportActions) ?? {}; const hasErrorsOtherThanFailedReceipt = doesReportHaveViolations || Object.values(allReportErrors).some((error) => error?.[0] !== 'report.genericSmartscanFailureMessage'); const shouldOverrideHidden = hasErrorsOtherThanFailedReceipt || isFocused || report.isPinned; if (hasErrorsOtherThanFailedReceipt) { - return true; + reportsToDisplay.push({ + ...report, + hasErrorsOtherThanFailedReceipt: true, + }); + return; } if (isHidden && !shouldOverrideHidden) { - return false; + return; } - return ReportUtils.shouldReportBeInOptionList({ - report, - currentReportId: currentReportId ?? '', - isInFocusMode, - betas, - policies: policies as OnyxCollection, - excludeEmptyChats: true, - doesReportHaveViolations, - includeSelfDM: true, - }); + if ( + ReportUtils.shouldReportBeInOptionList({ + report, + currentReportId: currentReportId ?? '', + isInFocusMode, + betas, + policies: policies as OnyxCollection, + excludeEmptyChats: true, + doesReportHaveViolations, + includeSelfDM: true, + }) + ) { + reportsToDisplay.push(report); + } }); // The LHN is split into four distinct groups, and each group is sorted a little differently. The groups will ALWAYS be in this order: @@ -133,6 +136,7 @@ function getOrderedReportIDs( const draftReports: Array> = []; const nonArchivedReports: Array> = []; const archivedReports: Array> = []; + const errorReports: Array> = []; if (currentPolicyID || policyMemberAccountIDs.length > 0) { reportsToDisplay = reportsToDisplay.filter( @@ -141,7 +145,7 @@ function getOrderedReportIDs( } // There are a few properties that need to be calculated for the report which are used when sorting reports. reportsToDisplay.forEach((reportToDisplay) => { - let report = reportToDisplay as OnyxEntry; + let report = reportToDisplay; if (report) { report = { ...report, @@ -157,6 +161,8 @@ function getOrderedReportIDs( draftReports.push(report); } else if (ReportUtils.isArchivedRoom(report)) { archivedReports.push(report); + } else if (report?.hasErrorsOtherThanFailedReceipt) { + errorReports.push(report); } else { nonArchivedReports.push(report); } @@ -164,6 +170,8 @@ function getOrderedReportIDs( // Sort each group of reports accordingly pinnedAndGBRReports.sort((a, b) => (a?.displayName && b?.displayName ? localeCompare(a.displayName, b.displayName) : 0)); + errorReports.sort((a, b) => (a?.displayName && b?.displayName ? localeCompare(a.displayName, b.displayName) : 0)); + draftReports.sort((a, b) => (a?.displayName && b?.displayName ? localeCompare(a.displayName, b.displayName) : 0)); if (isInDefaultMode) { @@ -184,7 +192,7 @@ function getOrderedReportIDs( // Now that we have all the reports grouped and sorted, they must be flattened into an array and only return the reportID. // The order the arrays are concatenated in matters and will determine the order that the groups are displayed in the sidebar. - const LHNReports = [...pinnedAndGBRReports, ...draftReports, ...nonArchivedReports, ...archivedReports].map((report) => report?.reportID ?? ''); + const LHNReports = [...pinnedAndGBRReports, ...errorReports, ...draftReports, ...nonArchivedReports, ...archivedReports].map((report) => report?.reportID ?? ''); return LHNReports; } From 3073d7c3d10fdadab93f021167d4b3863ba4db44 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 20 May 2024 17:44:42 +0700 Subject: [PATCH 4/6] fix test --- src/libs/SidebarUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 4cc29861c47d..3ebf5ab5783a 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -89,7 +89,7 @@ function getOrderedReportIDs( } const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`] ?? {}; - const doesReportHaveViolations = OptionsListUtils.checkReportHasViolations(report, betas, transactionViolations); + const doesReportHaveViolations = OptionsListUtils.checkReportHasViolations(report, betas ?? [], transactionViolations); const isHidden = report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; const isFocused = report.reportID === currentReportId; const allReportErrors = OptionsListUtils.getAllReportErrors(report, reportActions) ?? {}; From 6d28766569f0ecc749cd01fbf1663e4181f17e63 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 27 May 2024 11:05:11 +0700 Subject: [PATCH 5/6] clean code --- src/libs/OptionsListUtils.ts | 18 ++++++++++++------ src/libs/SidebarUtils.ts | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index ac5799a120bb..bc5665c3d400 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1650,14 +1650,20 @@ function getUserToInviteOption({ } /** - * check whether report has violations + * Check whether report has violations */ -function checkReportHasViolations(report: Report, betas: OnyxEntry, transactionViolations: OnyxCollection) { +function shouldShowViolations(report: Report, betas: OnyxEntry, transactionViolations: OnyxCollection) { + if (!Permissions.canUseViolations(betas)) { + return false; + } const {parentReportID, parentReportActionID} = report ?? {}; const canGetParentReport = parentReportID && parentReportActionID && allReportActions; + if (!canGetParentReport) { + return false; + } const parentReportActions = allReportActions ? allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`] ?? {} : {}; - const parentReportAction = canGetParentReport ? parentReportActions[parentReportActionID] ?? null : null; - return (Permissions.canUseViolations(betas) && !!parentReportAction && ReportUtils.shouldDisplayTransactionThreadViolations(report, transactionViolations, parentReportAction)) ?? false; + const parentReportAction = parentReportActions[parentReportActionID] ?? null; + return (!!parentReportAction && ReportUtils.shouldDisplayTransactionThreadViolations(report, transactionViolations, parentReportAction)) ?? false; } /** @@ -1767,7 +1773,7 @@ function getOptions( // Filter out all the reports that shouldn't be displayed const filteredReportOptions = options.reports.filter((option) => { const report = option.item; - const doesReportHaveViolations = checkReportHasViolations(report, betas, transactionViolations); + const doesReportHaveViolations = shouldShowViolations(report, betas, transactionViolations); return ReportUtils.shouldReportBeInOptionList({ report, @@ -2449,7 +2455,7 @@ export { getTaxRatesSection, getFirstKeyForList, getUserToInviteOption, - checkReportHasViolations, + shouldShowViolations, }; export type {MemberForList, CategorySection, CategoryTreeSection, Options, OptionList, SearchOption, PayeePersonalDetails, Category, Tax, TaxRatesOption, Option, OptionTree}; diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 3ebf5ab5783a..543d6228506d 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -89,7 +89,7 @@ function getOrderedReportIDs( } const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`] ?? {}; - const doesReportHaveViolations = OptionsListUtils.checkReportHasViolations(report, betas ?? [], transactionViolations); + const doesReportHaveViolations = OptionsListUtils.shouldShowViolations(report, betas ?? [], transactionViolations); const isHidden = report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; const isFocused = report.reportID === currentReportId; const allReportErrors = OptionsListUtils.getAllReportErrors(report, reportActions) ?? {}; From f7778aaa3736c7f92974fd748a5824d9c5e925eb Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 30 May 2024 09:51:27 +0700 Subject: [PATCH 6/6] fail fast --- src/libs/OptionsListUtils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index bc5665c3d400..f67f9b4dd844 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1663,7 +1663,10 @@ function shouldShowViolations(report: Report, betas: OnyxEntry, transact } const parentReportActions = allReportActions ? allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`] ?? {} : {}; const parentReportAction = parentReportActions[parentReportActionID] ?? null; - return (!!parentReportAction && ReportUtils.shouldDisplayTransactionThreadViolations(report, transactionViolations, parentReportAction)) ?? false; + if (!parentReportAction) { + return false; + } + return ReportUtils.shouldDisplayTransactionThreadViolations(report, transactionViolations, parentReportAction); } /**