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
15 changes: 15 additions & 0 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
isValidReportIDFromPath,
prepareOnboardingOnyxData,
} from '@libs/ReportUtils';
import {getCurrentSearchQueryJSON} from '@libs/SearchQueryUtils';
import shouldSkipDeepLinkNavigation from '@libs/shouldSkipDeepLinkNavigation';
import playSound, {SOUNDS} from '@libs/Sound';
import {isOnHold} from '@libs/TransactionUtils';
Expand Down Expand Up @@ -270,7 +271,7 @@
let currentUserAccountID = -1;
let currentUserEmail: string | undefined;

Onyx.connect({

Check warning on line 274 in src/libs/actions/Report.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
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -283,13 +284,13 @@
},
});

Onyx.connect({

Check warning on line 287 in src/libs/actions/Report.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
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => (conciergeReportID = value),
});

let preferredSkinTone: number = CONST.EMOJI_DEFAULT_SKIN_TONE;
Onyx.connect({

Check warning on line 293 in src/libs/actions/Report.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
key: ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE,
callback: (value) => {
preferredSkinTone = EmojiUtils.getPreferredSkinToneIndex(value);
Expand All @@ -299,7 +300,7 @@
// map of reportID to all reportActions for that report
const allReportActions: OnyxCollection<ReportActions> = {};

Onyx.connect({

Check warning on line 303 in src/libs/actions/Report.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
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {
if (!key || !actions) {
Expand All @@ -311,14 +312,14 @@
});

let allTransactionViolations: OnyxCollection<TransactionViolations> = {};
Onyx.connect({

Check warning on line 315 in src/libs/actions/Report.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
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => (allTransactionViolations = value),
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 322 in src/libs/actions/Report.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
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -328,7 +329,7 @@

let isNetworkOffline = false;
let networkStatus: NetworkStatus;
Onyx.connect({

Check warning on line 332 in src/libs/actions/Report.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
key: ONYXKEYS.NETWORK,
callback: (value) => {
isNetworkOffline = value?.isOffline ?? false;
Expand All @@ -337,7 +338,7 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
Onyx.connect({

Check warning on line 341 in src/libs/actions/Report.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
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand All @@ -345,7 +346,7 @@
});

let account: OnyxEntry<Account> = {};
Onyx.connect({

Check warning on line 349 in src/libs/actions/Report.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
key: ONYXKEYS.ACCOUNT,
callback: (value) => {
account = value ?? {};
Expand All @@ -353,7 +354,7 @@
});

const draftNoteMap: OnyxCollection<string> = {};
Onyx.connect({

Check warning on line 357 in src/libs/actions/Report.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
key: ONYXKEYS.COLLECTION.PRIVATE_NOTES_DRAFT,
callback: (value, key) => {
if (!key) {
Expand Down Expand Up @@ -5766,6 +5767,20 @@
},
});

const currentSearchQueryJSON = getCurrentSearchQueryJSON();
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];

// Search data might not have the new policy data so we should add it optimistically.
if (policy && currentSearchQueryJSON) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${currentSearchQueryJSON.hash}` as const,
value: {
data: {[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: policy},
},
});
}

// 5. Make sure the expense report is not archived
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
Expand Down
29 changes: 28 additions & 1 deletion tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ jest.mock('@libs/ReportUtils', () => {
};
});

const currentHash = 12345;
jest.mock('@src/libs/SearchQueryUtils', () => ({
getCurrentSearchQueryJSON: jest.fn().mockImplementation(() => ({
hash: currentHash,
query: 'test',
type: 'expense',
status: '',
flatFilters: [],
})),
}));

const UTC = 'UTC';
jest.mock('@src/libs/actions/Report', () => {
const originalModule = jest.requireActual<Report>('@src/libs/actions/Report');
Expand Down Expand Up @@ -1835,8 +1846,11 @@ describe('actions/Report', () => {
private_isArchived: DateUtils.getDBTime(),
});

const newPolicy = createRandomPolicy(2);
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`, newPolicy);

// When moving to another workspace
Report.changeReportPolicy(expenseReport, '2');
Report.changeReportPolicy(expenseReport, newPolicy.id);
await waitForBatchedUpdates();

// Then the expense report should not be archived anymore
Expand All @@ -1850,6 +1864,19 @@ describe('actions/Report', () => {
});
});
expect(isArchived).toBe(false);

const snapshotData = await new Promise<OnyxEntry<OnyxTypes.SearchResults>>((resolve) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${currentHash}`,
callback: (val) => {
resolve(val);
Onyx.disconnect(connection);
},
});
});

// Then the new policy data should also be populated on the current search snapshot.
expect(snapshotData?.data?.[`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`]).toBeDefined();
});
});

Expand Down
Loading