From 9407c4e32ce2625d4226a3ef16ce0b7ac549753e Mon Sep 17 00:00:00 2001 From: Srikar Parsi Date: Tue, 16 Jul 2024 20:21:29 -0400 Subject: [PATCH 1/6] Temprarily use reports collection for isArchived --- src/libs/ReportUtils.ts | 7 +++---- src/types/onyx/Report.ts | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ace8f547b75c..316d257582b3 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1287,11 +1287,10 @@ function isClosedExpenseReportWithNoExpenses(report: OnyxEntry): boolean * Whether the provided report is an archived room */ function isArchivedRoom(report: OnyxInputOrEntry, reportNameValuePairs?: OnyxInputOrEntry): boolean { - if (reportNameValuePairs) { - return reportNameValuePairs.private_isArchived; + if (report?.private_isArchived) { + return true; } - - return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED && report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED; + return false; } /** diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index b5d0a0a15d13..14fd2bd3ac81 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -289,6 +289,10 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** The trip ID in spotnana */ tripID: string; }; + + /** Whether the report is archived */ + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived?: string; }, PolicyReportField['fieldID'] >; From a1b4a1b8f2cf76fb603f80006283f377eff0be84 Mon Sep 17 00:00:00 2001 From: Srikar Parsi Date: Wed, 17 Jul 2024 22:35:32 -0400 Subject: [PATCH 2/6] add private_isArchived directly to report screen --- src/pages/home/ReportScreen.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 49897928ffe9..9e0fb3b048c9 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -203,6 +203,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro visibility: reportOnyx?.visibility, oldPolicyName: reportOnyx?.oldPolicyName, policyName: reportOnyx?.policyName, + private_isArchived: reportOnyx?.private_isArchived, isOptimisticReport: reportOnyx?.isOptimisticReport, lastMentionedTime: reportOnyx?.lastMentionedTime, avatarUrl: reportOnyx?.avatarUrl, From 4ad8aa61c17aac3da55f4d78f1a02dcc47787dcc Mon Sep 17 00:00:00 2001 From: Srikar Parsi Date: Wed, 17 Jul 2024 23:09:18 -0400 Subject: [PATCH 3/6] report footer fix --- src/libs/ReportUtils.ts | 6 ++---- src/pages/home/ReportScreen.tsx | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 316d257582b3..0f07ca1927ec 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1286,11 +1286,9 @@ function isClosedExpenseReportWithNoExpenses(report: OnyxEntry): boolean /** * Whether the provided report is an archived room */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars function isArchivedRoom(report: OnyxInputOrEntry, reportNameValuePairs?: OnyxInputOrEntry): boolean { - if (report?.private_isArchived) { - return true; - } - return false; + return !!report?.private_isArchived; } /** diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 9e0fb3b048c9..0af6a4387adf 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -203,6 +203,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro visibility: reportOnyx?.visibility, oldPolicyName: reportOnyx?.oldPolicyName, policyName: reportOnyx?.policyName, + // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: reportOnyx?.private_isArchived, isOptimisticReport: reportOnyx?.isOptimisticReport, lastMentionedTime: reportOnyx?.lastMentionedTime, @@ -245,6 +246,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro reportOnyx?.visibility, reportOnyx?.oldPolicyName, reportOnyx?.policyName, + reportOnyx?.private_isArchived, reportOnyx?.isOptimisticReport, reportOnyx?.lastMentionedTime, reportOnyx?.avatarUrl, From 38850451fdfe58539bdacb65378cd15dee2b6481 Mon Sep 17 00:00:00 2001 From: Srikar Parsi Date: Wed, 17 Jul 2024 23:12:23 -0400 Subject: [PATCH 4/6] add offline behavior --- src/libs/actions/Policy/Policy.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index e6d2e35dd8c1..366a0c819336 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -260,6 +260,7 @@ function deleteWorkspace(policyID: string, policyName: string) { (report) => report?.policyID === policyID && (ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report) || ReportUtils.isTaskReport(report)), ); const finallyData: OnyxUpdate[] = []; + const currentTime = DateUtils.getDBTime(); reportsToArchive.forEach((report) => { const {reportID, ownerAccountID} = report ?? {}; optimisticData.push({ @@ -270,6 +271,7 @@ function deleteWorkspace(policyID: string, policyName: string) { statusNum: CONST.REPORT.STATUS_NUM.CLOSED, oldPolicyName: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]?.name ?? '', policyName: '', + private_isArchived: currentTime, }, }); From 6a51d0715029f654d3b50f9aeeaea2855ea62e92 Mon Sep 17 00:00:00 2001 From: Srikar Parsi Date: Wed, 17 Jul 2024 23:37:20 -0400 Subject: [PATCH 5/6] fix tests --- src/libs/actions/Policy/Policy.ts | 1 + tests/unit/ReportUtilsTest.ts | 7 +++++++ tests/unit/SidebarTest.ts | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 366a0c819336..c5be4b6074a7 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -271,6 +271,7 @@ function deleteWorkspace(policyID: string, policyName: string) { statusNum: CONST.REPORT.STATUS_NUM.CLOSED, oldPolicyName: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]?.name ?? '', policyName: '', + // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: currentTime, }, }); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 34a9a923bd61..d692ee0fb834 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -7,6 +7,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetailsList, Policy, Report, ReportAction} from '@src/types/onyx'; import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; +import DateUtils from '@libs/DateUtils'; import * as NumberUtils from '../../src/libs/NumberUtils'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -166,6 +167,8 @@ describe('ReportUtils', () => { ...baseAdminsRoom, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime() }; expect(ReportUtils.getReportName(archivedAdminsRoom)).toBe('#admins (archived)'); @@ -190,6 +193,8 @@ describe('ReportUtils', () => { ...baseUserCreatedRoom, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime() }; expect(ReportUtils.getReportName(archivedPolicyRoom)).toBe('#VikingsChat (archived)'); @@ -234,6 +239,8 @@ describe('ReportUtils', () => { oldPolicyName: policy.name, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime() }; test('as member', () => { diff --git a/tests/unit/SidebarTest.ts b/tests/unit/SidebarTest.ts index 4c585f29bc61..312d31fecba5 100644 --- a/tests/unit/SidebarTest.ts +++ b/tests/unit/SidebarTest.ts @@ -5,6 +5,7 @@ import * as Localize from '@src/libs/Localize'; import ONYXKEYS from '@src/ONYXKEYS'; import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import type {ReportActionsCollectionDataSet} from '@src/types/onyx/ReportAction'; +import DateUtils from '@libs/DateUtils'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; @@ -42,6 +43,8 @@ describe('Sidebar', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), lastMessageText: 'test', }; @@ -95,6 +98,8 @@ describe('Sidebar', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), lastMessageText: 'test', }; const action = { From 0121182b69f183fa730138d7037a1464f40794b1 Mon Sep 17 00:00:00 2001 From: Srikar Parsi Date: Wed, 17 Jul 2024 23:54:51 -0400 Subject: [PATCH 6/6] fix additional tests and lint --- tests/unit/OptionsListUtilsTest.ts | 3 +++ tests/unit/ReportUtilsTest.ts | 8 ++++---- tests/unit/SidebarOrderTest.ts | 4 ++++ tests/unit/SidebarTest.ts | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 4a1171658f4d..79f19649f337 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -2,6 +2,7 @@ import type {OnyxCollection} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {SelectedTagOption} from '@components/TagPicker'; +import DateUtils from '@libs/DateUtils'; import CONST from '@src/CONST'; import * as OptionsListUtils from '@src/libs/OptionsListUtils'; import * as ReportUtils from '@src/libs/ReportUtils'; @@ -153,6 +154,8 @@ describe('OptionsListUtils', () => { // This indicates that the report is archived stateNum: 2, statusNum: 2, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), }, }; diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index d692ee0fb834..14c710c6ddf2 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -2,12 +2,12 @@ import {addDays, format as formatDate, subDays} from 'date-fns'; import type {OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; +import DateUtils from '@libs/DateUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetailsList, Policy, Report, ReportAction} from '@src/types/onyx'; import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; -import DateUtils from '@libs/DateUtils'; import * as NumberUtils from '../../src/libs/NumberUtils'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -168,7 +168,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, // eslint-disable-next-line @typescript-eslint/naming-convention - private_isArchived: DateUtils.getDBTime() + private_isArchived: DateUtils.getDBTime(), }; expect(ReportUtils.getReportName(archivedAdminsRoom)).toBe('#admins (archived)'); @@ -194,7 +194,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, // eslint-disable-next-line @typescript-eslint/naming-convention - private_isArchived: DateUtils.getDBTime() + private_isArchived: DateUtils.getDBTime(), }; expect(ReportUtils.getReportName(archivedPolicyRoom)).toBe('#VikingsChat (archived)'); @@ -240,7 +240,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, // eslint-disable-next-line @typescript-eslint/naming-convention - private_isArchived: DateUtils.getDBTime() + private_isArchived: DateUtils.getDBTime(), }; test('as member', () => { diff --git a/tests/unit/SidebarOrderTest.ts b/tests/unit/SidebarOrderTest.ts index 41e85c4fdd78..c8b885f98205 100644 --- a/tests/unit/SidebarOrderTest.ts +++ b/tests/unit/SidebarOrderTest.ts @@ -812,6 +812,8 @@ describe('Sidebar', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), }; const report2 = LHNTestUtils.getFakeReport([3, 4]); const report3 = LHNTestUtils.getFakeReport([5, 6]); @@ -919,6 +921,8 @@ describe('Sidebar', () => { statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, lastMessageText: 'test', + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), }; const report2 = { ...LHNTestUtils.getFakeReport([3, 4], 2, true), diff --git a/tests/unit/SidebarTest.ts b/tests/unit/SidebarTest.ts index 312d31fecba5..f9b258228937 100644 --- a/tests/unit/SidebarTest.ts +++ b/tests/unit/SidebarTest.ts @@ -1,11 +1,11 @@ import {screen} from '@testing-library/react-native'; import Onyx from 'react-native-onyx'; +import DateUtils from '@libs/DateUtils'; import CONST from '@src/CONST'; import * as Localize from '@src/libs/Localize'; import ONYXKEYS from '@src/ONYXKEYS'; import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import type {ReportActionsCollectionDataSet} from '@src/types/onyx/ReportAction'; -import DateUtils from '@libs/DateUtils'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';