Skip to content

Commit

Permalink
Merge pull request #38114 from callstack-internal/hur/bump-onyx-to-2.…
Browse files Browse the repository at this point in the history
…0.19

chore: bump react-native-onyx to 2.0.23
  • Loading branch information
mountiny authored Apr 4, 2024
2 parents 24c3175 + a6c2cc9 commit d57555b
Show file tree
Hide file tree
Showing 21 changed files with 30 additions and 38 deletions.
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"react-native-linear-gradient": "^2.8.1",
"react-native-localize": "^2.2.6",
"react-native-modal": "^13.0.0",
"react-native-onyx": "git+https://github.com/Expensify/react-native-onyx#cd778b55e419bf09ecf377b1e3ac013b7758434d",
"react-native-onyx": "2.0.23",
"react-native-pager-view": "6.2.2",
"react-native-pdf": "6.7.3",
"react-native-performance": "^5.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Onyx.connect({
const originalConsoleLog = console.log;

/* List of patterns to ignore in logs. "logs" key always needs to be ignored because otherwise it will cause infinite loop */
const logPatternsToIgnore = [`merge() called for key: ${ONYXKEYS.LOGS}`];
const logPatternsToIgnore = [`merge called for key: ${ONYXKEYS.LOGS}`];

/**
* Check if the log should be attached to the console
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ErrorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function getAuthenticateErrorMessage(response: Response): keyof TranslationFlatO
* Method used to get an error object with microsecond as the key.
* @param error - error key or message to be saved
*/
function getMicroSecondOnyxError(error: string | null, isTranslated = false, errorKey?: number): Errors {
function getMicroSecondOnyxError(error: string, isTranslated = false, errorKey?: number): Errors {
return {[errorKey ?? DateUtils.getMicroseconds()]: error && [error, {isTranslated}]};
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/ActiveClients.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';

function setActiveClients(activeClients: string[]): Promise<void> {
function setActiveClients(activeClients: string[]): Promise<void | void[]> {
return Onyx.set(ONYXKEYS.ACTIVE_CLIENTS, activeClients);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type PersonalAddress = {
requestorAddressZipCode?: string;
};

function clearPlaid(): Promise<void> {
function clearPlaid(): Promise<void | void[]> {
Onyx.set(ONYXKEYS.PLAID_LINK_TOKEN, '');
Onyx.set(ONYXKEYS.PLAID_CURRENT_EVENT, null);
return Onyx.set(ONYXKEYS.PLAID_DATA, PlaidDataProps.plaidDataDefaultProps);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/CachedPDFPaths/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Add = (id: string, path: string) => Promise<void>;
type Add = (id: string, path: string) => Promise<void | void[]>;
type Clear = (path: string) => Promise<void>;
type ClearAll = () => void;
type ClearByKey = (id: string) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
/**
* Set whether an attachment is being downloaded so that a spinner can be shown.
*/
function setDownload(sourceID: string, isDownloading: boolean): Promise<void> {
function setDownload(sourceID: string, isDownloading: boolean): Promise<void | void[]> {
return Onyx.merge(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`, {isDownloading});
}

Expand Down
6 changes: 3 additions & 3 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ function buildOnyxDataForMoneyRequest(
errors: getReceiptError(transaction.receipt, transaction.filename || transaction.receipt?.filename, isScanRequest, errorKey),
},
[iouAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError(null),
errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'),
},
}
: {
Expand Down Expand Up @@ -2524,7 +2524,7 @@ function createSplitsAndOnyxData(
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${splitChatReport.reportID}`,
value: {
[splitIOUReportAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError(null),
errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'),
},
},
},
Expand Down Expand Up @@ -4336,7 +4336,7 @@ function getSendMoneyParams(
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`,
value: {
[optimisticIOUReportAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError(null),
errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'),
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/OnyxUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {Merge} from 'type-fest';
import Log from '@libs/Log';
Expand Down Expand Up @@ -27,7 +27,7 @@ function applyHTTPSOnyxUpdates(request: Request, response: Response) {
console.debug('[OnyxUpdateManager] Applying https update');
// For most requests we can immediately update Onyx. For write requests we queue the updates and apply them after the sequential queue has flushed to prevent a replay effect in
// the UI. See https://github.com/Expensify/App/issues/12775 for more info.
const updateHandler = request?.data?.apiRequestType === CONST.API_REQUEST_TYPE.WRITE ? QueuedOnyxUpdates.queueOnyxUpdates : Onyx.update;
const updateHandler: (updates: OnyxUpdate[]) => Promise<unknown> = request?.data?.apiRequestType === CONST.API_REQUEST_TYPE.WRITE ? QueuedOnyxUpdates.queueOnyxUpdates : Onyx.update;

// First apply any onyx data updates that are being sent back from the API. We wait for this to complete and then
// apply successData or failureData. This ensures that we do not update any pending, loading, or other UI states contained
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/ReimbursementAccount/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export {setBankAccountFormValidationErrors, resetReimbursementAccount} from './e
* - CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL to ask them to enter their accountNumber and routingNumber
* - CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID to ask them to login to their bank via Plaid
*/
function setBankAccountSubStep(subStep: BankAccountSubStep | null): Promise<void> {
function setBankAccountSubStep(subStep: BankAccountSubStep | null): Promise<void | void[]> {
return Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {achData: {subStep}});
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ function saveReportCommentNumberOfLines(reportID: string, numberOfLines: number)
}

/** Immediate indication whether the report has a draft comment. */
function setReportWithDraft(reportID: string, hasDraft: boolean): Promise<void> {
function setReportWithDraft(reportID: string, hasDraft: boolean): Promise<void | void[]> {
return Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {hasDraft});
}

Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function saveWaypoint(transactionID: string, index: string, waypoint: RecentWayp
}
}

function removeWaypoint(transaction: OnyxEntry<Transaction>, currentIndex: string, isDraft?: boolean): Promise<void> {
function removeWaypoint(transaction: OnyxEntry<Transaction>, currentIndex: string, isDraft?: boolean): Promise<void | void[]> {
// Index comes from the route params and is a string
const index = Number(currentIndex);
const existingWaypoints = transaction?.comment?.waypoints ?? {};
Expand Down Expand Up @@ -234,7 +234,7 @@ function getRoute(transactionID: string, waypoints: WaypointCollection, isDraft:
* @param waypoints - An object containing all the waypoints
* which will replace the existing ones.
*/
function updateWaypoints(transactionID: string, waypoints: WaypointCollection, isDraft = false): Promise<void> {
function updateWaypoints(transactionID: string, waypoints: WaypointCollection, isDraft = false): Promise<void | void[]> {
return Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
comment: {
waypoints,
Expand Down
6 changes: 3 additions & 3 deletions src/libs/migrateOnyx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import RemoveEmptyReportActionsDrafts from './migrations/RemoveEmptyReportAction
import RenameReceiptFilename from './migrations/RenameReceiptFilename';
import TransactionBackupsToCollection from './migrations/TransactionBackupsToCollection';

export default function (): Promise<void> {
export default function () {
const startTime = Date.now();
Log.info('[Migrate Onyx] start');

return new Promise((resolve) => {
return new Promise<void>((resolve) => {
// Add all migrations to an array so they are executed in order
const migrationPromises = [
CheckForPreviousReportActionID,
Expand All @@ -25,7 +25,7 @@ export default function (): Promise<void> {
// previous promise to finish before moving onto the next one.
/* eslint-disable arrow-body-style */
migrationPromises
.reduce((previousPromise, migrationPromise) => {
.reduce<Promise<void | void[]>>((previousPromise, migrationPromise) => {
return previousPromise.then(() => {
return migrationPromise();
});
Expand Down
2 changes: 1 addition & 1 deletion src/libs/migrations/CheckForPreviousReportActionID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getReportActionsFromOnyx(): Promise<OnyxCollection<OnyxTypes.ReportActi
* This migration checks for the 'previousReportActionID' key in the first valid reportAction of a report in Onyx.
* If the key is not found then all reportActions for all reports are removed from Onyx.
*/
export default function (): Promise<void> {
export default function (): Promise<void | void[]> {
return getReportActionsFromOnyx().then((allReportActions) => {
if (Object.keys(allReportActions ?? {}).length === 0) {
Log.info(`[Migrate Onyx] Skipped migration CheckForPreviousReportActionID because there were no reportActions`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type ReportActionsDraftsKey = `${typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFT
* After: reportActionsDrafts_reportID: {[reportActionID]: value}
*/
export default function () {
return new Promise<void>((resolve) => {
return new Promise<void | void[]>((resolve) => {
const connectionID = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS,
waitForCollectionCallback: true,
Expand Down
2 changes: 0 additions & 2 deletions src/setup/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {I18nManager} from 'react-native';
import Onyx from 'react-native-onyx';
import intlPolyfill from '@libs/IntlPolyfill';
import * as Metrics from '@libs/Metrics';
import * as Device from '@userActions/Device';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -29,7 +28,6 @@ export default function () {
// Increase the cached key count so that the app works more consistently for accounts with large numbers of reports
maxCachedKeysCount: 20000,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
captureMetrics: Metrics.canCaptureOnyxMetrics(),
initialKeyStates: {
// Clear any loading and error messages so they do not appear on app startup
[ONYXKEYS.SESSION]: {loading: false},
Expand Down
3 changes: 0 additions & 3 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ describe('actions/IOU', () => {
new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
waitForCollectionCallback: true,
callback: (transaction) => {
Onyx.disconnect(connectionID);
expect(transaction?.pendingAction).toBeFalsy();
Expand Down Expand Up @@ -2640,7 +2639,6 @@ describe('actions/IOU', () => {
await new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT}${thread.reportID}`,
waitForCollectionCallback: true,
callback: (report) => {
Onyx.disconnect(connectionID);
expect(report).toBeTruthy();
Expand Down Expand Up @@ -2697,7 +2695,6 @@ describe('actions/IOU', () => {
await new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT}${thread.reportID}`,
waitForCollectionCallback: true,
callback: (report) => {
Onyx.disconnect(connectionID);
expect(report).toBeTruthy();
Expand Down
8 changes: 3 additions & 5 deletions tests/actions/PolicyTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Onyx from 'react-native-onyx';
import type {OnyxCollection} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager';
import * as Policy from '@src/libs/actions/Policy';
Expand Down Expand Up @@ -41,10 +41,9 @@ describe('actions/Policy', () => {
Policy.createWorkspace(ESH_EMAIL, true, WORKSPACE_NAME, policyID);
await waitForBatchedUpdates();

let policy: OnyxCollection<PolicyType> = await new Promise((resolve) => {
let policy: OnyxEntry<PolicyType> | OnyxCollection<PolicyType> = await new Promise((resolve) => {
const connectionID = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
waitForCollectionCallback: true,
callback: (workspace) => {
Onyx.disconnect(connectionID);
resolve(workspace);
Expand All @@ -61,10 +60,9 @@ describe('actions/Policy', () => {
expect(policy?.isPolicyExpenseChatEnabled).toBe(true);
expect(policy?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);

const policyMembers: OnyxCollection<PolicyMembers> = await new Promise((resolve) => {
const policyMembers: OnyxEntry<PolicyMembers> = await new Promise((resolve) => {
const connectionID = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`,
waitForCollectionCallback: true,
callback: (members) => {
Onyx.disconnect(connectionID);
resolve(members);
Expand Down
1 change: 0 additions & 1 deletion tests/unit/ReportActionsUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,6 @@ describe('ReportActionsUtils', () => {
new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
waitForCollectionCallback: true,
callback: () => {
Onyx.disconnect(connectionID);
const res = ReportActionsUtils.getLastVisibleAction(report.reportID);
Expand Down
3 changes: 2 additions & 1 deletion tests/utils/wrapOnyxWithWaitForBatchedUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type Onyx from 'react-native-onyx';
import type {Writable} from 'type-fest';
import waitForBatchedUpdates from './waitForBatchedUpdates';

/**
Expand All @@ -9,7 +10,7 @@ import waitForBatchedUpdates from './waitForBatchedUpdates';
* This is a convinience function, which wraps the onyxInstance's
* functions, to for the promises to resolve.
*/
function wrapOnyxWithWaitForBatchedUpdates(onyxInstance: typeof Onyx) {
function wrapOnyxWithWaitForBatchedUpdates(onyxInstance: Writable<typeof Onyx>) {
const multiSetImpl = onyxInstance.multiSet;
// eslint-disable-next-line no-param-reassign
onyxInstance.multiSet = (...args) => multiSetImpl(...args).then((result) => waitForBatchedUpdates().then(() => result));
Expand Down

0 comments on commit d57555b

Please sign in to comment.