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

[NoQA] Add policyID to getOrderedReportIDs and sortReportsByLastRead #33302

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
11 changes: 8 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,15 @@ function isDraftExpenseReport(report: OnyxEntry<Report>): boolean {
}

/**
* Given a collection of reports returns them sorted by last read
* Given a collection of reports returns them sorted by last read and optionally filtered by a specific policyID.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Given a collection of reports returns them sorted by last read and optionally filtered by a specific policyID.
* Given a collection of reports, return them sorted by the last read timestamp. Filters the sorted reports by a policy ID, if provided.

*/
function sortReportsByLastRead(reports: OnyxCollection<Report>): Array<OnyxEntry<Report>> {
return Object.values(reports ?? {})
function sortReportsByLastRead(reports: OnyxCollection<Report>, policyID?: string): Array<OnyxEntry<Report>> {
let reportsValues = Object.values(reports ?? {});
if (policyID) {
reportsValues = reportsValues.filter((report) => report?.policyID === policyID);
}

return reportsValues
.filter((report) => !!report?.reportID && !!report?.lastReadTime)
.sort((a, b) => {
const aTime = new Date(a?.lastReadTime ?? '');
Expand Down
9 changes: 7 additions & 2 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ function getOrderedReportIDs(
policies: Record<string, Policy>,
priorityMode: ValueOf<typeof CONST.PRIORITY_MODE>,
allReportActions: OnyxCollection<ReportAction[]>,
currentPolicyID = '',
): string[] {
// Generate a unique cache key based on the function arguments
const cachedReportsKey = JSON.stringify(
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
[currentReportId, allReports, betas, policies, priorityMode, allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentReportId}`]?.length || 1],
[currentPolicyID, currentReportId, allReports, betas, policies, priorityMode, allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentReportId}`]?.length || 1],
(key, value: unknown) => {
/**
* Exclude 'participantAccountIDs', 'participants' and 'lastMessageText' not to overwhelm a cached key value with huge data,
Expand All @@ -149,7 +150,7 @@ function getOrderedReportIDs(
const isInDefaultMode = !isInGSDMode;
const allReportsDictValues = Object.values(allReports);
// Filter out all the reports that shouldn't be displayed
const reportsToDisplay = allReportsDictValues.filter((report) => ReportUtils.shouldReportBeInOptionList(report, currentReportId ?? '', isInGSDMode, betas, policies, true));
let reportsToDisplay = allReportsDictValues.filter((report) => ReportUtils.shouldReportBeInOptionList(report, currentReportId ?? '', isInGSDMode, betas, policies, true));

if (reportsToDisplay.length === 0) {
// Display Concierge chat report when there is no report to be displayed
Expand All @@ -173,6 +174,10 @@ function getOrderedReportIDs(
const nonArchivedReports: Report[] = [];
const archivedReports: Report[] = [];

if (currentPolicyID) {
reportsToDisplay = reportsToDisplay.filter((report) => report.policyID === currentPolicyID);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi 👋 Coming from #35963

When the IOU report and details page are not highlighted in the LHN, the filter removes the current viewed report. So to fix it we decided to add a check where it's past the currently viewed report.


// There are a few properties that need to be calculated for the report which are used when sorting reports.
reportsToDisplay.forEach((report) => {
// Normally, the spread operator would be used here to clone the report and prevent the need to reassign the params.
Expand Down
Loading