Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/hooks/useSidebarOrderedReports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type SidebarOrderedReportsContextValue = {
clearLHNCache: () => void;
};

type ReportsToDisplayInLHN = Record<string, OnyxTypes.Report & {hasErrorsOtherThanFailedReceipt?: boolean}>;
type ReportsToDisplayInLHN = Record<string, OnyxTypes.Report & {hasErrorsOtherThanFailedReceipt?: boolean; requiresAttention?: boolean}>;

const SidebarOrderedReportsContext = createContext<SidebarOrderedReportsContextValue>({
orderedReports: [],
Expand Down Expand Up @@ -230,7 +230,7 @@ function SidebarOrderedReportsContextProvider({
}, [reportsToDisplayInLHN]);

const getOrderedReportIDs = useCallback(
() => SidebarUtils.sortReportsToDisplayInLHN(deepComparedReportsToDisplayInLHN ?? {}, priorityMode, localeCompare, deepComparedReportsDrafts, reportNameValuePairs, reportAttributes),
() => SidebarUtils.sortReportsToDisplayInLHN(deepComparedReportsToDisplayInLHN ?? {}, priorityMode, localeCompare, deepComparedReportsDrafts, reportNameValuePairs),
// Rule disabled intentionally - reports should be sorted only when the reportsToDisplayInLHN changes
// eslint-disable-next-line react-hooks/exhaustive-deps
[deepComparedReportsToDisplayInLHN, localeCompare, deepComparedReportsDrafts],
Expand Down
20 changes: 9 additions & 11 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ function getReportsToDisplayInLHN(
);

if (shouldDisplay) {
reportsToDisplay[reportID] = hasErrorsOtherThanFailedReceipt ? {...report, hasErrorsOtherThanFailedReceipt: true} : report;
const requiresAttention = reportAttributes?.[report?.reportID]?.requiresAttention ?? false;
const hasAttentionOrError = requiresAttention || hasErrorsOtherThanFailedReceipt;
reportsToDisplay[reportID] = hasAttentionOrError ? {...report, requiresAttention, hasErrorsOtherThanFailedReceipt} : report;
}
}

Expand Down Expand Up @@ -339,7 +341,9 @@ function updateReportsToDisplayInLHN({
);

if (shouldDisplay) {
displayedReportsCopy[reportID] = hasErrorsOtherThanFailedReceipt ? {...report, hasErrorsOtherThanFailedReceipt: true} : report;
const requiresAttention = reportAttributes?.[report?.reportID]?.requiresAttention ?? false;
const hasAttentionOrError = requiresAttention || hasErrorsOtherThanFailedReceipt;
displayedReportsCopy[reportID] = hasAttentionOrError ? {...report, requiresAttention, hasErrorsOtherThanFailedReceipt} : report;
} else {
delete displayedReportsCopy[reportID];
}
Expand All @@ -350,12 +354,7 @@ function updateReportsToDisplayInLHN({
/**
* Categorizes reports into their respective LHN groups
*/
function categorizeReportsForLHN(
reportsToDisplay: ReportsToDisplayInLHN,
reportsDrafts: OnyxCollection<string> | undefined,
reportNameValuePairs?: OnyxCollection<ReportNameValuePairs>,
reportAttributes?: ReportAttributesDerivedValue['reports'],
) {
function categorizeReportsForLHN(reportsToDisplay: ReportsToDisplayInLHN, reportsDrafts: OnyxCollection<string> | undefined, reportNameValuePairs?: OnyxCollection<ReportNameValuePairs>) {
const pinnedAndGBRReports: MiniReport[] = [];
const errorReports: MiniReport[] = [];
const draftReports: MiniReport[] = [];
Expand Down Expand Up @@ -389,7 +388,7 @@ function categorizeReportsForLHN(
};

const isPinned = !!report.isPinned;
const requiresAttention = !!reportAttributes?.[reportID]?.requiresAttention;
const requiresAttention = !!report?.requiresAttention;
const draftComment = reportsDrafts?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`];
const hasDraft = !!draftComment;
const reportNameValuePairsKey = `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`;
Expand Down Expand Up @@ -517,7 +516,6 @@ function sortReportsToDisplayInLHN(
localeCompare: LocaleContextProps['localeCompare'],
reportsDrafts: OnyxCollection<string> | undefined,
reportNameValuePairs?: OnyxCollection<ReportNameValuePairs>,
reportAttributes?: ReportAttributesDerivedValue['reports'],
): string[] {
Performance.markStart(CONST.TIMING.GET_ORDERED_REPORT_IDS);

Expand All @@ -535,7 +533,7 @@ function sortReportsToDisplayInLHN(
// - Sorted by reportDisplayName in GSD (focus) view mode

// Step 1: Categorize reports
const categories = categorizeReportsForLHN(reportsToDisplay, reportsDrafts, reportNameValuePairs, reportAttributes);
const categories = categorizeReportsForLHN(reportsToDisplay, reportsDrafts, reportNameValuePairs);

// Step 2: Sort each category
const sortedCategories = sortCategorizedReports(categories, isInDefaultMode, localeCompare);
Expand Down
17 changes: 4 additions & 13 deletions tests/unit/SidebarUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2276,15 +2276,15 @@ describe('SidebarUtils', () => {
describe('sortReportsToDisplayInLHN', () => {
describe('categorizeReportsForLHN', () => {
it('should categorize reports into correct groups', () => {
const {reports, reportNameValuePairs, reportAttributes} = createSidebarTestData();
const {reports, reportNameValuePairs} = createSidebarTestData();

// Given reportsDrafts contains a draft comment for report '2'
const reportsDrafts = {
[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}2`]: 'test',
};

// When the reports are categorized
const result = SidebarUtils.categorizeReportsForLHN(reports, reportsDrafts, reportNameValuePairs, reportAttributes);
const result = SidebarUtils.categorizeReportsForLHN(reports, reportsDrafts, reportNameValuePairs);

// Then the reports are categorized into the correct groups
expect(result.pinnedAndGBRReports).toHaveLength(1);
Expand All @@ -2306,21 +2306,12 @@ describe('SidebarUtils', () => {
reportName: 'Attention Report',
isPinned: false,
hasErrorsOtherThanFailedReceipt: false,
},
]);

const reportAttributes = {
'0': {
requiresAttention: true,
reportName: 'Test Report',
isEmpty: false,
brickRoadStatus: undefined,
reportErrors: {} as Record<string, string | null>,
},
};
]);

// When the reports are categorized
const result = SidebarUtils.categorizeReportsForLHN(reports, undefined, undefined, reportAttributes);
const result = SidebarUtils.categorizeReportsForLHN(reports, undefined, undefined);

// Then the reports are categorized into the correct groups
expect(result.pinnedAndGBRReports).toHaveLength(1);
Expand Down
1 change: 0 additions & 1 deletion tests/unit/useSidebarOrderedReportsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ describe('useSidebarOrderedReports', () => {
expect.any(Function), // localeCompare
expect.any(Object), // reportsDrafts
expect.any(Object), // reportNameValuePairs
expect.any(Object), // reportAttributes
);
});

Expand Down
7 changes: 5 additions & 2 deletions tests/utils/collections/sidebarReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ function createSidebarReport(
type?: ValueOf<typeof CONST.REPORT.TYPE>;
isPinned?: boolean;
hasErrorsOtherThanFailedReceipt?: boolean;
requiresAttention?: boolean;
lastVisibleActionCreated?: string;
isOwnPolicyExpenseChat?: boolean;
chatType?: ValueOf<typeof CONST.REPORT.CHAT_TYPE>;
ownerAccountID?: number;
policyID?: string;
currency?: string;
} = {},
): Report & {hasErrorsOtherThanFailedReceipt?: boolean} {
): Report & {hasErrorsOtherThanFailedReceipt?: boolean; requiresAttention?: boolean} {
const reportID = index.toString();
const baseReport = createRandomReport(index, options.chatType ?? CONST.REPORT.CHAT_TYPE.POLICY_ROOM);

Expand All @@ -35,6 +36,7 @@ function createSidebarReport(
type: options.type ?? CONST.REPORT.TYPE.CHAT,
isPinned: options.isPinned ?? false,
hasErrorsOtherThanFailedReceipt: options.hasErrorsOtherThanFailedReceipt ?? false,
requiresAttention: options.requiresAttention ?? false,
lastVisibleActionCreated: options.lastVisibleActionCreated ?? '2024-01-01 10:00:00',
isOwnPolicyExpenseChat: options.isOwnPolicyExpenseChat ?? false,
ownerAccountID: options.ownerAccountID ?? index,
Expand All @@ -58,9 +60,10 @@ function createSidebarReportsCollection(
ownerAccountID?: number;
policyID?: string;
currency?: string;
requiresAttention?: boolean;
}>,
): ReportsToDisplayInLHN {
return createCollection<Report & {hasErrorsOtherThanFailedReceipt?: boolean}>(
return createCollection<Report & {hasErrorsOtherThanFailedReceipt?: boolean; requiresAttention?: boolean}>(
(item) => item.reportID,
(index) => createSidebarReport(index, reportConfigs.at(index) ?? {}),
reportConfigs.length,
Expand Down
Loading