Skip to content

Commit 572af3b

Browse files
authored
Merge pull request #85248 from callstack-internal/VickyStash/refactor/bump-onyx-3.0.46
Bump onyx to 3.0.46
2 parents b12722f + 75145a7 commit 572af3b

11 files changed

Lines changed: 86 additions & 56 deletions

File tree

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
"react-native-localize": "^3.5.4",
182182
"react-native-nitro-modules": "0.29.4",
183183
"react-native-nitro-sqlite": "9.2.0",
184-
"react-native-onyx": "3.0.45",
184+
"react-native-onyx": "3.0.46",
185185
"react-native-pager-view": "8.0.0",
186186
"react-native-pdf": "7.0.2",
187187
"react-native-permissions": "^5.4.0",

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useFocusEffect} from '@react-navigation/native';
1+
import {useIsFocused} from '@react-navigation/native';
22
import {hasSeenTourSelector} from '@selectors/Onboarding';
33
import {FlashList} from '@shopify/flash-list';
44
import type {FlashListRef, ListRenderItemInfo} from '@shopify/flash-list';
@@ -552,31 +552,40 @@ function MoneyRequestReportPreviewContent({
552552
carouselTransactionsRef.current = carouselTransactions;
553553
}, [carouselTransactions]);
554554

555-
useFocusEffect(
556-
useCallback(() => {
557-
const index = carouselTransactions.findIndex((transaction) => newTransactionIDs?.has(transaction.transactionID));
555+
const isFocused = useIsFocused();
556+
const isFocusedRef = useRef(isFocused);
558557

559-
if (index < 0) {
558+
useEffect(() => {
559+
isFocusedRef.current = isFocused;
560+
}, [isFocused]);
561+
562+
useEffect(() => {
563+
const index = carouselTransactions.findIndex((transaction) => newTransactionIDs?.has(transaction.transactionID));
564+
565+
if (index < 0) {
566+
return;
567+
}
568+
const newTransaction = carouselTransactions.at(index);
569+
setTimeout(() => {
570+
if (!isFocusedRef.current) {
571+
return;
572+
}
573+
// If the new transaction is not available at the index it was on before the delay, avoid the scrolling
574+
// because we are scrolling to either a wrong or unavailable transaction (which can cause crash).
575+
if (newTransaction?.transactionID !== carouselTransactionsRef.current.at(index)?.transactionID) {
560576
return;
561577
}
562-
const newTransaction = carouselTransactions.at(index);
563-
setTimeout(() => {
564-
// If the new transaction is not available at the index it was on before the delay, avoid the scrolling
565-
// because we are scrolling to either a wrong or unavailable transaction (which can cause crash).
566-
if (newTransaction?.transactionID !== carouselTransactionsRef.current.at(index)?.transactionID) {
567-
return;
568-
}
569578

570-
carouselRef.current?.scrollToIndex({
571-
index,
572-
viewOffset: -2 * styles.gap2.gap,
573-
animated: true,
574-
});
575-
}, CONST.ANIMATED_TRANSITION);
579+
carouselRef.current?.scrollToIndex({
580+
index,
581+
viewOffset: -2 * styles.gap2.gap,
582+
animated: true,
583+
});
584+
}, CONST.ANIMATED_TRANSITION);
576585

577-
// eslint-disable-next-line react-hooks/exhaustive-deps
578-
}, [newTransactionIDs]),
579-
);
586+
// We only want to scroll to a new transaction when the set of new transaction IDs changes.
587+
// eslint-disable-next-line react-hooks/exhaustive-deps
588+
}, [newTransactionIDs]);
580589

581590
const onViewableItemsChanged = useRef(({viewableItems}: {viewableItems: ViewToken[]; changed: ViewToken[]}) => {
582591
const newIndex = viewableItems.at(0)?.index;

src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {useIsFocused} from '@react-navigation/native';
21
import type {ListRenderItem} from '@shopify/flash-list';
32
import React, {useCallback, useMemo, useRef, useState} from 'react';
43
import type {LayoutChangeEvent} from 'react-native';
@@ -122,9 +121,8 @@ function MoneyRequestReportPreview({
122121
selector: hasOnceLoadedReportActionsSelector,
123122
});
124123
const newTransactions = useNewTransactions(hasOnceLoadedReportActions, transactions);
125-
const isFocused = useIsFocused();
126124
// We only want to highlight the new expenses if the screen is focused.
127-
const newTransactionIDs = isFocused ? new Set(newTransactions.map((transaction) => transaction.transactionID)) : undefined;
125+
const newTransactionIDs = new Set(newTransactions.map((transaction) => transaction.transactionID));
128126

129127
const transactionPreviewContainerStyles = [styles.h100, reportPreviewStyles.transactionPreviewCarouselStyle];
130128

src/pages/workspace/withPolicy.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {ComponentType} from 'react';
2-
import React from 'react';
2+
import React, {useEffect} from 'react';
33
import type {OnyxEntry} from 'react-native-onyx';
44
import useOnyx from '@hooks/useOnyx';
55
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
@@ -91,9 +91,12 @@ export default function <TProps extends WithPolicyProps>(WrappedComponent: Compo
9191
/* eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing */
9292
const isLoadingPolicy = !hasLoadedApp || (!!policyID && isLoadingOnyxValue(policyResults, policyDraftResults));
9393

94-
if (policyID && policyID.length > 0) {
94+
useEffect(() => {
95+
if (!policyID) {
96+
return;
97+
}
9598
updateLastAccessedWorkspace(policyID);
96-
}
99+
}, [policyID]);
97100

98101
return (
99102
<WrappedComponent

tests/actions/ReportTest.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,8 @@ describe('actions/Report', () => {
15201520
currentUserAccountID: TEST_USER_ACCOUNT_ID,
15211521
});
15221522

1523+
await waitForBatchedUpdates();
1524+
15231525
// Need the reportActionID to delete the comments
15241526
const newComment = PersistedRequests.getAll().at(1);
15251527
const reportActionID = newComment?.data?.reportActionID as string | undefined;
@@ -2039,6 +2041,9 @@ describe('actions/Report', () => {
20392041
const newComment = PersistedRequests.getAll().at(0);
20402042
const reportActionID = newComment?.data?.reportActionID as string | undefined;
20412043
const reportAction = TestHelper.buildTestReportComment(created, TEST_USER_ACCOUNT_ID, reportActionID);
2044+
2045+
await waitForBatchedUpdates();
2046+
20422047
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: true});
20432048

20442049
// wait for Onyx.connect execute the callback and start processing the queue
@@ -2232,6 +2237,7 @@ describe('actions/Report', () => {
22322237
expect(requests?.at(0)?.data?.reportComment).toBe('value3');
22332238

22342239
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});
2240+
await waitForBatchedUpdates();
22352241

22362242
TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.UPDATE_COMMENT, 1);
22372243
});
@@ -2330,6 +2336,8 @@ describe('actions/Report', () => {
23302336
expect(requests?.at(0)?.data?.reportComment).toBe('value3');
23312337

23322338
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});
2339+
await waitForBatchedUpdates();
2340+
23332341
TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.UPDATE_COMMENT, 1);
23342342
});
23352343

tests/actions/SessionTest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ describe('Session', () => {
189189

190190
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});
191191

192+
await waitForBatchedUpdates();
193+
192194
expect(getAllPersistedRequests().length).toBe(0);
193195
});
194196

@@ -226,6 +228,8 @@ describe('Session', () => {
226228

227229
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});
228230

231+
await waitForBatchedUpdates();
232+
229233
expect(getAllPersistedRequests().length).toBe(0);
230234
});
231235

tests/unit/APITest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ describe('APITests', () => {
436436
});
437437

438438
Onyx.set(ONYXKEYS.NETWORK, {isOffline: true});
439-
expect(NetworkStore.isOffline()).toBe(false);
439+
expect(NetworkStore.isOffline()).toBe(true);
440440
expect(NetworkStore.isAuthenticating()).toBe(false);
441441
return waitForBatchedUpdates();
442442
})
@@ -551,7 +551,7 @@ describe('APITests', () => {
551551
API.write('MockCommandThree' as WriteCommand, {});
552552

553553
// THEN the retryable requests should immediately be added to the persisted requests
554-
expect(PersistedRequests.getAll().length).toBe(2);
554+
expect(PersistedRequests.getLength()).toBe(2);
555555

556556
// WHEN we wait for the queue to run and finish processing
557557
return waitForBatchedUpdates();

tests/unit/OptionsListUtilsTest.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,7 +3526,7 @@ describe('OptionsListUtils', () => {
35263526
expect(canCreate).toBe(false);
35273527
});
35283528

3529-
it('createOptionList() localization', () => {
3529+
it('createOptionList() localization', async () => {
35303530
renderLocaleContextProvider();
35313531
// Given a set of reports and personal details
35323532
// When we call createOptionList and extract the reports
@@ -3535,18 +3535,15 @@ describe('OptionsListUtils', () => {
35353535
// Then the returned reports should match the expected values
35363536
expect(reports.at(10)?.subtitle).toBe(`Submits to Mister Fantastic`);
35373537

3538-
return (
3539-
waitForBatchedUpdates()
3540-
// When we set the preferred locale to Spanish
3541-
.then(() => Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES))
3542-
.then(() => {
3543-
// When we call createOptionList again
3544-
const newReports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS).reports;
3545-
// Then the returned reports should change to Spanish
3546-
// cspell:disable-next-line
3547-
expect(newReports.at(10)?.subtitle).toBe('Se envía a Mister Fantastic');
3548-
})
3549-
);
3538+
await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES);
3539+
3540+
await waitForBatchedUpdates();
3541+
3542+
// When we call createOptionList again
3543+
const newReports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS).reports;
3544+
// Then the returned reports should change to Spanish
3545+
// cspell:disable-next-line
3546+
expect(newReports.at(10)?.subtitle).toBe('Se envía a Mister Fantastic');
35503547
});
35513548
});
35523549

@@ -3620,6 +3617,8 @@ describe('OptionsListUtils', () => {
36203617
'1': getFakeAdvancedReportAction(CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT),
36213618
},
36223619
});
3620+
await waitForBatchedUpdates();
3621+
36233622
// When we call createOptionList with report 10 marked as archived
36243623
const archivedMap: PrivateIsArchivedMap = {
36253624
[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}10`]: reportNameValuePairs.private_isArchived,

tests/unit/ReportSecondaryActionUtilsTest.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ describe('getSecondaryAction', () => {
5252
beforeAll(() => {
5353
Onyx.init({
5454
keys: ONYXKEYS,
55+
initialKeyStates: {
56+
[ONYXKEYS.SESSION]: SESSION,
57+
[ONYXKEYS.PERSONAL_DETAILS_LIST]: {[EMPLOYEE_ACCOUNT_ID]: PERSONAL_DETAILS, [APPROVER_ACCOUNT_ID]: {accountID: APPROVER_ACCOUNT_ID, login: APPROVER_EMAIL}},
58+
},
5559
});
5660
});
5761

5862
beforeEach(async () => {
5963
jest.clearAllMocks();
6064
Onyx.clear();
61-
await Onyx.merge(ONYXKEYS.SESSION, SESSION);
62-
await Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {[EMPLOYEE_ACCOUNT_ID]: PERSONAL_DETAILS, [APPROVER_ACCOUNT_ID]: {accountID: APPROVER_ACCOUNT_ID, login: APPROVER_EMAIL}});
6365
});
6466

6567
it('should always return default options', () => {

0 commit comments

Comments
 (0)