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

Temporarily use reports collection for isArchived #45568

Merged
merged 7 commits into from
Jul 18, 2024
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
7 changes: 2 additions & 5 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1286,12 +1286,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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't need reportNameValuePairs anymore, we should remove it as a param as well.

Suggested change
function isArchivedRoom(report: OnyxInputOrEntry<Report>, reportNameValuePairs?: OnyxInputOrEntry<ReportNameValuePairs>): boolean {
function isArchivedRoom(report: OnyxInputOrEntry<Report>): boolean {

If so we should also update it in every place that we used this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll need it in the future because the 'private_isArchived' variable will be stores in reportNameValuePairs instead of 'report'. This is just a temporary fix while we're sending the variable through 'report'.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. I'll start testing now

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 @@ -203,6 +203,8 @@ 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,
avatarUrl: reportOnyx?.avatarUrl,
Expand Down Expand Up @@ -244,6 +246,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
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
Loading