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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand",
"perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure",
"typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=280 --cache --cache-location=node_modules/.cache/eslint",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=278 --cache --cache-location=node_modules/.cache/eslint",
"lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh",
"lint-watch": "npx eslint-watch --watch --changed",
"shellcheck": "./scripts/shellCheck.sh",
Expand Down
34 changes: 16 additions & 18 deletions src/libs/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,8 @@

const TRANSACTION_VIOLATION_REQUIRED_PROPERTIES: Array<keyof TransactionViolation> = ['type', 'name'] satisfies Array<keyof TransactionViolation>;

let isInFocusMode: OnyxEntry<boolean>;
Onyx.connect({
key: ONYXKEYS.NVP_PRIORITY_MODE,
callback: (priorityMode) => {
isInFocusMode = priorityMode === CONST.PRIORITY_MODE.GSD;
},
});

let transactionViolations: OnyxCollection<TransactionViolation[]>;
Onyx.connect({

Check warning on line 91 in src/libs/DebugUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 91 in src/libs/DebugUtils.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -104,14 +96,6 @@
},
});

let betas: OnyxEntry<Beta[]>;
Onyx.connect({
key: ONYXKEYS.BETAS,
callback: (value) => {
betas = value;
},
});

function stringifyJSON(data: Record<string, unknown>) {
return JSON.stringify(data, null, 6);
}
Expand Down Expand Up @@ -1333,7 +1317,21 @@
/**
* Gets the reason for showing LHN row
*/
function getReasonForShowingRowInLHN(report: OnyxEntry<Report>, chatReport: OnyxEntry<Report>, hasRBR = false, isReportArchived = false): TranslationPaths | null {
function getReasonForShowingRowInLHN({
report,
chatReport,
hasRBR = false,
isReportArchived = false,
isInFocusMode = false,
betas = undefined,
}: {
report: OnyxEntry<Report>;
chatReport: OnyxEntry<Report>;
hasRBR?: boolean;
isReportArchived?: boolean;
isInFocusMode?: boolean;
betas?: OnyxEntry<Beta[]>;
}): TranslationPaths | null {
if (!report) {
return null;
}
Expand All @@ -1345,7 +1343,7 @@
chatReport,
// We can't pass report.reportID because it will cause reason to always be isFocused
currentReportId: '-1',
isInFocusMode: !!isInFocusMode,
isInFocusMode,
betas,
excludeEmptyChats: true,
doesReportHaveViolations,
Expand Down
6 changes: 4 additions & 2 deletions src/pages/Debug/Report/DebugReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function DebugReportPage({
selector: (attributes) => attributes?.reports?.[reportID],
canBeMissing: true,
});
const [priorityMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE, {canBeMissing: true});
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const transactionID = DebugUtils.getTransactionID(report, reportActions);
const isReportArchived = useReportIsArchived(reportID);

Expand All @@ -76,7 +78,7 @@ function DebugReportPage({
DebugUtils.getReasonAndReportActionForRBRInLHNRow(report, chatReport, reportActions, transactions, hasViolations, reportAttributes?.reportErrors ?? {}, isReportArchived) ?? {};
const hasRBR = !!reasonRBR;
const hasGBR = !hasRBR && !!reasonGBR;
const reasonLHN = DebugUtils.getReasonForShowingRowInLHN(report, chatReport, hasRBR, isReportArchived);
const reasonLHN = DebugUtils.getReasonForShowingRowInLHN({report, chatReport, betas, hasRBR, isReportArchived, isInFocusMode: priorityMode === CONST.PRIORITY_MODE.GSD});

return [
{
Expand Down Expand Up @@ -121,7 +123,7 @@ function DebugReportPage({
: undefined,
},
];
}, [chatReport, report, transactionViolations, reportID, reportActions, transactions, reportAttributes?.reportErrors, isReportArchived, translate]);
}, [report, transactionViolations, reportID, isReportArchived, chatReport, reportActions, transactions, reportAttributes?.reportErrors, betas, priorityMode, translate]);

const DebugDetailsTab = useCallback(
() => (
Expand Down
70 changes: 36 additions & 34 deletions tests/unit/DebugUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,56 +735,55 @@ describe('DebugUtils', () => {
Onyx.clear();
});
it('returns null when report is not defined', () => {
const reason = DebugUtils.getReasonForShowingRowInLHN(undefined, chatReportR14932);
const reason = DebugUtils.getReasonForShowingRowInLHN({report: undefined, chatReport: chatReportR14932});
expect(reason).toBeNull();
});
it('returns correct reason when report has a valid draft comment', async () => {
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}1`, 'Hello world!');
const reason = DebugUtils.getReasonForShowingRowInLHN(baseReport, chatReportR14932);
const reason = DebugUtils.getReasonForShowingRowInLHN({report: baseReport, chatReport: chatReportR14932});
expect(reason).toBe('debug.reasonVisibleInLHN.hasDraftComment');
});
it('returns correct reason when report has GBR', () => {
const reason = DebugUtils.getReasonForShowingRowInLHN(
{
const reason = DebugUtils.getReasonForShowingRowInLHN({
report: {
...baseReport,
lastMentionedTime: '2024-08-10 18:70:44.171',
lastReadTime: '2024-08-08 18:70:44.171',
},
chatReportR14932,
);
chatReport: chatReportR14932,
});
expect(reason).toBe('debug.reasonVisibleInLHN.hasGBR');
});
it('returns correct reason when report is pinned', () => {
const reason = DebugUtils.getReasonForShowingRowInLHN(
{
const reason = DebugUtils.getReasonForShowingRowInLHN({
report: {
...baseReport,
isPinned: true,
},
chatReportR14932,
);
chatReport: chatReportR14932,
});
expect(reason).toBe('debug.reasonVisibleInLHN.pinnedByUser');
});
it('returns correct reason when report has add workspace room errors', () => {
const reason = DebugUtils.getReasonForShowingRowInLHN(
{
const reason = DebugUtils.getReasonForShowingRowInLHN({
report: {
...baseReport,
errorFields: {
addWorkspaceRoom: {
error: 'Something happened',
},
},
},
chatReportR14932,
);
chatReport: chatReportR14932,
});
expect(reason).toBe('debug.reasonVisibleInLHN.hasAddWorkspaceRoomErrors');
});
it('returns correct reason when report is unread', async () => {
await Onyx.set(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.GSD);
await Onyx.set(ONYXKEYS.SESSION, {
accountID: 1234,
});
const reason = DebugUtils.getReasonForShowingRowInLHN(
{
const reason = DebugUtils.getReasonForShowingRowInLHN({
report: {
...baseReport,
participants: {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -796,39 +795,42 @@ describe('DebugUtils', () => {
lastReadTime: '2024-08-08 18:70:44.171',
lastMessageText: 'Hello world!',
},
chatReportR14932,
);
chatReport: chatReportR14932,
isInFocusMode: true,
});
expect(reason).toBe('debug.reasonVisibleInLHN.isUnread');
});
it('returns correct reason when report is archived', async () => {
const reportNameValuePairs = {
private_isArchived: DateUtils.getDBTime(),
};
await Onyx.set(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.DEFAULT);
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${baseReport.reportID}`, reportNameValuePairs);
const {result: isReportArchived} = renderHook(() => useReportIsArchived(baseReport?.reportID));
const reason = DebugUtils.getReasonForShowingRowInLHN(
{
const reason = DebugUtils.getReasonForShowingRowInLHN({
report: {
...baseReport,
},
chatReportR14932,
false,
isReportArchived.current,
);
chatReport: chatReportR14932,
hasRBR: false,
isReportArchived: isReportArchived.current,
});
expect(reason).toBe('debug.reasonVisibleInLHN.isArchived');
});
it('returns correct reason when report is self DM', () => {
const reason = DebugUtils.getReasonForShowingRowInLHN(
{
const reason = DebugUtils.getReasonForShowingRowInLHN({
report: {
...baseReport,
chatType: CONST.REPORT.CHAT_TYPE.SELF_DM,
},
chatReportR14932,
);
chatReport: chatReportR14932,
});
expect(reason).toBe('debug.reasonVisibleInLHN.isSelfDM');
});
it('returns correct reason when report is temporarily focused', () => {
const reason = DebugUtils.getReasonForShowingRowInLHN(baseReport, chatReportR14932);
const reason = DebugUtils.getReasonForShowingRowInLHN({
report: baseReport,
chatReport: chatReportR14932,
});
expect(reason).toBe('debug.reasonVisibleInLHN.isFocused');
});
it('returns correct reason when report has one transaction thread with violations', async () => {
Expand Down Expand Up @@ -886,7 +888,7 @@ describe('DebugUtils', () => {
},
],
});
const reason = DebugUtils.getReasonForShowingRowInLHN(MOCK_TRANSACTION_REPORT, chatReportR14932, true);
const reason = DebugUtils.getReasonForShowingRowInLHN({report: MOCK_TRANSACTION_REPORT, chatReport: chatReportR14932, hasRBR: true});
expect(reason).toBe('debug.reasonVisibleInLHN.hasRBR');
});
it('returns correct reason when report has violations', async () => {
Expand Down Expand Up @@ -944,11 +946,11 @@ describe('DebugUtils', () => {
},
],
});
const reason = DebugUtils.getReasonForShowingRowInLHN(MOCK_EXPENSE_REPORT, chatReportR14932, true);
const reason = DebugUtils.getReasonForShowingRowInLHN({report: MOCK_EXPENSE_REPORT, chatReport: chatReportR14932, hasRBR: true});
expect(reason).toBe('debug.reasonVisibleInLHN.hasRBR');
});
it('returns correct reason when report has errors', () => {
const reason = DebugUtils.getReasonForShowingRowInLHN(baseReport, chatReportR14932, true);
const reason = DebugUtils.getReasonForShowingRowInLHN({report: baseReport, chatReport: chatReportR14932, hasRBR: true});
expect(reason).toBe('debug.reasonVisibleInLHN.hasRBR');
});
});
Expand Down
Loading