From c004c4cccb367afaceaa1bfb459f9026e41ba512 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Fri, 15 Sep 2023 10:18:16 +0200 Subject: [PATCH 1/5] ref: move RenameExpensifyNewsStatus to TS --- ...meExpensifyNewsStatus.js => RenameExpensifyNewsStatus.ts} | 5 +++-- src/types/onyx/User.ts | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) rename src/libs/migrations/{RenameExpensifyNewsStatus.js => RenameExpensifyNewsStatus.ts} (83%) diff --git a/src/libs/migrations/RenameExpensifyNewsStatus.js b/src/libs/migrations/RenameExpensifyNewsStatus.ts similarity index 83% rename from src/libs/migrations/RenameExpensifyNewsStatus.js rename to src/libs/migrations/RenameExpensifyNewsStatus.ts index 421879b0e8ad..fd8c2cc62b61 100644 --- a/src/libs/migrations/RenameExpensifyNewsStatus.js +++ b/src/libs/migrations/RenameExpensifyNewsStatus.ts @@ -1,5 +1,4 @@ import Onyx from 'react-native-onyx'; -import _ from 'underscore'; import ONYXKEYS from '../../ONYXKEYS'; import Log from '../Log'; @@ -15,8 +14,9 @@ export default function () { Onyx.disconnect(connectionID); // Fail early here because there is nothing to migrate - if (!user || _.isNull(user.expensifyNewsStatus) || _.isUndefined(user.expensifyNewsStatus)) { + if (user?.expensifyNewsStatus === null || user?.expensifyNewsStatus === undefined) { Log.info('[Migrate Onyx] Skipped migration RenameExpensifyNewsStatus'); + // @ts-expect-error In that case we don't need to resolve anything return resolve(); } @@ -26,6 +26,7 @@ export default function () { isSubscribedToNewsletter: user.expensifyNewsStatus, }).then(() => { Log.info('[Migrate Onyx] Ran migration RenameExpensifyNewsStatus'); + // @ts-expect-error In that case we don't need to resolve anything resolve(); }); }, diff --git a/src/types/onyx/User.ts b/src/types/onyx/User.ts index f770b22b2272..097915490476 100644 --- a/src/types/onyx/User.ts +++ b/src/types/onyx/User.ts @@ -25,6 +25,7 @@ type User = { /** Whether the form is being submitted */ loading?: boolean; + expensifyNewsStatus?: boolean | null; }; export default User; From ce36e646656402094f7ad8737557a7481dea15c9 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Wed, 20 Sep 2023 11:14:32 +0200 Subject: [PATCH 2/5] fix: removed not needed onyx migration --- src/libs/migrateOnyx.js | 2 -- .../migrations/RenameExpensifyNewsStatus.ts | 35 ------------------- 2 files changed, 37 deletions(-) delete mode 100644 src/libs/migrations/RenameExpensifyNewsStatus.ts diff --git a/src/libs/migrateOnyx.js b/src/libs/migrateOnyx.js index 9389a9b66fbc..a58bb79a26f9 100644 --- a/src/libs/migrateOnyx.js +++ b/src/libs/migrateOnyx.js @@ -4,7 +4,6 @@ import AddEncryptedAuthToken from './migrations/AddEncryptedAuthToken'; import RenameActiveClientsKey from './migrations/RenameActiveClientsKey'; import RenamePriorityModeKey from './migrations/RenamePriorityModeKey'; import MoveToIndexedDB from './migrations/MoveToIndexedDB'; -import RenameExpensifyNewsStatus from './migrations/RenameExpensifyNewsStatus'; import AddLastVisibleActionCreated from './migrations/AddLastVisibleActionCreated'; import KeyReportActionsByReportActionID from './migrations/KeyReportActionsByReportActionID'; import PersonalDetailsByAccountID from './migrations/PersonalDetailsByAccountID'; @@ -20,7 +19,6 @@ export default function () { RenameActiveClientsKey, RenamePriorityModeKey, AddEncryptedAuthToken, - RenameExpensifyNewsStatus, AddLastVisibleActionCreated, KeyReportActionsByReportActionID, PersonalDetailsByAccountID, diff --git a/src/libs/migrations/RenameExpensifyNewsStatus.ts b/src/libs/migrations/RenameExpensifyNewsStatus.ts deleted file mode 100644 index fd8c2cc62b61..000000000000 --- a/src/libs/migrations/RenameExpensifyNewsStatus.ts +++ /dev/null @@ -1,35 +0,0 @@ -import Onyx from 'react-native-onyx'; -import ONYXKEYS from '../../ONYXKEYS'; -import Log from '../Log'; - -// This migration changes the name of the Onyx key user.expensifyNewsStatus from expensifyNewsStatus to isSubscribedToNewsletter -export default function () { - return new Promise((resolve) => { - // Connect to the USER key in Onyx to get the value of expensifyNewsStatus - // then set that value as isSubscribedToNewsletter - // finally remove expensifyNewsStatus by setting the value to null - const connectionID = Onyx.connect({ - key: ONYXKEYS.USER, - callback: (user) => { - Onyx.disconnect(connectionID); - - // Fail early here because there is nothing to migrate - if (user?.expensifyNewsStatus === null || user?.expensifyNewsStatus === undefined) { - Log.info('[Migrate Onyx] Skipped migration RenameExpensifyNewsStatus'); - // @ts-expect-error In that case we don't need to resolve anything - return resolve(); - } - - // eslint-disable-next-line rulesdir/prefer-actions-set-data - Onyx.merge(ONYXKEYS.USER, { - expensifyNewsStatus: null, - isSubscribedToNewsletter: user.expensifyNewsStatus, - }).then(() => { - Log.info('[Migrate Onyx] Ran migration RenameExpensifyNewsStatus'); - // @ts-expect-error In that case we don't need to resolve anything - resolve(); - }); - }, - }); - }); -} From 364fb226f8c29706f18231d34d740fa5fdd82e33 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Wed, 20 Sep 2023 12:29:47 +0200 Subject: [PATCH 3/5] ref: reverted changes from User type --- src/types/onyx/User.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types/onyx/User.ts b/src/types/onyx/User.ts index 097915490476..f770b22b2272 100644 --- a/src/types/onyx/User.ts +++ b/src/types/onyx/User.ts @@ -25,7 +25,6 @@ type User = { /** Whether the form is being submitted */ loading?: boolean; - expensifyNewsStatus?: boolean | null; }; export default User; From b45e8962563330795aba5652beb0e1c89570a092 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Thu, 21 Sep 2023 16:15:58 +0200 Subject: [PATCH 4/5] chore: check for lint error --- src/libs/migrateOnyx.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/migrateOnyx.js b/src/libs/migrateOnyx.js index a58bb79a26f9..23153fea0be2 100644 --- a/src/libs/migrateOnyx.js +++ b/src/libs/migrateOnyx.js @@ -18,6 +18,7 @@ export default function () { MoveToIndexedDB, RenameActiveClientsKey, RenamePriorityModeKey, + AddEncryptedAuthToken, AddLastVisibleActionCreated, KeyReportActionsByReportActionID, From 3006ce9911ed651b3b33a032c8b30a9c55ec2b24 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Thu, 21 Sep 2023 16:16:19 +0200 Subject: [PATCH 5/5] chore: revert change --- src/libs/migrateOnyx.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/migrateOnyx.js b/src/libs/migrateOnyx.js index 23153fea0be2..a58bb79a26f9 100644 --- a/src/libs/migrateOnyx.js +++ b/src/libs/migrateOnyx.js @@ -18,7 +18,6 @@ export default function () { MoveToIndexedDB, RenameActiveClientsKey, RenamePriorityModeKey, - AddEncryptedAuthToken, AddLastVisibleActionCreated, KeyReportActionsByReportActionID,