Skip to content

Commit 033019d

Browse files
committed
Revert "Merge pull request Expensify#85767 from margelo/@chrispader/dowgrade-onyx-to-v3.0.45"
This reverts commit 5277b58, reversing changes made to 7933470.
1 parent a56df80 commit 033019d

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';
@@ -90,9 +90,12 @@ export default function <TProps extends WithPolicyProps>(WrappedComponent: Compo
9090
/* eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing */
9191
const isLoadingPolicy = !hasLoadedApp || (!!policyID && isLoadingOnyxValue(policyResults, policyDraftResults));
9292

93-
if (policyID && policyID.length > 0) {
93+
useEffect(() => {
94+
if (!policyID) {
95+
return;
96+
}
9497
updateLastAccessedWorkspace(policyID);
95-
}
98+
}, [policyID]);
9699

97100
return (
98101
<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
@@ -190,6 +190,8 @@ describe('Session', () => {
190190

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

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

@@ -227,6 +229,8 @@ describe('Session', () => {
227229

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

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

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
@@ -3273,7 +3273,7 @@ describe('OptionsListUtils', () => {
32733273
expect(canCreate).toBe(false);
32743274
});
32753275

3276-
it('createOptionList() localization', () => {
3276+
it('createOptionList() localization', async () => {
32773277
renderLocaleContextProvider();
32783278
// Given a set of reports and personal details
32793279
// When we call createOptionList and extract the reports
@@ -3282,18 +3282,15 @@ describe('OptionsListUtils', () => {
32823282
// Then the returned reports should match the expected values
32833283
expect(reports.at(10)?.subtitle).toBe(`Submits to Mister Fantastic`);
32843284

3285-
return (
3286-
waitForBatchedUpdates()
3287-
// When we set the preferred locale to Spanish
3288-
.then(() => Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES))
3289-
.then(() => {
3290-
// When we call createOptionList again
3291-
const newReports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS).reports;
3292-
// Then the returned reports should change to Spanish
3293-
// cspell:disable-next-line
3294-
expect(newReports.at(10)?.subtitle).toBe('Se envía a Mister Fantastic');
3295-
})
3296-
);
3285+
await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES);
3286+
3287+
await waitForBatchedUpdates();
3288+
3289+
// When we call createOptionList again
3290+
const newReports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS).reports;
3291+
// Then the returned reports should change to Spanish
3292+
// cspell:disable-next-line
3293+
expect(newReports.at(10)?.subtitle).toBe('Se envía a Mister Fantastic');
32973294
});
32983295
});
32993296

@@ -3367,6 +3364,8 @@ describe('OptionsListUtils', () => {
33673364
'1': getFakeAdvancedReportAction(CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT),
33683365
},
33693366
});
3367+
await waitForBatchedUpdates();
3368+
33703369
// When we call createOptionList with report 10 marked as archived
33713370
const archivedMap: PrivateIsArchivedMap = {
33723371
[`${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)