Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RBR transaction thread is disappearing from the LHN when navigating to another chat #41507

Merged
merged 10 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
20 changes: 13 additions & 7 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,17 @@ function getUserToInviteOption({
return userToInvite;
}

/**
* check whether report has violations
tienifr marked this conversation as resolved.
Show resolved Hide resolved
*/
function checkReportHasViolations(report: Report, betas: OnyxEntry<Beta[]>, transactionViolations: OnyxCollection<TransactionViolation[]>) {
tienifr marked this conversation as resolved.
Show resolved Hide resolved
const {parentReportID, parentReportActionID} = report ?? {};
tienifr marked this conversation as resolved.
Show resolved Hide resolved
const canGetParentReport = parentReportID && parentReportActionID && allReportActions;
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;
}

/**
* filter options based on specific conditions
*/
Expand Down Expand Up @@ -1756,13 +1767,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 parentReportActions = allReportActions ? allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`] ?? {} : {};
const parentReportAction = canGetParentReport ? parentReportActions[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,
Expand Down Expand Up @@ -2444,6 +2449,7 @@ export {
getTaxRatesSection,
getFirstKeyForList,
getUserToInviteOption,
checkReportHasViolations,
};

export type {MemberForList, CategorySection, CategoryTreeSection, Options, OptionList, SearchOption, PayeePersonalDetails, Category, Tax, TaxRatesOption, Option, OptionTree};
58 changes: 35 additions & 23 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,39 +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<ChatReportSelector & {hasErrorsOtherThanFailedReceipt?: boolean}> = [];

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<ReportAction>)
);
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) {
reportsToDisplay.push({
...report,
hasErrorsOtherThanFailedReceipt: true,
});
return;
}

if (isHidden && !shouldOverrideHidden) {
return false;
return;
}

return ReportUtils.shouldReportBeInOptionList({
report,
currentReportId: currentReportId ?? '',
isInFocusMode,
betas,
policies: policies as OnyxCollection<Policy>,
excludeEmptyChats: true,
doesReportHaveViolations,
includeSelfDM: true,
});
if (
ReportUtils.shouldReportBeInOptionList({
report,
currentReportId: currentReportId ?? '',
isInFocusMode,
betas,
policies: policies as OnyxCollection<Policy>,
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:
Expand All @@ -129,6 +136,7 @@ function getOrderedReportIDs(
const draftReports: Array<OnyxEntry<Report>> = [];
const nonArchivedReports: Array<OnyxEntry<Report>> = [];
const archivedReports: Array<OnyxEntry<Report>> = [];
const errorReports: Array<OnyxEntry<Report>> = [];

if (currentPolicyID || policyMemberAccountIDs.length > 0) {
reportsToDisplay = reportsToDisplay.filter(
Expand All @@ -137,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<Report>;
let report = reportToDisplay;
if (report) {
report = {
...report,
Expand All @@ -153,13 +161,17 @@ function getOrderedReportIDs(
draftReports.push(report);
} else if (ReportUtils.isArchivedRoom(report)) {
archivedReports.push(report);
} else if (report?.hasErrorsOtherThanFailedReceipt) {
errorReports.push(report);
} else {
nonArchivedReports.push(report);
}
});

// 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) {
Expand All @@ -180,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;
}

Expand Down
Loading