Skip to content

Commit

Permalink
Merge pull request Expensify#45568 from Expensify/srikar-archivedTemp…
Browse files Browse the repository at this point in the history
…Report

Temporarily use reports collection for isArchived
  • Loading branch information
srikarparsi authored Jul 18, 2024
2 parents a5bff1d + 0121182 commit 4f2ebcd
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,12 +1287,9 @@ function isClosedExpenseReportWithNoExpenses(report: OnyxEntry<Report>): boolean
/**
* Whether the provided report is an archived room
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function isArchivedRoom(report: OnyxInputOrEntry<Report>, reportNameValuePairs?: OnyxInputOrEntry<ReportNameValuePairs>): boolean {
if (reportNameValuePairs) {
return reportNameValuePairs.private_isArchived;
}

return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED && report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED;
return !!report?.private_isArchived;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -270,6 +271,8 @@ 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,
},
});

Expand Down
3 changes: 3 additions & 0 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ function ReportScreen({
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,
avatarUrl: reportOnyx?.avatarUrl,
Expand Down Expand Up @@ -268,6 +270,7 @@ function ReportScreen({
reportOnyx?.visibility,
reportOnyx?.oldPolicyName,
reportOnyx?.policyName,
reportOnyx?.private_isArchived,
reportOnyx?.isOptimisticReport,
reportOnyx?.lastMentionedTime,
reportOnyx?.avatarUrl,
Expand Down
4 changes: 4 additions & 0 deletions src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
>;
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/OptionsListUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(),
},
};

Expand Down
7 changes: 7 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
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';
Expand Down Expand Up @@ -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)');
Expand All @@ -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)');
Expand Down Expand Up @@ -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', () => {
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/SidebarOrderTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/SidebarTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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';
Expand Down Expand Up @@ -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',
};

Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 4f2ebcd

Please sign in to comment.